1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Emit .debug_line header even when there are no functions, since
27 the file numbers are used by .debug_info. Alternately, leave
28 out locations for types and decls.
29 Avoid talking about ctors and op= for PODs.
30 Factor out common prologue sequences into multiple CIEs. */
32 /* The first part of this file deals with the DWARF 2 frame unwind
33 information, which is also used by the GCC efficient exception handling
34 mechanism. The second part, controlled only by an #ifdef
35 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
43 #include "hard-reg-set.h"
45 #include "insn-config.h"
51 #include "dwarf2out.h"
52 #include "dwarf2asm.h"
59 /* DWARF2 Abbreviation Glossary:
60 CFA = Canonical Frame Address
61 a fixed address on the stack which identifies a call frame.
62 We define it to be the value of SP just before the call insn.
63 The CFA register and offset, which may change during the course
64 of the function, are used to calculate its value at runtime.
65 CFI = Call Frame Instruction
66 an instruction for the DWARF2 abstract machine
67 CIE = Common Information Entry
68 information describing information common to one or more FDEs
69 DIE = Debugging Information Entry
70 FDE = Frame Description Entry
71 information describing the stack call frame, in particular,
72 how to restore registers
74 DW_CFA_... = DWARF2 CFA call frame instruction
75 DW_TAG_... = DWARF2 DIE tag */
77 /* Decide whether we want to emit frame unwind information for the current
83 return (write_symbols == DWARF2_DEBUG
84 #ifdef DWARF2_FRAME_INFO
87 #ifdef DWARF2_UNWIND_INFO
89 || (flag_exceptions && ! exceptions_via_longjmp)
94 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
96 /* How to start an assembler comment. */
97 #ifndef ASM_COMMENT_START
98 #define ASM_COMMENT_START ";#"
101 typedef struct dw_cfi_struct *dw_cfi_ref;
102 typedef struct dw_fde_struct *dw_fde_ref;
103 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
105 /* Call frames are described using a sequence of Call Frame
106 Information instructions. The register number, offset
107 and address fields are provided as possible operands;
108 their use is selected by the opcode field. */
110 typedef union dw_cfi_oprnd_struct
112 unsigned long dw_cfi_reg_num;
113 long int dw_cfi_offset;
114 const char *dw_cfi_addr;
115 struct dw_loc_descr_struct *dw_cfi_loc;
119 typedef struct dw_cfi_struct
121 dw_cfi_ref dw_cfi_next;
122 enum dwarf_call_frame_info dw_cfi_opc;
123 dw_cfi_oprnd dw_cfi_oprnd1;
124 dw_cfi_oprnd dw_cfi_oprnd2;
128 /* This is how we define the location of the CFA. We use to handle it
129 as REG + OFFSET all the time, but now it can be more complex.
130 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
131 Instead of passing around REG and OFFSET, we pass a copy
132 of this structure. */
133 typedef struct cfa_loc
138 int indirect; /* 1 if CFA is accessed via a dereference. */
141 /* All call frame descriptions (FDE's) in the GCC generated DWARF
142 refer to a single Common Information Entry (CIE), defined at
143 the beginning of the .debug_frame section. This used of a single
144 CIE obviates the need to keep track of multiple CIE's
145 in the DWARF generation routines below. */
147 typedef struct dw_fde_struct
149 const char *dw_fde_begin;
150 const char *dw_fde_current_label;
151 const char *dw_fde_end;
152 dw_cfi_ref dw_fde_cfi;
157 /* Maximum size (in bytes) of an artificially generated label. */
158 #define MAX_ARTIFICIAL_LABEL_BYTES 30
160 /* The size of the target's pointer type. */
162 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
165 /* The size of addresses as they appear in the Dwarf 2 data.
166 Some architectures use word addresses to refer to code locations,
167 but Dwarf 2 info always uses byte addresses. On such machines,
168 Dwarf 2 addresses need to be larger than the architecture's
170 #ifndef DWARF2_ADDR_SIZE
171 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
174 /* The size in bytes of a DWARF field indicating an offset or length
175 relative to a debug info section, specified to be 4 bytes in the
176 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
179 #ifndef DWARF_OFFSET_SIZE
180 #define DWARF_OFFSET_SIZE 4
183 #define DWARF_VERSION 2
185 /* Round SIZE up to the nearest BOUNDARY. */
186 #define DWARF_ROUND(SIZE,BOUNDARY) \
187 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
189 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
190 #ifndef DWARF_CIE_DATA_ALIGNMENT
191 #ifdef STACK_GROWS_DOWNWARD
192 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
194 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
196 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
198 /* A pointer to the base of a table that contains frame description
199 information for each routine. */
200 static dw_fde_ref fde_table;
202 /* Number of elements currently allocated for fde_table. */
203 static unsigned fde_table_allocated;
205 /* Number of elements in fde_table currently in use. */
206 static unsigned fde_table_in_use;
208 /* Size (in elements) of increments by which we may expand the
210 #define FDE_TABLE_INCREMENT 256
212 /* A list of call frame insns for the CIE. */
213 static dw_cfi_ref cie_cfi_head;
215 /* The number of the current function definition for which debugging
216 information is being generated. These numbers range from 1 up to the
217 maximum number of function definitions contained within the current
218 compilation unit. These numbers are used to create unique label id's
219 unique to each function definition. */
220 static unsigned current_funcdef_number = 0;
222 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
223 attribute that accelerates the lookup of the FDE associated
224 with the subprogram. This variable holds the table index of the FDE
225 associated with the current function (body) definition. */
226 static unsigned current_funcdef_fde;
228 /* Forward declarations for functions defined in this file. */
230 static char *stripattributes PARAMS ((const char *));
231 static const char *dwarf_cfi_name PARAMS ((unsigned));
232 static dw_cfi_ref new_cfi PARAMS ((void));
233 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
234 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
235 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
236 static void lookup_cfa PARAMS ((dw_cfa_location *));
237 static void reg_save PARAMS ((const char *, unsigned,
239 static void initial_return_save PARAMS ((rtx));
240 static long stack_adjust_offset PARAMS ((rtx));
241 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
242 static void output_call_frame_info PARAMS ((int));
243 static void dwarf2out_stack_adjust PARAMS ((rtx));
244 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
246 /* Support for complex CFA locations. */
247 static void output_cfa_loc PARAMS ((dw_cfi_ref));
248 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
249 struct dw_loc_descr_struct *));
250 static struct dw_loc_descr_struct *build_cfa_loc
251 PARAMS ((dw_cfa_location *));
252 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
254 /* How to start an assembler comment. */
255 #ifndef ASM_COMMENT_START
256 #define ASM_COMMENT_START ";#"
259 /* Data and reference forms for relocatable data. */
260 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
261 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
263 /* Pseudo-op for defining a new section. */
264 #ifndef SECTION_ASM_OP
265 #define SECTION_ASM_OP "\t.section\t"
268 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
269 print the SECTION_ASM_OP and the section name. The default here works for
270 almost all svr4 assemblers, except for the sparc, where the section name
271 must be enclosed in double quotes. (See sparcv4.h). */
272 #ifndef SECTION_FORMAT
273 #ifdef PUSHSECTION_FORMAT
274 #define SECTION_FORMAT PUSHSECTION_FORMAT
276 #define SECTION_FORMAT "%s%s\n"
280 #ifndef FRAME_SECTION
281 #define FRAME_SECTION ".debug_frame"
284 #ifndef FUNC_BEGIN_LABEL
285 #define FUNC_BEGIN_LABEL "LFB"
287 #ifndef FUNC_END_LABEL
288 #define FUNC_END_LABEL "LFE"
290 #define CIE_AFTER_SIZE_LABEL "LSCIE"
291 #define CIE_END_LABEL "LECIE"
292 #define CIE_LENGTH_LABEL "LLCIE"
293 #define FDE_LABEL "LSFDE"
294 #define FDE_AFTER_SIZE_LABEL "LASFDE"
295 #define FDE_END_LABEL "LEFDE"
296 #define FDE_LENGTH_LABEL "LLFDE"
297 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
298 #define LINE_NUMBER_END_LABEL "LELT"
299 #define LN_PROLOG_AS_LABEL "LASLTP"
300 #define LN_PROLOG_END_LABEL "LELTP"
301 #define DIE_LABEL_PREFIX "DW"
303 /* Definitions of defaults for various types of primitive assembly language
304 output operations. These may be overridden from within the tm.h file,
305 but typically, that is unnecessary. */
307 #ifndef ASM_OUTPUT_SECTION
308 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
309 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
313 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
314 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
316 fprintf (FILE, "%s", SET_ASM_OP); \
317 assemble_name (FILE, SY); \
319 assemble_name (FILE, HI); \
321 assemble_name (FILE, LO); \
324 #endif /* SET_ASM_OP */
326 /* The DWARF 2 CFA column which tracks the return address. Normally this
327 is the column for PC, or the first column after all of the hard
329 #ifndef DWARF_FRAME_RETURN_COLUMN
331 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
333 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
337 /* The mapping from gcc register number to DWARF 2 CFA column number. By
338 default, we just provide columns for all registers. */
339 #ifndef DWARF_FRAME_REGNUM
340 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
343 /* Hook used by __throw. */
346 expand_builtin_dwarf_fp_regnum ()
348 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
351 /* The offset from the incoming value of %sp to the top of the stack frame
352 for the current function. */
353 #ifndef INCOMING_FRAME_SP_OFFSET
354 #define INCOMING_FRAME_SP_OFFSET 0
357 /* Return a pointer to a copy of the section string name S with all
358 attributes stripped off, and an asterisk prepended (for assemble_name). */
364 char *stripped = xmalloc (strlen (s) + 2);
369 while (*s && *s != ',')
376 /* Generate code to initialize the register size table. */
379 expand_builtin_init_dwarf_reg_sizes (address)
383 enum machine_mode mode = TYPE_MODE (char_type_node);
384 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
385 rtx mem = gen_rtx_MEM (mode, addr);
387 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
389 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
390 int size = GET_MODE_SIZE (reg_raw_mode[i]);
395 emit_move_insn (change_address (mem, mode,
396 plus_constant (addr, offset)),
401 /* Convert a DWARF call frame info. operation to its string name */
404 dwarf_cfi_name (cfi_opc)
405 register unsigned cfi_opc;
409 case DW_CFA_advance_loc:
410 return "DW_CFA_advance_loc";
412 return "DW_CFA_offset";
414 return "DW_CFA_restore";
418 return "DW_CFA_set_loc";
419 case DW_CFA_advance_loc1:
420 return "DW_CFA_advance_loc1";
421 case DW_CFA_advance_loc2:
422 return "DW_CFA_advance_loc2";
423 case DW_CFA_advance_loc4:
424 return "DW_CFA_advance_loc4";
425 case DW_CFA_offset_extended:
426 return "DW_CFA_offset_extended";
427 case DW_CFA_restore_extended:
428 return "DW_CFA_restore_extended";
429 case DW_CFA_undefined:
430 return "DW_CFA_undefined";
431 case DW_CFA_same_value:
432 return "DW_CFA_same_value";
433 case DW_CFA_register:
434 return "DW_CFA_register";
435 case DW_CFA_remember_state:
436 return "DW_CFA_remember_state";
437 case DW_CFA_restore_state:
438 return "DW_CFA_restore_state";
440 return "DW_CFA_def_cfa";
441 case DW_CFA_def_cfa_register:
442 return "DW_CFA_def_cfa_register";
443 case DW_CFA_def_cfa_offset:
444 return "DW_CFA_def_cfa_offset";
445 case DW_CFA_def_cfa_expression:
446 return "DW_CFA_def_cfa_expression";
448 /* SGI/MIPS specific */
449 case DW_CFA_MIPS_advance_loc8:
450 return "DW_CFA_MIPS_advance_loc8";
453 case DW_CFA_GNU_window_save:
454 return "DW_CFA_GNU_window_save";
455 case DW_CFA_GNU_args_size:
456 return "DW_CFA_GNU_args_size";
457 case DW_CFA_GNU_negative_offset_extended:
458 return "DW_CFA_GNU_negative_offset_extended";
461 return "DW_CFA_<unknown>";
465 /* Return a pointer to a newly allocated Call Frame Instruction. */
467 static inline dw_cfi_ref
470 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
472 cfi->dw_cfi_next = NULL;
473 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
474 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
479 /* Add a Call Frame Instruction to list of instructions. */
482 add_cfi (list_head, cfi)
483 register dw_cfi_ref *list_head;
484 register dw_cfi_ref cfi;
486 register dw_cfi_ref *p;
488 /* Find the end of the chain. */
489 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
495 /* Generate a new label for the CFI info to refer to. */
498 dwarf2out_cfi_label ()
500 static char label[20];
501 static unsigned long label_num = 0;
503 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
504 ASM_OUTPUT_LABEL (asm_out_file, label);
509 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
510 or to the CIE if LABEL is NULL. */
513 add_fde_cfi (label, cfi)
514 register const char *label;
515 register dw_cfi_ref cfi;
519 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
522 label = dwarf2out_cfi_label ();
524 if (fde->dw_fde_current_label == NULL
525 || strcmp (label, fde->dw_fde_current_label) != 0)
527 register dw_cfi_ref xcfi;
529 fde->dw_fde_current_label = label = xstrdup (label);
531 /* Set the location counter to the new label. */
533 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
534 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
535 add_cfi (&fde->dw_fde_cfi, xcfi);
538 add_cfi (&fde->dw_fde_cfi, cfi);
542 add_cfi (&cie_cfi_head, cfi);
545 /* Subroutine of lookup_cfa. */
548 lookup_cfa_1 (cfi, loc)
549 register dw_cfi_ref cfi;
550 register dw_cfa_location *loc;
552 switch (cfi->dw_cfi_opc)
554 case DW_CFA_def_cfa_offset:
555 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
557 case DW_CFA_def_cfa_register:
558 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
561 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
562 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
564 case DW_CFA_def_cfa_expression:
565 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
572 /* Find the previous value for the CFA. */
576 register dw_cfa_location *loc;
578 register dw_cfi_ref cfi;
580 loc->reg = (unsigned long) -1;
583 loc->base_offset = 0;
585 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
586 lookup_cfa_1 (cfi, loc);
588 if (fde_table_in_use)
590 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
591 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
592 lookup_cfa_1 (cfi, loc);
596 /* The current rule for calculating the DWARF2 canonical frame address. */
599 /* The register used for saving registers to the stack, and its offset
601 dw_cfa_location cfa_store;
603 /* The running total of the size of arguments pushed onto the stack. */
604 static long args_size;
606 /* The last args_size we actually output. */
607 static long old_args_size;
609 /* Entry point to update the canonical frame address (CFA).
610 LABEL is passed to add_fde_cfi. The value of CFA is now to be
611 calculated from REG+OFFSET. */
614 dwarf2out_def_cfa (label, reg, offset)
615 register const char *label;
624 def_cfa_1 (label, &loc);
627 /* This routine does the actual work. The CFA is now calculated from
628 the dw_cfa_location structure. */
630 def_cfa_1 (label, loc_p)
631 register const char *label;
632 dw_cfa_location *loc_p;
634 register dw_cfi_ref cfi;
635 dw_cfa_location old_cfa, loc;
640 if (cfa_store.reg == loc.reg && loc.indirect == 0)
641 cfa_store.offset = loc.offset;
643 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
644 lookup_cfa (&old_cfa);
646 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
647 loc.indirect == old_cfa.indirect)
649 if (loc.indirect == 0
650 || loc.base_offset == old_cfa.base_offset)
651 /* Nothing changed so no need to issue any call frame
658 if (loc.reg == old_cfa.reg && !loc.indirect)
660 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
661 indicating the CFA register did not change but the offset
663 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
664 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
667 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
668 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
671 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
672 indicating the CFA register has changed to <register> but the
673 offset has not changed. */
674 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
675 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
679 else if (loc.indirect == 0)
681 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
682 indicating the CFA register has changed to <register> with
683 the specified offset. */
684 cfi->dw_cfi_opc = DW_CFA_def_cfa;
685 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
686 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
690 /* Construct a DW_CFA_def_cfa_expression instruction to
691 calculate the CFA using a full location expression since no
692 register-offset pair is available. */
693 struct dw_loc_descr_struct *loc_list;
694 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
695 loc_list = build_cfa_loc (&loc);
696 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
699 add_fde_cfi (label, cfi);
702 /* Add the CFI for saving a register. REG is the CFA column number.
703 LABEL is passed to add_fde_cfi.
704 If SREG is -1, the register is saved at OFFSET from the CFA;
705 otherwise it is saved in SREG. */
708 reg_save (label, reg, sreg, offset)
709 register const char *label;
710 register unsigned reg;
711 register unsigned sreg;
712 register long offset;
714 register dw_cfi_ref cfi = new_cfi ();
716 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
718 /* The following comparison is correct. -1 is used to indicate that
719 the value isn't a register number. */
720 if (sreg == (unsigned int) -1)
723 /* The register number won't fit in 6 bits, so we have to use
725 cfi->dw_cfi_opc = DW_CFA_offset_extended;
727 cfi->dw_cfi_opc = DW_CFA_offset;
729 #ifdef ENABLE_CHECKING
731 /* If we get an offset that is not a multiple of
732 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
733 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
735 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
737 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
741 offset /= DWARF_CIE_DATA_ALIGNMENT;
744 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
747 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
749 else if (sreg == reg)
750 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
754 cfi->dw_cfi_opc = DW_CFA_register;
755 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
758 add_fde_cfi (label, cfi);
761 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
762 This CFI tells the unwinder that it needs to restore the window registers
763 from the previous frame's window save area.
765 ??? Perhaps we should note in the CIE where windows are saved (instead of
766 assuming 0(cfa)) and what registers are in the window. */
769 dwarf2out_window_save (label)
770 register const char *label;
772 register dw_cfi_ref cfi = new_cfi ();
773 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
774 add_fde_cfi (label, cfi);
777 /* Add a CFI to update the running total of the size of arguments
778 pushed onto the stack. */
781 dwarf2out_args_size (label, size)
785 register dw_cfi_ref cfi;
787 if (size == old_args_size)
789 old_args_size = size;
792 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
793 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
794 add_fde_cfi (label, cfi);
797 /* Entry point for saving a register to the stack. REG is the GCC register
798 number. LABEL and OFFSET are passed to reg_save. */
801 dwarf2out_reg_save (label, reg, offset)
802 register const char *label;
803 register unsigned reg;
804 register long offset;
806 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
809 /* Entry point for saving the return address in the stack.
810 LABEL and OFFSET are passed to reg_save. */
813 dwarf2out_return_save (label, offset)
814 register const char *label;
815 register long offset;
817 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
820 /* Entry point for saving the return address in a register.
821 LABEL and SREG are passed to reg_save. */
824 dwarf2out_return_reg (label, sreg)
825 register const char *label;
826 register unsigned sreg;
828 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
831 /* Record the initial position of the return address. RTL is
832 INCOMING_RETURN_ADDR_RTX. */
835 initial_return_save (rtl)
838 unsigned int reg = (unsigned int) -1;
841 switch (GET_CODE (rtl))
844 /* RA is in a register. */
845 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
848 /* RA is on the stack. */
850 switch (GET_CODE (rtl))
853 if (REGNO (rtl) != STACK_POINTER_REGNUM)
858 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
860 offset = INTVAL (XEXP (rtl, 1));
863 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
865 offset = -INTVAL (XEXP (rtl, 1));
872 /* The return address is at some offset from any value we can
873 actually load. For instance, on the SPARC it is in %i7+8. Just
874 ignore the offset for now; it doesn't matter for unwinding frames. */
875 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
877 initial_return_save (XEXP (rtl, 0));
883 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
886 /* Given a SET, calculate the amount of stack adjustment it
890 stack_adjust_offset (pattern)
893 rtx src = SET_SRC (pattern);
894 rtx dest = SET_DEST (pattern);
898 if (dest == stack_pointer_rtx)
900 /* (set (reg sp) (plus (reg sp) (const_int))) */
901 code = GET_CODE (src);
902 if (! (code == PLUS || code == MINUS)
903 || XEXP (src, 0) != stack_pointer_rtx
904 || GET_CODE (XEXP (src, 1)) != CONST_INT)
907 offset = INTVAL (XEXP (src, 1));
909 else if (GET_CODE (dest) == MEM)
911 /* (set (mem (pre_dec (reg sp))) (foo)) */
912 src = XEXP (dest, 0);
913 code = GET_CODE (src);
915 if (! (code == PRE_DEC || code == PRE_INC
916 || code == PRE_MODIFY)
917 || XEXP (src, 0) != stack_pointer_rtx)
920 if (code == PRE_MODIFY)
922 rtx val = XEXP (XEXP (src, 1), 1);
923 /* We handle only adjustments by constant amount. */
924 if (GET_CODE (XEXP (src, 1)) != PLUS ||
925 GET_CODE (val) != CONST_INT)
927 offset = -INTVAL (val);
929 else offset = GET_MODE_SIZE (GET_MODE (dest));
934 if (code == PLUS || code == PRE_INC)
940 /* Check INSN to see if it looks like a push or a stack adjustment, and
941 make a note of it if it does. EH uses this information to find out how
942 much extra space it needs to pop off the stack. */
945 dwarf2out_stack_adjust (insn)
951 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
953 /* Extract the size of the args from the CALL rtx itself. */
955 insn = PATTERN (insn);
956 if (GET_CODE (insn) == PARALLEL)
957 insn = XVECEXP (insn, 0, 0);
958 if (GET_CODE (insn) == SET)
959 insn = SET_SRC (insn);
960 if (GET_CODE (insn) != CALL)
962 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
966 /* If only calls can throw, and we have a frame pointer,
967 save up adjustments until we see the CALL_INSN. */
968 else if (! asynchronous_exceptions
969 && cfa.reg != STACK_POINTER_REGNUM)
972 if (GET_CODE (insn) == BARRIER)
974 /* When we see a BARRIER, we know to reset args_size to 0. Usually
975 the compiler will have already emitted a stack adjustment, but
976 doesn't bother for calls to noreturn functions. */
977 #ifdef STACK_GROWS_DOWNWARD
983 else if (GET_CODE (PATTERN (insn)) == SET)
985 offset = stack_adjust_offset (PATTERN (insn));
987 else if (GET_CODE (PATTERN (insn)) == PARALLEL
988 || GET_CODE (PATTERN (insn)) == SEQUENCE)
990 /* There may be stack adjustments inside compound insns. Search
995 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
997 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
998 if (GET_CODE (pattern) == SET)
999 offset += stack_adjust_offset (pattern);
1008 if (cfa.reg == STACK_POINTER_REGNUM)
1009 cfa.offset += offset;
1011 #ifndef STACK_GROWS_DOWNWARD
1014 args_size += offset;
1018 label = dwarf2out_cfi_label ();
1019 def_cfa_1 (label, &cfa);
1020 dwarf2out_args_size (label, args_size);
1023 /* A temporary register holding an integral value used in adjusting SP
1024 or setting up the store_reg. The "offset" field holds the integer
1025 value, not an offset. */
1026 dw_cfa_location cfa_temp;
1028 /* Record call frame debugging information for an expression EXPR,
1029 which either sets SP or FP (adjusting how we calculate the frame
1030 address) or saves a register to the stack. LABEL indicates the
1033 This function encodes a state machine mapping rtxes to actions on
1034 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1035 users need not read the source code.
1037 The High-Level Picture
1039 Changes in the register we use to calculate the CFA: Currently we
1040 assume that if you copy the CFA register into another register, we
1041 should take the other one as the new CFA register; this seems to
1042 work pretty well. If it's wrong for some target, it's simple
1043 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1045 Changes in the register we use for saving registers to the stack:
1046 This is usually SP, but not always. Again, we deduce that if you
1047 copy SP into another register (and SP is not the CFA register),
1048 then the new register is the one we will be using for register
1049 saves. This also seems to work.
1051 Register saves: There's not much guesswork about this one; if
1052 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1053 register save, and the register used to calculate the destination
1054 had better be the one we think we're using for this purpose.
1056 Except: If the register being saved is the CFA register, and the
1057 offset is non-zero, we are saving the CFA, so we assume we have to
1058 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1059 the intent is to save the value of SP from the previous frame.
1061 Invariants / Summaries of Rules
1063 cfa current rule for calculating the CFA. It usually
1064 consists of a register and an offset.
1065 cfa_store register used by prologue code to save things to the stack
1066 cfa_store.offset is the offset from the value of
1067 cfa_store.reg to the actual CFA
1068 cfa_temp register holding an integral value. cfa_temp.offset
1069 stores the value, which will be used to adjust the
1072 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1073 with cfa.reg as the first operand changes the cfa.reg and its
1076 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1077 expression yielding a constant. This sets cfa_temp.reg
1078 and cfa_temp.offset.
1080 Rule 5: Create a new register cfa_store used to save items to the
1083 Rules 10-13: Save a register to the stack. Define offset as the
1084 difference of the original location and cfa_store's
1089 "{a,b}" indicates a choice of a xor b.
1090 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1093 (set <reg1> <reg2>:cfa.reg)
1094 effects: cfa.reg = <REG1>
1095 cfa.offset unchanged
1098 (set sp ({minus,plus} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1099 effects: cfa.reg = sp if fp used
1100 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1101 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1102 if cfa_store.reg==sp
1105 (set fp ({minus,plus} <reg>:cfa.reg <const_int>))
1106 effects: cfa.reg = fp
1107 cfa_offset += +/- <const_int>
1110 (set <reg1> (plus <reg2>:cfa.reg <const_int>))
1111 constraints: <reg1> != fp
1113 effects: cfa.reg = <reg1>
1116 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1117 constraints: <reg1> != fp
1119 effects: cfa_store.reg = <reg1>
1120 cfa_store.offset = cfa.offset - cfa_temp.offset
1123 (set <reg> <const_int>)
1124 effects: cfa_temp.reg = <reg>
1125 cfa_temp.offset = <const_int>
1128 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1129 effects: cfa_temp.reg = <reg1>
1130 cfa_temp.offset |= <const_int>
1133 (set <reg> (high <exp>))
1137 (set <reg> (lo_sum <exp> <const_int>))
1138 effects: cfa_temp.reg = <reg>
1139 cfa_temp.offset = <const_int>
1142 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1143 effects: cfa_store.offset -= <const_int>
1144 cfa.offset = cfa_store.offset if cfa.reg == sp
1145 offset = -cfa_store.offset
1147 cfa.base_offset = offset
1150 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1151 effects: cfa_store.offset += -/+ mode_size(mem)
1152 cfa.offset = cfa_store.offset if cfa.reg == sp
1153 offset = -cfa_store.offset
1155 cfa.base_offset = offset
1158 (set (mem ({minus,plus} <reg1>:cfa_store <const_int>)) <reg2>)
1159 effects: cfa_store.offset += -/+ <const_int>
1160 offset = -cfa_store.offset
1162 cfa.base_offset = offset
1165 (set (mem <reg1>:cfa_store) <reg2>)
1166 effects: offset = -cfa_store.offset
1168 cfa.base_offset = offset */
1171 dwarf2out_frame_debug_expr (expr, label)
1178 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1179 the PARALLEL independently. The first element is always processed if
1180 it is a SET. This is for backward compatibility. Other elements
1181 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1182 flag is set in them. */
1184 if (GET_CODE (expr) == PARALLEL
1185 || GET_CODE (expr) == SEQUENCE)
1188 int limit = XVECLEN (expr, 0);
1190 for (par_index = 0; par_index < limit; par_index++)
1192 rtx x = XVECEXP (expr, 0, par_index);
1194 if (GET_CODE (x) == SET &&
1195 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1196 dwarf2out_frame_debug_expr (x, label);
1201 if (GET_CODE (expr) != SET)
1204 src = SET_SRC (expr);
1205 dest = SET_DEST (expr);
1207 switch (GET_CODE (dest))
1211 /* Update the CFA rule wrt SP or FP. Make sure src is
1212 relative to the current CFA register. */
1213 switch (GET_CODE (src))
1215 /* Setting FP from SP. */
1217 if (cfa.reg == (unsigned) REGNO (src))
1223 /* We used to require that dest be either SP or FP, but the
1224 ARM copies SP to a temporary register, and from there to
1225 FP. So we just rely on the backends to only set
1226 RTX_FRAME_RELATED_P on appropriate insns. */
1227 cfa.reg = REGNO (dest);
1232 if (dest == stack_pointer_rtx)
1236 switch (GET_CODE (XEXP (src, 1)))
1239 offset = INTVAL (XEXP (src, 1));
1242 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1244 offset = cfa_temp.offset;
1250 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1252 /* Restoring SP from FP in the epilogue. */
1253 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1255 cfa.reg = STACK_POINTER_REGNUM;
1257 else if (XEXP (src, 0) != stack_pointer_rtx)
1260 if (GET_CODE (src) == PLUS)
1262 if (cfa.reg == STACK_POINTER_REGNUM)
1263 cfa.offset += offset;
1264 if (cfa_store.reg == STACK_POINTER_REGNUM)
1265 cfa_store.offset += offset;
1267 else if (dest == hard_frame_pointer_rtx)
1270 /* Either setting the FP from an offset of the SP,
1271 or adjusting the FP */
1272 if (! frame_pointer_needed)
1275 if (GET_CODE (XEXP (src, 0)) == REG
1276 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1277 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1279 offset = INTVAL (XEXP (src, 1));
1280 if (GET_CODE (src) == PLUS)
1282 cfa.offset += offset;
1283 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1290 if (GET_CODE (src) != PLUS)
1294 if (GET_CODE (XEXP (src, 0)) == REG
1295 && REGNO (XEXP (src, 0)) == cfa.reg
1296 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1298 /* Setting a temporary CFA register that will be copied
1299 into the FP later on. */
1300 offset = INTVAL (XEXP (src, 1));
1301 if (GET_CODE (src) == PLUS)
1303 cfa.offset += offset;
1304 cfa.reg = REGNO (dest);
1309 /* Setting a scratch register that we will use instead
1310 of SP for saving registers to the stack. */
1311 if (XEXP (src, 1) != stack_pointer_rtx)
1313 if (GET_CODE (XEXP (src, 0)) != REG
1314 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg)
1316 if (cfa.reg != STACK_POINTER_REGNUM)
1318 cfa_store.reg = REGNO (dest);
1319 cfa_store.offset = cfa.offset - cfa_temp.offset;
1326 cfa_temp.reg = REGNO (dest);
1327 cfa_temp.offset = INTVAL (src);
1332 if (GET_CODE (XEXP (src, 0)) != REG
1333 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1334 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1336 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1337 cfa_temp.reg = REGNO (dest);
1338 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1344 def_cfa_1 (label, &cfa);
1347 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1348 will fill in all of the bits. */
1355 if (GET_CODE (XEXP (src, 1)) != CONST_INT)
1357 cfa_temp.reg = REGNO (dest);
1358 cfa_temp.offset = INTVAL (XEXP (src, 1));
1362 if (GET_CODE (src) != REG)
1365 /* Saving a register to the stack. Make sure dest is relative to the
1367 switch (GET_CODE (XEXP (dest, 0)))
1372 /* We can't handle variable size modifications. */
1373 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1375 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1377 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1378 || cfa_store.reg != STACK_POINTER_REGNUM)
1380 cfa_store.offset += offset;
1381 if (cfa.reg == STACK_POINTER_REGNUM)
1382 cfa.offset = cfa_store.offset;
1384 offset = -cfa_store.offset;
1389 offset = GET_MODE_SIZE (GET_MODE (dest));
1390 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1393 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1394 || cfa_store.reg != STACK_POINTER_REGNUM)
1396 cfa_store.offset += offset;
1397 if (cfa.reg == STACK_POINTER_REGNUM)
1398 cfa.offset = cfa_store.offset;
1400 offset = -cfa_store.offset;
1404 /* With an offset. */
1407 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1409 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1410 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1413 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1415 offset -= cfa_store.offset;
1419 /* Without an offset. */
1421 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1423 offset = -cfa_store.offset;
1430 if (REGNO (src) != STACK_POINTER_REGNUM
1431 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1432 && (unsigned) REGNO (src) == cfa.reg)
1434 /* We're storing the current CFA reg into the stack. */
1436 if (cfa.offset == 0)
1438 /* If the source register is exactly the CFA, assume
1439 we're saving SP like any other register; this happens
1442 def_cfa_1 (label, &cfa);
1443 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1448 /* Otherwise, we'll need to look in the stack to
1449 calculate the CFA. */
1451 rtx x = XEXP (dest, 0);
1452 if (GET_CODE (x) != REG)
1454 if (GET_CODE (x) != REG)
1456 cfa.reg = (unsigned) REGNO (x);
1457 cfa.base_offset = offset;
1459 def_cfa_1 (label, &cfa);
1464 def_cfa_1 (label, &cfa);
1465 dwarf2out_reg_save (label, REGNO (src), offset);
1473 /* Record call frame debugging information for INSN, which either
1474 sets SP or FP (adjusting how we calculate the frame address) or saves a
1475 register to the stack. If INSN is NULL_RTX, initialize our state. */
1478 dwarf2out_frame_debug (insn)
1484 if (insn == NULL_RTX)
1486 /* Set up state for generating call frame debug info. */
1488 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1490 cfa.reg = STACK_POINTER_REGNUM;
1493 cfa_temp.offset = 0;
1497 if (! RTX_FRAME_RELATED_P (insn))
1499 dwarf2out_stack_adjust (insn);
1503 label = dwarf2out_cfi_label ();
1505 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1507 insn = XEXP (src, 0);
1509 insn = PATTERN (insn);
1511 dwarf2out_frame_debug_expr (insn, label);
1514 /* Output a Call Frame Information opcode and its operand(s). */
1517 output_cfi (cfi, fde)
1518 register dw_cfi_ref cfi;
1519 register dw_fde_ref fde;
1521 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1523 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1524 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1525 "DW_CFA_advance_loc 0x%lx",
1526 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1528 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1530 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1531 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1532 "DW_CFA_offset, column 0x%lx",
1533 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1534 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1536 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1538 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1539 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1540 "DW_CFA_restore, column 0x%lx",
1541 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1545 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1546 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1548 switch (cfi->dw_cfi_opc)
1550 case DW_CFA_set_loc:
1551 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1552 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1554 case DW_CFA_advance_loc1:
1555 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1556 fde->dw_fde_current_label, NULL);
1557 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1559 case DW_CFA_advance_loc2:
1560 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1561 fde->dw_fde_current_label, NULL);
1562 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1564 case DW_CFA_advance_loc4:
1565 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1566 fde->dw_fde_current_label, NULL);
1567 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1569 case DW_CFA_MIPS_advance_loc8:
1570 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1571 fde->dw_fde_current_label, NULL);
1572 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1574 case DW_CFA_offset_extended:
1575 case DW_CFA_GNU_negative_offset_extended:
1576 case DW_CFA_def_cfa:
1577 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1578 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1580 case DW_CFA_restore_extended:
1581 case DW_CFA_undefined:
1582 case DW_CFA_same_value:
1583 case DW_CFA_def_cfa_register:
1584 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1586 case DW_CFA_register:
1587 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1588 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1590 case DW_CFA_def_cfa_offset:
1591 case DW_CFA_GNU_args_size:
1592 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1594 case DW_CFA_GNU_window_save:
1596 case DW_CFA_def_cfa_expression:
1597 output_cfa_loc (cfi);
1605 /* Output the call frame information used to used to record information
1606 that relates to calculating the frame pointer, and records the
1607 location of saved registers. */
1610 output_call_frame_info (for_eh)
1613 register unsigned long i;
1614 register dw_fde_ref fde;
1615 register dw_cfi_ref cfi;
1616 char l1[20], l2[20];
1617 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1621 /* Do we want to include a pointer to the exception table? */
1622 int eh_ptr = for_eh && exception_table_p ();
1624 /* If we don't have any functions we'll want to unwind out of, don't
1625 emit any EH unwind information. */
1628 for (i = 0; i < fde_table_in_use; ++i)
1629 if (! fde_table[i].nothrow)
1635 /* We're going to be generating comments, so turn on app. */
1641 #ifdef EH_FRAME_SECTION
1642 EH_FRAME_SECTION ();
1644 tree label = get_file_function_name ('F');
1646 force_data_section ();
1647 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1648 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1649 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1651 assemble_label ("__FRAME_BEGIN__");
1654 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1656 /* Output the CIE. */
1657 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1658 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1659 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1660 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1661 dw2_asm_output_offset (for_eh ? 4 : DWARF_OFFSET_SIZE, ld,
1662 "Length of Common Information Entry");
1664 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1665 "Length of Common Information Entry");
1667 ASM_OUTPUT_LABEL (asm_out_file, l1);
1669 /* Now that the CIE pointer is PC-relative for EH,
1670 use 0 to identify the CIE. */
1671 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1672 (for_eh ? 0 : DW_CIE_ID),
1673 "CIE Identifier Tag");
1675 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1679 /* The CIE contains a pointer to the exception region info for the
1680 frame. Make the augmentation string three bytes (including the
1681 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1682 can't handle unaligned relocs. */
1683 dw2_asm_output_nstring ("eh", -1, "CIE Augmentation");
1684 dw2_asm_output_addr (DWARF2_ADDR_SIZE, "__EXCEPTION_TABLE__",
1685 "pointer to exception region info");
1689 dw2_asm_output_data (1, 0, "CIE Augmentation (none)");
1692 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1694 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1695 "CIE Data Alignment Factor");
1697 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1699 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1700 output_cfi (cfi, NULL);
1702 /* Pad the CIE out to an address sized boundary. */
1703 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1704 ASM_OUTPUT_LABEL (asm_out_file, l2);
1705 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1706 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1708 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1709 fputc ('\n', asm_out_file);
1712 /* Loop through all of the FDE's. */
1713 for (i = 0; i < fde_table_in_use; ++i)
1715 fde = &fde_table[i];
1717 /* Don't emit EH unwind info for leaf functions. */
1718 if (for_eh && fde->nothrow)
1721 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1722 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1723 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1724 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1725 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2);
1726 dw2_asm_output_offset (for_eh ? 4 : DWARF_OFFSET_SIZE, ld, "FDE Length");
1728 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1731 ASM_OUTPUT_LABEL (asm_out_file, l1);
1733 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1734 emits a target dependent sized offset when for_eh is not true.
1735 This inconsistency may confuse gdb. The only case where we need a
1736 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1737 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1738 though in order to be compatible with the dwarf_fde struct in frame.c.
1739 If the for_eh case is changed, then the struct in frame.c has
1740 to be adjusted appropriately. */
1742 dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset");
1744 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
1745 stripattributes (FRAME_SECTION),
1748 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1749 "FDE initial location");
1751 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
1752 fde->dw_fde_begin, "FDE address range");
1754 /* Loop through the Call Frame Instructions associated with
1756 fde->dw_fde_current_label = fde->dw_fde_begin;
1757 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1758 output_cfi (cfi, fde);
1760 /* Pad the FDE out to an address sized boundary. */
1761 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1762 ASM_OUTPUT_LABEL (asm_out_file, l2);
1763 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1764 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1766 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1767 fputc ('\n', asm_out_file);
1771 #ifndef EH_FRAME_SECTION
1773 dw2_asm_output_data (4, 0, "End of Table");
1775 #ifdef MIPS_DEBUGGING_INFO
1776 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1777 get a value of 0. Putting .align 0 after the label fixes it. */
1778 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1781 /* Turn off app to make assembly quicker. */
1786 /* Output a marker (i.e. a label) for the beginning of a function, before
1790 dwarf2out_begin_prologue ()
1792 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1793 register dw_fde_ref fde;
1795 ++current_funcdef_number;
1797 function_section (current_function_decl);
1798 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1799 current_funcdef_number);
1800 ASM_OUTPUT_LABEL (asm_out_file, label);
1801 current_function_func_begin_label = get_identifier (label);
1803 /* Expand the fde table if necessary. */
1804 if (fde_table_in_use == fde_table_allocated)
1806 fde_table_allocated += FDE_TABLE_INCREMENT;
1808 = (dw_fde_ref) xrealloc (fde_table,
1809 fde_table_allocated * sizeof (dw_fde_node));
1812 /* Record the FDE associated with this function. */
1813 current_funcdef_fde = fde_table_in_use;
1815 /* Add the new FDE at the end of the fde_table. */
1816 fde = &fde_table[fde_table_in_use++];
1817 fde->dw_fde_begin = xstrdup (label);
1818 fde->dw_fde_current_label = NULL;
1819 fde->dw_fde_end = NULL;
1820 fde->dw_fde_cfi = NULL;
1821 fde->nothrow = current_function_nothrow;
1823 args_size = old_args_size = 0;
1826 /* Output a marker (i.e. a label) for the absolute end of the generated code
1827 for a function definition. This gets called *after* the epilogue code has
1831 dwarf2out_end_epilogue ()
1834 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1836 /* Output a label to mark the endpoint of the code generated for this
1838 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1839 ASM_OUTPUT_LABEL (asm_out_file, label);
1840 fde = &fde_table[fde_table_in_use - 1];
1841 fde->dw_fde_end = xstrdup (label);
1845 dwarf2out_frame_init ()
1847 /* Allocate the initial hunk of the fde_table. */
1848 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
1849 fde_table_allocated = FDE_TABLE_INCREMENT;
1850 fde_table_in_use = 0;
1852 /* Generate the CFA instructions common to all FDE's. Do it now for the
1853 sake of lookup_cfa. */
1855 #ifdef DWARF2_UNWIND_INFO
1856 /* On entry, the Canonical Frame Address is at SP. */
1857 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1858 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1863 dwarf2out_frame_finish ()
1865 /* Output call frame information. */
1866 #ifdef MIPS_DEBUGGING_INFO
1867 if (write_symbols == DWARF2_DEBUG)
1868 output_call_frame_info (0);
1869 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1870 output_call_frame_info (1);
1872 if (write_symbols == DWARF2_DEBUG
1873 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1874 output_call_frame_info (1);
1878 /* And now, the subset of the debugging information support code necessary
1879 for emitting location expressions. */
1881 typedef struct dw_val_struct *dw_val_ref;
1882 typedef struct die_struct *dw_die_ref;
1883 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1885 /* Each DIE may have a series of attribute/value pairs. Values
1886 can take on several forms. The forms that are used in this
1887 implementation are listed below. */
1894 dw_val_class_unsigned_const,
1895 dw_val_class_long_long,
1898 dw_val_class_die_ref,
1899 dw_val_class_fde_ref,
1900 dw_val_class_lbl_id,
1901 dw_val_class_lbl_offset,
1906 /* Describe a double word constant value. */
1907 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
1909 typedef struct dw_long_long_struct
1916 /* Describe a floating point constant value. */
1918 typedef struct dw_fp_struct
1925 /* The dw_val_node describes an attribute's value, as it is
1926 represented internally. */
1928 typedef struct dw_val_struct
1930 dw_val_class val_class;
1934 dw_loc_descr_ref val_loc;
1936 long unsigned val_unsigned;
1937 dw_long_long_const val_long_long;
1938 dw_float_const val_float;
1943 unsigned val_fde_index;
1946 unsigned char val_flag;
1952 /* Locations in memory are described using a sequence of stack machine
1955 typedef struct dw_loc_descr_struct
1957 dw_loc_descr_ref dw_loc_next;
1958 enum dwarf_location_atom dw_loc_opc;
1959 dw_val_node dw_loc_oprnd1;
1960 dw_val_node dw_loc_oprnd2;
1965 static const char *dwarf_stack_op_name PARAMS ((unsigned));
1966 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
1969 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
1971 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
1972 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
1973 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
1974 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
1976 /* Convert a DWARF stack opcode into its string name. */
1979 dwarf_stack_op_name (op)
1980 register unsigned op;
1985 return "DW_OP_addr";
1987 return "DW_OP_deref";
1989 return "DW_OP_const1u";
1991 return "DW_OP_const1s";
1993 return "DW_OP_const2u";
1995 return "DW_OP_const2s";
1997 return "DW_OP_const4u";
1999 return "DW_OP_const4s";
2001 return "DW_OP_const8u";
2003 return "DW_OP_const8s";
2005 return "DW_OP_constu";
2007 return "DW_OP_consts";
2011 return "DW_OP_drop";
2013 return "DW_OP_over";
2015 return "DW_OP_pick";
2017 return "DW_OP_swap";
2021 return "DW_OP_xderef";
2029 return "DW_OP_minus";
2041 return "DW_OP_plus";
2042 case DW_OP_plus_uconst:
2043 return "DW_OP_plus_uconst";
2049 return "DW_OP_shra";
2067 return "DW_OP_skip";
2069 return "DW_OP_lit0";
2071 return "DW_OP_lit1";
2073 return "DW_OP_lit2";
2075 return "DW_OP_lit3";
2077 return "DW_OP_lit4";
2079 return "DW_OP_lit5";
2081 return "DW_OP_lit6";
2083 return "DW_OP_lit7";
2085 return "DW_OP_lit8";
2087 return "DW_OP_lit9";
2089 return "DW_OP_lit10";
2091 return "DW_OP_lit11";
2093 return "DW_OP_lit12";
2095 return "DW_OP_lit13";
2097 return "DW_OP_lit14";
2099 return "DW_OP_lit15";
2101 return "DW_OP_lit16";
2103 return "DW_OP_lit17";
2105 return "DW_OP_lit18";
2107 return "DW_OP_lit19";
2109 return "DW_OP_lit20";
2111 return "DW_OP_lit21";
2113 return "DW_OP_lit22";
2115 return "DW_OP_lit23";
2117 return "DW_OP_lit24";
2119 return "DW_OP_lit25";
2121 return "DW_OP_lit26";
2123 return "DW_OP_lit27";
2125 return "DW_OP_lit28";
2127 return "DW_OP_lit29";
2129 return "DW_OP_lit30";
2131 return "DW_OP_lit31";
2133 return "DW_OP_reg0";
2135 return "DW_OP_reg1";
2137 return "DW_OP_reg2";
2139 return "DW_OP_reg3";
2141 return "DW_OP_reg4";
2143 return "DW_OP_reg5";
2145 return "DW_OP_reg6";
2147 return "DW_OP_reg7";
2149 return "DW_OP_reg8";
2151 return "DW_OP_reg9";
2153 return "DW_OP_reg10";
2155 return "DW_OP_reg11";
2157 return "DW_OP_reg12";
2159 return "DW_OP_reg13";
2161 return "DW_OP_reg14";
2163 return "DW_OP_reg15";
2165 return "DW_OP_reg16";
2167 return "DW_OP_reg17";
2169 return "DW_OP_reg18";
2171 return "DW_OP_reg19";
2173 return "DW_OP_reg20";
2175 return "DW_OP_reg21";
2177 return "DW_OP_reg22";
2179 return "DW_OP_reg23";
2181 return "DW_OP_reg24";
2183 return "DW_OP_reg25";
2185 return "DW_OP_reg26";
2187 return "DW_OP_reg27";
2189 return "DW_OP_reg28";
2191 return "DW_OP_reg29";
2193 return "DW_OP_reg30";
2195 return "DW_OP_reg31";
2197 return "DW_OP_breg0";
2199 return "DW_OP_breg1";
2201 return "DW_OP_breg2";
2203 return "DW_OP_breg3";
2205 return "DW_OP_breg4";
2207 return "DW_OP_breg5";
2209 return "DW_OP_breg6";
2211 return "DW_OP_breg7";
2213 return "DW_OP_breg8";
2215 return "DW_OP_breg9";
2217 return "DW_OP_breg10";
2219 return "DW_OP_breg11";
2221 return "DW_OP_breg12";
2223 return "DW_OP_breg13";
2225 return "DW_OP_breg14";
2227 return "DW_OP_breg15";
2229 return "DW_OP_breg16";
2231 return "DW_OP_breg17";
2233 return "DW_OP_breg18";
2235 return "DW_OP_breg19";
2237 return "DW_OP_breg20";
2239 return "DW_OP_breg21";
2241 return "DW_OP_breg22";
2243 return "DW_OP_breg23";
2245 return "DW_OP_breg24";
2247 return "DW_OP_breg25";
2249 return "DW_OP_breg26";
2251 return "DW_OP_breg27";
2253 return "DW_OP_breg28";
2255 return "DW_OP_breg29";
2257 return "DW_OP_breg30";
2259 return "DW_OP_breg31";
2261 return "DW_OP_regx";
2263 return "DW_OP_fbreg";
2265 return "DW_OP_bregx";
2267 return "DW_OP_piece";
2268 case DW_OP_deref_size:
2269 return "DW_OP_deref_size";
2270 case DW_OP_xderef_size:
2271 return "DW_OP_xderef_size";
2275 return "OP_<unknown>";
2279 /* Return a pointer to a newly allocated location description. Location
2280 descriptions are simple expression terms that can be strung
2281 together to form more complicated location (address) descriptions. */
2283 static inline dw_loc_descr_ref
2284 new_loc_descr (op, oprnd1, oprnd2)
2285 register enum dwarf_location_atom op;
2286 register unsigned long oprnd1;
2287 register unsigned long oprnd2;
2289 /* Use xcalloc here so we clear out all of the long_long constant in
2291 register dw_loc_descr_ref descr
2292 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2294 descr->dw_loc_opc = op;
2295 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2296 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2297 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2298 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2303 /* Add a location description term to a location description expression. */
2306 add_loc_descr (list_head, descr)
2307 register dw_loc_descr_ref *list_head;
2308 register dw_loc_descr_ref descr;
2310 register dw_loc_descr_ref *d;
2312 /* Find the end of the chain. */
2313 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2319 /* Return the size of a location descriptor. */
2321 static unsigned long
2322 size_of_loc_descr (loc)
2323 register dw_loc_descr_ref loc;
2325 register unsigned long size = 1;
2327 switch (loc->dw_loc_opc)
2330 size += DWARF2_ADDR_SIZE;
2349 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2352 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2357 case DW_OP_plus_uconst:
2358 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2396 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2399 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2402 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2405 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2406 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2409 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2411 case DW_OP_deref_size:
2412 case DW_OP_xderef_size:
2422 /* Return the size of a series of location descriptors. */
2424 static unsigned long
2426 register dw_loc_descr_ref loc;
2428 register unsigned long size = 0;
2430 for (; loc != NULL; loc = loc->dw_loc_next)
2432 loc->dw_loc_addr = size;
2433 size += size_of_loc_descr (loc);
2439 /* Output location description stack opcode's operands (if any). */
2442 output_loc_operands (loc)
2443 register dw_loc_descr_ref loc;
2445 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2446 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2448 switch (loc->dw_loc_opc)
2450 #ifdef DWARF2_DEBUGGING_INFO
2452 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2456 dw2_asm_output_data (2, val1->v.val_int, NULL);
2460 dw2_asm_output_data (4, val1->v.val_int, NULL);
2464 if (HOST_BITS_PER_LONG < 64)
2466 dw2_asm_output_data (8, val1->v.val_int, NULL);
2473 if (val1->val_class == dw_val_class_loc)
2474 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2478 dw2_asm_output_data (2, offset, NULL);
2491 /* We currently don't make any attempt to make sure these are
2492 aligned properly like we do for the main unwind info, so
2493 don't support emitting things larger than a byte if we're
2494 only doing unwinding. */
2499 dw2_asm_output_data (1, val1->v.val_int, NULL);
2502 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2505 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2508 dw2_asm_output_data (1, val1->v.val_int, NULL);
2510 case DW_OP_plus_uconst:
2511 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2545 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2548 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2551 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2554 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2555 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2558 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2560 case DW_OP_deref_size:
2561 case DW_OP_xderef_size:
2562 dw2_asm_output_data (1, val1->v.val_int, NULL);
2565 /* Other codes have no operands. */
2570 /* Output a sequence of location operations. */
2573 output_loc_sequence (loc)
2574 dw_loc_descr_ref loc;
2576 for (; loc != NULL; loc = loc->dw_loc_next)
2578 /* Output the opcode. */
2579 dw2_asm_output_data (1, loc->dw_loc_opc,
2580 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2582 /* Output the operand(s) (if any). */
2583 output_loc_operands (loc);
2587 /* This routine will generate the correct assembly data for a location
2588 description based on a cfi entry with a complex address. */
2591 output_cfa_loc (cfi)
2594 dw_loc_descr_ref loc;
2597 /* Output the size of the block. */
2598 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2599 size = size_of_locs (loc);
2600 dw2_asm_output_data_uleb128 (size, NULL);
2602 /* Now output the operations themselves. */
2603 output_loc_sequence (loc);
2606 /* This function builds a dwarf location descriptor seqeunce from
2607 a dw_cfa_location. */
2609 static struct dw_loc_descr_struct *
2611 dw_cfa_location *cfa;
2613 struct dw_loc_descr_struct *head, *tmp;
2615 if (cfa->indirect == 0)
2618 if (cfa->base_offset)
2621 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2623 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2625 else if (cfa->reg <= 31)
2626 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2628 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2629 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2630 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2631 add_loc_descr (&head, tmp);
2632 if (cfa->offset != 0)
2634 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2635 add_loc_descr (&head, tmp);
2640 /* This function fills in aa dw_cfa_location structure from a
2641 dwarf location descriptor sequence. */
2644 get_cfa_from_loc_descr (cfa, loc)
2645 dw_cfa_location *cfa;
2646 struct dw_loc_descr_struct *loc;
2648 struct dw_loc_descr_struct *ptr;
2650 cfa->base_offset = 0;
2654 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2656 enum dwarf_location_atom op = ptr->dw_loc_opc;
2691 cfa->reg = op - DW_OP_reg0;
2694 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2728 cfa->reg = op - DW_OP_breg0;
2729 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2732 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2733 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2738 case DW_OP_plus_uconst:
2739 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2742 internal_error ("DW_LOC_OP %s not implememnted\n",
2743 dwarf_stack_op_name (ptr->dw_loc_opc));
2747 #endif /* .debug_frame support */
2749 /* And now, the support for symbolic debugging information. */
2750 #ifdef DWARF2_DEBUGGING_INFO
2752 /* NOTE: In the comments in this file, many references are made to
2753 "Debugging Information Entries". This term is abbreviated as `DIE'
2754 throughout the remainder of this file. */
2756 /* An internal representation of the DWARF output is built, and then
2757 walked to generate the DWARF debugging info. The walk of the internal
2758 representation is done after the entire program has been compiled.
2759 The types below are used to describe the internal representation. */
2761 /* Various DIE's use offsets relative to the beginning of the
2762 .debug_info section to refer to each other. */
2764 typedef long int dw_offset;
2766 /* Define typedefs here to avoid circular dependencies. */
2768 typedef struct dw_attr_struct *dw_attr_ref;
2769 typedef struct dw_line_info_struct *dw_line_info_ref;
2770 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
2771 typedef struct pubname_struct *pubname_ref;
2772 typedef dw_die_ref *arange_ref;
2774 /* Each entry in the line_info_table maintains the file and
2775 line number associated with the label generated for that
2776 entry. The label gives the PC value associated with
2777 the line number entry. */
2779 typedef struct dw_line_info_struct
2781 unsigned long dw_file_num;
2782 unsigned long dw_line_num;
2786 /* Line information for functions in separate sections; each one gets its
2788 typedef struct dw_separate_line_info_struct
2790 unsigned long dw_file_num;
2791 unsigned long dw_line_num;
2792 unsigned long function;
2794 dw_separate_line_info_entry;
2796 /* Each DIE attribute has a field specifying the attribute kind,
2797 a link to the next attribute in the chain, and an attribute value.
2798 Attributes are typically linked below the DIE they modify. */
2800 typedef struct dw_attr_struct
2802 enum dwarf_attribute dw_attr;
2803 dw_attr_ref dw_attr_next;
2804 dw_val_node dw_attr_val;
2808 /* The Debugging Information Entry (DIE) structure */
2810 typedef struct die_struct
2812 enum dwarf_tag die_tag;
2814 dw_attr_ref die_attr;
2815 dw_die_ref die_parent;
2816 dw_die_ref die_child;
2818 dw_offset die_offset;
2819 unsigned long die_abbrev;
2824 /* The pubname structure */
2826 typedef struct pubname_struct
2833 /* The limbo die list structure. */
2834 typedef struct limbo_die_struct
2837 struct limbo_die_struct *next;
2841 /* How to start an assembler comment. */
2842 #ifndef ASM_COMMENT_START
2843 #define ASM_COMMENT_START ";#"
2846 /* Define a macro which returns non-zero for a TYPE_DECL which was
2847 implicitly generated for a tagged type.
2849 Note that unlike the gcc front end (which generates a NULL named
2850 TYPE_DECL node for each complete tagged type, each array type, and
2851 each function type node created) the g++ front end generates a
2852 _named_ TYPE_DECL node for each tagged type node created.
2853 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2854 generate a DW_TAG_typedef DIE for them. */
2856 #define TYPE_DECL_IS_STUB(decl) \
2857 (DECL_NAME (decl) == NULL_TREE \
2858 || (DECL_ARTIFICIAL (decl) \
2859 && is_tagged_type (TREE_TYPE (decl)) \
2860 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2861 /* This is necessary for stub decls that \
2862 appear in nested inline functions. */ \
2863 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2864 && (decl_ultimate_origin (decl) \
2865 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2867 /* Information concerning the compilation unit's programming
2868 language, and compiler version. */
2870 extern int flag_traditional;
2872 /* Fixed size portion of the DWARF compilation unit header. */
2873 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2875 /* Fixed size portion of debugging line information prolog. */
2876 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2878 /* Fixed size portion of public names info. */
2879 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2881 /* Fixed size portion of the address range info. */
2882 #define DWARF_ARANGES_HEADER_SIZE \
2883 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
2884 - DWARF_OFFSET_SIZE)
2886 /* Size of padding portion in the address range info. It must be
2887 aligned to twice the pointer size. */
2888 #define DWARF_ARANGES_PAD_SIZE \
2889 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
2890 - (2 * DWARF_OFFSET_SIZE + 4))
2892 /* Use assembler line directives if available. */
2893 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2894 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2895 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2897 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2901 /* Define the architecture-dependent minimum instruction length (in bytes).
2902 In this implementation of DWARF, this field is used for information
2903 purposes only. Since GCC generates assembly language, we have
2904 no a priori knowledge of how many instruction bytes are generated
2905 for each source line, and therefore can use only the DW_LNE_set_address
2906 and DW_LNS_fixed_advance_pc line information commands. */
2908 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2909 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2912 /* Minimum line offset in a special line info. opcode.
2913 This value was chosen to give a reasonable range of values. */
2914 #define DWARF_LINE_BASE -10
2916 /* First special line opcde - leave room for the standard opcodes. */
2917 #define DWARF_LINE_OPCODE_BASE 10
2919 /* Range of line offsets in a special line info. opcode. */
2920 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2922 /* Flag that indicates the initial value of the is_stmt_start flag.
2923 In the present implementation, we do not mark any lines as
2924 the beginning of a source statement, because that information
2925 is not made available by the GCC front-end. */
2926 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2928 /* This location is used by calc_die_sizes() to keep track
2929 the offset of each DIE within the .debug_info section. */
2930 static unsigned long next_die_offset;
2932 /* Record the root of the DIE's built for the current compilation unit. */
2933 static dw_die_ref comp_unit_die;
2935 /* A list of DIEs with a NULL parent waiting to be relocated. */
2936 static limbo_die_node *limbo_die_list = 0;
2938 /* Structure used by lookup_filename to manage sets of filenames. */
2944 unsigned last_lookup_index;
2947 /* Size (in elements) of increments by which we may expand the filename
2949 #define FILE_TABLE_INCREMENT 64
2951 /* Filenames referenced by this compilation unit. */
2952 static struct file_table file_table;
2954 /* Local pointer to the name of the main input file. Initialized in
2956 static const char *primary_filename;
2958 /* A pointer to the base of a table of references to DIE's that describe
2959 declarations. The table is indexed by DECL_UID() which is a unique
2960 number identifying each decl. */
2961 static dw_die_ref *decl_die_table;
2963 /* Number of elements currently allocated for the decl_die_table. */
2964 static unsigned decl_die_table_allocated;
2966 /* Number of elements in decl_die_table currently in use. */
2967 static unsigned decl_die_table_in_use;
2969 /* Size (in elements) of increments by which we may expand the
2971 #define DECL_DIE_TABLE_INCREMENT 256
2973 /* A pointer to the base of a table of references to declaration
2974 scopes. This table is a display which tracks the nesting
2975 of declaration scopes at the current scope and containing
2976 scopes. This table is used to find the proper place to
2977 define type declaration DIE's. */
2978 static tree *decl_scope_table;
2980 /* Number of elements currently allocated for the decl_scope_table. */
2981 static int decl_scope_table_allocated;
2983 /* Current level of nesting of declaration scopes. */
2984 static int decl_scope_depth;
2986 /* Size (in elements) of increments by which we may expand the
2987 decl_scope_table. */
2988 #define DECL_SCOPE_TABLE_INCREMENT 64
2990 /* A pointer to the base of a list of references to DIE's that
2991 are uniquely identified by their tag, presence/absence of
2992 children DIE's, and list of attribute/value pairs. */
2993 static dw_die_ref *abbrev_die_table;
2995 /* Number of elements currently allocated for abbrev_die_table. */
2996 static unsigned abbrev_die_table_allocated;
2998 /* Number of elements in type_die_table currently in use. */
2999 static unsigned abbrev_die_table_in_use;
3001 /* Size (in elements) of increments by which we may expand the
3002 abbrev_die_table. */
3003 #define ABBREV_DIE_TABLE_INCREMENT 256
3005 /* A pointer to the base of a table that contains line information
3006 for each source code line in .text in the compilation unit. */
3007 static dw_line_info_ref line_info_table;
3009 /* Number of elements currently allocated for line_info_table. */
3010 static unsigned line_info_table_allocated;
3012 /* Number of elements in separate_line_info_table currently in use. */
3013 static unsigned separate_line_info_table_in_use;
3015 /* A pointer to the base of a table that contains line information
3016 for each source code line outside of .text in the compilation unit. */
3017 static dw_separate_line_info_ref separate_line_info_table;
3019 /* Number of elements currently allocated for separate_line_info_table. */
3020 static unsigned separate_line_info_table_allocated;
3022 /* Number of elements in line_info_table currently in use. */
3023 static unsigned line_info_table_in_use;
3025 /* Size (in elements) of increments by which we may expand the
3027 #define LINE_INFO_TABLE_INCREMENT 1024
3029 /* A pointer to the base of a table that contains a list of publicly
3030 accessible names. */
3031 static pubname_ref pubname_table;
3033 /* Number of elements currently allocated for pubname_table. */
3034 static unsigned pubname_table_allocated;
3036 /* Number of elements in pubname_table currently in use. */
3037 static unsigned pubname_table_in_use;
3039 /* Size (in elements) of increments by which we may expand the
3041 #define PUBNAME_TABLE_INCREMENT 64
3043 /* A pointer to the base of a table that contains a list of publicly
3044 accessible names. */
3045 static arange_ref arange_table;
3047 /* Number of elements currently allocated for arange_table. */
3048 static unsigned arange_table_allocated;
3050 /* Number of elements in arange_table currently in use. */
3051 static unsigned arange_table_in_use;
3053 /* Size (in elements) of increments by which we may expand the
3055 #define ARANGE_TABLE_INCREMENT 64
3057 /* A pointer to the base of a list of incomplete types which might be
3058 completed at some later time. */
3060 static tree *incomplete_types_list;
3062 /* Number of elements currently allocated for the incomplete_types_list. */
3063 static unsigned incomplete_types_allocated;
3065 /* Number of elements of incomplete_types_list currently in use. */
3066 static unsigned incomplete_types;
3068 /* Size (in elements) of increments by which we may expand the incomplete
3069 types list. Actually, a single hunk of space of this size should
3070 be enough for most typical programs. */
3071 #define INCOMPLETE_TYPES_INCREMENT 64
3073 /* Record whether the function being analyzed contains inlined functions. */
3074 static int current_function_has_inlines;
3075 #if 0 && defined (MIPS_DEBUGGING_INFO)
3076 static int comp_unit_has_inlines;
3079 /* Array of RTXes referenced by the debugging information, which therefore
3080 must be kept around forever. We do this rather than perform GC on
3081 the dwarf info because almost all of the dwarf info lives forever, and
3082 it's easier to support non-GC frontends this way. */
3083 static varray_type used_rtx_varray;
3085 /* Forward declarations for functions defined in this file. */
3087 static int is_pseudo_reg PARAMS ((rtx));
3088 static tree type_main_variant PARAMS ((tree));
3089 static int is_tagged_type PARAMS ((tree));
3090 static const char *dwarf_tag_name PARAMS ((unsigned));
3091 static const char *dwarf_attr_name PARAMS ((unsigned));
3092 static const char *dwarf_form_name PARAMS ((unsigned));
3094 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3096 static tree decl_ultimate_origin PARAMS ((tree));
3097 static tree block_ultimate_origin PARAMS ((tree));
3098 static tree decl_class_context PARAMS ((tree));
3099 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3100 static void add_AT_flag PARAMS ((dw_die_ref,
3101 enum dwarf_attribute,
3103 static void add_AT_int PARAMS ((dw_die_ref,
3104 enum dwarf_attribute, long));
3105 static void add_AT_unsigned PARAMS ((dw_die_ref,
3106 enum dwarf_attribute,
3108 static void add_AT_long_long PARAMS ((dw_die_ref,
3109 enum dwarf_attribute,
3112 static void add_AT_float PARAMS ((dw_die_ref,
3113 enum dwarf_attribute,
3115 static void add_AT_string PARAMS ((dw_die_ref,
3116 enum dwarf_attribute,
3118 static void add_AT_die_ref PARAMS ((dw_die_ref,
3119 enum dwarf_attribute,
3121 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3122 enum dwarf_attribute,
3124 static void add_AT_loc PARAMS ((dw_die_ref,
3125 enum dwarf_attribute,
3127 static void add_AT_addr PARAMS ((dw_die_ref,
3128 enum dwarf_attribute,
3130 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3131 enum dwarf_attribute,
3133 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3134 enum dwarf_attribute,
3136 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3137 enum dwarf_attribute));
3138 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3139 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3140 static const char *get_AT_string PARAMS ((dw_die_ref,
3141 enum dwarf_attribute));
3142 static int get_AT_flag PARAMS ((dw_die_ref,
3143 enum dwarf_attribute));
3144 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3145 enum dwarf_attribute));
3146 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3147 enum dwarf_attribute));
3148 static int is_c_family PARAMS ((void));
3149 static int is_java PARAMS ((void));
3150 static int is_fortran PARAMS ((void));
3151 static void remove_AT PARAMS ((dw_die_ref,
3152 enum dwarf_attribute));
3153 static void remove_children PARAMS ((dw_die_ref));
3154 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3155 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3156 static dw_die_ref lookup_type_die PARAMS ((tree));
3157 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3158 static dw_die_ref lookup_decl_die PARAMS ((tree));
3159 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3160 static void print_spaces PARAMS ((FILE *));
3161 static void print_die PARAMS ((dw_die_ref, FILE *));
3162 static void print_dwarf_line_table PARAMS ((FILE *));
3163 static void reverse_die_lists PARAMS ((dw_die_ref));
3164 static void reverse_all_dies PARAMS ((dw_die_ref));
3165 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3166 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3167 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3168 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3169 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3170 static void compute_section_prefix PARAMS ((dw_die_ref));
3171 static int is_type_die PARAMS ((dw_die_ref));
3172 static int is_comdat_die PARAMS ((dw_die_ref));
3173 static int is_symbol_die PARAMS ((dw_die_ref));
3174 static char *gen_internal_sym PARAMS ((void));
3175 static void assign_symbol_names PARAMS ((dw_die_ref));
3176 static void break_out_includes PARAMS ((dw_die_ref));
3177 static void add_sibling_attributes PARAMS ((dw_die_ref));
3178 static void build_abbrev_table PARAMS ((dw_die_ref));
3179 static unsigned long size_of_string PARAMS ((const char *));
3180 static int constant_size PARAMS ((long unsigned));
3181 static unsigned long size_of_die PARAMS ((dw_die_ref));
3182 static void calc_die_sizes PARAMS ((dw_die_ref));
3183 static void mark_dies PARAMS ((dw_die_ref));
3184 static void unmark_dies PARAMS ((dw_die_ref));
3185 static unsigned long size_of_pubnames PARAMS ((void));
3186 static unsigned long size_of_aranges PARAMS ((void));
3187 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3188 static void output_value_format PARAMS ((dw_attr_ref));
3189 static void output_abbrev_section PARAMS ((void));
3190 static void output_die_symbol PARAMS ((dw_die_ref));
3191 static void output_die PARAMS ((dw_die_ref));
3192 static void output_compilation_unit_header PARAMS ((void));
3193 static void output_comp_unit PARAMS ((dw_die_ref));
3194 static const char *dwarf2_name PARAMS ((tree, int));
3195 static void add_pubname PARAMS ((tree, dw_die_ref));
3196 static void output_pubnames PARAMS ((void));
3197 static void add_arange PARAMS ((tree, dw_die_ref));
3198 static void output_aranges PARAMS ((void));
3199 static void output_line_info PARAMS ((void));
3200 static void output_file_names PARAMS ((void));
3201 static dw_die_ref base_type_die PARAMS ((tree));
3202 static tree root_type PARAMS ((tree));
3203 static int is_base_type PARAMS ((tree));
3204 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3205 static int type_is_enum PARAMS ((tree));
3206 static unsigned int reg_number PARAMS ((rtx));
3207 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3208 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3209 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3210 static int is_based_loc PARAMS ((rtx));
3211 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3212 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3213 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3214 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3215 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3216 static tree field_type PARAMS ((tree));
3217 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3218 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3219 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3220 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3221 static void add_AT_location_description PARAMS ((dw_die_ref,
3222 enum dwarf_attribute, rtx));
3223 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3224 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3225 static rtx rtl_for_decl_location PARAMS ((tree));
3226 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3227 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3228 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3229 static void add_bound_info PARAMS ((dw_die_ref,
3230 enum dwarf_attribute, tree));
3231 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3232 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3233 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3234 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3235 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3236 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3237 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3238 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3239 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3240 static void push_decl_scope PARAMS ((tree));
3241 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3242 static void pop_decl_scope PARAMS ((void));
3243 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3245 static const char *type_tag PARAMS ((tree));
3246 static tree member_declared_type PARAMS ((tree));
3248 static const char *decl_start_label PARAMS ((tree));
3250 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3251 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3253 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3255 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3256 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3257 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3258 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3259 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3260 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3261 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3262 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3263 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3264 static void gen_label_die PARAMS ((tree, dw_die_ref));
3265 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3266 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3267 static void gen_field_die PARAMS ((tree, dw_die_ref));
3268 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3269 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3270 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3271 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3272 static void gen_member_die PARAMS ((tree, dw_die_ref));
3273 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3274 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3275 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3276 static void gen_type_die PARAMS ((tree, dw_die_ref));
3277 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3278 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3279 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3280 static int is_redundant_typedef PARAMS ((tree));
3281 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3282 static unsigned lookup_filename PARAMS ((const char *));
3283 static void init_file_table PARAMS ((void));
3284 static void add_incomplete_type PARAMS ((tree));
3285 static void retry_incomplete_types PARAMS ((void));
3286 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3287 static rtx save_rtx PARAMS ((rtx));
3288 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3289 static int file_info_cmp PARAMS ((const void *, const void *));
3291 /* Section names used to hold DWARF debugging information. */
3292 #ifndef DEBUG_INFO_SECTION
3293 #define DEBUG_INFO_SECTION ".debug_info"
3295 #ifndef ABBREV_SECTION
3296 #define ABBREV_SECTION ".debug_abbrev"
3298 #ifndef ARANGES_SECTION
3299 #define ARANGES_SECTION ".debug_aranges"
3301 #ifndef DW_MACINFO_SECTION
3302 #define DW_MACINFO_SECTION ".debug_macinfo"
3304 #ifndef DEBUG_LINE_SECTION
3305 #define DEBUG_LINE_SECTION ".debug_line"
3308 #define LOC_SECTION ".debug_loc"
3310 #ifndef PUBNAMES_SECTION
3311 #define PUBNAMES_SECTION ".debug_pubnames"
3314 #define STR_SECTION ".debug_str"
3317 /* Standard ELF section names for compiled code and data. */
3318 #ifndef TEXT_SECTION
3319 #define TEXT_SECTION ".text"
3321 #ifndef DATA_SECTION
3322 #define DATA_SECTION ".data"
3325 #define BSS_SECTION ".bss"
3328 /* Labels we insert at beginning sections we can reference instead of
3329 the section names themselves. */
3331 #ifndef TEXT_SECTION_LABEL
3332 #define TEXT_SECTION_LABEL "Ltext"
3334 #ifndef DEBUG_LINE_SECTION_LABEL
3335 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3337 #ifndef DEBUG_INFO_SECTION_LABEL
3338 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3340 #ifndef ABBREV_SECTION_LABEL
3341 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3344 /* Definitions of defaults for formats and names of various special
3345 (artificial) labels which may be generated within this file (when the -g
3346 options is used and DWARF_DEBUGGING_INFO is in effect.
3347 If necessary, these may be overridden from within the tm.h file, but
3348 typically, overriding these defaults is unnecessary. */
3350 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3351 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3352 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3353 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3354 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3356 #ifndef TEXT_END_LABEL
3357 #define TEXT_END_LABEL "Letext"
3359 #ifndef DATA_END_LABEL
3360 #define DATA_END_LABEL "Ledata"
3362 #ifndef BSS_END_LABEL
3363 #define BSS_END_LABEL "Lebss"
3365 #ifndef BLOCK_BEGIN_LABEL
3366 #define BLOCK_BEGIN_LABEL "LBB"
3368 #ifndef BLOCK_END_LABEL
3369 #define BLOCK_END_LABEL "LBE"
3371 #ifndef BODY_BEGIN_LABEL
3372 #define BODY_BEGIN_LABEL "Lbb"
3374 #ifndef BODY_END_LABEL
3375 #define BODY_END_LABEL "Lbe"
3377 #ifndef LINE_CODE_LABEL
3378 #define LINE_CODE_LABEL "LM"
3380 #ifndef SEPARATE_LINE_CODE_LABEL
3381 #define SEPARATE_LINE_CODE_LABEL "LSM"
3384 /* We allow a language front-end to designate a function that is to be
3385 called to "demangle" any name before it it put into a DIE. */
3387 static const char *(*demangle_name_func) PARAMS ((const char *));
3390 dwarf2out_set_demangle_name_func (func)
3391 const char *(*func) PARAMS ((const char *));
3393 demangle_name_func = func;
3396 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3397 that means adding it to used_rtx_varray. If not, that means making
3398 a copy on the permanent_obstack. */
3404 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3409 /* Test if rtl node points to a pseudo register. */
3415 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3416 || (GET_CODE (rtl) == SUBREG
3417 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3420 /* Return a reference to a type, with its const and volatile qualifiers
3424 type_main_variant (type)
3427 type = TYPE_MAIN_VARIANT (type);
3429 /* There really should be only one main variant among any group of variants
3430 of a given type (and all of the MAIN_VARIANT values for all members of
3431 the group should point to that one type) but sometimes the C front-end
3432 messes this up for array types, so we work around that bug here. */
3434 if (TREE_CODE (type) == ARRAY_TYPE)
3435 while (type != TYPE_MAIN_VARIANT (type))
3436 type = TYPE_MAIN_VARIANT (type);
3441 /* Return non-zero if the given type node represents a tagged type. */
3444 is_tagged_type (type)
3447 register enum tree_code code = TREE_CODE (type);
3449 return (code == RECORD_TYPE || code == UNION_TYPE
3450 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3453 /* Convert a DIE tag into its string name. */
3456 dwarf_tag_name (tag)
3457 register unsigned tag;
3461 case DW_TAG_padding:
3462 return "DW_TAG_padding";
3463 case DW_TAG_array_type:
3464 return "DW_TAG_array_type";
3465 case DW_TAG_class_type:
3466 return "DW_TAG_class_type";
3467 case DW_TAG_entry_point:
3468 return "DW_TAG_entry_point";
3469 case DW_TAG_enumeration_type:
3470 return "DW_TAG_enumeration_type";
3471 case DW_TAG_formal_parameter:
3472 return "DW_TAG_formal_parameter";
3473 case DW_TAG_imported_declaration:
3474 return "DW_TAG_imported_declaration";
3476 return "DW_TAG_label";
3477 case DW_TAG_lexical_block:
3478 return "DW_TAG_lexical_block";
3480 return "DW_TAG_member";
3481 case DW_TAG_pointer_type:
3482 return "DW_TAG_pointer_type";
3483 case DW_TAG_reference_type:
3484 return "DW_TAG_reference_type";
3485 case DW_TAG_compile_unit:
3486 return "DW_TAG_compile_unit";
3487 case DW_TAG_string_type:
3488 return "DW_TAG_string_type";
3489 case DW_TAG_structure_type:
3490 return "DW_TAG_structure_type";
3491 case DW_TAG_subroutine_type:
3492 return "DW_TAG_subroutine_type";
3493 case DW_TAG_typedef:
3494 return "DW_TAG_typedef";
3495 case DW_TAG_union_type:
3496 return "DW_TAG_union_type";
3497 case DW_TAG_unspecified_parameters:
3498 return "DW_TAG_unspecified_parameters";
3499 case DW_TAG_variant:
3500 return "DW_TAG_variant";
3501 case DW_TAG_common_block:
3502 return "DW_TAG_common_block";
3503 case DW_TAG_common_inclusion:
3504 return "DW_TAG_common_inclusion";
3505 case DW_TAG_inheritance:
3506 return "DW_TAG_inheritance";
3507 case DW_TAG_inlined_subroutine:
3508 return "DW_TAG_inlined_subroutine";
3510 return "DW_TAG_module";
3511 case DW_TAG_ptr_to_member_type:
3512 return "DW_TAG_ptr_to_member_type";
3513 case DW_TAG_set_type:
3514 return "DW_TAG_set_type";
3515 case DW_TAG_subrange_type:
3516 return "DW_TAG_subrange_type";
3517 case DW_TAG_with_stmt:
3518 return "DW_TAG_with_stmt";
3519 case DW_TAG_access_declaration:
3520 return "DW_TAG_access_declaration";
3521 case DW_TAG_base_type:
3522 return "DW_TAG_base_type";
3523 case DW_TAG_catch_block:
3524 return "DW_TAG_catch_block";
3525 case DW_TAG_const_type:
3526 return "DW_TAG_const_type";
3527 case DW_TAG_constant:
3528 return "DW_TAG_constant";
3529 case DW_TAG_enumerator:
3530 return "DW_TAG_enumerator";
3531 case DW_TAG_file_type:
3532 return "DW_TAG_file_type";
3534 return "DW_TAG_friend";
3535 case DW_TAG_namelist:
3536 return "DW_TAG_namelist";
3537 case DW_TAG_namelist_item:
3538 return "DW_TAG_namelist_item";
3539 case DW_TAG_packed_type:
3540 return "DW_TAG_packed_type";
3541 case DW_TAG_subprogram:
3542 return "DW_TAG_subprogram";
3543 case DW_TAG_template_type_param:
3544 return "DW_TAG_template_type_param";
3545 case DW_TAG_template_value_param:
3546 return "DW_TAG_template_value_param";
3547 case DW_TAG_thrown_type:
3548 return "DW_TAG_thrown_type";
3549 case DW_TAG_try_block:
3550 return "DW_TAG_try_block";
3551 case DW_TAG_variant_part:
3552 return "DW_TAG_variant_part";
3553 case DW_TAG_variable:
3554 return "DW_TAG_variable";
3555 case DW_TAG_volatile_type:
3556 return "DW_TAG_volatile_type";
3557 case DW_TAG_MIPS_loop:
3558 return "DW_TAG_MIPS_loop";
3559 case DW_TAG_format_label:
3560 return "DW_TAG_format_label";
3561 case DW_TAG_function_template:
3562 return "DW_TAG_function_template";
3563 case DW_TAG_class_template:
3564 return "DW_TAG_class_template";
3565 case DW_TAG_GNU_BINCL:
3566 return "DW_TAG_GNU_BINCL";
3567 case DW_TAG_GNU_EINCL:
3568 return "DW_TAG_GNU_EINCL";
3570 return "DW_TAG_<unknown>";
3574 /* Convert a DWARF attribute code into its string name. */
3577 dwarf_attr_name (attr)
3578 register unsigned attr;
3583 return "DW_AT_sibling";
3584 case DW_AT_location:
3585 return "DW_AT_location";
3587 return "DW_AT_name";
3588 case DW_AT_ordering:
3589 return "DW_AT_ordering";
3590 case DW_AT_subscr_data:
3591 return "DW_AT_subscr_data";
3592 case DW_AT_byte_size:
3593 return "DW_AT_byte_size";
3594 case DW_AT_bit_offset:
3595 return "DW_AT_bit_offset";
3596 case DW_AT_bit_size:
3597 return "DW_AT_bit_size";
3598 case DW_AT_element_list:
3599 return "DW_AT_element_list";
3600 case DW_AT_stmt_list:
3601 return "DW_AT_stmt_list";
3603 return "DW_AT_low_pc";
3605 return "DW_AT_high_pc";
3606 case DW_AT_language:
3607 return "DW_AT_language";
3609 return "DW_AT_member";
3611 return "DW_AT_discr";
3612 case DW_AT_discr_value:
3613 return "DW_AT_discr_value";
3614 case DW_AT_visibility:
3615 return "DW_AT_visibility";
3617 return "DW_AT_import";
3618 case DW_AT_string_length:
3619 return "DW_AT_string_length";
3620 case DW_AT_common_reference:
3621 return "DW_AT_common_reference";
3622 case DW_AT_comp_dir:
3623 return "DW_AT_comp_dir";
3624 case DW_AT_const_value:
3625 return "DW_AT_const_value";
3626 case DW_AT_containing_type:
3627 return "DW_AT_containing_type";
3628 case DW_AT_default_value:
3629 return "DW_AT_default_value";
3631 return "DW_AT_inline";
3632 case DW_AT_is_optional:
3633 return "DW_AT_is_optional";
3634 case DW_AT_lower_bound:
3635 return "DW_AT_lower_bound";
3636 case DW_AT_producer:
3637 return "DW_AT_producer";
3638 case DW_AT_prototyped:
3639 return "DW_AT_prototyped";
3640 case DW_AT_return_addr:
3641 return "DW_AT_return_addr";
3642 case DW_AT_start_scope:
3643 return "DW_AT_start_scope";
3644 case DW_AT_stride_size:
3645 return "DW_AT_stride_size";
3646 case DW_AT_upper_bound:
3647 return "DW_AT_upper_bound";
3648 case DW_AT_abstract_origin:
3649 return "DW_AT_abstract_origin";
3650 case DW_AT_accessibility:
3651 return "DW_AT_accessibility";
3652 case DW_AT_address_class:
3653 return "DW_AT_address_class";
3654 case DW_AT_artificial:
3655 return "DW_AT_artificial";
3656 case DW_AT_base_types:
3657 return "DW_AT_base_types";
3658 case DW_AT_calling_convention:
3659 return "DW_AT_calling_convention";
3661 return "DW_AT_count";
3662 case DW_AT_data_member_location:
3663 return "DW_AT_data_member_location";
3664 case DW_AT_decl_column:
3665 return "DW_AT_decl_column";
3666 case DW_AT_decl_file:
3667 return "DW_AT_decl_file";
3668 case DW_AT_decl_line:
3669 return "DW_AT_decl_line";
3670 case DW_AT_declaration:
3671 return "DW_AT_declaration";
3672 case DW_AT_discr_list:
3673 return "DW_AT_discr_list";
3674 case DW_AT_encoding:
3675 return "DW_AT_encoding";
3676 case DW_AT_external:
3677 return "DW_AT_external";
3678 case DW_AT_frame_base:
3679 return "DW_AT_frame_base";
3681 return "DW_AT_friend";
3682 case DW_AT_identifier_case:
3683 return "DW_AT_identifier_case";
3684 case DW_AT_macro_info:
3685 return "DW_AT_macro_info";
3686 case DW_AT_namelist_items:
3687 return "DW_AT_namelist_items";
3688 case DW_AT_priority:
3689 return "DW_AT_priority";
3691 return "DW_AT_segment";
3692 case DW_AT_specification:
3693 return "DW_AT_specification";
3694 case DW_AT_static_link:
3695 return "DW_AT_static_link";
3697 return "DW_AT_type";
3698 case DW_AT_use_location:
3699 return "DW_AT_use_location";
3700 case DW_AT_variable_parameter:
3701 return "DW_AT_variable_parameter";
3702 case DW_AT_virtuality:
3703 return "DW_AT_virtuality";
3704 case DW_AT_vtable_elem_location:
3705 return "DW_AT_vtable_elem_location";
3707 case DW_AT_MIPS_fde:
3708 return "DW_AT_MIPS_fde";
3709 case DW_AT_MIPS_loop_begin:
3710 return "DW_AT_MIPS_loop_begin";
3711 case DW_AT_MIPS_tail_loop_begin:
3712 return "DW_AT_MIPS_tail_loop_begin";
3713 case DW_AT_MIPS_epilog_begin:
3714 return "DW_AT_MIPS_epilog_begin";
3715 case DW_AT_MIPS_loop_unroll_factor:
3716 return "DW_AT_MIPS_loop_unroll_factor";
3717 case DW_AT_MIPS_software_pipeline_depth:
3718 return "DW_AT_MIPS_software_pipeline_depth";
3719 case DW_AT_MIPS_linkage_name:
3720 return "DW_AT_MIPS_linkage_name";
3721 case DW_AT_MIPS_stride:
3722 return "DW_AT_MIPS_stride";
3723 case DW_AT_MIPS_abstract_name:
3724 return "DW_AT_MIPS_abstract_name";
3725 case DW_AT_MIPS_clone_origin:
3726 return "DW_AT_MIPS_clone_origin";
3727 case DW_AT_MIPS_has_inlines:
3728 return "DW_AT_MIPS_has_inlines";
3730 case DW_AT_sf_names:
3731 return "DW_AT_sf_names";
3732 case DW_AT_src_info:
3733 return "DW_AT_src_info";
3734 case DW_AT_mac_info:
3735 return "DW_AT_mac_info";
3736 case DW_AT_src_coords:
3737 return "DW_AT_src_coords";
3738 case DW_AT_body_begin:
3739 return "DW_AT_body_begin";
3740 case DW_AT_body_end:
3741 return "DW_AT_body_end";
3743 return "DW_AT_<unknown>";
3747 /* Convert a DWARF value form code into its string name. */
3750 dwarf_form_name (form)
3751 register unsigned form;
3756 return "DW_FORM_addr";
3757 case DW_FORM_block2:
3758 return "DW_FORM_block2";
3759 case DW_FORM_block4:
3760 return "DW_FORM_block4";
3762 return "DW_FORM_data2";
3764 return "DW_FORM_data4";
3766 return "DW_FORM_data8";
3767 case DW_FORM_string:
3768 return "DW_FORM_string";
3770 return "DW_FORM_block";
3771 case DW_FORM_block1:
3772 return "DW_FORM_block1";
3774 return "DW_FORM_data1";
3776 return "DW_FORM_flag";
3778 return "DW_FORM_sdata";
3780 return "DW_FORM_strp";
3782 return "DW_FORM_udata";
3783 case DW_FORM_ref_addr:
3784 return "DW_FORM_ref_addr";
3786 return "DW_FORM_ref1";
3788 return "DW_FORM_ref2";
3790 return "DW_FORM_ref4";
3792 return "DW_FORM_ref8";
3793 case DW_FORM_ref_udata:
3794 return "DW_FORM_ref_udata";
3795 case DW_FORM_indirect:
3796 return "DW_FORM_indirect";
3798 return "DW_FORM_<unknown>";
3802 /* Convert a DWARF type code into its string name. */
3806 dwarf_type_encoding_name (enc)
3807 register unsigned enc;
3811 case DW_ATE_address:
3812 return "DW_ATE_address";
3813 case DW_ATE_boolean:
3814 return "DW_ATE_boolean";
3815 case DW_ATE_complex_float:
3816 return "DW_ATE_complex_float";
3818 return "DW_ATE_float";
3820 return "DW_ATE_signed";
3821 case DW_ATE_signed_char:
3822 return "DW_ATE_signed_char";
3823 case DW_ATE_unsigned:
3824 return "DW_ATE_unsigned";
3825 case DW_ATE_unsigned_char:
3826 return "DW_ATE_unsigned_char";
3828 return "DW_ATE_<unknown>";
3833 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3834 instance of an inlined instance of a decl which is local to an inline
3835 function, so we have to trace all of the way back through the origin chain
3836 to find out what sort of node actually served as the original seed for the
3840 decl_ultimate_origin (decl)
3843 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3844 nodes in the function to point to themselves; ignore that if
3845 we're trying to output the abstract instance of this function. */
3846 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
3849 #ifdef ENABLE_CHECKING
3850 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
3851 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3852 most distant ancestor, this should never happen. */
3856 return DECL_ABSTRACT_ORIGIN (decl);
3859 /* Determine the "ultimate origin" of a block. The block may be an inlined
3860 instance of an inlined instance of a block which is local to an inline
3861 function, so we have to trace all of the way back through the origin chain
3862 to find out what sort of node actually served as the original seed for the
3866 block_ultimate_origin (block)
3867 register tree block;
3869 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3871 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
3872 nodes in the function to point to themselves; ignore that if
3873 we're trying to output the abstract instance of this function. */
3874 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
3877 if (immediate_origin == NULL_TREE)
3881 register tree ret_val;
3882 register tree lookahead = immediate_origin;
3886 ret_val = lookahead;
3887 lookahead = (TREE_CODE (ret_val) == BLOCK)
3888 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3891 while (lookahead != NULL && lookahead != ret_val);
3897 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3898 of a virtual function may refer to a base class, so we check the 'this'
3902 decl_class_context (decl)
3905 tree context = NULL_TREE;
3907 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3908 context = DECL_CONTEXT (decl);
3910 context = TYPE_MAIN_VARIANT
3911 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3913 if (context && !TYPE_P (context))
3914 context = NULL_TREE;
3919 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
3920 addition order, and correct that in reverse_all_dies. */
3923 add_dwarf_attr (die, attr)
3924 register dw_die_ref die;
3925 register dw_attr_ref attr;
3927 if (die != NULL && attr != NULL)
3929 attr->dw_attr_next = die->die_attr;
3930 die->die_attr = attr;
3934 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
3935 static inline dw_val_class
3939 return a->dw_attr_val.val_class;
3942 /* Add a flag value attribute to a DIE. */
3945 add_AT_flag (die, attr_kind, flag)
3946 register dw_die_ref die;
3947 register enum dwarf_attribute attr_kind;
3948 register unsigned flag;
3950 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3952 attr->dw_attr_next = NULL;
3953 attr->dw_attr = attr_kind;
3954 attr->dw_attr_val.val_class = dw_val_class_flag;
3955 attr->dw_attr_val.v.val_flag = flag;
3956 add_dwarf_attr (die, attr);
3959 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3960 static inline unsigned
3962 register dw_attr_ref a;
3964 if (a && AT_class (a) == dw_val_class_flag)
3965 return a->dw_attr_val.v.val_flag;
3970 /* Add a signed integer attribute value to a DIE. */
3973 add_AT_int (die, attr_kind, int_val)
3974 register dw_die_ref die;
3975 register enum dwarf_attribute attr_kind;
3976 register long int int_val;
3978 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3980 attr->dw_attr_next = NULL;
3981 attr->dw_attr = attr_kind;
3982 attr->dw_attr_val.val_class = dw_val_class_const;
3983 attr->dw_attr_val.v.val_int = int_val;
3984 add_dwarf_attr (die, attr);
3987 static inline long int AT_int PARAMS ((dw_attr_ref));
3988 static inline long int
3990 register dw_attr_ref a;
3992 if (a && AT_class (a) == dw_val_class_const)
3993 return a->dw_attr_val.v.val_int;
3998 /* Add an unsigned integer attribute value to a DIE. */
4001 add_AT_unsigned (die, attr_kind, unsigned_val)
4002 register dw_die_ref die;
4003 register enum dwarf_attribute attr_kind;
4004 register unsigned long unsigned_val;
4006 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4008 attr->dw_attr_next = NULL;
4009 attr->dw_attr = attr_kind;
4010 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4011 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4012 add_dwarf_attr (die, attr);
4015 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4016 static inline unsigned long
4018 register dw_attr_ref a;
4020 if (a && AT_class (a) == dw_val_class_unsigned_const)
4021 return a->dw_attr_val.v.val_unsigned;
4026 /* Add an unsigned double integer attribute value to a DIE. */
4029 add_AT_long_long (die, attr_kind, val_hi, val_low)
4030 register dw_die_ref die;
4031 register enum dwarf_attribute attr_kind;
4032 register unsigned long val_hi;
4033 register unsigned long val_low;
4035 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4037 attr->dw_attr_next = NULL;
4038 attr->dw_attr = attr_kind;
4039 attr->dw_attr_val.val_class = dw_val_class_long_long;
4040 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4041 attr->dw_attr_val.v.val_long_long.low = val_low;
4042 add_dwarf_attr (die, attr);
4045 /* Add a floating point attribute value to a DIE and return it. */
4048 add_AT_float (die, attr_kind, length, array)
4049 register dw_die_ref die;
4050 register enum dwarf_attribute attr_kind;
4051 register unsigned length;
4052 register long *array;
4054 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4056 attr->dw_attr_next = NULL;
4057 attr->dw_attr = attr_kind;
4058 attr->dw_attr_val.val_class = dw_val_class_float;
4059 attr->dw_attr_val.v.val_float.length = length;
4060 attr->dw_attr_val.v.val_float.array = array;
4061 add_dwarf_attr (die, attr);
4064 /* Add a string attribute value to a DIE. */
4067 add_AT_string (die, attr_kind, str)
4068 register dw_die_ref die;
4069 register enum dwarf_attribute attr_kind;
4070 register const char *str;
4072 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4074 attr->dw_attr_next = NULL;
4075 attr->dw_attr = attr_kind;
4076 attr->dw_attr_val.val_class = dw_val_class_str;
4077 attr->dw_attr_val.v.val_str = xstrdup (str);
4078 add_dwarf_attr (die, attr);
4081 static inline const char *AT_string PARAMS ((dw_attr_ref));
4082 static inline const char *
4084 register dw_attr_ref a;
4086 if (a && AT_class (a) == dw_val_class_str)
4087 return a->dw_attr_val.v.val_str;
4092 /* Add a DIE reference attribute value to a DIE. */
4095 add_AT_die_ref (die, attr_kind, targ_die)
4096 register dw_die_ref die;
4097 register enum dwarf_attribute attr_kind;
4098 register dw_die_ref targ_die;
4100 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4102 attr->dw_attr_next = NULL;
4103 attr->dw_attr = attr_kind;
4104 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4105 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4106 attr->dw_attr_val.v.val_die_ref.external = 0;
4107 add_dwarf_attr (die, attr);
4110 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4111 static inline dw_die_ref
4113 register dw_attr_ref a;
4115 if (a && AT_class (a) == dw_val_class_die_ref)
4116 return a->dw_attr_val.v.val_die_ref.die;
4121 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4124 register dw_attr_ref a;
4126 if (a && AT_class (a) == dw_val_class_die_ref)
4127 return a->dw_attr_val.v.val_die_ref.external;
4132 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4134 set_AT_ref_external (a, i)
4135 register dw_attr_ref a;
4138 if (a && AT_class (a) == dw_val_class_die_ref)
4139 a->dw_attr_val.v.val_die_ref.external = i;
4144 /* Add an FDE reference attribute value to a DIE. */
4147 add_AT_fde_ref (die, attr_kind, targ_fde)
4148 register dw_die_ref die;
4149 register enum dwarf_attribute attr_kind;
4150 register unsigned targ_fde;
4152 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4154 attr->dw_attr_next = NULL;
4155 attr->dw_attr = attr_kind;
4156 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4157 attr->dw_attr_val.v.val_fde_index = targ_fde;
4158 add_dwarf_attr (die, attr);
4161 /* Add a location description attribute value to a DIE. */
4164 add_AT_loc (die, attr_kind, loc)
4165 register dw_die_ref die;
4166 register enum dwarf_attribute attr_kind;
4167 register dw_loc_descr_ref loc;
4169 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4171 attr->dw_attr_next = NULL;
4172 attr->dw_attr = attr_kind;
4173 attr->dw_attr_val.val_class = dw_val_class_loc;
4174 attr->dw_attr_val.v.val_loc = loc;
4175 add_dwarf_attr (die, attr);
4178 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4179 static inline dw_loc_descr_ref
4181 register dw_attr_ref a;
4183 if (a && AT_class (a) == dw_val_class_loc)
4184 return a->dw_attr_val.v.val_loc;
4189 /* Add an address constant attribute value to a DIE. */
4192 add_AT_addr (die, attr_kind, addr)
4193 register dw_die_ref die;
4194 register enum dwarf_attribute attr_kind;
4197 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4199 attr->dw_attr_next = NULL;
4200 attr->dw_attr = attr_kind;
4201 attr->dw_attr_val.val_class = dw_val_class_addr;
4202 attr->dw_attr_val.v.val_addr = addr;
4203 add_dwarf_attr (die, attr);
4206 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4209 register dw_attr_ref a;
4211 if (a && AT_class (a) == dw_val_class_addr)
4212 return a->dw_attr_val.v.val_addr;
4217 /* Add a label identifier attribute value to a DIE. */
4220 add_AT_lbl_id (die, attr_kind, lbl_id)
4221 register dw_die_ref die;
4222 register enum dwarf_attribute attr_kind;
4223 register const char *lbl_id;
4225 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4227 attr->dw_attr_next = NULL;
4228 attr->dw_attr = attr_kind;
4229 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4230 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4231 add_dwarf_attr (die, attr);
4234 /* Add a section offset attribute value to a DIE. */
4237 add_AT_lbl_offset (die, attr_kind, label)
4238 register dw_die_ref die;
4239 register enum dwarf_attribute attr_kind;
4240 register const char *label;
4242 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4244 attr->dw_attr_next = NULL;
4245 attr->dw_attr = attr_kind;
4246 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4247 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4248 add_dwarf_attr (die, attr);
4251 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4252 static inline const char *
4254 register dw_attr_ref a;
4256 if (a && (AT_class (a) == dw_val_class_lbl_id
4257 || AT_class (a) == dw_val_class_lbl_offset))
4258 return a->dw_attr_val.v.val_lbl_id;
4263 /* Get the attribute of type attr_kind. */
4265 static inline dw_attr_ref
4266 get_AT (die, attr_kind)
4267 register dw_die_ref die;
4268 register enum dwarf_attribute attr_kind;
4270 register dw_attr_ref a;
4271 register dw_die_ref spec = NULL;
4275 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4277 if (a->dw_attr == attr_kind)
4280 if (a->dw_attr == DW_AT_specification
4281 || a->dw_attr == DW_AT_abstract_origin)
4286 return get_AT (spec, attr_kind);
4292 /* Return the "low pc" attribute value, typically associated with
4293 a subprogram DIE. Return null if the "low pc" attribute is
4294 either not prsent, or if it cannot be represented as an
4295 assembler label identifier. */
4297 static inline const char *
4299 register dw_die_ref die;
4301 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4302 return a ? AT_lbl (a) : NULL;
4305 /* Return the "high pc" attribute value, typically associated with
4306 a subprogram DIE. Return null if the "high pc" attribute is
4307 either not prsent, or if it cannot be represented as an
4308 assembler label identifier. */
4310 static inline const char *
4312 register dw_die_ref die;
4314 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4315 return a ? AT_lbl (a) : NULL;
4318 /* Return the value of the string attribute designated by ATTR_KIND, or
4319 NULL if it is not present. */
4321 static inline const char *
4322 get_AT_string (die, attr_kind)
4323 register dw_die_ref die;
4324 register enum dwarf_attribute attr_kind;
4326 register dw_attr_ref a = get_AT (die, attr_kind);
4327 return a ? AT_string (a) : NULL;
4330 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4331 if it is not present. */
4334 get_AT_flag (die, attr_kind)
4335 register dw_die_ref die;
4336 register enum dwarf_attribute attr_kind;
4338 register dw_attr_ref a = get_AT (die, attr_kind);
4339 return a ? AT_flag (a) : 0;
4342 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4343 if it is not present. */
4345 static inline unsigned
4346 get_AT_unsigned (die, attr_kind)
4347 register dw_die_ref die;
4348 register enum dwarf_attribute attr_kind;
4350 register dw_attr_ref a = get_AT (die, attr_kind);
4351 return a ? AT_unsigned (a) : 0;
4354 static inline dw_die_ref
4355 get_AT_ref (die, attr_kind)
4357 register enum dwarf_attribute attr_kind;
4359 register dw_attr_ref a = get_AT (die, attr_kind);
4360 return a ? AT_ref (a) : NULL;
4366 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4368 return (lang == DW_LANG_C || lang == DW_LANG_C89
4369 || lang == DW_LANG_C_plus_plus);
4375 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4377 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4383 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4385 return (lang == DW_LANG_Java);
4388 /* Free up the memory used by A. */
4390 static inline void free_AT PARAMS ((dw_attr_ref));
4395 switch (AT_class (a))
4397 case dw_val_class_str:
4398 case dw_val_class_lbl_id:
4399 case dw_val_class_lbl_offset:
4400 free (a->dw_attr_val.v.val_str);
4403 case dw_val_class_float:
4404 free (a->dw_attr_val.v.val_float.array);
4414 /* Remove the specified attribute if present. */
4417 remove_AT (die, attr_kind)
4418 register dw_die_ref die;
4419 register enum dwarf_attribute attr_kind;
4421 register dw_attr_ref *p;
4422 register dw_attr_ref removed = NULL;
4426 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4427 if ((*p)->dw_attr == attr_kind)
4430 *p = (*p)->dw_attr_next;
4439 /* Free up the memory used by DIE. */
4441 static inline void free_die PARAMS ((dw_die_ref));
4446 remove_children (die);
4450 /* Discard the children of this DIE. */
4453 remove_children (die)
4454 register dw_die_ref die;
4456 register dw_die_ref child_die = die->die_child;
4458 die->die_child = NULL;
4460 while (child_die != NULL)
4462 register dw_die_ref tmp_die = child_die;
4463 register dw_attr_ref a;
4465 child_die = child_die->die_sib;
4467 for (a = tmp_die->die_attr; a != NULL;)
4469 register dw_attr_ref tmp_a = a;
4471 a = a->dw_attr_next;
4479 /* Add a child DIE below its parent. We build the lists up in reverse
4480 addition order, and correct that in reverse_all_dies. */
4483 add_child_die (die, child_die)
4484 register dw_die_ref die;
4485 register dw_die_ref child_die;
4487 if (die != NULL && child_die != NULL)
4489 if (die == child_die)
4491 child_die->die_parent = die;
4492 child_die->die_sib = die->die_child;
4493 die->die_child = child_die;
4497 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4498 is the specification, to the front of PARENT's list of children. */
4501 splice_child_die (parent, child)
4502 dw_die_ref parent, child;
4506 /* We want the declaration DIE from inside the class, not the
4507 specification DIE at toplevel. */
4508 if (child->die_parent != parent)
4510 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4515 if (child->die_parent != parent
4516 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4519 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4522 *p = child->die_sib;
4526 child->die_sib = parent->die_child;
4527 parent->die_child = child;
4530 /* Return a pointer to a newly created DIE node. */
4532 static inline dw_die_ref
4533 new_die (tag_value, parent_die)
4534 register enum dwarf_tag tag_value;
4535 register dw_die_ref parent_die;
4537 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4539 die->die_tag = tag_value;
4541 if (parent_die != NULL)
4542 add_child_die (parent_die, die);
4545 limbo_die_node *limbo_node;
4547 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4548 limbo_node->die = die;
4549 limbo_node->next = limbo_die_list;
4550 limbo_die_list = limbo_node;
4556 /* Return the DIE associated with the given type specifier. */
4558 static inline dw_die_ref
4559 lookup_type_die (type)
4562 if (TREE_CODE (type) == VECTOR_TYPE)
4563 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4564 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4567 /* Equate a DIE to a given type specifier. */
4570 equate_type_number_to_die (type, type_die)
4572 register dw_die_ref type_die;
4574 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4577 /* Return the DIE associated with a given declaration. */
4579 static inline dw_die_ref
4580 lookup_decl_die (decl)
4583 register unsigned decl_id = DECL_UID (decl);
4585 return (decl_id < decl_die_table_in_use
4586 ? decl_die_table[decl_id] : NULL);
4589 /* Equate a DIE to a particular declaration. */
4592 equate_decl_number_to_die (decl, decl_die)
4594 register dw_die_ref decl_die;
4596 register unsigned decl_id = DECL_UID (decl);
4597 register unsigned num_allocated;
4599 if (decl_id >= decl_die_table_allocated)
4602 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4603 / DECL_DIE_TABLE_INCREMENT)
4604 * DECL_DIE_TABLE_INCREMENT;
4607 = (dw_die_ref *) xrealloc (decl_die_table,
4608 sizeof (dw_die_ref) * num_allocated);
4610 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4611 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4612 decl_die_table_allocated = num_allocated;
4615 if (decl_id >= decl_die_table_in_use)
4616 decl_die_table_in_use = (decl_id + 1);
4618 decl_die_table[decl_id] = decl_die;
4621 /* Keep track of the number of spaces used to indent the
4622 output of the debugging routines that print the structure of
4623 the DIE internal representation. */
4624 static int print_indent;
4626 /* Indent the line the number of spaces given by print_indent. */
4629 print_spaces (outfile)
4632 fprintf (outfile, "%*s", print_indent, "");
4635 /* Print the information associated with a given DIE, and its children.
4636 This routine is a debugging aid only. */
4639 print_die (die, outfile)
4643 register dw_attr_ref a;
4644 register dw_die_ref c;
4646 print_spaces (outfile);
4647 fprintf (outfile, "DIE %4lu: %s\n",
4648 die->die_offset, dwarf_tag_name (die->die_tag));
4649 print_spaces (outfile);
4650 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4651 fprintf (outfile, " offset: %lu\n", die->die_offset);
4653 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4655 print_spaces (outfile);
4656 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4658 switch (AT_class (a))
4660 case dw_val_class_addr:
4661 fprintf (outfile, "address");
4663 case dw_val_class_loc:
4664 fprintf (outfile, "location descriptor");
4666 case dw_val_class_const:
4667 fprintf (outfile, "%ld", AT_int (a));
4669 case dw_val_class_unsigned_const:
4670 fprintf (outfile, "%lu", AT_unsigned (a));
4672 case dw_val_class_long_long:
4673 fprintf (outfile, "constant (%lu,%lu)",
4674 a->dw_attr_val.v.val_long_long.hi,
4675 a->dw_attr_val.v.val_long_long.low);
4677 case dw_val_class_float:
4678 fprintf (outfile, "floating-point constant");
4680 case dw_val_class_flag:
4681 fprintf (outfile, "%u", AT_flag (a));
4683 case dw_val_class_die_ref:
4684 if (AT_ref (a) != NULL)
4686 if (AT_ref (a)->die_symbol)
4687 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
4689 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4692 fprintf (outfile, "die -> <null>");
4694 case dw_val_class_lbl_id:
4695 case dw_val_class_lbl_offset:
4696 fprintf (outfile, "label: %s", AT_lbl (a));
4698 case dw_val_class_str:
4699 if (AT_string (a) != NULL)
4700 fprintf (outfile, "\"%s\"", AT_string (a));
4702 fprintf (outfile, "<null>");
4708 fprintf (outfile, "\n");
4711 if (die->die_child != NULL)
4714 for (c = die->die_child; c != NULL; c = c->die_sib)
4715 print_die (c, outfile);
4719 if (print_indent == 0)
4720 fprintf (outfile, "\n");
4723 /* Print the contents of the source code line number correspondence table.
4724 This routine is a debugging aid only. */
4727 print_dwarf_line_table (outfile)
4730 register unsigned i;
4731 register dw_line_info_ref line_info;
4733 fprintf (outfile, "\n\nDWARF source line information\n");
4734 for (i = 1; i < line_info_table_in_use; ++i)
4736 line_info = &line_info_table[i];
4737 fprintf (outfile, "%5d: ", i);
4738 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
4739 fprintf (outfile, "%6ld", line_info->dw_line_num);
4740 fprintf (outfile, "\n");
4743 fprintf (outfile, "\n\n");
4746 /* Print the information collected for a given DIE. */
4749 debug_dwarf_die (die)
4752 print_die (die, stderr);
4755 /* Print all DWARF information collected for the compilation unit.
4756 This routine is a debugging aid only. */
4762 print_die (comp_unit_die, stderr);
4763 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4764 print_dwarf_line_table (stderr);
4767 /* We build up the lists of children and attributes by pushing new ones
4768 onto the beginning of the list. Reverse the lists for DIE so that
4769 they are in order of addition. */
4772 reverse_die_lists (die)
4773 register dw_die_ref die;
4775 register dw_die_ref c, cp, cn;
4776 register dw_attr_ref a, ap, an;
4778 for (a = die->die_attr, ap = 0; a; a = an)
4780 an = a->dw_attr_next;
4781 a->dw_attr_next = ap;
4786 for (c = die->die_child, cp = 0; c; c = cn)
4792 die->die_child = cp;
4795 /* reverse_die_lists only reverses the single die you pass it. Since
4796 we used to reverse all dies in add_sibling_attributes, which runs
4797 through all the dies, it would reverse all the dies. Now, however,
4798 since we don't call reverse_die_lists in add_sibling_attributes, we
4799 need a routine to recursively reverse all the dies. This is that
4803 reverse_all_dies (die)
4804 register dw_die_ref die;
4806 register dw_die_ref c;
4808 reverse_die_lists (die);
4810 for (c = die->die_child; c; c = c->die_sib)
4811 reverse_all_dies (c);
4814 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
4815 the CU for the enclosing include file, if any. BINCL_DIE is the
4816 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
4820 push_new_compile_unit (old_unit, bincl_die)
4821 dw_die_ref old_unit, bincl_die;
4823 const char *filename = get_AT_string (bincl_die, DW_AT_name);
4824 dw_die_ref new_unit = gen_compile_unit_die (filename);
4825 new_unit->die_sib = old_unit;
4829 /* Close an include-file CU and reopen the enclosing one. */
4832 pop_compile_unit (old_unit)
4833 dw_die_ref old_unit;
4835 dw_die_ref new_unit = old_unit->die_sib;
4836 old_unit->die_sib = NULL;
4840 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
4841 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
4843 /* Calculate the checksum of a location expression. */
4846 loc_checksum (loc, ctx)
4847 dw_loc_descr_ref loc;
4848 struct md5_ctx *ctx;
4850 PROCESS (loc->dw_loc_opc);
4851 PROCESS (loc->dw_loc_oprnd1);
4852 PROCESS (loc->dw_loc_oprnd2);
4855 /* Calculate the checksum of an attribute. */
4858 attr_checksum (at, ctx)
4860 struct md5_ctx *ctx;
4862 dw_loc_descr_ref loc;
4865 PROCESS (at->dw_attr);
4867 /* We don't care about differences in file numbering. */
4868 if (at->dw_attr == DW_AT_decl_file
4869 /* Or that this was compiled with a different compiler snapshot; if
4870 the output is the same, that's what matters. */
4871 || at->dw_attr == DW_AT_producer)
4874 switch (AT_class (at))
4876 case dw_val_class_const:
4877 PROCESS (at->dw_attr_val.v.val_int);
4879 case dw_val_class_unsigned_const:
4880 PROCESS (at->dw_attr_val.v.val_unsigned);
4882 case dw_val_class_long_long:
4883 PROCESS (at->dw_attr_val.v.val_long_long);
4885 case dw_val_class_float:
4886 PROCESS (at->dw_attr_val.v.val_float);
4888 case dw_val_class_flag:
4889 PROCESS (at->dw_attr_val.v.val_flag);
4892 case dw_val_class_str:
4893 PROCESS_STRING (AT_string (at));
4895 case dw_val_class_addr:
4897 switch (GET_CODE (r))
4900 PROCESS_STRING (XSTR (r, 0));
4908 case dw_val_class_loc:
4909 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
4910 loc_checksum (loc, ctx);
4913 case dw_val_class_die_ref:
4914 if (AT_ref (at)->die_offset)
4915 PROCESS (AT_ref (at)->die_offset);
4916 /* FIXME else use target die name or something. */
4918 case dw_val_class_fde_ref:
4919 case dw_val_class_lbl_id:
4920 case dw_val_class_lbl_offset:
4927 /* Calculate the checksum of a DIE. */
4930 die_checksum (die, ctx)
4932 struct md5_ctx *ctx;
4937 PROCESS (die->die_tag);
4939 for (a = die->die_attr; a; a = a->dw_attr_next)
4940 attr_checksum (a, ctx);
4942 for (c = die->die_child; c; c = c->die_sib)
4943 die_checksum (c, ctx);
4947 #undef PROCESS_STRING
4949 /* The prefix to attach to symbols on DIEs in the current comdat debug
4951 static char *comdat_symbol_id;
4953 /* The index of the current symbol within the current comdat CU. */
4954 static unsigned int comdat_symbol_number;
4956 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
4957 children, and set comdat_symbol_id accordingly. */
4960 compute_section_prefix (unit_die)
4961 dw_die_ref unit_die;
4965 unsigned char checksum[16];
4968 md5_init_ctx (&ctx);
4969 die_checksum (unit_die, &ctx);
4970 md5_finish_ctx (&ctx, checksum);
4972 p = lbasename (get_AT_string (unit_die, DW_AT_name));
4973 name = (char *) alloca (strlen (p) + 64);
4974 sprintf (name, "%s.", p);
4976 clean_symbol_name (name);
4978 p = name + strlen (name);
4979 for (i = 0; i < 4; ++i)
4981 sprintf (p, "%.2x", checksum[i]);
4985 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
4986 comdat_symbol_number = 0;
4989 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
4995 switch (die->die_tag)
4997 case DW_TAG_array_type:
4998 case DW_TAG_class_type:
4999 case DW_TAG_enumeration_type:
5000 case DW_TAG_pointer_type:
5001 case DW_TAG_reference_type:
5002 case DW_TAG_string_type:
5003 case DW_TAG_structure_type:
5004 case DW_TAG_subroutine_type:
5005 case DW_TAG_union_type:
5006 case DW_TAG_ptr_to_member_type:
5007 case DW_TAG_set_type:
5008 case DW_TAG_subrange_type:
5009 case DW_TAG_base_type:
5010 case DW_TAG_const_type:
5011 case DW_TAG_file_type:
5012 case DW_TAG_packed_type:
5013 case DW_TAG_volatile_type:
5020 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5021 Basically, we want to choose the bits that are likely to be shared between
5022 compilations (types) and leave out the bits that are specific to individual
5023 compilations (functions). */
5030 /* I think we want to leave base types and __vtbl_ptr_type in the
5031 main CU, as we do for stabs. The advantage is a greater
5032 likelihood of sharing between objects that don't include headers
5033 in the same order (and therefore would put the base types in a
5034 different comdat). jason 8/28/00 */
5035 if (c->die_tag == DW_TAG_base_type)
5038 if (c->die_tag == DW_TAG_pointer_type
5039 || c->die_tag == DW_TAG_reference_type
5040 || c->die_tag == DW_TAG_const_type
5041 || c->die_tag == DW_TAG_volatile_type)
5043 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5044 return t ? is_comdat_die (t) : 0;
5048 return is_type_die (c);
5051 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5052 compilation unit. */
5058 if (is_type_die (c))
5060 if (get_AT (c, DW_AT_declaration)
5061 && ! get_AT (c, DW_AT_specification))
5070 static int label_num;
5071 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5072 return xstrdup (buf);
5075 /* Assign symbols to all worthy DIEs under DIE. */
5078 assign_symbol_names (die)
5079 register dw_die_ref die;
5081 register dw_die_ref c;
5083 if (is_symbol_die (die))
5085 if (comdat_symbol_id)
5087 char *p = alloca (strlen (comdat_symbol_id) + 64);
5088 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5089 comdat_symbol_id, comdat_symbol_number++);
5090 die->die_symbol = xstrdup (p);
5093 die->die_symbol = gen_internal_sym ();
5096 for (c = die->die_child; c != NULL; c = c->die_sib)
5097 assign_symbol_names (c);
5100 /* Traverse the DIE (which is always comp_unit_die), and set up
5101 additional compilation units for each of the include files we see
5102 bracketed by BINCL/EINCL. */
5105 break_out_includes (die)
5106 register dw_die_ref die;
5109 register dw_die_ref unit = NULL;
5110 limbo_die_node *node;
5112 for (ptr = &(die->die_child); *ptr; )
5114 register dw_die_ref c = *ptr;
5116 if (c->die_tag == DW_TAG_GNU_BINCL
5117 || c->die_tag == DW_TAG_GNU_EINCL
5118 || (unit && is_comdat_die (c)))
5120 /* This DIE is for a secondary CU; remove it from the main one. */
5123 if (c->die_tag == DW_TAG_GNU_BINCL)
5125 unit = push_new_compile_unit (unit, c);
5128 else if (c->die_tag == DW_TAG_GNU_EINCL)
5130 unit = pop_compile_unit (unit);
5134 add_child_die (unit, c);
5138 /* Leave this DIE in the main CU. */
5139 ptr = &(c->die_sib);
5145 /* We can only use this in debugging, since the frontend doesn't check
5146 to make sure that we leave every include file we enter. */
5151 assign_symbol_names (die);
5152 for (node = limbo_die_list; node; node = node->next)
5154 compute_section_prefix (node->die);
5155 assign_symbol_names (node->die);
5159 /* Traverse the DIE and add a sibling attribute if it may have the
5160 effect of speeding up access to siblings. To save some space,
5161 avoid generating sibling attributes for DIE's without children. */
5164 add_sibling_attributes (die)
5165 register dw_die_ref die;
5167 register dw_die_ref c;
5169 if (die->die_tag != DW_TAG_compile_unit
5170 && die->die_sib && die->die_child != NULL)
5171 /* Add the sibling link to the front of the attribute list. */
5172 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5174 for (c = die->die_child; c != NULL; c = c->die_sib)
5175 add_sibling_attributes (c);
5178 /* The format of each DIE (and its attribute value pairs)
5179 is encoded in an abbreviation table. This routine builds the
5180 abbreviation table and assigns a unique abbreviation id for
5181 each abbreviation entry. The children of each die are visited
5185 build_abbrev_table (die)
5186 register dw_die_ref die;
5188 register unsigned long abbrev_id;
5189 register unsigned long n_alloc;
5190 register dw_die_ref c;
5191 register dw_attr_ref d_attr, a_attr;
5193 /* Scan the DIE references, and mark as external any that refer to
5194 DIEs from other CUs (i.e. those which are not marked). */
5195 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5197 if (AT_class (d_attr) == dw_val_class_die_ref
5198 && AT_ref (d_attr)->die_mark == 0)
5200 if (AT_ref (d_attr)->die_symbol == 0)
5202 set_AT_ref_external (d_attr, 1);
5206 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5208 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5210 if (abbrev->die_tag == die->die_tag)
5212 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5214 a_attr = abbrev->die_attr;
5215 d_attr = die->die_attr;
5217 while (a_attr != NULL && d_attr != NULL)
5219 if ((a_attr->dw_attr != d_attr->dw_attr)
5220 || (value_format (a_attr) != value_format (d_attr)))
5223 a_attr = a_attr->dw_attr_next;
5224 d_attr = d_attr->dw_attr_next;
5227 if (a_attr == NULL && d_attr == NULL)
5233 if (abbrev_id >= abbrev_die_table_in_use)
5235 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5237 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5239 = (dw_die_ref *) xrealloc (abbrev_die_table,
5240 sizeof (dw_die_ref) * n_alloc);
5242 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5243 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5244 abbrev_die_table_allocated = n_alloc;
5247 ++abbrev_die_table_in_use;
5248 abbrev_die_table[abbrev_id] = die;
5251 die->die_abbrev = abbrev_id;
5252 for (c = die->die_child; c != NULL; c = c->die_sib)
5253 build_abbrev_table (c);
5256 /* Return the size of a string, including the null byte.
5258 This used to treat backslashes as escapes, and hence they were not included
5259 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5260 which treats a backslash as a backslash, escaping it if necessary, and hence
5261 we must include them in the count. */
5263 static unsigned long
5264 size_of_string (str)
5265 register const char *str;
5267 return strlen (str) + 1;
5270 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5273 constant_size (value)
5274 long unsigned value;
5281 log = floor_log2 (value);
5284 log = 1 << (floor_log2 (log) + 1);
5289 /* Return the size of a DIE, as it is represented in the
5290 .debug_info section. */
5292 static unsigned long
5294 register dw_die_ref die;
5296 register unsigned long size = 0;
5297 register dw_attr_ref a;
5299 size += size_of_uleb128 (die->die_abbrev);
5300 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5302 switch (AT_class (a))
5304 case dw_val_class_addr:
5305 size += DWARF2_ADDR_SIZE;
5307 case dw_val_class_loc:
5309 register unsigned long lsize = size_of_locs (AT_loc (a));
5312 size += constant_size (lsize);
5316 case dw_val_class_const:
5317 size += size_of_sleb128 (AT_int (a));
5319 case dw_val_class_unsigned_const:
5320 size += constant_size (AT_unsigned (a));
5322 case dw_val_class_long_long:
5323 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5325 case dw_val_class_float:
5326 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5328 case dw_val_class_flag:
5331 case dw_val_class_die_ref:
5332 size += DWARF_OFFSET_SIZE;
5334 case dw_val_class_fde_ref:
5335 size += DWARF_OFFSET_SIZE;
5337 case dw_val_class_lbl_id:
5338 size += DWARF2_ADDR_SIZE;
5340 case dw_val_class_lbl_offset:
5341 size += DWARF_OFFSET_SIZE;
5343 case dw_val_class_str:
5344 size += size_of_string (AT_string (a));
5354 /* Size the debugging information associated with a given DIE.
5355 Visits the DIE's children recursively. Updates the global
5356 variable next_die_offset, on each time through. Uses the
5357 current value of next_die_offset to update the die_offset
5358 field in each DIE. */
5361 calc_die_sizes (die)
5364 register dw_die_ref c;
5365 die->die_offset = next_die_offset;
5366 next_die_offset += size_of_die (die);
5368 for (c = die->die_child; c != NULL; c = c->die_sib)
5371 if (die->die_child != NULL)
5372 /* Count the null byte used to terminate sibling lists. */
5373 next_die_offset += 1;
5376 /* Set the marks for a die and its children. We do this so
5377 that we know whether or not a reference needs to use FORM_ref_addr; only
5378 DIEs in the same CU will be marked. We used to clear out the offset
5379 and use that as the flag, but ran into ordering problems. */
5385 register dw_die_ref c;
5387 for (c = die->die_child; c; c = c->die_sib)
5391 /* Clear the marks for a die and its children. */
5397 register dw_die_ref c;
5399 for (c = die->die_child; c; c = c->die_sib)
5403 /* Return the size of the .debug_pubnames table generated for the
5404 compilation unit. */
5406 static unsigned long
5409 register unsigned long size;
5410 register unsigned i;
5412 size = DWARF_PUBNAMES_HEADER_SIZE;
5413 for (i = 0; i < pubname_table_in_use; ++i)
5415 register pubname_ref p = &pubname_table[i];
5416 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5419 size += DWARF_OFFSET_SIZE;
5423 /* Return the size of the information in the .debug_aranges section. */
5425 static unsigned long
5428 register unsigned long size;
5430 size = DWARF_ARANGES_HEADER_SIZE;
5432 /* Count the address/length pair for this compilation unit. */
5433 size += 2 * DWARF2_ADDR_SIZE;
5434 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5436 /* Count the two zero words used to terminated the address range table. */
5437 size += 2 * DWARF2_ADDR_SIZE;
5441 /* Select the encoding of an attribute value. */
5443 static enum dwarf_form
5447 switch (a->dw_attr_val.val_class)
5449 case dw_val_class_addr:
5450 return DW_FORM_addr;
5451 case dw_val_class_loc:
5452 switch (constant_size (size_of_locs (AT_loc (a))))
5455 return DW_FORM_block1;
5457 return DW_FORM_block2;
5461 case dw_val_class_const:
5462 return DW_FORM_sdata;
5463 case dw_val_class_unsigned_const:
5464 switch (constant_size (AT_unsigned (a)))
5467 return DW_FORM_data1;
5469 return DW_FORM_data2;
5471 return DW_FORM_data4;
5473 return DW_FORM_data8;
5477 case dw_val_class_long_long:
5478 return DW_FORM_block1;
5479 case dw_val_class_float:
5480 return DW_FORM_block1;
5481 case dw_val_class_flag:
5482 return DW_FORM_flag;
5483 case dw_val_class_die_ref:
5484 if (AT_ref_external (a))
5485 return DW_FORM_ref_addr;
5488 case dw_val_class_fde_ref:
5489 return DW_FORM_data;
5490 case dw_val_class_lbl_id:
5491 return DW_FORM_addr;
5492 case dw_val_class_lbl_offset:
5493 return DW_FORM_data;
5494 case dw_val_class_str:
5495 return DW_FORM_string;
5501 /* Output the encoding of an attribute value. */
5504 output_value_format (a)
5507 enum dwarf_form form = value_format (a);
5508 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
5511 /* Output the .debug_abbrev section which defines the DIE abbreviation
5515 output_abbrev_section ()
5517 unsigned long abbrev_id;
5520 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5522 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5524 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
5526 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
5527 dwarf_tag_name (abbrev->die_tag));
5529 if (abbrev->die_child != NULL)
5530 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
5532 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
5534 for (a_attr = abbrev->die_attr; a_attr != NULL;
5535 a_attr = a_attr->dw_attr_next)
5537 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
5538 dwarf_attr_name (a_attr->dw_attr));
5539 output_value_format (a_attr);
5542 dw2_asm_output_data (1, 0, NULL);
5543 dw2_asm_output_data (1, 0, NULL);
5546 /* Terminate the table. */
5547 dw2_asm_output_data (1, 0, NULL);
5550 /* Output a symbol we can use to refer to this DIE from another CU. */
5553 output_die_symbol (die)
5554 register dw_die_ref die;
5556 char *sym = die->die_symbol;
5561 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5562 /* We make these global, not weak; if the target doesn't support
5563 .linkonce, it doesn't support combining the sections, so debugging
5565 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5566 ASM_OUTPUT_LABEL (asm_out_file, sym);
5569 /* Output the DIE and its attributes. Called recursively to generate
5570 the definitions of each child DIE. */
5574 register dw_die_ref die;
5576 register dw_attr_ref a;
5577 register dw_die_ref c;
5578 register unsigned long size;
5580 /* If someone in another CU might refer to us, set up a symbol for
5581 them to point to. */
5582 if (die->die_symbol)
5583 output_die_symbol (die);
5585 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
5586 die->die_offset, dwarf_tag_name (die->die_tag));
5588 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5590 const char *name = dwarf_attr_name (a->dw_attr);
5592 switch (AT_class (a))
5594 case dw_val_class_addr:
5595 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
5598 case dw_val_class_loc:
5599 size = size_of_locs (AT_loc (a));
5601 /* Output the block length for this list of location operations. */
5602 dw2_asm_output_data (constant_size (size), size, "%s", name);
5604 output_loc_sequence (AT_loc (a));
5607 case dw_val_class_const:
5608 /* ??? It would be slightly more efficient to use a scheme like is
5609 used for unsigned constants below, but gdb 4.x does not sign
5610 extend. Gdb 5.x does sign extend. */
5611 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
5614 case dw_val_class_unsigned_const:
5615 dw2_asm_output_data (constant_size (AT_unsigned (a)),
5616 AT_unsigned (a), "%s", name);
5619 case dw_val_class_long_long:
5621 unsigned HOST_WIDE_INT first, second;
5623 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5626 if (WORDS_BIG_ENDIAN)
5628 first = a->dw_attr_val.v.val_long_long.hi;
5629 second = a->dw_attr_val.v.val_long_long.low;
5633 first = a->dw_attr_val.v.val_long_long.low;
5634 second = a->dw_attr_val.v.val_long_long.hi;
5636 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5637 first, "long long constant");
5638 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5643 case dw_val_class_float:
5645 register unsigned int i;
5647 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
5650 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5651 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
5652 "fp constant word %u", i);
5656 case dw_val_class_flag:
5657 dw2_asm_output_data (1, AT_flag (a), "%s", name);
5660 case dw_val_class_die_ref:
5661 if (AT_ref_external (a))
5663 char *sym = AT_ref (a)->die_symbol;
5666 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
5668 else if (AT_ref (a)->die_offset == 0)
5671 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
5675 case dw_val_class_fde_ref:
5678 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
5679 a->dw_attr_val.v.val_fde_index * 2);
5680 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
5684 case dw_val_class_lbl_id:
5685 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
5688 case dw_val_class_lbl_offset:
5689 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
5692 case dw_val_class_str:
5693 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
5701 for (c = die->die_child; c != NULL; c = c->die_sib)
5704 if (die->die_child != NULL)
5706 /* Add null byte to terminate sibling list. */
5707 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
5712 /* Output the compilation unit that appears at the beginning of the
5713 .debug_info section, and precedes the DIE descriptions. */
5716 output_compilation_unit_header ()
5718 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
5719 "Length of Compilation Unit Info");
5721 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
5723 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
5724 "Offset Into Abbrev. Section");
5726 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
5729 /* Output the compilation unit DIE and its children. */
5732 output_comp_unit (die)
5735 const char *secname;
5737 if (die->die_child == 0)
5740 /* Mark all the DIEs in this CU so we know which get local refs. */
5743 build_abbrev_table (die);
5745 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
5746 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
5747 calc_die_sizes (die);
5749 if (die->die_symbol)
5751 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
5752 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
5754 die->die_symbol = NULL;
5757 secname = (const char *) DEBUG_INFO_SECTION;
5759 /* Output debugging information. */
5760 ASM_OUTPUT_SECTION (asm_out_file, secname);
5761 output_compilation_unit_header ();
5764 /* Leave the marks on the main CU, so we can check them in
5766 if (die->die_symbol)
5770 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5771 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5772 argument list, and maybe the scope. */
5775 dwarf2_name (decl, scope)
5779 return (*decl_printable_name) (decl, scope ? 1 : 0);
5782 /* Add a new entry to .debug_pubnames if appropriate. */
5785 add_pubname (decl, die)
5791 if (! TREE_PUBLIC (decl))
5794 if (pubname_table_in_use == pubname_table_allocated)
5796 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5797 pubname_table = (pubname_ref) xrealloc
5798 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5801 p = &pubname_table[pubname_table_in_use++];
5804 p->name = xstrdup (dwarf2_name (decl, 1));
5807 /* Output the public names table used to speed up access to externally
5808 visible names. For now, only generate entries for externally
5809 visible procedures. */
5814 register unsigned i;
5815 register unsigned long pubnames_length = size_of_pubnames ();
5817 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
5818 "Length of Public Names Info");
5820 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
5822 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
5823 "Offset of Compilation Unit Info");
5825 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
5826 "Compilation Unit Length");
5828 for (i = 0; i < pubname_table_in_use; ++i)
5830 register pubname_ref pub = &pubname_table[i];
5832 /* We shouldn't see pubnames for DIEs outside of the main CU. */
5833 if (pub->die->die_mark == 0)
5836 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
5839 dw2_asm_output_nstring (pub->name, -1, "external name");
5842 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
5845 /* Add a new entry to .debug_aranges if appropriate. */
5848 add_arange (decl, die)
5852 if (! DECL_SECTION_NAME (decl))
5855 if (arange_table_in_use == arange_table_allocated)
5857 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5859 = (arange_ref) xrealloc (arange_table,
5860 arange_table_allocated * sizeof (dw_die_ref));
5863 arange_table[arange_table_in_use++] = die;
5866 /* Output the information that goes into the .debug_aranges table.
5867 Namely, define the beginning and ending address range of the
5868 text section generated for this compilation unit. */
5873 register unsigned i;
5874 register unsigned long aranges_length = size_of_aranges ();
5876 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
5877 "Length of Address Ranges Info");
5879 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
5881 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
5882 "Offset of Compilation Unit Info");
5884 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
5886 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
5888 /* We need to align to twice the pointer size here. */
5889 if (DWARF_ARANGES_PAD_SIZE)
5891 /* Pad using a 2 byte words so that padding is correct for any
5893 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
5894 2 * DWARF2_ADDR_SIZE);
5895 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
5896 dw2_asm_output_data (2, 0, NULL);
5899 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
5900 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
5901 text_section_label, "Length");
5903 for (i = 0; i < arange_table_in_use; ++i)
5905 dw_die_ref die = arange_table[i];
5907 /* We shouldn't see aranges for DIEs outside of the main CU. */
5908 if (die->die_mark == 0)
5911 if (die->die_tag == DW_TAG_subprogram)
5913 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
5915 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
5916 get_AT_low_pc (die), "Length");
5920 /* A static variable; extract the symbol from DW_AT_location.
5921 Note that this code isn't currently hit, as we only emit
5922 aranges for functions (jason 9/23/99). */
5924 dw_attr_ref a = get_AT (die, DW_AT_location);
5925 dw_loc_descr_ref loc;
5926 if (! a || AT_class (a) != dw_val_class_loc)
5930 if (loc->dw_loc_opc != DW_OP_addr)
5933 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
5934 loc->dw_loc_oprnd1.v.val_addr, "Address");
5935 dw2_asm_output_data (DWARF2_ADDR_SIZE,
5936 get_AT_unsigned (die, DW_AT_byte_size),
5941 /* Output the terminator words. */
5942 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
5943 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
5947 /* Data structure containing information about input files. */
5950 char *path; /* Complete file name. */
5951 char *fname; /* File name part. */
5952 int length; /* Length of entire string. */
5953 int file_idx; /* Index in input file table. */
5954 int dir_idx; /* Index in directory table. */
5957 /* Data structure containing information about directories with source
5961 char *path; /* Path including directory name. */
5962 int length; /* Path length. */
5963 int prefix; /* Index of directory entry which is a prefix. */
5964 int count; /* Number of files in this directory. */
5965 int dir_idx; /* Index of directory used as base. */
5966 int used; /* Used in the end? */
5969 /* Callback function for file_info comparison. We sort by looking at
5970 the directories in the path. */
5972 file_info_cmp (p1, p2)
5976 const struct file_info *s1 = p1;
5977 const struct file_info *s2 = p2;
5981 /* Take care of file names without directories. */
5982 if (s1->path == s1->fname)
5984 else if (s2->path == s2->fname)
5987 cp1 = (unsigned char *) s1->path;
5988 cp2 = (unsigned char *) s2->path;
5994 /* Reached the end of the first path? */
5995 if (cp1 == (unsigned char *) s1->fname)
5996 /* It doesn't really matter in which order files from the
5997 same directory are sorted in. Therefore don't test for
5998 the second path reaching the end. */
6000 else if (cp2 == (unsigned char *) s2->fname)
6003 /* Character of current path component the same? */
6009 /* Output the directory table and the file name table. We try to minimize
6010 the total amount of memory needed. A heuristic is used to avoid large
6011 slowdowns with many input files. */
6013 output_file_names ()
6015 struct file_info *files;
6016 struct dir_info *dirs;
6025 /* Allocate the various arrays we need. */
6026 files = (struct file_info *) alloca (file_table.in_use
6027 * sizeof (struct file_info));
6028 dirs = (struct dir_info *) alloca (file_table.in_use
6029 * sizeof (struct dir_info));
6031 /* Sort the file names. */
6032 for (i = 1; i < (int) file_table.in_use; ++i)
6036 /* Skip all leading "./". */
6037 f = file_table.table[i];
6038 while (f[0] == '.' && f[1] == '/')
6041 /* Create a new array entry. */
6043 files[i].length = strlen (f);
6044 files[i].file_idx = i;
6046 /* Search for the file name part. */
6047 f = strrchr (f, '/');
6048 files[i].fname = f == NULL ? files[i].path : f + 1;
6050 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6052 /* Find all the different directories used. */
6053 dirs[0].path = files[1].path;
6054 dirs[0].length = files[1].fname - files[1].path;
6055 dirs[0].prefix = -1;
6057 dirs[0].dir_idx = 0;
6059 files[1].dir_idx = 0;
6062 for (i = 2; i < (int) file_table.in_use; ++i)
6063 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6064 && memcmp (dirs[ndirs - 1].path, files[i].path,
6065 dirs[ndirs - 1].length) == 0)
6067 /* Same directory as last entry. */
6068 files[i].dir_idx = ndirs - 1;
6069 ++dirs[ndirs - 1].count;
6075 /* This is a new directory. */
6076 dirs[ndirs].path = files[i].path;
6077 dirs[ndirs].length = files[i].fname - files[i].path;
6078 dirs[ndirs].count = 1;
6079 dirs[ndirs].dir_idx = ndirs;
6080 dirs[ndirs].used = 0;
6081 files[i].dir_idx = ndirs;
6083 /* Search for a prefix. */
6084 dirs[ndirs].prefix = -1;
6085 for (j = 0; j < ndirs; ++j)
6086 if (dirs[j].length < dirs[ndirs].length
6087 && dirs[j].length > 1
6088 && (dirs[ndirs].prefix == -1
6089 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6090 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6091 dirs[ndirs].prefix = j;
6096 /* Now to the actual work. We have to find a subset of the
6097 directories which allow expressing the file name using references
6098 to the directory table with the least amount of characters. We
6099 do not do an exhaustive search where we would have to check out
6100 every combination of every single possible prefix. Instead we
6101 use a heuristic which provides nearly optimal results in most
6102 cases and never is much off. */
6103 saved = (int *) alloca (ndirs * sizeof (int));
6104 savehere = (int *) alloca (ndirs * sizeof (int));
6106 memset (saved, '\0', ndirs * sizeof (saved[0]));
6107 for (i = 0; i < ndirs; ++i)
6112 /* We can always save some space for the current directory. But
6113 this does not mean it will be enough to justify adding the
6115 savehere[i] = dirs[i].length;
6116 total = (savehere[i] - saved[i]) * dirs[i].count;
6118 for (j = i + 1; j < ndirs; ++j)
6122 if (saved[j] < dirs[i].length)
6124 /* Determine whether the dirs[i] path is a prefix of the
6129 while (k != -1 && k != i)
6134 /* Yes it is. We can possibly safe some memory but
6135 writing the filenames in dirs[j] relative to
6137 savehere[j] = dirs[i].length;
6138 total += (savehere[j] - saved[j]) * dirs[j].count;
6143 /* Check whether we can safe enough to justify adding the dirs[i]
6145 if (total > dirs[i].length + 1)
6147 /* It's worthwhile adding. */
6148 for (j = i; j < ndirs; ++j)
6149 if (savehere[j] > 0)
6151 /* Remember how much we saved for this directory so far. */
6152 saved[j] = savehere[j];
6154 /* Remember the prefix directory. */
6155 dirs[j].dir_idx = i;
6160 /* We have to emit them in the order they appear in the file_table
6161 array since the index is used in the debug info generation. To
6162 do this efficiently we generate a back-mapping of the indices
6164 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6165 for (i = 1; i < (int) file_table.in_use; ++i)
6167 backmap[files[i].file_idx] = i;
6168 /* Mark this directory as used. */
6169 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6172 /* That was it. We are ready to emit the information. First the
6173 directory name table. Here we have to make sure that the first
6174 actually emitted directory name has the index one. Zero is
6175 reserved for the current working directory. Make sure we do not
6176 confuse these indices with the one for the constructed table
6177 (even though most of the time they are identical). */
6179 idx_offset = dirs[0].length > 0 ? 1 : 0;
6180 for (i = 1 - idx_offset; i < ndirs; ++i)
6181 if (dirs[i].used != 0)
6183 dirs[i].used = idx++;
6184 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6185 "Directory Entry: 0x%x", dirs[i].used);
6187 dw2_asm_output_data (1, 0, "End directory table");
6189 /* Correct the index for the current working directory entry if it
6191 if (idx_offset == 0)
6194 /* Now write all the file names. */
6195 for (i = 1; i < (int) file_table.in_use; ++i)
6197 int file_idx = backmap[i];
6198 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6200 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6201 "File Entry: 0x%x", i);
6203 /* Include directory index. */
6204 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6206 /* Modification time. */
6207 dw2_asm_output_data_uleb128 (0, NULL);
6209 /* File length in bytes. */
6210 dw2_asm_output_data_uleb128 (0, NULL);
6212 dw2_asm_output_data (1, 0, "End file name table");
6216 /* Output the source line number correspondence information. This
6217 information goes into the .debug_line section. */
6222 char l1[20], l2[20], p1[20], p2[20];
6223 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6224 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6225 register unsigned opc;
6226 register unsigned n_op_args;
6227 register unsigned long lt_index;
6228 register unsigned long current_line;
6229 register long line_offset;
6230 register long line_delta;
6231 register unsigned long current_file;
6232 register unsigned long function;
6234 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6235 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6236 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6237 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6239 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6240 "Length of Source Line Info");
6241 ASM_OUTPUT_LABEL (asm_out_file, l1);
6243 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6245 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6246 ASM_OUTPUT_LABEL (asm_out_file, p1);
6248 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6249 "Minimum Instruction Length");
6251 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6252 "Default is_stmt_start flag");
6254 dw2_asm_output_data (1, DWARF_LINE_BASE,
6255 "Line Base Value (Special Opcodes)");
6257 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6258 "Line Range Value (Special Opcodes)");
6260 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6261 "Special Opcode Base");
6263 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6267 case DW_LNS_advance_pc:
6268 case DW_LNS_advance_line:
6269 case DW_LNS_set_file:
6270 case DW_LNS_set_column:
6271 case DW_LNS_fixed_advance_pc:
6279 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6283 /* Write out the information about the files we use. */
6284 output_file_names ();
6285 ASM_OUTPUT_LABEL (asm_out_file, p2);
6287 /* We used to set the address register to the first location in the text
6288 section here, but that didn't accomplish anything since we already
6289 have a line note for the opening brace of the first function. */
6291 /* Generate the line number to PC correspondence table, encoded as
6292 a series of state machine operations. */
6295 strcpy (prev_line_label, text_section_label);
6296 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6298 register dw_line_info_ref line_info = &line_info_table[lt_index];
6301 /* Disable this optimization for now; GDB wants to see two line notes
6302 at the beginning of a function so it can find the end of the
6305 /* Don't emit anything for redundant notes. Just updating the
6306 address doesn't accomplish anything, because we already assume
6307 that anything after the last address is this line. */
6308 if (line_info->dw_line_num == current_line
6309 && line_info->dw_file_num == current_file)
6313 /* Emit debug info for the address of the current line.
6315 Unfortunately, we have little choice here currently, and must always
6316 use the most general form. Gcc does not know the address delta
6317 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
6318 attributes which will give an upper bound on the address range. We
6319 could perhaps use length attributes to determine when it is safe to
6320 use DW_LNS_fixed_advance_pc. */
6322 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6325 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6326 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6327 "DW_LNS_fixed_advance_pc");
6328 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6332 /* This can handle any delta. This takes
6333 4+DWARF2_ADDR_SIZE bytes. */
6334 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6335 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6336 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6337 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6339 strcpy (prev_line_label, line_label);
6341 /* Emit debug info for the source file of the current line, if
6342 different from the previous line. */
6343 if (line_info->dw_file_num != current_file)
6345 current_file = line_info->dw_file_num;
6346 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6347 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6348 file_table.table[current_file]);
6351 /* Emit debug info for the current line number, choosing the encoding
6352 that uses the least amount of space. */
6353 if (line_info->dw_line_num != current_line)
6355 line_offset = line_info->dw_line_num - current_line;
6356 line_delta = line_offset - DWARF_LINE_BASE;
6357 current_line = line_info->dw_line_num;
6358 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6360 /* This can handle deltas from -10 to 234, using the current
6361 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6363 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6364 "line %lu", current_line);
6368 /* This can handle any delta. This takes at least 4 bytes,
6369 depending on the value being encoded. */
6370 dw2_asm_output_data (1, DW_LNS_advance_line,
6371 "advance to line %lu", current_line);
6372 dw2_asm_output_data_sleb128 (line_offset, NULL);
6373 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6378 /* We still need to start a new row, so output a copy insn. */
6379 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6383 /* Emit debug info for the address of the end of the function. */
6386 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6387 "DW_LNS_fixed_advance_pc");
6388 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
6392 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6393 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6394 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6395 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
6398 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6399 dw2_asm_output_data_uleb128 (1, NULL);
6400 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6405 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6407 register dw_separate_line_info_ref line_info
6408 = &separate_line_info_table[lt_index];
6411 /* Don't emit anything for redundant notes. */
6412 if (line_info->dw_line_num == current_line
6413 && line_info->dw_file_num == current_file
6414 && line_info->function == function)
6418 /* Emit debug info for the address of the current line. If this is
6419 a new function, or the first line of a function, then we need
6420 to handle it differently. */
6421 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6423 if (function != line_info->function)
6425 function = line_info->function;
6427 /* Set the address register to the first line in the function */
6428 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6429 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6430 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6431 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6435 /* ??? See the DW_LNS_advance_pc comment above. */
6438 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6439 "DW_LNS_fixed_advance_pc");
6440 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6444 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6445 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6446 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6447 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6450 strcpy (prev_line_label, line_label);
6452 /* Emit debug info for the source file of the current line, if
6453 different from the previous line. */
6454 if (line_info->dw_file_num != current_file)
6456 current_file = line_info->dw_file_num;
6457 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6458 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6459 file_table.table[current_file]);
6462 /* Emit debug info for the current line number, choosing the encoding
6463 that uses the least amount of space. */
6464 if (line_info->dw_line_num != current_line)
6466 line_offset = line_info->dw_line_num - current_line;
6467 line_delta = line_offset - DWARF_LINE_BASE;
6468 current_line = line_info->dw_line_num;
6469 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6470 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6471 "line %lu", current_line);
6474 dw2_asm_output_data (1, DW_LNS_advance_line,
6475 "advance to line %lu", current_line);
6476 dw2_asm_output_data_sleb128 (line_offset, NULL);
6477 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6481 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6488 /* If we're done with a function, end its sequence. */
6489 if (lt_index == separate_line_info_table_in_use
6490 || separate_line_info_table[lt_index].function != function)
6495 /* Emit debug info for the address of the end of the function. */
6496 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6499 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6500 "DW_LNS_fixed_advance_pc");
6501 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6505 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6506 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6507 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6508 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6511 /* Output the marker for the end of this sequence. */
6512 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6513 dw2_asm_output_data_uleb128 (1, NULL);
6514 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6518 /* Output the marker for the end of the line number info. */
6519 ASM_OUTPUT_LABEL (asm_out_file, l2);
6522 /* Given a pointer to a tree node for some base type, return a pointer to
6523 a DIE that describes the given type.
6525 This routine must only be called for GCC type nodes that correspond to
6526 Dwarf base (fundamental) types. */
6529 base_type_die (type)
6532 register dw_die_ref base_type_result;
6533 register const char *type_name;
6534 register enum dwarf_type encoding;
6535 register tree name = TYPE_NAME (type);
6537 if (TREE_CODE (type) == ERROR_MARK
6538 || TREE_CODE (type) == VOID_TYPE)
6543 if (TREE_CODE (name) == TYPE_DECL)
6544 name = DECL_NAME (name);
6546 type_name = IDENTIFIER_POINTER (name);
6549 type_name = "__unknown__";
6551 switch (TREE_CODE (type))
6554 /* Carefully distinguish the C character types, without messing
6555 up if the language is not C. Note that we check only for the names
6556 that contain spaces; other names might occur by coincidence in other
6558 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6559 && (type == char_type_node
6560 || ! strcmp (type_name, "signed char")
6561 || ! strcmp (type_name, "unsigned char"))))
6563 if (TREE_UNSIGNED (type))
6564 encoding = DW_ATE_unsigned;
6566 encoding = DW_ATE_signed;
6569 /* else fall through. */
6572 /* GNU Pascal/Ada CHAR type. Not used in C. */
6573 if (TREE_UNSIGNED (type))
6574 encoding = DW_ATE_unsigned_char;
6576 encoding = DW_ATE_signed_char;
6580 encoding = DW_ATE_float;
6583 /* Dwarf2 doesn't know anything about complex ints, so use
6584 a user defined type for it. */
6586 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6587 encoding = DW_ATE_complex_float;
6589 encoding = DW_ATE_lo_user;
6593 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6594 encoding = DW_ATE_boolean;
6598 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6601 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6602 if (demangle_name_func)
6603 type_name = (*demangle_name_func) (type_name);
6605 add_AT_string (base_type_result, DW_AT_name, type_name);
6606 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6607 int_size_in_bytes (type));
6608 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6610 return base_type_result;
6613 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6614 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6615 a given type is generally the same as the given type, except that if the
6616 given type is a pointer or reference type, then the root type of the given
6617 type is the root type of the "basis" type for the pointer or reference
6618 type. (This definition of the "root" type is recursive.) Also, the root
6619 type of a `const' qualified type or a `volatile' qualified type is the
6620 root type of the given type without the qualifiers. */
6626 if (TREE_CODE (type) == ERROR_MARK)
6627 return error_mark_node;
6629 switch (TREE_CODE (type))
6632 return error_mark_node;
6635 case REFERENCE_TYPE:
6636 return type_main_variant (root_type (TREE_TYPE (type)));
6639 return type_main_variant (type);
6643 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6644 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6650 switch (TREE_CODE (type))
6665 case QUAL_UNION_TYPE:
6670 case REFERENCE_TYPE:
6684 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6685 entry that chains various modifiers in front of the given type. */
6688 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6690 register int is_const_type;
6691 register int is_volatile_type;
6692 register dw_die_ref context_die;
6694 register enum tree_code code = TREE_CODE (type);
6695 register dw_die_ref mod_type_die = NULL;
6696 register dw_die_ref sub_die = NULL;
6697 register tree item_type = NULL;
6699 if (code != ERROR_MARK)
6701 type = build_type_variant (type, is_const_type, is_volatile_type);
6703 mod_type_die = lookup_type_die (type);
6705 return mod_type_die;
6707 /* Handle C typedef types. */
6708 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6709 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6711 tree dtype = TREE_TYPE (TYPE_NAME (type));
6714 /* For a named type, use the typedef. */
6715 gen_type_die (type, context_die);
6716 mod_type_die = lookup_type_die (type);
6719 else if (is_const_type < TYPE_READONLY (dtype)
6720 || is_volatile_type < TYPE_VOLATILE (dtype))
6721 /* cv-unqualified version of named type. Just use the unnamed
6722 type to which it refers. */
6724 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6725 is_const_type, is_volatile_type,
6727 /* Else cv-qualified version of named type; fall through. */
6733 else if (is_const_type)
6735 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6736 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6738 else if (is_volatile_type)
6740 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6741 sub_die = modified_type_die (type, 0, 0, context_die);
6743 else if (code == POINTER_TYPE)
6745 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6746 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6748 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6750 item_type = TREE_TYPE (type);
6752 else if (code == REFERENCE_TYPE)
6754 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6755 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6757 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6759 item_type = TREE_TYPE (type);
6761 else if (is_base_type (type))
6762 mod_type_die = base_type_die (type);
6765 gen_type_die (type, context_die);
6767 /* We have to get the type_main_variant here (and pass that to the
6768 `lookup_type_die' routine) because the ..._TYPE node we have
6769 might simply be a *copy* of some original type node (where the
6770 copy was created to help us keep track of typedef names) and
6771 that copy might have a different TYPE_UID from the original
6773 mod_type_die = lookup_type_die (type_main_variant (type));
6774 if (mod_type_die == NULL)
6779 equate_type_number_to_die (type, mod_type_die);
6781 /* We must do this after the equate_type_number_to_die call, in case
6782 this is a recursive type. This ensures that the modified_type_die
6783 recursion will terminate even if the type is recursive. Recursive
6784 types are possible in Ada. */
6785 sub_die = modified_type_die (item_type,
6786 TYPE_READONLY (item_type),
6787 TYPE_VOLATILE (item_type),
6790 if (sub_die != NULL)
6791 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6793 return mod_type_die;
6796 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6797 an enumerated type. */
6803 return TREE_CODE (type) == ENUMERAL_TYPE;
6806 /* Return the register number described by a given RTL node. */
6812 register unsigned regno = REGNO (rtl);
6814 if (regno >= FIRST_PSEUDO_REGISTER)
6816 warning ("internal regno botch: regno = %d\n", regno);
6820 regno = DBX_REGISTER_NUMBER (regno);
6824 /* Return a location descriptor that designates a machine register. */
6826 static dw_loc_descr_ref
6827 reg_loc_descriptor (rtl)
6830 register dw_loc_descr_ref loc_result = NULL;
6831 register unsigned reg = reg_number (rtl);
6834 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6836 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6841 /* Return a location descriptor that designates a constant. */
6843 static dw_loc_descr_ref
6844 int_loc_descriptor (i)
6847 enum dwarf_location_atom op;
6849 /* Pick the smallest representation of a constant, rather than just
6850 defaulting to the LEB encoding. */
6854 op = DW_OP_lit0 + i;
6857 else if (i <= 0xffff)
6859 else if (HOST_BITS_PER_WIDE_INT == 32
6869 else if (i >= -0x8000)
6871 else if (HOST_BITS_PER_WIDE_INT == 32
6872 || i >= -0x80000000)
6878 return new_loc_descr (op, i, 0);
6881 /* Return a location descriptor that designates a base+offset location. */
6883 static dw_loc_descr_ref
6884 based_loc_descr (reg, offset)
6888 register dw_loc_descr_ref loc_result;
6889 /* For the "frame base", we use the frame pointer or stack pointer
6890 registers, since the RTL for local variables is relative to one of
6892 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6893 ? HARD_FRAME_POINTER_REGNUM
6894 : STACK_POINTER_REGNUM);
6897 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
6899 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
6901 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6906 /* Return true if this RTL expression describes a base+offset calculation. */
6912 return (GET_CODE (rtl) == PLUS
6913 && ((GET_CODE (XEXP (rtl, 0)) == REG
6914 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6917 /* The following routine converts the RTL for a variable or parameter
6918 (resident in memory) into an equivalent Dwarf representation of a
6919 mechanism for getting the address of that same variable onto the top of a
6920 hypothetical "address evaluation" stack.
6922 When creating memory location descriptors, we are effectively transforming
6923 the RTL for a memory-resident object into its Dwarf postfix expression
6924 equivalent. This routine recursively descends an RTL tree, turning
6925 it into Dwarf postfix code as it goes.
6927 MODE is the mode of the memory reference, needed to handle some
6928 autoincrement addressing modes. */
6930 static dw_loc_descr_ref
6931 mem_loc_descriptor (rtl, mode)
6933 enum machine_mode mode;
6935 dw_loc_descr_ref mem_loc_result = NULL;
6936 /* Note that for a dynamically sized array, the location we will generate a
6937 description of here will be the lowest numbered location which is
6938 actually within the array. That's *not* necessarily the same as the
6939 zeroth element of the array. */
6941 #ifdef ASM_SIMPLIFY_DWARF_ADDR
6942 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
6945 switch (GET_CODE (rtl))
6950 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
6951 just fall into the SUBREG code. */
6956 /* The case of a subreg may arise when we have a local (register)
6957 variable or a formal (register) parameter which doesn't quite fill
6958 up an entire register. For now, just assume that it is
6959 legitimate to make the Dwarf info refer to the whole register which
6960 contains the given subreg. */
6961 rtl = XEXP (rtl, 0);
6966 /* Whenever a register number forms a part of the description of the
6967 method for calculating the (dynamic) address of a memory resident
6968 object, DWARF rules require the register number be referred to as
6969 a "base register". This distinction is not based in any way upon
6970 what category of register the hardware believes the given register
6971 belongs to. This is strictly DWARF terminology we're dealing with
6972 here. Note that in cases where the location of a memory-resident
6973 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6974 OP_CONST (0)) the actual DWARF location descriptor that we generate
6975 may just be OP_BASEREG (basereg). This may look deceptively like
6976 the object in question was allocated to a register (rather than in
6977 memory) so DWARF consumers need to be aware of the subtle
6978 distinction between OP_REG and OP_BASEREG. */
6979 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6983 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
6984 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6988 /* Some ports can transform a symbol ref into a label ref, because
6989 the symbol ref is too far away and has to be dumped into a constant
6993 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6994 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6995 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
6999 /* Extract the PLUS expression nested inside and fall into
7000 PLUS code bellow. */
7001 rtl = XEXP (rtl, 1);
7006 /* Turn these into a PLUS expression and fall into the PLUS code
7008 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7009 GEN_INT (GET_CODE (rtl) == PRE_INC
7010 ? GET_MODE_UNIT_SIZE (mode)
7011 : -GET_MODE_UNIT_SIZE (mode)));
7017 if (is_based_loc (rtl))
7018 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7019 INTVAL (XEXP (rtl, 1)));
7022 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7024 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7025 && INTVAL (XEXP (rtl, 1)) >= 0)
7027 add_loc_descr (&mem_loc_result,
7028 new_loc_descr (DW_OP_plus_uconst,
7029 INTVAL (XEXP (rtl, 1)), 0));
7033 add_loc_descr (&mem_loc_result,
7034 mem_loc_descriptor (XEXP (rtl, 1), mode));
7035 add_loc_descr (&mem_loc_result,
7036 new_loc_descr (DW_OP_plus, 0, 0));
7042 /* If a pseudo-reg is optimized away, it is possible for it to
7043 be replaced with a MEM containing a multiply. */
7044 add_loc_descr (&mem_loc_result,
7045 mem_loc_descriptor (XEXP (rtl, 0), mode));
7046 add_loc_descr (&mem_loc_result,
7047 mem_loc_descriptor (XEXP (rtl, 1), mode));
7048 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7052 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7059 return mem_loc_result;
7062 /* Return a descriptor that describes the concatenation of two locations.
7063 This is typically a complex variable. */
7065 static dw_loc_descr_ref
7066 concat_loc_descriptor (x0, x1)
7067 register rtx x0, x1;
7069 dw_loc_descr_ref cc_loc_result = NULL;
7071 if (!is_pseudo_reg (x0)
7072 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7073 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7074 add_loc_descr (&cc_loc_result,
7075 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7077 if (!is_pseudo_reg (x1)
7078 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7079 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7080 add_loc_descr (&cc_loc_result,
7081 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7083 return cc_loc_result;
7086 /* Output a proper Dwarf location descriptor for a variable or parameter
7087 which is either allocated in a register or in a memory location. For a
7088 register, we just generate an OP_REG and the register number. For a
7089 memory location we provide a Dwarf postfix expression describing how to
7090 generate the (dynamic) address of the object onto the address stack. */
7092 static dw_loc_descr_ref
7093 loc_descriptor (rtl)
7096 dw_loc_descr_ref loc_result = NULL;
7097 switch (GET_CODE (rtl))
7100 /* The case of a subreg may arise when we have a local (register)
7101 variable or a formal (register) parameter which doesn't quite fill
7102 up an entire register. For now, just assume that it is
7103 legitimate to make the Dwarf info refer to the whole register which
7104 contains the given subreg. */
7105 rtl = XEXP (rtl, 0);
7110 loc_result = reg_loc_descriptor (rtl);
7114 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7118 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7128 /* Similar, but generate the descriptor from trees instead of rtl.
7129 This comes up particularly with variable length arrays. */
7131 static dw_loc_descr_ref
7132 loc_descriptor_from_tree (loc, addressp)
7136 dw_loc_descr_ref ret = NULL;
7137 int indirect_size = 0;
7138 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7139 enum dwarf_location_atom op;
7141 /* ??? Most of the time we do not take proper care for sign/zero
7142 extending the values properly. Hopefully this won't be a real
7145 switch (TREE_CODE (loc))
7150 case WITH_RECORD_EXPR:
7151 /* This case involves extracting fields from an object to determine the
7152 position of other fields. We don't try to encode this here. The
7153 only user of this is Ada, which encodes the needed information using
7154 the names of types. */
7160 rtx rtl = rtl_for_decl_location (loc);
7161 enum machine_mode mode = DECL_MODE (loc);
7163 if (rtl == NULL_RTX)
7165 else if (CONSTANT_P (rtl))
7167 ret = new_loc_descr (DW_OP_addr, 0, 0);
7168 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7169 ret->dw_loc_oprnd1.v.val_addr = rtl;
7170 indirect_size = GET_MODE_SIZE (mode);
7174 if (GET_CODE (rtl) == MEM)
7176 indirect_size = GET_MODE_SIZE (mode);
7177 rtl = XEXP (rtl, 0);
7179 ret = mem_loc_descriptor (rtl, mode);
7185 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7186 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7191 case NON_LVALUE_EXPR:
7193 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7200 HOST_WIDE_INT bitsize, bitpos, bytepos;
7201 enum machine_mode mode;
7203 unsigned int alignment;
7205 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7206 &unsignedp, &volatilep, &alignment);
7207 ret = loc_descriptor_from_tree (obj, 1);
7209 if (offset != NULL_TREE)
7211 /* Variable offset. */
7212 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7213 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7218 /* We cannot address anything not on a unit boundary. */
7219 if (bitpos % BITS_PER_UNIT != 0)
7224 if (bitpos % BITS_PER_UNIT != 0
7225 || bitsize % BITS_PER_UNIT != 0)
7227 /* ??? We could handle this by loading and shifting etc.
7228 Wait until someone needs it before expending the effort. */
7232 indirect_size = bitsize / BITS_PER_UNIT;
7235 bytepos = bitpos / BITS_PER_UNIT;
7237 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7238 else if (bytepos < 0)
7240 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7241 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7247 if (host_integerp (loc, 0))
7248 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7260 case TRUNC_DIV_EXPR:
7266 case TRUNC_MOD_EXPR:
7276 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7279 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7280 && host_integerp (TREE_OPERAND (loc, 1), 0))
7282 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7283 add_loc_descr (&ret,
7284 new_loc_descr (DW_OP_plus_uconst,
7285 tree_low_cst (TREE_OPERAND (loc, 1),
7293 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7298 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7303 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7308 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7320 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7321 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7322 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7336 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7337 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7341 loc = build (COND_EXPR, TREE_TYPE (loc),
7342 build (LT_EXPR, integer_type_node,
7343 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
7344 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
7349 dw_loc_descr_ref bra_node, jump_node, tmp;
7351 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7352 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
7353 add_loc_descr (&ret, bra_node);
7355 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
7356 add_loc_descr (&ret, tmp);
7357 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
7358 add_loc_descr (&ret, jump_node);
7360 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
7361 add_loc_descr (&ret, tmp);
7362 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7363 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
7365 /* ??? Need a node to point the skip at. Use a nop. */
7366 tmp = new_loc_descr (DW_OP_nop, 0, 0);
7367 add_loc_descr (&ret, tmp);
7368 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7369 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
7377 /* If we can't fill the request for an address, die. */
7378 if (addressp && indirect_size == 0)
7381 /* If we've got an address and don't want one, dereference. */
7382 if (!addressp && indirect_size > 0)
7384 if (indirect_size > DWARF2_ADDR_SIZE)
7386 if (indirect_size == DWARF2_ADDR_SIZE)
7389 op = DW_OP_deref_size;
7390 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
7396 /* Given a value, round it up to the lowest multiple of `boundary'
7397 which is not less than the value itself. */
7399 static inline HOST_WIDE_INT
7400 ceiling (value, boundary)
7401 HOST_WIDE_INT value;
7402 unsigned int boundary;
7404 return (((value + boundary - 1) / boundary) * boundary);
7407 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7408 pointer to the declared type for the relevant field variable, or return
7409 `integer_type_node' if the given node turns out to be an
7418 if (TREE_CODE (decl) == ERROR_MARK)
7419 return integer_type_node;
7421 type = DECL_BIT_FIELD_TYPE (decl);
7422 if (type == NULL_TREE)
7423 type = TREE_TYPE (decl);
7428 /* Given a pointer to a tree node, return the alignment in bits for
7429 it, or else return BITS_PER_WORD if the node actually turns out to
7430 be an ERROR_MARK node. */
7432 static inline unsigned
7433 simple_type_align_in_bits (type)
7436 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7439 static inline unsigned
7440 simple_decl_align_in_bits (decl)
7443 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
7446 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7447 node, return the size in bits for the type if it is a constant, or else
7448 return the alignment for the type if the type's size is not constant, or
7449 else return BITS_PER_WORD if the type actually turns out to be an
7452 static inline unsigned HOST_WIDE_INT
7453 simple_type_size_in_bits (type)
7456 tree type_size_tree;
7458 if (TREE_CODE (type) == ERROR_MARK)
7459 return BITS_PER_WORD;
7460 type_size_tree = TYPE_SIZE (type);
7462 if (type_size_tree == NULL_TREE)
7464 if (! host_integerp (type_size_tree, 1))
7465 return TYPE_ALIGN (type);
7466 return tree_low_cst (type_size_tree, 1);
7469 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7470 return the byte offset of the lowest addressed byte of the "containing
7471 object" for the given FIELD_DECL, or return 0 if we are unable to
7472 determine what that offset is, either because the argument turns out to
7473 be a pointer to an ERROR_MARK node, or because the offset is actually
7474 variable. (We can't handle the latter case just yet). */
7476 static HOST_WIDE_INT
7477 field_byte_offset (decl)
7480 unsigned int type_align_in_bits;
7481 unsigned int decl_align_in_bits;
7482 unsigned HOST_WIDE_INT type_size_in_bits;
7483 HOST_WIDE_INT object_offset_in_bits;
7484 HOST_WIDE_INT object_offset_in_bytes;
7486 tree field_size_tree;
7487 HOST_WIDE_INT bitpos_int;
7488 HOST_WIDE_INT deepest_bitpos;
7489 unsigned HOST_WIDE_INT field_size_in_bits;
7491 if (TREE_CODE (decl) == ERROR_MARK)
7494 if (TREE_CODE (decl) != FIELD_DECL)
7497 type = field_type (decl);
7498 field_size_tree = DECL_SIZE (decl);
7500 /* The size could be unspecified if there was an error, or for
7501 a flexible array member. */
7502 if (! field_size_tree)
7503 field_size_tree = bitsize_zero_node;
7505 /* We cannot yet cope with fields whose positions are variable, so
7506 for now, when we see such things, we simply return 0. Someday, we may
7507 be able to handle such cases, but it will be damn difficult. */
7508 if (! host_integerp (bit_position (decl), 0))
7511 bitpos_int = int_bit_position (decl);
7513 /* If we don't know the size of the field, pretend it's a full word. */
7514 if (host_integerp (field_size_tree, 1))
7515 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7517 field_size_in_bits = BITS_PER_WORD;
7519 type_size_in_bits = simple_type_size_in_bits (type);
7520 type_align_in_bits = simple_type_align_in_bits (type);
7521 decl_align_in_bits = simple_decl_align_in_bits (decl);
7523 /* Note that the GCC front-end doesn't make any attempt to keep track of
7524 the starting bit offset (relative to the start of the containing
7525 structure type) of the hypothetical "containing object" for a bit-
7526 field. Thus, when computing the byte offset value for the start of the
7527 "containing object" of a bit-field, we must deduce this information on
7528 our own. This can be rather tricky to do in some cases. For example,
7529 handling the following structure type definition when compiling for an
7530 i386/i486 target (which only aligns long long's to 32-bit boundaries)
7533 struct S { int field1; long long field2:31; };
7535 Fortunately, there is a simple rule-of-thumb which can be
7536 used in such cases. When compiling for an i386/i486, GCC will allocate
7537 8 bytes for the structure shown above. It decides to do this based upon
7538 one simple rule for bit-field allocation. Quite simply, GCC allocates
7539 each "containing object" for each bit-field at the first (i.e. lowest
7540 addressed) legitimate alignment boundary (based upon the required
7541 minimum alignment for the declared type of the field) which it can
7542 possibly use, subject to the condition that there is still enough
7543 available space remaining in the containing object (when allocated at
7544 the selected point) to fully accommodate all of the bits of the
7545 bit-field itself. This simple rule makes it obvious why GCC allocates
7546 8 bytes for each object of the structure type shown above. When looking
7547 for a place to allocate the "containing object" for `field2', the
7548 compiler simply tries to allocate a 64-bit "containing object" at each
7549 successive 32-bit boundary (starting at zero) until it finds a place to
7550 allocate that 64- bit field such that at least 31 contiguous (and
7551 previously unallocated) bits remain within that selected 64 bit field.
7552 (As it turns out, for the example above, the compiler finds that it is
7553 OK to allocate the "containing object" 64-bit field at bit-offset zero
7554 within the structure type.) Here we attempt to work backwards from the
7555 limited set of facts we're given, and we try to deduce from those facts,
7556 where GCC must have believed that the containing object started (within
7557 the structure type). The value we deduce is then used (by the callers of
7558 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
7559 for fields (both bit-fields and, in the case of DW_AT_location, regular
7562 /* Figure out the bit-distance from the start of the structure to the
7563 "deepest" bit of the bit-field. */
7564 deepest_bitpos = bitpos_int + field_size_in_bits;
7566 /* This is the tricky part. Use some fancy footwork to deduce where the
7567 lowest addressed bit of the containing object must be. */
7568 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
7570 /* Round up to type_align by default. This works best for bitfields. */
7571 object_offset_in_bits += type_align_in_bits - 1;
7572 object_offset_in_bits /= type_align_in_bits;
7573 object_offset_in_bits *= type_align_in_bits;
7575 if (object_offset_in_bits > bitpos_int)
7577 /* Sigh, the decl must be packed. */
7578 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
7580 /* Round up to decl_align instead. */
7581 object_offset_in_bits += decl_align_in_bits - 1;
7582 object_offset_in_bits /= decl_align_in_bits;
7583 object_offset_in_bits *= decl_align_in_bits;
7586 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
7588 return object_offset_in_bytes;
7591 /* The following routines define various Dwarf attributes and any data
7592 associated with them. */
7594 /* Add a location description attribute value to a DIE.
7596 This emits location attributes suitable for whole variables and
7597 whole parameters. Note that the location attributes for struct fields are
7598 generated by the routine `data_member_location_attribute' below. */
7601 add_AT_location_description (die, attr_kind, rtl)
7603 enum dwarf_attribute attr_kind;
7606 /* Handle a special case. If we are about to output a location descriptor
7607 for a variable or parameter which has been optimized out of existence,
7608 don't do that. A variable which has been optimized out
7609 of existence will have a DECL_RTL value which denotes a pseudo-reg.
7610 Currently, in some rare cases, variables can have DECL_RTL values which
7611 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
7612 elsewhere in the compiler. We treat such cases as if the variable(s) in
7613 question had been optimized out of existence. */
7615 if (is_pseudo_reg (rtl)
7616 || (GET_CODE (rtl) == MEM
7617 && is_pseudo_reg (XEXP (rtl, 0)))
7618 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
7619 references the internal argument pointer (a pseudo) in a function
7620 where all references to the internal argument pointer were
7621 eliminated via the optimizers. */
7622 || (GET_CODE (rtl) == MEM
7623 && GET_CODE (XEXP (rtl, 0)) == PLUS
7624 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
7625 || (GET_CODE (rtl) == CONCAT
7626 && is_pseudo_reg (XEXP (rtl, 0))
7627 && is_pseudo_reg (XEXP (rtl, 1))))
7630 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
7633 /* Attach the specialized form of location attribute used for data
7634 members of struct and union types. In the special case of a
7635 FIELD_DECL node which represents a bit-field, the "offset" part
7636 of this special location descriptor must indicate the distance
7637 in bytes from the lowest-addressed byte of the containing struct
7638 or union type to the lowest-addressed byte of the "containing
7639 object" for the bit-field. (See the `field_byte_offset' function
7640 above).. For any given bit-field, the "containing object" is a
7641 hypothetical object (of some integral or enum type) within which
7642 the given bit-field lives. The type of this hypothetical
7643 "containing object" is always the same as the declared type of
7644 the individual bit-field itself (for GCC anyway... the DWARF
7645 spec doesn't actually mandate this). Note that it is the size
7646 (in bytes) of the hypothetical "containing object" which will
7647 be given in the DW_AT_byte_size attribute for this bit-field.
7648 (See the `byte_size_attribute' function below.) It is also used
7649 when calculating the value of the DW_AT_bit_offset attribute.
7650 (See the `bit_offset_attribute' function below). */
7653 add_data_member_location_attribute (die, decl)
7654 register dw_die_ref die;
7657 register unsigned long offset;
7658 register dw_loc_descr_ref loc_descr;
7659 register enum dwarf_location_atom op;
7661 if (TREE_CODE (decl) == TREE_VEC)
7662 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
7664 offset = field_byte_offset (decl);
7666 /* The DWARF2 standard says that we should assume that the structure address
7667 is already on the stack, so we can specify a structure field address
7668 by using DW_OP_plus_uconst. */
7670 #ifdef MIPS_DEBUGGING_INFO
7671 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
7672 correctly. It works only if we leave the offset on the stack. */
7675 op = DW_OP_plus_uconst;
7678 loc_descr = new_loc_descr (op, offset, 0);
7679 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
7682 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
7683 does not have a "location" either in memory or in a register. These
7684 things can arise in GNU C when a constant is passed as an actual parameter
7685 to an inlined function. They can also arise in C++ where declared
7686 constants do not necessarily get memory "homes". */
7689 add_const_value_attribute (die, rtl)
7690 register dw_die_ref die;
7693 switch (GET_CODE (rtl))
7696 /* Note that a CONST_INT rtx could represent either an integer
7697 or a floating-point constant. A CONST_INT is used whenever
7698 the constant will fit into a single word. In all such
7699 cases, the original mode of the constant value is wiped
7700 out, and the CONST_INT rtx is assigned VOIDmode. */
7702 HOST_WIDE_INT val = INTVAL (rtl);
7704 /* ??? We really should be using HOST_WIDE_INT throughout. */
7707 if ((long) val != val)
7709 add_AT_int (die, DW_AT_const_value, (long) val);
7713 if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
7715 add_AT_int (die, DW_AT_const_value, (unsigned long) val);
7721 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
7722 floating-point constant. A CONST_DOUBLE is used whenever the
7723 constant requires more than one word in order to be adequately
7724 represented. We output CONST_DOUBLEs as blocks. */
7726 register enum machine_mode mode = GET_MODE (rtl);
7728 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
7730 register unsigned length = GET_MODE_SIZE (mode) / 4;
7731 long *array = (long *) xmalloc (sizeof (long) * length);
7734 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
7738 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
7742 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
7747 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
7754 add_AT_float (die, DW_AT_const_value, length, array);
7758 /* ??? We really should be using HOST_WIDE_INT throughout. */
7759 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
7761 add_AT_long_long (die, DW_AT_const_value,
7762 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
7768 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
7774 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
7778 /* In cases where an inlined instance of an inline function is passed
7779 the address of an `auto' variable (which is local to the caller) we
7780 can get a situation where the DECL_RTL of the artificial local
7781 variable (for the inlining) which acts as a stand-in for the
7782 corresponding formal parameter (of the inline function) will look
7783 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
7784 exactly a compile-time constant expression, but it isn't the address
7785 of the (artificial) local variable either. Rather, it represents the
7786 *value* which the artificial local variable always has during its
7787 lifetime. We currently have no way to represent such quasi-constant
7788 values in Dwarf, so for now we just punt and generate nothing. */
7792 /* No other kinds of rtx should be possible here. */
7799 rtl_for_decl_location (decl)
7804 /* Here we have to decide where we are going to say the parameter "lives"
7805 (as far as the debugger is concerned). We only have a couple of
7806 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
7808 DECL_RTL normally indicates where the parameter lives during most of the
7809 activation of the function. If optimization is enabled however, this
7810 could be either NULL or else a pseudo-reg. Both of those cases indicate
7811 that the parameter doesn't really live anywhere (as far as the code
7812 generation parts of GCC are concerned) during most of the function's
7813 activation. That will happen (for example) if the parameter is never
7814 referenced within the function.
7816 We could just generate a location descriptor here for all non-NULL
7817 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
7818 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
7819 where DECL_RTL is NULL or is a pseudo-reg.
7821 Note however that we can only get away with using DECL_INCOMING_RTL as
7822 a backup substitute for DECL_RTL in certain limited cases. In cases
7823 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
7824 we can be sure that the parameter was passed using the same type as it is
7825 declared to have within the function, and that its DECL_INCOMING_RTL
7826 points us to a place where a value of that type is passed.
7828 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
7829 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
7830 because in these cases DECL_INCOMING_RTL points us to a value of some
7831 type which is *different* from the type of the parameter itself. Thus,
7832 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
7833 such cases, the debugger would end up (for example) trying to fetch a
7834 `float' from a place which actually contains the first part of a
7835 `double'. That would lead to really incorrect and confusing
7836 output at debug-time.
7838 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
7839 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
7840 are a couple of exceptions however. On little-endian machines we can
7841 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
7842 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
7843 an integral type that is smaller than TREE_TYPE (decl). These cases arise
7844 when (on a little-endian machine) a non-prototyped function has a
7845 parameter declared to be of type `short' or `char'. In such cases,
7846 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
7847 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
7848 passed `int' value. If the debugger then uses that address to fetch
7849 a `short' or a `char' (on a little-endian machine) the result will be
7850 the correct data, so we allow for such exceptional cases below.
7852 Note that our goal here is to describe the place where the given formal
7853 parameter lives during most of the function's activation (i.e. between
7854 the end of the prologue and the start of the epilogue). We'll do that
7855 as best as we can. Note however that if the given formal parameter is
7856 modified sometime during the execution of the function, then a stack
7857 backtrace (at debug-time) will show the function as having been
7858 called with the *new* value rather than the value which was
7859 originally passed in. This happens rarely enough that it is not
7860 a major problem, but it *is* a problem, and I'd like to fix it.
7862 A future version of dwarf2out.c may generate two additional
7863 attributes for any given DW_TAG_formal_parameter DIE which will
7864 describe the "passed type" and the "passed location" for the
7865 given formal parameter in addition to the attributes we now
7866 generate to indicate the "declared type" and the "active
7867 location" for each parameter. This additional set of attributes
7868 could be used by debuggers for stack backtraces. Separately, note
7869 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
7870 NULL also. This happens (for example) for inlined-instances of
7871 inline function formal parameters which are never referenced.
7872 This really shouldn't be happening. All PARM_DECL nodes should
7873 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
7874 doesn't currently generate these values for inlined instances of
7875 inline function parameters, so when we see such cases, we are
7876 just out-of-luck for the time being (until integrate.c
7879 /* Use DECL_RTL as the "location" unless we find something better. */
7880 rtl = DECL_RTL_IF_SET (decl);
7882 if (TREE_CODE (decl) == PARM_DECL)
7884 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
7886 tree declared_type = type_main_variant (TREE_TYPE (decl));
7887 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
7889 /* This decl represents a formal parameter which was optimized out.
7890 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
7891 all* cases where (rtl == NULL_RTX) just below. */
7892 if (declared_type == passed_type)
7893 rtl = DECL_INCOMING_RTL (decl);
7894 else if (! BYTES_BIG_ENDIAN
7895 && TREE_CODE (declared_type) == INTEGER_TYPE
7896 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
7897 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
7898 rtl = DECL_INCOMING_RTL (decl);
7901 /* If the parm was passed in registers, but lives on the stack, then
7902 make a big endian correction if the mode of the type of the
7903 parameter is not the same as the mode of the rtl. */
7904 /* ??? This is the same series of checks that are made in dbxout.c before
7905 we reach the big endian correction code there. It isn't clear if all
7906 of these checks are necessary here, but keeping them all is the safe
7908 else if (GET_CODE (rtl) == MEM
7909 && XEXP (rtl, 0) != const0_rtx
7910 && ! CONSTANT_P (XEXP (rtl, 0))
7911 /* Not passed in memory. */
7912 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
7913 /* Not passed by invisible reference. */
7914 && (GET_CODE (XEXP (rtl, 0)) != REG
7915 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
7916 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
7917 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
7918 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
7921 /* Big endian correction check. */
7923 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
7924 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
7927 int offset = (UNITS_PER_WORD
7928 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
7929 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
7930 plus_constant (XEXP (rtl, 0), offset));
7934 if (rtl != NULL_RTX)
7936 rtl = eliminate_regs (rtl, 0, NULL_RTX);
7937 #ifdef LEAF_REG_REMAP
7938 if (current_function_uses_only_leaf_regs)
7939 leaf_renumber_regs_insn (rtl);
7946 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
7947 data attribute for a variable or a parameter. We generate the
7948 DW_AT_const_value attribute only in those cases where the given variable
7949 or parameter does not have a true "location" either in memory or in a
7950 register. This can happen (for example) when a constant is passed as an
7951 actual argument in a call to an inline function. (It's possible that
7952 these things can crop up in other ways also.) Note that one type of
7953 constant value which can be passed into an inlined function is a constant
7954 pointer. This can happen for example if an actual argument in an inlined
7955 function call evaluates to a compile-time constant address. */
7958 add_location_or_const_value_attribute (die, decl)
7959 register dw_die_ref die;
7964 if (TREE_CODE (decl) == ERROR_MARK)
7967 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
7970 rtl = rtl_for_decl_location (decl);
7971 if (rtl == NULL_RTX)
7974 switch (GET_CODE (rtl))
7977 /* The address of a variable that was optimized away; don't emit
7988 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7989 add_const_value_attribute (die, rtl);
7996 add_AT_location_description (die, DW_AT_location, rtl);
8004 /* If we don't have a copy of this variable in memory for some reason (such
8005 as a C++ member constant that doesn't have an out-of-line definition),
8006 we should tell the debugger about the constant value. */
8009 tree_add_const_value_attribute (var_die, decl)
8013 tree init = DECL_INITIAL (decl);
8014 tree type = TREE_TYPE (decl);
8016 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8017 && initializer_constant_valid_p (init, type) == null_pointer_node)
8022 switch (TREE_CODE (type))
8025 if (host_integerp (init, 0))
8026 add_AT_unsigned (var_die, DW_AT_const_value,
8027 TREE_INT_CST_LOW (init));
8029 add_AT_long_long (var_die, DW_AT_const_value,
8030 TREE_INT_CST_HIGH (init),
8031 TREE_INT_CST_LOW (init));
8038 /* Generate an DW_AT_name attribute given some string value to be included as
8039 the value of the attribute. */
8042 add_name_attribute (die, name_string)
8043 register dw_die_ref die;
8044 register const char *name_string;
8046 if (name_string != NULL && *name_string != 0)
8048 if (demangle_name_func)
8049 name_string = (*demangle_name_func) (name_string);
8051 add_AT_string (die, DW_AT_name, name_string);
8055 /* Given a tree node describing an array bound (either lower or upper) output
8056 a representation for that bound. */
8059 add_bound_info (subrange_die, bound_attr, bound)
8060 register dw_die_ref subrange_die;
8061 register enum dwarf_attribute bound_attr;
8062 register tree bound;
8064 /* If this is an Ada unconstrained array type, then don't emit any debug
8065 info because the array bounds are unknown. They are parameterized when
8066 the type is instantiated. */
8067 if (contains_placeholder_p (bound))
8070 switch (TREE_CODE (bound))
8075 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8077 if (! host_integerp (bound, 0)
8078 || (bound_attr == DW_AT_lower_bound
8079 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8080 || (is_fortran () && integer_onep (bound)))))
8081 /* use the default */
8084 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8089 case NON_LVALUE_EXPR:
8090 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8094 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8095 access the upper bound values may be bogus. If they refer to a
8096 register, they may only describe how to get at these values at the
8097 points in the generated code right after they have just been
8098 computed. Worse yet, in the typical case, the upper bound values
8099 will not even *be* computed in the optimized code (though the
8100 number of elements will), so these SAVE_EXPRs are entirely
8101 bogus. In order to compensate for this fact, we check here to see
8102 if optimization is enabled, and if so, we don't add an attribute
8103 for the (unknown and unknowable) upper bound. This should not
8104 cause too much trouble for existing (stupid?) debuggers because
8105 they have to deal with empty upper bounds location descriptions
8106 anyway in order to be able to deal with incomplete array types.
8107 Of course an intelligent debugger (GDB?) should be able to
8108 comprehend that a missing upper bound specification in a array
8109 type used for a storage class `auto' local array variable
8110 indicates that the upper bound is both unknown (at compile- time)
8111 and unknowable (at run-time) due to optimization.
8113 We assume that a MEM rtx is safe because gcc wouldn't put the
8114 value there unless it was going to be used repeatedly in the
8115 function, i.e. for cleanups. */
8116 if (SAVE_EXPR_RTL (bound)
8117 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8119 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8120 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8121 register rtx loc = SAVE_EXPR_RTL (bound);
8123 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8124 it references an outer function's frame. */
8126 if (GET_CODE (loc) == MEM)
8128 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8130 if (XEXP (loc, 0) != new_addr)
8131 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8134 add_AT_flag (decl_die, DW_AT_artificial, 1);
8135 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8136 add_AT_location_description (decl_die, DW_AT_location, loc);
8137 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8140 /* Else leave out the attribute. */
8146 dw_die_ref decl_die = lookup_decl_die (bound);
8148 /* ??? Can this happen, or should the variable have been bound
8149 first? Probably it can, since I imagine that we try to create
8150 the types of parameters in the order in which they exist in
8151 the list, and won't have created a forward reference to a
8153 if (decl_die != NULL)
8154 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8160 /* Otherwise try to create a stack operation procedure to
8161 evaluate the value of the array bound. */
8163 dw_die_ref ctx, decl_die;
8164 dw_loc_descr_ref loc;
8166 loc = loc_descriptor_from_tree (bound, 0);
8170 ctx = lookup_decl_die (current_function_decl);
8172 decl_die = new_die (DW_TAG_variable, ctx);
8173 add_AT_flag (decl_die, DW_AT_artificial, 1);
8174 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8175 add_AT_loc (decl_die, DW_AT_location, loc);
8177 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8183 /* Note that the block of subscript information for an array type also
8184 includes information about the element type of type given array type. */
8187 add_subscript_info (type_die, type)
8188 register dw_die_ref type_die;
8191 #ifndef MIPS_DEBUGGING_INFO
8192 register unsigned dimension_number;
8194 register tree lower, upper;
8195 register dw_die_ref subrange_die;
8197 /* The GNU compilers represent multidimensional array types as sequences of
8198 one dimensional array types whose element types are themselves array
8199 types. Here we squish that down, so that each multidimensional array
8200 type gets only one array_type DIE in the Dwarf debugging info. The draft
8201 Dwarf specification say that we are allowed to do this kind of
8202 compression in C (because there is no difference between an array or
8203 arrays and a multidimensional array in C) but for other source languages
8204 (e.g. Ada) we probably shouldn't do this. */
8206 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8207 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8208 We work around this by disabling this feature. See also
8209 gen_array_type_die. */
8210 #ifndef MIPS_DEBUGGING_INFO
8211 for (dimension_number = 0;
8212 TREE_CODE (type) == ARRAY_TYPE;
8213 type = TREE_TYPE (type), dimension_number++)
8216 register tree domain = TYPE_DOMAIN (type);
8218 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8219 and (in GNU C only) variable bounds. Handle all three forms
8221 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8224 /* We have an array type with specified bounds. */
8225 lower = TYPE_MIN_VALUE (domain);
8226 upper = TYPE_MAX_VALUE (domain);
8228 /* define the index type. */
8229 if (TREE_TYPE (domain))
8231 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8232 TREE_TYPE field. We can't emit debug info for this
8233 because it is an unnamed integral type. */
8234 if (TREE_CODE (domain) == INTEGER_TYPE
8235 && TYPE_NAME (domain) == NULL_TREE
8236 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8237 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8240 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8244 /* ??? If upper is NULL, the array has unspecified length,
8245 but it does have a lower bound. This happens with Fortran
8247 Since the debugger is definitely going to need to know N
8248 to produce useful results, go ahead and output the lower
8249 bound solo, and hope the debugger can cope. */
8251 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8253 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8256 /* We have an array type with an unspecified length. The DWARF-2
8257 spec does not say how to handle this; let's just leave out the
8261 #ifndef MIPS_DEBUGGING_INFO
8267 add_byte_size_attribute (die, tree_node)
8269 register tree tree_node;
8271 register unsigned size;
8273 switch (TREE_CODE (tree_node))
8281 case QUAL_UNION_TYPE:
8282 size = int_size_in_bytes (tree_node);
8285 /* For a data member of a struct or union, the DW_AT_byte_size is
8286 generally given as the number of bytes normally allocated for an
8287 object of the *declared* type of the member itself. This is true
8288 even for bit-fields. */
8289 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8295 /* Note that `size' might be -1 when we get to this point. If it is, that
8296 indicates that the byte size of the entity in question is variable. We
8297 have no good way of expressing this fact in Dwarf at the present time,
8298 so just let the -1 pass on through. */
8300 add_AT_unsigned (die, DW_AT_byte_size, size);
8303 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8304 which specifies the distance in bits from the highest order bit of the
8305 "containing object" for the bit-field to the highest order bit of the
8308 For any given bit-field, the "containing object" is a hypothetical
8309 object (of some integral or enum type) within which the given bit-field
8310 lives. The type of this hypothetical "containing object" is always the
8311 same as the declared type of the individual bit-field itself. The
8312 determination of the exact location of the "containing object" for a
8313 bit-field is rather complicated. It's handled by the
8314 `field_byte_offset' function (above).
8316 Note that it is the size (in bytes) of the hypothetical "containing object"
8317 which will be given in the DW_AT_byte_size attribute for this bit-field.
8318 (See `byte_size_attribute' above). */
8321 add_bit_offset_attribute (die, decl)
8322 register dw_die_ref die;
8325 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8326 tree type = DECL_BIT_FIELD_TYPE (decl);
8327 HOST_WIDE_INT bitpos_int;
8328 HOST_WIDE_INT highest_order_object_bit_offset;
8329 HOST_WIDE_INT highest_order_field_bit_offset;
8330 HOST_WIDE_INT unsigned bit_offset;
8332 /* Must be a field and a bit field. */
8334 || TREE_CODE (decl) != FIELD_DECL)
8337 /* We can't yet handle bit-fields whose offsets are variable, so if we
8338 encounter such things, just return without generating any attribute
8339 whatsoever. Likewise for variable or too large size. */
8340 if (! host_integerp (bit_position (decl), 0)
8341 || ! host_integerp (DECL_SIZE (decl), 1))
8344 bitpos_int = int_bit_position (decl);
8346 /* Note that the bit offset is always the distance (in bits) from the
8347 highest-order bit of the "containing object" to the highest-order bit of
8348 the bit-field itself. Since the "high-order end" of any object or field
8349 is different on big-endian and little-endian machines, the computation
8350 below must take account of these differences. */
8351 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8352 highest_order_field_bit_offset = bitpos_int;
8354 if (! BYTES_BIG_ENDIAN)
8356 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8357 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8361 = (! BYTES_BIG_ENDIAN
8362 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8363 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8365 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8368 /* For a FIELD_DECL node which represents a bit field, output an attribute
8369 which specifies the length in bits of the given field. */
8372 add_bit_size_attribute (die, decl)
8373 register dw_die_ref die;
8376 /* Must be a field and a bit field. */
8377 if (TREE_CODE (decl) != FIELD_DECL
8378 || ! DECL_BIT_FIELD_TYPE (decl))
8381 if (host_integerp (DECL_SIZE (decl), 1))
8382 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8385 /* If the compiled language is ANSI C, then add a 'prototyped'
8386 attribute, if arg types are given for the parameters of a function. */
8389 add_prototyped_attribute (die, func_type)
8390 register dw_die_ref die;
8391 register tree func_type;
8393 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8394 && TYPE_ARG_TYPES (func_type) != NULL)
8395 add_AT_flag (die, DW_AT_prototyped, 1);
8398 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8399 by looking in either the type declaration or object declaration
8403 add_abstract_origin_attribute (die, origin)
8404 register dw_die_ref die;
8405 register tree origin;
8407 dw_die_ref origin_die = NULL;
8409 if (TREE_CODE (origin) != FUNCTION_DECL)
8411 /* We may have gotten separated from the block for the inlined
8412 function, if we're in an exception handler or some such; make
8413 sure that the abstract function has been written out.
8415 Doing this for nested functions is wrong, however; functions are
8416 distinct units, and our context might not even be inline. */
8419 fn = TYPE_STUB_DECL (fn);
8420 fn = decl_function_context (fn);
8422 dwarf2out_abstract_function (fn);
8425 if (DECL_P (origin))
8426 origin_die = lookup_decl_die (origin);
8427 else if (TYPE_P (origin))
8428 origin_die = lookup_type_die (origin);
8430 if (origin_die == NULL)
8433 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8436 /* We do not currently support the pure_virtual attribute. */
8439 add_pure_or_virtual_attribute (die, func_decl)
8440 register dw_die_ref die;
8441 register tree func_decl;
8443 if (DECL_VINDEX (func_decl))
8445 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8447 if (host_integerp (DECL_VINDEX (func_decl), 0))
8448 add_AT_loc (die, DW_AT_vtable_elem_location,
8449 new_loc_descr (DW_OP_constu,
8450 tree_low_cst (DECL_VINDEX (func_decl), 0),
8453 /* GNU extension: Record what type this method came from originally. */
8454 if (debug_info_level > DINFO_LEVEL_TERSE)
8455 add_AT_die_ref (die, DW_AT_containing_type,
8456 lookup_type_die (DECL_CONTEXT (func_decl)));
8460 /* Add source coordinate attributes for the given decl. */
8463 add_src_coords_attributes (die, decl)
8464 register dw_die_ref die;
8467 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
8469 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8470 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8473 /* Add an DW_AT_name attribute and source coordinate attribute for the
8474 given decl, but only if it actually has a name. */
8477 add_name_and_src_coords_attributes (die, decl)
8478 register dw_die_ref die;
8481 register tree decl_name;
8483 decl_name = DECL_NAME (decl);
8484 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8486 add_name_attribute (die, dwarf2_name (decl, 0));
8487 if (! DECL_ARTIFICIAL (decl))
8488 add_src_coords_attributes (die, decl);
8490 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8491 && TREE_PUBLIC (decl)
8492 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
8493 && !DECL_ABSTRACT (decl))
8494 add_AT_string (die, DW_AT_MIPS_linkage_name,
8495 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8499 /* Push a new declaration scope. */
8502 push_decl_scope (scope)
8505 /* Make room in the decl_scope_table, if necessary. */
8506 if (decl_scope_table_allocated == decl_scope_depth)
8508 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
8510 = (tree *) xrealloc (decl_scope_table,
8511 decl_scope_table_allocated * sizeof (tree));
8514 decl_scope_table[decl_scope_depth] = scope;
8518 /* Pop a declaration scope. */
8522 if (decl_scope_depth <= 0)
8527 /* Return the DIE for the scope that immediately contains this type.
8528 Non-named types get global scope. Named types nested in other
8529 types get their containing scope if it's open, or global scope
8530 otherwise. All other types (i.e. function-local named types) get
8531 the current active scope. */
8534 scope_die_for (t, context_die)
8536 register dw_die_ref context_die;
8538 register dw_die_ref scope_die = NULL;
8539 register tree containing_scope;
8542 /* Non-types always go in the current scope. */
8546 containing_scope = TYPE_CONTEXT (t);
8548 /* Ignore namespaces for the moment. */
8549 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
8550 containing_scope = NULL_TREE;
8552 /* Ignore function type "scopes" from the C frontend. They mean that
8553 a tagged type is local to a parmlist of a function declarator, but
8554 that isn't useful to DWARF. */
8555 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
8556 containing_scope = NULL_TREE;
8558 if (containing_scope == NULL_TREE)
8559 scope_die = comp_unit_die;
8560 else if (TYPE_P (containing_scope))
8562 /* For types, we can just look up the appropriate DIE. But
8563 first we check to see if we're in the middle of emitting it
8564 so we know where the new DIE should go. */
8566 for (i = decl_scope_depth - 1; i >= 0; --i)
8567 if (decl_scope_table[i] == containing_scope)
8572 if (debug_info_level > DINFO_LEVEL_TERSE
8573 && !TREE_ASM_WRITTEN (containing_scope))
8576 /* If none of the current dies are suitable, we get file scope. */
8577 scope_die = comp_unit_die;
8580 scope_die = lookup_type_die (containing_scope);
8583 scope_die = context_die;
8588 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
8590 static inline int local_scope_p PARAMS ((dw_die_ref));
8592 local_scope_p (context_die)
8593 dw_die_ref context_die;
8595 for (; context_die; context_die = context_die->die_parent)
8596 if (context_die->die_tag == DW_TAG_inlined_subroutine
8597 || context_die->die_tag == DW_TAG_subprogram)
8602 /* Returns nonzero iff CONTEXT_DIE is a class. */
8604 static inline int class_scope_p PARAMS ((dw_die_ref));
8606 class_scope_p (context_die)
8607 dw_die_ref context_die;
8610 && (context_die->die_tag == DW_TAG_structure_type
8611 || context_die->die_tag == DW_TAG_union_type));
8614 /* Many forms of DIEs require a "type description" attribute. This
8615 routine locates the proper "type descriptor" die for the type given
8616 by 'type', and adds an DW_AT_type attribute below the given die. */
8619 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
8620 register dw_die_ref object_die;
8622 register int decl_const;
8623 register int decl_volatile;
8624 register dw_die_ref context_die;
8626 register enum tree_code code = TREE_CODE (type);
8627 register dw_die_ref type_die = NULL;
8629 /* ??? If this type is an unnamed subrange type of an integral or
8630 floating-point type, use the inner type. This is because we have no
8631 support for unnamed types in base_type_die. This can happen if this is
8632 an Ada subrange type. Correct solution is emit a subrange type die. */
8633 if ((code == INTEGER_TYPE || code == REAL_TYPE)
8634 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
8635 type = TREE_TYPE (type), code = TREE_CODE (type);
8637 if (code == ERROR_MARK)
8640 /* Handle a special case. For functions whose return type is void, we
8641 generate *no* type attribute. (Note that no object may have type
8642 `void', so this only applies to function return types). */
8643 if (code == VOID_TYPE)
8646 type_die = modified_type_die (type,
8647 decl_const || TYPE_READONLY (type),
8648 decl_volatile || TYPE_VOLATILE (type),
8650 if (type_die != NULL)
8651 add_AT_die_ref (object_die, DW_AT_type, type_die);
8654 /* Given a tree pointer to a struct, class, union, or enum type node, return
8655 a pointer to the (string) tag name for the given type, or zero if the type
8656 was declared without a tag. */
8662 register const char *name = 0;
8664 if (TYPE_NAME (type) != 0)
8666 register tree t = 0;
8668 /* Find the IDENTIFIER_NODE for the type name. */
8669 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
8670 t = TYPE_NAME (type);
8672 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
8673 a TYPE_DECL node, regardless of whether or not a `typedef' was
8675 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8676 && ! DECL_IGNORED_P (TYPE_NAME (type)))
8677 t = DECL_NAME (TYPE_NAME (type));
8679 /* Now get the name as a string, or invent one. */
8681 name = IDENTIFIER_POINTER (t);
8684 return (name == 0 || *name == '\0') ? 0 : name;
8687 /* Return the type associated with a data member, make a special check
8688 for bit field types. */
8691 member_declared_type (member)
8692 register tree member;
8694 return (DECL_BIT_FIELD_TYPE (member)
8695 ? DECL_BIT_FIELD_TYPE (member)
8696 : TREE_TYPE (member));
8699 /* Get the decl's label, as described by its RTL. This may be different
8700 from the DECL_NAME name used in the source file. */
8704 decl_start_label (decl)
8709 x = DECL_RTL (decl);
8710 if (GET_CODE (x) != MEM)
8714 if (GET_CODE (x) != SYMBOL_REF)
8717 fnname = XSTR (x, 0);
8722 /* These routines generate the internal representation of the DIE's for
8723 the compilation unit. Debugging information is collected by walking
8724 the declaration trees passed in from dwarf2out_decl(). */
8727 gen_array_type_die (type, context_die)
8729 register dw_die_ref context_die;
8731 register dw_die_ref scope_die = scope_die_for (type, context_die);
8732 register dw_die_ref array_die;
8733 register tree element_type;
8735 /* ??? The SGI dwarf reader fails for array of array of enum types unless
8736 the inner array type comes before the outer array type. Thus we must
8737 call gen_type_die before we call new_die. See below also. */
8738 #ifdef MIPS_DEBUGGING_INFO
8739 gen_type_die (TREE_TYPE (type), context_die);
8742 array_die = new_die (DW_TAG_array_type, scope_die);
8745 /* We default the array ordering. SDB will probably do
8746 the right things even if DW_AT_ordering is not present. It's not even
8747 an issue until we start to get into multidimensional arrays anyway. If
8748 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
8749 then we'll have to put the DW_AT_ordering attribute back in. (But if
8750 and when we find out that we need to put these in, we will only do so
8751 for multidimensional arrays. */
8752 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
8755 #ifdef MIPS_DEBUGGING_INFO
8756 /* The SGI compilers handle arrays of unknown bound by setting
8757 AT_declaration and not emitting any subrange DIEs. */
8758 if (! TYPE_DOMAIN (type))
8759 add_AT_unsigned (array_die, DW_AT_declaration, 1);
8762 add_subscript_info (array_die, type);
8764 add_name_attribute (array_die, type_tag (type));
8765 equate_type_number_to_die (type, array_die);
8767 /* Add representation of the type of the elements of this array type. */
8768 element_type = TREE_TYPE (type);
8770 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8771 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8772 We work around this by disabling this feature. See also
8773 add_subscript_info. */
8774 #ifndef MIPS_DEBUGGING_INFO
8775 while (TREE_CODE (element_type) == ARRAY_TYPE)
8776 element_type = TREE_TYPE (element_type);
8778 gen_type_die (element_type, context_die);
8781 add_type_attribute (array_die, element_type, 0, 0, context_die);
8785 gen_set_type_die (type, context_die)
8787 register dw_die_ref context_die;
8789 register dw_die_ref type_die
8790 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
8792 equate_type_number_to_die (type, type_die);
8793 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
8798 gen_entry_point_die (decl, context_die)
8800 register dw_die_ref context_die;
8802 register tree origin = decl_ultimate_origin (decl);
8803 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
8805 add_abstract_origin_attribute (decl_die, origin);
8808 add_name_and_src_coords_attributes (decl_die, decl);
8809 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
8813 if (DECL_ABSTRACT (decl))
8814 equate_decl_number_to_die (decl, decl_die);
8816 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
8820 /* Remember a type in the incomplete_types_list. */
8823 add_incomplete_type (type)
8826 if (incomplete_types == incomplete_types_allocated)
8828 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
8829 incomplete_types_list
8830 = (tree *) xrealloc (incomplete_types_list,
8831 sizeof (tree) * incomplete_types_allocated);
8834 incomplete_types_list[incomplete_types++] = type;
8837 /* Walk through the list of incomplete types again, trying once more to
8838 emit full debugging info for them. */
8841 retry_incomplete_types ()
8845 while (incomplete_types)
8848 type = incomplete_types_list[incomplete_types];
8849 gen_type_die (type, comp_unit_die);
8853 /* Generate a DIE to represent an inlined instance of an enumeration type. */
8856 gen_inlined_enumeration_type_die (type, context_die)
8858 register dw_die_ref context_die;
8860 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
8862 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8863 be incomplete and such types are not marked. */
8864 add_abstract_origin_attribute (type_die, type);
8867 /* Generate a DIE to represent an inlined instance of a structure type. */
8870 gen_inlined_structure_type_die (type, context_die)
8872 register dw_die_ref context_die;
8874 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
8876 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8877 be incomplete and such types are not marked. */
8878 add_abstract_origin_attribute (type_die, type);
8881 /* Generate a DIE to represent an inlined instance of a union type. */
8884 gen_inlined_union_type_die (type, context_die)
8886 register dw_die_ref context_die;
8888 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
8890 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8891 be incomplete and such types are not marked. */
8892 add_abstract_origin_attribute (type_die, type);
8895 /* Generate a DIE to represent an enumeration type. Note that these DIEs
8896 include all of the information about the enumeration values also. Each
8897 enumerated type name/value is listed as a child of the enumerated type
8901 gen_enumeration_type_die (type, context_die)
8903 register dw_die_ref context_die;
8905 register dw_die_ref type_die = lookup_type_die (type);
8907 if (type_die == NULL)
8909 type_die = new_die (DW_TAG_enumeration_type,
8910 scope_die_for (type, context_die));
8911 equate_type_number_to_die (type, type_die);
8912 add_name_attribute (type_die, type_tag (type));
8914 else if (! TYPE_SIZE (type))
8917 remove_AT (type_die, DW_AT_declaration);
8919 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
8920 given enum type is incomplete, do not generate the DW_AT_byte_size
8921 attribute or the DW_AT_element_list attribute. */
8922 if (TYPE_SIZE (type))
8926 TREE_ASM_WRITTEN (type) = 1;
8927 add_byte_size_attribute (type_die, type);
8928 if (TYPE_STUB_DECL (type) != NULL_TREE)
8929 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8931 /* If the first reference to this type was as the return type of an
8932 inline function, then it may not have a parent. Fix this now. */
8933 if (type_die->die_parent == NULL)
8934 add_child_die (scope_die_for (type, context_die), type_die);
8936 for (link = TYPE_FIELDS (type);
8937 link != NULL; link = TREE_CHAIN (link))
8939 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
8941 add_name_attribute (enum_die,
8942 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
8944 if (host_integerp (TREE_VALUE (link), 0))
8946 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
8947 add_AT_int (enum_die, DW_AT_const_value,
8948 tree_low_cst (TREE_VALUE (link), 0));
8950 add_AT_unsigned (enum_die, DW_AT_const_value,
8951 tree_low_cst (TREE_VALUE (link), 0));
8956 add_AT_flag (type_die, DW_AT_declaration, 1);
8959 /* Generate a DIE to represent either a real live formal parameter decl or to
8960 represent just the type of some formal parameter position in some function
8963 Note that this routine is a bit unusual because its argument may be a
8964 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
8965 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
8966 node. If it's the former then this function is being called to output a
8967 DIE to represent a formal parameter object (or some inlining thereof). If
8968 it's the latter, then this function is only being called to output a
8969 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
8970 argument type of some subprogram type. */
8973 gen_formal_parameter_die (node, context_die)
8975 register dw_die_ref context_die;
8977 register dw_die_ref parm_die
8978 = new_die (DW_TAG_formal_parameter, context_die);
8979 register tree origin;
8981 switch (TREE_CODE_CLASS (TREE_CODE (node)))
8984 origin = decl_ultimate_origin (node);
8986 add_abstract_origin_attribute (parm_die, origin);
8989 add_name_and_src_coords_attributes (parm_die, node);
8990 add_type_attribute (parm_die, TREE_TYPE (node),
8991 TREE_READONLY (node),
8992 TREE_THIS_VOLATILE (node),
8994 if (DECL_ARTIFICIAL (node))
8995 add_AT_flag (parm_die, DW_AT_artificial, 1);
8998 equate_decl_number_to_die (node, parm_die);
8999 if (! DECL_ABSTRACT (node))
9000 add_location_or_const_value_attribute (parm_die, node);
9005 /* We were called with some kind of a ..._TYPE node. */
9006 add_type_attribute (parm_die, node, 0, 0, context_die);
9016 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9017 at the end of an (ANSI prototyped) formal parameters list. */
9020 gen_unspecified_parameters_die (decl_or_type, context_die)
9021 register tree decl_or_type ATTRIBUTE_UNUSED;
9022 register dw_die_ref context_die;
9024 new_die (DW_TAG_unspecified_parameters, context_die);
9027 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9028 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9029 parameters as specified in some function type specification (except for
9030 those which appear as part of a function *definition*). */
9033 gen_formal_types_die (function_or_method_type, context_die)
9034 register tree function_or_method_type;
9035 register dw_die_ref context_die;
9038 register tree formal_type = NULL;
9039 register tree first_parm_type;
9042 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9044 arg = DECL_ARGUMENTS (function_or_method_type);
9045 function_or_method_type = TREE_TYPE (function_or_method_type);
9050 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9052 /* Make our first pass over the list of formal parameter types and output a
9053 DW_TAG_formal_parameter DIE for each one. */
9054 for (link = first_parm_type; link; )
9056 register dw_die_ref parm_die;
9058 formal_type = TREE_VALUE (link);
9059 if (formal_type == void_type_node)
9062 /* Output a (nameless) DIE to represent the formal parameter itself. */
9063 parm_die = gen_formal_parameter_die (formal_type, context_die);
9064 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9065 && link == first_parm_type)
9066 || (arg && DECL_ARTIFICIAL (arg)))
9067 add_AT_flag (parm_die, DW_AT_artificial, 1);
9069 link = TREE_CHAIN (link);
9071 arg = TREE_CHAIN (arg);
9074 /* If this function type has an ellipsis, add a
9075 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9076 if (formal_type != void_type_node)
9077 gen_unspecified_parameters_die (function_or_method_type, context_die);
9079 /* Make our second (and final) pass over the list of formal parameter types
9080 and output DIEs to represent those types (as necessary). */
9081 for (link = TYPE_ARG_TYPES (function_or_method_type);
9083 link = TREE_CHAIN (link))
9085 formal_type = TREE_VALUE (link);
9086 if (formal_type == void_type_node)
9089 gen_type_die (formal_type, context_die);
9093 /* We want to generate the DIE for TYPE so that we can generate the
9094 die for MEMBER, which has been defined; we will need to refer back
9095 to the member declaration nested within TYPE. If we're trying to
9096 generate minimal debug info for TYPE, processing TYPE won't do the
9097 trick; we need to attach the member declaration by hand. */
9100 gen_type_die_for_member (type, member, context_die)
9102 dw_die_ref context_die;
9104 gen_type_die (type, context_die);
9106 /* If we're trying to avoid duplicate debug info, we may not have
9107 emitted the member decl for this function. Emit it now. */
9108 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9109 && ! lookup_decl_die (member))
9111 if (decl_ultimate_origin (member))
9114 push_decl_scope (type);
9115 if (TREE_CODE (member) == FUNCTION_DECL)
9116 gen_subprogram_die (member, lookup_type_die (type));
9118 gen_variable_die (member, lookup_type_die (type));
9123 /* Generate the DWARF2 info for the "abstract" instance
9124 of a function which we may later generate inlined and/or
9125 out-of-line instances of. */
9128 dwarf2out_abstract_function (decl)
9131 register dw_die_ref old_die;
9134 int was_abstract = DECL_ABSTRACT (decl);
9136 /* Make sure we have the actual abstract inline, not a clone. */
9137 decl = DECL_ORIGIN (decl);
9139 old_die = lookup_decl_die (decl);
9140 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9141 /* We've already generated the abstract instance. */
9144 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9145 we don't get confused by DECL_ABSTRACT. */
9146 context = decl_class_context (decl);
9148 gen_type_die_for_member
9149 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9151 /* Pretend we've just finished compiling this function. */
9152 save_fn = current_function_decl;
9153 current_function_decl = decl;
9155 set_decl_abstract_flags (decl, 1);
9156 dwarf2out_decl (decl);
9158 set_decl_abstract_flags (decl, 0);
9160 current_function_decl = save_fn;
9163 /* Generate a DIE to represent a declared function (either file-scope or
9167 gen_subprogram_die (decl, context_die)
9169 register dw_die_ref context_die;
9171 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9172 register tree origin = decl_ultimate_origin (decl);
9173 register dw_die_ref subr_die;
9174 register rtx fp_reg;
9175 register tree fn_arg_types;
9176 register tree outer_scope;
9177 register dw_die_ref old_die = lookup_decl_die (decl);
9178 register int declaration = (current_function_decl != decl
9179 || class_scope_p (context_die));
9181 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9182 be true, if we started to generate the abstract instance of an inline,
9183 decided to output its containing class, and proceeded to emit the
9184 declaration of the inline from the member list for the class. In that
9185 case, `declaration' takes priority; we'll get back to the abstract
9186 instance when we're done with the class. */
9188 /* The class-scope declaration DIE must be the primary DIE. */
9189 if (origin && declaration && class_scope_p (context_die))
9198 if (declaration && ! local_scope_p (context_die))
9201 /* Fixup die_parent for the abstract instance of a nested
9203 if (old_die && old_die->die_parent == NULL)
9204 add_child_die (context_die, old_die);
9206 subr_die = new_die (DW_TAG_subprogram, context_die);
9207 add_abstract_origin_attribute (subr_die, origin);
9211 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9213 if (!get_AT_flag (old_die, DW_AT_declaration)
9214 /* We can have a normal definition following an inline one in the
9215 case of redefinition of GNU C extern inlines.
9216 It seems reasonable to use AT_specification in this case. */
9217 && !get_AT_unsigned (old_die, DW_AT_inline))
9219 /* ??? This can happen if there is a bug in the program, for
9220 instance, if it has duplicate function definitions. Ideally,
9221 we should detect this case and ignore it. For now, if we have
9222 already reported an error, any error at all, then assume that
9223 we got here because of a input error, not a dwarf2 bug. */
9229 /* If the definition comes from the same place as the declaration,
9230 maybe use the old DIE. We always want the DIE for this function
9231 that has the *_pc attributes to be under comp_unit_die so the
9232 debugger can find it. We also need to do this for abstract
9233 instances of inlines, since the spec requires the out-of-line copy
9234 to have the same parent. For local class methods, this doesn't
9235 apply; we just use the old DIE. */
9236 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9237 && (DECL_ARTIFICIAL (decl)
9238 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9239 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9240 == (unsigned) DECL_SOURCE_LINE (decl)))))
9244 /* Clear out the declaration attribute and the parm types. */
9245 remove_AT (subr_die, DW_AT_declaration);
9246 remove_children (subr_die);
9250 subr_die = new_die (DW_TAG_subprogram, context_die);
9251 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9252 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9253 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9254 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9255 != (unsigned) DECL_SOURCE_LINE (decl))
9257 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9262 subr_die = new_die (DW_TAG_subprogram, context_die);
9264 if (TREE_PUBLIC (decl))
9265 add_AT_flag (subr_die, DW_AT_external, 1);
9267 add_name_and_src_coords_attributes (subr_die, decl);
9268 if (debug_info_level > DINFO_LEVEL_TERSE)
9270 register tree type = TREE_TYPE (decl);
9272 add_prototyped_attribute (subr_die, type);
9273 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9276 add_pure_or_virtual_attribute (subr_die, decl);
9277 if (DECL_ARTIFICIAL (decl))
9278 add_AT_flag (subr_die, DW_AT_artificial, 1);
9279 if (TREE_PROTECTED (decl))
9280 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9281 else if (TREE_PRIVATE (decl))
9282 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9287 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9289 add_AT_flag (subr_die, DW_AT_declaration, 1);
9291 /* The first time we see a member function, it is in the context of
9292 the class to which it belongs. We make sure of this by emitting
9293 the class first. The next time is the definition, which is
9294 handled above. The two may come from the same source text. */
9295 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9296 equate_decl_number_to_die (decl, subr_die);
9299 else if (DECL_ABSTRACT (decl))
9301 if (DECL_INLINE (decl) && !flag_no_inline)
9303 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9304 inline functions, but not for extern inline functions.
9305 We can't get this completely correct because information
9306 about whether the function was declared inline is not
9308 if (DECL_DEFER_OUTPUT (decl))
9309 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9311 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9314 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9316 equate_decl_number_to_die (decl, subr_die);
9318 else if (!DECL_EXTERNAL (decl))
9320 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9321 equate_decl_number_to_die (decl, subr_die);
9323 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9324 current_funcdef_number);
9325 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9326 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9327 current_funcdef_number);
9328 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9330 add_pubname (decl, subr_die);
9331 add_arange (decl, subr_die);
9333 #ifdef MIPS_DEBUGGING_INFO
9334 /* Add a reference to the FDE for this routine. */
9335 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9338 /* Define the "frame base" location for this routine. We use the
9339 frame pointer or stack pointer registers, since the RTL for local
9340 variables is relative to one of them. */
9342 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9343 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9346 /* ??? This fails for nested inline functions, because context_display
9347 is not part of the state saved/restored for inline functions. */
9348 if (current_function_needs_context)
9349 add_AT_location_description (subr_die, DW_AT_static_link,
9350 lookup_static_chain (decl));
9354 /* Now output descriptions of the arguments for this function. This gets
9355 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9356 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9357 `...' at the end of the formal parameter list. In order to find out if
9358 there was a trailing ellipsis or not, we must instead look at the type
9359 associated with the FUNCTION_DECL. This will be a node of type
9360 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9361 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9362 an ellipsis at the end. */
9364 /* In the case where we are describing a mere function declaration, all we
9365 need to do here (and all we *can* do here) is to describe the *types* of
9366 its formal parameters. */
9367 if (debug_info_level <= DINFO_LEVEL_TERSE)
9369 else if (declaration)
9370 gen_formal_types_die (decl, subr_die);
9373 /* Generate DIEs to represent all known formal parameters */
9374 register tree arg_decls = DECL_ARGUMENTS (decl);
9377 /* When generating DIEs, generate the unspecified_parameters DIE
9378 instead if we come across the arg "__builtin_va_alist" */
9379 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9380 if (TREE_CODE (parm) == PARM_DECL)
9382 if (DECL_NAME (parm)
9383 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9384 "__builtin_va_alist"))
9385 gen_unspecified_parameters_die (parm, subr_die);
9387 gen_decl_die (parm, subr_die);
9390 /* Decide whether we need a unspecified_parameters DIE at the end.
9391 There are 2 more cases to do this for: 1) the ansi ... declaration -
9392 this is detectable when the end of the arg list is not a
9393 void_type_node 2) an unprototyped function declaration (not a
9394 definition). This just means that we have no info about the
9395 parameters at all. */
9396 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9397 if (fn_arg_types != NULL)
9399 /* this is the prototyped case, check for ... */
9400 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9401 gen_unspecified_parameters_die (decl, subr_die);
9403 else if (DECL_INITIAL (decl) == NULL_TREE)
9404 gen_unspecified_parameters_die (decl, subr_die);
9407 /* Output Dwarf info for all of the stuff within the body of the function
9408 (if it has one - it may be just a declaration). */
9409 outer_scope = DECL_INITIAL (decl);
9411 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9412 node created to represent a function. This outermost BLOCK actually
9413 represents the outermost binding contour for the function, i.e. the
9414 contour in which the function's formal parameters and labels get
9415 declared. Curiously, it appears that the front end doesn't actually
9416 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9417 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9418 list for the function instead.) The BLOCK_VARS list for the
9419 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9420 the function however, and we output DWARF info for those in
9421 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9422 node representing the function's outermost pair of curly braces, and
9423 any blocks used for the base and member initializers of a C++
9424 constructor function. */
9425 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9427 current_function_has_inlines = 0;
9428 decls_for_scope (outer_scope, subr_die, 0);
9430 #if 0 && defined (MIPS_DEBUGGING_INFO)
9431 if (current_function_has_inlines)
9433 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9434 if (! comp_unit_has_inlines)
9436 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9437 comp_unit_has_inlines = 1;
9444 /* Generate a DIE to represent a declared data object. */
9447 gen_variable_die (decl, context_die)
9449 register dw_die_ref context_die;
9451 register tree origin = decl_ultimate_origin (decl);
9452 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9454 dw_die_ref old_die = lookup_decl_die (decl);
9455 int declaration = (DECL_EXTERNAL (decl)
9456 || class_scope_p (context_die));
9459 add_abstract_origin_attribute (var_die, origin);
9460 /* Loop unrolling can create multiple blocks that refer to the same
9461 static variable, so we must test for the DW_AT_declaration flag. */
9462 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9463 copy decls and set the DECL_ABSTRACT flag on them instead of
9465 else if (old_die && TREE_STATIC (decl)
9466 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9468 /* This is a definition of a C++ class level static. */
9469 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9470 if (DECL_NAME (decl))
9472 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9474 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9475 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9477 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9478 != (unsigned) DECL_SOURCE_LINE (decl))
9480 add_AT_unsigned (var_die, DW_AT_decl_line,
9481 DECL_SOURCE_LINE (decl));
9486 add_name_and_src_coords_attributes (var_die, decl);
9487 add_type_attribute (var_die, TREE_TYPE (decl),
9488 TREE_READONLY (decl),
9489 TREE_THIS_VOLATILE (decl), context_die);
9491 if (TREE_PUBLIC (decl))
9492 add_AT_flag (var_die, DW_AT_external, 1);
9494 if (DECL_ARTIFICIAL (decl))
9495 add_AT_flag (var_die, DW_AT_artificial, 1);
9497 if (TREE_PROTECTED (decl))
9498 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9500 else if (TREE_PRIVATE (decl))
9501 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9505 add_AT_flag (var_die, DW_AT_declaration, 1);
9507 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9508 equate_decl_number_to_die (decl, var_die);
9510 if (! declaration && ! DECL_ABSTRACT (decl))
9512 add_location_or_const_value_attribute (var_die, decl);
9513 add_pubname (decl, var_die);
9516 tree_add_const_value_attribute (var_die, decl);
9519 /* Generate a DIE to represent a label identifier. */
9522 gen_label_die (decl, context_die)
9524 register dw_die_ref context_die;
9526 register tree origin = decl_ultimate_origin (decl);
9527 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
9529 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9532 add_abstract_origin_attribute (lbl_die, origin);
9534 add_name_and_src_coords_attributes (lbl_die, decl);
9536 if (DECL_ABSTRACT (decl))
9537 equate_decl_number_to_die (decl, lbl_die);
9540 insn = DECL_RTL (decl);
9542 /* Deleted labels are programmer specified labels which have been
9543 eliminated because of various optimisations. We still emit them
9544 here so that it is possible to put breakpoints on them. */
9545 if (GET_CODE (insn) == CODE_LABEL
9546 || ((GET_CODE (insn) == NOTE
9547 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
9549 /* When optimization is enabled (via -O) some parts of the compiler
9550 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
9551 represent source-level labels which were explicitly declared by
9552 the user. This really shouldn't be happening though, so catch
9553 it if it ever does happen. */
9554 if (INSN_DELETED_P (insn))
9557 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
9558 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
9563 /* Generate a DIE for a lexical block. */
9566 gen_lexical_block_die (stmt, context_die, depth)
9568 register dw_die_ref context_die;
9571 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
9572 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9574 if (! BLOCK_ABSTRACT (stmt))
9576 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9577 BLOCK_NUMBER (stmt));
9578 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
9579 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9580 BLOCK_NUMBER (stmt));
9581 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
9584 decls_for_scope (stmt, stmt_die, depth);
9587 /* Generate a DIE for an inlined subprogram. */
9590 gen_inlined_subroutine_die (stmt, context_die, depth)
9592 register dw_die_ref context_die;
9595 if (! BLOCK_ABSTRACT (stmt))
9597 register dw_die_ref subr_die
9598 = new_die (DW_TAG_inlined_subroutine, context_die);
9599 register tree decl = block_ultimate_origin (stmt);
9600 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9602 /* Emit info for the abstract instance first, if we haven't yet. */
9603 dwarf2out_abstract_function (decl);
9605 add_abstract_origin_attribute (subr_die, decl);
9606 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9607 BLOCK_NUMBER (stmt));
9608 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
9609 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9610 BLOCK_NUMBER (stmt));
9611 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
9612 decls_for_scope (stmt, subr_die, depth);
9613 current_function_has_inlines = 1;
9617 /* Generate a DIE for a field in a record, or structure. */
9620 gen_field_die (decl, context_die)
9622 register dw_die_ref context_die;
9624 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
9626 add_name_and_src_coords_attributes (decl_die, decl);
9627 add_type_attribute (decl_die, member_declared_type (decl),
9628 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
9631 /* If this is a bit field... */
9632 if (DECL_BIT_FIELD_TYPE (decl))
9634 add_byte_size_attribute (decl_die, decl);
9635 add_bit_size_attribute (decl_die, decl);
9636 add_bit_offset_attribute (decl_die, decl);
9639 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
9640 add_data_member_location_attribute (decl_die, decl);
9642 if (DECL_ARTIFICIAL (decl))
9643 add_AT_flag (decl_die, DW_AT_artificial, 1);
9645 if (TREE_PROTECTED (decl))
9646 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
9648 else if (TREE_PRIVATE (decl))
9649 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
9653 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9654 Use modified_type_die instead.
9655 We keep this code here just in case these types of DIEs may be needed to
9656 represent certain things in other languages (e.g. Pascal) someday. */
9658 gen_pointer_type_die (type, context_die)
9660 register dw_die_ref context_die;
9662 register dw_die_ref ptr_die
9663 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
9665 equate_type_number_to_die (type, ptr_die);
9666 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9667 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9670 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9671 Use modified_type_die instead.
9672 We keep this code here just in case these types of DIEs may be needed to
9673 represent certain things in other languages (e.g. Pascal) someday. */
9675 gen_reference_type_die (type, context_die)
9677 register dw_die_ref context_die;
9679 register dw_die_ref ref_die
9680 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
9682 equate_type_number_to_die (type, ref_die);
9683 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
9684 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9688 /* Generate a DIE for a pointer to a member type. */
9690 gen_ptr_to_mbr_type_die (type, context_die)
9692 register dw_die_ref context_die;
9694 register dw_die_ref ptr_die
9695 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
9697 equate_type_number_to_die (type, ptr_die);
9698 add_AT_die_ref (ptr_die, DW_AT_containing_type,
9699 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
9700 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9703 /* Generate the DIE for the compilation unit. */
9706 gen_compile_unit_die (filename)
9707 register const char *filename;
9709 register dw_die_ref die;
9711 const char *wd = getpwd ();
9714 die = new_die (DW_TAG_compile_unit, NULL);
9715 add_name_attribute (die, filename);
9717 if (wd != NULL && filename[0] != DIR_SEPARATOR)
9718 add_AT_string (die, DW_AT_comp_dir, wd);
9720 sprintf (producer, "%s %s", language_string, version_string);
9722 #ifdef MIPS_DEBUGGING_INFO
9723 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
9724 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
9725 not appear in the producer string, the debugger reaches the conclusion
9726 that the object file is stripped and has no debugging information.
9727 To get the MIPS/SGI debugger to believe that there is debugging
9728 information in the object file, we add a -g to the producer string. */
9729 if (debug_info_level > DINFO_LEVEL_TERSE)
9730 strcat (producer, " -g");
9733 add_AT_string (die, DW_AT_producer, producer);
9735 if (strcmp (language_string, "GNU C++") == 0)
9736 language = DW_LANG_C_plus_plus;
9737 else if (strcmp (language_string, "GNU Ada") == 0)
9738 language = DW_LANG_Ada83;
9739 else if (strcmp (language_string, "GNU F77") == 0)
9740 language = DW_LANG_Fortran77;
9741 else if (strcmp (language_string, "GNU Pascal") == 0)
9742 language = DW_LANG_Pascal83;
9743 else if (strcmp (language_string, "GNU Java") == 0)
9744 language = DW_LANG_Java;
9745 else if (flag_traditional)
9746 language = DW_LANG_C;
9748 language = DW_LANG_C89;
9750 add_AT_unsigned (die, DW_AT_language, language);
9755 /* Generate a DIE for a string type. */
9758 gen_string_type_die (type, context_die)
9760 register dw_die_ref context_die;
9762 register dw_die_ref type_die
9763 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
9765 equate_type_number_to_die (type, type_die);
9767 /* Fudge the string length attribute for now. */
9769 /* TODO: add string length info.
9770 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
9771 bound_representation (upper_bound, 0, 'u'); */
9774 /* Generate the DIE for a base class. */
9777 gen_inheritance_die (binfo, context_die)
9778 register tree binfo;
9779 register dw_die_ref context_die;
9781 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
9783 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
9784 add_data_member_location_attribute (die, binfo);
9786 if (TREE_VIA_VIRTUAL (binfo))
9787 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9788 if (TREE_VIA_PUBLIC (binfo))
9789 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
9790 else if (TREE_VIA_PROTECTED (binfo))
9791 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
9794 /* Generate a DIE for a class member. */
9797 gen_member_die (type, context_die)
9799 register dw_die_ref context_die;
9801 register tree member;
9804 /* If this is not an incomplete type, output descriptions of each of its
9805 members. Note that as we output the DIEs necessary to represent the
9806 members of this record or union type, we will also be trying to output
9807 DIEs to represent the *types* of those members. However the `type'
9808 function (above) will specifically avoid generating type DIEs for member
9809 types *within* the list of member DIEs for this (containing) type execpt
9810 for those types (of members) which are explicitly marked as also being
9811 members of this (containing) type themselves. The g++ front- end can
9812 force any given type to be treated as a member of some other
9813 (containing) type by setting the TYPE_CONTEXT of the given (member) type
9814 to point to the TREE node representing the appropriate (containing)
9817 /* First output info about the base classes. */
9818 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
9820 register tree bases = TYPE_BINFO_BASETYPES (type);
9821 register int n_bases = TREE_VEC_LENGTH (bases);
9824 for (i = 0; i < n_bases; i++)
9825 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
9828 /* Now output info about the data members and type members. */
9829 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
9831 /* If we thought we were generating minimal debug info for TYPE
9832 and then changed our minds, some of the member declarations
9833 may have already been defined. Don't define them again, but
9834 do put them in the right order. */
9836 child = lookup_decl_die (member);
9838 splice_child_die (context_die, child);
9840 gen_decl_die (member, context_die);
9843 /* Now output info about the function members (if any). */
9844 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
9846 /* Don't include clones in the member list. */
9847 if (DECL_ABSTRACT_ORIGIN (member))
9850 child = lookup_decl_die (member);
9852 splice_child_die (context_die, child);
9854 gen_decl_die (member, context_die);
9858 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
9859 is set, we pretend that the type was never defined, so we only get the
9860 member DIEs needed by later specification DIEs. */
9863 gen_struct_or_union_type_die (type, context_die)
9865 register dw_die_ref context_die;
9867 register dw_die_ref type_die = lookup_type_die (type);
9868 register dw_die_ref scope_die = 0;
9869 register int nested = 0;
9870 int complete = (TYPE_SIZE (type)
9871 && (! TYPE_STUB_DECL (type)
9872 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
9874 if (type_die && ! complete)
9877 if (TYPE_CONTEXT (type) != NULL_TREE
9878 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
9881 scope_die = scope_die_for (type, context_die);
9883 if (! type_die || (nested && scope_die == comp_unit_die))
9884 /* First occurrence of type or toplevel definition of nested class. */
9886 register dw_die_ref old_die = type_die;
9888 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
9889 ? DW_TAG_structure_type : DW_TAG_union_type,
9891 equate_type_number_to_die (type, type_die);
9893 add_AT_die_ref (type_die, DW_AT_specification, old_die);
9895 add_name_attribute (type_die, type_tag (type));
9898 remove_AT (type_die, DW_AT_declaration);
9900 /* If this type has been completed, then give it a byte_size attribute and
9901 then give a list of members. */
9904 /* Prevent infinite recursion in cases where the type of some member of
9905 this type is expressed in terms of this type itself. */
9906 TREE_ASM_WRITTEN (type) = 1;
9907 add_byte_size_attribute (type_die, type);
9908 if (TYPE_STUB_DECL (type) != NULL_TREE)
9909 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9911 /* If the first reference to this type was as the return type of an
9912 inline function, then it may not have a parent. Fix this now. */
9913 if (type_die->die_parent == NULL)
9914 add_child_die (scope_die, type_die);
9916 push_decl_scope (type);
9917 gen_member_die (type, type_die);
9920 /* GNU extension: Record what type our vtable lives in. */
9921 if (TYPE_VFIELD (type))
9923 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
9925 gen_type_die (vtype, context_die);
9926 add_AT_die_ref (type_die, DW_AT_containing_type,
9927 lookup_type_die (vtype));
9932 add_AT_flag (type_die, DW_AT_declaration, 1);
9934 /* We don't need to do this for function-local types. */
9935 if (! decl_function_context (TYPE_STUB_DECL (type)))
9936 add_incomplete_type (type);
9940 /* Generate a DIE for a subroutine _type_. */
9943 gen_subroutine_type_die (type, context_die)
9945 register dw_die_ref context_die;
9947 register tree return_type = TREE_TYPE (type);
9948 register dw_die_ref subr_die
9949 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
9951 equate_type_number_to_die (type, subr_die);
9952 add_prototyped_attribute (subr_die, type);
9953 add_type_attribute (subr_die, return_type, 0, 0, context_die);
9954 gen_formal_types_die (type, subr_die);
9957 /* Generate a DIE for a type definition */
9960 gen_typedef_die (decl, context_die)
9962 register dw_die_ref context_die;
9964 register dw_die_ref type_die;
9965 register tree origin;
9967 if (TREE_ASM_WRITTEN (decl))
9969 TREE_ASM_WRITTEN (decl) = 1;
9971 type_die = new_die (DW_TAG_typedef, context_die);
9972 origin = decl_ultimate_origin (decl);
9974 add_abstract_origin_attribute (type_die, origin);
9978 add_name_and_src_coords_attributes (type_die, decl);
9979 if (DECL_ORIGINAL_TYPE (decl))
9981 type = DECL_ORIGINAL_TYPE (decl);
9983 if (type == TREE_TYPE (decl))
9986 equate_type_number_to_die (TREE_TYPE (decl), type_die);
9989 type = TREE_TYPE (decl);
9990 add_type_attribute (type_die, type, TREE_READONLY (decl),
9991 TREE_THIS_VOLATILE (decl), context_die);
9994 if (DECL_ABSTRACT (decl))
9995 equate_decl_number_to_die (decl, type_die);
9998 /* Generate a type description DIE. */
10001 gen_type_die (type, context_die)
10002 register tree type;
10003 register dw_die_ref context_die;
10007 if (type == NULL_TREE || type == error_mark_node)
10010 /* We are going to output a DIE to represent the unqualified version of
10011 this type (i.e. without any const or volatile qualifiers) so get the
10012 main variant (i.e. the unqualified version) of this type now. */
10013 type = type_main_variant (type);
10015 if (TREE_ASM_WRITTEN (type))
10018 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10019 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10021 TREE_ASM_WRITTEN (type) = 1;
10022 gen_decl_die (TYPE_NAME (type), context_die);
10026 switch (TREE_CODE (type))
10032 case REFERENCE_TYPE:
10033 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10034 ensures that the gen_type_die recursion will terminate even if the
10035 type is recursive. Recursive types are possible in Ada. */
10036 /* ??? We could perhaps do this for all types before the switch
10038 TREE_ASM_WRITTEN (type) = 1;
10040 /* For these types, all that is required is that we output a DIE (or a
10041 set of DIEs) to represent the "basis" type. */
10042 gen_type_die (TREE_TYPE (type), context_die);
10046 /* This code is used for C++ pointer-to-data-member types.
10047 Output a description of the relevant class type. */
10048 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10050 /* Output a description of the type of the object pointed to. */
10051 gen_type_die (TREE_TYPE (type), context_die);
10053 /* Now output a DIE to represent this pointer-to-data-member type
10055 gen_ptr_to_mbr_type_die (type, context_die);
10059 gen_type_die (TYPE_DOMAIN (type), context_die);
10060 gen_set_type_die (type, context_die);
10064 gen_type_die (TREE_TYPE (type), context_die);
10065 abort (); /* No way to represent these in Dwarf yet! */
10068 case FUNCTION_TYPE:
10069 /* Force out return type (in case it wasn't forced out already). */
10070 gen_type_die (TREE_TYPE (type), context_die);
10071 gen_subroutine_type_die (type, context_die);
10075 /* Force out return type (in case it wasn't forced out already). */
10076 gen_type_die (TREE_TYPE (type), context_die);
10077 gen_subroutine_type_die (type, context_die);
10081 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10083 gen_type_die (TREE_TYPE (type), context_die);
10084 gen_string_type_die (type, context_die);
10087 gen_array_type_die (type, context_die);
10091 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10094 case ENUMERAL_TYPE:
10097 case QUAL_UNION_TYPE:
10098 /* If this is a nested type whose containing class hasn't been
10099 written out yet, writing it out will cover this one, too.
10100 This does not apply to instantiations of member class templates;
10101 they need to be added to the containing class as they are
10102 generated. FIXME: This hurts the idea of combining type decls
10103 from multiple TUs, since we can't predict what set of template
10104 instantiations we'll get. */
10105 if (TYPE_CONTEXT (type)
10106 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10107 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10109 gen_type_die (TYPE_CONTEXT (type), context_die);
10111 if (TREE_ASM_WRITTEN (type))
10114 /* If that failed, attach ourselves to the stub. */
10115 push_decl_scope (TYPE_CONTEXT (type));
10116 context_die = lookup_type_die (TYPE_CONTEXT (type));
10122 if (TREE_CODE (type) == ENUMERAL_TYPE)
10123 gen_enumeration_type_die (type, context_die);
10125 gen_struct_or_union_type_die (type, context_die);
10130 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10131 it up if it is ever completed. gen_*_type_die will set it for us
10132 when appropriate. */
10141 /* No DIEs needed for fundamental types. */
10145 /* No Dwarf representation currently defined. */
10152 TREE_ASM_WRITTEN (type) = 1;
10155 /* Generate a DIE for a tagged type instantiation. */
10158 gen_tagged_type_instantiation_die (type, context_die)
10159 register tree type;
10160 register dw_die_ref context_die;
10162 if (type == NULL_TREE || type == error_mark_node)
10165 /* We are going to output a DIE to represent the unqualified version of
10166 this type (i.e. without any const or volatile qualifiers) so make sure
10167 that we have the main variant (i.e. the unqualified version) of this
10169 if (type != type_main_variant (type))
10172 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10173 an instance of an unresolved type. */
10175 switch (TREE_CODE (type))
10180 case ENUMERAL_TYPE:
10181 gen_inlined_enumeration_type_die (type, context_die);
10185 gen_inlined_structure_type_die (type, context_die);
10189 case QUAL_UNION_TYPE:
10190 gen_inlined_union_type_die (type, context_die);
10198 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10199 things which are local to the given block. */
10202 gen_block_die (stmt, context_die, depth)
10203 register tree stmt;
10204 register dw_die_ref context_die;
10207 register int must_output_die = 0;
10208 register tree origin;
10209 register tree decl;
10210 register enum tree_code origin_code;
10212 /* Ignore blocks never really used to make RTL. */
10214 if (stmt == NULL_TREE || !TREE_USED (stmt)
10215 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10218 /* Determine the "ultimate origin" of this block. This block may be an
10219 inlined instance of an inlined instance of inline function, so we have
10220 to trace all of the way back through the origin chain to find out what
10221 sort of node actually served as the original seed for the creation of
10222 the current block. */
10223 origin = block_ultimate_origin (stmt);
10224 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10226 /* Determine if we need to output any Dwarf DIEs at all to represent this
10228 if (origin_code == FUNCTION_DECL)
10229 /* The outer scopes for inlinings *must* always be represented. We
10230 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10231 must_output_die = 1;
10234 /* In the case where the current block represents an inlining of the
10235 "body block" of an inline function, we must *NOT* output any DIE for
10236 this block because we have already output a DIE to represent the
10237 whole inlined function scope and the "body block" of any function
10238 doesn't really represent a different scope according to ANSI C
10239 rules. So we check here to make sure that this block does not
10240 represent a "body block inlining" before trying to set the
10241 `must_output_die' flag. */
10242 if (! is_body_block (origin ? origin : stmt))
10244 /* Determine if this block directly contains any "significant"
10245 local declarations which we will need to output DIEs for. */
10246 if (debug_info_level > DINFO_LEVEL_TERSE)
10247 /* We are not in terse mode so *any* local declaration counts
10248 as being a "significant" one. */
10249 must_output_die = (BLOCK_VARS (stmt) != NULL);
10251 /* We are in terse mode, so only local (nested) function
10252 definitions count as "significant" local declarations. */
10253 for (decl = BLOCK_VARS (stmt);
10254 decl != NULL; decl = TREE_CHAIN (decl))
10255 if (TREE_CODE (decl) == FUNCTION_DECL
10256 && DECL_INITIAL (decl))
10258 must_output_die = 1;
10264 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10265 DIE for any block which contains no significant local declarations at
10266 all. Rather, in such cases we just call `decls_for_scope' so that any
10267 needed Dwarf info for any sub-blocks will get properly generated. Note
10268 that in terse mode, our definition of what constitutes a "significant"
10269 local declaration gets restricted to include only inlined function
10270 instances and local (nested) function definitions. */
10271 if (must_output_die)
10273 if (origin_code == FUNCTION_DECL)
10274 gen_inlined_subroutine_die (stmt, context_die, depth);
10276 gen_lexical_block_die (stmt, context_die, depth);
10279 decls_for_scope (stmt, context_die, depth);
10282 /* Generate all of the decls declared within a given scope and (recursively)
10283 all of its sub-blocks. */
10286 decls_for_scope (stmt, context_die, depth)
10287 register tree stmt;
10288 register dw_die_ref context_die;
10291 register tree decl;
10292 register tree subblocks;
10294 /* Ignore blocks never really used to make RTL. */
10295 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10298 /* Output the DIEs to represent all of the data objects and typedefs
10299 declared directly within this block but not within any nested
10300 sub-blocks. Also, nested function and tag DIEs have been
10301 generated with a parent of NULL; fix that up now. */
10302 for (decl = BLOCK_VARS (stmt);
10303 decl != NULL; decl = TREE_CHAIN (decl))
10305 register dw_die_ref die;
10307 if (TREE_CODE (decl) == FUNCTION_DECL)
10308 die = lookup_decl_die (decl);
10309 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10310 die = lookup_type_die (TREE_TYPE (decl));
10314 if (die != NULL && die->die_parent == NULL)
10315 add_child_die (context_die, die);
10317 gen_decl_die (decl, context_die);
10320 /* Output the DIEs to represent all sub-blocks (and the items declared
10321 therein) of this block. */
10322 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10324 subblocks = BLOCK_CHAIN (subblocks))
10325 gen_block_die (subblocks, context_die, depth + 1);
10328 /* Is this a typedef we can avoid emitting? */
10331 is_redundant_typedef (decl)
10332 register tree decl;
10334 if (TYPE_DECL_IS_STUB (decl))
10337 if (DECL_ARTIFICIAL (decl)
10338 && DECL_CONTEXT (decl)
10339 && is_tagged_type (DECL_CONTEXT (decl))
10340 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10341 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10342 /* Also ignore the artificial member typedef for the class name. */
10348 /* Generate Dwarf debug information for a decl described by DECL. */
10351 gen_decl_die (decl, context_die)
10352 register tree decl;
10353 register dw_die_ref context_die;
10355 register tree origin;
10357 if (TREE_CODE (decl) == ERROR_MARK)
10360 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10361 if (DECL_IGNORED_P (decl))
10364 switch (TREE_CODE (decl))
10367 /* The individual enumerators of an enum type get output when we output
10368 the Dwarf representation of the relevant enum type itself. */
10371 case FUNCTION_DECL:
10372 /* Don't output any DIEs to represent mere function declarations,
10373 unless they are class members or explicit block externs. */
10374 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10375 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10378 /* If we're emitting a clone, emit info for the abstract instance. */
10379 if (DECL_ORIGIN (decl) != decl)
10380 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
10381 /* If we're emitting an out-of-line copy of an inline function,
10382 emit info for the abstract instance and set up to refer to it. */
10383 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10384 && ! class_scope_p (context_die)
10385 /* dwarf2out_abstract_function won't emit a die if this is just
10386 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10387 that case, because that works only if we have a die. */
10388 && DECL_INITIAL (decl) != NULL_TREE)
10390 dwarf2out_abstract_function (decl);
10391 set_decl_origin_self (decl);
10393 /* Otherwise we're emitting the primary DIE for this decl. */
10394 else if (debug_info_level > DINFO_LEVEL_TERSE)
10396 /* Before we describe the FUNCTION_DECL itself, make sure that we
10397 have described its return type. */
10398 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10400 /* And its virtual context. */
10401 if (DECL_VINDEX (decl) != NULL_TREE)
10402 gen_type_die (DECL_CONTEXT (decl), context_die);
10404 /* And its containing type. */
10405 origin = decl_class_context (decl);
10406 if (origin != NULL_TREE)
10407 gen_type_die_for_member (origin, decl, context_die);
10410 /* Now output a DIE to represent the function itself. */
10411 gen_subprogram_die (decl, context_die);
10415 /* If we are in terse mode, don't generate any DIEs to represent any
10416 actual typedefs. */
10417 if (debug_info_level <= DINFO_LEVEL_TERSE)
10420 /* In the special case of a TYPE_DECL node representing the
10421 declaration of some type tag, if the given TYPE_DECL is marked as
10422 having been instantiated from some other (original) TYPE_DECL node
10423 (e.g. one which was generated within the original definition of an
10424 inline function) we have to generate a special (abbreviated)
10425 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10427 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10429 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10433 if (is_redundant_typedef (decl))
10434 gen_type_die (TREE_TYPE (decl), context_die);
10436 /* Output a DIE to represent the typedef itself. */
10437 gen_typedef_die (decl, context_die);
10441 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10442 gen_label_die (decl, context_die);
10446 /* If we are in terse mode, don't generate any DIEs to represent any
10447 variable declarations or definitions. */
10448 if (debug_info_level <= DINFO_LEVEL_TERSE)
10451 /* Output any DIEs that are needed to specify the type of this data
10453 gen_type_die (TREE_TYPE (decl), context_die);
10455 /* And its containing type. */
10456 origin = decl_class_context (decl);
10457 if (origin != NULL_TREE)
10458 gen_type_die_for_member (origin, decl, context_die);
10460 /* Now output the DIE to represent the data object itself. This gets
10461 complicated because of the possibility that the VAR_DECL really
10462 represents an inlined instance of a formal parameter for an inline
10464 origin = decl_ultimate_origin (decl);
10465 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10466 gen_formal_parameter_die (decl, context_die);
10468 gen_variable_die (decl, context_die);
10472 /* Ignore the nameless fields that are used to skip bits, but
10473 handle C++ anonymous unions. */
10474 if (DECL_NAME (decl) != NULL_TREE
10475 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10477 gen_type_die (member_declared_type (decl), context_die);
10478 gen_field_die (decl, context_die);
10483 gen_type_die (TREE_TYPE (decl), context_die);
10484 gen_formal_parameter_die (decl, context_die);
10487 case NAMESPACE_DECL:
10488 /* Ignore for now. */
10496 /* Add Ada "use" clause information for SGI Workshop debugger. */
10499 dwarf2out_add_library_unit_info (filename, context_list)
10500 const char *filename;
10501 const char *context_list;
10503 unsigned int file_index;
10505 if (filename != NULL)
10507 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10508 tree context_list_decl
10509 = build_decl (LABEL_DECL, get_identifier (context_list),
10512 TREE_PUBLIC (context_list_decl) = TRUE;
10513 add_name_attribute (unit_die, context_list);
10514 file_index = lookup_filename (filename);
10515 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10516 add_pubname (context_list_decl, unit_die);
10520 /* Write the debugging output for DECL. */
10523 dwarf2out_decl (decl)
10524 register tree decl;
10526 register dw_die_ref context_die = comp_unit_die;
10528 if (TREE_CODE (decl) == ERROR_MARK)
10531 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10532 if (DECL_IGNORED_P (decl))
10535 switch (TREE_CODE (decl))
10537 case FUNCTION_DECL:
10538 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
10539 builtin function. Explicit programmer-supplied declarations of
10540 these same functions should NOT be ignored however. */
10541 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
10544 /* What we would really like to do here is to filter out all mere
10545 file-scope declarations of file-scope functions which are never
10546 referenced later within this translation unit (and keep all of ones
10547 that *are* referenced later on) but we aren't clairvoyant, so we have
10548 no idea which functions will be referenced in the future (i.e. later
10549 on within the current translation unit). So here we just ignore all
10550 file-scope function declarations which are not also definitions. If
10551 and when the debugger needs to know something about these functions,
10552 it will have to hunt around and find the DWARF information associated
10553 with the definition of the function. Note that we can't just check
10554 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
10555 definitions and which ones represent mere declarations. We have to
10556 check `DECL_INITIAL' instead. That's because the C front-end
10557 supports some weird semantics for "extern inline" function
10558 definitions. These can get inlined within the current translation
10559 unit (an thus, we need to generate DWARF info for their abstract
10560 instances so that the DWARF info for the concrete inlined instances
10561 can have something to refer to) but the compiler never generates any
10562 out-of-lines instances of such things (despite the fact that they
10563 *are* definitions). The important point is that the C front-end
10564 marks these "extern inline" functions as DECL_EXTERNAL, but we need
10565 to generate DWARF for them anyway. Note that the C++ front-end also
10566 plays some similar games for inline function definitions appearing
10567 within include files which also contain
10568 `#pragma interface' pragmas. */
10569 if (DECL_INITIAL (decl) == NULL_TREE)
10572 /* If we're a nested function, initially use a parent of NULL; if we're
10573 a plain function, this will be fixed up in decls_for_scope. If
10574 we're a method, it will be ignored, since we already have a DIE. */
10575 if (decl_function_context (decl))
10576 context_die = NULL;
10581 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
10582 declaration and if the declaration was never even referenced from
10583 within this entire compilation unit. We suppress these DIEs in
10584 order to save space in the .debug section (by eliminating entries
10585 which are probably useless). Note that we must not suppress
10586 block-local extern declarations (whether used or not) because that
10587 would screw-up the debugger's name lookup mechanism and cause it to
10588 miss things which really ought to be in scope at a given point. */
10589 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
10592 /* If we are in terse mode, don't generate any DIEs to represent any
10593 variable declarations or definitions. */
10594 if (debug_info_level <= DINFO_LEVEL_TERSE)
10599 /* Don't emit stubs for types unless they are needed by other DIEs. */
10600 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
10603 /* Don't bother trying to generate any DIEs to represent any of the
10604 normal built-in types for the language we are compiling. */
10605 if (DECL_SOURCE_LINE (decl) == 0)
10607 /* OK, we need to generate one for `bool' so GDB knows what type
10608 comparisons have. */
10609 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
10610 == DW_LANG_C_plus_plus)
10611 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
10612 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
10617 /* If we are in terse mode, don't generate any DIEs for types. */
10618 if (debug_info_level <= DINFO_LEVEL_TERSE)
10621 /* If we're a function-scope tag, initially use a parent of NULL;
10622 this will be fixed up in decls_for_scope. */
10623 if (decl_function_context (decl))
10624 context_die = NULL;
10632 gen_decl_die (decl, context_die);
10635 /* Output a marker (i.e. a label) for the beginning of the generated code for
10636 a lexical block. */
10639 dwarf2out_begin_block (blocknum)
10640 register unsigned blocknum;
10642 function_section (current_function_decl);
10643 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
10646 /* Output a marker (i.e. a label) for the end of the generated code for a
10650 dwarf2out_end_block (blocknum)
10651 register unsigned blocknum;
10653 function_section (current_function_decl);
10654 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
10657 /* Returns nonzero if it is appropriate not to emit any debugging
10658 information for BLOCK, because it doesn't contain any instructions.
10660 Don't allow this for blocks with nested functions or local classes
10661 as we would end up with orphans, and in the presence of scheduling
10662 we may end up calling them anyway. */
10665 dwarf2out_ignore_block (block)
10669 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
10670 if (TREE_CODE (decl) == FUNCTION_DECL
10671 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
10676 /* Lookup a filename (in the list of filenames that we know about here in
10677 dwarf2out.c) and return its "index". The index of each (known) filename is
10678 just a unique number which is associated with only that one filename.
10679 We need such numbers for the sake of generating labels
10680 (in the .debug_sfnames section) and references to those
10681 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
10682 If the filename given as an argument is not found in our current list,
10683 add it to the list and assign it the next available unique index number.
10684 In order to speed up searches, we remember the index of the filename
10685 was looked up last. This handles the majority of all searches. */
10688 lookup_filename (file_name)
10689 const char *file_name;
10691 register unsigned i;
10693 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
10694 if (strcmp (file_name, "<internal>") == 0
10695 || strcmp (file_name, "<built-in>") == 0)
10698 /* Check to see if the file name that was searched on the previous
10699 call matches this file name. If so, return the index. */
10700 if (file_table.last_lookup_index != 0)
10701 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
10702 return file_table.last_lookup_index;
10704 /* Didn't match the previous lookup, search the table */
10705 for (i = 1; i < file_table.in_use; ++i)
10706 if (strcmp (file_name, file_table.table[i]) == 0)
10708 file_table.last_lookup_index = i;
10712 /* Prepare to add a new table entry by making sure there is enough space in
10713 the table to do so. If not, expand the current table. */
10714 if (i == file_table.allocated)
10716 file_table.allocated = i + FILE_TABLE_INCREMENT;
10717 file_table.table = (char **)
10718 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
10721 /* Add the new entry to the end of the filename table. */
10722 file_table.table[i] = xstrdup (file_name);
10723 file_table.in_use = i + 1;
10724 file_table.last_lookup_index = i;
10726 if (DWARF2_ASM_LINE_DEBUG_INFO)
10727 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
10735 /* Allocate the initial hunk of the file_table. */
10736 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
10737 file_table.allocated = FILE_TABLE_INCREMENT;
10739 /* Skip the first entry - file numbers begin at 1. */
10740 file_table.in_use = 1;
10741 file_table.last_lookup_index = 0;
10744 /* Output a label to mark the beginning of a source code line entry
10745 and record information relating to this source line, in
10746 'line_info_table' for later output of the .debug_line section. */
10749 dwarf2out_line (filename, line)
10750 register const char *filename;
10751 register unsigned line;
10753 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10755 function_section (current_function_decl);
10757 if (DWARF2_ASM_LINE_DEBUG_INFO)
10759 unsigned file_num = lookup_filename (filename);
10761 /* Emit the .loc directive understood by GNU as. */
10762 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
10764 /* Indicate that line number info exists. */
10765 ++line_info_table_in_use;
10767 /* Indicate that multiple line number tables exist. */
10768 if (DECL_SECTION_NAME (current_function_decl))
10769 ++separate_line_info_table_in_use;
10771 else if (DECL_SECTION_NAME (current_function_decl))
10773 register dw_separate_line_info_ref line_info;
10774 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
10775 separate_line_info_table_in_use);
10776 if (flag_debug_asm)
10777 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
10780 /* expand the line info table if necessary */
10781 if (separate_line_info_table_in_use
10782 == separate_line_info_table_allocated)
10784 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10785 separate_line_info_table
10786 = (dw_separate_line_info_ref)
10787 xrealloc (separate_line_info_table,
10788 separate_line_info_table_allocated
10789 * sizeof (dw_separate_line_info_entry));
10792 /* Add the new entry at the end of the line_info_table. */
10794 = &separate_line_info_table[separate_line_info_table_in_use++];
10795 line_info->dw_file_num = lookup_filename (filename);
10796 line_info->dw_line_num = line;
10797 line_info->function = current_funcdef_number;
10801 register dw_line_info_ref line_info;
10803 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
10804 line_info_table_in_use);
10805 if (flag_debug_asm)
10806 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
10809 /* Expand the line info table if necessary. */
10810 if (line_info_table_in_use == line_info_table_allocated)
10812 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10814 = (dw_line_info_ref)
10815 xrealloc (line_info_table,
10816 (line_info_table_allocated
10817 * sizeof (dw_line_info_entry)));
10820 /* Add the new entry at the end of the line_info_table. */
10821 line_info = &line_info_table[line_info_table_in_use++];
10822 line_info->dw_file_num = lookup_filename (filename);
10823 line_info->dw_line_num = line;
10828 /* Record the beginning of a new source file, for later output
10829 of the .debug_macinfo section. At present, unimplemented. */
10832 dwarf2out_start_source_file (filename)
10833 register const char *filename ATTRIBUTE_UNUSED;
10835 if (flag_eliminate_dwarf2_dups)
10837 /* Record the beginning of the file for break_out_includes. */
10838 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
10839 add_AT_string (bincl_die, DW_AT_name, filename);
10843 /* Record the end of a source file, for later output
10844 of the .debug_macinfo section. At present, unimplemented. */
10847 dwarf2out_end_source_file ()
10849 if (flag_eliminate_dwarf2_dups)
10851 /* Record the end of the file for break_out_includes. */
10852 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
10856 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10857 the tail part of the directive line, i.e. the part which is past the
10858 initial whitespace, #, whitespace, directive-name, whitespace part. */
10861 dwarf2out_define (lineno, buffer)
10862 register unsigned lineno ATTRIBUTE_UNUSED;
10863 register const char *buffer ATTRIBUTE_UNUSED;
10865 static int initialized = 0;
10868 dwarf2out_start_source_file (primary_filename);
10873 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10874 the tail part of the directive line, i.e. the part which is past the
10875 initial whitespace, #, whitespace, directive-name, whitespace part. */
10878 dwarf2out_undef (lineno, buffer)
10879 register unsigned lineno ATTRIBUTE_UNUSED;
10880 register const char *buffer ATTRIBUTE_UNUSED;
10884 /* Set up for Dwarf output at the start of compilation. */
10887 dwarf2out_init (asm_out_file, main_input_filename)
10888 register FILE *asm_out_file;
10889 register const char *main_input_filename;
10891 init_file_table ();
10893 /* Remember the name of the primary input file. */
10894 primary_filename = main_input_filename;
10896 /* Add it to the file table first, under the assumption that we'll
10897 be emitting line number data for it first, which avoids having
10898 to add an initial DW_LNS_set_file. */
10899 lookup_filename (main_input_filename);
10901 /* Allocate the initial hunk of the decl_die_table. */
10903 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
10904 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
10905 decl_die_table_in_use = 0;
10907 /* Allocate the initial hunk of the decl_scope_table. */
10909 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
10910 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
10911 decl_scope_depth = 0;
10913 /* Allocate the initial hunk of the abbrev_die_table. */
10915 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
10916 sizeof (dw_die_ref));
10917 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
10918 /* Zero-th entry is allocated, but unused */
10919 abbrev_die_table_in_use = 1;
10921 /* Allocate the initial hunk of the line_info_table. */
10923 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
10924 sizeof (dw_line_info_entry));
10925 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
10926 /* Zero-th entry is allocated, but unused */
10927 line_info_table_in_use = 1;
10929 /* Generate the initial DIE for the .debug section. Note that the (string)
10930 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
10931 will (typically) be a relative pathname and that this pathname should be
10932 taken as being relative to the directory from which the compiler was
10933 invoked when the given (base) source file was compiled. */
10934 comp_unit_die = gen_compile_unit_die (main_input_filename);
10936 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
10937 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
10939 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
10940 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
10941 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
10942 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
10944 strcpy (text_section_label, stripattributes (TEXT_SECTION));
10945 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
10946 DEBUG_INFO_SECTION_LABEL, 0);
10947 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
10948 DEBUG_LINE_SECTION_LABEL, 0);
10950 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
10951 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
10952 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
10954 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
10955 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
10957 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
10958 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
10959 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
10960 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
10963 /* Output stuff that dwarf requires at the end of every file,
10964 and generate the DWARF-2 debugging info. */
10967 dwarf2out_finish ()
10969 limbo_die_node *node, *next_node;
10972 /* Traverse the limbo die list, and add parent/child links. The only
10973 dies without parents that should be here are concrete instances of
10974 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
10975 For concrete instances, we can get the parent die from the abstract
10977 for (node = limbo_die_list; node; node = next_node)
10979 next_node = node->next;
10982 if (die->die_parent == NULL)
10984 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
10986 add_child_die (origin->die_parent, die);
10987 else if (die == comp_unit_die)
10994 limbo_die_list = NULL;
10996 /* Walk through the list of incomplete types again, trying once more to
10997 emit full debugging info for them. */
10998 retry_incomplete_types ();
11000 /* We need to reverse all the dies before break_out_includes, or
11001 we'll see the end of an include file before the beginning. */
11002 reverse_all_dies (comp_unit_die);
11004 /* Generate separate CUs for each of the include files we've seen.
11005 They will go into limbo_die_list. */
11006 if (flag_eliminate_dwarf2_dups)
11007 break_out_includes (comp_unit_die);
11009 /* Traverse the DIE's and add add sibling attributes to those DIE's
11010 that have children. */
11011 add_sibling_attributes (comp_unit_die);
11012 for (node = limbo_die_list; node; node = node->next)
11013 add_sibling_attributes (node->die);
11015 /* Output a terminator label for the .text section. */
11016 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11017 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11020 /* Output a terminator label for the .data section. */
11021 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11022 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11024 /* Output a terminator label for the .bss section. */
11025 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11026 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11029 /* Output the source line correspondence table. */
11030 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
11032 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11034 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11035 output_line_info ();
11038 /* We can only use the low/high_pc attributes if all of the code
11040 if (separate_line_info_table_in_use == 0)
11042 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11043 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11046 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11047 debug_line_section_label);
11050 #if 0 /* unimplemented */
11051 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11052 add_AT_unsigned (die, DW_AT_macro_info, 0);
11055 /* Output all of the compilation units. We put the main one last so that
11056 the offsets are available to output_pubnames. */
11057 for (node = limbo_die_list; node; node = node->next)
11058 output_comp_unit (node->die);
11059 output_comp_unit (comp_unit_die);
11061 /* Output the abbreviation table. */
11062 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11063 output_abbrev_section ();
11065 if (pubname_table_in_use)
11067 /* Output public names table. */
11068 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11069 output_pubnames ();
11072 /* We only put functions in the arange table, so don't write it out if
11073 we don't have any. */
11074 if (fde_table_in_use)
11076 /* Output the address range information. */
11077 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11081 #endif /* DWARF2_DEBUGGING_INFO */