1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Emit .debug_line header even when there are no functions, since
27 the file numbers are used by .debug_info. Alternately, leave
28 out locations for types and decls.
29 Avoid talking about ctors and op= for PODs.
30 Factor out common prologue sequences into multiple CIEs. */
32 /* The first part of this file deals with the DWARF 2 frame unwind
33 information, which is also used by the GCC efficient exception handling
34 mechanism. The second part, controlled only by an #ifdef
35 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
43 #include "hard-reg-set.h"
45 #include "insn-config.h"
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,
1744 tree label = get_file_function_name ('F');
1747 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1748 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1749 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1751 assemble_label ("__FRAME_BEGIN__");
1754 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG, 1);
1756 /* Output the CIE. */
1757 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1758 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1759 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1760 "Length of Common Information Entry");
1761 ASM_OUTPUT_LABEL (asm_out_file, l1);
1763 /* Now that the CIE pointer is PC-relative for EH,
1764 use 0 to identify the CIE. */
1765 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1766 (for_eh ? 0 : DW_CIE_ID),
1767 "CIE Identifier Tag");
1769 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1771 augmentation[0] = 0;
1772 augmentation_size = 0;
1778 z Indicates that a uleb128 is present to size the
1779 augmentation section.
1780 L Indicates the encoding (and thus presence) of
1781 an LSDA pointer in the FDE augmentation.
1782 R Indicates a non-default pointer encoding for
1784 P Indicates the presence of an encoding + language
1785 personality routine in the CIE augmentation. */
1787 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1788 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1789 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1791 p = augmentation + 1;
1792 if (eh_personality_libfunc)
1795 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1797 if (any_lsda_needed)
1800 augmentation_size += 1;
1802 if (fde_encoding != DW_EH_PE_absptr)
1805 augmentation_size += 1;
1807 if (p > augmentation + 1)
1809 augmentation[0] = 'z';
1813 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1814 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1816 int offset = ( 4 /* Length */
1818 + 1 /* CIE version */
1819 + strlen (augmentation) + 1 /* Augmentation */
1820 + size_of_uleb128 (1) /* Code alignment */
1821 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1823 + 1 /* Augmentation size */
1824 + 1 /* Personality encoding */ );
1825 int pad = -offset & (PTR_SIZE - 1);
1827 augmentation_size += pad;
1829 /* Augmentations should be small, so there's scarce need to
1830 iterate for a solution. Die if we exceed one uleb128 byte. */
1831 if (size_of_uleb128 (augmentation_size) != 1)
1835 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1837 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1839 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1840 "CIE Data Alignment Factor");
1842 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1844 if (augmentation[0])
1846 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1847 if (eh_personality_libfunc)
1849 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1850 eh_data_format_name (per_encoding));
1851 dw2_asm_output_encoded_addr_rtx (per_encoding,
1852 eh_personality_libfunc, NULL);
1854 if (any_lsda_needed)
1855 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1856 eh_data_format_name (lsda_encoding));
1857 if (fde_encoding != DW_EH_PE_absptr)
1858 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1859 eh_data_format_name (fde_encoding));
1862 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1863 output_cfi (cfi, NULL, for_eh);
1865 /* Pad the CIE out to an address sized boundary. */
1866 ASM_OUTPUT_ALIGN (asm_out_file,
1867 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1868 ASM_OUTPUT_LABEL (asm_out_file, l2);
1870 /* Loop through all of the FDE's. */
1871 for (i = 0; i < fde_table_in_use; ++i)
1873 fde = &fde_table[i];
1875 /* Don't emit EH unwind info for leaf functions that don't need it. */
1876 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1879 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1880 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1881 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1882 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1884 ASM_OUTPUT_LABEL (asm_out_file, l1);
1886 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1887 emits a target dependent sized offset when for_eh is not true.
1888 This inconsistency may confuse gdb. The only case where we need a
1889 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1890 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1891 though in order to be compatible with the dwarf_fde struct in frame.c.
1892 If the for_eh case is changed, then the struct in frame.c has
1893 to be adjusted appropriately. */
1895 dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset");
1897 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
1898 stripattributes (DEBUG_FRAME_SECTION),
1903 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1904 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1905 "FDE initial location");
1906 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1907 fde->dw_fde_end, fde->dw_fde_begin,
1908 "FDE address range");
1912 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1913 "FDE initial location");
1914 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1915 fde->dw_fde_end, fde->dw_fde_begin,
1916 "FDE address range");
1919 if (augmentation[0])
1921 if (any_lsda_needed)
1923 int size = size_of_encoded_value (lsda_encoding);
1925 if (lsda_encoding == DW_EH_PE_aligned)
1927 int offset = ( 4 /* Length */
1928 + 4 /* CIE offset */
1929 + 2 * size_of_encoded_value (fde_encoding)
1930 + 1 /* Augmentation size */ );
1931 int pad = -offset & (PTR_SIZE - 1);
1934 if (size_of_uleb128 (size) != 1)
1938 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1940 if (fde->uses_eh_lsda)
1942 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
1943 fde->funcdef_number);
1944 dw2_asm_output_encoded_addr_rtx (
1945 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
1946 "Language Specific Data Area");
1950 if (lsda_encoding == DW_EH_PE_aligned)
1951 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1952 dw2_asm_output_data (size_of_encoded_value (lsda_encoding),
1953 0, "Language Specific Data Area (none)");
1957 dw2_asm_output_data_uleb128 (0, "Augmentation size");
1960 /* Loop through the Call Frame Instructions associated with
1962 fde->dw_fde_current_label = fde->dw_fde_begin;
1963 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1964 output_cfi (cfi, fde, for_eh);
1966 /* Pad the FDE out to an address sized boundary. */
1967 ASM_OUTPUT_ALIGN (asm_out_file,
1968 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1969 ASM_OUTPUT_LABEL (asm_out_file, l2);
1972 #ifndef EH_FRAME_SECTION_NAME
1974 dw2_asm_output_data (4, 0, "End of Table");
1976 #ifdef MIPS_DEBUGGING_INFO
1977 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1978 get a value of 0. Putting .align 0 after the label fixes it. */
1979 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1982 /* Turn off app to make assembly quicker. */
1987 /* Output a marker (i.e. a label) for the beginning of a function, before
1991 dwarf2out_begin_prologue (line, file)
1992 unsigned int line ATTRIBUTE_UNUSED;
1993 const char *file ATTRIBUTE_UNUSED;
1995 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1996 register dw_fde_ref fde;
1998 current_function_func_begin_label = 0;
2000 #ifdef IA64_UNWIND_INFO
2001 /* ??? current_function_func_begin_label is also used by except.c
2002 for call-site information. We must emit this label if it might
2004 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2005 && ! dwarf2out_do_frame ())
2008 if (! dwarf2out_do_frame ())
2012 ++current_funcdef_number;
2014 function_section (current_function_decl);
2015 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2016 current_funcdef_number);
2017 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2018 current_funcdef_number);
2019 current_function_func_begin_label = get_identifier (label);
2021 #ifdef IA64_UNWIND_INFO
2022 /* We can elide the fde allocation if we're not emitting debug info. */
2023 if (! dwarf2out_do_frame ())
2027 /* Expand the fde table if necessary. */
2028 if (fde_table_in_use == fde_table_allocated)
2030 fde_table_allocated += FDE_TABLE_INCREMENT;
2032 = (dw_fde_ref) xrealloc (fde_table,
2033 fde_table_allocated * sizeof (dw_fde_node));
2036 /* Record the FDE associated with this function. */
2037 current_funcdef_fde = fde_table_in_use;
2039 /* Add the new FDE at the end of the fde_table. */
2040 fde = &fde_table[fde_table_in_use++];
2041 fde->dw_fde_begin = xstrdup (label);
2042 fde->dw_fde_current_label = NULL;
2043 fde->dw_fde_end = NULL;
2044 fde->dw_fde_cfi = NULL;
2045 fde->funcdef_number = current_funcdef_number;
2046 fde->nothrow = current_function_nothrow;
2047 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2049 args_size = old_args_size = 0;
2051 /* We only want to output line number information for the genuine
2052 dwarf2 prologue case, not the eh frame case. */
2053 #ifdef DWARF2_DEBUGGING_INFO
2055 dwarf2out_source_line (line, file);
2059 /* Output a marker (i.e. a label) for the absolute end of the generated code
2060 for a function definition. This gets called *after* the epilogue code has
2064 dwarf2out_end_epilogue ()
2067 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2069 /* Output a label to mark the endpoint of the code generated for this
2071 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2072 ASM_OUTPUT_LABEL (asm_out_file, label);
2073 fde = &fde_table[fde_table_in_use - 1];
2074 fde->dw_fde_end = xstrdup (label);
2078 dwarf2out_frame_init ()
2080 /* Allocate the initial hunk of the fde_table. */
2081 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2082 fde_table_allocated = FDE_TABLE_INCREMENT;
2083 fde_table_in_use = 0;
2085 /* Generate the CFA instructions common to all FDE's. Do it now for the
2086 sake of lookup_cfa. */
2088 #ifdef DWARF2_UNWIND_INFO
2089 /* On entry, the Canonical Frame Address is at SP. */
2090 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2091 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2096 dwarf2out_frame_finish ()
2098 /* Output call frame information. */
2099 #ifdef MIPS_DEBUGGING_INFO
2100 if (write_symbols == DWARF2_DEBUG)
2101 output_call_frame_info (0);
2102 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2103 output_call_frame_info (1);
2105 int for_eh = (! USING_SJLJ_EXCEPTIONS
2106 && (flag_unwind_tables || flag_exceptions));
2107 if (write_symbols == DWARF2_DEBUG || for_eh)
2108 output_call_frame_info (for_eh);
2112 /* And now, the subset of the debugging information support code necessary
2113 for emitting location expressions. */
2115 typedef struct dw_val_struct *dw_val_ref;
2116 typedef struct die_struct *dw_die_ref;
2117 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2118 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2120 /* Each DIE may have a series of attribute/value pairs. Values
2121 can take on several forms. The forms that are used in this
2122 implementation are listed below. */
2127 dw_val_class_offset,
2129 dw_val_class_loc_list,
2131 dw_val_class_unsigned_const,
2132 dw_val_class_long_long,
2135 dw_val_class_die_ref,
2136 dw_val_class_fde_ref,
2137 dw_val_class_lbl_id,
2138 dw_val_class_lbl_offset,
2143 /* Describe a double word constant value. */
2144 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2146 typedef struct dw_long_long_struct
2153 /* Describe a floating point constant value. */
2155 typedef struct dw_fp_struct
2162 /* The dw_val_node describes an attribute's value, as it is
2163 represented internally. */
2165 typedef struct dw_val_struct
2167 dw_val_class val_class;
2171 long unsigned val_offset;
2172 dw_loc_list_ref val_loc_list;
2173 dw_loc_descr_ref val_loc;
2175 long unsigned val_unsigned;
2176 dw_long_long_const val_long_long;
2177 dw_float_const val_float;
2182 unsigned val_fde_index;
2185 unsigned char val_flag;
2191 /* Locations in memory are described using a sequence of stack machine
2194 typedef struct dw_loc_descr_struct
2196 dw_loc_descr_ref dw_loc_next;
2197 enum dwarf_location_atom dw_loc_opc;
2198 dw_val_node dw_loc_oprnd1;
2199 dw_val_node dw_loc_oprnd2;
2204 /* Location lists are ranges + location descriptions for that range,
2205 so you can track variables that are in different places over
2206 their entire life. */
2207 typedef struct dw_loc_list_struct
2209 dw_loc_list_ref dw_loc_next;
2210 const char *begin; /* Label for begin address of range */
2211 const char *end; /* Label for end address of range */
2212 char *ll_symbol; /* Label for beginning of location list. Only on head of list */
2213 const char *section; /* Section this loclist is relative to */
2214 dw_loc_descr_ref expr;
2217 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2218 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2221 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2223 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2224 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2225 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2226 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2228 /* Convert a DWARF stack opcode into its string name. */
2231 dwarf_stack_op_name (op)
2232 register unsigned op;
2237 return "DW_OP_addr";
2239 return "DW_OP_deref";
2241 return "DW_OP_const1u";
2243 return "DW_OP_const1s";
2245 return "DW_OP_const2u";
2247 return "DW_OP_const2s";
2249 return "DW_OP_const4u";
2251 return "DW_OP_const4s";
2253 return "DW_OP_const8u";
2255 return "DW_OP_const8s";
2257 return "DW_OP_constu";
2259 return "DW_OP_consts";
2263 return "DW_OP_drop";
2265 return "DW_OP_over";
2267 return "DW_OP_pick";
2269 return "DW_OP_swap";
2273 return "DW_OP_xderef";
2281 return "DW_OP_minus";
2293 return "DW_OP_plus";
2294 case DW_OP_plus_uconst:
2295 return "DW_OP_plus_uconst";
2301 return "DW_OP_shra";
2319 return "DW_OP_skip";
2321 return "DW_OP_lit0";
2323 return "DW_OP_lit1";
2325 return "DW_OP_lit2";
2327 return "DW_OP_lit3";
2329 return "DW_OP_lit4";
2331 return "DW_OP_lit5";
2333 return "DW_OP_lit6";
2335 return "DW_OP_lit7";
2337 return "DW_OP_lit8";
2339 return "DW_OP_lit9";
2341 return "DW_OP_lit10";
2343 return "DW_OP_lit11";
2345 return "DW_OP_lit12";
2347 return "DW_OP_lit13";
2349 return "DW_OP_lit14";
2351 return "DW_OP_lit15";
2353 return "DW_OP_lit16";
2355 return "DW_OP_lit17";
2357 return "DW_OP_lit18";
2359 return "DW_OP_lit19";
2361 return "DW_OP_lit20";
2363 return "DW_OP_lit21";
2365 return "DW_OP_lit22";
2367 return "DW_OP_lit23";
2369 return "DW_OP_lit24";
2371 return "DW_OP_lit25";
2373 return "DW_OP_lit26";
2375 return "DW_OP_lit27";
2377 return "DW_OP_lit28";
2379 return "DW_OP_lit29";
2381 return "DW_OP_lit30";
2383 return "DW_OP_lit31";
2385 return "DW_OP_reg0";
2387 return "DW_OP_reg1";
2389 return "DW_OP_reg2";
2391 return "DW_OP_reg3";
2393 return "DW_OP_reg4";
2395 return "DW_OP_reg5";
2397 return "DW_OP_reg6";
2399 return "DW_OP_reg7";
2401 return "DW_OP_reg8";
2403 return "DW_OP_reg9";
2405 return "DW_OP_reg10";
2407 return "DW_OP_reg11";
2409 return "DW_OP_reg12";
2411 return "DW_OP_reg13";
2413 return "DW_OP_reg14";
2415 return "DW_OP_reg15";
2417 return "DW_OP_reg16";
2419 return "DW_OP_reg17";
2421 return "DW_OP_reg18";
2423 return "DW_OP_reg19";
2425 return "DW_OP_reg20";
2427 return "DW_OP_reg21";
2429 return "DW_OP_reg22";
2431 return "DW_OP_reg23";
2433 return "DW_OP_reg24";
2435 return "DW_OP_reg25";
2437 return "DW_OP_reg26";
2439 return "DW_OP_reg27";
2441 return "DW_OP_reg28";
2443 return "DW_OP_reg29";
2445 return "DW_OP_reg30";
2447 return "DW_OP_reg31";
2449 return "DW_OP_breg0";
2451 return "DW_OP_breg1";
2453 return "DW_OP_breg2";
2455 return "DW_OP_breg3";
2457 return "DW_OP_breg4";
2459 return "DW_OP_breg5";
2461 return "DW_OP_breg6";
2463 return "DW_OP_breg7";
2465 return "DW_OP_breg8";
2467 return "DW_OP_breg9";
2469 return "DW_OP_breg10";
2471 return "DW_OP_breg11";
2473 return "DW_OP_breg12";
2475 return "DW_OP_breg13";
2477 return "DW_OP_breg14";
2479 return "DW_OP_breg15";
2481 return "DW_OP_breg16";
2483 return "DW_OP_breg17";
2485 return "DW_OP_breg18";
2487 return "DW_OP_breg19";
2489 return "DW_OP_breg20";
2491 return "DW_OP_breg21";
2493 return "DW_OP_breg22";
2495 return "DW_OP_breg23";
2497 return "DW_OP_breg24";
2499 return "DW_OP_breg25";
2501 return "DW_OP_breg26";
2503 return "DW_OP_breg27";
2505 return "DW_OP_breg28";
2507 return "DW_OP_breg29";
2509 return "DW_OP_breg30";
2511 return "DW_OP_breg31";
2513 return "DW_OP_regx";
2515 return "DW_OP_fbreg";
2517 return "DW_OP_bregx";
2519 return "DW_OP_piece";
2520 case DW_OP_deref_size:
2521 return "DW_OP_deref_size";
2522 case DW_OP_xderef_size:
2523 return "DW_OP_xderef_size";
2527 return "OP_<unknown>";
2531 /* Return a pointer to a newly allocated location description. Location
2532 descriptions are simple expression terms that can be strung
2533 together to form more complicated location (address) descriptions. */
2535 static inline dw_loc_descr_ref
2536 new_loc_descr (op, oprnd1, oprnd2)
2537 register enum dwarf_location_atom op;
2538 register unsigned long oprnd1;
2539 register unsigned long oprnd2;
2541 /* Use xcalloc here so we clear out all of the long_long constant in
2543 register dw_loc_descr_ref descr
2544 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2546 descr->dw_loc_opc = op;
2547 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2548 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2549 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2550 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2556 /* Add a location description term to a location description expression. */
2559 add_loc_descr (list_head, descr)
2560 register dw_loc_descr_ref *list_head;
2561 register dw_loc_descr_ref descr;
2563 register dw_loc_descr_ref *d;
2565 /* Find the end of the chain. */
2566 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2572 /* Return the size of a location descriptor. */
2574 static unsigned long
2575 size_of_loc_descr (loc)
2576 register dw_loc_descr_ref loc;
2578 register unsigned long size = 1;
2580 switch (loc->dw_loc_opc)
2583 size += DWARF2_ADDR_SIZE;
2602 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2605 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2610 case DW_OP_plus_uconst:
2611 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2649 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2652 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2655 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2658 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2659 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2662 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2664 case DW_OP_deref_size:
2665 case DW_OP_xderef_size:
2675 /* Return the size of a series of location descriptors. */
2677 static unsigned long
2679 register dw_loc_descr_ref loc;
2681 register unsigned long size = 0;
2683 for (; loc != NULL; loc = loc->dw_loc_next)
2685 loc->dw_loc_addr = size;
2686 size += size_of_loc_descr (loc);
2692 /* Output location description stack opcode's operands (if any). */
2695 output_loc_operands (loc)
2696 register dw_loc_descr_ref loc;
2698 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2699 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2701 switch (loc->dw_loc_opc)
2703 #ifdef DWARF2_DEBUGGING_INFO
2705 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2709 dw2_asm_output_data (2, val1->v.val_int, NULL);
2713 dw2_asm_output_data (4, val1->v.val_int, NULL);
2717 if (HOST_BITS_PER_LONG < 64)
2719 dw2_asm_output_data (8, val1->v.val_int, NULL);
2726 if (val1->val_class == dw_val_class_loc)
2727 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2731 dw2_asm_output_data (2, offset, NULL);
2744 /* We currently don't make any attempt to make sure these are
2745 aligned properly like we do for the main unwind info, so
2746 don't support emitting things larger than a byte if we're
2747 only doing unwinding. */
2752 dw2_asm_output_data (1, val1->v.val_int, NULL);
2755 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2758 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2761 dw2_asm_output_data (1, val1->v.val_int, NULL);
2763 case DW_OP_plus_uconst:
2764 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2798 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2801 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2804 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2807 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2808 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2811 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2813 case DW_OP_deref_size:
2814 case DW_OP_xderef_size:
2815 dw2_asm_output_data (1, val1->v.val_int, NULL);
2818 /* Other codes have no operands. */
2823 /* Output a sequence of location operations. */
2826 output_loc_sequence (loc)
2827 dw_loc_descr_ref loc;
2829 for (; loc != NULL; loc = loc->dw_loc_next)
2831 /* Output the opcode. */
2832 dw2_asm_output_data (1, loc->dw_loc_opc,
2833 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2835 /* Output the operand(s) (if any). */
2836 output_loc_operands (loc);
2840 /* This routine will generate the correct assembly data for a location
2841 description based on a cfi entry with a complex address. */
2844 output_cfa_loc (cfi)
2847 dw_loc_descr_ref loc;
2850 /* Output the size of the block. */
2851 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2852 size = size_of_locs (loc);
2853 dw2_asm_output_data_uleb128 (size, NULL);
2855 /* Now output the operations themselves. */
2856 output_loc_sequence (loc);
2859 /* This function builds a dwarf location descriptor sequence from
2860 a dw_cfa_location. */
2862 static struct dw_loc_descr_struct *
2864 dw_cfa_location *cfa;
2866 struct dw_loc_descr_struct *head, *tmp;
2868 if (cfa->indirect == 0)
2871 if (cfa->base_offset)
2874 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2876 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2878 else if (cfa->reg <= 31)
2879 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2881 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2882 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2883 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2884 add_loc_descr (&head, tmp);
2885 if (cfa->offset != 0)
2887 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2888 add_loc_descr (&head, tmp);
2893 /* This function fills in aa dw_cfa_location structure from a
2894 dwarf location descriptor sequence. */
2897 get_cfa_from_loc_descr (cfa, loc)
2898 dw_cfa_location *cfa;
2899 struct dw_loc_descr_struct *loc;
2901 struct dw_loc_descr_struct *ptr;
2903 cfa->base_offset = 0;
2907 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2909 enum dwarf_location_atom op = ptr->dw_loc_opc;
2944 cfa->reg = op - DW_OP_reg0;
2947 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2981 cfa->reg = op - DW_OP_breg0;
2982 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2985 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2986 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2991 case DW_OP_plus_uconst:
2992 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2995 internal_error ("DW_LOC_OP %s not implememnted\n",
2996 dwarf_stack_op_name (ptr->dw_loc_opc));
3000 #endif /* .debug_frame support */
3002 /* And now, the support for symbolic debugging information. */
3003 #ifdef DWARF2_DEBUGGING_INFO
3005 static void dwarf2out_init PARAMS ((const char *));
3006 static void dwarf2out_finish PARAMS ((const char *));
3007 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3008 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3009 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3010 static void dwarf2out_end_source_file PARAMS ((unsigned));
3011 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3012 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3013 static bool dwarf2out_ignore_block PARAMS ((tree));
3014 static void dwarf2out_global_decl PARAMS ((tree));
3015 static void dwarf2out_abstract_function PARAMS ((tree));
3017 /* The debug hooks structure. */
3019 struct gcc_debug_hooks dwarf2_debug_hooks =
3025 dwarf2out_start_source_file,
3026 dwarf2out_end_source_file,
3027 dwarf2out_begin_block,
3028 dwarf2out_end_block,
3029 dwarf2out_ignore_block,
3030 dwarf2out_source_line,
3031 dwarf2out_begin_prologue,
3032 debug_nothing_int, /* end_prologue */
3033 dwarf2out_end_epilogue,
3034 debug_nothing_tree, /* begin_function */
3035 debug_nothing_int, /* end_function */
3036 dwarf2out_decl, /* function_decl */
3037 dwarf2out_global_decl,
3038 debug_nothing_tree, /* deferred_inline_function */
3039 /* The DWARF 2 backend tries to reduce debugging bloat by not
3040 emitting the abstract description of inline functions until
3041 something tries to reference them. */
3042 dwarf2out_abstract_function, /* outlining_inline_function */
3043 debug_nothing_rtx /* label */
3046 /* NOTE: In the comments in this file, many references are made to
3047 "Debugging Information Entries". This term is abbreviated as `DIE'
3048 throughout the remainder of this file. */
3050 /* An internal representation of the DWARF output is built, and then
3051 walked to generate the DWARF debugging info. The walk of the internal
3052 representation is done after the entire program has been compiled.
3053 The types below are used to describe the internal representation. */
3055 /* Various DIE's use offsets relative to the beginning of the
3056 .debug_info section to refer to each other. */
3058 typedef long int dw_offset;
3060 /* Define typedefs here to avoid circular dependencies. */
3062 typedef struct dw_attr_struct *dw_attr_ref;
3063 typedef struct dw_line_info_struct *dw_line_info_ref;
3064 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3065 typedef struct pubname_struct *pubname_ref;
3066 typedef struct dw_ranges_struct *dw_ranges_ref;
3068 /* Each entry in the line_info_table maintains the file and
3069 line number associated with the label generated for that
3070 entry. The label gives the PC value associated with
3071 the line number entry. */
3073 typedef struct dw_line_info_struct
3075 unsigned long dw_file_num;
3076 unsigned long dw_line_num;
3080 /* Line information for functions in separate sections; each one gets its
3082 typedef struct dw_separate_line_info_struct
3084 unsigned long dw_file_num;
3085 unsigned long dw_line_num;
3086 unsigned long function;
3088 dw_separate_line_info_entry;
3090 /* Each DIE attribute has a field specifying the attribute kind,
3091 a link to the next attribute in the chain, and an attribute value.
3092 Attributes are typically linked below the DIE they modify. */
3094 typedef struct dw_attr_struct
3096 enum dwarf_attribute dw_attr;
3097 dw_attr_ref dw_attr_next;
3098 dw_val_node dw_attr_val;
3102 /* The Debugging Information Entry (DIE) structure */
3104 typedef struct die_struct
3106 enum dwarf_tag die_tag;
3108 dw_attr_ref die_attr;
3109 dw_die_ref die_parent;
3110 dw_die_ref die_child;
3112 dw_offset die_offset;
3113 unsigned long die_abbrev;
3118 /* The pubname structure */
3120 typedef struct pubname_struct
3127 struct dw_ranges_struct
3132 /* The limbo die list structure. */
3133 typedef struct limbo_die_struct
3136 struct limbo_die_struct *next;
3140 /* How to start an assembler comment. */
3141 #ifndef ASM_COMMENT_START
3142 #define ASM_COMMENT_START ";#"
3145 /* Define a macro which returns non-zero for a TYPE_DECL which was
3146 implicitly generated for a tagged type.
3148 Note that unlike the gcc front end (which generates a NULL named
3149 TYPE_DECL node for each complete tagged type, each array type, and
3150 each function type node created) the g++ front end generates a
3151 _named_ TYPE_DECL node for each tagged type node created.
3152 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3153 generate a DW_TAG_typedef DIE for them. */
3155 #define TYPE_DECL_IS_STUB(decl) \
3156 (DECL_NAME (decl) == NULL_TREE \
3157 || (DECL_ARTIFICIAL (decl) \
3158 && is_tagged_type (TREE_TYPE (decl)) \
3159 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3160 /* This is necessary for stub decls that \
3161 appear in nested inline functions. */ \
3162 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3163 && (decl_ultimate_origin (decl) \
3164 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3166 /* Information concerning the compilation unit's programming
3167 language, and compiler version. */
3169 extern int flag_traditional;
3171 /* Fixed size portion of the DWARF compilation unit header. */
3172 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3174 /* Fixed size portion of debugging line information prolog. */
3175 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3177 /* Fixed size portion of public names info. */
3178 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3180 /* Fixed size portion of the address range info. */
3181 #define DWARF_ARANGES_HEADER_SIZE \
3182 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3183 - DWARF_OFFSET_SIZE)
3185 /* Size of padding portion in the address range info. It must be
3186 aligned to twice the pointer size. */
3187 #define DWARF_ARANGES_PAD_SIZE \
3188 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3189 - (2 * DWARF_OFFSET_SIZE + 4))
3191 /* Use assembler line directives if available. */
3192 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3193 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3194 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3196 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3200 /* Define the architecture-dependent minimum instruction length (in bytes).
3201 In this implementation of DWARF, this field is used for information
3202 purposes only. Since GCC generates assembly language, we have
3203 no a priori knowledge of how many instruction bytes are generated
3204 for each source line, and therefore can use only the DW_LNE_set_address
3205 and DW_LNS_fixed_advance_pc line information commands. */
3207 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3208 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3211 /* Minimum line offset in a special line info. opcode.
3212 This value was chosen to give a reasonable range of values. */
3213 #define DWARF_LINE_BASE -10
3215 /* First special line opcde - leave room for the standard opcodes. */
3216 #define DWARF_LINE_OPCODE_BASE 10
3218 /* Range of line offsets in a special line info. opcode. */
3219 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3221 /* Flag that indicates the initial value of the is_stmt_start flag.
3222 In the present implementation, we do not mark any lines as
3223 the beginning of a source statement, because that information
3224 is not made available by the GCC front-end. */
3225 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3227 /* This location is used by calc_die_sizes() to keep track
3228 the offset of each DIE within the .debug_info section. */
3229 static unsigned long next_die_offset;
3231 /* Record the root of the DIE's built for the current compilation unit. */
3232 static dw_die_ref comp_unit_die;
3234 /* A list of DIEs with a NULL parent waiting to be relocated. */
3235 static limbo_die_node *limbo_die_list = 0;
3237 /* Structure used by lookup_filename to manage sets of filenames. */
3243 unsigned last_lookup_index;
3246 /* Size (in elements) of increments by which we may expand the filename
3248 #define FILE_TABLE_INCREMENT 64
3250 /* Filenames referenced by this compilation unit. */
3251 static struct file_table file_table;
3253 /* Local pointer to the name of the main input file. Initialized in
3255 static const char *primary_filename;
3257 /* A pointer to the base of a table of references to DIE's that describe
3258 declarations. The table is indexed by DECL_UID() which is a unique
3259 number identifying each decl. */
3260 static dw_die_ref *decl_die_table;
3262 /* Number of elements currently allocated for the decl_die_table. */
3263 static unsigned decl_die_table_allocated;
3265 /* Number of elements in decl_die_table currently in use. */
3266 static unsigned decl_die_table_in_use;
3268 /* Size (in elements) of increments by which we may expand the
3270 #define DECL_DIE_TABLE_INCREMENT 256
3272 /* A pointer to the base of a table of references to declaration
3273 scopes. This table is a display which tracks the nesting
3274 of declaration scopes at the current scope and containing
3275 scopes. This table is used to find the proper place to
3276 define type declaration DIE's. */
3277 static tree *decl_scope_table;
3279 /* Number of elements currently allocated for the decl_scope_table. */
3280 static int decl_scope_table_allocated;
3282 /* Current level of nesting of declaration scopes. */
3283 static int decl_scope_depth;
3285 /* Size (in elements) of increments by which we may expand the
3286 decl_scope_table. */
3287 #define DECL_SCOPE_TABLE_INCREMENT 64
3289 /* A pointer to the base of a list of references to DIE's that
3290 are uniquely identified by their tag, presence/absence of
3291 children DIE's, and list of attribute/value pairs. */
3292 static dw_die_ref *abbrev_die_table;
3294 /* Number of elements currently allocated for abbrev_die_table. */
3295 static unsigned abbrev_die_table_allocated;
3297 /* Number of elements in type_die_table currently in use. */
3298 static unsigned abbrev_die_table_in_use;
3300 /* Size (in elements) of increments by which we may expand the
3301 abbrev_die_table. */
3302 #define ABBREV_DIE_TABLE_INCREMENT 256
3304 /* A pointer to the base of a table that contains line information
3305 for each source code line in .text in the compilation unit. */
3306 static dw_line_info_ref line_info_table;
3308 /* Number of elements currently allocated for line_info_table. */
3309 static unsigned line_info_table_allocated;
3311 /* Number of elements in separate_line_info_table currently in use. */
3312 static unsigned separate_line_info_table_in_use;
3314 /* A pointer to the base of a table that contains line information
3315 for each source code line outside of .text in the compilation unit. */
3316 static dw_separate_line_info_ref separate_line_info_table;
3318 /* Number of elements currently allocated for separate_line_info_table. */
3319 static unsigned separate_line_info_table_allocated;
3321 /* Number of elements in line_info_table currently in use. */
3322 static unsigned line_info_table_in_use;
3324 /* Size (in elements) of increments by which we may expand the
3326 #define LINE_INFO_TABLE_INCREMENT 1024
3328 /* A pointer to the base of a table that contains a list of publicly
3329 accessible names. */
3330 static pubname_ref pubname_table;
3332 /* Number of elements currently allocated for pubname_table. */
3333 static unsigned pubname_table_allocated;
3335 /* Number of elements in pubname_table currently in use. */
3336 static unsigned pubname_table_in_use;
3338 /* Size (in elements) of increments by which we may expand the
3340 #define PUBNAME_TABLE_INCREMENT 64
3342 /* Array of dies for which we should generate .debug_arange info. */
3343 static dw_die_ref *arange_table;
3345 /* Number of elements currently allocated for arange_table. */
3346 static unsigned arange_table_allocated;
3348 /* Number of elements in arange_table currently in use. */
3349 static unsigned arange_table_in_use;
3351 /* Size (in elements) of increments by which we may expand the
3353 #define ARANGE_TABLE_INCREMENT 64
3355 /* Array of dies for which we should generate .debug_ranges info. */
3356 static dw_ranges_ref ranges_table;
3358 /* Number of elements currently allocated for ranges_table. */
3359 static unsigned ranges_table_allocated;
3361 /* Number of elements in ranges_table currently in use. */
3362 static unsigned ranges_table_in_use;
3364 /* Size (in elements) of increments by which we may expand the
3366 #define RANGES_TABLE_INCREMENT 64
3368 /* Whether we have location lists that need outputting */
3369 static unsigned have_location_lists;
3371 /* A pointer to the base of a list of incomplete types which might be
3372 completed at some later time. */
3374 static tree *incomplete_types_list;
3376 /* Number of elements currently allocated for the incomplete_types_list. */
3377 static unsigned incomplete_types_allocated;
3379 /* Number of elements of incomplete_types_list currently in use. */
3380 static unsigned incomplete_types;
3382 /* Size (in elements) of increments by which we may expand the incomplete
3383 types list. Actually, a single hunk of space of this size should
3384 be enough for most typical programs. */
3385 #define INCOMPLETE_TYPES_INCREMENT 64
3387 /* Record whether the function being analyzed contains inlined functions. */
3388 static int current_function_has_inlines;
3389 #if 0 && defined (MIPS_DEBUGGING_INFO)
3390 static int comp_unit_has_inlines;
3393 /* Array of RTXes referenced by the debugging information, which therefore
3394 must be kept around forever. We do this rather than perform GC on
3395 the dwarf info because almost all of the dwarf info lives forever, and
3396 it's easier to support non-GC frontends this way. */
3397 static varray_type used_rtx_varray;
3399 /* Forward declarations for functions defined in this file. */
3401 static int is_pseudo_reg PARAMS ((rtx));
3402 static tree type_main_variant PARAMS ((tree));
3403 static int is_tagged_type PARAMS ((tree));
3404 static const char *dwarf_tag_name PARAMS ((unsigned));
3405 static const char *dwarf_attr_name PARAMS ((unsigned));
3406 static const char *dwarf_form_name PARAMS ((unsigned));
3408 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3410 static tree decl_ultimate_origin PARAMS ((tree));
3411 static tree block_ultimate_origin PARAMS ((tree));
3412 static tree decl_class_context PARAMS ((tree));
3413 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3414 static void add_AT_flag PARAMS ((dw_die_ref,
3415 enum dwarf_attribute,
3417 static void add_AT_int PARAMS ((dw_die_ref,
3418 enum dwarf_attribute, long));
3419 static void add_AT_unsigned PARAMS ((dw_die_ref,
3420 enum dwarf_attribute,
3422 static void add_AT_long_long PARAMS ((dw_die_ref,
3423 enum dwarf_attribute,
3426 static void add_AT_float PARAMS ((dw_die_ref,
3427 enum dwarf_attribute,
3429 static void add_AT_string PARAMS ((dw_die_ref,
3430 enum dwarf_attribute,
3432 static void add_AT_die_ref PARAMS ((dw_die_ref,
3433 enum dwarf_attribute,
3435 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3436 enum dwarf_attribute,
3438 static void add_AT_loc PARAMS ((dw_die_ref,
3439 enum dwarf_attribute,
3441 static void add_AT_loc_list PARAMS ((dw_die_ref,
3442 enum dwarf_attribute,
3444 static void add_AT_addr PARAMS ((dw_die_ref,
3445 enum dwarf_attribute,
3447 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3448 enum dwarf_attribute,
3450 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3451 enum dwarf_attribute,
3453 static void add_AT_offset PARAMS ((dw_die_ref,
3454 enum dwarf_attribute,
3456 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3457 enum dwarf_attribute));
3458 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3459 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3460 static const char *get_AT_string PARAMS ((dw_die_ref,
3461 enum dwarf_attribute));
3462 static int get_AT_flag PARAMS ((dw_die_ref,
3463 enum dwarf_attribute));
3464 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3465 enum dwarf_attribute));
3466 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3467 enum dwarf_attribute));
3468 static int is_c_family PARAMS ((void));
3469 static int is_java PARAMS ((void));
3470 static int is_fortran PARAMS ((void));
3471 static void remove_AT PARAMS ((dw_die_ref,
3472 enum dwarf_attribute));
3473 static void remove_children PARAMS ((dw_die_ref));
3474 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3475 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3476 static dw_die_ref lookup_type_die PARAMS ((tree));
3477 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3478 static dw_die_ref lookup_decl_die PARAMS ((tree));
3479 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3480 static void print_spaces PARAMS ((FILE *));
3481 static void print_die PARAMS ((dw_die_ref, FILE *));
3482 static void print_dwarf_line_table PARAMS ((FILE *));
3483 static void reverse_die_lists PARAMS ((dw_die_ref));
3484 static void reverse_all_dies PARAMS ((dw_die_ref));
3485 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3486 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3487 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3488 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3489 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3490 static void compute_section_prefix PARAMS ((dw_die_ref));
3491 static int is_type_die PARAMS ((dw_die_ref));
3492 static int is_comdat_die PARAMS ((dw_die_ref));
3493 static int is_symbol_die PARAMS ((dw_die_ref));
3494 static void assign_symbol_names PARAMS ((dw_die_ref));
3495 static void break_out_includes PARAMS ((dw_die_ref));
3496 static void add_sibling_attributes PARAMS ((dw_die_ref));
3497 static void build_abbrev_table PARAMS ((dw_die_ref));
3498 static void output_location_lists PARAMS ((dw_die_ref));
3499 static unsigned long size_of_string PARAMS ((const char *));
3500 static int constant_size PARAMS ((long unsigned));
3501 static unsigned long size_of_die PARAMS ((dw_die_ref));
3502 static void calc_die_sizes PARAMS ((dw_die_ref));
3503 static void mark_dies PARAMS ((dw_die_ref));
3504 static void unmark_dies PARAMS ((dw_die_ref));
3505 static unsigned long size_of_pubnames PARAMS ((void));
3506 static unsigned long size_of_aranges PARAMS ((void));
3507 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3508 static void output_value_format PARAMS ((dw_attr_ref));
3509 static void output_abbrev_section PARAMS ((void));
3510 static void output_die_symbol PARAMS ((dw_die_ref));
3511 static void output_die PARAMS ((dw_die_ref));
3512 static void output_compilation_unit_header PARAMS ((void));
3513 static void output_comp_unit PARAMS ((dw_die_ref));
3514 static const char *dwarf2_name PARAMS ((tree, int));
3515 static void add_pubname PARAMS ((tree, dw_die_ref));
3516 static void output_pubnames PARAMS ((void));
3517 static void add_arange PARAMS ((tree, dw_die_ref));
3518 static void output_aranges PARAMS ((void));
3519 static unsigned int add_ranges PARAMS ((tree));
3520 static void output_ranges PARAMS ((void));
3521 static void output_line_info PARAMS ((void));
3522 static void output_file_names PARAMS ((void));
3523 static dw_die_ref base_type_die PARAMS ((tree));
3524 static tree root_type PARAMS ((tree));
3525 static int is_base_type PARAMS ((tree));
3526 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3527 static int type_is_enum PARAMS ((tree));
3528 static unsigned int reg_number PARAMS ((rtx));
3529 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3530 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3531 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3532 static int is_based_loc PARAMS ((rtx));
3533 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3534 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3535 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3536 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3537 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3538 static tree field_type PARAMS ((tree));
3539 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3540 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3541 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3542 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3543 static void add_AT_location_description PARAMS ((dw_die_ref,
3544 enum dwarf_attribute, rtx));
3545 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3546 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3547 static rtx rtl_for_decl_location PARAMS ((tree));
3548 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3549 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3550 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3551 static void add_bound_info PARAMS ((dw_die_ref,
3552 enum dwarf_attribute, tree));
3553 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3554 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3555 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3556 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3557 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3558 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3559 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3560 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3561 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3562 static void push_decl_scope PARAMS ((tree));
3563 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3564 static void pop_decl_scope PARAMS ((void));
3565 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3567 static const char *type_tag PARAMS ((tree));
3568 static tree member_declared_type PARAMS ((tree));
3570 static const char *decl_start_label PARAMS ((tree));
3572 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3573 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3575 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3577 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3578 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3579 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3580 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3581 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3582 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3583 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3584 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3585 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3586 static void gen_label_die PARAMS ((tree, dw_die_ref));
3587 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3588 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3589 static void gen_field_die PARAMS ((tree, dw_die_ref));
3590 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3591 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3592 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3593 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3594 static void gen_member_die PARAMS ((tree, dw_die_ref));
3595 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3596 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3597 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3598 static void gen_type_die PARAMS ((tree, dw_die_ref));
3599 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3600 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3601 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3602 static int is_redundant_typedef PARAMS ((tree));
3603 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3604 static unsigned lookup_filename PARAMS ((const char *));
3605 static void init_file_table PARAMS ((void));
3606 static void add_incomplete_type PARAMS ((tree));
3607 static void retry_incomplete_types PARAMS ((void));
3608 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3609 static rtx save_rtx PARAMS ((rtx));
3610 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3611 static int file_info_cmp PARAMS ((const void *, const void *));
3612 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3613 const char *, const char *,
3614 const char *, unsigned));
3615 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3617 const char *, const char *, const char *));
3618 static void output_loc_list PARAMS ((dw_loc_list_ref));
3619 static char *gen_internal_sym PARAMS ((const char *));
3621 /* Section names used to hold DWARF debugging information. */
3622 #ifndef DEBUG_INFO_SECTION
3623 #define DEBUG_INFO_SECTION ".debug_info"
3625 #ifndef DEBUG_ABBREV_SECTION
3626 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3628 #ifndef DEBUG_ARANGES_SECTION
3629 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3631 #ifndef DEBUG_MACINFO_SECTION
3632 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3634 #ifndef DEBUG_LINE_SECTION
3635 #define DEBUG_LINE_SECTION ".debug_line"
3637 #ifndef DEBUG_LOC_SECTION
3638 #define DEBUG_LOC_SECTION ".debug_loc"
3640 #ifndef DEBUG_PUBNAMES_SECTION
3641 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3643 #ifndef DEBUG_STR_SECTION
3644 #define DEBUG_STR_SECTION ".debug_str"
3646 #ifndef DEBUG_RANGES_SECTION
3647 #define DEBUG_RANGES_SECTION ".debug_ranges"
3650 /* Standard ELF section names for compiled code and data. */
3651 #ifndef TEXT_SECTION
3652 #define TEXT_SECTION ".text"
3654 #ifndef DATA_SECTION
3655 #define DATA_SECTION ".data"
3658 #define BSS_SECTION ".bss"
3661 /* Labels we insert at beginning sections we can reference instead of
3662 the section names themselves. */
3664 #ifndef TEXT_SECTION_LABEL
3665 #define TEXT_SECTION_LABEL "Ltext"
3667 #ifndef DEBUG_LINE_SECTION_LABEL
3668 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3670 #ifndef DEBUG_INFO_SECTION_LABEL
3671 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3673 #ifndef DEBUG_ABBREV_SECTION_LABEL
3674 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3676 #ifndef DEBUG_LOC_SECTION_LABEL
3677 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3679 #ifndef DEBUG_MACINFO_SECTION_LABEL
3680 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3683 /* Definitions of defaults for formats and names of various special
3684 (artificial) labels which may be generated within this file (when the -g
3685 options is used and DWARF_DEBUGGING_INFO is in effect.
3686 If necessary, these may be overridden from within the tm.h file, but
3687 typically, overriding these defaults is unnecessary. */
3689 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3690 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3691 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3692 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3693 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3694 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3695 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3696 #ifndef TEXT_END_LABEL
3697 #define TEXT_END_LABEL "Letext"
3699 #ifndef DATA_END_LABEL
3700 #define DATA_END_LABEL "Ledata"
3702 #ifndef BSS_END_LABEL
3703 #define BSS_END_LABEL "Lebss"
3705 #ifndef BLOCK_BEGIN_LABEL
3706 #define BLOCK_BEGIN_LABEL "LBB"
3708 #ifndef BLOCK_END_LABEL
3709 #define BLOCK_END_LABEL "LBE"
3711 #ifndef BODY_BEGIN_LABEL
3712 #define BODY_BEGIN_LABEL "Lbb"
3714 #ifndef BODY_END_LABEL
3715 #define BODY_END_LABEL "Lbe"
3717 #ifndef LINE_CODE_LABEL
3718 #define LINE_CODE_LABEL "LM"
3720 #ifndef SEPARATE_LINE_CODE_LABEL
3721 #define SEPARATE_LINE_CODE_LABEL "LSM"
3724 /* We allow a language front-end to designate a function that is to be
3725 called to "demangle" any name before it it put into a DIE. */
3727 static const char *(*demangle_name_func) PARAMS ((const char *));
3730 dwarf2out_set_demangle_name_func (func)
3731 const char *(*func) PARAMS ((const char *));
3733 demangle_name_func = func;
3736 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3737 that means adding it to used_rtx_varray. If not, that means making
3738 a copy on the permanent_obstack. */
3744 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3749 /* Test if rtl node points to a pseudo register. */
3755 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3756 || (GET_CODE (rtl) == SUBREG
3757 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3760 /* Return a reference to a type, with its const and volatile qualifiers
3764 type_main_variant (type)
3767 type = TYPE_MAIN_VARIANT (type);
3769 /* There really should be only one main variant among any group of variants
3770 of a given type (and all of the MAIN_VARIANT values for all members of
3771 the group should point to that one type) but sometimes the C front-end
3772 messes this up for array types, so we work around that bug here. */
3774 if (TREE_CODE (type) == ARRAY_TYPE)
3775 while (type != TYPE_MAIN_VARIANT (type))
3776 type = TYPE_MAIN_VARIANT (type);
3781 /* Return non-zero if the given type node represents a tagged type. */
3784 is_tagged_type (type)
3787 register enum tree_code code = TREE_CODE (type);
3789 return (code == RECORD_TYPE || code == UNION_TYPE
3790 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3793 /* Convert a DIE tag into its string name. */
3796 dwarf_tag_name (tag)
3797 register unsigned tag;
3801 case DW_TAG_padding:
3802 return "DW_TAG_padding";
3803 case DW_TAG_array_type:
3804 return "DW_TAG_array_type";
3805 case DW_TAG_class_type:
3806 return "DW_TAG_class_type";
3807 case DW_TAG_entry_point:
3808 return "DW_TAG_entry_point";
3809 case DW_TAG_enumeration_type:
3810 return "DW_TAG_enumeration_type";
3811 case DW_TAG_formal_parameter:
3812 return "DW_TAG_formal_parameter";
3813 case DW_TAG_imported_declaration:
3814 return "DW_TAG_imported_declaration";
3816 return "DW_TAG_label";
3817 case DW_TAG_lexical_block:
3818 return "DW_TAG_lexical_block";
3820 return "DW_TAG_member";
3821 case DW_TAG_pointer_type:
3822 return "DW_TAG_pointer_type";
3823 case DW_TAG_reference_type:
3824 return "DW_TAG_reference_type";
3825 case DW_TAG_compile_unit:
3826 return "DW_TAG_compile_unit";
3827 case DW_TAG_string_type:
3828 return "DW_TAG_string_type";
3829 case DW_TAG_structure_type:
3830 return "DW_TAG_structure_type";
3831 case DW_TAG_subroutine_type:
3832 return "DW_TAG_subroutine_type";
3833 case DW_TAG_typedef:
3834 return "DW_TAG_typedef";
3835 case DW_TAG_union_type:
3836 return "DW_TAG_union_type";
3837 case DW_TAG_unspecified_parameters:
3838 return "DW_TAG_unspecified_parameters";
3839 case DW_TAG_variant:
3840 return "DW_TAG_variant";
3841 case DW_TAG_common_block:
3842 return "DW_TAG_common_block";
3843 case DW_TAG_common_inclusion:
3844 return "DW_TAG_common_inclusion";
3845 case DW_TAG_inheritance:
3846 return "DW_TAG_inheritance";
3847 case DW_TAG_inlined_subroutine:
3848 return "DW_TAG_inlined_subroutine";
3850 return "DW_TAG_module";
3851 case DW_TAG_ptr_to_member_type:
3852 return "DW_TAG_ptr_to_member_type";
3853 case DW_TAG_set_type:
3854 return "DW_TAG_set_type";
3855 case DW_TAG_subrange_type:
3856 return "DW_TAG_subrange_type";
3857 case DW_TAG_with_stmt:
3858 return "DW_TAG_with_stmt";
3859 case DW_TAG_access_declaration:
3860 return "DW_TAG_access_declaration";
3861 case DW_TAG_base_type:
3862 return "DW_TAG_base_type";
3863 case DW_TAG_catch_block:
3864 return "DW_TAG_catch_block";
3865 case DW_TAG_const_type:
3866 return "DW_TAG_const_type";
3867 case DW_TAG_constant:
3868 return "DW_TAG_constant";
3869 case DW_TAG_enumerator:
3870 return "DW_TAG_enumerator";
3871 case DW_TAG_file_type:
3872 return "DW_TAG_file_type";
3874 return "DW_TAG_friend";
3875 case DW_TAG_namelist:
3876 return "DW_TAG_namelist";
3877 case DW_TAG_namelist_item:
3878 return "DW_TAG_namelist_item";
3879 case DW_TAG_packed_type:
3880 return "DW_TAG_packed_type";
3881 case DW_TAG_subprogram:
3882 return "DW_TAG_subprogram";
3883 case DW_TAG_template_type_param:
3884 return "DW_TAG_template_type_param";
3885 case DW_TAG_template_value_param:
3886 return "DW_TAG_template_value_param";
3887 case DW_TAG_thrown_type:
3888 return "DW_TAG_thrown_type";
3889 case DW_TAG_try_block:
3890 return "DW_TAG_try_block";
3891 case DW_TAG_variant_part:
3892 return "DW_TAG_variant_part";
3893 case DW_TAG_variable:
3894 return "DW_TAG_variable";
3895 case DW_TAG_volatile_type:
3896 return "DW_TAG_volatile_type";
3897 case DW_TAG_MIPS_loop:
3898 return "DW_TAG_MIPS_loop";
3899 case DW_TAG_format_label:
3900 return "DW_TAG_format_label";
3901 case DW_TAG_function_template:
3902 return "DW_TAG_function_template";
3903 case DW_TAG_class_template:
3904 return "DW_TAG_class_template";
3905 case DW_TAG_GNU_BINCL:
3906 return "DW_TAG_GNU_BINCL";
3907 case DW_TAG_GNU_EINCL:
3908 return "DW_TAG_GNU_EINCL";
3910 return "DW_TAG_<unknown>";
3914 /* Convert a DWARF attribute code into its string name. */
3917 dwarf_attr_name (attr)
3918 register unsigned attr;
3923 return "DW_AT_sibling";
3924 case DW_AT_location:
3925 return "DW_AT_location";
3927 return "DW_AT_name";
3928 case DW_AT_ordering:
3929 return "DW_AT_ordering";
3930 case DW_AT_subscr_data:
3931 return "DW_AT_subscr_data";
3932 case DW_AT_byte_size:
3933 return "DW_AT_byte_size";
3934 case DW_AT_bit_offset:
3935 return "DW_AT_bit_offset";
3936 case DW_AT_bit_size:
3937 return "DW_AT_bit_size";
3938 case DW_AT_element_list:
3939 return "DW_AT_element_list";
3940 case DW_AT_stmt_list:
3941 return "DW_AT_stmt_list";
3943 return "DW_AT_low_pc";
3945 return "DW_AT_high_pc";
3946 case DW_AT_language:
3947 return "DW_AT_language";
3949 return "DW_AT_member";
3951 return "DW_AT_discr";
3952 case DW_AT_discr_value:
3953 return "DW_AT_discr_value";
3954 case DW_AT_visibility:
3955 return "DW_AT_visibility";
3957 return "DW_AT_import";
3958 case DW_AT_string_length:
3959 return "DW_AT_string_length";
3960 case DW_AT_common_reference:
3961 return "DW_AT_common_reference";
3962 case DW_AT_comp_dir:
3963 return "DW_AT_comp_dir";
3964 case DW_AT_const_value:
3965 return "DW_AT_const_value";
3966 case DW_AT_containing_type:
3967 return "DW_AT_containing_type";
3968 case DW_AT_default_value:
3969 return "DW_AT_default_value";
3971 return "DW_AT_inline";
3972 case DW_AT_is_optional:
3973 return "DW_AT_is_optional";
3974 case DW_AT_lower_bound:
3975 return "DW_AT_lower_bound";
3976 case DW_AT_producer:
3977 return "DW_AT_producer";
3978 case DW_AT_prototyped:
3979 return "DW_AT_prototyped";
3980 case DW_AT_return_addr:
3981 return "DW_AT_return_addr";
3982 case DW_AT_start_scope:
3983 return "DW_AT_start_scope";
3984 case DW_AT_stride_size:
3985 return "DW_AT_stride_size";
3986 case DW_AT_upper_bound:
3987 return "DW_AT_upper_bound";
3988 case DW_AT_abstract_origin:
3989 return "DW_AT_abstract_origin";
3990 case DW_AT_accessibility:
3991 return "DW_AT_accessibility";
3992 case DW_AT_address_class:
3993 return "DW_AT_address_class";
3994 case DW_AT_artificial:
3995 return "DW_AT_artificial";
3996 case DW_AT_base_types:
3997 return "DW_AT_base_types";
3998 case DW_AT_calling_convention:
3999 return "DW_AT_calling_convention";
4001 return "DW_AT_count";
4002 case DW_AT_data_member_location:
4003 return "DW_AT_data_member_location";
4004 case DW_AT_decl_column:
4005 return "DW_AT_decl_column";
4006 case DW_AT_decl_file:
4007 return "DW_AT_decl_file";
4008 case DW_AT_decl_line:
4009 return "DW_AT_decl_line";
4010 case DW_AT_declaration:
4011 return "DW_AT_declaration";
4012 case DW_AT_discr_list:
4013 return "DW_AT_discr_list";
4014 case DW_AT_encoding:
4015 return "DW_AT_encoding";
4016 case DW_AT_external:
4017 return "DW_AT_external";
4018 case DW_AT_frame_base:
4019 return "DW_AT_frame_base";
4021 return "DW_AT_friend";
4022 case DW_AT_identifier_case:
4023 return "DW_AT_identifier_case";
4024 case DW_AT_macro_info:
4025 return "DW_AT_macro_info";
4026 case DW_AT_namelist_items:
4027 return "DW_AT_namelist_items";
4028 case DW_AT_priority:
4029 return "DW_AT_priority";
4031 return "DW_AT_segment";
4032 case DW_AT_specification:
4033 return "DW_AT_specification";
4034 case DW_AT_static_link:
4035 return "DW_AT_static_link";
4037 return "DW_AT_type";
4038 case DW_AT_use_location:
4039 return "DW_AT_use_location";
4040 case DW_AT_variable_parameter:
4041 return "DW_AT_variable_parameter";
4042 case DW_AT_virtuality:
4043 return "DW_AT_virtuality";
4044 case DW_AT_vtable_elem_location:
4045 return "DW_AT_vtable_elem_location";
4047 case DW_AT_allocated:
4048 return "DW_AT_allocated";
4049 case DW_AT_associated:
4050 return "DW_AT_associated";
4051 case DW_AT_data_location:
4052 return "DW_AT_data_location";
4054 return "DW_AT_stride";
4055 case DW_AT_entry_pc:
4056 return "DW_AT_entry_pc";
4057 case DW_AT_use_UTF8:
4058 return "DW_AT_use_UTF8";
4059 case DW_AT_extension:
4060 return "DW_AT_extension";
4062 return "DW_AT_ranges";
4063 case DW_AT_trampoline:
4064 return "DW_AT_trampoline";
4065 case DW_AT_call_column:
4066 return "DW_AT_call_column";
4067 case DW_AT_call_file:
4068 return "DW_AT_call_file";
4069 case DW_AT_call_line:
4070 return "DW_AT_call_line";
4072 case DW_AT_MIPS_fde:
4073 return "DW_AT_MIPS_fde";
4074 case DW_AT_MIPS_loop_begin:
4075 return "DW_AT_MIPS_loop_begin";
4076 case DW_AT_MIPS_tail_loop_begin:
4077 return "DW_AT_MIPS_tail_loop_begin";
4078 case DW_AT_MIPS_epilog_begin:
4079 return "DW_AT_MIPS_epilog_begin";
4080 case DW_AT_MIPS_loop_unroll_factor:
4081 return "DW_AT_MIPS_loop_unroll_factor";
4082 case DW_AT_MIPS_software_pipeline_depth:
4083 return "DW_AT_MIPS_software_pipeline_depth";
4084 case DW_AT_MIPS_linkage_name:
4085 return "DW_AT_MIPS_linkage_name";
4086 case DW_AT_MIPS_stride:
4087 return "DW_AT_MIPS_stride";
4088 case DW_AT_MIPS_abstract_name:
4089 return "DW_AT_MIPS_abstract_name";
4090 case DW_AT_MIPS_clone_origin:
4091 return "DW_AT_MIPS_clone_origin";
4092 case DW_AT_MIPS_has_inlines:
4093 return "DW_AT_MIPS_has_inlines";
4095 case DW_AT_sf_names:
4096 return "DW_AT_sf_names";
4097 case DW_AT_src_info:
4098 return "DW_AT_src_info";
4099 case DW_AT_mac_info:
4100 return "DW_AT_mac_info";
4101 case DW_AT_src_coords:
4102 return "DW_AT_src_coords";
4103 case DW_AT_body_begin:
4104 return "DW_AT_body_begin";
4105 case DW_AT_body_end:
4106 return "DW_AT_body_end";
4108 return "DW_AT_<unknown>";
4112 /* Convert a DWARF value form code into its string name. */
4115 dwarf_form_name (form)
4116 register unsigned form;
4121 return "DW_FORM_addr";
4122 case DW_FORM_block2:
4123 return "DW_FORM_block2";
4124 case DW_FORM_block4:
4125 return "DW_FORM_block4";
4127 return "DW_FORM_data2";
4129 return "DW_FORM_data4";
4131 return "DW_FORM_data8";
4132 case DW_FORM_string:
4133 return "DW_FORM_string";
4135 return "DW_FORM_block";
4136 case DW_FORM_block1:
4137 return "DW_FORM_block1";
4139 return "DW_FORM_data1";
4141 return "DW_FORM_flag";
4143 return "DW_FORM_sdata";
4145 return "DW_FORM_strp";
4147 return "DW_FORM_udata";
4148 case DW_FORM_ref_addr:
4149 return "DW_FORM_ref_addr";
4151 return "DW_FORM_ref1";
4153 return "DW_FORM_ref2";
4155 return "DW_FORM_ref4";
4157 return "DW_FORM_ref8";
4158 case DW_FORM_ref_udata:
4159 return "DW_FORM_ref_udata";
4160 case DW_FORM_indirect:
4161 return "DW_FORM_indirect";
4163 return "DW_FORM_<unknown>";
4167 /* Convert a DWARF type code into its string name. */
4171 dwarf_type_encoding_name (enc)
4172 register unsigned enc;
4176 case DW_ATE_address:
4177 return "DW_ATE_address";
4178 case DW_ATE_boolean:
4179 return "DW_ATE_boolean";
4180 case DW_ATE_complex_float:
4181 return "DW_ATE_complex_float";
4183 return "DW_ATE_float";
4185 return "DW_ATE_signed";
4186 case DW_ATE_signed_char:
4187 return "DW_ATE_signed_char";
4188 case DW_ATE_unsigned:
4189 return "DW_ATE_unsigned";
4190 case DW_ATE_unsigned_char:
4191 return "DW_ATE_unsigned_char";
4193 return "DW_ATE_<unknown>";
4198 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4199 instance of an inlined instance of a decl which is local to an inline
4200 function, so we have to trace all of the way back through the origin chain
4201 to find out what sort of node actually served as the original seed for the
4205 decl_ultimate_origin (decl)
4208 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4209 nodes in the function to point to themselves; ignore that if
4210 we're trying to output the abstract instance of this function. */
4211 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4214 #ifdef ENABLE_CHECKING
4215 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4216 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4217 most distant ancestor, this should never happen. */
4221 return DECL_ABSTRACT_ORIGIN (decl);
4224 /* Determine the "ultimate origin" of a block. The block may be an inlined
4225 instance of an inlined instance of a block which is local to an inline
4226 function, so we have to trace all of the way back through the origin chain
4227 to find out what sort of node actually served as the original seed for the
4231 block_ultimate_origin (block)
4232 register tree block;
4234 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4236 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4237 nodes in the function to point to themselves; ignore that if
4238 we're trying to output the abstract instance of this function. */
4239 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4242 if (immediate_origin == NULL_TREE)
4246 register tree ret_val;
4247 register tree lookahead = immediate_origin;
4251 ret_val = lookahead;
4252 lookahead = (TREE_CODE (ret_val) == BLOCK)
4253 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4256 while (lookahead != NULL && lookahead != ret_val);
4262 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4263 of a virtual function may refer to a base class, so we check the 'this'
4267 decl_class_context (decl)
4270 tree context = NULL_TREE;
4272 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4273 context = DECL_CONTEXT (decl);
4275 context = TYPE_MAIN_VARIANT
4276 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4278 if (context && !TYPE_P (context))
4279 context = NULL_TREE;
4284 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4285 addition order, and correct that in reverse_all_dies. */
4288 add_dwarf_attr (die, attr)
4289 register dw_die_ref die;
4290 register dw_attr_ref attr;
4292 if (die != NULL && attr != NULL)
4294 attr->dw_attr_next = die->die_attr;
4295 die->die_attr = attr;
4299 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4300 static inline dw_val_class
4304 return a->dw_attr_val.val_class;
4307 /* Add a flag value attribute to a DIE. */
4310 add_AT_flag (die, attr_kind, flag)
4311 register dw_die_ref die;
4312 register enum dwarf_attribute attr_kind;
4313 register unsigned flag;
4315 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4317 attr->dw_attr_next = NULL;
4318 attr->dw_attr = attr_kind;
4319 attr->dw_attr_val.val_class = dw_val_class_flag;
4320 attr->dw_attr_val.v.val_flag = flag;
4321 add_dwarf_attr (die, attr);
4324 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4325 static inline unsigned
4327 register dw_attr_ref a;
4329 if (a && AT_class (a) == dw_val_class_flag)
4330 return a->dw_attr_val.v.val_flag;
4335 /* Add a signed integer attribute value to a DIE. */
4338 add_AT_int (die, attr_kind, int_val)
4339 register dw_die_ref die;
4340 register enum dwarf_attribute attr_kind;
4341 register long int int_val;
4343 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4345 attr->dw_attr_next = NULL;
4346 attr->dw_attr = attr_kind;
4347 attr->dw_attr_val.val_class = dw_val_class_const;
4348 attr->dw_attr_val.v.val_int = int_val;
4349 add_dwarf_attr (die, attr);
4352 static inline long int AT_int PARAMS ((dw_attr_ref));
4353 static inline long int
4355 register dw_attr_ref a;
4357 if (a && AT_class (a) == dw_val_class_const)
4358 return a->dw_attr_val.v.val_int;
4363 /* Add an unsigned integer attribute value to a DIE. */
4366 add_AT_unsigned (die, attr_kind, unsigned_val)
4367 register dw_die_ref die;
4368 register enum dwarf_attribute attr_kind;
4369 register unsigned long unsigned_val;
4371 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4373 attr->dw_attr_next = NULL;
4374 attr->dw_attr = attr_kind;
4375 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4376 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4377 add_dwarf_attr (die, attr);
4380 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4381 static inline unsigned long
4383 register dw_attr_ref a;
4385 if (a && AT_class (a) == dw_val_class_unsigned_const)
4386 return a->dw_attr_val.v.val_unsigned;
4391 /* Add an unsigned double integer attribute value to a DIE. */
4394 add_AT_long_long (die, attr_kind, val_hi, val_low)
4395 register dw_die_ref die;
4396 register enum dwarf_attribute attr_kind;
4397 register unsigned long val_hi;
4398 register unsigned long val_low;
4400 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4402 attr->dw_attr_next = NULL;
4403 attr->dw_attr = attr_kind;
4404 attr->dw_attr_val.val_class = dw_val_class_long_long;
4405 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4406 attr->dw_attr_val.v.val_long_long.low = val_low;
4407 add_dwarf_attr (die, attr);
4410 /* Add a floating point attribute value to a DIE and return it. */
4413 add_AT_float (die, attr_kind, length, array)
4414 register dw_die_ref die;
4415 register enum dwarf_attribute attr_kind;
4416 register unsigned length;
4417 register long *array;
4419 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4421 attr->dw_attr_next = NULL;
4422 attr->dw_attr = attr_kind;
4423 attr->dw_attr_val.val_class = dw_val_class_float;
4424 attr->dw_attr_val.v.val_float.length = length;
4425 attr->dw_attr_val.v.val_float.array = array;
4426 add_dwarf_attr (die, attr);
4429 /* Add a string attribute value to a DIE. */
4432 add_AT_string (die, attr_kind, str)
4433 register dw_die_ref die;
4434 register enum dwarf_attribute attr_kind;
4435 register const char *str;
4437 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4439 attr->dw_attr_next = NULL;
4440 attr->dw_attr = attr_kind;
4441 attr->dw_attr_val.val_class = dw_val_class_str;
4442 attr->dw_attr_val.v.val_str = xstrdup (str);
4443 add_dwarf_attr (die, attr);
4446 static inline const char *AT_string PARAMS ((dw_attr_ref));
4447 static inline const char *
4449 register dw_attr_ref a;
4451 if (a && AT_class (a) == dw_val_class_str)
4452 return a->dw_attr_val.v.val_str;
4457 /* Add a DIE reference attribute value to a DIE. */
4460 add_AT_die_ref (die, attr_kind, targ_die)
4461 register dw_die_ref die;
4462 register enum dwarf_attribute attr_kind;
4463 register dw_die_ref targ_die;
4465 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4467 attr->dw_attr_next = NULL;
4468 attr->dw_attr = attr_kind;
4469 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4470 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4471 attr->dw_attr_val.v.val_die_ref.external = 0;
4472 add_dwarf_attr (die, attr);
4475 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4476 static inline dw_die_ref
4478 register dw_attr_ref a;
4480 if (a && AT_class (a) == dw_val_class_die_ref)
4481 return a->dw_attr_val.v.val_die_ref.die;
4486 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4489 register dw_attr_ref a;
4491 if (a && AT_class (a) == dw_val_class_die_ref)
4492 return a->dw_attr_val.v.val_die_ref.external;
4497 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4499 set_AT_ref_external (a, i)
4500 register dw_attr_ref a;
4503 if (a && AT_class (a) == dw_val_class_die_ref)
4504 a->dw_attr_val.v.val_die_ref.external = i;
4509 /* Add an FDE reference attribute value to a DIE. */
4512 add_AT_fde_ref (die, attr_kind, targ_fde)
4513 register dw_die_ref die;
4514 register enum dwarf_attribute attr_kind;
4515 register unsigned targ_fde;
4517 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4519 attr->dw_attr_next = NULL;
4520 attr->dw_attr = attr_kind;
4521 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4522 attr->dw_attr_val.v.val_fde_index = targ_fde;
4523 add_dwarf_attr (die, attr);
4526 /* Add a location description attribute value to a DIE. */
4529 add_AT_loc (die, attr_kind, loc)
4530 register dw_die_ref die;
4531 register enum dwarf_attribute attr_kind;
4532 register dw_loc_descr_ref loc;
4534 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4536 attr->dw_attr_next = NULL;
4537 attr->dw_attr = attr_kind;
4538 attr->dw_attr_val.val_class = dw_val_class_loc;
4539 attr->dw_attr_val.v.val_loc = loc;
4540 add_dwarf_attr (die, attr);
4543 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4544 static inline dw_loc_descr_ref
4546 register dw_attr_ref a;
4548 if (a && AT_class (a) == dw_val_class_loc)
4549 return a->dw_attr_val.v.val_loc;
4555 add_AT_loc_list (die, attr_kind, loc_list)
4556 register dw_die_ref die;
4557 register enum dwarf_attribute attr_kind;
4558 register dw_loc_list_ref loc_list;
4560 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4562 attr->dw_attr_next = NULL;
4563 attr->dw_attr = attr_kind;
4564 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4565 attr->dw_attr_val.v.val_loc_list = loc_list;
4566 add_dwarf_attr (die, attr);
4567 have_location_lists = 1;
4570 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
4572 static inline dw_loc_list_ref
4574 register dw_attr_ref a;
4576 if (a && AT_class (a) == dw_val_class_loc_list)
4577 return a->dw_attr_val.v.val_loc_list;
4582 /* Add an address constant attribute value to a DIE. */
4585 add_AT_addr (die, attr_kind, addr)
4586 register dw_die_ref die;
4587 register enum dwarf_attribute attr_kind;
4590 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4592 attr->dw_attr_next = NULL;
4593 attr->dw_attr = attr_kind;
4594 attr->dw_attr_val.val_class = dw_val_class_addr;
4595 attr->dw_attr_val.v.val_addr = addr;
4596 add_dwarf_attr (die, attr);
4599 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4602 register dw_attr_ref a;
4604 if (a && AT_class (a) == dw_val_class_addr)
4605 return a->dw_attr_val.v.val_addr;
4610 /* Add a label identifier attribute value to a DIE. */
4613 add_AT_lbl_id (die, attr_kind, lbl_id)
4614 register dw_die_ref die;
4615 register enum dwarf_attribute attr_kind;
4616 register const char *lbl_id;
4618 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4620 attr->dw_attr_next = NULL;
4621 attr->dw_attr = attr_kind;
4622 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4623 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4624 add_dwarf_attr (die, attr);
4627 /* Add a section offset attribute value to a DIE. */
4630 add_AT_lbl_offset (die, attr_kind, label)
4631 register dw_die_ref die;
4632 register enum dwarf_attribute attr_kind;
4633 register const char *label;
4635 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4637 attr->dw_attr_next = NULL;
4638 attr->dw_attr = attr_kind;
4639 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4640 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4641 add_dwarf_attr (die, attr);
4644 /* Add an offset attribute value to a DIE. */
4647 add_AT_offset (die, attr_kind, offset)
4648 register dw_die_ref die;
4649 register enum dwarf_attribute attr_kind;
4650 register unsigned long offset;
4652 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4654 attr->dw_attr_next = NULL;
4655 attr->dw_attr = attr_kind;
4656 attr->dw_attr_val.val_class = dw_val_class_offset;
4657 attr->dw_attr_val.v.val_offset = offset;
4658 add_dwarf_attr (die, attr);
4661 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4662 static inline const char *
4664 register dw_attr_ref a;
4666 if (a && (AT_class (a) == dw_val_class_lbl_id
4667 || AT_class (a) == dw_val_class_lbl_offset))
4668 return a->dw_attr_val.v.val_lbl_id;
4673 /* Get the attribute of type attr_kind. */
4675 static inline dw_attr_ref
4676 get_AT (die, attr_kind)
4677 register dw_die_ref die;
4678 register enum dwarf_attribute attr_kind;
4680 register dw_attr_ref a;
4681 register dw_die_ref spec = NULL;
4685 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4687 if (a->dw_attr == attr_kind)
4690 if (a->dw_attr == DW_AT_specification
4691 || a->dw_attr == DW_AT_abstract_origin)
4696 return get_AT (spec, attr_kind);
4702 /* Return the "low pc" attribute value, typically associated with
4703 a subprogram DIE. Return null if the "low pc" attribute is
4704 either not prsent, or if it cannot be represented as an
4705 assembler label identifier. */
4707 static inline const char *
4709 register dw_die_ref die;
4711 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4712 return a ? AT_lbl (a) : NULL;
4715 /* Return the "high pc" attribute value, typically associated with
4716 a subprogram DIE. Return null if the "high pc" attribute is
4717 either not prsent, or if it cannot be represented as an
4718 assembler label identifier. */
4720 static inline const char *
4722 register dw_die_ref die;
4724 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4725 return a ? AT_lbl (a) : NULL;
4728 /* Return the value of the string attribute designated by ATTR_KIND, or
4729 NULL if it is not present. */
4731 static inline const char *
4732 get_AT_string (die, attr_kind)
4733 register dw_die_ref die;
4734 register enum dwarf_attribute attr_kind;
4736 register dw_attr_ref a = get_AT (die, attr_kind);
4737 return a ? AT_string (a) : NULL;
4740 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4741 if it is not present. */
4744 get_AT_flag (die, attr_kind)
4745 register dw_die_ref die;
4746 register enum dwarf_attribute attr_kind;
4748 register dw_attr_ref a = get_AT (die, attr_kind);
4749 return a ? AT_flag (a) : 0;
4752 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4753 if it is not present. */
4755 static inline unsigned
4756 get_AT_unsigned (die, attr_kind)
4757 register dw_die_ref die;
4758 register enum dwarf_attribute attr_kind;
4760 register dw_attr_ref a = get_AT (die, attr_kind);
4761 return a ? AT_unsigned (a) : 0;
4764 static inline dw_die_ref
4765 get_AT_ref (die, attr_kind)
4767 register enum dwarf_attribute attr_kind;
4769 register dw_attr_ref a = get_AT (die, attr_kind);
4770 return a ? AT_ref (a) : NULL;
4776 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4778 return (lang == DW_LANG_C || lang == DW_LANG_C89
4779 || lang == DW_LANG_C_plus_plus);
4785 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4787 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4793 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4795 return (lang == DW_LANG_Java);
4798 /* Free up the memory used by A. */
4800 static inline void free_AT PARAMS ((dw_attr_ref));
4805 switch (AT_class (a))
4807 case dw_val_class_str:
4808 case dw_val_class_lbl_id:
4809 case dw_val_class_lbl_offset:
4810 free (a->dw_attr_val.v.val_str);
4813 case dw_val_class_float:
4814 free (a->dw_attr_val.v.val_float.array);
4824 /* Remove the specified attribute if present. */
4827 remove_AT (die, attr_kind)
4828 register dw_die_ref die;
4829 register enum dwarf_attribute attr_kind;
4831 register dw_attr_ref *p;
4832 register dw_attr_ref removed = NULL;
4836 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4837 if ((*p)->dw_attr == attr_kind)
4840 *p = (*p)->dw_attr_next;
4849 /* Free up the memory used by DIE. */
4851 static inline void free_die PARAMS ((dw_die_ref));
4856 remove_children (die);
4860 /* Discard the children of this DIE. */
4863 remove_children (die)
4864 register dw_die_ref die;
4866 register dw_die_ref child_die = die->die_child;
4868 die->die_child = NULL;
4870 while (child_die != NULL)
4872 register dw_die_ref tmp_die = child_die;
4873 register dw_attr_ref a;
4875 child_die = child_die->die_sib;
4877 for (a = tmp_die->die_attr; a != NULL;)
4879 register dw_attr_ref tmp_a = a;
4881 a = a->dw_attr_next;
4889 /* Add a child DIE below its parent. We build the lists up in reverse
4890 addition order, and correct that in reverse_all_dies. */
4893 add_child_die (die, child_die)
4894 register dw_die_ref die;
4895 register dw_die_ref child_die;
4897 if (die != NULL && child_die != NULL)
4899 if (die == child_die)
4901 child_die->die_parent = die;
4902 child_die->die_sib = die->die_child;
4903 die->die_child = child_die;
4907 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4908 is the specification, to the front of PARENT's list of children. */
4911 splice_child_die (parent, child)
4912 dw_die_ref parent, child;
4916 /* We want the declaration DIE from inside the class, not the
4917 specification DIE at toplevel. */
4918 if (child->die_parent != parent)
4920 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4925 if (child->die_parent != parent
4926 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4929 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4932 *p = child->die_sib;
4936 child->die_sib = parent->die_child;
4937 parent->die_child = child;
4940 /* Return a pointer to a newly created DIE node. */
4942 static inline dw_die_ref
4943 new_die (tag_value, parent_die)
4944 register enum dwarf_tag tag_value;
4945 register dw_die_ref parent_die;
4947 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4949 die->die_tag = tag_value;
4951 if (parent_die != NULL)
4952 add_child_die (parent_die, die);
4955 limbo_die_node *limbo_node;
4957 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4958 limbo_node->die = die;
4959 limbo_node->next = limbo_die_list;
4960 limbo_die_list = limbo_node;
4966 /* Return the DIE associated with the given type specifier. */
4968 static inline dw_die_ref
4969 lookup_type_die (type)
4972 if (TREE_CODE (type) == VECTOR_TYPE)
4973 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4974 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4977 /* Equate a DIE to a given type specifier. */
4980 equate_type_number_to_die (type, type_die)
4982 register dw_die_ref type_die;
4984 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4987 /* Return the DIE associated with a given declaration. */
4989 static inline dw_die_ref
4990 lookup_decl_die (decl)
4993 register unsigned decl_id = DECL_UID (decl);
4995 return (decl_id < decl_die_table_in_use
4996 ? decl_die_table[decl_id] : NULL);
4999 /* Equate a DIE to a particular declaration. */
5002 equate_decl_number_to_die (decl, decl_die)
5004 register dw_die_ref decl_die;
5006 register unsigned decl_id = DECL_UID (decl);
5007 register unsigned num_allocated;
5009 if (decl_id >= decl_die_table_allocated)
5012 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5013 / DECL_DIE_TABLE_INCREMENT)
5014 * DECL_DIE_TABLE_INCREMENT;
5017 = (dw_die_ref *) xrealloc (decl_die_table,
5018 sizeof (dw_die_ref) * num_allocated);
5020 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5021 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5022 decl_die_table_allocated = num_allocated;
5025 if (decl_id >= decl_die_table_in_use)
5026 decl_die_table_in_use = (decl_id + 1);
5028 decl_die_table[decl_id] = decl_die;
5031 /* Keep track of the number of spaces used to indent the
5032 output of the debugging routines that print the structure of
5033 the DIE internal representation. */
5034 static int print_indent;
5036 /* Indent the line the number of spaces given by print_indent. */
5039 print_spaces (outfile)
5042 fprintf (outfile, "%*s", print_indent, "");
5045 /* Print the information associated with a given DIE, and its children.
5046 This routine is a debugging aid only. */
5049 print_die (die, outfile)
5053 register dw_attr_ref a;
5054 register dw_die_ref c;
5056 print_spaces (outfile);
5057 fprintf (outfile, "DIE %4lu: %s\n",
5058 die->die_offset, dwarf_tag_name (die->die_tag));
5059 print_spaces (outfile);
5060 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5061 fprintf (outfile, " offset: %lu\n", die->die_offset);
5063 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5065 print_spaces (outfile);
5066 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5068 switch (AT_class (a))
5070 case dw_val_class_addr:
5071 fprintf (outfile, "address");
5073 case dw_val_class_offset:
5074 fprintf (outfile, "offset");
5076 case dw_val_class_loc:
5077 fprintf (outfile, "location descriptor");
5079 case dw_val_class_loc_list:
5080 fprintf (outfile, "location list -> label:%s",
5081 AT_loc_list (a)->ll_symbol);
5083 case dw_val_class_const:
5084 fprintf (outfile, "%ld", AT_int (a));
5086 case dw_val_class_unsigned_const:
5087 fprintf (outfile, "%lu", AT_unsigned (a));
5089 case dw_val_class_long_long:
5090 fprintf (outfile, "constant (%lu,%lu)",
5091 a->dw_attr_val.v.val_long_long.hi,
5092 a->dw_attr_val.v.val_long_long.low);
5094 case dw_val_class_float:
5095 fprintf (outfile, "floating-point constant");
5097 case dw_val_class_flag:
5098 fprintf (outfile, "%u", AT_flag (a));
5100 case dw_val_class_die_ref:
5101 if (AT_ref (a) != NULL)
5103 if (AT_ref (a)->die_symbol)
5104 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5106 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5109 fprintf (outfile, "die -> <null>");
5111 case dw_val_class_lbl_id:
5112 case dw_val_class_lbl_offset:
5113 fprintf (outfile, "label: %s", AT_lbl (a));
5115 case dw_val_class_str:
5116 if (AT_string (a) != NULL)
5117 fprintf (outfile, "\"%s\"", AT_string (a));
5119 fprintf (outfile, "<null>");
5125 fprintf (outfile, "\n");
5128 if (die->die_child != NULL)
5131 for (c = die->die_child; c != NULL; c = c->die_sib)
5132 print_die (c, outfile);
5136 if (print_indent == 0)
5137 fprintf (outfile, "\n");
5140 /* Print the contents of the source code line number correspondence table.
5141 This routine is a debugging aid only. */
5144 print_dwarf_line_table (outfile)
5147 register unsigned i;
5148 register dw_line_info_ref line_info;
5150 fprintf (outfile, "\n\nDWARF source line information\n");
5151 for (i = 1; i < line_info_table_in_use; ++i)
5153 line_info = &line_info_table[i];
5154 fprintf (outfile, "%5d: ", i);
5155 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5156 fprintf (outfile, "%6ld", line_info->dw_line_num);
5157 fprintf (outfile, "\n");
5160 fprintf (outfile, "\n\n");
5163 /* Print the information collected for a given DIE. */
5166 debug_dwarf_die (die)
5169 print_die (die, stderr);
5172 /* Print all DWARF information collected for the compilation unit.
5173 This routine is a debugging aid only. */
5179 print_die (comp_unit_die, stderr);
5180 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5181 print_dwarf_line_table (stderr);
5184 /* We build up the lists of children and attributes by pushing new ones
5185 onto the beginning of the list. Reverse the lists for DIE so that
5186 they are in order of addition. */
5189 reverse_die_lists (die)
5190 register dw_die_ref die;
5192 register dw_die_ref c, cp, cn;
5193 register dw_attr_ref a, ap, an;
5195 for (a = die->die_attr, ap = 0; a; a = an)
5197 an = a->dw_attr_next;
5198 a->dw_attr_next = ap;
5203 for (c = die->die_child, cp = 0; c; c = cn)
5209 die->die_child = cp;
5212 /* reverse_die_lists only reverses the single die you pass it. Since
5213 we used to reverse all dies in add_sibling_attributes, which runs
5214 through all the dies, it would reverse all the dies. Now, however,
5215 since we don't call reverse_die_lists in add_sibling_attributes, we
5216 need a routine to recursively reverse all the dies. This is that
5220 reverse_all_dies (die)
5221 register dw_die_ref die;
5223 register dw_die_ref c;
5225 reverse_die_lists (die);
5227 for (c = die->die_child; c; c = c->die_sib)
5228 reverse_all_dies (c);
5231 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5232 the CU for the enclosing include file, if any. BINCL_DIE is the
5233 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5237 push_new_compile_unit (old_unit, bincl_die)
5238 dw_die_ref old_unit, bincl_die;
5240 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5241 dw_die_ref new_unit = gen_compile_unit_die (filename);
5242 new_unit->die_sib = old_unit;
5246 /* Close an include-file CU and reopen the enclosing one. */
5249 pop_compile_unit (old_unit)
5250 dw_die_ref old_unit;
5252 dw_die_ref new_unit = old_unit->die_sib;
5253 old_unit->die_sib = NULL;
5257 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5258 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5260 /* Calculate the checksum of a location expression. */
5263 loc_checksum (loc, ctx)
5264 dw_loc_descr_ref loc;
5265 struct md5_ctx *ctx;
5267 PROCESS (loc->dw_loc_opc);
5268 PROCESS (loc->dw_loc_oprnd1);
5269 PROCESS (loc->dw_loc_oprnd2);
5272 /* Calculate the checksum of an attribute. */
5275 attr_checksum (at, ctx)
5277 struct md5_ctx *ctx;
5279 dw_loc_descr_ref loc;
5282 PROCESS (at->dw_attr);
5284 /* We don't care about differences in file numbering. */
5285 if (at->dw_attr == DW_AT_decl_file
5286 /* Or that this was compiled with a different compiler snapshot; if
5287 the output is the same, that's what matters. */
5288 || at->dw_attr == DW_AT_producer)
5291 switch (AT_class (at))
5293 case dw_val_class_const:
5294 PROCESS (at->dw_attr_val.v.val_int);
5296 case dw_val_class_unsigned_const:
5297 PROCESS (at->dw_attr_val.v.val_unsigned);
5299 case dw_val_class_long_long:
5300 PROCESS (at->dw_attr_val.v.val_long_long);
5302 case dw_val_class_float:
5303 PROCESS (at->dw_attr_val.v.val_float);
5305 case dw_val_class_flag:
5306 PROCESS (at->dw_attr_val.v.val_flag);
5309 case dw_val_class_str:
5310 PROCESS_STRING (AT_string (at));
5313 case dw_val_class_addr:
5315 switch (GET_CODE (r))
5318 PROCESS_STRING (XSTR (r, 0));
5326 case dw_val_class_offset:
5327 PROCESS (at->dw_attr_val.v.val_offset);
5330 case dw_val_class_loc:
5331 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5332 loc_checksum (loc, ctx);
5335 case dw_val_class_die_ref:
5336 if (AT_ref (at)->die_offset)
5337 PROCESS (AT_ref (at)->die_offset);
5338 /* FIXME else use target die name or something. */
5340 case dw_val_class_fde_ref:
5341 case dw_val_class_lbl_id:
5342 case dw_val_class_lbl_offset:
5350 /* Calculate the checksum of a DIE. */
5353 die_checksum (die, ctx)
5355 struct md5_ctx *ctx;
5360 PROCESS (die->die_tag);
5362 for (a = die->die_attr; a; a = a->dw_attr_next)
5363 attr_checksum (a, ctx);
5365 for (c = die->die_child; c; c = c->die_sib)
5366 die_checksum (c, ctx);
5370 #undef PROCESS_STRING
5372 /* The prefix to attach to symbols on DIEs in the current comdat debug
5374 static char *comdat_symbol_id;
5376 /* The index of the current symbol within the current comdat CU. */
5377 static unsigned int comdat_symbol_number;
5379 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5380 children, and set comdat_symbol_id accordingly. */
5383 compute_section_prefix (unit_die)
5384 dw_die_ref unit_die;
5388 unsigned char checksum[16];
5391 md5_init_ctx (&ctx);
5392 die_checksum (unit_die, &ctx);
5393 md5_finish_ctx (&ctx, checksum);
5396 const char *p = lbasename (get_AT_string (unit_die, DW_AT_name));
5397 name = (char *) alloca (strlen (p) + 64);
5398 sprintf (name, "%s.", p);
5401 clean_symbol_name (name);
5404 char *p = name + strlen (name);
5405 for (i = 0; i < 4; ++i)
5407 sprintf (p, "%.2x", checksum[i]);
5412 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5413 comdat_symbol_number = 0;
5416 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5422 switch (die->die_tag)
5424 case DW_TAG_array_type:
5425 case DW_TAG_class_type:
5426 case DW_TAG_enumeration_type:
5427 case DW_TAG_pointer_type:
5428 case DW_TAG_reference_type:
5429 case DW_TAG_string_type:
5430 case DW_TAG_structure_type:
5431 case DW_TAG_subroutine_type:
5432 case DW_TAG_union_type:
5433 case DW_TAG_ptr_to_member_type:
5434 case DW_TAG_set_type:
5435 case DW_TAG_subrange_type:
5436 case DW_TAG_base_type:
5437 case DW_TAG_const_type:
5438 case DW_TAG_file_type:
5439 case DW_TAG_packed_type:
5440 case DW_TAG_volatile_type:
5447 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5448 Basically, we want to choose the bits that are likely to be shared between
5449 compilations (types) and leave out the bits that are specific to individual
5450 compilations (functions). */
5457 /* I think we want to leave base types and __vtbl_ptr_type in the
5458 main CU, as we do for stabs. The advantage is a greater
5459 likelihood of sharing between objects that don't include headers
5460 in the same order (and therefore would put the base types in a
5461 different comdat). jason 8/28/00 */
5462 if (c->die_tag == DW_TAG_base_type)
5465 if (c->die_tag == DW_TAG_pointer_type
5466 || c->die_tag == DW_TAG_reference_type
5467 || c->die_tag == DW_TAG_const_type
5468 || c->die_tag == DW_TAG_volatile_type)
5470 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5471 return t ? is_comdat_die (t) : 0;
5475 return is_type_die (c);
5478 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5479 compilation unit. */
5485 if (is_type_die (c))
5487 if (get_AT (c, DW_AT_declaration)
5488 && ! get_AT (c, DW_AT_specification))
5494 gen_internal_sym (prefix)
5498 static int label_num;
5499 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5500 return xstrdup (buf);
5503 /* Assign symbols to all worthy DIEs under DIE. */
5506 assign_symbol_names (die)
5507 register dw_die_ref die;
5509 register dw_die_ref c;
5511 if (is_symbol_die (die))
5513 if (comdat_symbol_id)
5515 char *p = alloca (strlen (comdat_symbol_id) + 64);
5516 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5517 comdat_symbol_id, comdat_symbol_number++);
5518 die->die_symbol = xstrdup (p);
5521 die->die_symbol = gen_internal_sym ("LDIE");
5524 for (c = die->die_child; c != NULL; c = c->die_sib)
5525 assign_symbol_names (c);
5528 /* Traverse the DIE (which is always comp_unit_die), and set up
5529 additional compilation units for each of the include files we see
5530 bracketed by BINCL/EINCL. */
5533 break_out_includes (die)
5534 register dw_die_ref die;
5537 register dw_die_ref unit = NULL;
5538 limbo_die_node *node;
5540 for (ptr = &(die->die_child); *ptr; )
5542 register dw_die_ref c = *ptr;
5544 if (c->die_tag == DW_TAG_GNU_BINCL
5545 || c->die_tag == DW_TAG_GNU_EINCL
5546 || (unit && is_comdat_die (c)))
5548 /* This DIE is for a secondary CU; remove it from the main one. */
5551 if (c->die_tag == DW_TAG_GNU_BINCL)
5553 unit = push_new_compile_unit (unit, c);
5556 else if (c->die_tag == DW_TAG_GNU_EINCL)
5558 unit = pop_compile_unit (unit);
5562 add_child_die (unit, c);
5566 /* Leave this DIE in the main CU. */
5567 ptr = &(c->die_sib);
5573 /* We can only use this in debugging, since the frontend doesn't check
5574 to make sure that we leave every include file we enter. */
5579 assign_symbol_names (die);
5580 for (node = limbo_die_list; node; node = node->next)
5582 compute_section_prefix (node->die);
5583 assign_symbol_names (node->die);
5587 /* Traverse the DIE and add a sibling attribute if it may have the
5588 effect of speeding up access to siblings. To save some space,
5589 avoid generating sibling attributes for DIE's without children. */
5592 add_sibling_attributes (die)
5593 register dw_die_ref die;
5595 register dw_die_ref c;
5597 if (die->die_tag != DW_TAG_compile_unit
5598 && die->die_sib && die->die_child != NULL)
5599 /* Add the sibling link to the front of the attribute list. */
5600 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5602 for (c = die->die_child; c != NULL; c = c->die_sib)
5603 add_sibling_attributes (c);
5606 /* Output all location lists for the DIE and it's children */
5608 output_location_lists (die)
5609 register dw_die_ref die;
5613 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5615 if (AT_class (d_attr) == dw_val_class_loc_list)
5617 output_loc_list (AT_loc_list (d_attr));
5620 for (c = die->die_child; c != NULL; c = c->die_sib)
5621 output_location_lists (c);
5624 /* The format of each DIE (and its attribute value pairs)
5625 is encoded in an abbreviation table. This routine builds the
5626 abbreviation table and assigns a unique abbreviation id for
5627 each abbreviation entry. The children of each die are visited
5631 build_abbrev_table (die)
5632 register dw_die_ref die;
5634 register unsigned long abbrev_id;
5635 register unsigned int n_alloc;
5636 register dw_die_ref c;
5637 register dw_attr_ref d_attr, a_attr;
5639 /* Scan the DIE references, and mark as external any that refer to
5640 DIEs from other CUs (i.e. those which are not marked). */
5641 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5643 if (AT_class (d_attr) == dw_val_class_die_ref
5644 && AT_ref (d_attr)->die_mark == 0)
5646 if (AT_ref (d_attr)->die_symbol == 0)
5648 set_AT_ref_external (d_attr, 1);
5652 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5654 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5656 if (abbrev->die_tag == die->die_tag)
5658 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5660 a_attr = abbrev->die_attr;
5661 d_attr = die->die_attr;
5663 while (a_attr != NULL && d_attr != NULL)
5665 if ((a_attr->dw_attr != d_attr->dw_attr)
5666 || (value_format (a_attr) != value_format (d_attr)))
5669 a_attr = a_attr->dw_attr_next;
5670 d_attr = d_attr->dw_attr_next;
5673 if (a_attr == NULL && d_attr == NULL)
5679 if (abbrev_id >= abbrev_die_table_in_use)
5681 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5683 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5685 = (dw_die_ref *) xrealloc (abbrev_die_table,
5686 sizeof (dw_die_ref) * n_alloc);
5688 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5689 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5690 abbrev_die_table_allocated = n_alloc;
5693 ++abbrev_die_table_in_use;
5694 abbrev_die_table[abbrev_id] = die;
5697 die->die_abbrev = abbrev_id;
5698 for (c = die->die_child; c != NULL; c = c->die_sib)
5699 build_abbrev_table (c);
5702 /* Return the size of a string, including the null byte.
5704 This used to treat backslashes as escapes, and hence they were not included
5705 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5706 which treats a backslash as a backslash, escaping it if necessary, and hence
5707 we must include them in the count. */
5709 static unsigned long
5710 size_of_string (str)
5711 register const char *str;
5713 return strlen (str) + 1;
5716 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5719 constant_size (value)
5720 long unsigned value;
5727 log = floor_log2 (value);
5730 log = 1 << (floor_log2 (log) + 1);
5735 /* Return the size of a DIE, as it is represented in the
5736 .debug_info section. */
5738 static unsigned long
5740 register dw_die_ref die;
5742 register unsigned long size = 0;
5743 register dw_attr_ref a;
5745 size += size_of_uleb128 (die->die_abbrev);
5746 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5748 switch (AT_class (a))
5750 case dw_val_class_addr:
5751 size += DWARF2_ADDR_SIZE;
5753 case dw_val_class_offset:
5754 size += DWARF_OFFSET_SIZE;
5756 case dw_val_class_loc:
5758 register unsigned long lsize = size_of_locs (AT_loc (a));
5761 size += constant_size (lsize);
5765 case dw_val_class_loc_list:
5766 size += DWARF_OFFSET_SIZE;
5768 case dw_val_class_const:
5769 size += size_of_sleb128 (AT_int (a));
5771 case dw_val_class_unsigned_const:
5772 size += constant_size (AT_unsigned (a));
5774 case dw_val_class_long_long:
5775 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5777 case dw_val_class_float:
5778 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5780 case dw_val_class_flag:
5783 case dw_val_class_die_ref:
5784 size += DWARF_OFFSET_SIZE;
5786 case dw_val_class_fde_ref:
5787 size += DWARF_OFFSET_SIZE;
5789 case dw_val_class_lbl_id:
5790 size += DWARF2_ADDR_SIZE;
5792 case dw_val_class_lbl_offset:
5793 size += DWARF_OFFSET_SIZE;
5795 case dw_val_class_str:
5796 size += size_of_string (AT_string (a));
5806 /* Size the debugging information associated with a given DIE.
5807 Visits the DIE's children recursively. Updates the global
5808 variable next_die_offset, on each time through. Uses the
5809 current value of next_die_offset to update the die_offset
5810 field in each DIE. */
5813 calc_die_sizes (die)
5816 register dw_die_ref c;
5817 die->die_offset = next_die_offset;
5818 next_die_offset += size_of_die (die);
5820 for (c = die->die_child; c != NULL; c = c->die_sib)
5823 if (die->die_child != NULL)
5824 /* Count the null byte used to terminate sibling lists. */
5825 next_die_offset += 1;
5828 /* Set the marks for a die and its children. We do this so
5829 that we know whether or not a reference needs to use FORM_ref_addr; only
5830 DIEs in the same CU will be marked. We used to clear out the offset
5831 and use that as the flag, but ran into ordering problems. */
5837 register dw_die_ref c;
5839 for (c = die->die_child; c; c = c->die_sib)
5843 /* Clear the marks for a die and its children. */
5849 register dw_die_ref c;
5851 for (c = die->die_child; c; c = c->die_sib)
5855 /* Return the size of the .debug_pubnames table generated for the
5856 compilation unit. */
5858 static unsigned long
5861 register unsigned long size;
5862 register unsigned i;
5864 size = DWARF_PUBNAMES_HEADER_SIZE;
5865 for (i = 0; i < pubname_table_in_use; ++i)
5867 register pubname_ref p = &pubname_table[i];
5868 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5871 size += DWARF_OFFSET_SIZE;
5875 /* Return the size of the information in the .debug_aranges section. */
5877 static unsigned long
5880 register unsigned long size;
5882 size = DWARF_ARANGES_HEADER_SIZE;
5884 /* Count the address/length pair for this compilation unit. */
5885 size += 2 * DWARF2_ADDR_SIZE;
5886 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5888 /* Count the two zero words used to terminated the address range table. */
5889 size += 2 * DWARF2_ADDR_SIZE;
5893 /* Select the encoding of an attribute value. */
5895 static enum dwarf_form
5899 switch (a->dw_attr_val.val_class)
5901 case dw_val_class_addr:
5902 return DW_FORM_addr;
5903 case dw_val_class_offset:
5904 if (DWARF_OFFSET_SIZE == 4)
5905 return DW_FORM_data4;
5906 if (DWARF_OFFSET_SIZE == 8)
5907 return DW_FORM_data8;
5909 case dw_val_class_loc_list:
5910 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
5911 .debug_loc section */
5912 return DW_FORM_data4;
5913 case dw_val_class_loc:
5914 switch (constant_size (size_of_locs (AT_loc (a))))
5917 return DW_FORM_block1;
5919 return DW_FORM_block2;
5923 case dw_val_class_const:
5924 return DW_FORM_sdata;
5925 case dw_val_class_unsigned_const:
5926 switch (constant_size (AT_unsigned (a)))
5929 return DW_FORM_data1;
5931 return DW_FORM_data2;
5933 return DW_FORM_data4;
5935 return DW_FORM_data8;
5939 case dw_val_class_long_long:
5940 return DW_FORM_block1;
5941 case dw_val_class_float:
5942 return DW_FORM_block1;
5943 case dw_val_class_flag:
5944 return DW_FORM_flag;
5945 case dw_val_class_die_ref:
5946 if (AT_ref_external (a))
5947 return DW_FORM_ref_addr;
5950 case dw_val_class_fde_ref:
5951 return DW_FORM_data;
5952 case dw_val_class_lbl_id:
5953 return DW_FORM_addr;
5954 case dw_val_class_lbl_offset:
5955 return DW_FORM_data;
5956 case dw_val_class_str:
5957 return DW_FORM_string;
5964 /* Output the encoding of an attribute value. */
5967 output_value_format (a)
5970 enum dwarf_form form = value_format (a);
5971 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
5974 /* Output the .debug_abbrev section which defines the DIE abbreviation
5978 output_abbrev_section ()
5980 unsigned long abbrev_id;
5983 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5985 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5987 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
5989 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
5990 dwarf_tag_name (abbrev->die_tag));
5992 if (abbrev->die_child != NULL)
5993 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
5995 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
5997 for (a_attr = abbrev->die_attr; a_attr != NULL;
5998 a_attr = a_attr->dw_attr_next)
6000 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6001 dwarf_attr_name (a_attr->dw_attr));
6002 output_value_format (a_attr);
6005 dw2_asm_output_data (1, 0, NULL);
6006 dw2_asm_output_data (1, 0, NULL);
6009 /* Terminate the table. */
6010 dw2_asm_output_data (1, 0, NULL);
6013 /* Output a symbol we can use to refer to this DIE from another CU. */
6016 output_die_symbol (die)
6017 register dw_die_ref die;
6019 char *sym = die->die_symbol;
6024 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6025 /* We make these global, not weak; if the target doesn't support
6026 .linkonce, it doesn't support combining the sections, so debugging
6028 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6029 ASM_OUTPUT_LABEL (asm_out_file, sym);
6032 /* Return a new location list, given the begin and end range, and the
6033 expression. gensym tells us whether to generate a new internal
6034 symbol for this location list node, which is done for the head of
6036 static inline dw_loc_list_ref
6037 new_loc_list (expr, begin, end, section, gensym)
6038 register dw_loc_descr_ref expr;
6039 register const char *begin;
6040 register const char *end;
6041 register const char *section;
6042 register unsigned gensym;
6044 register dw_loc_list_ref retlist
6045 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6046 retlist->begin = begin;
6048 retlist->expr = expr;
6049 retlist->section = section;
6051 retlist->ll_symbol = gen_internal_sym ("LLST");
6055 /* Add a location description expression to a location list */
6057 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6058 register dw_loc_list_ref *list_head;
6059 register dw_loc_descr_ref descr;
6060 register const char *begin;
6061 register const char *end;
6062 register const char *section;
6064 register dw_loc_list_ref *d;
6066 /* Find the end of the chain. */
6067 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6069 /* Add a new location list node to the list */
6070 *d = new_loc_list (descr, begin, end, section, 0);
6073 /* Output the location list given to us */
6075 output_loc_list (list_head)
6076 register dw_loc_list_ref list_head;
6078 register dw_loc_list_ref curr=list_head;
6079 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6081 /* ??? This shouldn't be needed now that we've forced the
6082 compilation unit base address to zero when there is code
6083 in more than one section. */
6084 if (strcmp (curr->section, ".text") == 0)
6086 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6087 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT)0,
6088 "Location list base address specifier fake entry");
6089 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6090 "Location list base address specifier base");
6092 for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
6095 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6096 "Location list begin address (%s)",
6097 list_head->ll_symbol);
6098 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6099 "Location list end address (%s)",
6100 list_head->ll_symbol);
6101 size = size_of_locs (curr->expr);
6103 /* Output the block length for this list of location operations. */
6104 dw2_asm_output_data (constant_size (size), size, "%s",
6105 "Location expression size");
6107 output_loc_sequence (curr->expr);
6109 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6110 "Location list terminator begin (%s)",
6111 list_head->ll_symbol);
6112 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6113 "Location list terminator end (%s)",
6114 list_head->ll_symbol);
6116 /* Output the DIE and its attributes. Called recursively to generate
6117 the definitions of each child DIE. */
6121 register dw_die_ref die;
6123 register dw_attr_ref a;
6124 register dw_die_ref c;
6125 register unsigned long size;
6127 /* If someone in another CU might refer to us, set up a symbol for
6128 them to point to. */
6129 if (die->die_symbol)
6130 output_die_symbol (die);
6132 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6133 die->die_offset, dwarf_tag_name (die->die_tag));
6135 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6137 const char *name = dwarf_attr_name (a->dw_attr);
6139 switch (AT_class (a))
6141 case dw_val_class_addr:
6142 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6145 case dw_val_class_offset:
6146 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6150 case dw_val_class_loc:
6151 size = size_of_locs (AT_loc (a));
6153 /* Output the block length for this list of location operations. */
6154 dw2_asm_output_data (constant_size (size), size, "%s", name);
6156 output_loc_sequence (AT_loc (a));
6159 case dw_val_class_const:
6160 /* ??? It would be slightly more efficient to use a scheme like is
6161 used for unsigned constants below, but gdb 4.x does not sign
6162 extend. Gdb 5.x does sign extend. */
6163 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6166 case dw_val_class_unsigned_const:
6167 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6168 AT_unsigned (a), "%s", name);
6171 case dw_val_class_long_long:
6173 unsigned HOST_WIDE_INT first, second;
6175 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6178 if (WORDS_BIG_ENDIAN)
6180 first = a->dw_attr_val.v.val_long_long.hi;
6181 second = a->dw_attr_val.v.val_long_long.low;
6185 first = a->dw_attr_val.v.val_long_long.low;
6186 second = a->dw_attr_val.v.val_long_long.hi;
6188 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6189 first, "long long constant");
6190 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6195 case dw_val_class_float:
6197 register unsigned int i;
6199 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6202 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6203 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6204 "fp constant word %u", i);
6208 case dw_val_class_flag:
6209 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6212 case dw_val_class_loc_list:
6214 char *sym = AT_loc_list (a)->ll_symbol;
6217 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6218 loc_section_label, "%s", name);
6222 case dw_val_class_die_ref:
6223 if (AT_ref_external (a))
6225 char *sym = AT_ref (a)->die_symbol;
6228 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6230 else if (AT_ref (a)->die_offset == 0)
6233 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6237 case dw_val_class_fde_ref:
6240 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6241 a->dw_attr_val.v.val_fde_index * 2);
6242 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6246 case dw_val_class_lbl_id:
6247 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6250 case dw_val_class_lbl_offset:
6251 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6254 case dw_val_class_str:
6255 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6263 for (c = die->die_child; c != NULL; c = c->die_sib)
6266 if (die->die_child != NULL)
6268 /* Add null byte to terminate sibling list. */
6269 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6274 /* Output the compilation unit that appears at the beginning of the
6275 .debug_info section, and precedes the DIE descriptions. */
6278 output_compilation_unit_header ()
6280 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6281 "Length of Compilation Unit Info");
6283 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6285 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6286 "Offset Into Abbrev. Section");
6288 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6291 /* Output the compilation unit DIE and its children. */
6294 output_comp_unit (die)
6297 const char *secname;
6299 /* Even if there are no children of this DIE, we must output the
6300 information about the compilation unit. Otherwise, on an empty
6301 translation unit, we will generate a present, but empty,
6302 .debug_info section. IRIX 6.5 `nm' will then complain when
6305 Mark all the DIEs in this CU so we know which get local refs. */
6308 build_abbrev_table (die);
6310 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6311 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6312 calc_die_sizes (die);
6314 if (die->die_symbol)
6316 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6317 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6319 die->die_symbol = NULL;
6322 secname = (const char *) DEBUG_INFO_SECTION;
6324 /* Output debugging information. */
6325 named_section_flags (secname, SECTION_DEBUG, 1);
6326 output_compilation_unit_header ();
6329 /* Leave the marks on the main CU, so we can check them in
6331 if (die->die_symbol)
6335 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6336 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6337 argument list, and maybe the scope. */
6340 dwarf2_name (decl, scope)
6344 return (*decl_printable_name) (decl, scope ? 1 : 0);
6347 /* Add a new entry to .debug_pubnames if appropriate. */
6350 add_pubname (decl, die)
6356 if (! TREE_PUBLIC (decl))
6359 if (pubname_table_in_use == pubname_table_allocated)
6361 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6362 pubname_table = (pubname_ref) xrealloc
6363 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6366 p = &pubname_table[pubname_table_in_use++];
6369 p->name = xstrdup (dwarf2_name (decl, 1));
6372 /* Output the public names table used to speed up access to externally
6373 visible names. For now, only generate entries for externally
6374 visible procedures. */
6379 register unsigned i;
6380 register unsigned long pubnames_length = size_of_pubnames ();
6382 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6383 "Length of Public Names Info");
6385 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6387 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6388 "Offset of Compilation Unit Info");
6390 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6391 "Compilation Unit Length");
6393 for (i = 0; i < pubname_table_in_use; ++i)
6395 register pubname_ref pub = &pubname_table[i];
6397 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6398 if (pub->die->die_mark == 0)
6401 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6404 dw2_asm_output_nstring (pub->name, -1, "external name");
6407 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6410 /* Add a new entry to .debug_aranges if appropriate. */
6413 add_arange (decl, die)
6417 if (! DECL_SECTION_NAME (decl))
6420 if (arange_table_in_use == arange_table_allocated)
6422 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6423 arange_table = (dw_die_ref *)
6424 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6427 arange_table[arange_table_in_use++] = die;
6430 /* Output the information that goes into the .debug_aranges table.
6431 Namely, define the beginning and ending address range of the
6432 text section generated for this compilation unit. */
6437 register unsigned i;
6438 register unsigned long aranges_length = size_of_aranges ();
6440 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6441 "Length of Address Ranges Info");
6443 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6445 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6446 "Offset of Compilation Unit Info");
6448 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6450 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6452 /* We need to align to twice the pointer size here. */
6453 if (DWARF_ARANGES_PAD_SIZE)
6455 /* Pad using a 2 byte words so that padding is correct for any
6457 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6458 2 * DWARF2_ADDR_SIZE);
6459 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6460 dw2_asm_output_data (2, 0, NULL);
6463 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6464 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6465 text_section_label, "Length");
6467 for (i = 0; i < arange_table_in_use; ++i)
6469 dw_die_ref die = arange_table[i];
6471 /* We shouldn't see aranges for DIEs outside of the main CU. */
6472 if (die->die_mark == 0)
6475 if (die->die_tag == DW_TAG_subprogram)
6477 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6479 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6480 get_AT_low_pc (die), "Length");
6484 /* A static variable; extract the symbol from DW_AT_location.
6485 Note that this code isn't currently hit, as we only emit
6486 aranges for functions (jason 9/23/99). */
6488 dw_attr_ref a = get_AT (die, DW_AT_location);
6489 dw_loc_descr_ref loc;
6490 if (! a || AT_class (a) != dw_val_class_loc)
6494 if (loc->dw_loc_opc != DW_OP_addr)
6497 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6498 loc->dw_loc_oprnd1.v.val_addr, "Address");
6499 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6500 get_AT_unsigned (die, DW_AT_byte_size),
6505 /* Output the terminator words. */
6506 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6507 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6510 /* Add a new entry to .debug_ranges. Return the offset at which it
6517 unsigned int in_use = ranges_table_in_use;
6519 if (in_use == ranges_table_allocated)
6521 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6522 ranges_table = (dw_ranges_ref)
6523 xrealloc (ranges_table, (ranges_table_allocated
6524 * sizeof (struct dw_ranges_struct)));
6527 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6528 ranges_table_in_use = in_use + 1;
6530 return in_use * 2 * DWARF2_ADDR_SIZE;
6536 register unsigned i;
6537 const char *start_fmt = "Offset 0x%x";
6538 const char *fmt = start_fmt;
6540 for (i = 0; i < ranges_table_in_use; ++i)
6542 int block_num = ranges_table[i].block_num;
6546 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6547 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6549 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6550 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6552 /* If all code is in the text section, then the compilation
6553 unit base address defaults to DW_AT_low_pc, which is the
6554 base of the text section. */
6555 if (separate_line_info_table_in_use == 0)
6557 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6559 fmt, i * 2 * DWARF2_ADDR_SIZE);
6560 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6561 text_section_label, NULL);
6563 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6564 compilation unit base address to zero, which allows us to
6565 use absolute addresses, and not worry about whether the
6566 target supports cross-section arithmetic. */
6569 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6570 fmt, i * 2 * DWARF2_ADDR_SIZE);
6571 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6578 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6579 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6585 /* Data structure containing information about input files. */
6588 char *path; /* Complete file name. */
6589 char *fname; /* File name part. */
6590 int length; /* Length of entire string. */
6591 int file_idx; /* Index in input file table. */
6592 int dir_idx; /* Index in directory table. */
6595 /* Data structure containing information about directories with source
6599 char *path; /* Path including directory name. */
6600 int length; /* Path length. */
6601 int prefix; /* Index of directory entry which is a prefix. */
6602 int count; /* Number of files in this directory. */
6603 int dir_idx; /* Index of directory used as base. */
6604 int used; /* Used in the end? */
6607 /* Callback function for file_info comparison. We sort by looking at
6608 the directories in the path. */
6610 file_info_cmp (p1, p2)
6614 const struct file_info *s1 = p1;
6615 const struct file_info *s2 = p2;
6619 /* Take care of file names without directories. */
6620 if (s1->path == s1->fname)
6622 else if (s2->path == s2->fname)
6625 cp1 = (unsigned char *) s1->path;
6626 cp2 = (unsigned char *) s2->path;
6632 /* Reached the end of the first path? */
6633 if (cp1 == (unsigned char *) s1->fname)
6634 /* It doesn't really matter in which order files from the
6635 same directory are sorted in. Therefore don't test for
6636 the second path reaching the end. */
6638 else if (cp2 == (unsigned char *) s2->fname)
6641 /* Character of current path component the same? */
6647 /* Output the directory table and the file name table. We try to minimize
6648 the total amount of memory needed. A heuristic is used to avoid large
6649 slowdowns with many input files. */
6651 output_file_names ()
6653 struct file_info *files;
6654 struct dir_info *dirs;
6663 /* Allocate the various arrays we need. */
6664 files = (struct file_info *) alloca (file_table.in_use
6665 * sizeof (struct file_info));
6666 dirs = (struct dir_info *) alloca (file_table.in_use
6667 * sizeof (struct dir_info));
6669 /* Sort the file names. */
6670 for (i = 1; i < (int) file_table.in_use; ++i)
6674 /* Skip all leading "./". */
6675 f = file_table.table[i];
6676 while (f[0] == '.' && f[1] == '/')
6679 /* Create a new array entry. */
6681 files[i].length = strlen (f);
6682 files[i].file_idx = i;
6684 /* Search for the file name part. */
6685 f = strrchr (f, '/');
6686 files[i].fname = f == NULL ? files[i].path : f + 1;
6688 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6690 /* Find all the different directories used. */
6691 dirs[0].path = files[1].path;
6692 dirs[0].length = files[1].fname - files[1].path;
6693 dirs[0].prefix = -1;
6695 dirs[0].dir_idx = 0;
6697 files[1].dir_idx = 0;
6700 for (i = 2; i < (int) file_table.in_use; ++i)
6701 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6702 && memcmp (dirs[ndirs - 1].path, files[i].path,
6703 dirs[ndirs - 1].length) == 0)
6705 /* Same directory as last entry. */
6706 files[i].dir_idx = ndirs - 1;
6707 ++dirs[ndirs - 1].count;
6713 /* This is a new directory. */
6714 dirs[ndirs].path = files[i].path;
6715 dirs[ndirs].length = files[i].fname - files[i].path;
6716 dirs[ndirs].count = 1;
6717 dirs[ndirs].dir_idx = ndirs;
6718 dirs[ndirs].used = 0;
6719 files[i].dir_idx = ndirs;
6721 /* Search for a prefix. */
6722 dirs[ndirs].prefix = -1;
6723 for (j = 0; j < ndirs; ++j)
6724 if (dirs[j].length < dirs[ndirs].length
6725 && dirs[j].length > 1
6726 && (dirs[ndirs].prefix == -1
6727 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6728 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6729 dirs[ndirs].prefix = j;
6734 /* Now to the actual work. We have to find a subset of the
6735 directories which allow expressing the file name using references
6736 to the directory table with the least amount of characters. We
6737 do not do an exhaustive search where we would have to check out
6738 every combination of every single possible prefix. Instead we
6739 use a heuristic which provides nearly optimal results in most
6740 cases and never is much off. */
6741 saved = (int *) alloca (ndirs * sizeof (int));
6742 savehere = (int *) alloca (ndirs * sizeof (int));
6744 memset (saved, '\0', ndirs * sizeof (saved[0]));
6745 for (i = 0; i < ndirs; ++i)
6750 /* We can always save some space for the current directory. But
6751 this does not mean it will be enough to justify adding the
6753 savehere[i] = dirs[i].length;
6754 total = (savehere[i] - saved[i]) * dirs[i].count;
6756 for (j = i + 1; j < ndirs; ++j)
6760 if (saved[j] < dirs[i].length)
6762 /* Determine whether the dirs[i] path is a prefix of the
6767 while (k != -1 && k != i)
6772 /* Yes it is. We can possibly safe some memory but
6773 writing the filenames in dirs[j] relative to
6775 savehere[j] = dirs[i].length;
6776 total += (savehere[j] - saved[j]) * dirs[j].count;
6781 /* Check whether we can safe enough to justify adding the dirs[i]
6783 if (total > dirs[i].length + 1)
6785 /* It's worthwhile adding. */
6786 for (j = i; j < ndirs; ++j)
6787 if (savehere[j] > 0)
6789 /* Remember how much we saved for this directory so far. */
6790 saved[j] = savehere[j];
6792 /* Remember the prefix directory. */
6793 dirs[j].dir_idx = i;
6798 /* We have to emit them in the order they appear in the file_table
6799 array since the index is used in the debug info generation. To
6800 do this efficiently we generate a back-mapping of the indices
6802 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6803 for (i = 1; i < (int) file_table.in_use; ++i)
6805 backmap[files[i].file_idx] = i;
6806 /* Mark this directory as used. */
6807 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6810 /* That was it. We are ready to emit the information. First the
6811 directory name table. Here we have to make sure that the first
6812 actually emitted directory name has the index one. Zero is
6813 reserved for the current working directory. Make sure we do not
6814 confuse these indices with the one for the constructed table
6815 (even though most of the time they are identical). */
6817 idx_offset = dirs[0].length > 0 ? 1 : 0;
6818 for (i = 1 - idx_offset; i < ndirs; ++i)
6819 if (dirs[i].used != 0)
6821 dirs[i].used = idx++;
6822 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6823 "Directory Entry: 0x%x", dirs[i].used);
6825 dw2_asm_output_data (1, 0, "End directory table");
6827 /* Correct the index for the current working directory entry if it
6829 if (idx_offset == 0)
6832 /* Now write all the file names. */
6833 for (i = 1; i < (int) file_table.in_use; ++i)
6835 int file_idx = backmap[i];
6836 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6838 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6839 "File Entry: 0x%x", i);
6841 /* Include directory index. */
6842 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6844 /* Modification time. */
6845 dw2_asm_output_data_uleb128 (0, NULL);
6847 /* File length in bytes. */
6848 dw2_asm_output_data_uleb128 (0, NULL);
6850 dw2_asm_output_data (1, 0, "End file name table");
6854 /* Output the source line number correspondence information. This
6855 information goes into the .debug_line section. */
6860 char l1[20], l2[20], p1[20], p2[20];
6861 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6862 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6863 register unsigned opc;
6864 register unsigned n_op_args;
6865 register unsigned long lt_index;
6866 register unsigned long current_line;
6867 register long line_offset;
6868 register long line_delta;
6869 register unsigned long current_file;
6870 register unsigned long function;
6872 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6873 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6874 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6875 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6877 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6878 "Length of Source Line Info");
6879 ASM_OUTPUT_LABEL (asm_out_file, l1);
6881 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6883 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6884 ASM_OUTPUT_LABEL (asm_out_file, p1);
6886 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6887 "Minimum Instruction Length");
6889 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6890 "Default is_stmt_start flag");
6892 dw2_asm_output_data (1, DWARF_LINE_BASE,
6893 "Line Base Value (Special Opcodes)");
6895 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6896 "Line Range Value (Special Opcodes)");
6898 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6899 "Special Opcode Base");
6901 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6905 case DW_LNS_advance_pc:
6906 case DW_LNS_advance_line:
6907 case DW_LNS_set_file:
6908 case DW_LNS_set_column:
6909 case DW_LNS_fixed_advance_pc:
6917 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6921 /* Write out the information about the files we use. */
6922 output_file_names ();
6923 ASM_OUTPUT_LABEL (asm_out_file, p2);
6925 /* We used to set the address register to the first location in the text
6926 section here, but that didn't accomplish anything since we already
6927 have a line note for the opening brace of the first function. */
6929 /* Generate the line number to PC correspondence table, encoded as
6930 a series of state machine operations. */
6933 strcpy (prev_line_label, text_section_label);
6934 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6936 register dw_line_info_ref line_info = &line_info_table[lt_index];
6939 /* Disable this optimization for now; GDB wants to see two line notes
6940 at the beginning of a function so it can find the end of the
6943 /* Don't emit anything for redundant notes. Just updating the
6944 address doesn't accomplish anything, because we already assume
6945 that anything after the last address is this line. */
6946 if (line_info->dw_line_num == current_line
6947 && line_info->dw_file_num == current_file)
6951 /* Emit debug info for the address of the current line.
6953 Unfortunately, we have little choice here currently, and must always
6954 use the most general form. Gcc does not know the address delta
6955 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
6956 attributes which will give an upper bound on the address range. We
6957 could perhaps use length attributes to determine when it is safe to
6958 use DW_LNS_fixed_advance_pc. */
6960 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6963 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6964 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6965 "DW_LNS_fixed_advance_pc");
6966 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6970 /* This can handle any delta. This takes
6971 4+DWARF2_ADDR_SIZE bytes. */
6972 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6973 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6974 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6975 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6977 strcpy (prev_line_label, line_label);
6979 /* Emit debug info for the source file of the current line, if
6980 different from the previous line. */
6981 if (line_info->dw_file_num != current_file)
6983 current_file = line_info->dw_file_num;
6984 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6985 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6986 file_table.table[current_file]);
6989 /* Emit debug info for the current line number, choosing the encoding
6990 that uses the least amount of space. */
6991 if (line_info->dw_line_num != current_line)
6993 line_offset = line_info->dw_line_num - current_line;
6994 line_delta = line_offset - DWARF_LINE_BASE;
6995 current_line = line_info->dw_line_num;
6996 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6998 /* This can handle deltas from -10 to 234, using the current
6999 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7001 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7002 "line %lu", current_line);
7006 /* This can handle any delta. This takes at least 4 bytes,
7007 depending on the value being encoded. */
7008 dw2_asm_output_data (1, DW_LNS_advance_line,
7009 "advance to line %lu", current_line);
7010 dw2_asm_output_data_sleb128 (line_offset, NULL);
7011 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7016 /* We still need to start a new row, so output a copy insn. */
7017 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7021 /* Emit debug info for the address of the end of the function. */
7024 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7025 "DW_LNS_fixed_advance_pc");
7026 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7030 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7031 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7032 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7033 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7036 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7037 dw2_asm_output_data_uleb128 (1, NULL);
7038 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7043 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7045 register dw_separate_line_info_ref line_info
7046 = &separate_line_info_table[lt_index];
7049 /* Don't emit anything for redundant notes. */
7050 if (line_info->dw_line_num == current_line
7051 && line_info->dw_file_num == current_file
7052 && line_info->function == function)
7056 /* Emit debug info for the address of the current line. If this is
7057 a new function, or the first line of a function, then we need
7058 to handle it differently. */
7059 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7061 if (function != line_info->function)
7063 function = line_info->function;
7065 /* Set the address register to the first line in the function */
7066 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7067 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7068 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7069 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7073 /* ??? See the DW_LNS_advance_pc comment above. */
7076 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7077 "DW_LNS_fixed_advance_pc");
7078 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7082 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7083 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7084 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7085 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7088 strcpy (prev_line_label, line_label);
7090 /* Emit debug info for the source file of the current line, if
7091 different from the previous line. */
7092 if (line_info->dw_file_num != current_file)
7094 current_file = line_info->dw_file_num;
7095 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7096 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7097 file_table.table[current_file]);
7100 /* Emit debug info for the current line number, choosing the encoding
7101 that uses the least amount of space. */
7102 if (line_info->dw_line_num != current_line)
7104 line_offset = line_info->dw_line_num - current_line;
7105 line_delta = line_offset - DWARF_LINE_BASE;
7106 current_line = line_info->dw_line_num;
7107 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7108 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7109 "line %lu", current_line);
7112 dw2_asm_output_data (1, DW_LNS_advance_line,
7113 "advance to line %lu", current_line);
7114 dw2_asm_output_data_sleb128 (line_offset, NULL);
7115 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7119 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7126 /* If we're done with a function, end its sequence. */
7127 if (lt_index == separate_line_info_table_in_use
7128 || separate_line_info_table[lt_index].function != function)
7133 /* Emit debug info for the address of the end of the function. */
7134 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7137 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7138 "DW_LNS_fixed_advance_pc");
7139 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7143 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7144 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7145 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7146 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7149 /* Output the marker for the end of this sequence. */
7150 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7151 dw2_asm_output_data_uleb128 (1, NULL);
7152 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7156 /* Output the marker for the end of the line number info. */
7157 ASM_OUTPUT_LABEL (asm_out_file, l2);
7160 /* Given a pointer to a tree node for some base type, return a pointer to
7161 a DIE that describes the given type.
7163 This routine must only be called for GCC type nodes that correspond to
7164 Dwarf base (fundamental) types. */
7167 base_type_die (type)
7170 register dw_die_ref base_type_result;
7171 register const char *type_name;
7172 register enum dwarf_type encoding;
7173 register tree name = TYPE_NAME (type);
7175 if (TREE_CODE (type) == ERROR_MARK
7176 || TREE_CODE (type) == VOID_TYPE)
7181 if (TREE_CODE (name) == TYPE_DECL)
7182 name = DECL_NAME (name);
7184 type_name = IDENTIFIER_POINTER (name);
7187 type_name = "__unknown__";
7189 switch (TREE_CODE (type))
7192 /* Carefully distinguish the C character types, without messing
7193 up if the language is not C. Note that we check only for the names
7194 that contain spaces; other names might occur by coincidence in other
7196 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7197 && (type == char_type_node
7198 || ! strcmp (type_name, "signed char")
7199 || ! strcmp (type_name, "unsigned char"))))
7201 if (TREE_UNSIGNED (type))
7202 encoding = DW_ATE_unsigned;
7204 encoding = DW_ATE_signed;
7207 /* else fall through. */
7210 /* GNU Pascal/Ada CHAR type. Not used in C. */
7211 if (TREE_UNSIGNED (type))
7212 encoding = DW_ATE_unsigned_char;
7214 encoding = DW_ATE_signed_char;
7218 encoding = DW_ATE_float;
7221 /* Dwarf2 doesn't know anything about complex ints, so use
7222 a user defined type for it. */
7224 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7225 encoding = DW_ATE_complex_float;
7227 encoding = DW_ATE_lo_user;
7231 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7232 encoding = DW_ATE_boolean;
7236 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7239 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7240 if (demangle_name_func)
7241 type_name = (*demangle_name_func) (type_name);
7243 add_AT_string (base_type_result, DW_AT_name, type_name);
7244 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7245 int_size_in_bytes (type));
7246 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7248 return base_type_result;
7251 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7252 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7253 a given type is generally the same as the given type, except that if the
7254 given type is a pointer or reference type, then the root type of the given
7255 type is the root type of the "basis" type for the pointer or reference
7256 type. (This definition of the "root" type is recursive.) Also, the root
7257 type of a `const' qualified type or a `volatile' qualified type is the
7258 root type of the given type without the qualifiers. */
7264 if (TREE_CODE (type) == ERROR_MARK)
7265 return error_mark_node;
7267 switch (TREE_CODE (type))
7270 return error_mark_node;
7273 case REFERENCE_TYPE:
7274 return type_main_variant (root_type (TREE_TYPE (type)));
7277 return type_main_variant (type);
7281 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7282 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7288 switch (TREE_CODE (type))
7303 case QUAL_UNION_TYPE:
7308 case REFERENCE_TYPE:
7322 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7323 entry that chains various modifiers in front of the given type. */
7326 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7328 register int is_const_type;
7329 register int is_volatile_type;
7330 register dw_die_ref context_die;
7332 register enum tree_code code = TREE_CODE (type);
7333 register dw_die_ref mod_type_die = NULL;
7334 register dw_die_ref sub_die = NULL;
7335 register tree item_type = NULL;
7337 if (code != ERROR_MARK)
7339 tree qualified_type;
7341 /* See if we already have the appropriately qualified variant of
7344 = get_qualified_type (type,
7345 ((is_const_type ? TYPE_QUAL_CONST : 0)
7347 ? TYPE_QUAL_VOLATILE : 0)));
7348 /* If we do, then we can just use its DIE, if it exists. */
7351 mod_type_die = lookup_type_die (qualified_type);
7353 return mod_type_die;
7356 /* Handle C typedef types. */
7357 if (qualified_type && TYPE_NAME (qualified_type)
7358 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7359 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7361 tree type_name = TYPE_NAME (qualified_type);
7362 tree dtype = TREE_TYPE (type_name);
7363 if (qualified_type == dtype)
7365 /* For a named type, use the typedef. */
7366 gen_type_die (qualified_type, context_die);
7367 mod_type_die = lookup_type_die (qualified_type);
7370 else if (is_const_type < TYPE_READONLY (dtype)
7371 || is_volatile_type < TYPE_VOLATILE (dtype))
7372 /* cv-unqualified version of named type. Just use the unnamed
7373 type to which it refers. */
7375 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7376 is_const_type, is_volatile_type,
7378 /* Else cv-qualified version of named type; fall through. */
7384 else if (is_const_type)
7386 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7387 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7389 else if (is_volatile_type)
7391 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7392 sub_die = modified_type_die (type, 0, 0, context_die);
7394 else if (code == POINTER_TYPE)
7396 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7397 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7399 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7401 item_type = TREE_TYPE (type);
7403 else if (code == REFERENCE_TYPE)
7405 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7406 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7408 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7410 item_type = TREE_TYPE (type);
7412 else if (is_base_type (type))
7413 mod_type_die = base_type_die (type);
7416 gen_type_die (type, context_die);
7418 /* We have to get the type_main_variant here (and pass that to the
7419 `lookup_type_die' routine) because the ..._TYPE node we have
7420 might simply be a *copy* of some original type node (where the
7421 copy was created to help us keep track of typedef names) and
7422 that copy might have a different TYPE_UID from the original
7424 mod_type_die = lookup_type_die (type_main_variant (type));
7425 if (mod_type_die == NULL)
7429 /* We want to equate the qualified type to the die below. */
7431 type = qualified_type;
7434 equate_type_number_to_die (type, mod_type_die);
7436 /* We must do this after the equate_type_number_to_die call, in case
7437 this is a recursive type. This ensures that the modified_type_die
7438 recursion will terminate even if the type is recursive. Recursive
7439 types are possible in Ada. */
7440 sub_die = modified_type_die (item_type,
7441 TYPE_READONLY (item_type),
7442 TYPE_VOLATILE (item_type),
7445 if (sub_die != NULL)
7446 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7448 return mod_type_die;
7451 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7452 an enumerated type. */
7458 return TREE_CODE (type) == ENUMERAL_TYPE;
7461 /* Return the register number described by a given RTL node. */
7467 register unsigned regno = REGNO (rtl);
7469 if (regno >= FIRST_PSEUDO_REGISTER)
7471 warning ("internal regno botch: regno = %d\n", regno);
7475 regno = DBX_REGISTER_NUMBER (regno);
7479 /* Return a location descriptor that designates a machine register. */
7481 static dw_loc_descr_ref
7482 reg_loc_descriptor (rtl)
7485 register dw_loc_descr_ref loc_result = NULL;
7486 register unsigned reg = reg_number (rtl);
7489 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7491 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7496 /* Return a location descriptor that designates a constant. */
7498 static dw_loc_descr_ref
7499 int_loc_descriptor (i)
7502 enum dwarf_location_atom op;
7504 /* Pick the smallest representation of a constant, rather than just
7505 defaulting to the LEB encoding. */
7509 op = DW_OP_lit0 + i;
7512 else if (i <= 0xffff)
7514 else if (HOST_BITS_PER_WIDE_INT == 32
7524 else if (i >= -0x8000)
7526 else if (HOST_BITS_PER_WIDE_INT == 32
7527 || i >= -0x80000000)
7533 return new_loc_descr (op, i, 0);
7536 /* Return a location descriptor that designates a base+offset location. */
7538 static dw_loc_descr_ref
7539 based_loc_descr (reg, offset)
7543 register dw_loc_descr_ref loc_result;
7544 /* For the "frame base", we use the frame pointer or stack pointer
7545 registers, since the RTL for local variables is relative to one of
7547 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7548 ? HARD_FRAME_POINTER_REGNUM
7549 : STACK_POINTER_REGNUM);
7552 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7554 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7556 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7561 /* Return true if this RTL expression describes a base+offset calculation. */
7567 return (GET_CODE (rtl) == PLUS
7568 && ((GET_CODE (XEXP (rtl, 0)) == REG
7569 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7572 /* The following routine converts the RTL for a variable or parameter
7573 (resident in memory) into an equivalent Dwarf representation of a
7574 mechanism for getting the address of that same variable onto the top of a
7575 hypothetical "address evaluation" stack.
7577 When creating memory location descriptors, we are effectively transforming
7578 the RTL for a memory-resident object into its Dwarf postfix expression
7579 equivalent. This routine recursively descends an RTL tree, turning
7580 it into Dwarf postfix code as it goes.
7582 MODE is the mode of the memory reference, needed to handle some
7583 autoincrement addressing modes. */
7585 static dw_loc_descr_ref
7586 mem_loc_descriptor (rtl, mode)
7588 enum machine_mode mode;
7590 dw_loc_descr_ref mem_loc_result = NULL;
7591 /* Note that for a dynamically sized array, the location we will generate a
7592 description of here will be the lowest numbered location which is
7593 actually within the array. That's *not* necessarily the same as the
7594 zeroth element of the array. */
7596 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7597 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7600 switch (GET_CODE (rtl))
7605 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7606 just fall into the SUBREG code. */
7611 /* The case of a subreg may arise when we have a local (register)
7612 variable or a formal (register) parameter which doesn't quite fill
7613 up an entire register. For now, just assume that it is
7614 legitimate to make the Dwarf info refer to the whole register which
7615 contains the given subreg. */
7616 rtl = SUBREG_REG (rtl);
7621 /* Whenever a register number forms a part of the description of the
7622 method for calculating the (dynamic) address of a memory resident
7623 object, DWARF rules require the register number be referred to as
7624 a "base register". This distinction is not based in any way upon
7625 what category of register the hardware believes the given register
7626 belongs to. This is strictly DWARF terminology we're dealing with
7627 here. Note that in cases where the location of a memory-resident
7628 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7629 OP_CONST (0)) the actual DWARF location descriptor that we generate
7630 may just be OP_BASEREG (basereg). This may look deceptively like
7631 the object in question was allocated to a register (rather than in
7632 memory) so DWARF consumers need to be aware of the subtle
7633 distinction between OP_REG and OP_BASEREG. */
7634 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7638 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7639 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7643 /* Some ports can transform a symbol ref into a label ref, because
7644 the symbol ref is too far away and has to be dumped into a constant
7648 /* Alternatively, the symbol in the constant pool might be referenced
7649 by a different symbol. */
7650 if (GET_CODE (rtl) == SYMBOL_REF
7651 && CONSTANT_POOL_ADDRESS_P (rtl))
7653 rtx tmp = get_pool_constant (rtl);
7654 if (GET_CODE (tmp) == SYMBOL_REF)
7658 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7659 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7660 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7664 /* Extract the PLUS expression nested inside and fall into
7666 rtl = XEXP (rtl, 1);
7671 /* Turn these into a PLUS expression and fall into the PLUS code
7673 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7674 GEN_INT (GET_CODE (rtl) == PRE_INC
7675 ? GET_MODE_UNIT_SIZE (mode)
7676 : -GET_MODE_UNIT_SIZE (mode)));
7682 if (is_based_loc (rtl))
7683 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7684 INTVAL (XEXP (rtl, 1)));
7687 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7689 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7690 && INTVAL (XEXP (rtl, 1)) >= 0)
7692 add_loc_descr (&mem_loc_result,
7693 new_loc_descr (DW_OP_plus_uconst,
7694 INTVAL (XEXP (rtl, 1)), 0));
7698 add_loc_descr (&mem_loc_result,
7699 mem_loc_descriptor (XEXP (rtl, 1), mode));
7700 add_loc_descr (&mem_loc_result,
7701 new_loc_descr (DW_OP_plus, 0, 0));
7707 /* If a pseudo-reg is optimized away, it is possible for it to
7708 be replaced with a MEM containing a multiply. */
7709 add_loc_descr (&mem_loc_result,
7710 mem_loc_descriptor (XEXP (rtl, 0), mode));
7711 add_loc_descr (&mem_loc_result,
7712 mem_loc_descriptor (XEXP (rtl, 1), mode));
7713 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7717 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7724 return mem_loc_result;
7727 /* Return a descriptor that describes the concatenation of two locations.
7728 This is typically a complex variable. */
7730 static dw_loc_descr_ref
7731 concat_loc_descriptor (x0, x1)
7732 register rtx x0, x1;
7734 dw_loc_descr_ref cc_loc_result = NULL;
7736 if (!is_pseudo_reg (x0)
7737 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7738 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7739 add_loc_descr (&cc_loc_result,
7740 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7742 if (!is_pseudo_reg (x1)
7743 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7744 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7745 add_loc_descr (&cc_loc_result,
7746 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7748 return cc_loc_result;
7751 /* Output a proper Dwarf location descriptor for a variable or parameter
7752 which is either allocated in a register or in a memory location. For a
7753 register, we just generate an OP_REG and the register number. For a
7754 memory location we provide a Dwarf postfix expression describing how to
7755 generate the (dynamic) address of the object onto the address stack. */
7757 static dw_loc_descr_ref
7758 loc_descriptor (rtl)
7761 dw_loc_descr_ref loc_result = NULL;
7762 switch (GET_CODE (rtl))
7765 /* The case of a subreg may arise when we have a local (register)
7766 variable or a formal (register) parameter which doesn't quite fill
7767 up an entire register. For now, just assume that it is
7768 legitimate to make the Dwarf info refer to the whole register which
7769 contains the given subreg. */
7770 rtl = SUBREG_REG (rtl);
7775 loc_result = reg_loc_descriptor (rtl);
7779 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7783 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7793 /* Similar, but generate the descriptor from trees instead of rtl.
7794 This comes up particularly with variable length arrays. */
7796 static dw_loc_descr_ref
7797 loc_descriptor_from_tree (loc, addressp)
7801 dw_loc_descr_ref ret = NULL;
7802 int indirect_size = 0;
7803 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7804 enum dwarf_location_atom op;
7806 /* ??? Most of the time we do not take proper care for sign/zero
7807 extending the values properly. Hopefully this won't be a real
7810 switch (TREE_CODE (loc))
7815 case WITH_RECORD_EXPR:
7816 /* This case involves extracting fields from an object to determine the
7817 position of other fields. We don't try to encode this here. The
7818 only user of this is Ada, which encodes the needed information using
7819 the names of types. */
7825 rtx rtl = rtl_for_decl_location (loc);
7826 enum machine_mode mode = DECL_MODE (loc);
7828 if (rtl == NULL_RTX)
7830 else if (CONSTANT_P (rtl))
7832 ret = new_loc_descr (DW_OP_addr, 0, 0);
7833 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7834 ret->dw_loc_oprnd1.v.val_addr = rtl;
7835 indirect_size = GET_MODE_SIZE (mode);
7839 if (GET_CODE (rtl) == MEM)
7841 indirect_size = GET_MODE_SIZE (mode);
7842 rtl = XEXP (rtl, 0);
7844 ret = mem_loc_descriptor (rtl, mode);
7850 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7851 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7856 case NON_LVALUE_EXPR:
7858 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7863 case ARRAY_RANGE_REF:
7866 HOST_WIDE_INT bitsize, bitpos, bytepos;
7867 enum machine_mode mode;
7869 unsigned int alignment;
7871 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7872 &unsignedp, &volatilep, &alignment);
7873 ret = loc_descriptor_from_tree (obj, 1);
7875 if (offset != NULL_TREE)
7877 /* Variable offset. */
7878 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7879 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7884 /* We cannot address anything not on a unit boundary. */
7885 if (bitpos % BITS_PER_UNIT != 0)
7890 if (bitpos % BITS_PER_UNIT != 0
7891 || bitsize % BITS_PER_UNIT != 0)
7893 /* ??? We could handle this by loading and shifting etc.
7894 Wait until someone needs it before expending the effort. */
7898 indirect_size = bitsize / BITS_PER_UNIT;
7901 bytepos = bitpos / BITS_PER_UNIT;
7903 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7904 else if (bytepos < 0)
7906 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7907 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7913 if (host_integerp (loc, 0))
7914 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7926 case TRUNC_DIV_EXPR:
7932 case TRUNC_MOD_EXPR:
7942 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7945 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7946 && host_integerp (TREE_OPERAND (loc, 1), 0))
7948 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7949 add_loc_descr (&ret,
7950 new_loc_descr (DW_OP_plus_uconst,
7951 tree_low_cst (TREE_OPERAND (loc, 1),
7959 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7964 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7969 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7974 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7986 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7987 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7988 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8002 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8003 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8007 loc = build (COND_EXPR, TREE_TYPE (loc),
8008 build (LT_EXPR, integer_type_node,
8009 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8010 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8015 dw_loc_descr_ref bra_node, jump_node, tmp;
8017 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8018 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8019 add_loc_descr (&ret, bra_node);
8021 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8022 add_loc_descr (&ret, tmp);
8023 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8024 add_loc_descr (&ret, jump_node);
8026 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8027 add_loc_descr (&ret, tmp);
8028 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8029 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
8031 /* ??? Need a node to point the skip at. Use a nop. */
8032 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8033 add_loc_descr (&ret, tmp);
8034 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8035 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8043 /* If we can't fill the request for an address, die. */
8044 if (addressp && indirect_size == 0)
8047 /* If we've got an address and don't want one, dereference. */
8048 if (!addressp && indirect_size > 0)
8050 if (indirect_size > DWARF2_ADDR_SIZE)
8052 if (indirect_size == DWARF2_ADDR_SIZE)
8055 op = DW_OP_deref_size;
8056 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
8062 /* Given a value, round it up to the lowest multiple of `boundary'
8063 which is not less than the value itself. */
8065 static inline HOST_WIDE_INT
8066 ceiling (value, boundary)
8067 HOST_WIDE_INT value;
8068 unsigned int boundary;
8070 return (((value + boundary - 1) / boundary) * boundary);
8073 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8074 pointer to the declared type for the relevant field variable, or return
8075 `integer_type_node' if the given node turns out to be an
8084 if (TREE_CODE (decl) == ERROR_MARK)
8085 return integer_type_node;
8087 type = DECL_BIT_FIELD_TYPE (decl);
8088 if (type == NULL_TREE)
8089 type = TREE_TYPE (decl);
8094 /* Given a pointer to a tree node, return the alignment in bits for
8095 it, or else return BITS_PER_WORD if the node actually turns out to
8096 be an ERROR_MARK node. */
8098 static inline unsigned
8099 simple_type_align_in_bits (type)
8102 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8105 static inline unsigned
8106 simple_decl_align_in_bits (decl)
8109 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8112 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8113 node, return the size in bits for the type if it is a constant, or else
8114 return the alignment for the type if the type's size is not constant, or
8115 else return BITS_PER_WORD if the type actually turns out to be an
8118 static inline unsigned HOST_WIDE_INT
8119 simple_type_size_in_bits (type)
8122 tree type_size_tree;
8124 if (TREE_CODE (type) == ERROR_MARK)
8125 return BITS_PER_WORD;
8126 type_size_tree = TYPE_SIZE (type);
8128 if (type_size_tree == NULL_TREE)
8130 if (! host_integerp (type_size_tree, 1))
8131 return TYPE_ALIGN (type);
8132 return tree_low_cst (type_size_tree, 1);
8135 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8136 return the byte offset of the lowest addressed byte of the "containing
8137 object" for the given FIELD_DECL, or return 0 if we are unable to
8138 determine what that offset is, either because the argument turns out to
8139 be a pointer to an ERROR_MARK node, or because the offset is actually
8140 variable. (We can't handle the latter case just yet). */
8142 static HOST_WIDE_INT
8143 field_byte_offset (decl)
8146 unsigned int type_align_in_bits;
8147 unsigned int decl_align_in_bits;
8148 unsigned HOST_WIDE_INT type_size_in_bits;
8149 HOST_WIDE_INT object_offset_in_bits;
8150 HOST_WIDE_INT object_offset_in_bytes;
8152 tree field_size_tree;
8153 HOST_WIDE_INT bitpos_int;
8154 HOST_WIDE_INT deepest_bitpos;
8155 unsigned HOST_WIDE_INT field_size_in_bits;
8157 if (TREE_CODE (decl) == ERROR_MARK)
8160 if (TREE_CODE (decl) != FIELD_DECL)
8163 type = field_type (decl);
8164 field_size_tree = DECL_SIZE (decl);
8166 /* The size could be unspecified if there was an error, or for
8167 a flexible array member. */
8168 if (! field_size_tree)
8169 field_size_tree = bitsize_zero_node;
8171 /* We cannot yet cope with fields whose positions are variable, so
8172 for now, when we see such things, we simply return 0. Someday, we may
8173 be able to handle such cases, but it will be damn difficult. */
8174 if (! host_integerp (bit_position (decl), 0))
8177 bitpos_int = int_bit_position (decl);
8179 /* If we don't know the size of the field, pretend it's a full word. */
8180 if (host_integerp (field_size_tree, 1))
8181 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8183 field_size_in_bits = BITS_PER_WORD;
8185 type_size_in_bits = simple_type_size_in_bits (type);
8186 type_align_in_bits = simple_type_align_in_bits (type);
8187 decl_align_in_bits = simple_decl_align_in_bits (decl);
8189 /* Note that the GCC front-end doesn't make any attempt to keep track of
8190 the starting bit offset (relative to the start of the containing
8191 structure type) of the hypothetical "containing object" for a bit-
8192 field. Thus, when computing the byte offset value for the start of the
8193 "containing object" of a bit-field, we must deduce this information on
8194 our own. This can be rather tricky to do in some cases. For example,
8195 handling the following structure type definition when compiling for an
8196 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8199 struct S { int field1; long long field2:31; };
8201 Fortunately, there is a simple rule-of-thumb which can be
8202 used in such cases. When compiling for an i386/i486, GCC will allocate
8203 8 bytes for the structure shown above. It decides to do this based upon
8204 one simple rule for bit-field allocation. Quite simply, GCC allocates
8205 each "containing object" for each bit-field at the first (i.e. lowest
8206 addressed) legitimate alignment boundary (based upon the required
8207 minimum alignment for the declared type of the field) which it can
8208 possibly use, subject to the condition that there is still enough
8209 available space remaining in the containing object (when allocated at
8210 the selected point) to fully accommodate all of the bits of the
8211 bit-field itself. This simple rule makes it obvious why GCC allocates
8212 8 bytes for each object of the structure type shown above. When looking
8213 for a place to allocate the "containing object" for `field2', the
8214 compiler simply tries to allocate a 64-bit "containing object" at each
8215 successive 32-bit boundary (starting at zero) until it finds a place to
8216 allocate that 64- bit field such that at least 31 contiguous (and
8217 previously unallocated) bits remain within that selected 64 bit field.
8218 (As it turns out, for the example above, the compiler finds that it is
8219 OK to allocate the "containing object" 64-bit field at bit-offset zero
8220 within the structure type.) Here we attempt to work backwards from the
8221 limited set of facts we're given, and we try to deduce from those facts,
8222 where GCC must have believed that the containing object started (within
8223 the structure type). The value we deduce is then used (by the callers of
8224 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8225 for fields (both bit-fields and, in the case of DW_AT_location, regular
8228 /* Figure out the bit-distance from the start of the structure to the
8229 "deepest" bit of the bit-field. */
8230 deepest_bitpos = bitpos_int + field_size_in_bits;
8232 /* This is the tricky part. Use some fancy footwork to deduce where the
8233 lowest addressed bit of the containing object must be. */
8234 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8236 /* Round up to type_align by default. This works best for bitfields. */
8237 object_offset_in_bits += type_align_in_bits - 1;
8238 object_offset_in_bits /= type_align_in_bits;
8239 object_offset_in_bits *= type_align_in_bits;
8241 if (object_offset_in_bits > bitpos_int)
8243 /* Sigh, the decl must be packed. */
8244 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8246 /* Round up to decl_align instead. */
8247 object_offset_in_bits += decl_align_in_bits - 1;
8248 object_offset_in_bits /= decl_align_in_bits;
8249 object_offset_in_bits *= decl_align_in_bits;
8252 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8254 return object_offset_in_bytes;
8257 /* The following routines define various Dwarf attributes and any data
8258 associated with them. */
8260 /* Add a location description attribute value to a DIE.
8262 This emits location attributes suitable for whole variables and
8263 whole parameters. Note that the location attributes for struct fields are
8264 generated by the routine `data_member_location_attribute' below. */
8267 add_AT_location_description (die, attr_kind, rtl)
8269 enum dwarf_attribute attr_kind;
8272 /* Handle a special case. If we are about to output a location descriptor
8273 for a variable or parameter which has been optimized out of existence,
8274 don't do that. A variable which has been optimized out
8275 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8276 Currently, in some rare cases, variables can have DECL_RTL values which
8277 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8278 elsewhere in the compiler. We treat such cases as if the variable(s) in
8279 question had been optimized out of existence. */
8281 if (is_pseudo_reg (rtl)
8282 || (GET_CODE (rtl) == MEM
8283 && is_pseudo_reg (XEXP (rtl, 0)))
8284 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8285 references the internal argument pointer (a pseudo) in a function
8286 where all references to the internal argument pointer were
8287 eliminated via the optimizers. */
8288 || (GET_CODE (rtl) == MEM
8289 && GET_CODE (XEXP (rtl, 0)) == PLUS
8290 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8291 || (GET_CODE (rtl) == CONCAT
8292 && is_pseudo_reg (XEXP (rtl, 0))
8293 && is_pseudo_reg (XEXP (rtl, 1))))
8296 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8299 /* Attach the specialized form of location attribute used for data
8300 members of struct and union types. In the special case of a
8301 FIELD_DECL node which represents a bit-field, the "offset" part
8302 of this special location descriptor must indicate the distance
8303 in bytes from the lowest-addressed byte of the containing struct
8304 or union type to the lowest-addressed byte of the "containing
8305 object" for the bit-field. (See the `field_byte_offset' function
8306 above).. For any given bit-field, the "containing object" is a
8307 hypothetical object (of some integral or enum type) within which
8308 the given bit-field lives. The type of this hypothetical
8309 "containing object" is always the same as the declared type of
8310 the individual bit-field itself (for GCC anyway... the DWARF
8311 spec doesn't actually mandate this). Note that it is the size
8312 (in bytes) of the hypothetical "containing object" which will
8313 be given in the DW_AT_byte_size attribute for this bit-field.
8314 (See the `byte_size_attribute' function below.) It is also used
8315 when calculating the value of the DW_AT_bit_offset attribute.
8316 (See the `bit_offset_attribute' function below). */
8319 add_data_member_location_attribute (die, decl)
8320 register dw_die_ref die;
8323 register unsigned long offset;
8324 register dw_loc_descr_ref loc_descr;
8325 register enum dwarf_location_atom op;
8327 if (TREE_CODE (decl) == TREE_VEC)
8328 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8330 offset = field_byte_offset (decl);
8332 /* The DWARF2 standard says that we should assume that the structure address
8333 is already on the stack, so we can specify a structure field address
8334 by using DW_OP_plus_uconst. */
8336 #ifdef MIPS_DEBUGGING_INFO
8337 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8338 correctly. It works only if we leave the offset on the stack. */
8341 op = DW_OP_plus_uconst;
8344 loc_descr = new_loc_descr (op, offset, 0);
8345 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8348 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8349 does not have a "location" either in memory or in a register. These
8350 things can arise in GNU C when a constant is passed as an actual parameter
8351 to an inlined function. They can also arise in C++ where declared
8352 constants do not necessarily get memory "homes". */
8355 add_const_value_attribute (die, rtl)
8356 register dw_die_ref die;
8359 switch (GET_CODE (rtl))
8362 /* Note that a CONST_INT rtx could represent either an integer
8363 or a floating-point constant. A CONST_INT is used whenever
8364 the constant will fit into a single word. In all such
8365 cases, the original mode of the constant value is wiped
8366 out, and the CONST_INT rtx is assigned VOIDmode. */
8368 HOST_WIDE_INT val = INTVAL (rtl);
8370 /* ??? We really should be using HOST_WIDE_INT throughout. */
8373 if ((long) val != val)
8375 add_AT_int (die, DW_AT_const_value, (long) val);
8379 if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
8381 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8387 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8388 floating-point constant. A CONST_DOUBLE is used whenever the
8389 constant requires more than one word in order to be adequately
8390 represented. We output CONST_DOUBLEs as blocks. */
8392 register enum machine_mode mode = GET_MODE (rtl);
8394 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8396 register unsigned length = GET_MODE_SIZE (mode) / 4;
8397 long *array = (long *) xmalloc (sizeof (long) * length);
8400 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8404 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8408 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8413 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8420 add_AT_float (die, DW_AT_const_value, length, array);
8424 /* ??? We really should be using HOST_WIDE_INT throughout. */
8425 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8427 add_AT_long_long (die, DW_AT_const_value,
8428 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8434 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8440 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8444 /* In cases where an inlined instance of an inline function is passed
8445 the address of an `auto' variable (which is local to the caller) we
8446 can get a situation where the DECL_RTL of the artificial local
8447 variable (for the inlining) which acts as a stand-in for the
8448 corresponding formal parameter (of the inline function) will look
8449 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8450 exactly a compile-time constant expression, but it isn't the address
8451 of the (artificial) local variable either. Rather, it represents the
8452 *value* which the artificial local variable always has during its
8453 lifetime. We currently have no way to represent such quasi-constant
8454 values in Dwarf, so for now we just punt and generate nothing. */
8458 /* No other kinds of rtx should be possible here. */
8465 rtl_for_decl_location (decl)
8470 /* Here we have to decide where we are going to say the parameter "lives"
8471 (as far as the debugger is concerned). We only have a couple of
8472 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8474 DECL_RTL normally indicates where the parameter lives during most of the
8475 activation of the function. If optimization is enabled however, this
8476 could be either NULL or else a pseudo-reg. Both of those cases indicate
8477 that the parameter doesn't really live anywhere (as far as the code
8478 generation parts of GCC are concerned) during most of the function's
8479 activation. That will happen (for example) if the parameter is never
8480 referenced within the function.
8482 We could just generate a location descriptor here for all non-NULL
8483 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8484 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8485 where DECL_RTL is NULL or is a pseudo-reg.
8487 Note however that we can only get away with using DECL_INCOMING_RTL as
8488 a backup substitute for DECL_RTL in certain limited cases. In cases
8489 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8490 we can be sure that the parameter was passed using the same type as it is
8491 declared to have within the function, and that its DECL_INCOMING_RTL
8492 points us to a place where a value of that type is passed.
8494 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8495 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8496 because in these cases DECL_INCOMING_RTL points us to a value of some
8497 type which is *different* from the type of the parameter itself. Thus,
8498 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8499 such cases, the debugger would end up (for example) trying to fetch a
8500 `float' from a place which actually contains the first part of a
8501 `double'. That would lead to really incorrect and confusing
8502 output at debug-time.
8504 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8505 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8506 are a couple of exceptions however. On little-endian machines we can
8507 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8508 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8509 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8510 when (on a little-endian machine) a non-prototyped function has a
8511 parameter declared to be of type `short' or `char'. In such cases,
8512 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8513 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8514 passed `int' value. If the debugger then uses that address to fetch
8515 a `short' or a `char' (on a little-endian machine) the result will be
8516 the correct data, so we allow for such exceptional cases below.
8518 Note that our goal here is to describe the place where the given formal
8519 parameter lives during most of the function's activation (i.e. between
8520 the end of the prologue and the start of the epilogue). We'll do that
8521 as best as we can. Note however that if the given formal parameter is
8522 modified sometime during the execution of the function, then a stack
8523 backtrace (at debug-time) will show the function as having been
8524 called with the *new* value rather than the value which was
8525 originally passed in. This happens rarely enough that it is not
8526 a major problem, but it *is* a problem, and I'd like to fix it.
8528 A future version of dwarf2out.c may generate two additional
8529 attributes for any given DW_TAG_formal_parameter DIE which will
8530 describe the "passed type" and the "passed location" for the
8531 given formal parameter in addition to the attributes we now
8532 generate to indicate the "declared type" and the "active
8533 location" for each parameter. This additional set of attributes
8534 could be used by debuggers for stack backtraces. Separately, note
8535 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8536 NULL also. This happens (for example) for inlined-instances of
8537 inline function formal parameters which are never referenced.
8538 This really shouldn't be happening. All PARM_DECL nodes should
8539 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8540 doesn't currently generate these values for inlined instances of
8541 inline function parameters, so when we see such cases, we are
8542 just out-of-luck for the time being (until integrate.c
8545 /* Use DECL_RTL as the "location" unless we find something better. */
8546 rtl = DECL_RTL_IF_SET (decl);
8548 if (TREE_CODE (decl) == PARM_DECL)
8550 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8552 tree declared_type = type_main_variant (TREE_TYPE (decl));
8553 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8555 /* This decl represents a formal parameter which was optimized out.
8556 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8557 all* cases where (rtl == NULL_RTX) just below. */
8558 if (declared_type == passed_type)
8559 rtl = DECL_INCOMING_RTL (decl);
8560 else if (! BYTES_BIG_ENDIAN
8561 && TREE_CODE (declared_type) == INTEGER_TYPE
8562 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8563 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8564 rtl = DECL_INCOMING_RTL (decl);
8567 /* If the parm was passed in registers, but lives on the stack, then
8568 make a big endian correction if the mode of the type of the
8569 parameter is not the same as the mode of the rtl. */
8570 /* ??? This is the same series of checks that are made in dbxout.c before
8571 we reach the big endian correction code there. It isn't clear if all
8572 of these checks are necessary here, but keeping them all is the safe
8574 else if (GET_CODE (rtl) == MEM
8575 && XEXP (rtl, 0) != const0_rtx
8576 && ! CONSTANT_P (XEXP (rtl, 0))
8577 /* Not passed in memory. */
8578 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8579 /* Not passed by invisible reference. */
8580 && (GET_CODE (XEXP (rtl, 0)) != REG
8581 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8582 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8583 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8584 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8587 /* Big endian correction check. */
8589 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8590 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8593 int offset = (UNITS_PER_WORD
8594 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8595 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8596 plus_constant (XEXP (rtl, 0), offset));
8600 if (rtl != NULL_RTX)
8602 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8603 #ifdef LEAF_REG_REMAP
8604 if (current_function_uses_only_leaf_regs)
8605 leaf_renumber_regs_insn (rtl);
8612 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8613 data attribute for a variable or a parameter. We generate the
8614 DW_AT_const_value attribute only in those cases where the given variable
8615 or parameter does not have a true "location" either in memory or in a
8616 register. This can happen (for example) when a constant is passed as an
8617 actual argument in a call to an inline function. (It's possible that
8618 these things can crop up in other ways also.) Note that one type of
8619 constant value which can be passed into an inlined function is a constant
8620 pointer. This can happen for example if an actual argument in an inlined
8621 function call evaluates to a compile-time constant address. */
8624 add_location_or_const_value_attribute (die, decl)
8625 register dw_die_ref die;
8630 if (TREE_CODE (decl) == ERROR_MARK)
8633 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8636 rtl = rtl_for_decl_location (decl);
8637 if (rtl == NULL_RTX)
8640 /* If we don't look past the constant pool, we risk emitting a
8641 reference to a constant pool entry that isn't referenced from
8642 code, and thus is not emitted. */
8643 rtl = avoid_constant_pool_reference (rtl);
8645 switch (GET_CODE (rtl))
8648 /* The address of a variable that was optimized away; don't emit
8659 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8660 add_const_value_attribute (die, rtl);
8667 add_AT_location_description (die, DW_AT_location, rtl);
8675 /* If we don't have a copy of this variable in memory for some reason (such
8676 as a C++ member constant that doesn't have an out-of-line definition),
8677 we should tell the debugger about the constant value. */
8680 tree_add_const_value_attribute (var_die, decl)
8684 tree init = DECL_INITIAL (decl);
8685 tree type = TREE_TYPE (decl);
8687 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8688 && initializer_constant_valid_p (init, type) == null_pointer_node)
8693 switch (TREE_CODE (type))
8696 if (host_integerp (init, 0))
8697 add_AT_unsigned (var_die, DW_AT_const_value,
8698 TREE_INT_CST_LOW (init));
8700 add_AT_long_long (var_die, DW_AT_const_value,
8701 TREE_INT_CST_HIGH (init),
8702 TREE_INT_CST_LOW (init));
8709 /* Generate an DW_AT_name attribute given some string value to be included as
8710 the value of the attribute. */
8713 add_name_attribute (die, name_string)
8714 register dw_die_ref die;
8715 register const char *name_string;
8717 if (name_string != NULL && *name_string != 0)
8719 if (demangle_name_func)
8720 name_string = (*demangle_name_func) (name_string);
8722 add_AT_string (die, DW_AT_name, name_string);
8726 /* Given a tree node describing an array bound (either lower or upper) output
8727 a representation for that bound. */
8730 add_bound_info (subrange_die, bound_attr, bound)
8731 register dw_die_ref subrange_die;
8732 register enum dwarf_attribute bound_attr;
8733 register tree bound;
8735 /* If this is an Ada unconstrained array type, then don't emit any debug
8736 info because the array bounds are unknown. They are parameterized when
8737 the type is instantiated. */
8738 if (contains_placeholder_p (bound))
8741 switch (TREE_CODE (bound))
8746 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8748 if (! host_integerp (bound, 0)
8749 || (bound_attr == DW_AT_lower_bound
8750 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8751 || (is_fortran () && integer_onep (bound)))))
8752 /* use the default */
8755 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8760 case NON_LVALUE_EXPR:
8761 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8765 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8766 access the upper bound values may be bogus. If they refer to a
8767 register, they may only describe how to get at these values at the
8768 points in the generated code right after they have just been
8769 computed. Worse yet, in the typical case, the upper bound values
8770 will not even *be* computed in the optimized code (though the
8771 number of elements will), so these SAVE_EXPRs are entirely
8772 bogus. In order to compensate for this fact, we check here to see
8773 if optimization is enabled, and if so, we don't add an attribute
8774 for the (unknown and unknowable) upper bound. This should not
8775 cause too much trouble for existing (stupid?) debuggers because
8776 they have to deal with empty upper bounds location descriptions
8777 anyway in order to be able to deal with incomplete array types.
8778 Of course an intelligent debugger (GDB?) should be able to
8779 comprehend that a missing upper bound specification in a array
8780 type used for a storage class `auto' local array variable
8781 indicates that the upper bound is both unknown (at compile- time)
8782 and unknowable (at run-time) due to optimization.
8784 We assume that a MEM rtx is safe because gcc wouldn't put the
8785 value there unless it was going to be used repeatedly in the
8786 function, i.e. for cleanups. */
8787 if (SAVE_EXPR_RTL (bound)
8788 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8790 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8791 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8792 register rtx loc = SAVE_EXPR_RTL (bound);
8794 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8795 it references an outer function's frame. */
8797 if (GET_CODE (loc) == MEM)
8799 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8801 if (XEXP (loc, 0) != new_addr)
8802 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8805 add_AT_flag (decl_die, DW_AT_artificial, 1);
8806 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8807 add_AT_location_description (decl_die, DW_AT_location, loc);
8808 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8811 /* Else leave out the attribute. */
8817 dw_die_ref decl_die = lookup_decl_die (bound);
8819 /* ??? Can this happen, or should the variable have been bound
8820 first? Probably it can, since I imagine that we try to create
8821 the types of parameters in the order in which they exist in
8822 the list, and won't have created a forward reference to a
8824 if (decl_die != NULL)
8825 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8831 /* Otherwise try to create a stack operation procedure to
8832 evaluate the value of the array bound. */
8834 dw_die_ref ctx, decl_die;
8835 dw_loc_descr_ref loc;
8837 loc = loc_descriptor_from_tree (bound, 0);
8841 ctx = lookup_decl_die (current_function_decl);
8843 decl_die = new_die (DW_TAG_variable, ctx);
8844 add_AT_flag (decl_die, DW_AT_artificial, 1);
8845 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8846 add_AT_loc (decl_die, DW_AT_location, loc);
8848 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8854 /* Note that the block of subscript information for an array type also
8855 includes information about the element type of type given array type. */
8858 add_subscript_info (type_die, type)
8859 register dw_die_ref type_die;
8862 #ifndef MIPS_DEBUGGING_INFO
8863 register unsigned dimension_number;
8865 register tree lower, upper;
8866 register dw_die_ref subrange_die;
8868 /* The GNU compilers represent multidimensional array types as sequences of
8869 one dimensional array types whose element types are themselves array
8870 types. Here we squish that down, so that each multidimensional array
8871 type gets only one array_type DIE in the Dwarf debugging info. The draft
8872 Dwarf specification say that we are allowed to do this kind of
8873 compression in C (because there is no difference between an array or
8874 arrays and a multidimensional array in C) but for other source languages
8875 (e.g. Ada) we probably shouldn't do this. */
8877 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8878 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8879 We work around this by disabling this feature. See also
8880 gen_array_type_die. */
8881 #ifndef MIPS_DEBUGGING_INFO
8882 for (dimension_number = 0;
8883 TREE_CODE (type) == ARRAY_TYPE;
8884 type = TREE_TYPE (type), dimension_number++)
8887 register tree domain = TYPE_DOMAIN (type);
8889 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8890 and (in GNU C only) variable bounds. Handle all three forms
8892 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8895 /* We have an array type with specified bounds. */
8896 lower = TYPE_MIN_VALUE (domain);
8897 upper = TYPE_MAX_VALUE (domain);
8899 /* define the index type. */
8900 if (TREE_TYPE (domain))
8902 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8903 TREE_TYPE field. We can't emit debug info for this
8904 because it is an unnamed integral type. */
8905 if (TREE_CODE (domain) == INTEGER_TYPE
8906 && TYPE_NAME (domain) == NULL_TREE
8907 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8908 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8911 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8915 /* ??? If upper is NULL, the array has unspecified length,
8916 but it does have a lower bound. This happens with Fortran
8918 Since the debugger is definitely going to need to know N
8919 to produce useful results, go ahead and output the lower
8920 bound solo, and hope the debugger can cope. */
8922 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8924 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8927 /* We have an array type with an unspecified length. The DWARF-2
8928 spec does not say how to handle this; let's just leave out the
8932 #ifndef MIPS_DEBUGGING_INFO
8938 add_byte_size_attribute (die, tree_node)
8940 register tree tree_node;
8942 register unsigned size;
8944 switch (TREE_CODE (tree_node))
8952 case QUAL_UNION_TYPE:
8953 size = int_size_in_bytes (tree_node);
8956 /* For a data member of a struct or union, the DW_AT_byte_size is
8957 generally given as the number of bytes normally allocated for an
8958 object of the *declared* type of the member itself. This is true
8959 even for bit-fields. */
8960 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8966 /* Note that `size' might be -1 when we get to this point. If it is, that
8967 indicates that the byte size of the entity in question is variable. We
8968 have no good way of expressing this fact in Dwarf at the present time,
8969 so just let the -1 pass on through. */
8971 add_AT_unsigned (die, DW_AT_byte_size, size);
8974 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8975 which specifies the distance in bits from the highest order bit of the
8976 "containing object" for the bit-field to the highest order bit of the
8979 For any given bit-field, the "containing object" is a hypothetical
8980 object (of some integral or enum type) within which the given bit-field
8981 lives. The type of this hypothetical "containing object" is always the
8982 same as the declared type of the individual bit-field itself. The
8983 determination of the exact location of the "containing object" for a
8984 bit-field is rather complicated. It's handled by the
8985 `field_byte_offset' function (above).
8987 Note that it is the size (in bytes) of the hypothetical "containing object"
8988 which will be given in the DW_AT_byte_size attribute for this bit-field.
8989 (See `byte_size_attribute' above). */
8992 add_bit_offset_attribute (die, decl)
8993 register dw_die_ref die;
8996 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8997 tree type = DECL_BIT_FIELD_TYPE (decl);
8998 HOST_WIDE_INT bitpos_int;
8999 HOST_WIDE_INT highest_order_object_bit_offset;
9000 HOST_WIDE_INT highest_order_field_bit_offset;
9001 HOST_WIDE_INT unsigned bit_offset;
9003 /* Must be a field and a bit field. */
9005 || TREE_CODE (decl) != FIELD_DECL)
9008 /* We can't yet handle bit-fields whose offsets are variable, so if we
9009 encounter such things, just return without generating any attribute
9010 whatsoever. Likewise for variable or too large size. */
9011 if (! host_integerp (bit_position (decl), 0)
9012 || ! host_integerp (DECL_SIZE (decl), 1))
9015 bitpos_int = int_bit_position (decl);
9017 /* Note that the bit offset is always the distance (in bits) from the
9018 highest-order bit of the "containing object" to the highest-order bit of
9019 the bit-field itself. Since the "high-order end" of any object or field
9020 is different on big-endian and little-endian machines, the computation
9021 below must take account of these differences. */
9022 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9023 highest_order_field_bit_offset = bitpos_int;
9025 if (! BYTES_BIG_ENDIAN)
9027 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9028 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9032 = (! BYTES_BIG_ENDIAN
9033 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9034 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9036 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9039 /* For a FIELD_DECL node which represents a bit field, output an attribute
9040 which specifies the length in bits of the given field. */
9043 add_bit_size_attribute (die, decl)
9044 register dw_die_ref die;
9047 /* Must be a field and a bit field. */
9048 if (TREE_CODE (decl) != FIELD_DECL
9049 || ! DECL_BIT_FIELD_TYPE (decl))
9052 if (host_integerp (DECL_SIZE (decl), 1))
9053 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9056 /* If the compiled language is ANSI C, then add a 'prototyped'
9057 attribute, if arg types are given for the parameters of a function. */
9060 add_prototyped_attribute (die, func_type)
9061 register dw_die_ref die;
9062 register tree func_type;
9064 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9065 && TYPE_ARG_TYPES (func_type) != NULL)
9066 add_AT_flag (die, DW_AT_prototyped, 1);
9069 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9070 by looking in either the type declaration or object declaration
9074 add_abstract_origin_attribute (die, origin)
9075 register dw_die_ref die;
9076 register tree origin;
9078 dw_die_ref origin_die = NULL;
9080 if (TREE_CODE (origin) != FUNCTION_DECL)
9082 /* We may have gotten separated from the block for the inlined
9083 function, if we're in an exception handler or some such; make
9084 sure that the abstract function has been written out.
9086 Doing this for nested functions is wrong, however; functions are
9087 distinct units, and our context might not even be inline. */
9090 fn = TYPE_STUB_DECL (fn);
9091 fn = decl_function_context (fn);
9093 dwarf2out_abstract_function (fn);
9096 if (DECL_P (origin))
9097 origin_die = lookup_decl_die (origin);
9098 else if (TYPE_P (origin))
9099 origin_die = lookup_type_die (origin);
9101 if (origin_die == NULL)
9104 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9107 /* We do not currently support the pure_virtual attribute. */
9110 add_pure_or_virtual_attribute (die, func_decl)
9111 register dw_die_ref die;
9112 register tree func_decl;
9114 if (DECL_VINDEX (func_decl))
9116 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9118 if (host_integerp (DECL_VINDEX (func_decl), 0))
9119 add_AT_loc (die, DW_AT_vtable_elem_location,
9120 new_loc_descr (DW_OP_constu,
9121 tree_low_cst (DECL_VINDEX (func_decl), 0),
9124 /* GNU extension: Record what type this method came from originally. */
9125 if (debug_info_level > DINFO_LEVEL_TERSE)
9126 add_AT_die_ref (die, DW_AT_containing_type,
9127 lookup_type_die (DECL_CONTEXT (func_decl)));
9131 /* Add source coordinate attributes for the given decl. */
9134 add_src_coords_attributes (die, decl)
9135 register dw_die_ref die;
9138 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9140 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9141 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9144 /* Add an DW_AT_name attribute and source coordinate attribute for the
9145 given decl, but only if it actually has a name. */
9148 add_name_and_src_coords_attributes (die, decl)
9149 register dw_die_ref die;
9152 register tree decl_name;
9154 decl_name = DECL_NAME (decl);
9155 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9157 add_name_attribute (die, dwarf2_name (decl, 0));
9158 if (! DECL_ARTIFICIAL (decl))
9159 add_src_coords_attributes (die, decl);
9161 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9162 && TREE_PUBLIC (decl)
9163 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9164 && !DECL_ABSTRACT (decl))
9165 add_AT_string (die, DW_AT_MIPS_linkage_name,
9166 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9170 /* Push a new declaration scope. */
9173 push_decl_scope (scope)
9176 /* Make room in the decl_scope_table, if necessary. */
9177 if (decl_scope_table_allocated == decl_scope_depth)
9179 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
9181 = (tree *) xrealloc (decl_scope_table,
9182 decl_scope_table_allocated * sizeof (tree));
9185 decl_scope_table[decl_scope_depth] = scope;
9189 /* Pop a declaration scope. */
9193 if (decl_scope_depth <= 0)
9198 /* Return the DIE for the scope that immediately contains this type.
9199 Non-named types get global scope. Named types nested in other
9200 types get their containing scope if it's open, or global scope
9201 otherwise. All other types (i.e. function-local named types) get
9202 the current active scope. */
9205 scope_die_for (t, context_die)
9207 register dw_die_ref context_die;
9209 register dw_die_ref scope_die = NULL;
9210 register tree containing_scope;
9213 /* Non-types always go in the current scope. */
9217 containing_scope = TYPE_CONTEXT (t);
9219 /* Ignore namespaces for the moment. */
9220 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9221 containing_scope = NULL_TREE;
9223 /* Ignore function type "scopes" from the C frontend. They mean that
9224 a tagged type is local to a parmlist of a function declarator, but
9225 that isn't useful to DWARF. */
9226 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9227 containing_scope = NULL_TREE;
9229 if (containing_scope == NULL_TREE)
9230 scope_die = comp_unit_die;
9231 else if (TYPE_P (containing_scope))
9233 /* For types, we can just look up the appropriate DIE. But
9234 first we check to see if we're in the middle of emitting it
9235 so we know where the new DIE should go. */
9237 for (i = decl_scope_depth - 1; i >= 0; --i)
9238 if (decl_scope_table[i] == containing_scope)
9243 if (debug_info_level > DINFO_LEVEL_TERSE
9244 && !TREE_ASM_WRITTEN (containing_scope))
9247 /* If none of the current dies are suitable, we get file scope. */
9248 scope_die = comp_unit_die;
9251 scope_die = lookup_type_die (containing_scope);
9254 scope_die = context_die;
9259 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9261 static inline int local_scope_p PARAMS ((dw_die_ref));
9263 local_scope_p (context_die)
9264 dw_die_ref context_die;
9266 for (; context_die; context_die = context_die->die_parent)
9267 if (context_die->die_tag == DW_TAG_inlined_subroutine
9268 || context_die->die_tag == DW_TAG_subprogram)
9273 /* Returns nonzero iff CONTEXT_DIE is a class. */
9275 static inline int class_scope_p PARAMS ((dw_die_ref));
9277 class_scope_p (context_die)
9278 dw_die_ref context_die;
9281 && (context_die->die_tag == DW_TAG_structure_type
9282 || context_die->die_tag == DW_TAG_union_type));
9285 /* Many forms of DIEs require a "type description" attribute. This
9286 routine locates the proper "type descriptor" die for the type given
9287 by 'type', and adds an DW_AT_type attribute below the given die. */
9290 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9291 register dw_die_ref object_die;
9293 register int decl_const;
9294 register int decl_volatile;
9295 register dw_die_ref context_die;
9297 register enum tree_code code = TREE_CODE (type);
9298 register dw_die_ref type_die = NULL;
9300 /* ??? If this type is an unnamed subrange type of an integral or
9301 floating-point type, use the inner type. This is because we have no
9302 support for unnamed types in base_type_die. This can happen if this is
9303 an Ada subrange type. Correct solution is emit a subrange type die. */
9304 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9305 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9306 type = TREE_TYPE (type), code = TREE_CODE (type);
9308 if (code == ERROR_MARK)
9311 /* Handle a special case. For functions whose return type is void, we
9312 generate *no* type attribute. (Note that no object may have type
9313 `void', so this only applies to function return types). */
9314 if (code == VOID_TYPE)
9317 type_die = modified_type_die (type,
9318 decl_const || TYPE_READONLY (type),
9319 decl_volatile || TYPE_VOLATILE (type),
9321 if (type_die != NULL)
9322 add_AT_die_ref (object_die, DW_AT_type, type_die);
9325 /* Given a tree pointer to a struct, class, union, or enum type node, return
9326 a pointer to the (string) tag name for the given type, or zero if the type
9327 was declared without a tag. */
9333 register const char *name = 0;
9335 if (TYPE_NAME (type) != 0)
9337 register tree t = 0;
9339 /* Find the IDENTIFIER_NODE for the type name. */
9340 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9341 t = TYPE_NAME (type);
9343 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9344 a TYPE_DECL node, regardless of whether or not a `typedef' was
9346 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9347 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9348 t = DECL_NAME (TYPE_NAME (type));
9350 /* Now get the name as a string, or invent one. */
9352 name = IDENTIFIER_POINTER (t);
9355 return (name == 0 || *name == '\0') ? 0 : name;
9358 /* Return the type associated with a data member, make a special check
9359 for bit field types. */
9362 member_declared_type (member)
9363 register tree member;
9365 return (DECL_BIT_FIELD_TYPE (member)
9366 ? DECL_BIT_FIELD_TYPE (member)
9367 : TREE_TYPE (member));
9370 /* Get the decl's label, as described by its RTL. This may be different
9371 from the DECL_NAME name used in the source file. */
9375 decl_start_label (decl)
9380 x = DECL_RTL (decl);
9381 if (GET_CODE (x) != MEM)
9385 if (GET_CODE (x) != SYMBOL_REF)
9388 fnname = XSTR (x, 0);
9393 /* These routines generate the internal representation of the DIE's for
9394 the compilation unit. Debugging information is collected by walking
9395 the declaration trees passed in from dwarf2out_decl(). */
9398 gen_array_type_die (type, context_die)
9400 register dw_die_ref context_die;
9402 register dw_die_ref scope_die = scope_die_for (type, context_die);
9403 register dw_die_ref array_die;
9404 register tree element_type;
9406 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9407 the inner array type comes before the outer array type. Thus we must
9408 call gen_type_die before we call new_die. See below also. */
9409 #ifdef MIPS_DEBUGGING_INFO
9410 gen_type_die (TREE_TYPE (type), context_die);
9413 array_die = new_die (DW_TAG_array_type, scope_die);
9416 /* We default the array ordering. SDB will probably do
9417 the right things even if DW_AT_ordering is not present. It's not even
9418 an issue until we start to get into multidimensional arrays anyway. If
9419 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9420 then we'll have to put the DW_AT_ordering attribute back in. (But if
9421 and when we find out that we need to put these in, we will only do so
9422 for multidimensional arrays. */
9423 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9426 #ifdef MIPS_DEBUGGING_INFO
9427 /* The SGI compilers handle arrays of unknown bound by setting
9428 AT_declaration and not emitting any subrange DIEs. */
9429 if (! TYPE_DOMAIN (type))
9430 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9433 add_subscript_info (array_die, type);
9435 add_name_attribute (array_die, type_tag (type));
9436 equate_type_number_to_die (type, array_die);
9438 /* Add representation of the type of the elements of this array type. */
9439 element_type = TREE_TYPE (type);
9441 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9442 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9443 We work around this by disabling this feature. See also
9444 add_subscript_info. */
9445 #ifndef MIPS_DEBUGGING_INFO
9446 while (TREE_CODE (element_type) == ARRAY_TYPE)
9447 element_type = TREE_TYPE (element_type);
9449 gen_type_die (element_type, context_die);
9452 add_type_attribute (array_die, element_type, 0, 0, context_die);
9456 gen_set_type_die (type, context_die)
9458 register dw_die_ref context_die;
9460 register dw_die_ref type_die
9461 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9463 equate_type_number_to_die (type, type_die);
9464 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9469 gen_entry_point_die (decl, context_die)
9471 register dw_die_ref context_die;
9473 register tree origin = decl_ultimate_origin (decl);
9474 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9476 add_abstract_origin_attribute (decl_die, origin);
9479 add_name_and_src_coords_attributes (decl_die, decl);
9480 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9484 if (DECL_ABSTRACT (decl))
9485 equate_decl_number_to_die (decl, decl_die);
9487 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9491 /* Remember a type in the incomplete_types_list. */
9494 add_incomplete_type (type)
9497 if (incomplete_types == incomplete_types_allocated)
9499 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9500 incomplete_types_list
9501 = (tree *) xrealloc (incomplete_types_list,
9502 sizeof (tree) * incomplete_types_allocated);
9505 incomplete_types_list[incomplete_types++] = type;
9508 /* Walk through the list of incomplete types again, trying once more to
9509 emit full debugging info for them. */
9512 retry_incomplete_types ()
9516 while (incomplete_types)
9519 type = incomplete_types_list[incomplete_types];
9520 gen_type_die (type, comp_unit_die);
9524 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9527 gen_inlined_enumeration_type_die (type, context_die)
9529 register dw_die_ref context_die;
9531 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9533 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9534 be incomplete and such types are not marked. */
9535 add_abstract_origin_attribute (type_die, type);
9538 /* Generate a DIE to represent an inlined instance of a structure type. */
9541 gen_inlined_structure_type_die (type, context_die)
9543 register dw_die_ref context_die;
9545 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9547 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9548 be incomplete and such types are not marked. */
9549 add_abstract_origin_attribute (type_die, type);
9552 /* Generate a DIE to represent an inlined instance of a union type. */
9555 gen_inlined_union_type_die (type, context_die)
9557 register dw_die_ref context_die;
9559 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9561 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9562 be incomplete and such types are not marked. */
9563 add_abstract_origin_attribute (type_die, type);
9566 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9567 include all of the information about the enumeration values also. Each
9568 enumerated type name/value is listed as a child of the enumerated type
9572 gen_enumeration_type_die (type, context_die)
9574 register dw_die_ref context_die;
9576 register dw_die_ref type_die = lookup_type_die (type);
9578 if (type_die == NULL)
9580 type_die = new_die (DW_TAG_enumeration_type,
9581 scope_die_for (type, context_die));
9582 equate_type_number_to_die (type, type_die);
9583 add_name_attribute (type_die, type_tag (type));
9585 else if (! TYPE_SIZE (type))
9588 remove_AT (type_die, DW_AT_declaration);
9590 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9591 given enum type is incomplete, do not generate the DW_AT_byte_size
9592 attribute or the DW_AT_element_list attribute. */
9593 if (TYPE_SIZE (type))
9597 TREE_ASM_WRITTEN (type) = 1;
9598 add_byte_size_attribute (type_die, type);
9599 if (TYPE_STUB_DECL (type) != NULL_TREE)
9600 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9602 /* If the first reference to this type was as the return type of an
9603 inline function, then it may not have a parent. Fix this now. */
9604 if (type_die->die_parent == NULL)
9605 add_child_die (scope_die_for (type, context_die), type_die);
9607 for (link = TYPE_FIELDS (type);
9608 link != NULL; link = TREE_CHAIN (link))
9610 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9612 add_name_attribute (enum_die,
9613 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9615 if (host_integerp (TREE_VALUE (link), 0))
9617 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9618 add_AT_int (enum_die, DW_AT_const_value,
9619 tree_low_cst (TREE_VALUE (link), 0));
9621 add_AT_unsigned (enum_die, DW_AT_const_value,
9622 tree_low_cst (TREE_VALUE (link), 0));
9627 add_AT_flag (type_die, DW_AT_declaration, 1);
9630 /* Generate a DIE to represent either a real live formal parameter decl or to
9631 represent just the type of some formal parameter position in some function
9634 Note that this routine is a bit unusual because its argument may be a
9635 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9636 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9637 node. If it's the former then this function is being called to output a
9638 DIE to represent a formal parameter object (or some inlining thereof). If
9639 it's the latter, then this function is only being called to output a
9640 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9641 argument type of some subprogram type. */
9644 gen_formal_parameter_die (node, context_die)
9646 register dw_die_ref context_die;
9648 register dw_die_ref parm_die
9649 = new_die (DW_TAG_formal_parameter, context_die);
9650 register tree origin;
9652 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9655 origin = decl_ultimate_origin (node);
9657 add_abstract_origin_attribute (parm_die, origin);
9660 add_name_and_src_coords_attributes (parm_die, node);
9661 add_type_attribute (parm_die, TREE_TYPE (node),
9662 TREE_READONLY (node),
9663 TREE_THIS_VOLATILE (node),
9665 if (DECL_ARTIFICIAL (node))
9666 add_AT_flag (parm_die, DW_AT_artificial, 1);
9669 equate_decl_number_to_die (node, parm_die);
9670 if (! DECL_ABSTRACT (node))
9671 add_location_or_const_value_attribute (parm_die, node);
9676 /* We were called with some kind of a ..._TYPE node. */
9677 add_type_attribute (parm_die, node, 0, 0, context_die);
9687 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9688 at the end of an (ANSI prototyped) formal parameters list. */
9691 gen_unspecified_parameters_die (decl_or_type, context_die)
9692 register tree decl_or_type ATTRIBUTE_UNUSED;
9693 register dw_die_ref context_die;
9695 new_die (DW_TAG_unspecified_parameters, context_die);
9698 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9699 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9700 parameters as specified in some function type specification (except for
9701 those which appear as part of a function *definition*). */
9704 gen_formal_types_die (function_or_method_type, context_die)
9705 register tree function_or_method_type;
9706 register dw_die_ref context_die;
9709 register tree formal_type = NULL;
9710 register tree first_parm_type;
9713 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9715 arg = DECL_ARGUMENTS (function_or_method_type);
9716 function_or_method_type = TREE_TYPE (function_or_method_type);
9721 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9723 /* Make our first pass over the list of formal parameter types and output a
9724 DW_TAG_formal_parameter DIE for each one. */
9725 for (link = first_parm_type; link; )
9727 register dw_die_ref parm_die;
9729 formal_type = TREE_VALUE (link);
9730 if (formal_type == void_type_node)
9733 /* Output a (nameless) DIE to represent the formal parameter itself. */
9734 parm_die = gen_formal_parameter_die (formal_type, context_die);
9735 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9736 && link == first_parm_type)
9737 || (arg && DECL_ARTIFICIAL (arg)))
9738 add_AT_flag (parm_die, DW_AT_artificial, 1);
9740 link = TREE_CHAIN (link);
9742 arg = TREE_CHAIN (arg);
9745 /* If this function type has an ellipsis, add a
9746 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9747 if (formal_type != void_type_node)
9748 gen_unspecified_parameters_die (function_or_method_type, context_die);
9750 /* Make our second (and final) pass over the list of formal parameter types
9751 and output DIEs to represent those types (as necessary). */
9752 for (link = TYPE_ARG_TYPES (function_or_method_type);
9754 link = TREE_CHAIN (link))
9756 formal_type = TREE_VALUE (link);
9757 if (formal_type == void_type_node)
9760 gen_type_die (formal_type, context_die);
9764 /* We want to generate the DIE for TYPE so that we can generate the
9765 die for MEMBER, which has been defined; we will need to refer back
9766 to the member declaration nested within TYPE. If we're trying to
9767 generate minimal debug info for TYPE, processing TYPE won't do the
9768 trick; we need to attach the member declaration by hand. */
9771 gen_type_die_for_member (type, member, context_die)
9773 dw_die_ref context_die;
9775 gen_type_die (type, context_die);
9777 /* If we're trying to avoid duplicate debug info, we may not have
9778 emitted the member decl for this function. Emit it now. */
9779 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9780 && ! lookup_decl_die (member))
9782 if (decl_ultimate_origin (member))
9785 push_decl_scope (type);
9786 if (TREE_CODE (member) == FUNCTION_DECL)
9787 gen_subprogram_die (member, lookup_type_die (type));
9789 gen_variable_die (member, lookup_type_die (type));
9794 /* Generate the DWARF2 info for the "abstract" instance
9795 of a function which we may later generate inlined and/or
9796 out-of-line instances of. */
9799 dwarf2out_abstract_function (decl)
9802 register dw_die_ref old_die;
9805 int was_abstract = DECL_ABSTRACT (decl);
9807 /* Make sure we have the actual abstract inline, not a clone. */
9808 decl = DECL_ORIGIN (decl);
9810 old_die = lookup_decl_die (decl);
9811 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9812 /* We've already generated the abstract instance. */
9815 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9816 we don't get confused by DECL_ABSTRACT. */
9817 if (debug_info_level > DINFO_LEVEL_TERSE)
9819 context = decl_class_context (decl);
9821 gen_type_die_for_member
9822 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9825 /* Pretend we've just finished compiling this function. */
9826 save_fn = current_function_decl;
9827 current_function_decl = decl;
9829 set_decl_abstract_flags (decl, 1);
9830 dwarf2out_decl (decl);
9832 set_decl_abstract_flags (decl, 0);
9834 current_function_decl = save_fn;
9837 /* Generate a DIE to represent a declared function (either file-scope or
9841 gen_subprogram_die (decl, context_die)
9843 register dw_die_ref context_die;
9845 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9846 register tree origin = decl_ultimate_origin (decl);
9847 register dw_die_ref subr_die;
9848 register rtx fp_reg;
9849 register tree fn_arg_types;
9850 register tree outer_scope;
9851 register dw_die_ref old_die = lookup_decl_die (decl);
9852 register int declaration = (current_function_decl != decl
9853 || class_scope_p (context_die));
9855 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9856 be true, if we started to generate the abstract instance of an inline,
9857 decided to output its containing class, and proceeded to emit the
9858 declaration of the inline from the member list for the class. In that
9859 case, `declaration' takes priority; we'll get back to the abstract
9860 instance when we're done with the class. */
9862 /* The class-scope declaration DIE must be the primary DIE. */
9863 if (origin && declaration && class_scope_p (context_die))
9872 if (declaration && ! local_scope_p (context_die))
9875 /* Fixup die_parent for the abstract instance of a nested
9877 if (old_die && old_die->die_parent == NULL)
9878 add_child_die (context_die, old_die);
9880 subr_die = new_die (DW_TAG_subprogram, context_die);
9881 add_abstract_origin_attribute (subr_die, origin);
9885 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9887 if (!get_AT_flag (old_die, DW_AT_declaration)
9888 /* We can have a normal definition following an inline one in the
9889 case of redefinition of GNU C extern inlines.
9890 It seems reasonable to use AT_specification in this case. */
9891 && !get_AT_unsigned (old_die, DW_AT_inline))
9893 /* ??? This can happen if there is a bug in the program, for
9894 instance, if it has duplicate function definitions. Ideally,
9895 we should detect this case and ignore it. For now, if we have
9896 already reported an error, any error at all, then assume that
9897 we got here because of a input error, not a dwarf2 bug. */
9903 /* If the definition comes from the same place as the declaration,
9904 maybe use the old DIE. We always want the DIE for this function
9905 that has the *_pc attributes to be under comp_unit_die so the
9906 debugger can find it. We also need to do this for abstract
9907 instances of inlines, since the spec requires the out-of-line copy
9908 to have the same parent. For local class methods, this doesn't
9909 apply; we just use the old DIE. */
9910 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9911 && (DECL_ARTIFICIAL (decl)
9912 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9913 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9914 == (unsigned) DECL_SOURCE_LINE (decl)))))
9918 /* Clear out the declaration attribute and the parm types. */
9919 remove_AT (subr_die, DW_AT_declaration);
9920 remove_children (subr_die);
9924 subr_die = new_die (DW_TAG_subprogram, context_die);
9925 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9926 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9927 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9928 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9929 != (unsigned) DECL_SOURCE_LINE (decl))
9931 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9936 subr_die = new_die (DW_TAG_subprogram, context_die);
9938 if (TREE_PUBLIC (decl))
9939 add_AT_flag (subr_die, DW_AT_external, 1);
9941 add_name_and_src_coords_attributes (subr_die, decl);
9942 if (debug_info_level > DINFO_LEVEL_TERSE)
9944 register tree type = TREE_TYPE (decl);
9946 add_prototyped_attribute (subr_die, type);
9947 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9950 add_pure_or_virtual_attribute (subr_die, decl);
9951 if (DECL_ARTIFICIAL (decl))
9952 add_AT_flag (subr_die, DW_AT_artificial, 1);
9953 if (TREE_PROTECTED (decl))
9954 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9955 else if (TREE_PRIVATE (decl))
9956 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9961 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9963 add_AT_flag (subr_die, DW_AT_declaration, 1);
9965 /* The first time we see a member function, it is in the context of
9966 the class to which it belongs. We make sure of this by emitting
9967 the class first. The next time is the definition, which is
9968 handled above. The two may come from the same source text. */
9969 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9970 equate_decl_number_to_die (decl, subr_die);
9973 else if (DECL_ABSTRACT (decl))
9975 if (DECL_INLINE (decl) && !flag_no_inline)
9977 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9978 inline functions, but not for extern inline functions.
9979 We can't get this completely correct because information
9980 about whether the function was declared inline is not
9982 if (DECL_DEFER_OUTPUT (decl))
9983 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9985 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9988 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9990 equate_decl_number_to_die (decl, subr_die);
9992 else if (!DECL_EXTERNAL (decl))
9994 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9995 equate_decl_number_to_die (decl, subr_die);
9997 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9998 current_funcdef_number);
9999 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10000 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10001 current_funcdef_number);
10002 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10004 add_pubname (decl, subr_die);
10005 add_arange (decl, subr_die);
10007 #ifdef MIPS_DEBUGGING_INFO
10008 /* Add a reference to the FDE for this routine. */
10009 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10012 /* Define the "frame base" location for this routine. We use the
10013 frame pointer or stack pointer registers, since the RTL for local
10014 variables is relative to one of them. */
10016 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10017 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10020 /* ??? This fails for nested inline functions, because context_display
10021 is not part of the state saved/restored for inline functions. */
10022 if (current_function_needs_context)
10023 add_AT_location_description (subr_die, DW_AT_static_link,
10024 lookup_static_chain (decl));
10028 /* Now output descriptions of the arguments for this function. This gets
10029 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10030 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10031 `...' at the end of the formal parameter list. In order to find out if
10032 there was a trailing ellipsis or not, we must instead look at the type
10033 associated with the FUNCTION_DECL. This will be a node of type
10034 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10035 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10036 an ellipsis at the end. */
10038 /* In the case where we are describing a mere function declaration, all we
10039 need to do here (and all we *can* do here) is to describe the *types* of
10040 its formal parameters. */
10041 if (debug_info_level <= DINFO_LEVEL_TERSE)
10043 else if (declaration)
10044 gen_formal_types_die (decl, subr_die);
10047 /* Generate DIEs to represent all known formal parameters */
10048 register tree arg_decls = DECL_ARGUMENTS (decl);
10049 register tree parm;
10051 /* When generating DIEs, generate the unspecified_parameters DIE
10052 instead if we come across the arg "__builtin_va_alist" */
10053 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10054 if (TREE_CODE (parm) == PARM_DECL)
10056 if (DECL_NAME (parm)
10057 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10058 "__builtin_va_alist"))
10059 gen_unspecified_parameters_die (parm, subr_die);
10061 gen_decl_die (parm, subr_die);
10064 /* Decide whether we need a unspecified_parameters DIE at the end.
10065 There are 2 more cases to do this for: 1) the ansi ... declaration -
10066 this is detectable when the end of the arg list is not a
10067 void_type_node 2) an unprototyped function declaration (not a
10068 definition). This just means that we have no info about the
10069 parameters at all. */
10070 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10071 if (fn_arg_types != NULL)
10073 /* this is the prototyped case, check for ... */
10074 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10075 gen_unspecified_parameters_die (decl, subr_die);
10077 else if (DECL_INITIAL (decl) == NULL_TREE)
10078 gen_unspecified_parameters_die (decl, subr_die);
10081 /* Output Dwarf info for all of the stuff within the body of the function
10082 (if it has one - it may be just a declaration). */
10083 outer_scope = DECL_INITIAL (decl);
10085 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
10086 node created to represent a function. This outermost BLOCK actually
10087 represents the outermost binding contour for the function, i.e. the
10088 contour in which the function's formal parameters and labels get
10089 declared. Curiously, it appears that the front end doesn't actually
10090 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
10091 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
10092 list for the function instead.) The BLOCK_VARS list for the
10093 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
10094 the function however, and we output DWARF info for those in
10095 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
10096 node representing the function's outermost pair of curly braces, and
10097 any blocks used for the base and member initializers of a C++
10098 constructor function. */
10099 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10101 current_function_has_inlines = 0;
10102 decls_for_scope (outer_scope, subr_die, 0);
10104 #if 0 && defined (MIPS_DEBUGGING_INFO)
10105 if (current_function_has_inlines)
10107 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10108 if (! comp_unit_has_inlines)
10110 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10111 comp_unit_has_inlines = 1;
10118 /* Generate a DIE to represent a declared data object. */
10121 gen_variable_die (decl, context_die)
10122 register tree decl;
10123 register dw_die_ref context_die;
10125 register tree origin = decl_ultimate_origin (decl);
10126 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
10128 dw_die_ref old_die = lookup_decl_die (decl);
10129 int declaration = (DECL_EXTERNAL (decl)
10130 || class_scope_p (context_die));
10132 if (origin != NULL)
10133 add_abstract_origin_attribute (var_die, origin);
10134 /* Loop unrolling can create multiple blocks that refer to the same
10135 static variable, so we must test for the DW_AT_declaration flag. */
10136 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10137 copy decls and set the DECL_ABSTRACT flag on them instead of
10139 /* ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10140 else if (old_die && TREE_STATIC (decl)
10141 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10143 /* This is a definition of a C++ class level static. */
10144 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10145 if (DECL_NAME (decl))
10147 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10149 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10150 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10152 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10153 != (unsigned) DECL_SOURCE_LINE (decl))
10155 add_AT_unsigned (var_die, DW_AT_decl_line,
10156 DECL_SOURCE_LINE (decl));
10161 add_name_and_src_coords_attributes (var_die, decl);
10162 add_type_attribute (var_die, TREE_TYPE (decl),
10163 TREE_READONLY (decl),
10164 TREE_THIS_VOLATILE (decl), context_die);
10166 if (TREE_PUBLIC (decl))
10167 add_AT_flag (var_die, DW_AT_external, 1);
10169 if (DECL_ARTIFICIAL (decl))
10170 add_AT_flag (var_die, DW_AT_artificial, 1);
10172 if (TREE_PROTECTED (decl))
10173 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10175 else if (TREE_PRIVATE (decl))
10176 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10180 add_AT_flag (var_die, DW_AT_declaration, 1);
10182 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10183 equate_decl_number_to_die (decl, var_die);
10185 if (! declaration && ! DECL_ABSTRACT (decl))
10187 add_location_or_const_value_attribute (var_die, decl);
10188 add_pubname (decl, var_die);
10191 tree_add_const_value_attribute (var_die, decl);
10194 /* Generate a DIE to represent a label identifier. */
10197 gen_label_die (decl, context_die)
10198 register tree decl;
10199 register dw_die_ref context_die;
10201 register tree origin = decl_ultimate_origin (decl);
10202 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10204 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10206 if (origin != NULL)
10207 add_abstract_origin_attribute (lbl_die, origin);
10209 add_name_and_src_coords_attributes (lbl_die, decl);
10211 if (DECL_ABSTRACT (decl))
10212 equate_decl_number_to_die (decl, lbl_die);
10215 insn = DECL_RTL (decl);
10217 /* Deleted labels are programmer specified labels which have been
10218 eliminated because of various optimisations. We still emit them
10219 here so that it is possible to put breakpoints on them. */
10220 if (GET_CODE (insn) == CODE_LABEL
10221 || ((GET_CODE (insn) == NOTE
10222 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10224 /* When optimization is enabled (via -O) some parts of the compiler
10225 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10226 represent source-level labels which were explicitly declared by
10227 the user. This really shouldn't be happening though, so catch
10228 it if it ever does happen. */
10229 if (INSN_DELETED_P (insn))
10232 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10233 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10238 /* Generate a DIE for a lexical block. */
10241 gen_lexical_block_die (stmt, context_die, depth)
10242 register tree stmt;
10243 register dw_die_ref context_die;
10246 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10247 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10249 if (! BLOCK_ABSTRACT (stmt))
10251 if (BLOCK_FRAGMENT_CHAIN (stmt))
10255 add_AT_offset (stmt_die, DW_AT_ranges, add_ranges (stmt));
10257 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10260 add_ranges (chain);
10261 chain = BLOCK_FRAGMENT_CHAIN (chain);
10268 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10269 BLOCK_NUMBER (stmt));
10270 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10271 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10272 BLOCK_NUMBER (stmt));
10273 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10277 decls_for_scope (stmt, stmt_die, depth);
10280 /* Generate a DIE for an inlined subprogram. */
10283 gen_inlined_subroutine_die (stmt, context_die, depth)
10284 register tree stmt;
10285 register dw_die_ref context_die;
10288 if (! BLOCK_ABSTRACT (stmt))
10290 register dw_die_ref subr_die
10291 = new_die (DW_TAG_inlined_subroutine, context_die);
10292 register tree decl = block_ultimate_origin (stmt);
10293 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10295 /* Emit info for the abstract instance first, if we haven't yet. */
10296 dwarf2out_abstract_function (decl);
10298 add_abstract_origin_attribute (subr_die, decl);
10299 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10300 BLOCK_NUMBER (stmt));
10301 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10302 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10303 BLOCK_NUMBER (stmt));
10304 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10305 decls_for_scope (stmt, subr_die, depth);
10306 current_function_has_inlines = 1;
10310 /* Generate a DIE for a field in a record, or structure. */
10313 gen_field_die (decl, context_die)
10314 register tree decl;
10315 register dw_die_ref context_die;
10317 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10319 add_name_and_src_coords_attributes (decl_die, decl);
10320 add_type_attribute (decl_die, member_declared_type (decl),
10321 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10324 /* If this is a bit field... */
10325 if (DECL_BIT_FIELD_TYPE (decl))
10327 add_byte_size_attribute (decl_die, decl);
10328 add_bit_size_attribute (decl_die, decl);
10329 add_bit_offset_attribute (decl_die, decl);
10332 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10333 add_data_member_location_attribute (decl_die, decl);
10335 if (DECL_ARTIFICIAL (decl))
10336 add_AT_flag (decl_die, DW_AT_artificial, 1);
10338 if (TREE_PROTECTED (decl))
10339 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10341 else if (TREE_PRIVATE (decl))
10342 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10346 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10347 Use modified_type_die instead.
10348 We keep this code here just in case these types of DIEs may be needed to
10349 represent certain things in other languages (e.g. Pascal) someday. */
10351 gen_pointer_type_die (type, context_die)
10352 register tree type;
10353 register dw_die_ref context_die;
10355 register dw_die_ref ptr_die
10356 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10358 equate_type_number_to_die (type, ptr_die);
10359 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10360 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10363 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10364 Use modified_type_die instead.
10365 We keep this code here just in case these types of DIEs may be needed to
10366 represent certain things in other languages (e.g. Pascal) someday. */
10368 gen_reference_type_die (type, context_die)
10369 register tree type;
10370 register dw_die_ref context_die;
10372 register dw_die_ref ref_die
10373 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10375 equate_type_number_to_die (type, ref_die);
10376 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10377 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10381 /* Generate a DIE for a pointer to a member type. */
10383 gen_ptr_to_mbr_type_die (type, context_die)
10384 register tree type;
10385 register dw_die_ref context_die;
10387 register dw_die_ref ptr_die
10388 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10390 equate_type_number_to_die (type, ptr_die);
10391 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10392 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10393 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10396 /* Generate the DIE for the compilation unit. */
10399 gen_compile_unit_die (filename)
10400 register const char *filename;
10402 register dw_die_ref die;
10403 char producer[250];
10404 const char *wd = getpwd ();
10407 die = new_die (DW_TAG_compile_unit, NULL);
10408 add_name_attribute (die, filename);
10410 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10411 add_AT_string (die, DW_AT_comp_dir, wd);
10413 sprintf (producer, "%s %s", language_string, version_string);
10415 #ifdef MIPS_DEBUGGING_INFO
10416 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10417 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10418 not appear in the producer string, the debugger reaches the conclusion
10419 that the object file is stripped and has no debugging information.
10420 To get the MIPS/SGI debugger to believe that there is debugging
10421 information in the object file, we add a -g to the producer string. */
10422 if (debug_info_level > DINFO_LEVEL_TERSE)
10423 strcat (producer, " -g");
10426 add_AT_string (die, DW_AT_producer, producer);
10428 if (strcmp (language_string, "GNU C++") == 0)
10429 language = DW_LANG_C_plus_plus;
10430 else if (strcmp (language_string, "GNU Ada") == 0)
10431 language = DW_LANG_Ada83;
10432 else if (strcmp (language_string, "GNU F77") == 0)
10433 language = DW_LANG_Fortran77;
10434 else if (strcmp (language_string, "GNU Pascal") == 0)
10435 language = DW_LANG_Pascal83;
10436 else if (strcmp (language_string, "GNU Java") == 0)
10437 language = DW_LANG_Java;
10438 else if (flag_traditional)
10439 language = DW_LANG_C;
10441 language = DW_LANG_C89;
10443 add_AT_unsigned (die, DW_AT_language, language);
10448 /* Generate a DIE for a string type. */
10451 gen_string_type_die (type, context_die)
10452 register tree type;
10453 register dw_die_ref context_die;
10455 register dw_die_ref type_die
10456 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10458 equate_type_number_to_die (type, type_die);
10460 /* Fudge the string length attribute for now. */
10462 /* TODO: add string length info.
10463 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10464 bound_representation (upper_bound, 0, 'u'); */
10467 /* Generate the DIE for a base class. */
10470 gen_inheritance_die (binfo, context_die)
10471 register tree binfo;
10472 register dw_die_ref context_die;
10474 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10476 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10477 add_data_member_location_attribute (die, binfo);
10479 if (TREE_VIA_VIRTUAL (binfo))
10480 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10481 if (TREE_VIA_PUBLIC (binfo))
10482 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10483 else if (TREE_VIA_PROTECTED (binfo))
10484 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10487 /* Generate a DIE for a class member. */
10490 gen_member_die (type, context_die)
10491 register tree type;
10492 register dw_die_ref context_die;
10494 register tree member;
10497 /* If this is not an incomplete type, output descriptions of each of its
10498 members. Note that as we output the DIEs necessary to represent the
10499 members of this record or union type, we will also be trying to output
10500 DIEs to represent the *types* of those members. However the `type'
10501 function (above) will specifically avoid generating type DIEs for member
10502 types *within* the list of member DIEs for this (containing) type execpt
10503 for those types (of members) which are explicitly marked as also being
10504 members of this (containing) type themselves. The g++ front- end can
10505 force any given type to be treated as a member of some other
10506 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10507 to point to the TREE node representing the appropriate (containing)
10510 /* First output info about the base classes. */
10511 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10513 register tree bases = TYPE_BINFO_BASETYPES (type);
10514 register int n_bases = TREE_VEC_LENGTH (bases);
10517 for (i = 0; i < n_bases; i++)
10518 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10521 /* Now output info about the data members and type members. */
10522 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10524 /* If we thought we were generating minimal debug info for TYPE
10525 and then changed our minds, some of the member declarations
10526 may have already been defined. Don't define them again, but
10527 do put them in the right order. */
10529 child = lookup_decl_die (member);
10531 splice_child_die (context_die, child);
10533 gen_decl_die (member, context_die);
10536 /* Now output info about the function members (if any). */
10537 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10539 /* Don't include clones in the member list. */
10540 if (DECL_ABSTRACT_ORIGIN (member))
10543 child = lookup_decl_die (member);
10545 splice_child_die (context_die, child);
10547 gen_decl_die (member, context_die);
10551 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10552 is set, we pretend that the type was never defined, so we only get the
10553 member DIEs needed by later specification DIEs. */
10556 gen_struct_or_union_type_die (type, context_die)
10557 register tree type;
10558 register dw_die_ref context_die;
10560 register dw_die_ref type_die = lookup_type_die (type);
10561 register dw_die_ref scope_die = 0;
10562 register int nested = 0;
10563 int complete = (TYPE_SIZE (type)
10564 && (! TYPE_STUB_DECL (type)
10565 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10567 if (type_die && ! complete)
10570 if (TYPE_CONTEXT (type) != NULL_TREE
10571 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10574 scope_die = scope_die_for (type, context_die);
10576 if (! type_die || (nested && scope_die == comp_unit_die))
10577 /* First occurrence of type or toplevel definition of nested class. */
10579 register dw_die_ref old_die = type_die;
10581 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10582 ? DW_TAG_structure_type : DW_TAG_union_type,
10584 equate_type_number_to_die (type, type_die);
10586 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10588 add_name_attribute (type_die, type_tag (type));
10591 remove_AT (type_die, DW_AT_declaration);
10593 /* If this type has been completed, then give it a byte_size attribute and
10594 then give a list of members. */
10597 /* Prevent infinite recursion in cases where the type of some member of
10598 this type is expressed in terms of this type itself. */
10599 TREE_ASM_WRITTEN (type) = 1;
10600 add_byte_size_attribute (type_die, type);
10601 if (TYPE_STUB_DECL (type) != NULL_TREE)
10602 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10604 /* If the first reference to this type was as the return type of an
10605 inline function, then it may not have a parent. Fix this now. */
10606 if (type_die->die_parent == NULL)
10607 add_child_die (scope_die, type_die);
10609 push_decl_scope (type);
10610 gen_member_die (type, type_die);
10613 /* GNU extension: Record what type our vtable lives in. */
10614 if (TYPE_VFIELD (type))
10616 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10618 gen_type_die (vtype, context_die);
10619 add_AT_die_ref (type_die, DW_AT_containing_type,
10620 lookup_type_die (vtype));
10625 add_AT_flag (type_die, DW_AT_declaration, 1);
10627 /* We don't need to do this for function-local types. */
10628 if (! decl_function_context (TYPE_STUB_DECL (type)))
10629 add_incomplete_type (type);
10633 /* Generate a DIE for a subroutine _type_. */
10636 gen_subroutine_type_die (type, context_die)
10637 register tree type;
10638 register dw_die_ref context_die;
10640 register tree return_type = TREE_TYPE (type);
10641 register dw_die_ref subr_die
10642 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10644 equate_type_number_to_die (type, subr_die);
10645 add_prototyped_attribute (subr_die, type);
10646 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10647 gen_formal_types_die (type, subr_die);
10650 /* Generate a DIE for a type definition */
10653 gen_typedef_die (decl, context_die)
10654 register tree decl;
10655 register dw_die_ref context_die;
10657 register dw_die_ref type_die;
10658 register tree origin;
10660 if (TREE_ASM_WRITTEN (decl))
10662 TREE_ASM_WRITTEN (decl) = 1;
10664 type_die = new_die (DW_TAG_typedef, context_die);
10665 origin = decl_ultimate_origin (decl);
10666 if (origin != NULL)
10667 add_abstract_origin_attribute (type_die, origin);
10670 register tree type;
10671 add_name_and_src_coords_attributes (type_die, decl);
10672 if (DECL_ORIGINAL_TYPE (decl))
10674 type = DECL_ORIGINAL_TYPE (decl);
10676 if (type == TREE_TYPE (decl))
10679 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10682 type = TREE_TYPE (decl);
10683 add_type_attribute (type_die, type, TREE_READONLY (decl),
10684 TREE_THIS_VOLATILE (decl), context_die);
10687 if (DECL_ABSTRACT (decl))
10688 equate_decl_number_to_die (decl, type_die);
10691 /* Generate a type description DIE. */
10694 gen_type_die (type, context_die)
10695 register tree type;
10696 register dw_die_ref context_die;
10700 if (type == NULL_TREE || type == error_mark_node)
10703 /* We are going to output a DIE to represent the unqualified version of
10704 this type (i.e. without any const or volatile qualifiers) so get the
10705 main variant (i.e. the unqualified version) of this type now. */
10706 type = type_main_variant (type);
10708 if (TREE_ASM_WRITTEN (type))
10711 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10712 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10714 TREE_ASM_WRITTEN (type) = 1;
10715 gen_decl_die (TYPE_NAME (type), context_die);
10719 switch (TREE_CODE (type))
10725 case REFERENCE_TYPE:
10726 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10727 ensures that the gen_type_die recursion will terminate even if the
10728 type is recursive. Recursive types are possible in Ada. */
10729 /* ??? We could perhaps do this for all types before the switch
10731 TREE_ASM_WRITTEN (type) = 1;
10733 /* For these types, all that is required is that we output a DIE (or a
10734 set of DIEs) to represent the "basis" type. */
10735 gen_type_die (TREE_TYPE (type), context_die);
10739 /* This code is used for C++ pointer-to-data-member types.
10740 Output a description of the relevant class type. */
10741 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10743 /* Output a description of the type of the object pointed to. */
10744 gen_type_die (TREE_TYPE (type), context_die);
10746 /* Now output a DIE to represent this pointer-to-data-member type
10748 gen_ptr_to_mbr_type_die (type, context_die);
10752 gen_type_die (TYPE_DOMAIN (type), context_die);
10753 gen_set_type_die (type, context_die);
10757 gen_type_die (TREE_TYPE (type), context_die);
10758 abort (); /* No way to represent these in Dwarf yet! */
10761 case FUNCTION_TYPE:
10762 /* Force out return type (in case it wasn't forced out already). */
10763 gen_type_die (TREE_TYPE (type), context_die);
10764 gen_subroutine_type_die (type, context_die);
10768 /* Force out return type (in case it wasn't forced out already). */
10769 gen_type_die (TREE_TYPE (type), context_die);
10770 gen_subroutine_type_die (type, context_die);
10774 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10776 gen_type_die (TREE_TYPE (type), context_die);
10777 gen_string_type_die (type, context_die);
10780 gen_array_type_die (type, context_die);
10784 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10787 case ENUMERAL_TYPE:
10790 case QUAL_UNION_TYPE:
10791 /* If this is a nested type whose containing class hasn't been
10792 written out yet, writing it out will cover this one, too.
10793 This does not apply to instantiations of member class templates;
10794 they need to be added to the containing class as they are
10795 generated. FIXME: This hurts the idea of combining type decls
10796 from multiple TUs, since we can't predict what set of template
10797 instantiations we'll get. */
10798 if (TYPE_CONTEXT (type)
10799 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10800 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10802 gen_type_die (TYPE_CONTEXT (type), context_die);
10804 if (TREE_ASM_WRITTEN (type))
10807 /* If that failed, attach ourselves to the stub. */
10808 push_decl_scope (TYPE_CONTEXT (type));
10809 context_die = lookup_type_die (TYPE_CONTEXT (type));
10815 if (TREE_CODE (type) == ENUMERAL_TYPE)
10816 gen_enumeration_type_die (type, context_die);
10818 gen_struct_or_union_type_die (type, context_die);
10823 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10824 it up if it is ever completed. gen_*_type_die will set it for us
10825 when appropriate. */
10834 /* No DIEs needed for fundamental types. */
10838 /* No Dwarf representation currently defined. */
10845 TREE_ASM_WRITTEN (type) = 1;
10848 /* Generate a DIE for a tagged type instantiation. */
10851 gen_tagged_type_instantiation_die (type, context_die)
10852 register tree type;
10853 register dw_die_ref context_die;
10855 if (type == NULL_TREE || type == error_mark_node)
10858 /* We are going to output a DIE to represent the unqualified version of
10859 this type (i.e. without any const or volatile qualifiers) so make sure
10860 that we have the main variant (i.e. the unqualified version) of this
10862 if (type != type_main_variant (type))
10865 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10866 an instance of an unresolved type. */
10868 switch (TREE_CODE (type))
10873 case ENUMERAL_TYPE:
10874 gen_inlined_enumeration_type_die (type, context_die);
10878 gen_inlined_structure_type_die (type, context_die);
10882 case QUAL_UNION_TYPE:
10883 gen_inlined_union_type_die (type, context_die);
10891 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10892 things which are local to the given block. */
10895 gen_block_die (stmt, context_die, depth)
10896 register tree stmt;
10897 register dw_die_ref context_die;
10900 register int must_output_die = 0;
10901 register tree origin;
10902 register tree decl;
10903 register enum tree_code origin_code;
10905 /* Ignore blocks never really used to make RTL. */
10906 if (stmt == NULL_TREE || !TREE_USED (stmt)
10907 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10910 /* If the block is one fragment of a non-contiguous block, do not
10911 process the variables, since they will have been done by the
10912 origin block. Do process subblocks. */
10913 if (BLOCK_FRAGMENT_ORIGIN (stmt))
10917 for (sub= BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
10918 gen_block_die (sub, context_die, depth + 1);
10922 /* Determine the "ultimate origin" of this block. This block may be an
10923 inlined instance of an inlined instance of inline function, so we have
10924 to trace all of the way back through the origin chain to find out what
10925 sort of node actually served as the original seed for the creation of
10926 the current block. */
10927 origin = block_ultimate_origin (stmt);
10928 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10930 /* Determine if we need to output any Dwarf DIEs at all to represent this
10932 if (origin_code == FUNCTION_DECL)
10933 /* The outer scopes for inlinings *must* always be represented. We
10934 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10935 must_output_die = 1;
10938 /* In the case where the current block represents an inlining of the
10939 "body block" of an inline function, we must *NOT* output any DIE for
10940 this block because we have already output a DIE to represent the
10941 whole inlined function scope and the "body block" of any function
10942 doesn't really represent a different scope according to ANSI C
10943 rules. So we check here to make sure that this block does not
10944 represent a "body block inlining" before trying to set the
10945 `must_output_die' flag. */
10946 if (! is_body_block (origin ? origin : stmt))
10948 /* Determine if this block directly contains any "significant"
10949 local declarations which we will need to output DIEs for. */
10950 if (debug_info_level > DINFO_LEVEL_TERSE)
10951 /* We are not in terse mode so *any* local declaration counts
10952 as being a "significant" one. */
10953 must_output_die = (BLOCK_VARS (stmt) != NULL);
10955 /* We are in terse mode, so only local (nested) function
10956 definitions count as "significant" local declarations. */
10957 for (decl = BLOCK_VARS (stmt);
10958 decl != NULL; decl = TREE_CHAIN (decl))
10959 if (TREE_CODE (decl) == FUNCTION_DECL
10960 && DECL_INITIAL (decl))
10962 must_output_die = 1;
10968 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10969 DIE for any block which contains no significant local declarations at
10970 all. Rather, in such cases we just call `decls_for_scope' so that any
10971 needed Dwarf info for any sub-blocks will get properly generated. Note
10972 that in terse mode, our definition of what constitutes a "significant"
10973 local declaration gets restricted to include only inlined function
10974 instances and local (nested) function definitions. */
10975 if (must_output_die)
10977 if (origin_code == FUNCTION_DECL)
10978 gen_inlined_subroutine_die (stmt, context_die, depth);
10980 gen_lexical_block_die (stmt, context_die, depth);
10983 decls_for_scope (stmt, context_die, depth);
10986 /* Generate all of the decls declared within a given scope and (recursively)
10987 all of its sub-blocks. */
10990 decls_for_scope (stmt, context_die, depth)
10991 register tree stmt;
10992 register dw_die_ref context_die;
10995 register tree decl;
10996 register tree subblocks;
10998 /* Ignore blocks never really used to make RTL. */
10999 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11002 /* Output the DIEs to represent all of the data objects and typedefs
11003 declared directly within this block but not within any nested
11004 sub-blocks. Also, nested function and tag DIEs have been
11005 generated with a parent of NULL; fix that up now. */
11006 for (decl = BLOCK_VARS (stmt);
11007 decl != NULL; decl = TREE_CHAIN (decl))
11009 register dw_die_ref die;
11011 if (TREE_CODE (decl) == FUNCTION_DECL)
11012 die = lookup_decl_die (decl);
11013 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11014 die = lookup_type_die (TREE_TYPE (decl));
11018 if (die != NULL && die->die_parent == NULL)
11019 add_child_die (context_die, die);
11021 gen_decl_die (decl, context_die);
11024 /* Output the DIEs to represent all sub-blocks (and the items declared
11025 therein) of this block. */
11026 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11028 subblocks = BLOCK_CHAIN (subblocks))
11029 gen_block_die (subblocks, context_die, depth + 1);
11032 /* Is this a typedef we can avoid emitting? */
11035 is_redundant_typedef (decl)
11036 register tree decl;
11038 if (TYPE_DECL_IS_STUB (decl))
11041 if (DECL_ARTIFICIAL (decl)
11042 && DECL_CONTEXT (decl)
11043 && is_tagged_type (DECL_CONTEXT (decl))
11044 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11045 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11046 /* Also ignore the artificial member typedef for the class name. */
11052 /* Generate Dwarf debug information for a decl described by DECL. */
11055 gen_decl_die (decl, context_die)
11056 register tree decl;
11057 register dw_die_ref context_die;
11059 register tree origin;
11061 if (TREE_CODE (decl) == ERROR_MARK)
11064 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11065 if (DECL_IGNORED_P (decl))
11068 switch (TREE_CODE (decl))
11071 /* The individual enumerators of an enum type get output when we output
11072 the Dwarf representation of the relevant enum type itself. */
11075 case FUNCTION_DECL:
11076 /* Don't output any DIEs to represent mere function declarations,
11077 unless they are class members or explicit block externs. */
11078 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11079 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11082 /* If we're emitting a clone, emit info for the abstract instance. */
11083 if (DECL_ORIGIN (decl) != decl)
11084 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11085 /* If we're emitting an out-of-line copy of an inline function,
11086 emit info for the abstract instance and set up to refer to it. */
11087 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11088 && ! class_scope_p (context_die)
11089 /* dwarf2out_abstract_function won't emit a die if this is just
11090 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11091 that case, because that works only if we have a die. */
11092 && DECL_INITIAL (decl) != NULL_TREE)
11094 dwarf2out_abstract_function (decl);
11095 set_decl_origin_self (decl);
11097 /* Otherwise we're emitting the primary DIE for this decl. */
11098 else if (debug_info_level > DINFO_LEVEL_TERSE)
11100 /* Before we describe the FUNCTION_DECL itself, make sure that we
11101 have described its return type. */
11102 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11104 /* And its virtual context. */
11105 if (DECL_VINDEX (decl) != NULL_TREE)
11106 gen_type_die (DECL_CONTEXT (decl), context_die);
11108 /* And its containing type. */
11109 origin = decl_class_context (decl);
11110 if (origin != NULL_TREE)
11111 gen_type_die_for_member (origin, decl, context_die);
11114 /* Now output a DIE to represent the function itself. */
11115 gen_subprogram_die (decl, context_die);
11119 /* If we are in terse mode, don't generate any DIEs to represent any
11120 actual typedefs. */
11121 if (debug_info_level <= DINFO_LEVEL_TERSE)
11124 /* In the special case of a TYPE_DECL node representing the
11125 declaration of some type tag, if the given TYPE_DECL is marked as
11126 having been instantiated from some other (original) TYPE_DECL node
11127 (e.g. one which was generated within the original definition of an
11128 inline function) we have to generate a special (abbreviated)
11129 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
11131 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11133 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11137 if (is_redundant_typedef (decl))
11138 gen_type_die (TREE_TYPE (decl), context_die);
11140 /* Output a DIE to represent the typedef itself. */
11141 gen_typedef_die (decl, context_die);
11145 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11146 gen_label_die (decl, context_die);
11150 /* If we are in terse mode, don't generate any DIEs to represent any
11151 variable declarations or definitions. */
11152 if (debug_info_level <= DINFO_LEVEL_TERSE)
11155 /* Output any DIEs that are needed to specify the type of this data
11157 gen_type_die (TREE_TYPE (decl), context_die);
11159 /* And its containing type. */
11160 origin = decl_class_context (decl);
11161 if (origin != NULL_TREE)
11162 gen_type_die_for_member (origin, decl, context_die);
11164 /* Now output the DIE to represent the data object itself. This gets
11165 complicated because of the possibility that the VAR_DECL really
11166 represents an inlined instance of a formal parameter for an inline
11168 origin = decl_ultimate_origin (decl);
11169 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11170 gen_formal_parameter_die (decl, context_die);
11172 gen_variable_die (decl, context_die);
11176 /* Ignore the nameless fields that are used to skip bits, but
11177 handle C++ anonymous unions. */
11178 if (DECL_NAME (decl) != NULL_TREE
11179 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11181 gen_type_die (member_declared_type (decl), context_die);
11182 gen_field_die (decl, context_die);
11187 gen_type_die (TREE_TYPE (decl), context_die);
11188 gen_formal_parameter_die (decl, context_die);
11191 case NAMESPACE_DECL:
11192 /* Ignore for now. */
11200 /* Add Ada "use" clause information for SGI Workshop debugger. */
11203 dwarf2out_add_library_unit_info (filename, context_list)
11204 const char *filename;
11205 const char *context_list;
11207 unsigned int file_index;
11209 if (filename != NULL)
11211 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
11212 tree context_list_decl
11213 = build_decl (LABEL_DECL, get_identifier (context_list),
11216 TREE_PUBLIC (context_list_decl) = TRUE;
11217 add_name_attribute (unit_die, context_list);
11218 file_index = lookup_filename (filename);
11219 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11220 add_pubname (context_list_decl, unit_die);
11224 /* Debug information for a global DECL. Called from toplev.c after
11225 compilation proper has finished. */
11227 dwarf2out_global_decl (decl)
11230 /* Output DWARF2 information for file-scope tentative data object
11231 declarations, file-scope (extern) function declarations (which
11232 had no corresponding body) and file-scope tagged type
11233 declarations and definitions which have not yet been forced out. */
11235 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11236 dwarf2out_decl (decl);
11239 /* Write the debugging output for DECL. */
11242 dwarf2out_decl (decl)
11243 register tree decl;
11245 register dw_die_ref context_die = comp_unit_die;
11247 if (TREE_CODE (decl) == ERROR_MARK)
11250 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11251 if (DECL_IGNORED_P (decl))
11254 switch (TREE_CODE (decl))
11256 case FUNCTION_DECL:
11257 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11258 builtin function. Explicit programmer-supplied declarations of
11259 these same functions should NOT be ignored however. */
11260 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11263 /* What we would really like to do here is to filter out all mere
11264 file-scope declarations of file-scope functions which are never
11265 referenced later within this translation unit (and keep all of ones
11266 that *are* referenced later on) but we aren't clairvoyant, so we have
11267 no idea which functions will be referenced in the future (i.e. later
11268 on within the current translation unit). So here we just ignore all
11269 file-scope function declarations which are not also definitions. If
11270 and when the debugger needs to know something about these functions,
11271 it will have to hunt around and find the DWARF information associated
11272 with the definition of the function. Note that we can't just check
11273 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11274 definitions and which ones represent mere declarations. We have to
11275 check `DECL_INITIAL' instead. That's because the C front-end
11276 supports some weird semantics for "extern inline" function
11277 definitions. These can get inlined within the current translation
11278 unit (an thus, we need to generate DWARF info for their abstract
11279 instances so that the DWARF info for the concrete inlined instances
11280 can have something to refer to) but the compiler never generates any
11281 out-of-lines instances of such things (despite the fact that they
11282 *are* definitions). The important point is that the C front-end
11283 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11284 to generate DWARF for them anyway. Note that the C++ front-end also
11285 plays some similar games for inline function definitions appearing
11286 within include files which also contain
11287 `#pragma interface' pragmas. */
11288 if (DECL_INITIAL (decl) == NULL_TREE)
11291 /* If we're a nested function, initially use a parent of NULL; if we're
11292 a plain function, this will be fixed up in decls_for_scope. If
11293 we're a method, it will be ignored, since we already have a DIE. */
11294 if (decl_function_context (decl))
11295 context_die = NULL;
11300 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11301 declaration and if the declaration was never even referenced from
11302 within this entire compilation unit. We suppress these DIEs in
11303 order to save space in the .debug section (by eliminating entries
11304 which are probably useless). Note that we must not suppress
11305 block-local extern declarations (whether used or not) because that
11306 would screw-up the debugger's name lookup mechanism and cause it to
11307 miss things which really ought to be in scope at a given point. */
11308 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11311 /* If we are in terse mode, don't generate any DIEs to represent any
11312 variable declarations or definitions. */
11313 if (debug_info_level <= DINFO_LEVEL_TERSE)
11318 /* Don't emit stubs for types unless they are needed by other DIEs. */
11319 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11322 /* Don't bother trying to generate any DIEs to represent any of the
11323 normal built-in types for the language we are compiling. */
11324 if (DECL_SOURCE_LINE (decl) == 0)
11326 /* OK, we need to generate one for `bool' so GDB knows what type
11327 comparisons have. */
11328 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11329 == DW_LANG_C_plus_plus)
11330 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11331 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11336 /* If we are in terse mode, don't generate any DIEs for types. */
11337 if (debug_info_level <= DINFO_LEVEL_TERSE)
11340 /* If we're a function-scope tag, initially use a parent of NULL;
11341 this will be fixed up in decls_for_scope. */
11342 if (decl_function_context (decl))
11343 context_die = NULL;
11351 gen_decl_die (decl, context_die);
11354 /* Output a marker (i.e. a label) for the beginning of the generated code for
11355 a lexical block. */
11358 dwarf2out_begin_block (line, blocknum)
11359 unsigned int line ATTRIBUTE_UNUSED;
11360 unsigned int blocknum;
11362 function_section (current_function_decl);
11363 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11366 /* Output a marker (i.e. a label) for the end of the generated code for a
11370 dwarf2out_end_block (line, blocknum)
11371 unsigned int line ATTRIBUTE_UNUSED;
11372 unsigned int blocknum;
11374 function_section (current_function_decl);
11375 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11378 /* Returns nonzero if it is appropriate not to emit any debugging
11379 information for BLOCK, because it doesn't contain any instructions.
11381 Don't allow this for blocks with nested functions or local classes
11382 as we would end up with orphans, and in the presence of scheduling
11383 we may end up calling them anyway. */
11386 dwarf2out_ignore_block (block)
11390 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11391 if (TREE_CODE (decl) == FUNCTION_DECL
11392 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11397 /* Lookup a filename (in the list of filenames that we know about here in
11398 dwarf2out.c) and return its "index". The index of each (known) filename is
11399 just a unique number which is associated with only that one filename.
11400 We need such numbers for the sake of generating labels
11401 (in the .debug_sfnames section) and references to those
11402 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11403 If the filename given as an argument is not found in our current list,
11404 add it to the list and assign it the next available unique index number.
11405 In order to speed up searches, we remember the index of the filename
11406 was looked up last. This handles the majority of all searches. */
11409 lookup_filename (file_name)
11410 const char *file_name;
11412 register unsigned i;
11414 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11415 if (strcmp (file_name, "<internal>") == 0
11416 || strcmp (file_name, "<built-in>") == 0)
11419 /* Check to see if the file name that was searched on the previous
11420 call matches this file name. If so, return the index. */
11421 if (file_table.last_lookup_index != 0)
11422 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
11423 return file_table.last_lookup_index;
11425 /* Didn't match the previous lookup, search the table */
11426 for (i = 1; i < file_table.in_use; ++i)
11427 if (strcmp (file_name, file_table.table[i]) == 0)
11429 file_table.last_lookup_index = i;
11433 /* Prepare to add a new table entry by making sure there is enough space in
11434 the table to do so. If not, expand the current table. */
11435 if (i == file_table.allocated)
11437 file_table.allocated = i + FILE_TABLE_INCREMENT;
11438 file_table.table = (char **)
11439 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11442 /* Add the new entry to the end of the filename table. */
11443 file_table.table[i] = xstrdup (file_name);
11444 file_table.in_use = i + 1;
11445 file_table.last_lookup_index = i;
11447 if (DWARF2_ASM_LINE_DEBUG_INFO)
11448 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11456 /* Allocate the initial hunk of the file_table. */
11457 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11458 file_table.allocated = FILE_TABLE_INCREMENT;
11460 /* Skip the first entry - file numbers begin at 1. */
11461 file_table.in_use = 1;
11462 file_table.last_lookup_index = 0;
11465 /* Output a label to mark the beginning of a source code line entry
11466 and record information relating to this source line, in
11467 'line_info_table' for later output of the .debug_line section. */
11470 dwarf2out_source_line (line, filename)
11472 register const char *filename;
11474 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11476 function_section (current_function_decl);
11478 /* If requested, emit something human-readable. */
11479 if (flag_debug_asm)
11480 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11483 if (DWARF2_ASM_LINE_DEBUG_INFO)
11485 unsigned file_num = lookup_filename (filename);
11487 /* Emit the .loc directive understood by GNU as. */
11488 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11490 /* Indicate that line number info exists. */
11491 ++line_info_table_in_use;
11493 /* Indicate that multiple line number tables exist. */
11494 if (DECL_SECTION_NAME (current_function_decl))
11495 ++separate_line_info_table_in_use;
11497 else if (DECL_SECTION_NAME (current_function_decl))
11499 register dw_separate_line_info_ref line_info;
11500 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11501 separate_line_info_table_in_use);
11503 /* expand the line info table if necessary */
11504 if (separate_line_info_table_in_use
11505 == separate_line_info_table_allocated)
11507 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11508 separate_line_info_table
11509 = (dw_separate_line_info_ref)
11510 xrealloc (separate_line_info_table,
11511 separate_line_info_table_allocated
11512 * sizeof (dw_separate_line_info_entry));
11515 /* Add the new entry at the end of the line_info_table. */
11517 = &separate_line_info_table[separate_line_info_table_in_use++];
11518 line_info->dw_file_num = lookup_filename (filename);
11519 line_info->dw_line_num = line;
11520 line_info->function = current_funcdef_number;
11524 register dw_line_info_ref line_info;
11526 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11527 line_info_table_in_use);
11529 /* Expand the line info table if necessary. */
11530 if (line_info_table_in_use == line_info_table_allocated)
11532 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11534 = (dw_line_info_ref)
11535 xrealloc (line_info_table,
11536 (line_info_table_allocated
11537 * sizeof (dw_line_info_entry)));
11540 /* Add the new entry at the end of the line_info_table. */
11541 line_info = &line_info_table[line_info_table_in_use++];
11542 line_info->dw_file_num = lookup_filename (filename);
11543 line_info->dw_line_num = line;
11548 /* Record the beginning of a new source file. */
11551 dwarf2out_start_source_file (lineno, filename)
11552 register unsigned int lineno;
11553 register const char *filename;
11555 if (flag_eliminate_dwarf2_dups)
11557 /* Record the beginning of the file for break_out_includes. */
11558 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11559 add_AT_string (bincl_die, DW_AT_name, filename);
11561 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11563 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG, 1);
11564 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11565 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11567 dw2_asm_output_data_uleb128 (lookup_filename (filename),
11568 "Filename we just started");
11572 /* Record the end of a source file. */
11575 dwarf2out_end_source_file (lineno)
11576 unsigned int lineno ATTRIBUTE_UNUSED;
11578 if (flag_eliminate_dwarf2_dups)
11580 /* Record the end of the file for break_out_includes. */
11581 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11583 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11585 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG, 1);
11586 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11590 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11591 the tail part of the directive line, i.e. the part which is past the
11592 initial whitespace, #, whitespace, directive-name, whitespace part. */
11595 dwarf2out_define (lineno, buffer)
11596 register unsigned lineno ATTRIBUTE_UNUSED;
11597 register const char *buffer ATTRIBUTE_UNUSED;
11599 static int initialized = 0;
11602 dwarf2out_start_source_file (0, primary_filename);
11605 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11607 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG, 1);
11608 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11609 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11610 dw2_asm_output_nstring (buffer, -1, "The macro");
11614 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11615 the tail part of the directive line, i.e. the part which is past the
11616 initial whitespace, #, whitespace, directive-name, whitespace part. */
11619 dwarf2out_undef (lineno, buffer)
11620 register unsigned lineno ATTRIBUTE_UNUSED;
11621 register const char *buffer ATTRIBUTE_UNUSED;
11623 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11625 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG, 1);
11626 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
11627 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11628 dw2_asm_output_nstring (buffer, -1, "The macro");
11632 /* Set up for Dwarf output at the start of compilation. */
11635 dwarf2out_init (main_input_filename)
11636 register const char *main_input_filename;
11638 init_file_table ();
11640 /* Remember the name of the primary input file. */
11641 primary_filename = main_input_filename;
11643 /* Add it to the file table first, under the assumption that we'll
11644 be emitting line number data for it first, which avoids having
11645 to add an initial DW_LNS_set_file. */
11646 lookup_filename (main_input_filename);
11648 /* Allocate the initial hunk of the decl_die_table. */
11650 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11651 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11652 decl_die_table_in_use = 0;
11654 /* Allocate the initial hunk of the decl_scope_table. */
11656 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11657 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11658 decl_scope_depth = 0;
11660 /* Allocate the initial hunk of the abbrev_die_table. */
11662 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11663 sizeof (dw_die_ref));
11664 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11665 /* Zero-th entry is allocated, but unused */
11666 abbrev_die_table_in_use = 1;
11668 /* Allocate the initial hunk of the line_info_table. */
11670 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11671 sizeof (dw_line_info_entry));
11672 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11673 /* Zero-th entry is allocated, but unused */
11674 line_info_table_in_use = 1;
11676 /* Generate the initial DIE for the .debug section. Note that the (string)
11677 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11678 will (typically) be a relative pathname and that this pathname should be
11679 taken as being relative to the directory from which the compiler was
11680 invoked when the given (base) source file was compiled. */
11681 comp_unit_die = gen_compile_unit_die (main_input_filename);
11683 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11684 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11686 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11687 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
11688 DEBUG_ABBREV_SECTION_LABEL, 0);
11689 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11690 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11692 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11693 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11694 DEBUG_INFO_SECTION_LABEL, 0);
11695 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11696 DEBUG_LINE_SECTION_LABEL, 0);
11697 ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, 0);
11698 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG, 1);
11699 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
11700 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG, 1);
11701 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11702 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG, 1);
11703 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11704 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG, 1);
11705 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11706 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11708 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG, 1);
11709 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
11710 DEBUG_MACINFO_SECTION_LABEL, 0);
11711 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
11714 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11717 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11721 /* Output stuff that dwarf requires at the end of every file,
11722 and generate the DWARF-2 debugging info. */
11725 dwarf2out_finish (input_filename)
11726 register const char *input_filename ATTRIBUTE_UNUSED;
11728 limbo_die_node *node, *next_node;
11729 dw_die_ref die = 0;
11731 /* Traverse the limbo die list, and add parent/child links. The only
11732 dies without parents that should be here are concrete instances of
11733 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11734 For concrete instances, we can get the parent die from the abstract
11736 for (node = limbo_die_list; node; node = next_node)
11738 next_node = node->next;
11741 if (die->die_parent == NULL)
11743 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11745 add_child_die (origin->die_parent, die);
11746 else if (die == comp_unit_die)
11753 limbo_die_list = NULL;
11755 /* Walk through the list of incomplete types again, trying once more to
11756 emit full debugging info for them. */
11757 retry_incomplete_types ();
11759 /* We need to reverse all the dies before break_out_includes, or
11760 we'll see the end of an include file before the beginning. */
11761 reverse_all_dies (comp_unit_die);
11763 /* Generate separate CUs for each of the include files we've seen.
11764 They will go into limbo_die_list. */
11765 if (flag_eliminate_dwarf2_dups)
11766 break_out_includes (comp_unit_die);
11768 /* Traverse the DIE's and add add sibling attributes to those DIE's
11769 that have children. */
11770 add_sibling_attributes (comp_unit_die);
11771 for (node = limbo_die_list; node; node = node->next)
11772 add_sibling_attributes (node->die);
11774 /* Output a terminator label for the .text section. */
11776 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11778 /* Output the source line correspondence table. We must do this
11779 even if there is no line information. Otherwise, on an empty
11780 translation unit, we will generate a present, but empty,
11781 .debug_info section. IRIX 6.5 `nm' will then complain when
11782 examining the file. */
11783 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11785 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG, 1);
11786 output_line_info ();
11789 /* We can only use the low/high_pc attributes if all of the code was
11791 if (separate_line_info_table_in_use == 0)
11793 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11794 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11796 /* And if it wasn't, we need to give .debug_loc and .debug_ranges
11797 an appropriate "base address". Use zero so that these addresses
11798 become absolute. */
11799 else if (have_location_lists || ranges_table_in_use)
11800 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
11802 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11803 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11804 debug_line_section_label);
11806 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11807 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
11809 /* Output all of the compilation units. We put the main one last so that
11810 the offsets are available to output_pubnames. */
11811 for (node = limbo_die_list; node; node = node->next)
11812 output_comp_unit (node->die);
11813 output_comp_unit (comp_unit_die);
11815 /* Output the abbreviation table. */
11816 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG, 1);
11817 output_abbrev_section ();
11819 if (pubname_table_in_use)
11821 /* Output public names table. */
11822 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG, 1);
11823 output_pubnames ();
11826 /* We only put functions in the arange table, so don't write it out if
11827 we don't have any. */
11828 if (fde_table_in_use)
11830 /* Output the address range information. */
11831 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG, 1);
11835 /* Output location list section if necessary. */
11836 if (have_location_lists)
11838 /* Output the location lists info. */
11839 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG, 1);
11840 output_location_lists (die);
11841 have_location_lists = 0;
11844 /* Output ranges section if necessary. */
11845 if (ranges_table_in_use)
11847 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG, 1);
11851 /* Have to end the primary source file. */
11852 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11854 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG, 1);
11855 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11858 #endif /* DWARF2_DEBUGGING_INFO */