1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Emit .debug_line header even when there are no functions, since
27 the file numbers are used by .debug_info. Alternately, leave
28 out locations for types and decls.
29 Avoid talking about ctors and op= for PODs.
30 Factor out common prologue sequences into multiple CIEs. */
32 /* The first part of this file deals with the DWARF 2 frame unwind
33 information, which is also used by the GCC efficient exception handling
34 mechanism. The second part, controlled only by an #ifdef
35 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
43 #include "hard-reg-set.h"
45 #include "insn-config.h"
52 #include "dwarf2out.h"
53 #include "dwarf2asm.h"
59 #include "diagnostic.h"
62 /* DWARF2 Abbreviation Glossary:
63 CFA = Canonical Frame Address
64 a fixed address on the stack which identifies a call frame.
65 We define it to be the value of SP just before the call insn.
66 The CFA register and offset, which may change during the course
67 of the function, are used to calculate its value at runtime.
68 CFI = Call Frame Instruction
69 an instruction for the DWARF2 abstract machine
70 CIE = Common Information Entry
71 information describing information common to one or more FDEs
72 DIE = Debugging Information Entry
73 FDE = Frame Description Entry
74 information describing the stack call frame, in particular,
75 how to restore registers
77 DW_CFA_... = DWARF2 CFA call frame instruction
78 DW_TAG_... = DWARF2 DIE tag */
80 /* Decide whether we want to emit frame unwind information for the current
86 return (write_symbols == DWARF2_DEBUG
87 #ifdef DWARF2_FRAME_INFO
90 #ifdef DWARF2_UNWIND_INFO
92 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
97 /* The number of the current function definition for which debugging
98 information is being generated. These numbers range from 1 up to the
99 maximum number of function definitions contained within the current
100 compilation unit. These numbers are used to create unique label id's
101 unique to each function definition. */
102 unsigned current_funcdef_number = 0;
104 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
106 /* How to start an assembler comment. */
107 #ifndef ASM_COMMENT_START
108 #define ASM_COMMENT_START ";#"
111 typedef struct dw_cfi_struct *dw_cfi_ref;
112 typedef struct dw_fde_struct *dw_fde_ref;
113 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
115 /* Call frames are described using a sequence of Call Frame
116 Information instructions. The register number, offset
117 and address fields are provided as possible operands;
118 their use is selected by the opcode field. */
120 typedef union dw_cfi_oprnd_struct
122 unsigned long dw_cfi_reg_num;
123 long int dw_cfi_offset;
124 const char *dw_cfi_addr;
125 struct dw_loc_descr_struct *dw_cfi_loc;
129 typedef struct dw_cfi_struct
131 dw_cfi_ref dw_cfi_next;
132 enum dwarf_call_frame_info dw_cfi_opc;
133 dw_cfi_oprnd dw_cfi_oprnd1;
134 dw_cfi_oprnd dw_cfi_oprnd2;
138 /* This is how we define the location of the CFA. We use to handle it
139 as REG + OFFSET all the time, but now it can be more complex.
140 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
141 Instead of passing around REG and OFFSET, we pass a copy
142 of this structure. */
143 typedef struct cfa_loc
148 int indirect; /* 1 if CFA is accessed via a dereference. */
151 /* All call frame descriptions (FDE's) in the GCC generated DWARF
152 refer to a single Common Information Entry (CIE), defined at
153 the beginning of the .debug_frame section. This used of a single
154 CIE obviates the need to keep track of multiple CIE's
155 in the DWARF generation routines below. */
157 typedef struct dw_fde_struct
159 const char *dw_fde_begin;
160 const char *dw_fde_current_label;
161 const char *dw_fde_end;
162 dw_cfi_ref dw_fde_cfi;
163 unsigned funcdef_number;
164 unsigned nothrow : 1;
165 unsigned uses_eh_lsda : 1;
169 /* Maximum size (in bytes) of an artificially generated label. */
170 #define MAX_ARTIFICIAL_LABEL_BYTES 30
172 /* The size of the target's pointer type. */
174 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
177 /* The size of addresses as they appear in the Dwarf 2 data.
178 Some architectures use word addresses to refer to code locations,
179 but Dwarf 2 info always uses byte addresses. On such machines,
180 Dwarf 2 addresses need to be larger than the architecture's
182 #ifndef DWARF2_ADDR_SIZE
183 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
186 /* The size in bytes of a DWARF field indicating an offset or length
187 relative to a debug info section, specified to be 4 bytes in the
188 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
191 #ifndef DWARF_OFFSET_SIZE
192 #define DWARF_OFFSET_SIZE 4
195 #define DWARF_VERSION 2
197 /* Round SIZE up to the nearest BOUNDARY. */
198 #define DWARF_ROUND(SIZE,BOUNDARY) \
199 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
201 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
202 #ifndef DWARF_CIE_DATA_ALIGNMENT
203 #ifdef STACK_GROWS_DOWNWARD
204 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
206 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
208 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
210 /* A pointer to the base of a table that contains frame description
211 information for each routine. */
212 static dw_fde_ref fde_table;
214 /* Number of elements currently allocated for fde_table. */
215 static unsigned fde_table_allocated;
217 /* Number of elements in fde_table currently in use. */
218 static unsigned fde_table_in_use;
220 /* Size (in elements) of increments by which we may expand the
222 #define FDE_TABLE_INCREMENT 256
224 /* A list of call frame insns for the CIE. */
225 static dw_cfi_ref cie_cfi_head;
227 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
228 attribute that accelerates the lookup of the FDE associated
229 with the subprogram. This variable holds the table index of the FDE
230 associated with the current function (body) definition. */
231 static unsigned current_funcdef_fde;
233 /* Forward declarations for functions defined in this file. */
235 static void dwarf2out_init PARAMS ((FILE *, const char *));
236 static void dwarf2out_finish PARAMS ((FILE *, const char *));
237 static char *stripattributes PARAMS ((const char *));
238 static const char *dwarf_cfi_name PARAMS ((unsigned));
239 static dw_cfi_ref new_cfi PARAMS ((void));
240 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
241 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
242 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
243 static void lookup_cfa PARAMS ((dw_cfa_location *));
244 static void reg_save PARAMS ((const char *, unsigned,
246 static void initial_return_save PARAMS ((rtx));
247 static long stack_adjust_offset PARAMS ((rtx));
248 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
249 static void output_call_frame_info PARAMS ((int));
250 static void dwarf2out_stack_adjust PARAMS ((rtx));
251 static void queue_reg_save PARAMS ((const char *, rtx, long));
252 static void flush_queued_reg_saves PARAMS ((void));
253 static bool clobbers_queued_reg_save PARAMS ((rtx));
254 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
256 /* Support for complex CFA locations. */
257 static void output_cfa_loc PARAMS ((dw_cfi_ref));
258 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
259 struct dw_loc_descr_struct *));
260 static struct dw_loc_descr_struct *build_cfa_loc
261 PARAMS ((dw_cfa_location *));
262 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
264 /* How to start an assembler comment. */
265 #ifndef ASM_COMMENT_START
266 #define ASM_COMMENT_START ";#"
269 /* Data and reference forms for relocatable data. */
270 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
271 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
273 /* Pseudo-op for defining a new section. */
274 #ifndef SECTION_ASM_OP
275 #define SECTION_ASM_OP "\t.section\t"
278 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
279 print the SECTION_ASM_OP and the section name. The default here works for
280 almost all svr4 assemblers, except for the sparc, where the section name
281 must be enclosed in double quotes. (See sparcv4.h). */
282 #ifndef SECTION_FORMAT
283 #ifdef PUSHSECTION_FORMAT
284 #define SECTION_FORMAT PUSHSECTION_FORMAT
286 #define SECTION_FORMAT "%s%s\n"
290 #ifndef DEBUG_FRAME_SECTION
291 #define DEBUG_FRAME_SECTION ".debug_frame"
294 #ifndef FUNC_BEGIN_LABEL
295 #define FUNC_BEGIN_LABEL "LFB"
297 #ifndef FUNC_END_LABEL
298 #define FUNC_END_LABEL "LFE"
300 #define CIE_AFTER_SIZE_LABEL "LSCIE"
301 #define CIE_END_LABEL "LECIE"
302 #define CIE_LENGTH_LABEL "LLCIE"
303 #define FDE_LABEL "LSFDE"
304 #define FDE_AFTER_SIZE_LABEL "LASFDE"
305 #define FDE_END_LABEL "LEFDE"
306 #define FDE_LENGTH_LABEL "LLFDE"
307 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
308 #define LINE_NUMBER_END_LABEL "LELT"
309 #define LN_PROLOG_AS_LABEL "LASLTP"
310 #define LN_PROLOG_END_LABEL "LELTP"
311 #define DIE_LABEL_PREFIX "DW"
313 /* Definitions of defaults for various types of primitive assembly language
314 output operations. These may be overridden from within the tm.h file,
315 but typically, that is unnecessary. */
317 #ifndef ASM_OUTPUT_SECTION
318 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
319 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
323 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
324 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
326 fprintf (FILE, "%s", SET_ASM_OP); \
327 assemble_name (FILE, SY); \
329 assemble_name (FILE, HI); \
331 assemble_name (FILE, LO); \
334 #endif /* SET_ASM_OP */
336 /* The DWARF 2 CFA column which tracks the return address. Normally this
337 is the column for PC, or the first column after all of the hard
339 #ifndef DWARF_FRAME_RETURN_COLUMN
341 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
343 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
347 /* The mapping from gcc register number to DWARF 2 CFA column number. By
348 default, we just provide columns for all registers. */
349 #ifndef DWARF_FRAME_REGNUM
350 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
353 /* Hook used by __throw. */
356 expand_builtin_dwarf_fp_regnum ()
358 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
361 /* The offset from the incoming value of %sp to the top of the stack frame
362 for the current function. */
363 #ifndef INCOMING_FRAME_SP_OFFSET
364 #define INCOMING_FRAME_SP_OFFSET 0
367 /* The target debug structure. */
369 struct gcc_debug_hooks dwarf2_debug_hooks =
375 /* Return a pointer to a copy of the section string name S with all
376 attributes stripped off, and an asterisk prepended (for assemble_name). */
382 char *stripped = xmalloc (strlen (s) + 2);
387 while (*s && *s != ',')
394 /* Generate code to initialize the register size table. */
397 expand_builtin_init_dwarf_reg_sizes (address)
401 enum machine_mode mode = TYPE_MODE (char_type_node);
402 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
403 rtx mem = gen_rtx_MEM (mode, addr);
405 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
407 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
408 int size = GET_MODE_SIZE (reg_raw_mode[i]);
413 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
417 /* Convert a DWARF call frame info. operation to its string name */
420 dwarf_cfi_name (cfi_opc)
421 register unsigned cfi_opc;
425 case DW_CFA_advance_loc:
426 return "DW_CFA_advance_loc";
428 return "DW_CFA_offset";
430 return "DW_CFA_restore";
434 return "DW_CFA_set_loc";
435 case DW_CFA_advance_loc1:
436 return "DW_CFA_advance_loc1";
437 case DW_CFA_advance_loc2:
438 return "DW_CFA_advance_loc2";
439 case DW_CFA_advance_loc4:
440 return "DW_CFA_advance_loc4";
441 case DW_CFA_offset_extended:
442 return "DW_CFA_offset_extended";
443 case DW_CFA_restore_extended:
444 return "DW_CFA_restore_extended";
445 case DW_CFA_undefined:
446 return "DW_CFA_undefined";
447 case DW_CFA_same_value:
448 return "DW_CFA_same_value";
449 case DW_CFA_register:
450 return "DW_CFA_register";
451 case DW_CFA_remember_state:
452 return "DW_CFA_remember_state";
453 case DW_CFA_restore_state:
454 return "DW_CFA_restore_state";
456 return "DW_CFA_def_cfa";
457 case DW_CFA_def_cfa_register:
458 return "DW_CFA_def_cfa_register";
459 case DW_CFA_def_cfa_offset:
460 return "DW_CFA_def_cfa_offset";
461 case DW_CFA_def_cfa_expression:
462 return "DW_CFA_def_cfa_expression";
464 /* SGI/MIPS specific */
465 case DW_CFA_MIPS_advance_loc8:
466 return "DW_CFA_MIPS_advance_loc8";
469 case DW_CFA_GNU_window_save:
470 return "DW_CFA_GNU_window_save";
471 case DW_CFA_GNU_args_size:
472 return "DW_CFA_GNU_args_size";
473 case DW_CFA_GNU_negative_offset_extended:
474 return "DW_CFA_GNU_negative_offset_extended";
477 return "DW_CFA_<unknown>";
481 /* Return a pointer to a newly allocated Call Frame Instruction. */
483 static inline dw_cfi_ref
486 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
488 cfi->dw_cfi_next = NULL;
489 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
490 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
495 /* Add a Call Frame Instruction to list of instructions. */
498 add_cfi (list_head, cfi)
499 register dw_cfi_ref *list_head;
500 register dw_cfi_ref cfi;
502 register dw_cfi_ref *p;
504 /* Find the end of the chain. */
505 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
511 /* Generate a new label for the CFI info to refer to. */
514 dwarf2out_cfi_label ()
516 static char label[20];
517 static unsigned long label_num = 0;
519 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
520 ASM_OUTPUT_LABEL (asm_out_file, label);
525 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
526 or to the CIE if LABEL is NULL. */
529 add_fde_cfi (label, cfi)
530 register const char *label;
531 register dw_cfi_ref cfi;
535 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
538 label = dwarf2out_cfi_label ();
540 if (fde->dw_fde_current_label == NULL
541 || strcmp (label, fde->dw_fde_current_label) != 0)
543 register dw_cfi_ref xcfi;
545 fde->dw_fde_current_label = label = xstrdup (label);
547 /* Set the location counter to the new label. */
549 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
550 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
551 add_cfi (&fde->dw_fde_cfi, xcfi);
554 add_cfi (&fde->dw_fde_cfi, cfi);
558 add_cfi (&cie_cfi_head, cfi);
561 /* Subroutine of lookup_cfa. */
564 lookup_cfa_1 (cfi, loc)
565 register dw_cfi_ref cfi;
566 register dw_cfa_location *loc;
568 switch (cfi->dw_cfi_opc)
570 case DW_CFA_def_cfa_offset:
571 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
573 case DW_CFA_def_cfa_register:
574 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
577 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
578 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
580 case DW_CFA_def_cfa_expression:
581 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
588 /* Find the previous value for the CFA. */
592 register dw_cfa_location *loc;
594 register dw_cfi_ref cfi;
596 loc->reg = (unsigned long) -1;
599 loc->base_offset = 0;
601 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
602 lookup_cfa_1 (cfi, loc);
604 if (fde_table_in_use)
606 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
607 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
608 lookup_cfa_1 (cfi, loc);
612 /* The current rule for calculating the DWARF2 canonical frame address. */
613 static dw_cfa_location cfa;
615 /* The register used for saving registers to the stack, and its offset
617 static dw_cfa_location cfa_store;
619 /* The running total of the size of arguments pushed onto the stack. */
620 static long args_size;
622 /* The last args_size we actually output. */
623 static long old_args_size;
625 /* Entry point to update the canonical frame address (CFA).
626 LABEL is passed to add_fde_cfi. The value of CFA is now to be
627 calculated from REG+OFFSET. */
630 dwarf2out_def_cfa (label, reg, offset)
631 register const char *label;
640 def_cfa_1 (label, &loc);
643 /* This routine does the actual work. The CFA is now calculated from
644 the dw_cfa_location structure. */
646 def_cfa_1 (label, loc_p)
647 register const char *label;
648 dw_cfa_location *loc_p;
650 register dw_cfi_ref cfi;
651 dw_cfa_location old_cfa, loc;
656 if (cfa_store.reg == loc.reg && loc.indirect == 0)
657 cfa_store.offset = loc.offset;
659 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
660 lookup_cfa (&old_cfa);
662 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
663 loc.indirect == old_cfa.indirect)
665 if (loc.indirect == 0
666 || loc.base_offset == old_cfa.base_offset)
667 /* Nothing changed so no need to issue any call frame
674 if (loc.reg == old_cfa.reg && !loc.indirect)
676 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
677 indicating the CFA register did not change but the offset
679 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
680 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
683 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
684 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
687 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
688 indicating the CFA register has changed to <register> but the
689 offset has not changed. */
690 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
691 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
695 else if (loc.indirect == 0)
697 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
698 indicating the CFA register has changed to <register> with
699 the specified offset. */
700 cfi->dw_cfi_opc = DW_CFA_def_cfa;
701 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
702 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
706 /* Construct a DW_CFA_def_cfa_expression instruction to
707 calculate the CFA using a full location expression since no
708 register-offset pair is available. */
709 struct dw_loc_descr_struct *loc_list;
710 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
711 loc_list = build_cfa_loc (&loc);
712 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
715 add_fde_cfi (label, cfi);
718 /* Add the CFI for saving a register. REG is the CFA column number.
719 LABEL is passed to add_fde_cfi.
720 If SREG is -1, the register is saved at OFFSET from the CFA;
721 otherwise it is saved in SREG. */
724 reg_save (label, reg, sreg, offset)
725 register const char *label;
726 register unsigned reg;
727 register unsigned sreg;
728 register long offset;
730 register dw_cfi_ref cfi = new_cfi ();
732 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
734 /* The following comparison is correct. -1 is used to indicate that
735 the value isn't a register number. */
736 if (sreg == (unsigned int) -1)
739 /* The register number won't fit in 6 bits, so we have to use
741 cfi->dw_cfi_opc = DW_CFA_offset_extended;
743 cfi->dw_cfi_opc = DW_CFA_offset;
745 #ifdef ENABLE_CHECKING
747 /* If we get an offset that is not a multiple of
748 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
749 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
751 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
753 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
757 offset /= DWARF_CIE_DATA_ALIGNMENT;
760 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
763 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
765 else if (sreg == reg)
766 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
770 cfi->dw_cfi_opc = DW_CFA_register;
771 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
774 add_fde_cfi (label, cfi);
777 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
778 This CFI tells the unwinder that it needs to restore the window registers
779 from the previous frame's window save area.
781 ??? Perhaps we should note in the CIE where windows are saved (instead of
782 assuming 0(cfa)) and what registers are in the window. */
785 dwarf2out_window_save (label)
786 register const char *label;
788 register dw_cfi_ref cfi = new_cfi ();
789 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
790 add_fde_cfi (label, cfi);
793 /* Add a CFI to update the running total of the size of arguments
794 pushed onto the stack. */
797 dwarf2out_args_size (label, size)
801 register dw_cfi_ref cfi;
803 if (size == old_args_size)
805 old_args_size = size;
808 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
809 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
810 add_fde_cfi (label, cfi);
813 /* Entry point for saving a register to the stack. REG is the GCC register
814 number. LABEL and OFFSET are passed to reg_save. */
817 dwarf2out_reg_save (label, reg, offset)
818 register const char *label;
819 register unsigned reg;
820 register long offset;
822 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
825 /* Entry point for saving the return address in the stack.
826 LABEL and OFFSET are passed to reg_save. */
829 dwarf2out_return_save (label, offset)
830 register const char *label;
831 register long offset;
833 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
836 /* Entry point for saving the return address in a register.
837 LABEL and SREG are passed to reg_save. */
840 dwarf2out_return_reg (label, sreg)
841 register const char *label;
842 register unsigned sreg;
844 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
847 /* Record the initial position of the return address. RTL is
848 INCOMING_RETURN_ADDR_RTX. */
851 initial_return_save (rtl)
854 unsigned int reg = (unsigned int) -1;
857 switch (GET_CODE (rtl))
860 /* RA is in a register. */
861 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
864 /* RA is on the stack. */
866 switch (GET_CODE (rtl))
869 if (REGNO (rtl) != STACK_POINTER_REGNUM)
874 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
876 offset = INTVAL (XEXP (rtl, 1));
879 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
881 offset = -INTVAL (XEXP (rtl, 1));
888 /* The return address is at some offset from any value we can
889 actually load. For instance, on the SPARC it is in %i7+8. Just
890 ignore the offset for now; it doesn't matter for unwinding frames. */
891 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
893 initial_return_save (XEXP (rtl, 0));
899 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
902 /* Given a SET, calculate the amount of stack adjustment it
906 stack_adjust_offset (pattern)
909 rtx src = SET_SRC (pattern);
910 rtx dest = SET_DEST (pattern);
914 if (dest == stack_pointer_rtx)
916 /* (set (reg sp) (plus (reg sp) (const_int))) */
917 code = GET_CODE (src);
918 if (! (code == PLUS || code == MINUS)
919 || XEXP (src, 0) != stack_pointer_rtx
920 || GET_CODE (XEXP (src, 1)) != CONST_INT)
923 offset = INTVAL (XEXP (src, 1));
925 else if (GET_CODE (dest) == MEM)
927 /* (set (mem (pre_dec (reg sp))) (foo)) */
928 src = XEXP (dest, 0);
929 code = GET_CODE (src);
931 if (! (code == PRE_DEC || code == PRE_INC
932 || code == PRE_MODIFY)
933 || XEXP (src, 0) != stack_pointer_rtx)
936 if (code == PRE_MODIFY)
938 rtx val = XEXP (XEXP (src, 1), 1);
939 /* We handle only adjustments by constant amount. */
940 if (GET_CODE (XEXP (src, 1)) != PLUS ||
941 GET_CODE (val) != CONST_INT)
943 offset = -INTVAL (val);
945 else offset = GET_MODE_SIZE (GET_MODE (dest));
950 if (code == PLUS || code == PRE_INC)
956 /* Check INSN to see if it looks like a push or a stack adjustment, and
957 make a note of it if it does. EH uses this information to find out how
958 much extra space it needs to pop off the stack. */
961 dwarf2out_stack_adjust (insn)
967 if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN)
969 /* Extract the size of the args from the CALL rtx itself. */
971 insn = PATTERN (insn);
972 if (GET_CODE (insn) == PARALLEL)
973 insn = XVECEXP (insn, 0, 0);
974 if (GET_CODE (insn) == SET)
975 insn = SET_SRC (insn);
976 if (GET_CODE (insn) != CALL)
978 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
982 /* If only calls can throw, and we have a frame pointer,
983 save up adjustments until we see the CALL_INSN. */
984 else if (! flag_non_call_exceptions
985 && cfa.reg != STACK_POINTER_REGNUM)
988 if (GET_CODE (insn) == BARRIER)
990 /* When we see a BARRIER, we know to reset args_size to 0. Usually
991 the compiler will have already emitted a stack adjustment, but
992 doesn't bother for calls to noreturn functions. */
993 #ifdef STACK_GROWS_DOWNWARD
999 else if (GET_CODE (PATTERN (insn)) == SET)
1001 offset = stack_adjust_offset (PATTERN (insn));
1003 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1004 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1006 /* There may be stack adjustments inside compound insns. Search
1011 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1013 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1014 if (GET_CODE (pattern) == SET)
1015 offset += stack_adjust_offset (pattern);
1024 if (cfa.reg == STACK_POINTER_REGNUM)
1025 cfa.offset += offset;
1027 #ifndef STACK_GROWS_DOWNWARD
1030 args_size += offset;
1034 label = dwarf2out_cfi_label ();
1035 def_cfa_1 (label, &cfa);
1036 dwarf2out_args_size (label, args_size);
1039 /* We delay emitting a register save until either (a) we reach the end
1040 of the prologue or (b) the register is clobbered. This clusters
1041 register saves so that there are fewer pc advances. */
1043 struct queued_reg_save
1045 struct queued_reg_save *next;
1050 static struct queued_reg_save *queued_reg_saves;
1051 static const char *last_reg_save_label;
1054 queue_reg_save (label, reg, offset)
1059 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1061 q->next = queued_reg_saves;
1063 q->cfa_offset = offset;
1064 queued_reg_saves = q;
1066 last_reg_save_label = label;
1070 flush_queued_reg_saves ()
1072 struct queued_reg_save *q, *next;
1074 for (q = queued_reg_saves; q ; q = next)
1076 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1081 queued_reg_saves = NULL;
1082 last_reg_save_label = NULL;
1086 clobbers_queued_reg_save (insn)
1089 struct queued_reg_save *q;
1091 for (q = queued_reg_saves; q ; q = q->next)
1092 if (modified_in_p (q->reg, insn))
1099 /* A temporary register holding an integral value used in adjusting SP
1100 or setting up the store_reg. The "offset" field holds the integer
1101 value, not an offset. */
1102 static dw_cfa_location cfa_temp;
1104 /* Record call frame debugging information for an expression EXPR,
1105 which either sets SP or FP (adjusting how we calculate the frame
1106 address) or saves a register to the stack. LABEL indicates the
1109 This function encodes a state machine mapping rtxes to actions on
1110 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1111 users need not read the source code.
1113 The High-Level Picture
1115 Changes in the register we use to calculate the CFA: Currently we
1116 assume that if you copy the CFA register into another register, we
1117 should take the other one as the new CFA register; this seems to
1118 work pretty well. If it's wrong for some target, it's simple
1119 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1121 Changes in the register we use for saving registers to the stack:
1122 This is usually SP, but not always. Again, we deduce that if you
1123 copy SP into another register (and SP is not the CFA register),
1124 then the new register is the one we will be using for register
1125 saves. This also seems to work.
1127 Register saves: There's not much guesswork about this one; if
1128 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1129 register save, and the register used to calculate the destination
1130 had better be the one we think we're using for this purpose.
1132 Except: If the register being saved is the CFA register, and the
1133 offset is non-zero, we are saving the CFA, so we assume we have to
1134 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1135 the intent is to save the value of SP from the previous frame.
1137 Invariants / Summaries of Rules
1139 cfa current rule for calculating the CFA. It usually
1140 consists of a register and an offset.
1141 cfa_store register used by prologue code to save things to the stack
1142 cfa_store.offset is the offset from the value of
1143 cfa_store.reg to the actual CFA
1144 cfa_temp register holding an integral value. cfa_temp.offset
1145 stores the value, which will be used to adjust the
1146 stack pointer. cfa_temp is also used like cfa_store,
1147 to track stores to the stack via fp or a temp reg.
1149 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1150 with cfa.reg as the first operand changes the cfa.reg and its
1151 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1154 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1155 expression yielding a constant. This sets cfa_temp.reg
1156 and cfa_temp.offset.
1158 Rule 5: Create a new register cfa_store used to save items to the
1161 Rules 10-14: Save a register to the stack. Define offset as the
1162 difference of the original location and cfa_store's
1163 location (or cfa_temp's location if cfa_temp is used).
1167 "{a,b}" indicates a choice of a xor b.
1168 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1171 (set <reg1> <reg2>:cfa.reg)
1172 effects: cfa.reg = <reg1>
1173 cfa.offset unchanged
1174 cfa_temp.reg = <reg1>
1175 cfa_temp.offset = cfa.offset
1178 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1179 effects: cfa.reg = sp if fp used
1180 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1181 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1182 if cfa_store.reg==sp
1185 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1186 effects: cfa.reg = fp
1187 cfa_offset += +/- <const_int>
1190 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1191 constraints: <reg1> != fp
1193 effects: cfa.reg = <reg1>
1194 cfa_temp.reg = <reg1>
1195 cfa_temp.offset = cfa.offset
1198 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1199 constraints: <reg1> != fp
1201 effects: cfa_store.reg = <reg1>
1202 cfa_store.offset = cfa.offset - cfa_temp.offset
1205 (set <reg> <const_int>)
1206 effects: cfa_temp.reg = <reg>
1207 cfa_temp.offset = <const_int>
1210 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1211 effects: cfa_temp.reg = <reg1>
1212 cfa_temp.offset |= <const_int>
1215 (set <reg> (high <exp>))
1219 (set <reg> (lo_sum <exp> <const_int>))
1220 effects: cfa_temp.reg = <reg>
1221 cfa_temp.offset = <const_int>
1224 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1225 effects: cfa_store.offset -= <const_int>
1226 cfa.offset = cfa_store.offset if cfa.reg == sp
1228 cfa.base_offset = -cfa_store.offset
1231 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1232 effects: cfa_store.offset += -/+ mode_size(mem)
1233 cfa.offset = cfa_store.offset if cfa.reg == sp
1235 cfa.base_offset = -cfa_store.offset
1238 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>)
1239 effects: cfa.reg = <reg1>
1240 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1243 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1244 effects: cfa.reg = <reg1>
1245 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1248 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1249 effects: cfa.reg = <reg1>
1250 cfa.base_offset = -cfa_temp.offset
1251 cfa_temp.offset -= mode_size(mem) */
1254 dwarf2out_frame_debug_expr (expr, label)
1261 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1262 the PARALLEL independently. The first element is always processed if
1263 it is a SET. This is for backward compatibility. Other elements
1264 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1265 flag is set in them. */
1267 if (GET_CODE (expr) == PARALLEL
1268 || GET_CODE (expr) == SEQUENCE)
1271 int limit = XVECLEN (expr, 0);
1273 for (par_index = 0; par_index < limit; par_index++)
1275 rtx x = XVECEXP (expr, 0, par_index);
1277 if (GET_CODE (x) == SET &&
1278 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1279 dwarf2out_frame_debug_expr (x, label);
1284 if (GET_CODE (expr) != SET)
1287 src = SET_SRC (expr);
1288 dest = SET_DEST (expr);
1290 switch (GET_CODE (dest))
1294 /* Update the CFA rule wrt SP or FP. Make sure src is
1295 relative to the current CFA register. */
1296 switch (GET_CODE (src))
1298 /* Setting FP from SP. */
1300 if (cfa.reg == (unsigned) REGNO (src))
1306 /* We used to require that dest be either SP or FP, but the
1307 ARM copies SP to a temporary register, and from there to
1308 FP. So we just rely on the backends to only set
1309 RTX_FRAME_RELATED_P on appropriate insns. */
1310 cfa.reg = REGNO (dest);
1311 cfa_temp.reg = cfa.reg;
1312 cfa_temp.offset = cfa.offset;
1318 if (dest == stack_pointer_rtx)
1322 switch (GET_CODE (XEXP (src, 1)))
1325 offset = INTVAL (XEXP (src, 1));
1328 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1330 offset = cfa_temp.offset;
1336 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1338 /* Restoring SP from FP in the epilogue. */
1339 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1341 cfa.reg = STACK_POINTER_REGNUM;
1343 else if (GET_CODE (src) == LO_SUM)
1344 /* Assume we've set the source reg of the LO_SUM from sp. */
1346 else if (XEXP (src, 0) != stack_pointer_rtx)
1349 if (GET_CODE (src) != MINUS)
1351 if (cfa.reg == STACK_POINTER_REGNUM)
1352 cfa.offset += offset;
1353 if (cfa_store.reg == STACK_POINTER_REGNUM)
1354 cfa_store.offset += offset;
1356 else if (dest == hard_frame_pointer_rtx)
1359 /* Either setting the FP from an offset of the SP,
1360 or adjusting the FP */
1361 if (! frame_pointer_needed)
1364 if (GET_CODE (XEXP (src, 0)) == REG
1365 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1366 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1368 offset = INTVAL (XEXP (src, 1));
1369 if (GET_CODE (src) != MINUS)
1371 cfa.offset += offset;
1372 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1379 if (GET_CODE (src) == MINUS)
1383 if (GET_CODE (XEXP (src, 0)) == REG
1384 && REGNO (XEXP (src, 0)) == cfa.reg
1385 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1387 /* Setting a temporary CFA register that will be copied
1388 into the FP later on. */
1389 offset = - INTVAL (XEXP (src, 1));
1390 cfa.offset += offset;
1391 cfa.reg = REGNO (dest);
1392 /* Or used to save regs to the stack. */
1393 cfa_temp.reg = cfa.reg;
1394 cfa_temp.offset = cfa.offset;
1397 else if (GET_CODE (XEXP (src, 0)) == REG
1398 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1399 && XEXP (src, 1) == stack_pointer_rtx)
1401 /* Setting a scratch register that we will use instead
1402 of SP for saving registers to the stack. */
1403 if (cfa.reg != STACK_POINTER_REGNUM)
1405 cfa_store.reg = REGNO (dest);
1406 cfa_store.offset = cfa.offset - cfa_temp.offset;
1409 else if (GET_CODE (src) == LO_SUM
1410 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1412 cfa_temp.reg = REGNO (dest);
1413 cfa_temp.offset = INTVAL (XEXP (src, 1));
1422 cfa_temp.reg = REGNO (dest);
1423 cfa_temp.offset = INTVAL (src);
1428 if (GET_CODE (XEXP (src, 0)) != REG
1429 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1430 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1432 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1433 cfa_temp.reg = REGNO (dest);
1434 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1437 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1438 which will fill in all of the bits. */
1446 def_cfa_1 (label, &cfa);
1450 if (GET_CODE (src) != REG)
1453 /* Saving a register to the stack. Make sure dest is relative to the
1455 switch (GET_CODE (XEXP (dest, 0)))
1460 /* We can't handle variable size modifications. */
1461 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1463 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1465 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1466 || cfa_store.reg != STACK_POINTER_REGNUM)
1468 cfa_store.offset += offset;
1469 if (cfa.reg == STACK_POINTER_REGNUM)
1470 cfa.offset = cfa_store.offset;
1472 offset = -cfa_store.offset;
1477 offset = GET_MODE_SIZE (GET_MODE (dest));
1478 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1481 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1482 || cfa_store.reg != STACK_POINTER_REGNUM)
1484 cfa_store.offset += offset;
1485 if (cfa.reg == STACK_POINTER_REGNUM)
1486 cfa.offset = cfa_store.offset;
1488 offset = -cfa_store.offset;
1492 /* With an offset. */
1496 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1498 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1499 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1502 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1503 offset -= cfa_store.offset;
1504 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1505 offset -= cfa_temp.offset;
1511 /* Without an offset. */
1513 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1514 offset = -cfa_store.offset;
1515 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1516 offset = -cfa_temp.offset;
1523 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1525 offset = -cfa_temp.offset;
1526 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1533 if (REGNO (src) != STACK_POINTER_REGNUM
1534 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1535 && (unsigned) REGNO (src) == cfa.reg)
1537 /* We're storing the current CFA reg into the stack. */
1539 if (cfa.offset == 0)
1541 /* If the source register is exactly the CFA, assume
1542 we're saving SP like any other register; this happens
1545 def_cfa_1 (label, &cfa);
1546 queue_reg_save (label, stack_pointer_rtx, offset);
1551 /* Otherwise, we'll need to look in the stack to
1552 calculate the CFA. */
1554 rtx x = XEXP (dest, 0);
1555 if (GET_CODE (x) != REG)
1557 if (GET_CODE (x) != REG)
1559 cfa.reg = (unsigned) REGNO (x);
1560 cfa.base_offset = offset;
1562 def_cfa_1 (label, &cfa);
1567 def_cfa_1 (label, &cfa);
1568 queue_reg_save (label, src, offset);
1576 /* Record call frame debugging information for INSN, which either
1577 sets SP or FP (adjusting how we calculate the frame address) or saves a
1578 register to the stack. If INSN is NULL_RTX, initialize our state. */
1581 dwarf2out_frame_debug (insn)
1587 if (insn == NULL_RTX)
1589 /* Flush any queued register saves. */
1590 flush_queued_reg_saves ();
1592 /* Set up state for generating call frame debug info. */
1594 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1596 cfa.reg = STACK_POINTER_REGNUM;
1599 cfa_temp.offset = 0;
1603 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1604 flush_queued_reg_saves ();
1606 if (! RTX_FRAME_RELATED_P (insn))
1608 if (!ACCUMULATE_OUTGOING_ARGS)
1609 dwarf2out_stack_adjust (insn);
1613 label = dwarf2out_cfi_label ();
1615 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1617 insn = XEXP (src, 0);
1619 insn = PATTERN (insn);
1621 dwarf2out_frame_debug_expr (insn, label);
1624 /* Output a Call Frame Information opcode and its operand(s). */
1627 output_cfi (cfi, fde, for_eh)
1628 register dw_cfi_ref cfi;
1629 register dw_fde_ref fde;
1632 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1634 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1635 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1636 "DW_CFA_advance_loc 0x%lx",
1637 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1639 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1641 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1642 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1643 "DW_CFA_offset, column 0x%lx",
1644 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1645 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1647 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1649 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1650 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1651 "DW_CFA_restore, column 0x%lx",
1652 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1656 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1657 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1659 switch (cfi->dw_cfi_opc)
1661 case DW_CFA_set_loc:
1663 dw2_asm_output_encoded_addr_rtx (
1664 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1665 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1668 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1669 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1671 case DW_CFA_advance_loc1:
1672 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1673 fde->dw_fde_current_label, NULL);
1674 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1676 case DW_CFA_advance_loc2:
1677 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1678 fde->dw_fde_current_label, NULL);
1679 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1681 case DW_CFA_advance_loc4:
1682 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1683 fde->dw_fde_current_label, NULL);
1684 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1686 case DW_CFA_MIPS_advance_loc8:
1687 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1688 fde->dw_fde_current_label, NULL);
1689 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1691 case DW_CFA_offset_extended:
1692 case DW_CFA_GNU_negative_offset_extended:
1693 case DW_CFA_def_cfa:
1694 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1695 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1697 case DW_CFA_restore_extended:
1698 case DW_CFA_undefined:
1699 case DW_CFA_same_value:
1700 case DW_CFA_def_cfa_register:
1701 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1703 case DW_CFA_register:
1704 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1705 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1707 case DW_CFA_def_cfa_offset:
1708 case DW_CFA_GNU_args_size:
1709 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1711 case DW_CFA_GNU_window_save:
1713 case DW_CFA_def_cfa_expression:
1714 output_cfa_loc (cfi);
1722 /* Output the call frame information used to used to record information
1723 that relates to calculating the frame pointer, and records the
1724 location of saved registers. */
1727 output_call_frame_info (for_eh)
1730 register unsigned int i;
1731 register dw_fde_ref fde;
1732 register dw_cfi_ref cfi;
1733 char l1[20], l2[20];
1734 int any_lsda_needed = 0;
1735 char augmentation[6];
1736 int augmentation_size;
1737 int fde_encoding = DW_EH_PE_absptr;
1738 int per_encoding = DW_EH_PE_absptr;
1739 int lsda_encoding = DW_EH_PE_absptr;
1741 /* If we don't have any functions we'll want to unwind out of, don't
1742 emit any EH unwind information. */
1745 int any_eh_needed = 0;
1746 for (i = 0; i < fde_table_in_use; ++i)
1747 if (fde_table[i].uses_eh_lsda)
1748 any_eh_needed = any_lsda_needed = 1;
1749 else if (! fde_table[i].nothrow)
1752 if (! any_eh_needed)
1756 /* We're going to be generating comments, so turn on app. */
1762 #ifdef EH_FRAME_SECTION
1763 EH_FRAME_SECTION ();
1765 tree label = get_file_function_name ('F');
1767 force_data_section ();
1768 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1769 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1770 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1772 assemble_label ("__FRAME_BEGIN__");
1775 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_FRAME_SECTION);
1777 /* Output the CIE. */
1778 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1779 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1780 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1781 "Length of Common Information Entry");
1782 ASM_OUTPUT_LABEL (asm_out_file, l1);
1784 /* Now that the CIE pointer is PC-relative for EH,
1785 use 0 to identify the CIE. */
1786 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1787 (for_eh ? 0 : DW_CIE_ID),
1788 "CIE Identifier Tag");
1790 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1792 augmentation[0] = 0;
1793 augmentation_size = 0;
1799 z Indicates that a uleb128 is present to size the
1800 augmentation section.
1801 L Indicates the encoding (and thus presence) of
1802 an LSDA pointer in the FDE augmentation.
1803 R Indicates a non-default pointer encoding for
1805 P Indicates the presence of an encoding + language
1806 personality routine in the CIE augmentation. */
1808 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1809 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1810 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1812 p = augmentation + 1;
1813 if (eh_personality_libfunc)
1816 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1818 if (any_lsda_needed)
1821 augmentation_size += 1;
1823 if (fde_encoding != DW_EH_PE_absptr)
1826 augmentation_size += 1;
1828 if (p > augmentation + 1)
1830 augmentation[0] = 'z';
1834 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1835 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1837 int offset = ( 4 /* Length */
1839 + 1 /* CIE version */
1840 + strlen (augmentation) + 1 /* Augmentation */
1841 + size_of_uleb128 (1) /* Code alignment */
1842 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1844 + 1 /* Augmentation size */
1845 + 1 /* Personality encoding */ );
1846 int pad = -offset & (PTR_SIZE - 1);
1848 augmentation_size += pad;
1850 /* Augmentations should be small, so there's scarce need to
1851 iterate for a solution. Die if we exceed one uleb128 byte. */
1852 if (size_of_uleb128 (augmentation_size) != 1)
1856 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1858 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1860 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1861 "CIE Data Alignment Factor");
1863 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1865 if (augmentation[0])
1867 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1868 if (eh_personality_libfunc)
1870 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1871 eh_data_format_name (per_encoding));
1872 dw2_asm_output_encoded_addr_rtx (per_encoding,
1873 eh_personality_libfunc, NULL);
1875 if (any_lsda_needed)
1876 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1877 eh_data_format_name (lsda_encoding));
1878 if (fde_encoding != DW_EH_PE_absptr)
1879 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1880 eh_data_format_name (fde_encoding));
1883 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1884 output_cfi (cfi, NULL, for_eh);
1886 /* Pad the CIE out to an address sized boundary. */
1887 ASM_OUTPUT_ALIGN (asm_out_file,
1888 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1889 ASM_OUTPUT_LABEL (asm_out_file, l2);
1891 /* Loop through all of the FDE's. */
1892 for (i = 0; i < fde_table_in_use; ++i)
1894 fde = &fde_table[i];
1896 /* Don't emit EH unwind info for leaf functions that don't need it. */
1897 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1900 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1901 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1902 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1903 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1905 ASM_OUTPUT_LABEL (asm_out_file, l1);
1907 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1908 emits a target dependent sized offset when for_eh is not true.
1909 This inconsistency may confuse gdb. The only case where we need a
1910 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1911 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1912 though in order to be compatible with the dwarf_fde struct in frame.c.
1913 If the for_eh case is changed, then the struct in frame.c has
1914 to be adjusted appropriately. */
1916 dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset");
1918 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
1919 stripattributes (DEBUG_FRAME_SECTION),
1924 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1925 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1926 "FDE initial location");
1927 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1928 fde->dw_fde_end, fde->dw_fde_begin,
1929 "FDE address range");
1933 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1934 "FDE initial location");
1935 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1936 fde->dw_fde_end, fde->dw_fde_begin,
1937 "FDE address range");
1940 if (augmentation[0])
1942 if (any_lsda_needed)
1944 int size = size_of_encoded_value (lsda_encoding);
1946 if (lsda_encoding == DW_EH_PE_aligned)
1948 int offset = ( 4 /* Length */
1949 + 4 /* CIE offset */
1950 + 2 * size_of_encoded_value (fde_encoding)
1951 + 1 /* Augmentation size */ );
1952 int pad = -offset & (PTR_SIZE - 1);
1955 if (size_of_uleb128 (size) != 1)
1959 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1961 if (fde->uses_eh_lsda)
1963 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
1964 fde->funcdef_number);
1965 dw2_asm_output_encoded_addr_rtx (
1966 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
1967 "Language Specific Data Area");
1971 if (lsda_encoding == DW_EH_PE_aligned)
1972 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1973 dw2_asm_output_data (size_of_encoded_value (lsda_encoding),
1974 0, "Language Specific Data Area (none)");
1978 dw2_asm_output_data_uleb128 (0, "Augmentation size");
1981 /* Loop through the Call Frame Instructions associated with
1983 fde->dw_fde_current_label = fde->dw_fde_begin;
1984 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1985 output_cfi (cfi, fde, for_eh);
1987 /* Pad the FDE out to an address sized boundary. */
1988 ASM_OUTPUT_ALIGN (asm_out_file,
1989 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1990 ASM_OUTPUT_LABEL (asm_out_file, l2);
1993 #ifndef EH_FRAME_SECTION
1995 dw2_asm_output_data (4, 0, "End of Table");
1997 #ifdef MIPS_DEBUGGING_INFO
1998 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1999 get a value of 0. Putting .align 0 after the label fixes it. */
2000 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2003 /* Turn off app to make assembly quicker. */
2008 /* Output a marker (i.e. a label) for the beginning of a function, before
2012 dwarf2out_begin_prologue ()
2014 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2015 register dw_fde_ref fde;
2017 current_function_func_begin_label = 0;
2019 #ifdef IA64_UNWIND_INFO
2020 /* ??? current_function_func_begin_label is also used by except.c
2021 for call-site information. We must emit this label if it might
2023 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2024 && ! dwarf2out_do_frame ())
2027 if (! dwarf2out_do_frame ())
2031 ++current_funcdef_number;
2033 function_section (current_function_decl);
2034 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2035 current_funcdef_number);
2036 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2037 current_funcdef_number);
2038 current_function_func_begin_label = get_identifier (label);
2040 #ifdef IA64_UNWIND_INFO
2041 /* We can elide the fde allocation if we're not emitting debug info. */
2042 if (! dwarf2out_do_frame ())
2046 /* Expand the fde table if necessary. */
2047 if (fde_table_in_use == fde_table_allocated)
2049 fde_table_allocated += FDE_TABLE_INCREMENT;
2051 = (dw_fde_ref) xrealloc (fde_table,
2052 fde_table_allocated * sizeof (dw_fde_node));
2055 /* Record the FDE associated with this function. */
2056 current_funcdef_fde = fde_table_in_use;
2058 /* Add the new FDE at the end of the fde_table. */
2059 fde = &fde_table[fde_table_in_use++];
2060 fde->dw_fde_begin = xstrdup (label);
2061 fde->dw_fde_current_label = NULL;
2062 fde->dw_fde_end = NULL;
2063 fde->dw_fde_cfi = NULL;
2064 fde->funcdef_number = current_funcdef_number;
2065 fde->nothrow = current_function_nothrow;
2066 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2068 args_size = old_args_size = 0;
2071 /* Output a marker (i.e. a label) for the absolute end of the generated code
2072 for a function definition. This gets called *after* the epilogue code has
2076 dwarf2out_end_epilogue ()
2079 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2081 /* Output a label to mark the endpoint of the code generated for this
2083 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2084 ASM_OUTPUT_LABEL (asm_out_file, label);
2085 fde = &fde_table[fde_table_in_use - 1];
2086 fde->dw_fde_end = xstrdup (label);
2090 dwarf2out_frame_init ()
2092 /* Allocate the initial hunk of the fde_table. */
2093 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2094 fde_table_allocated = FDE_TABLE_INCREMENT;
2095 fde_table_in_use = 0;
2097 /* Generate the CFA instructions common to all FDE's. Do it now for the
2098 sake of lookup_cfa. */
2100 #ifdef DWARF2_UNWIND_INFO
2101 /* On entry, the Canonical Frame Address is at SP. */
2102 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2103 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2108 dwarf2out_frame_finish ()
2110 /* Output call frame information. */
2111 #ifdef MIPS_DEBUGGING_INFO
2112 if (write_symbols == DWARF2_DEBUG)
2113 output_call_frame_info (0);
2114 if (flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
2115 output_call_frame_info (1);
2117 if (write_symbols == DWARF2_DEBUG
2118 || flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
2119 output_call_frame_info (1);
2123 /* And now, the subset of the debugging information support code necessary
2124 for emitting location expressions. */
2126 typedef struct dw_val_struct *dw_val_ref;
2127 typedef struct die_struct *dw_die_ref;
2128 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2129 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2131 /* Each DIE may have a series of attribute/value pairs. Values
2132 can take on several forms. The forms that are used in this
2133 implementation are listed below. */
2139 dw_val_class_loc_list,
2141 dw_val_class_unsigned_const,
2142 dw_val_class_long_long,
2145 dw_val_class_die_ref,
2146 dw_val_class_fde_ref,
2147 dw_val_class_lbl_id,
2148 dw_val_class_lbl_offset,
2153 /* Describe a double word constant value. */
2154 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2156 typedef struct dw_long_long_struct
2163 /* Describe a floating point constant value. */
2165 typedef struct dw_fp_struct
2172 /* The dw_val_node describes an attribute's value, as it is
2173 represented internally. */
2175 typedef struct dw_val_struct
2177 dw_val_class val_class;
2181 dw_loc_list_ref val_loc_list;
2182 dw_loc_descr_ref val_loc;
2184 long unsigned val_unsigned;
2185 dw_long_long_const val_long_long;
2186 dw_float_const val_float;
2191 unsigned val_fde_index;
2194 unsigned char val_flag;
2200 /* Locations in memory are described using a sequence of stack machine
2203 typedef struct dw_loc_descr_struct
2205 dw_loc_descr_ref dw_loc_next;
2206 enum dwarf_location_atom dw_loc_opc;
2207 dw_val_node dw_loc_oprnd1;
2208 dw_val_node dw_loc_oprnd2;
2213 /* Location lists are ranges + location descriptions for that range,
2214 so you can track variables that are in different places over
2215 their entire life. */
2216 typedef struct dw_loc_list_struct
2218 dw_loc_list_ref dw_loc_next;
2219 const char *begin; /* Label for begin address of range */
2220 const char *end; /* Label for end address of range */
2221 char *ll_symbol; /* Label for beginning of location list. Only on head of list */
2222 const char *section; /* Section this loclist is relative to */
2223 dw_loc_descr_ref expr;
2226 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2227 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2230 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2232 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2233 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2234 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2235 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2237 /* Convert a DWARF stack opcode into its string name. */
2240 dwarf_stack_op_name (op)
2241 register unsigned op;
2246 return "DW_OP_addr";
2248 return "DW_OP_deref";
2250 return "DW_OP_const1u";
2252 return "DW_OP_const1s";
2254 return "DW_OP_const2u";
2256 return "DW_OP_const2s";
2258 return "DW_OP_const4u";
2260 return "DW_OP_const4s";
2262 return "DW_OP_const8u";
2264 return "DW_OP_const8s";
2266 return "DW_OP_constu";
2268 return "DW_OP_consts";
2272 return "DW_OP_drop";
2274 return "DW_OP_over";
2276 return "DW_OP_pick";
2278 return "DW_OP_swap";
2282 return "DW_OP_xderef";
2290 return "DW_OP_minus";
2302 return "DW_OP_plus";
2303 case DW_OP_plus_uconst:
2304 return "DW_OP_plus_uconst";
2310 return "DW_OP_shra";
2328 return "DW_OP_skip";
2330 return "DW_OP_lit0";
2332 return "DW_OP_lit1";
2334 return "DW_OP_lit2";
2336 return "DW_OP_lit3";
2338 return "DW_OP_lit4";
2340 return "DW_OP_lit5";
2342 return "DW_OP_lit6";
2344 return "DW_OP_lit7";
2346 return "DW_OP_lit8";
2348 return "DW_OP_lit9";
2350 return "DW_OP_lit10";
2352 return "DW_OP_lit11";
2354 return "DW_OP_lit12";
2356 return "DW_OP_lit13";
2358 return "DW_OP_lit14";
2360 return "DW_OP_lit15";
2362 return "DW_OP_lit16";
2364 return "DW_OP_lit17";
2366 return "DW_OP_lit18";
2368 return "DW_OP_lit19";
2370 return "DW_OP_lit20";
2372 return "DW_OP_lit21";
2374 return "DW_OP_lit22";
2376 return "DW_OP_lit23";
2378 return "DW_OP_lit24";
2380 return "DW_OP_lit25";
2382 return "DW_OP_lit26";
2384 return "DW_OP_lit27";
2386 return "DW_OP_lit28";
2388 return "DW_OP_lit29";
2390 return "DW_OP_lit30";
2392 return "DW_OP_lit31";
2394 return "DW_OP_reg0";
2396 return "DW_OP_reg1";
2398 return "DW_OP_reg2";
2400 return "DW_OP_reg3";
2402 return "DW_OP_reg4";
2404 return "DW_OP_reg5";
2406 return "DW_OP_reg6";
2408 return "DW_OP_reg7";
2410 return "DW_OP_reg8";
2412 return "DW_OP_reg9";
2414 return "DW_OP_reg10";
2416 return "DW_OP_reg11";
2418 return "DW_OP_reg12";
2420 return "DW_OP_reg13";
2422 return "DW_OP_reg14";
2424 return "DW_OP_reg15";
2426 return "DW_OP_reg16";
2428 return "DW_OP_reg17";
2430 return "DW_OP_reg18";
2432 return "DW_OP_reg19";
2434 return "DW_OP_reg20";
2436 return "DW_OP_reg21";
2438 return "DW_OP_reg22";
2440 return "DW_OP_reg23";
2442 return "DW_OP_reg24";
2444 return "DW_OP_reg25";
2446 return "DW_OP_reg26";
2448 return "DW_OP_reg27";
2450 return "DW_OP_reg28";
2452 return "DW_OP_reg29";
2454 return "DW_OP_reg30";
2456 return "DW_OP_reg31";
2458 return "DW_OP_breg0";
2460 return "DW_OP_breg1";
2462 return "DW_OP_breg2";
2464 return "DW_OP_breg3";
2466 return "DW_OP_breg4";
2468 return "DW_OP_breg5";
2470 return "DW_OP_breg6";
2472 return "DW_OP_breg7";
2474 return "DW_OP_breg8";
2476 return "DW_OP_breg9";
2478 return "DW_OP_breg10";
2480 return "DW_OP_breg11";
2482 return "DW_OP_breg12";
2484 return "DW_OP_breg13";
2486 return "DW_OP_breg14";
2488 return "DW_OP_breg15";
2490 return "DW_OP_breg16";
2492 return "DW_OP_breg17";
2494 return "DW_OP_breg18";
2496 return "DW_OP_breg19";
2498 return "DW_OP_breg20";
2500 return "DW_OP_breg21";
2502 return "DW_OP_breg22";
2504 return "DW_OP_breg23";
2506 return "DW_OP_breg24";
2508 return "DW_OP_breg25";
2510 return "DW_OP_breg26";
2512 return "DW_OP_breg27";
2514 return "DW_OP_breg28";
2516 return "DW_OP_breg29";
2518 return "DW_OP_breg30";
2520 return "DW_OP_breg31";
2522 return "DW_OP_regx";
2524 return "DW_OP_fbreg";
2526 return "DW_OP_bregx";
2528 return "DW_OP_piece";
2529 case DW_OP_deref_size:
2530 return "DW_OP_deref_size";
2531 case DW_OP_xderef_size:
2532 return "DW_OP_xderef_size";
2536 return "OP_<unknown>";
2540 /* Return a pointer to a newly allocated location description. Location
2541 descriptions are simple expression terms that can be strung
2542 together to form more complicated location (address) descriptions. */
2544 static inline dw_loc_descr_ref
2545 new_loc_descr (op, oprnd1, oprnd2)
2546 register enum dwarf_location_atom op;
2547 register unsigned long oprnd1;
2548 register unsigned long oprnd2;
2550 /* Use xcalloc here so we clear out all of the long_long constant in
2552 register dw_loc_descr_ref descr
2553 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2555 descr->dw_loc_opc = op;
2556 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2557 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2558 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2559 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2565 /* Add a location description term to a location description expression. */
2568 add_loc_descr (list_head, descr)
2569 register dw_loc_descr_ref *list_head;
2570 register dw_loc_descr_ref descr;
2572 register dw_loc_descr_ref *d;
2574 /* Find the end of the chain. */
2575 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2581 /* Return the size of a location descriptor. */
2583 static unsigned long
2584 size_of_loc_descr (loc)
2585 register dw_loc_descr_ref loc;
2587 register unsigned long size = 1;
2589 switch (loc->dw_loc_opc)
2592 size += DWARF2_ADDR_SIZE;
2611 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2614 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2619 case DW_OP_plus_uconst:
2620 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2658 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2661 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2664 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2667 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2668 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2671 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2673 case DW_OP_deref_size:
2674 case DW_OP_xderef_size:
2684 /* Return the size of a series of location descriptors. */
2686 static unsigned long
2688 register dw_loc_descr_ref loc;
2690 register unsigned long size = 0;
2692 for (; loc != NULL; loc = loc->dw_loc_next)
2694 loc->dw_loc_addr = size;
2695 size += size_of_loc_descr (loc);
2701 /* Output location description stack opcode's operands (if any). */
2704 output_loc_operands (loc)
2705 register dw_loc_descr_ref loc;
2707 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2708 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2710 switch (loc->dw_loc_opc)
2712 #ifdef DWARF2_DEBUGGING_INFO
2714 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2718 dw2_asm_output_data (2, val1->v.val_int, NULL);
2722 dw2_asm_output_data (4, val1->v.val_int, NULL);
2726 if (HOST_BITS_PER_LONG < 64)
2728 dw2_asm_output_data (8, val1->v.val_int, NULL);
2735 if (val1->val_class == dw_val_class_loc)
2736 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2740 dw2_asm_output_data (2, offset, NULL);
2753 /* We currently don't make any attempt to make sure these are
2754 aligned properly like we do for the main unwind info, so
2755 don't support emitting things larger than a byte if we're
2756 only doing unwinding. */
2761 dw2_asm_output_data (1, val1->v.val_int, NULL);
2764 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2767 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2770 dw2_asm_output_data (1, val1->v.val_int, NULL);
2772 case DW_OP_plus_uconst:
2773 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2807 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2810 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2813 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2816 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2817 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2820 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2822 case DW_OP_deref_size:
2823 case DW_OP_xderef_size:
2824 dw2_asm_output_data (1, val1->v.val_int, NULL);
2827 /* Other codes have no operands. */
2832 /* Output a sequence of location operations. */
2835 output_loc_sequence (loc)
2836 dw_loc_descr_ref loc;
2838 for (; loc != NULL; loc = loc->dw_loc_next)
2840 /* Output the opcode. */
2841 dw2_asm_output_data (1, loc->dw_loc_opc,
2842 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2844 /* Output the operand(s) (if any). */
2845 output_loc_operands (loc);
2849 /* This routine will generate the correct assembly data for a location
2850 description based on a cfi entry with a complex address. */
2853 output_cfa_loc (cfi)
2856 dw_loc_descr_ref loc;
2859 /* Output the size of the block. */
2860 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2861 size = size_of_locs (loc);
2862 dw2_asm_output_data_uleb128 (size, NULL);
2864 /* Now output the operations themselves. */
2865 output_loc_sequence (loc);
2868 /* This function builds a dwarf location descriptor seqeunce from
2869 a dw_cfa_location. */
2871 static struct dw_loc_descr_struct *
2873 dw_cfa_location *cfa;
2875 struct dw_loc_descr_struct *head, *tmp;
2877 if (cfa->indirect == 0)
2880 if (cfa->base_offset)
2883 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2885 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2887 else if (cfa->reg <= 31)
2888 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2890 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2891 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2892 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2893 add_loc_descr (&head, tmp);
2894 if (cfa->offset != 0)
2896 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2897 add_loc_descr (&head, tmp);
2902 /* This function fills in aa dw_cfa_location structure from a
2903 dwarf location descriptor sequence. */
2906 get_cfa_from_loc_descr (cfa, loc)
2907 dw_cfa_location *cfa;
2908 struct dw_loc_descr_struct *loc;
2910 struct dw_loc_descr_struct *ptr;
2912 cfa->base_offset = 0;
2916 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2918 enum dwarf_location_atom op = ptr->dw_loc_opc;
2953 cfa->reg = op - DW_OP_reg0;
2956 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2990 cfa->reg = op - DW_OP_breg0;
2991 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2994 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2995 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3000 case DW_OP_plus_uconst:
3001 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3004 internal_error ("DW_LOC_OP %s not implememnted\n",
3005 dwarf_stack_op_name (ptr->dw_loc_opc));
3009 #endif /* .debug_frame support */
3011 /* And now, the support for symbolic debugging information. */
3012 #ifdef DWARF2_DEBUGGING_INFO
3014 /* NOTE: In the comments in this file, many references are made to
3015 "Debugging Information Entries". This term is abbreviated as `DIE'
3016 throughout the remainder of this file. */
3018 /* An internal representation of the DWARF output is built, and then
3019 walked to generate the DWARF debugging info. The walk of the internal
3020 representation is done after the entire program has been compiled.
3021 The types below are used to describe the internal representation. */
3023 /* Various DIE's use offsets relative to the beginning of the
3024 .debug_info section to refer to each other. */
3026 typedef long int dw_offset;
3028 /* Define typedefs here to avoid circular dependencies. */
3030 typedef struct dw_attr_struct *dw_attr_ref;
3031 typedef struct dw_line_info_struct *dw_line_info_ref;
3032 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3033 typedef struct pubname_struct *pubname_ref;
3034 typedef dw_die_ref *arange_ref;
3036 /* Each entry in the line_info_table maintains the file and
3037 line number associated with the label generated for that
3038 entry. The label gives the PC value associated with
3039 the line number entry. */
3041 typedef struct dw_line_info_struct
3043 unsigned long dw_file_num;
3044 unsigned long dw_line_num;
3048 /* Line information for functions in separate sections; each one gets its
3050 typedef struct dw_separate_line_info_struct
3052 unsigned long dw_file_num;
3053 unsigned long dw_line_num;
3054 unsigned long function;
3056 dw_separate_line_info_entry;
3058 /* Each DIE attribute has a field specifying the attribute kind,
3059 a link to the next attribute in the chain, and an attribute value.
3060 Attributes are typically linked below the DIE they modify. */
3062 typedef struct dw_attr_struct
3064 enum dwarf_attribute dw_attr;
3065 dw_attr_ref dw_attr_next;
3066 dw_val_node dw_attr_val;
3070 /* The Debugging Information Entry (DIE) structure */
3072 typedef struct die_struct
3074 enum dwarf_tag die_tag;
3076 dw_attr_ref die_attr;
3077 dw_die_ref die_parent;
3078 dw_die_ref die_child;
3080 dw_offset die_offset;
3081 unsigned long die_abbrev;
3086 /* The pubname structure */
3088 typedef struct pubname_struct
3095 /* The limbo die list structure. */
3096 typedef struct limbo_die_struct
3099 struct limbo_die_struct *next;
3103 /* How to start an assembler comment. */
3104 #ifndef ASM_COMMENT_START
3105 #define ASM_COMMENT_START ";#"
3108 /* Define a macro which returns non-zero for a TYPE_DECL which was
3109 implicitly generated for a tagged type.
3111 Note that unlike the gcc front end (which generates a NULL named
3112 TYPE_DECL node for each complete tagged type, each array type, and
3113 each function type node created) the g++ front end generates a
3114 _named_ TYPE_DECL node for each tagged type node created.
3115 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3116 generate a DW_TAG_typedef DIE for them. */
3118 #define TYPE_DECL_IS_STUB(decl) \
3119 (DECL_NAME (decl) == NULL_TREE \
3120 || (DECL_ARTIFICIAL (decl) \
3121 && is_tagged_type (TREE_TYPE (decl)) \
3122 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3123 /* This is necessary for stub decls that \
3124 appear in nested inline functions. */ \
3125 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3126 && (decl_ultimate_origin (decl) \
3127 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3129 /* Information concerning the compilation unit's programming
3130 language, and compiler version. */
3132 extern int flag_traditional;
3134 /* Fixed size portion of the DWARF compilation unit header. */
3135 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3137 /* Fixed size portion of debugging line information prolog. */
3138 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3140 /* Fixed size portion of public names info. */
3141 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3143 /* Fixed size portion of the address range info. */
3144 #define DWARF_ARANGES_HEADER_SIZE \
3145 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3146 - DWARF_OFFSET_SIZE)
3148 /* Size of padding portion in the address range info. It must be
3149 aligned to twice the pointer size. */
3150 #define DWARF_ARANGES_PAD_SIZE \
3151 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3152 - (2 * DWARF_OFFSET_SIZE + 4))
3154 /* Use assembler line directives if available. */
3155 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3156 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3157 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3159 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3163 /* Define the architecture-dependent minimum instruction length (in bytes).
3164 In this implementation of DWARF, this field is used for information
3165 purposes only. Since GCC generates assembly language, we have
3166 no a priori knowledge of how many instruction bytes are generated
3167 for each source line, and therefore can use only the DW_LNE_set_address
3168 and DW_LNS_fixed_advance_pc line information commands. */
3170 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3171 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3174 /* Minimum line offset in a special line info. opcode.
3175 This value was chosen to give a reasonable range of values. */
3176 #define DWARF_LINE_BASE -10
3178 /* First special line opcde - leave room for the standard opcodes. */
3179 #define DWARF_LINE_OPCODE_BASE 10
3181 /* Range of line offsets in a special line info. opcode. */
3182 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3184 /* Flag that indicates the initial value of the is_stmt_start flag.
3185 In the present implementation, we do not mark any lines as
3186 the beginning of a source statement, because that information
3187 is not made available by the GCC front-end. */
3188 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3190 /* This location is used by calc_die_sizes() to keep track
3191 the offset of each DIE within the .debug_info section. */
3192 static unsigned long next_die_offset;
3194 /* Record the root of the DIE's built for the current compilation unit. */
3195 static dw_die_ref comp_unit_die;
3197 /* A list of DIEs with a NULL parent waiting to be relocated. */
3198 static limbo_die_node *limbo_die_list = 0;
3200 /* Structure used by lookup_filename to manage sets of filenames. */
3206 unsigned last_lookup_index;
3209 /* Size (in elements) of increments by which we may expand the filename
3211 #define FILE_TABLE_INCREMENT 64
3213 /* Filenames referenced by this compilation unit. */
3214 static struct file_table file_table;
3216 /* Local pointer to the name of the main input file. Initialized in
3218 static const char *primary_filename;
3220 /* A pointer to the base of a table of references to DIE's that describe
3221 declarations. The table is indexed by DECL_UID() which is a unique
3222 number identifying each decl. */
3223 static dw_die_ref *decl_die_table;
3225 /* Number of elements currently allocated for the decl_die_table. */
3226 static unsigned decl_die_table_allocated;
3228 /* Number of elements in decl_die_table currently in use. */
3229 static unsigned decl_die_table_in_use;
3231 /* Size (in elements) of increments by which we may expand the
3233 #define DECL_DIE_TABLE_INCREMENT 256
3235 /* A pointer to the base of a table of references to declaration
3236 scopes. This table is a display which tracks the nesting
3237 of declaration scopes at the current scope and containing
3238 scopes. This table is used to find the proper place to
3239 define type declaration DIE's. */
3240 static tree *decl_scope_table;
3242 /* Number of elements currently allocated for the decl_scope_table. */
3243 static int decl_scope_table_allocated;
3245 /* Current level of nesting of declaration scopes. */
3246 static int decl_scope_depth;
3248 /* Size (in elements) of increments by which we may expand the
3249 decl_scope_table. */
3250 #define DECL_SCOPE_TABLE_INCREMENT 64
3252 /* A pointer to the base of a list of references to DIE's that
3253 are uniquely identified by their tag, presence/absence of
3254 children DIE's, and list of attribute/value pairs. */
3255 static dw_die_ref *abbrev_die_table;
3257 /* Number of elements currently allocated for abbrev_die_table. */
3258 static unsigned abbrev_die_table_allocated;
3260 /* Number of elements in type_die_table currently in use. */
3261 static unsigned abbrev_die_table_in_use;
3263 /* Size (in elements) of increments by which we may expand the
3264 abbrev_die_table. */
3265 #define ABBREV_DIE_TABLE_INCREMENT 256
3267 /* A pointer to the base of a table that contains line information
3268 for each source code line in .text in the compilation unit. */
3269 static dw_line_info_ref line_info_table;
3271 /* Number of elements currently allocated for line_info_table. */
3272 static unsigned line_info_table_allocated;
3274 /* Number of elements in separate_line_info_table currently in use. */
3275 static unsigned separate_line_info_table_in_use;
3277 /* A pointer to the base of a table that contains line information
3278 for each source code line outside of .text in the compilation unit. */
3279 static dw_separate_line_info_ref separate_line_info_table;
3281 /* Number of elements currently allocated for separate_line_info_table. */
3282 static unsigned separate_line_info_table_allocated;
3284 /* Number of elements in line_info_table currently in use. */
3285 static unsigned line_info_table_in_use;
3287 /* Size (in elements) of increments by which we may expand the
3289 #define LINE_INFO_TABLE_INCREMENT 1024
3291 /* A pointer to the base of a table that contains a list of publicly
3292 accessible names. */
3293 static pubname_ref pubname_table;
3295 /* Number of elements currently allocated for pubname_table. */
3296 static unsigned pubname_table_allocated;
3298 /* Number of elements in pubname_table currently in use. */
3299 static unsigned pubname_table_in_use;
3301 /* Size (in elements) of increments by which we may expand the
3303 #define PUBNAME_TABLE_INCREMENT 64
3305 /* A pointer to the base of a table that contains a list of publicly
3306 accessible names. */
3307 static arange_ref arange_table;
3309 /* Number of elements currently allocated for arange_table. */
3310 static unsigned arange_table_allocated;
3312 /* Number of elements in arange_table currently in use. */
3313 static unsigned arange_table_in_use;
3315 /* Size (in elements) of increments by which we may expand the
3317 #define ARANGE_TABLE_INCREMENT 64
3319 /* Whether we have location lists that need outputting */
3320 static unsigned have_location_lists;
3322 /* A pointer to the base of a list of incomplete types which might be
3323 completed at some later time. */
3325 static tree *incomplete_types_list;
3327 /* Number of elements currently allocated for the incomplete_types_list. */
3328 static unsigned incomplete_types_allocated;
3330 /* Number of elements of incomplete_types_list currently in use. */
3331 static unsigned incomplete_types;
3333 /* Size (in elements) of increments by which we may expand the incomplete
3334 types list. Actually, a single hunk of space of this size should
3335 be enough for most typical programs. */
3336 #define INCOMPLETE_TYPES_INCREMENT 64
3338 /* Record whether the function being analyzed contains inlined functions. */
3339 static int current_function_has_inlines;
3340 #if 0 && defined (MIPS_DEBUGGING_INFO)
3341 static int comp_unit_has_inlines;
3344 /* Array of RTXes referenced by the debugging information, which therefore
3345 must be kept around forever. We do this rather than perform GC on
3346 the dwarf info because almost all of the dwarf info lives forever, and
3347 it's easier to support non-GC frontends this way. */
3348 static varray_type used_rtx_varray;
3350 /* Forward declarations for functions defined in this file. */
3352 static int is_pseudo_reg PARAMS ((rtx));
3353 static tree type_main_variant PARAMS ((tree));
3354 static int is_tagged_type PARAMS ((tree));
3355 static const char *dwarf_tag_name PARAMS ((unsigned));
3356 static const char *dwarf_attr_name PARAMS ((unsigned));
3357 static const char *dwarf_form_name PARAMS ((unsigned));
3359 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3361 static tree decl_ultimate_origin PARAMS ((tree));
3362 static tree block_ultimate_origin PARAMS ((tree));
3363 static tree decl_class_context PARAMS ((tree));
3364 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3365 static void add_AT_flag PARAMS ((dw_die_ref,
3366 enum dwarf_attribute,
3368 static void add_AT_int PARAMS ((dw_die_ref,
3369 enum dwarf_attribute, long));
3370 static void add_AT_unsigned PARAMS ((dw_die_ref,
3371 enum dwarf_attribute,
3373 static void add_AT_long_long PARAMS ((dw_die_ref,
3374 enum dwarf_attribute,
3377 static void add_AT_float PARAMS ((dw_die_ref,
3378 enum dwarf_attribute,
3380 static void add_AT_string PARAMS ((dw_die_ref,
3381 enum dwarf_attribute,
3383 static void add_AT_die_ref PARAMS ((dw_die_ref,
3384 enum dwarf_attribute,
3386 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3387 enum dwarf_attribute,
3389 static void add_AT_loc PARAMS ((dw_die_ref,
3390 enum dwarf_attribute,
3392 static void add_AT_loc_list PARAMS ((dw_die_ref,
3393 enum dwarf_attribute,
3395 static void add_AT_addr PARAMS ((dw_die_ref,
3396 enum dwarf_attribute,
3398 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3399 enum dwarf_attribute,
3401 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3402 enum dwarf_attribute,
3404 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3405 enum dwarf_attribute));
3406 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3407 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3408 static const char *get_AT_string PARAMS ((dw_die_ref,
3409 enum dwarf_attribute));
3410 static int get_AT_flag PARAMS ((dw_die_ref,
3411 enum dwarf_attribute));
3412 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3413 enum dwarf_attribute));
3414 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3415 enum dwarf_attribute));
3416 static int is_c_family PARAMS ((void));
3417 static int is_java PARAMS ((void));
3418 static int is_fortran PARAMS ((void));
3419 static void remove_AT PARAMS ((dw_die_ref,
3420 enum dwarf_attribute));
3421 static void remove_children PARAMS ((dw_die_ref));
3422 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3423 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3424 static dw_die_ref lookup_type_die PARAMS ((tree));
3425 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3426 static dw_die_ref lookup_decl_die PARAMS ((tree));
3427 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3428 static void print_spaces PARAMS ((FILE *));
3429 static void print_die PARAMS ((dw_die_ref, FILE *));
3430 static void print_dwarf_line_table PARAMS ((FILE *));
3431 static void reverse_die_lists PARAMS ((dw_die_ref));
3432 static void reverse_all_dies PARAMS ((dw_die_ref));
3433 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3434 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3435 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3436 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3437 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3438 static void compute_section_prefix PARAMS ((dw_die_ref));
3439 static int is_type_die PARAMS ((dw_die_ref));
3440 static int is_comdat_die PARAMS ((dw_die_ref));
3441 static int is_symbol_die PARAMS ((dw_die_ref));
3442 static void assign_symbol_names PARAMS ((dw_die_ref));
3443 static void break_out_includes PARAMS ((dw_die_ref));
3444 static void add_sibling_attributes PARAMS ((dw_die_ref));
3445 static void build_abbrev_table PARAMS ((dw_die_ref));
3446 static void output_location_lists PARAMS ((dw_die_ref));
3447 static unsigned long size_of_string PARAMS ((const char *));
3448 static int constant_size PARAMS ((long unsigned));
3449 static unsigned long size_of_die PARAMS ((dw_die_ref));
3450 static void calc_die_sizes PARAMS ((dw_die_ref));
3451 static void mark_dies PARAMS ((dw_die_ref));
3452 static void unmark_dies PARAMS ((dw_die_ref));
3453 static unsigned long size_of_pubnames PARAMS ((void));
3454 static unsigned long size_of_aranges PARAMS ((void));
3455 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3456 static void output_value_format PARAMS ((dw_attr_ref));
3457 static void output_abbrev_section PARAMS ((void));
3458 static void output_die_symbol PARAMS ((dw_die_ref));
3459 static void output_die PARAMS ((dw_die_ref));
3460 static void output_compilation_unit_header PARAMS ((void));
3461 static void output_comp_unit PARAMS ((dw_die_ref));
3462 static const char *dwarf2_name PARAMS ((tree, int));
3463 static void add_pubname PARAMS ((tree, dw_die_ref));
3464 static void output_pubnames PARAMS ((void));
3465 static void add_arange PARAMS ((tree, dw_die_ref));
3466 static void output_aranges PARAMS ((void));
3467 static void output_line_info PARAMS ((void));
3468 static void output_file_names PARAMS ((void));
3469 static dw_die_ref base_type_die PARAMS ((tree));
3470 static tree root_type PARAMS ((tree));
3471 static int is_base_type PARAMS ((tree));
3472 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3473 static int type_is_enum PARAMS ((tree));
3474 static unsigned int reg_number PARAMS ((rtx));
3475 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3476 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3477 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3478 static int is_based_loc PARAMS ((rtx));
3479 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3480 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3481 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3482 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3483 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3484 static tree field_type PARAMS ((tree));
3485 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3486 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3487 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3488 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3489 static void add_AT_location_description PARAMS ((dw_die_ref,
3490 enum dwarf_attribute, rtx));
3491 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3492 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3493 static rtx rtl_for_decl_location PARAMS ((tree));
3494 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3495 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3496 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3497 static void add_bound_info PARAMS ((dw_die_ref,
3498 enum dwarf_attribute, tree));
3499 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3500 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3501 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3502 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3503 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3504 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3505 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3506 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3507 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3508 static void push_decl_scope PARAMS ((tree));
3509 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3510 static void pop_decl_scope PARAMS ((void));
3511 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3513 static const char *type_tag PARAMS ((tree));
3514 static tree member_declared_type PARAMS ((tree));
3516 static const char *decl_start_label PARAMS ((tree));
3518 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3519 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3521 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3523 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3524 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3525 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3526 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3527 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3528 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3529 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3530 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3531 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3532 static void gen_label_die PARAMS ((tree, dw_die_ref));
3533 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3534 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3535 static void gen_field_die PARAMS ((tree, dw_die_ref));
3536 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3537 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3538 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3539 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3540 static void gen_member_die PARAMS ((tree, dw_die_ref));
3541 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3542 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3543 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3544 static void gen_type_die PARAMS ((tree, dw_die_ref));
3545 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3546 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3547 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3548 static int is_redundant_typedef PARAMS ((tree));
3549 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3550 static unsigned lookup_filename PARAMS ((const char *));
3551 static void init_file_table PARAMS ((void));
3552 static void add_incomplete_type PARAMS ((tree));
3553 static void retry_incomplete_types PARAMS ((void));
3554 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3555 static rtx save_rtx PARAMS ((rtx));
3556 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3557 static int file_info_cmp PARAMS ((const void *, const void *));
3558 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3559 const char *, const char *,
3560 const char *, unsigned));
3561 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3563 const char *, const char *, const char *));
3564 static void output_loc_list PARAMS ((dw_loc_list_ref));
3565 static char *gen_internal_sym PARAMS ((const char *));
3567 /* Section names used to hold DWARF debugging information. */
3568 #ifndef DEBUG_INFO_SECTION
3569 #define DEBUG_INFO_SECTION ".debug_info"
3571 #ifndef DEBUG_ABBREV_SECTION
3572 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3574 #ifndef DEBUG_ARANGES_SECTION
3575 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3577 #ifndef DEBUG_MACINFO_SECTION
3578 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3580 #ifndef DEBUG_LINE_SECTION
3581 #define DEBUG_LINE_SECTION ".debug_line"
3583 #ifndef DEBUG_LOC_SECTION
3584 #define DEBUG_LOC_SECTION ".debug_loc"
3586 #ifndef DEBUG_PUBNAMES_SECTION
3587 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3589 #ifndef DEBUG_STR_SECTION
3590 #define DEBUG_STR_SECTION ".debug_str"
3593 /* Standard ELF section names for compiled code and data. */
3594 #ifndef TEXT_SECTION
3595 #define TEXT_SECTION ".text"
3597 #ifndef DATA_SECTION
3598 #define DATA_SECTION ".data"
3601 #define BSS_SECTION ".bss"
3604 /* Labels we insert at beginning sections we can reference instead of
3605 the section names themselves. */
3607 #ifndef TEXT_SECTION_LABEL
3608 #define TEXT_SECTION_LABEL "Ltext"
3610 #ifndef DEBUG_LINE_SECTION_LABEL
3611 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3613 #ifndef DEBUG_INFO_SECTION_LABEL
3614 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3616 #ifndef DEBUG_ABBREV_SECTION_LABEL
3617 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3619 #ifndef DEBUG_LOC_SECTION_LABEL
3620 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3622 #ifndef DEBUG_MACINFO_SECTION_LABEL
3623 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3625 /* Definitions of defaults for formats and names of various special
3626 (artificial) labels which may be generated within this file (when the -g
3627 options is used and DWARF_DEBUGGING_INFO is in effect.
3628 If necessary, these may be overridden from within the tm.h file, but
3629 typically, overriding these defaults is unnecessary. */
3631 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3632 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3633 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3634 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3635 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3636 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3637 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3638 #ifndef TEXT_END_LABEL
3639 #define TEXT_END_LABEL "Letext"
3641 #ifndef DATA_END_LABEL
3642 #define DATA_END_LABEL "Ledata"
3644 #ifndef BSS_END_LABEL
3645 #define BSS_END_LABEL "Lebss"
3647 #ifndef BLOCK_BEGIN_LABEL
3648 #define BLOCK_BEGIN_LABEL "LBB"
3650 #ifndef BLOCK_END_LABEL
3651 #define BLOCK_END_LABEL "LBE"
3653 #ifndef BODY_BEGIN_LABEL
3654 #define BODY_BEGIN_LABEL "Lbb"
3656 #ifndef BODY_END_LABEL
3657 #define BODY_END_LABEL "Lbe"
3659 #ifndef LINE_CODE_LABEL
3660 #define LINE_CODE_LABEL "LM"
3662 #ifndef SEPARATE_LINE_CODE_LABEL
3663 #define SEPARATE_LINE_CODE_LABEL "LSM"
3666 /* We allow a language front-end to designate a function that is to be
3667 called to "demangle" any name before it it put into a DIE. */
3669 static const char *(*demangle_name_func) PARAMS ((const char *));
3672 dwarf2out_set_demangle_name_func (func)
3673 const char *(*func) PARAMS ((const char *));
3675 demangle_name_func = func;
3678 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3679 that means adding it to used_rtx_varray. If not, that means making
3680 a copy on the permanent_obstack. */
3686 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3691 /* Test if rtl node points to a pseudo register. */
3697 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3698 || (GET_CODE (rtl) == SUBREG
3699 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3702 /* Return a reference to a type, with its const and volatile qualifiers
3706 type_main_variant (type)
3709 type = TYPE_MAIN_VARIANT (type);
3711 /* There really should be only one main variant among any group of variants
3712 of a given type (and all of the MAIN_VARIANT values for all members of
3713 the group should point to that one type) but sometimes the C front-end
3714 messes this up for array types, so we work around that bug here. */
3716 if (TREE_CODE (type) == ARRAY_TYPE)
3717 while (type != TYPE_MAIN_VARIANT (type))
3718 type = TYPE_MAIN_VARIANT (type);
3723 /* Return non-zero if the given type node represents a tagged type. */
3726 is_tagged_type (type)
3729 register enum tree_code code = TREE_CODE (type);
3731 return (code == RECORD_TYPE || code == UNION_TYPE
3732 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3735 /* Convert a DIE tag into its string name. */
3738 dwarf_tag_name (tag)
3739 register unsigned tag;
3743 case DW_TAG_padding:
3744 return "DW_TAG_padding";
3745 case DW_TAG_array_type:
3746 return "DW_TAG_array_type";
3747 case DW_TAG_class_type:
3748 return "DW_TAG_class_type";
3749 case DW_TAG_entry_point:
3750 return "DW_TAG_entry_point";
3751 case DW_TAG_enumeration_type:
3752 return "DW_TAG_enumeration_type";
3753 case DW_TAG_formal_parameter:
3754 return "DW_TAG_formal_parameter";
3755 case DW_TAG_imported_declaration:
3756 return "DW_TAG_imported_declaration";
3758 return "DW_TAG_label";
3759 case DW_TAG_lexical_block:
3760 return "DW_TAG_lexical_block";
3762 return "DW_TAG_member";
3763 case DW_TAG_pointer_type:
3764 return "DW_TAG_pointer_type";
3765 case DW_TAG_reference_type:
3766 return "DW_TAG_reference_type";
3767 case DW_TAG_compile_unit:
3768 return "DW_TAG_compile_unit";
3769 case DW_TAG_string_type:
3770 return "DW_TAG_string_type";
3771 case DW_TAG_structure_type:
3772 return "DW_TAG_structure_type";
3773 case DW_TAG_subroutine_type:
3774 return "DW_TAG_subroutine_type";
3775 case DW_TAG_typedef:
3776 return "DW_TAG_typedef";
3777 case DW_TAG_union_type:
3778 return "DW_TAG_union_type";
3779 case DW_TAG_unspecified_parameters:
3780 return "DW_TAG_unspecified_parameters";
3781 case DW_TAG_variant:
3782 return "DW_TAG_variant";
3783 case DW_TAG_common_block:
3784 return "DW_TAG_common_block";
3785 case DW_TAG_common_inclusion:
3786 return "DW_TAG_common_inclusion";
3787 case DW_TAG_inheritance:
3788 return "DW_TAG_inheritance";
3789 case DW_TAG_inlined_subroutine:
3790 return "DW_TAG_inlined_subroutine";
3792 return "DW_TAG_module";
3793 case DW_TAG_ptr_to_member_type:
3794 return "DW_TAG_ptr_to_member_type";
3795 case DW_TAG_set_type:
3796 return "DW_TAG_set_type";
3797 case DW_TAG_subrange_type:
3798 return "DW_TAG_subrange_type";
3799 case DW_TAG_with_stmt:
3800 return "DW_TAG_with_stmt";
3801 case DW_TAG_access_declaration:
3802 return "DW_TAG_access_declaration";
3803 case DW_TAG_base_type:
3804 return "DW_TAG_base_type";
3805 case DW_TAG_catch_block:
3806 return "DW_TAG_catch_block";
3807 case DW_TAG_const_type:
3808 return "DW_TAG_const_type";
3809 case DW_TAG_constant:
3810 return "DW_TAG_constant";
3811 case DW_TAG_enumerator:
3812 return "DW_TAG_enumerator";
3813 case DW_TAG_file_type:
3814 return "DW_TAG_file_type";
3816 return "DW_TAG_friend";
3817 case DW_TAG_namelist:
3818 return "DW_TAG_namelist";
3819 case DW_TAG_namelist_item:
3820 return "DW_TAG_namelist_item";
3821 case DW_TAG_packed_type:
3822 return "DW_TAG_packed_type";
3823 case DW_TAG_subprogram:
3824 return "DW_TAG_subprogram";
3825 case DW_TAG_template_type_param:
3826 return "DW_TAG_template_type_param";
3827 case DW_TAG_template_value_param:
3828 return "DW_TAG_template_value_param";
3829 case DW_TAG_thrown_type:
3830 return "DW_TAG_thrown_type";
3831 case DW_TAG_try_block:
3832 return "DW_TAG_try_block";
3833 case DW_TAG_variant_part:
3834 return "DW_TAG_variant_part";
3835 case DW_TAG_variable:
3836 return "DW_TAG_variable";
3837 case DW_TAG_volatile_type:
3838 return "DW_TAG_volatile_type";
3839 case DW_TAG_MIPS_loop:
3840 return "DW_TAG_MIPS_loop";
3841 case DW_TAG_format_label:
3842 return "DW_TAG_format_label";
3843 case DW_TAG_function_template:
3844 return "DW_TAG_function_template";
3845 case DW_TAG_class_template:
3846 return "DW_TAG_class_template";
3847 case DW_TAG_GNU_BINCL:
3848 return "DW_TAG_GNU_BINCL";
3849 case DW_TAG_GNU_EINCL:
3850 return "DW_TAG_GNU_EINCL";
3852 return "DW_TAG_<unknown>";
3856 /* Convert a DWARF attribute code into its string name. */
3859 dwarf_attr_name (attr)
3860 register unsigned attr;
3865 return "DW_AT_sibling";
3866 case DW_AT_location:
3867 return "DW_AT_location";
3869 return "DW_AT_name";
3870 case DW_AT_ordering:
3871 return "DW_AT_ordering";
3872 case DW_AT_subscr_data:
3873 return "DW_AT_subscr_data";
3874 case DW_AT_byte_size:
3875 return "DW_AT_byte_size";
3876 case DW_AT_bit_offset:
3877 return "DW_AT_bit_offset";
3878 case DW_AT_bit_size:
3879 return "DW_AT_bit_size";
3880 case DW_AT_element_list:
3881 return "DW_AT_element_list";
3882 case DW_AT_stmt_list:
3883 return "DW_AT_stmt_list";
3885 return "DW_AT_low_pc";
3887 return "DW_AT_high_pc";
3888 case DW_AT_language:
3889 return "DW_AT_language";
3891 return "DW_AT_member";
3893 return "DW_AT_discr";
3894 case DW_AT_discr_value:
3895 return "DW_AT_discr_value";
3896 case DW_AT_visibility:
3897 return "DW_AT_visibility";
3899 return "DW_AT_import";
3900 case DW_AT_string_length:
3901 return "DW_AT_string_length";
3902 case DW_AT_common_reference:
3903 return "DW_AT_common_reference";
3904 case DW_AT_comp_dir:
3905 return "DW_AT_comp_dir";
3906 case DW_AT_const_value:
3907 return "DW_AT_const_value";
3908 case DW_AT_containing_type:
3909 return "DW_AT_containing_type";
3910 case DW_AT_default_value:
3911 return "DW_AT_default_value";
3913 return "DW_AT_inline";
3914 case DW_AT_is_optional:
3915 return "DW_AT_is_optional";
3916 case DW_AT_lower_bound:
3917 return "DW_AT_lower_bound";
3918 case DW_AT_producer:
3919 return "DW_AT_producer";
3920 case DW_AT_prototyped:
3921 return "DW_AT_prototyped";
3922 case DW_AT_return_addr:
3923 return "DW_AT_return_addr";
3924 case DW_AT_start_scope:
3925 return "DW_AT_start_scope";
3926 case DW_AT_stride_size:
3927 return "DW_AT_stride_size";
3928 case DW_AT_upper_bound:
3929 return "DW_AT_upper_bound";
3930 case DW_AT_abstract_origin:
3931 return "DW_AT_abstract_origin";
3932 case DW_AT_accessibility:
3933 return "DW_AT_accessibility";
3934 case DW_AT_address_class:
3935 return "DW_AT_address_class";
3936 case DW_AT_artificial:
3937 return "DW_AT_artificial";
3938 case DW_AT_base_types:
3939 return "DW_AT_base_types";
3940 case DW_AT_calling_convention:
3941 return "DW_AT_calling_convention";
3943 return "DW_AT_count";
3944 case DW_AT_data_member_location:
3945 return "DW_AT_data_member_location";
3946 case DW_AT_decl_column:
3947 return "DW_AT_decl_column";
3948 case DW_AT_decl_file:
3949 return "DW_AT_decl_file";
3950 case DW_AT_decl_line:
3951 return "DW_AT_decl_line";
3952 case DW_AT_declaration:
3953 return "DW_AT_declaration";
3954 case DW_AT_discr_list:
3955 return "DW_AT_discr_list";
3956 case DW_AT_encoding:
3957 return "DW_AT_encoding";
3958 case DW_AT_external:
3959 return "DW_AT_external";
3960 case DW_AT_frame_base:
3961 return "DW_AT_frame_base";
3963 return "DW_AT_friend";
3964 case DW_AT_identifier_case:
3965 return "DW_AT_identifier_case";
3966 case DW_AT_macro_info:
3967 return "DW_AT_macro_info";
3968 case DW_AT_namelist_items:
3969 return "DW_AT_namelist_items";
3970 case DW_AT_priority:
3971 return "DW_AT_priority";
3973 return "DW_AT_segment";
3974 case DW_AT_specification:
3975 return "DW_AT_specification";
3976 case DW_AT_static_link:
3977 return "DW_AT_static_link";
3979 return "DW_AT_type";
3980 case DW_AT_use_location:
3981 return "DW_AT_use_location";
3982 case DW_AT_variable_parameter:
3983 return "DW_AT_variable_parameter";
3984 case DW_AT_virtuality:
3985 return "DW_AT_virtuality";
3986 case DW_AT_vtable_elem_location:
3987 return "DW_AT_vtable_elem_location";
3989 case DW_AT_MIPS_fde:
3990 return "DW_AT_MIPS_fde";
3991 case DW_AT_MIPS_loop_begin:
3992 return "DW_AT_MIPS_loop_begin";
3993 case DW_AT_MIPS_tail_loop_begin:
3994 return "DW_AT_MIPS_tail_loop_begin";
3995 case DW_AT_MIPS_epilog_begin:
3996 return "DW_AT_MIPS_epilog_begin";
3997 case DW_AT_MIPS_loop_unroll_factor:
3998 return "DW_AT_MIPS_loop_unroll_factor";
3999 case DW_AT_MIPS_software_pipeline_depth:
4000 return "DW_AT_MIPS_software_pipeline_depth";
4001 case DW_AT_MIPS_linkage_name:
4002 return "DW_AT_MIPS_linkage_name";
4003 case DW_AT_MIPS_stride:
4004 return "DW_AT_MIPS_stride";
4005 case DW_AT_MIPS_abstract_name:
4006 return "DW_AT_MIPS_abstract_name";
4007 case DW_AT_MIPS_clone_origin:
4008 return "DW_AT_MIPS_clone_origin";
4009 case DW_AT_MIPS_has_inlines:
4010 return "DW_AT_MIPS_has_inlines";
4012 case DW_AT_sf_names:
4013 return "DW_AT_sf_names";
4014 case DW_AT_src_info:
4015 return "DW_AT_src_info";
4016 case DW_AT_mac_info:
4017 return "DW_AT_mac_info";
4018 case DW_AT_src_coords:
4019 return "DW_AT_src_coords";
4020 case DW_AT_body_begin:
4021 return "DW_AT_body_begin";
4022 case DW_AT_body_end:
4023 return "DW_AT_body_end";
4025 return "DW_AT_<unknown>";
4029 /* Convert a DWARF value form code into its string name. */
4032 dwarf_form_name (form)
4033 register unsigned form;
4038 return "DW_FORM_addr";
4039 case DW_FORM_block2:
4040 return "DW_FORM_block2";
4041 case DW_FORM_block4:
4042 return "DW_FORM_block4";
4044 return "DW_FORM_data2";
4046 return "DW_FORM_data4";
4048 return "DW_FORM_data8";
4049 case DW_FORM_string:
4050 return "DW_FORM_string";
4052 return "DW_FORM_block";
4053 case DW_FORM_block1:
4054 return "DW_FORM_block1";
4056 return "DW_FORM_data1";
4058 return "DW_FORM_flag";
4060 return "DW_FORM_sdata";
4062 return "DW_FORM_strp";
4064 return "DW_FORM_udata";
4065 case DW_FORM_ref_addr:
4066 return "DW_FORM_ref_addr";
4068 return "DW_FORM_ref1";
4070 return "DW_FORM_ref2";
4072 return "DW_FORM_ref4";
4074 return "DW_FORM_ref8";
4075 case DW_FORM_ref_udata:
4076 return "DW_FORM_ref_udata";
4077 case DW_FORM_indirect:
4078 return "DW_FORM_indirect";
4080 return "DW_FORM_<unknown>";
4084 /* Convert a DWARF type code into its string name. */
4088 dwarf_type_encoding_name (enc)
4089 register unsigned enc;
4093 case DW_ATE_address:
4094 return "DW_ATE_address";
4095 case DW_ATE_boolean:
4096 return "DW_ATE_boolean";
4097 case DW_ATE_complex_float:
4098 return "DW_ATE_complex_float";
4100 return "DW_ATE_float";
4102 return "DW_ATE_signed";
4103 case DW_ATE_signed_char:
4104 return "DW_ATE_signed_char";
4105 case DW_ATE_unsigned:
4106 return "DW_ATE_unsigned";
4107 case DW_ATE_unsigned_char:
4108 return "DW_ATE_unsigned_char";
4110 return "DW_ATE_<unknown>";
4115 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4116 instance of an inlined instance of a decl which is local to an inline
4117 function, so we have to trace all of the way back through the origin chain
4118 to find out what sort of node actually served as the original seed for the
4122 decl_ultimate_origin (decl)
4125 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4126 nodes in the function to point to themselves; ignore that if
4127 we're trying to output the abstract instance of this function. */
4128 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4131 #ifdef ENABLE_CHECKING
4132 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4133 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4134 most distant ancestor, this should never happen. */
4138 return DECL_ABSTRACT_ORIGIN (decl);
4141 /* Determine the "ultimate origin" of a block. The block may be an inlined
4142 instance of an inlined instance of a block which is local to an inline
4143 function, so we have to trace all of the way back through the origin chain
4144 to find out what sort of node actually served as the original seed for the
4148 block_ultimate_origin (block)
4149 register tree block;
4151 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4153 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4154 nodes in the function to point to themselves; ignore that if
4155 we're trying to output the abstract instance of this function. */
4156 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4159 if (immediate_origin == NULL_TREE)
4163 register tree ret_val;
4164 register tree lookahead = immediate_origin;
4168 ret_val = lookahead;
4169 lookahead = (TREE_CODE (ret_val) == BLOCK)
4170 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4173 while (lookahead != NULL && lookahead != ret_val);
4179 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4180 of a virtual function may refer to a base class, so we check the 'this'
4184 decl_class_context (decl)
4187 tree context = NULL_TREE;
4189 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4190 context = DECL_CONTEXT (decl);
4192 context = TYPE_MAIN_VARIANT
4193 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4195 if (context && !TYPE_P (context))
4196 context = NULL_TREE;
4201 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4202 addition order, and correct that in reverse_all_dies. */
4205 add_dwarf_attr (die, attr)
4206 register dw_die_ref die;
4207 register dw_attr_ref attr;
4209 if (die != NULL && attr != NULL)
4211 attr->dw_attr_next = die->die_attr;
4212 die->die_attr = attr;
4216 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4217 static inline dw_val_class
4221 return a->dw_attr_val.val_class;
4224 /* Add a flag value attribute to a DIE. */
4227 add_AT_flag (die, attr_kind, flag)
4228 register dw_die_ref die;
4229 register enum dwarf_attribute attr_kind;
4230 register unsigned flag;
4232 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4234 attr->dw_attr_next = NULL;
4235 attr->dw_attr = attr_kind;
4236 attr->dw_attr_val.val_class = dw_val_class_flag;
4237 attr->dw_attr_val.v.val_flag = flag;
4238 add_dwarf_attr (die, attr);
4241 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4242 static inline unsigned
4244 register dw_attr_ref a;
4246 if (a && AT_class (a) == dw_val_class_flag)
4247 return a->dw_attr_val.v.val_flag;
4252 /* Add a signed integer attribute value to a DIE. */
4255 add_AT_int (die, attr_kind, int_val)
4256 register dw_die_ref die;
4257 register enum dwarf_attribute attr_kind;
4258 register long int int_val;
4260 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4262 attr->dw_attr_next = NULL;
4263 attr->dw_attr = attr_kind;
4264 attr->dw_attr_val.val_class = dw_val_class_const;
4265 attr->dw_attr_val.v.val_int = int_val;
4266 add_dwarf_attr (die, attr);
4269 static inline long int AT_int PARAMS ((dw_attr_ref));
4270 static inline long int
4272 register dw_attr_ref a;
4274 if (a && AT_class (a) == dw_val_class_const)
4275 return a->dw_attr_val.v.val_int;
4280 /* Add an unsigned integer attribute value to a DIE. */
4283 add_AT_unsigned (die, attr_kind, unsigned_val)
4284 register dw_die_ref die;
4285 register enum dwarf_attribute attr_kind;
4286 register unsigned long unsigned_val;
4288 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4290 attr->dw_attr_next = NULL;
4291 attr->dw_attr = attr_kind;
4292 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4293 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4294 add_dwarf_attr (die, attr);
4297 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4298 static inline unsigned long
4300 register dw_attr_ref a;
4302 if (a && AT_class (a) == dw_val_class_unsigned_const)
4303 return a->dw_attr_val.v.val_unsigned;
4308 /* Add an unsigned double integer attribute value to a DIE. */
4311 add_AT_long_long (die, attr_kind, val_hi, val_low)
4312 register dw_die_ref die;
4313 register enum dwarf_attribute attr_kind;
4314 register unsigned long val_hi;
4315 register unsigned long val_low;
4317 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4319 attr->dw_attr_next = NULL;
4320 attr->dw_attr = attr_kind;
4321 attr->dw_attr_val.val_class = dw_val_class_long_long;
4322 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4323 attr->dw_attr_val.v.val_long_long.low = val_low;
4324 add_dwarf_attr (die, attr);
4327 /* Add a floating point attribute value to a DIE and return it. */
4330 add_AT_float (die, attr_kind, length, array)
4331 register dw_die_ref die;
4332 register enum dwarf_attribute attr_kind;
4333 register unsigned length;
4334 register long *array;
4336 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4338 attr->dw_attr_next = NULL;
4339 attr->dw_attr = attr_kind;
4340 attr->dw_attr_val.val_class = dw_val_class_float;
4341 attr->dw_attr_val.v.val_float.length = length;
4342 attr->dw_attr_val.v.val_float.array = array;
4343 add_dwarf_attr (die, attr);
4346 /* Add a string attribute value to a DIE. */
4349 add_AT_string (die, attr_kind, str)
4350 register dw_die_ref die;
4351 register enum dwarf_attribute attr_kind;
4352 register const char *str;
4354 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4356 attr->dw_attr_next = NULL;
4357 attr->dw_attr = attr_kind;
4358 attr->dw_attr_val.val_class = dw_val_class_str;
4359 attr->dw_attr_val.v.val_str = xstrdup (str);
4360 add_dwarf_attr (die, attr);
4363 static inline const char *AT_string PARAMS ((dw_attr_ref));
4364 static inline const char *
4366 register dw_attr_ref a;
4368 if (a && AT_class (a) == dw_val_class_str)
4369 return a->dw_attr_val.v.val_str;
4374 /* Add a DIE reference attribute value to a DIE. */
4377 add_AT_die_ref (die, attr_kind, targ_die)
4378 register dw_die_ref die;
4379 register enum dwarf_attribute attr_kind;
4380 register dw_die_ref targ_die;
4382 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4384 attr->dw_attr_next = NULL;
4385 attr->dw_attr = attr_kind;
4386 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4387 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4388 attr->dw_attr_val.v.val_die_ref.external = 0;
4389 add_dwarf_attr (die, attr);
4392 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4393 static inline dw_die_ref
4395 register dw_attr_ref a;
4397 if (a && AT_class (a) == dw_val_class_die_ref)
4398 return a->dw_attr_val.v.val_die_ref.die;
4403 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4406 register dw_attr_ref a;
4408 if (a && AT_class (a) == dw_val_class_die_ref)
4409 return a->dw_attr_val.v.val_die_ref.external;
4414 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4416 set_AT_ref_external (a, i)
4417 register dw_attr_ref a;
4420 if (a && AT_class (a) == dw_val_class_die_ref)
4421 a->dw_attr_val.v.val_die_ref.external = i;
4426 /* Add an FDE reference attribute value to a DIE. */
4429 add_AT_fde_ref (die, attr_kind, targ_fde)
4430 register dw_die_ref die;
4431 register enum dwarf_attribute attr_kind;
4432 register unsigned targ_fde;
4434 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4436 attr->dw_attr_next = NULL;
4437 attr->dw_attr = attr_kind;
4438 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4439 attr->dw_attr_val.v.val_fde_index = targ_fde;
4440 add_dwarf_attr (die, attr);
4443 /* Add a location description attribute value to a DIE. */
4446 add_AT_loc (die, attr_kind, loc)
4447 register dw_die_ref die;
4448 register enum dwarf_attribute attr_kind;
4449 register dw_loc_descr_ref loc;
4451 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4453 attr->dw_attr_next = NULL;
4454 attr->dw_attr = attr_kind;
4455 attr->dw_attr_val.val_class = dw_val_class_loc;
4456 attr->dw_attr_val.v.val_loc = loc;
4457 add_dwarf_attr (die, attr);
4460 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4461 static inline dw_loc_descr_ref
4463 register dw_attr_ref a;
4465 if (a && AT_class (a) == dw_val_class_loc)
4466 return a->dw_attr_val.v.val_loc;
4472 add_AT_loc_list (die, attr_kind, loc_list)
4473 register dw_die_ref die;
4474 register enum dwarf_attribute attr_kind;
4475 register dw_loc_list_ref loc_list;
4477 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4479 attr->dw_attr_next = NULL;
4480 attr->dw_attr = attr_kind;
4481 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4482 attr->dw_attr_val.v.val_loc_list = loc_list;
4483 add_dwarf_attr (die, attr);
4484 have_location_lists = 1;
4487 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
4489 static inline dw_loc_list_ref
4491 register dw_attr_ref a;
4493 if (a && AT_class (a) == dw_val_class_loc_list)
4494 return a->dw_attr_val.v.val_loc_list;
4499 /* Add an address constant attribute value to a DIE. */
4502 add_AT_addr (die, attr_kind, addr)
4503 register dw_die_ref die;
4504 register enum dwarf_attribute attr_kind;
4507 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4509 attr->dw_attr_next = NULL;
4510 attr->dw_attr = attr_kind;
4511 attr->dw_attr_val.val_class = dw_val_class_addr;
4512 attr->dw_attr_val.v.val_addr = addr;
4513 add_dwarf_attr (die, attr);
4516 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4519 register dw_attr_ref a;
4521 if (a && AT_class (a) == dw_val_class_addr)
4522 return a->dw_attr_val.v.val_addr;
4527 /* Add a label identifier attribute value to a DIE. */
4530 add_AT_lbl_id (die, attr_kind, lbl_id)
4531 register dw_die_ref die;
4532 register enum dwarf_attribute attr_kind;
4533 register const char *lbl_id;
4535 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4537 attr->dw_attr_next = NULL;
4538 attr->dw_attr = attr_kind;
4539 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4540 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4541 add_dwarf_attr (die, attr);
4544 /* Add a section offset attribute value to a DIE. */
4547 add_AT_lbl_offset (die, attr_kind, label)
4548 register dw_die_ref die;
4549 register enum dwarf_attribute attr_kind;
4550 register const char *label;
4552 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4554 attr->dw_attr_next = NULL;
4555 attr->dw_attr = attr_kind;
4556 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4557 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4558 add_dwarf_attr (die, attr);
4561 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4562 static inline const char *
4564 register dw_attr_ref a;
4566 if (a && (AT_class (a) == dw_val_class_lbl_id
4567 || AT_class (a) == dw_val_class_lbl_offset))
4568 return a->dw_attr_val.v.val_lbl_id;
4573 /* Get the attribute of type attr_kind. */
4575 static inline dw_attr_ref
4576 get_AT (die, attr_kind)
4577 register dw_die_ref die;
4578 register enum dwarf_attribute attr_kind;
4580 register dw_attr_ref a;
4581 register dw_die_ref spec = NULL;
4585 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4587 if (a->dw_attr == attr_kind)
4590 if (a->dw_attr == DW_AT_specification
4591 || a->dw_attr == DW_AT_abstract_origin)
4596 return get_AT (spec, attr_kind);
4602 /* Return the "low pc" attribute value, typically associated with
4603 a subprogram DIE. Return null if the "low pc" attribute is
4604 either not prsent, or if it cannot be represented as an
4605 assembler label identifier. */
4607 static inline const char *
4609 register dw_die_ref die;
4611 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4612 return a ? AT_lbl (a) : NULL;
4615 /* Return the "high pc" attribute value, typically associated with
4616 a subprogram DIE. Return null if the "high pc" attribute is
4617 either not prsent, or if it cannot be represented as an
4618 assembler label identifier. */
4620 static inline const char *
4622 register dw_die_ref die;
4624 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4625 return a ? AT_lbl (a) : NULL;
4628 /* Return the value of the string attribute designated by ATTR_KIND, or
4629 NULL if it is not present. */
4631 static inline const char *
4632 get_AT_string (die, attr_kind)
4633 register dw_die_ref die;
4634 register enum dwarf_attribute attr_kind;
4636 register dw_attr_ref a = get_AT (die, attr_kind);
4637 return a ? AT_string (a) : NULL;
4640 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4641 if it is not present. */
4644 get_AT_flag (die, attr_kind)
4645 register dw_die_ref die;
4646 register enum dwarf_attribute attr_kind;
4648 register dw_attr_ref a = get_AT (die, attr_kind);
4649 return a ? AT_flag (a) : 0;
4652 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4653 if it is not present. */
4655 static inline unsigned
4656 get_AT_unsigned (die, attr_kind)
4657 register dw_die_ref die;
4658 register enum dwarf_attribute attr_kind;
4660 register dw_attr_ref a = get_AT (die, attr_kind);
4661 return a ? AT_unsigned (a) : 0;
4664 static inline dw_die_ref
4665 get_AT_ref (die, attr_kind)
4667 register enum dwarf_attribute attr_kind;
4669 register dw_attr_ref a = get_AT (die, attr_kind);
4670 return a ? AT_ref (a) : NULL;
4676 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4678 return (lang == DW_LANG_C || lang == DW_LANG_C89
4679 || lang == DW_LANG_C_plus_plus);
4685 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4687 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4693 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4695 return (lang == DW_LANG_Java);
4698 /* Free up the memory used by A. */
4700 static inline void free_AT PARAMS ((dw_attr_ref));
4705 switch (AT_class (a))
4707 case dw_val_class_str:
4708 case dw_val_class_lbl_id:
4709 case dw_val_class_lbl_offset:
4710 free (a->dw_attr_val.v.val_str);
4713 case dw_val_class_float:
4714 free (a->dw_attr_val.v.val_float.array);
4724 /* Remove the specified attribute if present. */
4727 remove_AT (die, attr_kind)
4728 register dw_die_ref die;
4729 register enum dwarf_attribute attr_kind;
4731 register dw_attr_ref *p;
4732 register dw_attr_ref removed = NULL;
4736 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4737 if ((*p)->dw_attr == attr_kind)
4740 *p = (*p)->dw_attr_next;
4749 /* Free up the memory used by DIE. */
4751 static inline void free_die PARAMS ((dw_die_ref));
4756 remove_children (die);
4760 /* Discard the children of this DIE. */
4763 remove_children (die)
4764 register dw_die_ref die;
4766 register dw_die_ref child_die = die->die_child;
4768 die->die_child = NULL;
4770 while (child_die != NULL)
4772 register dw_die_ref tmp_die = child_die;
4773 register dw_attr_ref a;
4775 child_die = child_die->die_sib;
4777 for (a = tmp_die->die_attr; a != NULL;)
4779 register dw_attr_ref tmp_a = a;
4781 a = a->dw_attr_next;
4789 /* Add a child DIE below its parent. We build the lists up in reverse
4790 addition order, and correct that in reverse_all_dies. */
4793 add_child_die (die, child_die)
4794 register dw_die_ref die;
4795 register dw_die_ref child_die;
4797 if (die != NULL && child_die != NULL)
4799 if (die == child_die)
4801 child_die->die_parent = die;
4802 child_die->die_sib = die->die_child;
4803 die->die_child = child_die;
4807 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4808 is the specification, to the front of PARENT's list of children. */
4811 splice_child_die (parent, child)
4812 dw_die_ref parent, child;
4816 /* We want the declaration DIE from inside the class, not the
4817 specification DIE at toplevel. */
4818 if (child->die_parent != parent)
4820 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4825 if (child->die_parent != parent
4826 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4829 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4832 *p = child->die_sib;
4836 child->die_sib = parent->die_child;
4837 parent->die_child = child;
4840 /* Return a pointer to a newly created DIE node. */
4842 static inline dw_die_ref
4843 new_die (tag_value, parent_die)
4844 register enum dwarf_tag tag_value;
4845 register dw_die_ref parent_die;
4847 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4849 die->die_tag = tag_value;
4851 if (parent_die != NULL)
4852 add_child_die (parent_die, die);
4855 limbo_die_node *limbo_node;
4857 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4858 limbo_node->die = die;
4859 limbo_node->next = limbo_die_list;
4860 limbo_die_list = limbo_node;
4866 /* Return the DIE associated with the given type specifier. */
4868 static inline dw_die_ref
4869 lookup_type_die (type)
4872 if (TREE_CODE (type) == VECTOR_TYPE)
4873 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4874 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4877 /* Equate a DIE to a given type specifier. */
4880 equate_type_number_to_die (type, type_die)
4882 register dw_die_ref type_die;
4884 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4887 /* Return the DIE associated with a given declaration. */
4889 static inline dw_die_ref
4890 lookup_decl_die (decl)
4893 register unsigned decl_id = DECL_UID (decl);
4895 return (decl_id < decl_die_table_in_use
4896 ? decl_die_table[decl_id] : NULL);
4899 /* Equate a DIE to a particular declaration. */
4902 equate_decl_number_to_die (decl, decl_die)
4904 register dw_die_ref decl_die;
4906 register unsigned decl_id = DECL_UID (decl);
4907 register unsigned num_allocated;
4909 if (decl_id >= decl_die_table_allocated)
4912 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4913 / DECL_DIE_TABLE_INCREMENT)
4914 * DECL_DIE_TABLE_INCREMENT;
4917 = (dw_die_ref *) xrealloc (decl_die_table,
4918 sizeof (dw_die_ref) * num_allocated);
4920 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4921 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4922 decl_die_table_allocated = num_allocated;
4925 if (decl_id >= decl_die_table_in_use)
4926 decl_die_table_in_use = (decl_id + 1);
4928 decl_die_table[decl_id] = decl_die;
4931 /* Keep track of the number of spaces used to indent the
4932 output of the debugging routines that print the structure of
4933 the DIE internal representation. */
4934 static int print_indent;
4936 /* Indent the line the number of spaces given by print_indent. */
4939 print_spaces (outfile)
4942 fprintf (outfile, "%*s", print_indent, "");
4945 /* Print the information associated with a given DIE, and its children.
4946 This routine is a debugging aid only. */
4949 print_die (die, outfile)
4953 register dw_attr_ref a;
4954 register dw_die_ref c;
4956 print_spaces (outfile);
4957 fprintf (outfile, "DIE %4lu: %s\n",
4958 die->die_offset, dwarf_tag_name (die->die_tag));
4959 print_spaces (outfile);
4960 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4961 fprintf (outfile, " offset: %lu\n", die->die_offset);
4963 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4965 print_spaces (outfile);
4966 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4968 switch (AT_class (a))
4970 case dw_val_class_addr:
4971 fprintf (outfile, "address");
4973 case dw_val_class_loc:
4974 fprintf (outfile, "location descriptor");
4976 case dw_val_class_loc_list:
4977 fprintf (outfile, "location list -> label:%s", AT_loc_list (a)->ll_symbol);
4979 case dw_val_class_const:
4980 fprintf (outfile, "%ld", AT_int (a));
4982 case dw_val_class_unsigned_const:
4983 fprintf (outfile, "%lu", AT_unsigned (a));
4985 case dw_val_class_long_long:
4986 fprintf (outfile, "constant (%lu,%lu)",
4987 a->dw_attr_val.v.val_long_long.hi,
4988 a->dw_attr_val.v.val_long_long.low);
4990 case dw_val_class_float:
4991 fprintf (outfile, "floating-point constant");
4993 case dw_val_class_flag:
4994 fprintf (outfile, "%u", AT_flag (a));
4996 case dw_val_class_die_ref:
4997 if (AT_ref (a) != NULL)
4999 if (AT_ref (a)->die_symbol)
5000 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5002 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5005 fprintf (outfile, "die -> <null>");
5007 case dw_val_class_lbl_id:
5008 case dw_val_class_lbl_offset:
5009 fprintf (outfile, "label: %s", AT_lbl (a));
5011 case dw_val_class_str:
5012 if (AT_string (a) != NULL)
5013 fprintf (outfile, "\"%s\"", AT_string (a));
5015 fprintf (outfile, "<null>");
5021 fprintf (outfile, "\n");
5024 if (die->die_child != NULL)
5027 for (c = die->die_child; c != NULL; c = c->die_sib)
5028 print_die (c, outfile);
5032 if (print_indent == 0)
5033 fprintf (outfile, "\n");
5036 /* Print the contents of the source code line number correspondence table.
5037 This routine is a debugging aid only. */
5040 print_dwarf_line_table (outfile)
5043 register unsigned i;
5044 register dw_line_info_ref line_info;
5046 fprintf (outfile, "\n\nDWARF source line information\n");
5047 for (i = 1; i < line_info_table_in_use; ++i)
5049 line_info = &line_info_table[i];
5050 fprintf (outfile, "%5d: ", i);
5051 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5052 fprintf (outfile, "%6ld", line_info->dw_line_num);
5053 fprintf (outfile, "\n");
5056 fprintf (outfile, "\n\n");
5059 /* Print the information collected for a given DIE. */
5062 debug_dwarf_die (die)
5065 print_die (die, stderr);
5068 /* Print all DWARF information collected for the compilation unit.
5069 This routine is a debugging aid only. */
5075 print_die (comp_unit_die, stderr);
5076 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5077 print_dwarf_line_table (stderr);
5080 /* We build up the lists of children and attributes by pushing new ones
5081 onto the beginning of the list. Reverse the lists for DIE so that
5082 they are in order of addition. */
5085 reverse_die_lists (die)
5086 register dw_die_ref die;
5088 register dw_die_ref c, cp, cn;
5089 register dw_attr_ref a, ap, an;
5091 for (a = die->die_attr, ap = 0; a; a = an)
5093 an = a->dw_attr_next;
5094 a->dw_attr_next = ap;
5099 for (c = die->die_child, cp = 0; c; c = cn)
5105 die->die_child = cp;
5108 /* reverse_die_lists only reverses the single die you pass it. Since
5109 we used to reverse all dies in add_sibling_attributes, which runs
5110 through all the dies, it would reverse all the dies. Now, however,
5111 since we don't call reverse_die_lists in add_sibling_attributes, we
5112 need a routine to recursively reverse all the dies. This is that
5116 reverse_all_dies (die)
5117 register dw_die_ref die;
5119 register dw_die_ref c;
5121 reverse_die_lists (die);
5123 for (c = die->die_child; c; c = c->die_sib)
5124 reverse_all_dies (c);
5127 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5128 the CU for the enclosing include file, if any. BINCL_DIE is the
5129 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5133 push_new_compile_unit (old_unit, bincl_die)
5134 dw_die_ref old_unit, bincl_die;
5136 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5137 dw_die_ref new_unit = gen_compile_unit_die (filename);
5138 new_unit->die_sib = old_unit;
5142 /* Close an include-file CU and reopen the enclosing one. */
5145 pop_compile_unit (old_unit)
5146 dw_die_ref old_unit;
5148 dw_die_ref new_unit = old_unit->die_sib;
5149 old_unit->die_sib = NULL;
5153 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5154 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5156 /* Calculate the checksum of a location expression. */
5159 loc_checksum (loc, ctx)
5160 dw_loc_descr_ref loc;
5161 struct md5_ctx *ctx;
5163 PROCESS (loc->dw_loc_opc);
5164 PROCESS (loc->dw_loc_oprnd1);
5165 PROCESS (loc->dw_loc_oprnd2);
5168 /* Calculate the checksum of an attribute. */
5171 attr_checksum (at, ctx)
5173 struct md5_ctx *ctx;
5175 dw_loc_descr_ref loc;
5178 PROCESS (at->dw_attr);
5180 /* We don't care about differences in file numbering. */
5181 if (at->dw_attr == DW_AT_decl_file
5182 /* Or that this was compiled with a different compiler snapshot; if
5183 the output is the same, that's what matters. */
5184 || at->dw_attr == DW_AT_producer)
5187 switch (AT_class (at))
5189 case dw_val_class_const:
5190 PROCESS (at->dw_attr_val.v.val_int);
5192 case dw_val_class_unsigned_const:
5193 PROCESS (at->dw_attr_val.v.val_unsigned);
5195 case dw_val_class_long_long:
5196 PROCESS (at->dw_attr_val.v.val_long_long);
5198 case dw_val_class_float:
5199 PROCESS (at->dw_attr_val.v.val_float);
5201 case dw_val_class_flag:
5202 PROCESS (at->dw_attr_val.v.val_flag);
5205 case dw_val_class_str:
5206 PROCESS_STRING (AT_string (at));
5208 case dw_val_class_addr:
5210 switch (GET_CODE (r))
5213 PROCESS_STRING (XSTR (r, 0));
5221 case dw_val_class_loc:
5222 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5223 loc_checksum (loc, ctx);
5226 case dw_val_class_die_ref:
5227 if (AT_ref (at)->die_offset)
5228 PROCESS (AT_ref (at)->die_offset);
5229 /* FIXME else use target die name or something. */
5231 case dw_val_class_fde_ref:
5232 case dw_val_class_lbl_id:
5233 case dw_val_class_lbl_offset:
5240 /* Calculate the checksum of a DIE. */
5243 die_checksum (die, ctx)
5245 struct md5_ctx *ctx;
5250 PROCESS (die->die_tag);
5252 for (a = die->die_attr; a; a = a->dw_attr_next)
5253 attr_checksum (a, ctx);
5255 for (c = die->die_child; c; c = c->die_sib)
5256 die_checksum (c, ctx);
5260 #undef PROCESS_STRING
5262 /* The prefix to attach to symbols on DIEs in the current comdat debug
5264 static char *comdat_symbol_id;
5266 /* The index of the current symbol within the current comdat CU. */
5267 static unsigned int comdat_symbol_number;
5269 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5270 children, and set comdat_symbol_id accordingly. */
5273 compute_section_prefix (unit_die)
5274 dw_die_ref unit_die;
5278 unsigned char checksum[16];
5281 md5_init_ctx (&ctx);
5282 die_checksum (unit_die, &ctx);
5283 md5_finish_ctx (&ctx, checksum);
5285 p = lbasename (get_AT_string (unit_die, DW_AT_name));
5286 name = (char *) alloca (strlen (p) + 64);
5287 sprintf (name, "%s.", p);
5289 clean_symbol_name (name);
5291 p = name + strlen (name);
5292 for (i = 0; i < 4; ++i)
5294 sprintf (p, "%.2x", checksum[i]);
5298 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5299 comdat_symbol_number = 0;
5302 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5308 switch (die->die_tag)
5310 case DW_TAG_array_type:
5311 case DW_TAG_class_type:
5312 case DW_TAG_enumeration_type:
5313 case DW_TAG_pointer_type:
5314 case DW_TAG_reference_type:
5315 case DW_TAG_string_type:
5316 case DW_TAG_structure_type:
5317 case DW_TAG_subroutine_type:
5318 case DW_TAG_union_type:
5319 case DW_TAG_ptr_to_member_type:
5320 case DW_TAG_set_type:
5321 case DW_TAG_subrange_type:
5322 case DW_TAG_base_type:
5323 case DW_TAG_const_type:
5324 case DW_TAG_file_type:
5325 case DW_TAG_packed_type:
5326 case DW_TAG_volatile_type:
5333 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5334 Basically, we want to choose the bits that are likely to be shared between
5335 compilations (types) and leave out the bits that are specific to individual
5336 compilations (functions). */
5343 /* I think we want to leave base types and __vtbl_ptr_type in the
5344 main CU, as we do for stabs. The advantage is a greater
5345 likelihood of sharing between objects that don't include headers
5346 in the same order (and therefore would put the base types in a
5347 different comdat). jason 8/28/00 */
5348 if (c->die_tag == DW_TAG_base_type)
5351 if (c->die_tag == DW_TAG_pointer_type
5352 || c->die_tag == DW_TAG_reference_type
5353 || c->die_tag == DW_TAG_const_type
5354 || c->die_tag == DW_TAG_volatile_type)
5356 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5357 return t ? is_comdat_die (t) : 0;
5361 return is_type_die (c);
5364 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5365 compilation unit. */
5371 if (is_type_die (c))
5373 if (get_AT (c, DW_AT_declaration)
5374 && ! get_AT (c, DW_AT_specification))
5380 gen_internal_sym (prefix)
5384 static int label_num;
5385 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5386 return xstrdup (buf);
5389 /* Assign symbols to all worthy DIEs under DIE. */
5392 assign_symbol_names (die)
5393 register dw_die_ref die;
5395 register dw_die_ref c;
5397 if (is_symbol_die (die))
5399 if (comdat_symbol_id)
5401 char *p = alloca (strlen (comdat_symbol_id) + 64);
5402 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5403 comdat_symbol_id, comdat_symbol_number++);
5404 die->die_symbol = xstrdup (p);
5407 die->die_symbol = gen_internal_sym ("LDIE");
5410 for (c = die->die_child; c != NULL; c = c->die_sib)
5411 assign_symbol_names (c);
5414 /* Traverse the DIE (which is always comp_unit_die), and set up
5415 additional compilation units for each of the include files we see
5416 bracketed by BINCL/EINCL. */
5419 break_out_includes (die)
5420 register dw_die_ref die;
5423 register dw_die_ref unit = NULL;
5424 limbo_die_node *node;
5426 for (ptr = &(die->die_child); *ptr; )
5428 register dw_die_ref c = *ptr;
5430 if (c->die_tag == DW_TAG_GNU_BINCL
5431 || c->die_tag == DW_TAG_GNU_EINCL
5432 || (unit && is_comdat_die (c)))
5434 /* This DIE is for a secondary CU; remove it from the main one. */
5437 if (c->die_tag == DW_TAG_GNU_BINCL)
5439 unit = push_new_compile_unit (unit, c);
5442 else if (c->die_tag == DW_TAG_GNU_EINCL)
5444 unit = pop_compile_unit (unit);
5448 add_child_die (unit, c);
5452 /* Leave this DIE in the main CU. */
5453 ptr = &(c->die_sib);
5459 /* We can only use this in debugging, since the frontend doesn't check
5460 to make sure that we leave every include file we enter. */
5465 assign_symbol_names (die);
5466 for (node = limbo_die_list; node; node = node->next)
5468 compute_section_prefix (node->die);
5469 assign_symbol_names (node->die);
5473 /* Traverse the DIE and add a sibling attribute if it may have the
5474 effect of speeding up access to siblings. To save some space,
5475 avoid generating sibling attributes for DIE's without children. */
5478 add_sibling_attributes (die)
5479 register dw_die_ref die;
5481 register dw_die_ref c;
5483 if (die->die_tag != DW_TAG_compile_unit
5484 && die->die_sib && die->die_child != NULL)
5485 /* Add the sibling link to the front of the attribute list. */
5486 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5488 for (c = die->die_child; c != NULL; c = c->die_sib)
5489 add_sibling_attributes (c);
5492 /* Output all location lists for the DIE and it's children */
5494 output_location_lists (die)
5495 register dw_die_ref die;
5499 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5501 if (AT_class (d_attr) == dw_val_class_loc_list)
5503 output_loc_list (AT_loc_list (d_attr));
5506 for (c = die->die_child; c != NULL; c = c->die_sib)
5507 output_location_lists (c);
5510 /* The format of each DIE (and its attribute value pairs)
5511 is encoded in an abbreviation table. This routine builds the
5512 abbreviation table and assigns a unique abbreviation id for
5513 each abbreviation entry. The children of each die are visited
5517 build_abbrev_table (die)
5518 register dw_die_ref die;
5520 register unsigned long abbrev_id;
5521 register unsigned int n_alloc;
5522 register dw_die_ref c;
5523 register dw_attr_ref d_attr, a_attr;
5525 /* Scan the DIE references, and mark as external any that refer to
5526 DIEs from other CUs (i.e. those which are not marked). */
5527 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5529 if (AT_class (d_attr) == dw_val_class_die_ref
5530 && AT_ref (d_attr)->die_mark == 0)
5532 if (AT_ref (d_attr)->die_symbol == 0)
5534 set_AT_ref_external (d_attr, 1);
5538 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5540 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5542 if (abbrev->die_tag == die->die_tag)
5544 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5546 a_attr = abbrev->die_attr;
5547 d_attr = die->die_attr;
5549 while (a_attr != NULL && d_attr != NULL)
5551 if ((a_attr->dw_attr != d_attr->dw_attr)
5552 || (value_format (a_attr) != value_format (d_attr)))
5555 a_attr = a_attr->dw_attr_next;
5556 d_attr = d_attr->dw_attr_next;
5559 if (a_attr == NULL && d_attr == NULL)
5565 if (abbrev_id >= abbrev_die_table_in_use)
5567 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5569 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5571 = (dw_die_ref *) xrealloc (abbrev_die_table,
5572 sizeof (dw_die_ref) * n_alloc);
5574 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5575 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5576 abbrev_die_table_allocated = n_alloc;
5579 ++abbrev_die_table_in_use;
5580 abbrev_die_table[abbrev_id] = die;
5583 die->die_abbrev = abbrev_id;
5584 for (c = die->die_child; c != NULL; c = c->die_sib)
5585 build_abbrev_table (c);
5588 /* Return the size of a string, including the null byte.
5590 This used to treat backslashes as escapes, and hence they were not included
5591 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5592 which treats a backslash as a backslash, escaping it if necessary, and hence
5593 we must include them in the count. */
5595 static unsigned long
5596 size_of_string (str)
5597 register const char *str;
5599 return strlen (str) + 1;
5602 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5605 constant_size (value)
5606 long unsigned value;
5613 log = floor_log2 (value);
5616 log = 1 << (floor_log2 (log) + 1);
5621 /* Return the size of a DIE, as it is represented in the
5622 .debug_info section. */
5624 static unsigned long
5626 register dw_die_ref die;
5628 register unsigned long size = 0;
5629 register dw_attr_ref a;
5631 size += size_of_uleb128 (die->die_abbrev);
5632 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5634 switch (AT_class (a))
5636 case dw_val_class_addr:
5637 size += DWARF2_ADDR_SIZE;
5639 case dw_val_class_loc:
5641 register unsigned long lsize = size_of_locs (AT_loc (a));
5644 size += constant_size (lsize);
5648 case dw_val_class_loc_list:
5649 size += DWARF_OFFSET_SIZE;
5651 case dw_val_class_const:
5652 size += size_of_sleb128 (AT_int (a));
5654 case dw_val_class_unsigned_const:
5655 size += constant_size (AT_unsigned (a));
5657 case dw_val_class_long_long:
5658 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5660 case dw_val_class_float:
5661 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5663 case dw_val_class_flag:
5666 case dw_val_class_die_ref:
5667 size += DWARF_OFFSET_SIZE;
5669 case dw_val_class_fde_ref:
5670 size += DWARF_OFFSET_SIZE;
5672 case dw_val_class_lbl_id:
5673 size += DWARF2_ADDR_SIZE;
5675 case dw_val_class_lbl_offset:
5676 size += DWARF_OFFSET_SIZE;
5678 case dw_val_class_str:
5679 size += size_of_string (AT_string (a));
5689 /* Size the debugging information associated with a given DIE.
5690 Visits the DIE's children recursively. Updates the global
5691 variable next_die_offset, on each time through. Uses the
5692 current value of next_die_offset to update the die_offset
5693 field in each DIE. */
5696 calc_die_sizes (die)
5699 register dw_die_ref c;
5700 die->die_offset = next_die_offset;
5701 next_die_offset += size_of_die (die);
5703 for (c = die->die_child; c != NULL; c = c->die_sib)
5706 if (die->die_child != NULL)
5707 /* Count the null byte used to terminate sibling lists. */
5708 next_die_offset += 1;
5711 /* Set the marks for a die and its children. We do this so
5712 that we know whether or not a reference needs to use FORM_ref_addr; only
5713 DIEs in the same CU will be marked. We used to clear out the offset
5714 and use that as the flag, but ran into ordering problems. */
5720 register dw_die_ref c;
5722 for (c = die->die_child; c; c = c->die_sib)
5726 /* Clear the marks for a die and its children. */
5732 register dw_die_ref c;
5734 for (c = die->die_child; c; c = c->die_sib)
5738 /* Return the size of the .debug_pubnames table generated for the
5739 compilation unit. */
5741 static unsigned long
5744 register unsigned long size;
5745 register unsigned i;
5747 size = DWARF_PUBNAMES_HEADER_SIZE;
5748 for (i = 0; i < pubname_table_in_use; ++i)
5750 register pubname_ref p = &pubname_table[i];
5751 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5754 size += DWARF_OFFSET_SIZE;
5758 /* Return the size of the information in the .debug_aranges section. */
5760 static unsigned long
5763 register unsigned long size;
5765 size = DWARF_ARANGES_HEADER_SIZE;
5767 /* Count the address/length pair for this compilation unit. */
5768 size += 2 * DWARF2_ADDR_SIZE;
5769 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5771 /* Count the two zero words used to terminated the address range table. */
5772 size += 2 * DWARF2_ADDR_SIZE;
5776 /* Select the encoding of an attribute value. */
5778 static enum dwarf_form
5782 switch (a->dw_attr_val.val_class)
5784 case dw_val_class_addr:
5785 return DW_FORM_addr;
5786 case dw_val_class_loc_list:
5787 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
5788 .debug_loc section */
5789 return DW_FORM_data4;
5790 case dw_val_class_loc:
5791 switch (constant_size (size_of_locs (AT_loc (a))))
5794 return DW_FORM_block1;
5796 return DW_FORM_block2;
5800 case dw_val_class_const:
5801 return DW_FORM_sdata;
5802 case dw_val_class_unsigned_const:
5803 switch (constant_size (AT_unsigned (a)))
5806 return DW_FORM_data1;
5808 return DW_FORM_data2;
5810 return DW_FORM_data4;
5812 return DW_FORM_data8;
5816 case dw_val_class_long_long:
5817 return DW_FORM_block1;
5818 case dw_val_class_float:
5819 return DW_FORM_block1;
5820 case dw_val_class_flag:
5821 return DW_FORM_flag;
5822 case dw_val_class_die_ref:
5823 if (AT_ref_external (a))
5824 return DW_FORM_ref_addr;
5827 case dw_val_class_fde_ref:
5828 return DW_FORM_data;
5829 case dw_val_class_lbl_id:
5830 return DW_FORM_addr;
5831 case dw_val_class_lbl_offset:
5832 return DW_FORM_data;
5833 case dw_val_class_str:
5834 return DW_FORM_string;
5840 /* Output the encoding of an attribute value. */
5843 output_value_format (a)
5846 enum dwarf_form form = value_format (a);
5847 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
5850 /* Output the .debug_abbrev section which defines the DIE abbreviation
5854 output_abbrev_section ()
5856 unsigned long abbrev_id;
5859 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5861 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5863 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
5865 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
5866 dwarf_tag_name (abbrev->die_tag));
5868 if (abbrev->die_child != NULL)
5869 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
5871 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
5873 for (a_attr = abbrev->die_attr; a_attr != NULL;
5874 a_attr = a_attr->dw_attr_next)
5876 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
5877 dwarf_attr_name (a_attr->dw_attr));
5878 output_value_format (a_attr);
5881 dw2_asm_output_data (1, 0, NULL);
5882 dw2_asm_output_data (1, 0, NULL);
5885 /* Terminate the table. */
5886 dw2_asm_output_data (1, 0, NULL);
5889 /* Output a symbol we can use to refer to this DIE from another CU. */
5892 output_die_symbol (die)
5893 register dw_die_ref die;
5895 char *sym = die->die_symbol;
5900 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5901 /* We make these global, not weak; if the target doesn't support
5902 .linkonce, it doesn't support combining the sections, so debugging
5904 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5905 ASM_OUTPUT_LABEL (asm_out_file, sym);
5908 /* Return a new location list, given the begin and end range, and the
5909 expression. gensym tells us whether to generate a new internal
5910 symbol for this location list node, which is done for the head of
5912 static inline dw_loc_list_ref
5913 new_loc_list (expr, begin, end, section, gensym)
5914 register dw_loc_descr_ref expr;
5915 register const char *begin;
5916 register const char *end;
5917 register const char *section;
5918 register unsigned gensym;
5920 register dw_loc_list_ref retlist
5921 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
5922 retlist->begin = begin;
5924 retlist->expr = expr;
5925 retlist->section = section;
5927 retlist->ll_symbol = gen_internal_sym ("LLST");
5931 /* Add a location description expression to a location list */
5933 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
5934 register dw_loc_list_ref *list_head;
5935 register dw_loc_descr_ref descr;
5936 register const char *begin;
5937 register const char *end;
5938 register const char *section;
5940 register dw_loc_list_ref *d;
5942 /* Find the end of the chain. */
5943 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
5945 /* Add a new location list node to the list */
5946 *d = new_loc_list (descr, begin, end, section, 0);
5951 /* Output the location list given to us */
5953 output_loc_list (list_head)
5954 register dw_loc_list_ref list_head;
5956 register dw_loc_list_ref curr=list_head;
5957 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
5958 if (strcmp (curr->section, ".text") == 0)
5960 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
5961 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT)0,
5962 "Location list base address specifier fake entry");
5963 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
5964 "Location list base address specifier base");
5966 for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
5969 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
5970 "Location list begin address (%s)",
5971 list_head->ll_symbol);
5972 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
5973 "Location list end address (%s)",
5974 list_head->ll_symbol);
5975 size = size_of_locs (curr->expr);
5977 /* Output the block length for this list of location operations. */
5978 dw2_asm_output_data (constant_size (size), size, "%s",
5979 "Location expression size");
5981 output_loc_sequence (curr->expr);
5983 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
5984 "Location list terminator begin (%s)",
5985 list_head->ll_symbol);
5986 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
5987 "Location list terminator end (%s)",
5988 list_head->ll_symbol);
5990 /* Output the DIE and its attributes. Called recursively to generate
5991 the definitions of each child DIE. */
5995 register dw_die_ref die;
5997 register dw_attr_ref a;
5998 register dw_die_ref c;
5999 register unsigned long size;
6001 /* If someone in another CU might refer to us, set up a symbol for
6002 them to point to. */
6003 if (die->die_symbol)
6004 output_die_symbol (die);
6006 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6007 die->die_offset, dwarf_tag_name (die->die_tag));
6009 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6011 const char *name = dwarf_attr_name (a->dw_attr);
6013 switch (AT_class (a))
6015 case dw_val_class_addr:
6016 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6019 case dw_val_class_loc:
6020 size = size_of_locs (AT_loc (a));
6022 /* Output the block length for this list of location operations. */
6023 dw2_asm_output_data (constant_size (size), size, "%s", name);
6025 output_loc_sequence (AT_loc (a));
6028 case dw_val_class_const:
6029 /* ??? It would be slightly more efficient to use a scheme like is
6030 used for unsigned constants below, but gdb 4.x does not sign
6031 extend. Gdb 5.x does sign extend. */
6032 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6035 case dw_val_class_unsigned_const:
6036 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6037 AT_unsigned (a), "%s", name);
6040 case dw_val_class_long_long:
6042 unsigned HOST_WIDE_INT first, second;
6044 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6047 if (WORDS_BIG_ENDIAN)
6049 first = a->dw_attr_val.v.val_long_long.hi;
6050 second = a->dw_attr_val.v.val_long_long.low;
6054 first = a->dw_attr_val.v.val_long_long.low;
6055 second = a->dw_attr_val.v.val_long_long.hi;
6057 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6058 first, "long long constant");
6059 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6064 case dw_val_class_float:
6066 register unsigned int i;
6068 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6071 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6072 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6073 "fp constant word %u", i);
6077 case dw_val_class_flag:
6078 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6080 case dw_val_class_loc_list:
6082 char *sym = AT_loc_list (a)->ll_symbol;
6085 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label, name);
6088 case dw_val_class_die_ref:
6089 if (AT_ref_external (a))
6091 char *sym = AT_ref (a)->die_symbol;
6094 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6096 else if (AT_ref (a)->die_offset == 0)
6099 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6103 case dw_val_class_fde_ref:
6106 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6107 a->dw_attr_val.v.val_fde_index * 2);
6108 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6112 case dw_val_class_lbl_id:
6113 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6116 case dw_val_class_lbl_offset:
6117 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6120 case dw_val_class_str:
6121 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6129 for (c = die->die_child; c != NULL; c = c->die_sib)
6132 if (die->die_child != NULL)
6134 /* Add null byte to terminate sibling list. */
6135 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6140 /* Output the compilation unit that appears at the beginning of the
6141 .debug_info section, and precedes the DIE descriptions. */
6144 output_compilation_unit_header ()
6146 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6147 "Length of Compilation Unit Info");
6149 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6151 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6152 "Offset Into Abbrev. Section");
6154 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6157 /* Output the compilation unit DIE and its children. */
6160 output_comp_unit (die)
6163 const char *secname;
6165 /* Even if there are no children of this DIE, we must output the
6166 information about the compilation unit. Otherwise, on an empty
6167 translation unit, we will generate a present, but empty,
6168 .debug_info section. IRIX 6.5 `nm' will then complain when
6171 Mark all the DIEs in this CU so we know which get local refs. */
6174 build_abbrev_table (die);
6176 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6177 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6178 calc_die_sizes (die);
6180 if (die->die_symbol)
6182 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6183 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6185 die->die_symbol = NULL;
6188 secname = (const char *) DEBUG_INFO_SECTION;
6190 /* Output debugging information. */
6191 ASM_OUTPUT_SECTION (asm_out_file, secname);
6192 output_compilation_unit_header ();
6195 /* Leave the marks on the main CU, so we can check them in
6197 if (die->die_symbol)
6201 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6202 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6203 argument list, and maybe the scope. */
6206 dwarf2_name (decl, scope)
6210 return (*decl_printable_name) (decl, scope ? 1 : 0);
6213 /* Add a new entry to .debug_pubnames if appropriate. */
6216 add_pubname (decl, die)
6222 if (! TREE_PUBLIC (decl))
6225 if (pubname_table_in_use == pubname_table_allocated)
6227 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6228 pubname_table = (pubname_ref) xrealloc
6229 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6232 p = &pubname_table[pubname_table_in_use++];
6235 p->name = xstrdup (dwarf2_name (decl, 1));
6238 /* Output the public names table used to speed up access to externally
6239 visible names. For now, only generate entries for externally
6240 visible procedures. */
6245 register unsigned i;
6246 register unsigned long pubnames_length = size_of_pubnames ();
6248 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6249 "Length of Public Names Info");
6251 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6253 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6254 "Offset of Compilation Unit Info");
6256 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6257 "Compilation Unit Length");
6259 for (i = 0; i < pubname_table_in_use; ++i)
6261 register pubname_ref pub = &pubname_table[i];
6263 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6264 if (pub->die->die_mark == 0)
6267 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6270 dw2_asm_output_nstring (pub->name, -1, "external name");
6273 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6276 /* Add a new entry to .debug_aranges if appropriate. */
6279 add_arange (decl, die)
6283 if (! DECL_SECTION_NAME (decl))
6286 if (arange_table_in_use == arange_table_allocated)
6288 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6290 = (arange_ref) xrealloc (arange_table,
6291 arange_table_allocated * sizeof (dw_die_ref));
6294 arange_table[arange_table_in_use++] = die;
6297 /* Output the information that goes into the .debug_aranges table.
6298 Namely, define the beginning and ending address range of the
6299 text section generated for this compilation unit. */
6304 register unsigned i;
6305 register unsigned long aranges_length = size_of_aranges ();
6307 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6308 "Length of Address Ranges Info");
6310 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6312 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6313 "Offset of Compilation Unit Info");
6315 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6317 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6319 /* We need to align to twice the pointer size here. */
6320 if (DWARF_ARANGES_PAD_SIZE)
6322 /* Pad using a 2 byte words so that padding is correct for any
6324 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6325 2 * DWARF2_ADDR_SIZE);
6326 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6327 dw2_asm_output_data (2, 0, NULL);
6330 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6331 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6332 text_section_label, "Length");
6334 for (i = 0; i < arange_table_in_use; ++i)
6336 dw_die_ref die = arange_table[i];
6338 /* We shouldn't see aranges for DIEs outside of the main CU. */
6339 if (die->die_mark == 0)
6342 if (die->die_tag == DW_TAG_subprogram)
6344 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6346 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6347 get_AT_low_pc (die), "Length");
6351 /* A static variable; extract the symbol from DW_AT_location.
6352 Note that this code isn't currently hit, as we only emit
6353 aranges for functions (jason 9/23/99). */
6355 dw_attr_ref a = get_AT (die, DW_AT_location);
6356 dw_loc_descr_ref loc;
6357 if (! a || AT_class (a) != dw_val_class_loc)
6361 if (loc->dw_loc_opc != DW_OP_addr)
6364 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6365 loc->dw_loc_oprnd1.v.val_addr, "Address");
6366 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6367 get_AT_unsigned (die, DW_AT_byte_size),
6372 /* Output the terminator words. */
6373 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6374 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6378 /* Data structure containing information about input files. */
6381 char *path; /* Complete file name. */
6382 char *fname; /* File name part. */
6383 int length; /* Length of entire string. */
6384 int file_idx; /* Index in input file table. */
6385 int dir_idx; /* Index in directory table. */
6388 /* Data structure containing information about directories with source
6392 char *path; /* Path including directory name. */
6393 int length; /* Path length. */
6394 int prefix; /* Index of directory entry which is a prefix. */
6395 int count; /* Number of files in this directory. */
6396 int dir_idx; /* Index of directory used as base. */
6397 int used; /* Used in the end? */
6400 /* Callback function for file_info comparison. We sort by looking at
6401 the directories in the path. */
6403 file_info_cmp (p1, p2)
6407 const struct file_info *s1 = p1;
6408 const struct file_info *s2 = p2;
6412 /* Take care of file names without directories. */
6413 if (s1->path == s1->fname)
6415 else if (s2->path == s2->fname)
6418 cp1 = (unsigned char *) s1->path;
6419 cp2 = (unsigned char *) s2->path;
6425 /* Reached the end of the first path? */
6426 if (cp1 == (unsigned char *) s1->fname)
6427 /* It doesn't really matter in which order files from the
6428 same directory are sorted in. Therefore don't test for
6429 the second path reaching the end. */
6431 else if (cp2 == (unsigned char *) s2->fname)
6434 /* Character of current path component the same? */
6440 /* Output the directory table and the file name table. We try to minimize
6441 the total amount of memory needed. A heuristic is used to avoid large
6442 slowdowns with many input files. */
6444 output_file_names ()
6446 struct file_info *files;
6447 struct dir_info *dirs;
6456 /* Allocate the various arrays we need. */
6457 files = (struct file_info *) alloca (file_table.in_use
6458 * sizeof (struct file_info));
6459 dirs = (struct dir_info *) alloca (file_table.in_use
6460 * sizeof (struct dir_info));
6462 /* Sort the file names. */
6463 for (i = 1; i < (int) file_table.in_use; ++i)
6467 /* Skip all leading "./". */
6468 f = file_table.table[i];
6469 while (f[0] == '.' && f[1] == '/')
6472 /* Create a new array entry. */
6474 files[i].length = strlen (f);
6475 files[i].file_idx = i;
6477 /* Search for the file name part. */
6478 f = strrchr (f, '/');
6479 files[i].fname = f == NULL ? files[i].path : f + 1;
6481 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6483 /* Find all the different directories used. */
6484 dirs[0].path = files[1].path;
6485 dirs[0].length = files[1].fname - files[1].path;
6486 dirs[0].prefix = -1;
6488 dirs[0].dir_idx = 0;
6490 files[1].dir_idx = 0;
6493 for (i = 2; i < (int) file_table.in_use; ++i)
6494 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6495 && memcmp (dirs[ndirs - 1].path, files[i].path,
6496 dirs[ndirs - 1].length) == 0)
6498 /* Same directory as last entry. */
6499 files[i].dir_idx = ndirs - 1;
6500 ++dirs[ndirs - 1].count;
6506 /* This is a new directory. */
6507 dirs[ndirs].path = files[i].path;
6508 dirs[ndirs].length = files[i].fname - files[i].path;
6509 dirs[ndirs].count = 1;
6510 dirs[ndirs].dir_idx = ndirs;
6511 dirs[ndirs].used = 0;
6512 files[i].dir_idx = ndirs;
6514 /* Search for a prefix. */
6515 dirs[ndirs].prefix = -1;
6516 for (j = 0; j < ndirs; ++j)
6517 if (dirs[j].length < dirs[ndirs].length
6518 && dirs[j].length > 1
6519 && (dirs[ndirs].prefix == -1
6520 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6521 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6522 dirs[ndirs].prefix = j;
6527 /* Now to the actual work. We have to find a subset of the
6528 directories which allow expressing the file name using references
6529 to the directory table with the least amount of characters. We
6530 do not do an exhaustive search where we would have to check out
6531 every combination of every single possible prefix. Instead we
6532 use a heuristic which provides nearly optimal results in most
6533 cases and never is much off. */
6534 saved = (int *) alloca (ndirs * sizeof (int));
6535 savehere = (int *) alloca (ndirs * sizeof (int));
6537 memset (saved, '\0', ndirs * sizeof (saved[0]));
6538 for (i = 0; i < ndirs; ++i)
6543 /* We can always save some space for the current directory. But
6544 this does not mean it will be enough to justify adding the
6546 savehere[i] = dirs[i].length;
6547 total = (savehere[i] - saved[i]) * dirs[i].count;
6549 for (j = i + 1; j < ndirs; ++j)
6553 if (saved[j] < dirs[i].length)
6555 /* Determine whether the dirs[i] path is a prefix of the
6560 while (k != -1 && k != i)
6565 /* Yes it is. We can possibly safe some memory but
6566 writing the filenames in dirs[j] relative to
6568 savehere[j] = dirs[i].length;
6569 total += (savehere[j] - saved[j]) * dirs[j].count;
6574 /* Check whether we can safe enough to justify adding the dirs[i]
6576 if (total > dirs[i].length + 1)
6578 /* It's worthwhile adding. */
6579 for (j = i; j < ndirs; ++j)
6580 if (savehere[j] > 0)
6582 /* Remember how much we saved for this directory so far. */
6583 saved[j] = savehere[j];
6585 /* Remember the prefix directory. */
6586 dirs[j].dir_idx = i;
6591 /* We have to emit them in the order they appear in the file_table
6592 array since the index is used in the debug info generation. To
6593 do this efficiently we generate a back-mapping of the indices
6595 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6596 for (i = 1; i < (int) file_table.in_use; ++i)
6598 backmap[files[i].file_idx] = i;
6599 /* Mark this directory as used. */
6600 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6603 /* That was it. We are ready to emit the information. First the
6604 directory name table. Here we have to make sure that the first
6605 actually emitted directory name has the index one. Zero is
6606 reserved for the current working directory. Make sure we do not
6607 confuse these indices with the one for the constructed table
6608 (even though most of the time they are identical). */
6610 idx_offset = dirs[0].length > 0 ? 1 : 0;
6611 for (i = 1 - idx_offset; i < ndirs; ++i)
6612 if (dirs[i].used != 0)
6614 dirs[i].used = idx++;
6615 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6616 "Directory Entry: 0x%x", dirs[i].used);
6618 dw2_asm_output_data (1, 0, "End directory table");
6620 /* Correct the index for the current working directory entry if it
6622 if (idx_offset == 0)
6625 /* Now write all the file names. */
6626 for (i = 1; i < (int) file_table.in_use; ++i)
6628 int file_idx = backmap[i];
6629 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6631 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6632 "File Entry: 0x%x", i);
6634 /* Include directory index. */
6635 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6637 /* Modification time. */
6638 dw2_asm_output_data_uleb128 (0, NULL);
6640 /* File length in bytes. */
6641 dw2_asm_output_data_uleb128 (0, NULL);
6643 dw2_asm_output_data (1, 0, "End file name table");
6647 /* Output the source line number correspondence information. This
6648 information goes into the .debug_line section. */
6653 char l1[20], l2[20], p1[20], p2[20];
6654 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6655 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6656 register unsigned opc;
6657 register unsigned n_op_args;
6658 register unsigned long lt_index;
6659 register unsigned long current_line;
6660 register long line_offset;
6661 register long line_delta;
6662 register unsigned long current_file;
6663 register unsigned long function;
6665 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6666 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6667 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6668 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6670 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6671 "Length of Source Line Info");
6672 ASM_OUTPUT_LABEL (asm_out_file, l1);
6674 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6676 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6677 ASM_OUTPUT_LABEL (asm_out_file, p1);
6679 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6680 "Minimum Instruction Length");
6682 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6683 "Default is_stmt_start flag");
6685 dw2_asm_output_data (1, DWARF_LINE_BASE,
6686 "Line Base Value (Special Opcodes)");
6688 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6689 "Line Range Value (Special Opcodes)");
6691 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6692 "Special Opcode Base");
6694 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6698 case DW_LNS_advance_pc:
6699 case DW_LNS_advance_line:
6700 case DW_LNS_set_file:
6701 case DW_LNS_set_column:
6702 case DW_LNS_fixed_advance_pc:
6710 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6714 /* Write out the information about the files we use. */
6715 output_file_names ();
6716 ASM_OUTPUT_LABEL (asm_out_file, p2);
6718 /* We used to set the address register to the first location in the text
6719 section here, but that didn't accomplish anything since we already
6720 have a line note for the opening brace of the first function. */
6722 /* Generate the line number to PC correspondence table, encoded as
6723 a series of state machine operations. */
6726 strcpy (prev_line_label, text_section_label);
6727 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6729 register dw_line_info_ref line_info = &line_info_table[lt_index];
6732 /* Disable this optimization for now; GDB wants to see two line notes
6733 at the beginning of a function so it can find the end of the
6736 /* Don't emit anything for redundant notes. Just updating the
6737 address doesn't accomplish anything, because we already assume
6738 that anything after the last address is this line. */
6739 if (line_info->dw_line_num == current_line
6740 && line_info->dw_file_num == current_file)
6744 /* Emit debug info for the address of the current line.
6746 Unfortunately, we have little choice here currently, and must always
6747 use the most general form. Gcc does not know the address delta
6748 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
6749 attributes which will give an upper bound on the address range. We
6750 could perhaps use length attributes to determine when it is safe to
6751 use DW_LNS_fixed_advance_pc. */
6753 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6756 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6757 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6758 "DW_LNS_fixed_advance_pc");
6759 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6763 /* This can handle any delta. This takes
6764 4+DWARF2_ADDR_SIZE bytes. */
6765 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6766 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6767 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6768 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6770 strcpy (prev_line_label, line_label);
6772 /* Emit debug info for the source file of the current line, if
6773 different from the previous line. */
6774 if (line_info->dw_file_num != current_file)
6776 current_file = line_info->dw_file_num;
6777 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6778 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6779 file_table.table[current_file]);
6782 /* Emit debug info for the current line number, choosing the encoding
6783 that uses the least amount of space. */
6784 if (line_info->dw_line_num != current_line)
6786 line_offset = line_info->dw_line_num - current_line;
6787 line_delta = line_offset - DWARF_LINE_BASE;
6788 current_line = line_info->dw_line_num;
6789 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6791 /* This can handle deltas from -10 to 234, using the current
6792 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6794 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6795 "line %lu", current_line);
6799 /* This can handle any delta. This takes at least 4 bytes,
6800 depending on the value being encoded. */
6801 dw2_asm_output_data (1, DW_LNS_advance_line,
6802 "advance to line %lu", current_line);
6803 dw2_asm_output_data_sleb128 (line_offset, NULL);
6804 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6809 /* We still need to start a new row, so output a copy insn. */
6810 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6814 /* Emit debug info for the address of the end of the function. */
6817 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6818 "DW_LNS_fixed_advance_pc");
6819 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
6823 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6824 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6825 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6826 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
6829 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6830 dw2_asm_output_data_uleb128 (1, NULL);
6831 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6836 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6838 register dw_separate_line_info_ref line_info
6839 = &separate_line_info_table[lt_index];
6842 /* Don't emit anything for redundant notes. */
6843 if (line_info->dw_line_num == current_line
6844 && line_info->dw_file_num == current_file
6845 && line_info->function == function)
6849 /* Emit debug info for the address of the current line. If this is
6850 a new function, or the first line of a function, then we need
6851 to handle it differently. */
6852 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6854 if (function != line_info->function)
6856 function = line_info->function;
6858 /* Set the address register to the first line in the function */
6859 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6860 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6861 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6862 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6866 /* ??? See the DW_LNS_advance_pc comment above. */
6869 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6870 "DW_LNS_fixed_advance_pc");
6871 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6875 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6876 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6877 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6878 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6881 strcpy (prev_line_label, line_label);
6883 /* Emit debug info for the source file of the current line, if
6884 different from the previous line. */
6885 if (line_info->dw_file_num != current_file)
6887 current_file = line_info->dw_file_num;
6888 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6889 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6890 file_table.table[current_file]);
6893 /* Emit debug info for the current line number, choosing the encoding
6894 that uses the least amount of space. */
6895 if (line_info->dw_line_num != current_line)
6897 line_offset = line_info->dw_line_num - current_line;
6898 line_delta = line_offset - DWARF_LINE_BASE;
6899 current_line = line_info->dw_line_num;
6900 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6901 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6902 "line %lu", current_line);
6905 dw2_asm_output_data (1, DW_LNS_advance_line,
6906 "advance to line %lu", current_line);
6907 dw2_asm_output_data_sleb128 (line_offset, NULL);
6908 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6912 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6919 /* If we're done with a function, end its sequence. */
6920 if (lt_index == separate_line_info_table_in_use
6921 || separate_line_info_table[lt_index].function != function)
6926 /* Emit debug info for the address of the end of the function. */
6927 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6930 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6931 "DW_LNS_fixed_advance_pc");
6932 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6936 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6937 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6938 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6939 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6942 /* Output the marker for the end of this sequence. */
6943 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6944 dw2_asm_output_data_uleb128 (1, NULL);
6945 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6949 /* Output the marker for the end of the line number info. */
6950 ASM_OUTPUT_LABEL (asm_out_file, l2);
6953 /* Given a pointer to a tree node for some base type, return a pointer to
6954 a DIE that describes the given type.
6956 This routine must only be called for GCC type nodes that correspond to
6957 Dwarf base (fundamental) types. */
6960 base_type_die (type)
6963 register dw_die_ref base_type_result;
6964 register const char *type_name;
6965 register enum dwarf_type encoding;
6966 register tree name = TYPE_NAME (type);
6968 if (TREE_CODE (type) == ERROR_MARK
6969 || TREE_CODE (type) == VOID_TYPE)
6974 if (TREE_CODE (name) == TYPE_DECL)
6975 name = DECL_NAME (name);
6977 type_name = IDENTIFIER_POINTER (name);
6980 type_name = "__unknown__";
6982 switch (TREE_CODE (type))
6985 /* Carefully distinguish the C character types, without messing
6986 up if the language is not C. Note that we check only for the names
6987 that contain spaces; other names might occur by coincidence in other
6989 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6990 && (type == char_type_node
6991 || ! strcmp (type_name, "signed char")
6992 || ! strcmp (type_name, "unsigned char"))))
6994 if (TREE_UNSIGNED (type))
6995 encoding = DW_ATE_unsigned;
6997 encoding = DW_ATE_signed;
7000 /* else fall through. */
7003 /* GNU Pascal/Ada CHAR type. Not used in C. */
7004 if (TREE_UNSIGNED (type))
7005 encoding = DW_ATE_unsigned_char;
7007 encoding = DW_ATE_signed_char;
7011 encoding = DW_ATE_float;
7014 /* Dwarf2 doesn't know anything about complex ints, so use
7015 a user defined type for it. */
7017 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7018 encoding = DW_ATE_complex_float;
7020 encoding = DW_ATE_lo_user;
7024 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7025 encoding = DW_ATE_boolean;
7029 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7032 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7033 if (demangle_name_func)
7034 type_name = (*demangle_name_func) (type_name);
7036 add_AT_string (base_type_result, DW_AT_name, type_name);
7037 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7038 int_size_in_bytes (type));
7039 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7041 return base_type_result;
7044 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7045 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7046 a given type is generally the same as the given type, except that if the
7047 given type is a pointer or reference type, then the root type of the given
7048 type is the root type of the "basis" type for the pointer or reference
7049 type. (This definition of the "root" type is recursive.) Also, the root
7050 type of a `const' qualified type or a `volatile' qualified type is the
7051 root type of the given type without the qualifiers. */
7057 if (TREE_CODE (type) == ERROR_MARK)
7058 return error_mark_node;
7060 switch (TREE_CODE (type))
7063 return error_mark_node;
7066 case REFERENCE_TYPE:
7067 return type_main_variant (root_type (TREE_TYPE (type)));
7070 return type_main_variant (type);
7074 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7075 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7081 switch (TREE_CODE (type))
7096 case QUAL_UNION_TYPE:
7101 case REFERENCE_TYPE:
7115 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7116 entry that chains various modifiers in front of the given type. */
7119 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7121 register int is_const_type;
7122 register int is_volatile_type;
7123 register dw_die_ref context_die;
7125 register enum tree_code code = TREE_CODE (type);
7126 register dw_die_ref mod_type_die = NULL;
7127 register dw_die_ref sub_die = NULL;
7128 register tree item_type = NULL;
7130 if (code != ERROR_MARK)
7132 tree qualified_type;
7134 /* See if we already have the appropriately qualified variant of
7137 = get_qualified_type (type,
7138 ((is_const_type ? TYPE_QUAL_CONST : 0)
7140 ? TYPE_QUAL_VOLATILE : 0)));
7141 /* If we do, then we can just use its DIE, if it exists. */
7144 mod_type_die = lookup_type_die (qualified_type);
7146 return mod_type_die;
7149 /* Handle C typedef types. */
7150 if (qualified_type && TYPE_NAME (qualified_type)
7151 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7152 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7154 tree type_name = TYPE_NAME (qualified_type);
7155 tree dtype = TREE_TYPE (type_name);
7156 if (qualified_type == dtype)
7158 /* For a named type, use the typedef. */
7159 gen_type_die (qualified_type, context_die);
7160 mod_type_die = lookup_type_die (qualified_type);
7163 else if (is_const_type < TYPE_READONLY (dtype)
7164 || is_volatile_type < TYPE_VOLATILE (dtype))
7165 /* cv-unqualified version of named type. Just use the unnamed
7166 type to which it refers. */
7168 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7169 is_const_type, is_volatile_type,
7171 /* Else cv-qualified version of named type; fall through. */
7177 else if (is_const_type)
7179 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7180 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7182 else if (is_volatile_type)
7184 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7185 sub_die = modified_type_die (type, 0, 0, context_die);
7187 else if (code == POINTER_TYPE)
7189 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7190 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7192 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7194 item_type = TREE_TYPE (type);
7196 else if (code == REFERENCE_TYPE)
7198 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7199 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7201 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7203 item_type = TREE_TYPE (type);
7205 else if (is_base_type (type))
7206 mod_type_die = base_type_die (type);
7209 gen_type_die (type, context_die);
7211 /* We have to get the type_main_variant here (and pass that to the
7212 `lookup_type_die' routine) because the ..._TYPE node we have
7213 might simply be a *copy* of some original type node (where the
7214 copy was created to help us keep track of typedef names) and
7215 that copy might have a different TYPE_UID from the original
7217 mod_type_die = lookup_type_die (type_main_variant (type));
7218 if (mod_type_die == NULL)
7222 /* We want to equate the qualified type to the die below. */
7224 type = qualified_type;
7227 equate_type_number_to_die (type, mod_type_die);
7229 /* We must do this after the equate_type_number_to_die call, in case
7230 this is a recursive type. This ensures that the modified_type_die
7231 recursion will terminate even if the type is recursive. Recursive
7232 types are possible in Ada. */
7233 sub_die = modified_type_die (item_type,
7234 TYPE_READONLY (item_type),
7235 TYPE_VOLATILE (item_type),
7238 if (sub_die != NULL)
7239 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7241 return mod_type_die;
7244 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7245 an enumerated type. */
7251 return TREE_CODE (type) == ENUMERAL_TYPE;
7254 /* Return the register number described by a given RTL node. */
7260 register unsigned regno = REGNO (rtl);
7262 if (regno >= FIRST_PSEUDO_REGISTER)
7264 warning ("internal regno botch: regno = %d\n", regno);
7268 regno = DBX_REGISTER_NUMBER (regno);
7272 /* Return a location descriptor that designates a machine register. */
7274 static dw_loc_descr_ref
7275 reg_loc_descriptor (rtl)
7278 register dw_loc_descr_ref loc_result = NULL;
7279 register unsigned reg = reg_number (rtl);
7282 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7284 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7289 /* Return a location descriptor that designates a constant. */
7291 static dw_loc_descr_ref
7292 int_loc_descriptor (i)
7295 enum dwarf_location_atom op;
7297 /* Pick the smallest representation of a constant, rather than just
7298 defaulting to the LEB encoding. */
7302 op = DW_OP_lit0 + i;
7305 else if (i <= 0xffff)
7307 else if (HOST_BITS_PER_WIDE_INT == 32
7317 else if (i >= -0x8000)
7319 else if (HOST_BITS_PER_WIDE_INT == 32
7320 || i >= -0x80000000)
7326 return new_loc_descr (op, i, 0);
7329 /* Return a location descriptor that designates a base+offset location. */
7331 static dw_loc_descr_ref
7332 based_loc_descr (reg, offset)
7336 register dw_loc_descr_ref loc_result;
7337 /* For the "frame base", we use the frame pointer or stack pointer
7338 registers, since the RTL for local variables is relative to one of
7340 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7341 ? HARD_FRAME_POINTER_REGNUM
7342 : STACK_POINTER_REGNUM);
7345 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7347 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7349 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7354 /* Return true if this RTL expression describes a base+offset calculation. */
7360 return (GET_CODE (rtl) == PLUS
7361 && ((GET_CODE (XEXP (rtl, 0)) == REG
7362 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7365 /* The following routine converts the RTL for a variable or parameter
7366 (resident in memory) into an equivalent Dwarf representation of a
7367 mechanism for getting the address of that same variable onto the top of a
7368 hypothetical "address evaluation" stack.
7370 When creating memory location descriptors, we are effectively transforming
7371 the RTL for a memory-resident object into its Dwarf postfix expression
7372 equivalent. This routine recursively descends an RTL tree, turning
7373 it into Dwarf postfix code as it goes.
7375 MODE is the mode of the memory reference, needed to handle some
7376 autoincrement addressing modes. */
7378 static dw_loc_descr_ref
7379 mem_loc_descriptor (rtl, mode)
7381 enum machine_mode mode;
7383 dw_loc_descr_ref mem_loc_result = NULL;
7384 /* Note that for a dynamically sized array, the location we will generate a
7385 description of here will be the lowest numbered location which is
7386 actually within the array. That's *not* necessarily the same as the
7387 zeroth element of the array. */
7389 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7390 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7393 switch (GET_CODE (rtl))
7398 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7399 just fall into the SUBREG code. */
7404 /* The case of a subreg may arise when we have a local (register)
7405 variable or a formal (register) parameter which doesn't quite fill
7406 up an entire register. For now, just assume that it is
7407 legitimate to make the Dwarf info refer to the whole register which
7408 contains the given subreg. */
7409 rtl = SUBREG_REG (rtl);
7414 /* Whenever a register number forms a part of the description of the
7415 method for calculating the (dynamic) address of a memory resident
7416 object, DWARF rules require the register number be referred to as
7417 a "base register". This distinction is not based in any way upon
7418 what category of register the hardware believes the given register
7419 belongs to. This is strictly DWARF terminology we're dealing with
7420 here. Note that in cases where the location of a memory-resident
7421 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7422 OP_CONST (0)) the actual DWARF location descriptor that we generate
7423 may just be OP_BASEREG (basereg). This may look deceptively like
7424 the object in question was allocated to a register (rather than in
7425 memory) so DWARF consumers need to be aware of the subtle
7426 distinction between OP_REG and OP_BASEREG. */
7427 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7431 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7432 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7436 /* Some ports can transform a symbol ref into a label ref, because
7437 the symbol ref is too far away and has to be dumped into a constant
7441 /* Alternatively, the symbol in the constant pool might be referenced
7442 by a different symbol. */
7443 if (GET_CODE (rtl) == SYMBOL_REF
7444 && CONSTANT_POOL_ADDRESS_P (rtl))
7446 rtx tmp = get_pool_constant (rtl);
7447 if (GET_CODE (tmp) == SYMBOL_REF)
7451 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7452 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7453 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7457 /* Extract the PLUS expression nested inside and fall into
7458 PLUS code bellow. */
7459 rtl = XEXP (rtl, 1);
7464 /* Turn these into a PLUS expression and fall into the PLUS code
7466 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7467 GEN_INT (GET_CODE (rtl) == PRE_INC
7468 ? GET_MODE_UNIT_SIZE (mode)
7469 : -GET_MODE_UNIT_SIZE (mode)));
7475 if (is_based_loc (rtl))
7476 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7477 INTVAL (XEXP (rtl, 1)));
7480 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7482 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7483 && INTVAL (XEXP (rtl, 1)) >= 0)
7485 add_loc_descr (&mem_loc_result,
7486 new_loc_descr (DW_OP_plus_uconst,
7487 INTVAL (XEXP (rtl, 1)), 0));
7491 add_loc_descr (&mem_loc_result,
7492 mem_loc_descriptor (XEXP (rtl, 1), mode));
7493 add_loc_descr (&mem_loc_result,
7494 new_loc_descr (DW_OP_plus, 0, 0));
7500 /* If a pseudo-reg is optimized away, it is possible for it to
7501 be replaced with a MEM containing a multiply. */
7502 add_loc_descr (&mem_loc_result,
7503 mem_loc_descriptor (XEXP (rtl, 0), mode));
7504 add_loc_descr (&mem_loc_result,
7505 mem_loc_descriptor (XEXP (rtl, 1), mode));
7506 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7510 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7517 return mem_loc_result;
7520 /* Return a descriptor that describes the concatenation of two locations.
7521 This is typically a complex variable. */
7523 static dw_loc_descr_ref
7524 concat_loc_descriptor (x0, x1)
7525 register rtx x0, x1;
7527 dw_loc_descr_ref cc_loc_result = NULL;
7529 if (!is_pseudo_reg (x0)
7530 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7531 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7532 add_loc_descr (&cc_loc_result,
7533 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7535 if (!is_pseudo_reg (x1)
7536 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7537 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7538 add_loc_descr (&cc_loc_result,
7539 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7541 return cc_loc_result;
7544 /* Output a proper Dwarf location descriptor for a variable or parameter
7545 which is either allocated in a register or in a memory location. For a
7546 register, we just generate an OP_REG and the register number. For a
7547 memory location we provide a Dwarf postfix expression describing how to
7548 generate the (dynamic) address of the object onto the address stack. */
7550 static dw_loc_descr_ref
7551 loc_descriptor (rtl)
7554 dw_loc_descr_ref loc_result = NULL;
7555 switch (GET_CODE (rtl))
7558 /* The case of a subreg may arise when we have a local (register)
7559 variable or a formal (register) parameter which doesn't quite fill
7560 up an entire register. For now, just assume that it is
7561 legitimate to make the Dwarf info refer to the whole register which
7562 contains the given subreg. */
7563 rtl = SUBREG_REG (rtl);
7568 loc_result = reg_loc_descriptor (rtl);
7572 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7576 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7586 /* Similar, but generate the descriptor from trees instead of rtl.
7587 This comes up particularly with variable length arrays. */
7589 static dw_loc_descr_ref
7590 loc_descriptor_from_tree (loc, addressp)
7594 dw_loc_descr_ref ret = NULL;
7595 int indirect_size = 0;
7596 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7597 enum dwarf_location_atom op;
7599 /* ??? Most of the time we do not take proper care for sign/zero
7600 extending the values properly. Hopefully this won't be a real
7603 switch (TREE_CODE (loc))
7608 case WITH_RECORD_EXPR:
7609 /* This case involves extracting fields from an object to determine the
7610 position of other fields. We don't try to encode this here. The
7611 only user of this is Ada, which encodes the needed information using
7612 the names of types. */
7618 rtx rtl = rtl_for_decl_location (loc);
7619 enum machine_mode mode = DECL_MODE (loc);
7621 if (rtl == NULL_RTX)
7623 else if (CONSTANT_P (rtl))
7625 ret = new_loc_descr (DW_OP_addr, 0, 0);
7626 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7627 ret->dw_loc_oprnd1.v.val_addr = rtl;
7628 indirect_size = GET_MODE_SIZE (mode);
7632 if (GET_CODE (rtl) == MEM)
7634 indirect_size = GET_MODE_SIZE (mode);
7635 rtl = XEXP (rtl, 0);
7637 ret = mem_loc_descriptor (rtl, mode);
7643 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7644 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7649 case NON_LVALUE_EXPR:
7651 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7656 case ARRAY_RANGE_REF:
7659 HOST_WIDE_INT bitsize, bitpos, bytepos;
7660 enum machine_mode mode;
7662 unsigned int alignment;
7664 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7665 &unsignedp, &volatilep, &alignment);
7666 ret = loc_descriptor_from_tree (obj, 1);
7668 if (offset != NULL_TREE)
7670 /* Variable offset. */
7671 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7672 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7677 /* We cannot address anything not on a unit boundary. */
7678 if (bitpos % BITS_PER_UNIT != 0)
7683 if (bitpos % BITS_PER_UNIT != 0
7684 || bitsize % BITS_PER_UNIT != 0)
7686 /* ??? We could handle this by loading and shifting etc.
7687 Wait until someone needs it before expending the effort. */
7691 indirect_size = bitsize / BITS_PER_UNIT;
7694 bytepos = bitpos / BITS_PER_UNIT;
7696 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7697 else if (bytepos < 0)
7699 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7700 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7706 if (host_integerp (loc, 0))
7707 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7719 case TRUNC_DIV_EXPR:
7725 case TRUNC_MOD_EXPR:
7735 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7738 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7739 && host_integerp (TREE_OPERAND (loc, 1), 0))
7741 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7742 add_loc_descr (&ret,
7743 new_loc_descr (DW_OP_plus_uconst,
7744 tree_low_cst (TREE_OPERAND (loc, 1),
7752 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7757 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7762 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7767 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7779 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7780 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7781 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7795 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7796 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7800 loc = build (COND_EXPR, TREE_TYPE (loc),
7801 build (LT_EXPR, integer_type_node,
7802 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
7803 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
7808 dw_loc_descr_ref bra_node, jump_node, tmp;
7810 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7811 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
7812 add_loc_descr (&ret, bra_node);
7814 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
7815 add_loc_descr (&ret, tmp);
7816 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
7817 add_loc_descr (&ret, jump_node);
7819 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
7820 add_loc_descr (&ret, tmp);
7821 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7822 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
7824 /* ??? Need a node to point the skip at. Use a nop. */
7825 tmp = new_loc_descr (DW_OP_nop, 0, 0);
7826 add_loc_descr (&ret, tmp);
7827 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7828 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
7836 /* If we can't fill the request for an address, die. */
7837 if (addressp && indirect_size == 0)
7840 /* If we've got an address and don't want one, dereference. */
7841 if (!addressp && indirect_size > 0)
7843 if (indirect_size > DWARF2_ADDR_SIZE)
7845 if (indirect_size == DWARF2_ADDR_SIZE)
7848 op = DW_OP_deref_size;
7849 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
7855 /* Given a value, round it up to the lowest multiple of `boundary'
7856 which is not less than the value itself. */
7858 static inline HOST_WIDE_INT
7859 ceiling (value, boundary)
7860 HOST_WIDE_INT value;
7861 unsigned int boundary;
7863 return (((value + boundary - 1) / boundary) * boundary);
7866 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7867 pointer to the declared type for the relevant field variable, or return
7868 `integer_type_node' if the given node turns out to be an
7877 if (TREE_CODE (decl) == ERROR_MARK)
7878 return integer_type_node;
7880 type = DECL_BIT_FIELD_TYPE (decl);
7881 if (type == NULL_TREE)
7882 type = TREE_TYPE (decl);
7887 /* Given a pointer to a tree node, return the alignment in bits for
7888 it, or else return BITS_PER_WORD if the node actually turns out to
7889 be an ERROR_MARK node. */
7891 static inline unsigned
7892 simple_type_align_in_bits (type)
7895 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7898 static inline unsigned
7899 simple_decl_align_in_bits (decl)
7902 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
7905 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7906 node, return the size in bits for the type if it is a constant, or else
7907 return the alignment for the type if the type's size is not constant, or
7908 else return BITS_PER_WORD if the type actually turns out to be an
7911 static inline unsigned HOST_WIDE_INT
7912 simple_type_size_in_bits (type)
7915 tree type_size_tree;
7917 if (TREE_CODE (type) == ERROR_MARK)
7918 return BITS_PER_WORD;
7919 type_size_tree = TYPE_SIZE (type);
7921 if (type_size_tree == NULL_TREE)
7923 if (! host_integerp (type_size_tree, 1))
7924 return TYPE_ALIGN (type);
7925 return tree_low_cst (type_size_tree, 1);
7928 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7929 return the byte offset of the lowest addressed byte of the "containing
7930 object" for the given FIELD_DECL, or return 0 if we are unable to
7931 determine what that offset is, either because the argument turns out to
7932 be a pointer to an ERROR_MARK node, or because the offset is actually
7933 variable. (We can't handle the latter case just yet). */
7935 static HOST_WIDE_INT
7936 field_byte_offset (decl)
7939 unsigned int type_align_in_bits;
7940 unsigned int decl_align_in_bits;
7941 unsigned HOST_WIDE_INT type_size_in_bits;
7942 HOST_WIDE_INT object_offset_in_bits;
7943 HOST_WIDE_INT object_offset_in_bytes;
7945 tree field_size_tree;
7946 HOST_WIDE_INT bitpos_int;
7947 HOST_WIDE_INT deepest_bitpos;
7948 unsigned HOST_WIDE_INT field_size_in_bits;
7950 if (TREE_CODE (decl) == ERROR_MARK)
7953 if (TREE_CODE (decl) != FIELD_DECL)
7956 type = field_type (decl);
7957 field_size_tree = DECL_SIZE (decl);
7959 /* The size could be unspecified if there was an error, or for
7960 a flexible array member. */
7961 if (! field_size_tree)
7962 field_size_tree = bitsize_zero_node;
7964 /* We cannot yet cope with fields whose positions are variable, so
7965 for now, when we see such things, we simply return 0. Someday, we may
7966 be able to handle such cases, but it will be damn difficult. */
7967 if (! host_integerp (bit_position (decl), 0))
7970 bitpos_int = int_bit_position (decl);
7972 /* If we don't know the size of the field, pretend it's a full word. */
7973 if (host_integerp (field_size_tree, 1))
7974 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7976 field_size_in_bits = BITS_PER_WORD;
7978 type_size_in_bits = simple_type_size_in_bits (type);
7979 type_align_in_bits = simple_type_align_in_bits (type);
7980 decl_align_in_bits = simple_decl_align_in_bits (decl);
7982 /* Note that the GCC front-end doesn't make any attempt to keep track of
7983 the starting bit offset (relative to the start of the containing
7984 structure type) of the hypothetical "containing object" for a bit-
7985 field. Thus, when computing the byte offset value for the start of the
7986 "containing object" of a bit-field, we must deduce this information on
7987 our own. This can be rather tricky to do in some cases. For example,
7988 handling the following structure type definition when compiling for an
7989 i386/i486 target (which only aligns long long's to 32-bit boundaries)
7992 struct S { int field1; long long field2:31; };
7994 Fortunately, there is a simple rule-of-thumb which can be
7995 used in such cases. When compiling for an i386/i486, GCC will allocate
7996 8 bytes for the structure shown above. It decides to do this based upon
7997 one simple rule for bit-field allocation. Quite simply, GCC allocates
7998 each "containing object" for each bit-field at the first (i.e. lowest
7999 addressed) legitimate alignment boundary (based upon the required
8000 minimum alignment for the declared type of the field) which it can
8001 possibly use, subject to the condition that there is still enough
8002 available space remaining in the containing object (when allocated at
8003 the selected point) to fully accommodate all of the bits of the
8004 bit-field itself. This simple rule makes it obvious why GCC allocates
8005 8 bytes for each object of the structure type shown above. When looking
8006 for a place to allocate the "containing object" for `field2', the
8007 compiler simply tries to allocate a 64-bit "containing object" at each
8008 successive 32-bit boundary (starting at zero) until it finds a place to
8009 allocate that 64- bit field such that at least 31 contiguous (and
8010 previously unallocated) bits remain within that selected 64 bit field.
8011 (As it turns out, for the example above, the compiler finds that it is
8012 OK to allocate the "containing object" 64-bit field at bit-offset zero
8013 within the structure type.) Here we attempt to work backwards from the
8014 limited set of facts we're given, and we try to deduce from those facts,
8015 where GCC must have believed that the containing object started (within
8016 the structure type). The value we deduce is then used (by the callers of
8017 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8018 for fields (both bit-fields and, in the case of DW_AT_location, regular
8021 /* Figure out the bit-distance from the start of the structure to the
8022 "deepest" bit of the bit-field. */
8023 deepest_bitpos = bitpos_int + field_size_in_bits;
8025 /* This is the tricky part. Use some fancy footwork to deduce where the
8026 lowest addressed bit of the containing object must be. */
8027 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8029 /* Round up to type_align by default. This works best for bitfields. */
8030 object_offset_in_bits += type_align_in_bits - 1;
8031 object_offset_in_bits /= type_align_in_bits;
8032 object_offset_in_bits *= type_align_in_bits;
8034 if (object_offset_in_bits > bitpos_int)
8036 /* Sigh, the decl must be packed. */
8037 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8039 /* Round up to decl_align instead. */
8040 object_offset_in_bits += decl_align_in_bits - 1;
8041 object_offset_in_bits /= decl_align_in_bits;
8042 object_offset_in_bits *= decl_align_in_bits;
8045 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8047 return object_offset_in_bytes;
8050 /* The following routines define various Dwarf attributes and any data
8051 associated with them. */
8053 /* Add a location description attribute value to a DIE.
8055 This emits location attributes suitable for whole variables and
8056 whole parameters. Note that the location attributes for struct fields are
8057 generated by the routine `data_member_location_attribute' below. */
8060 add_AT_location_description (die, attr_kind, rtl)
8062 enum dwarf_attribute attr_kind;
8065 /* Handle a special case. If we are about to output a location descriptor
8066 for a variable or parameter which has been optimized out of existence,
8067 don't do that. A variable which has been optimized out
8068 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8069 Currently, in some rare cases, variables can have DECL_RTL values which
8070 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8071 elsewhere in the compiler. We treat such cases as if the variable(s) in
8072 question had been optimized out of existence. */
8074 if (is_pseudo_reg (rtl)
8075 || (GET_CODE (rtl) == MEM
8076 && is_pseudo_reg (XEXP (rtl, 0)))
8077 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8078 references the internal argument pointer (a pseudo) in a function
8079 where all references to the internal argument pointer were
8080 eliminated via the optimizers. */
8081 || (GET_CODE (rtl) == MEM
8082 && GET_CODE (XEXP (rtl, 0)) == PLUS
8083 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8084 || (GET_CODE (rtl) == CONCAT
8085 && is_pseudo_reg (XEXP (rtl, 0))
8086 && is_pseudo_reg (XEXP (rtl, 1))))
8089 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8092 /* Attach the specialized form of location attribute used for data
8093 members of struct and union types. In the special case of a
8094 FIELD_DECL node which represents a bit-field, the "offset" part
8095 of this special location descriptor must indicate the distance
8096 in bytes from the lowest-addressed byte of the containing struct
8097 or union type to the lowest-addressed byte of the "containing
8098 object" for the bit-field. (See the `field_byte_offset' function
8099 above).. For any given bit-field, the "containing object" is a
8100 hypothetical object (of some integral or enum type) within which
8101 the given bit-field lives. The type of this hypothetical
8102 "containing object" is always the same as the declared type of
8103 the individual bit-field itself (for GCC anyway... the DWARF
8104 spec doesn't actually mandate this). Note that it is the size
8105 (in bytes) of the hypothetical "containing object" which will
8106 be given in the DW_AT_byte_size attribute for this bit-field.
8107 (See the `byte_size_attribute' function below.) It is also used
8108 when calculating the value of the DW_AT_bit_offset attribute.
8109 (See the `bit_offset_attribute' function below). */
8112 add_data_member_location_attribute (die, decl)
8113 register dw_die_ref die;
8116 register unsigned long offset;
8117 register dw_loc_descr_ref loc_descr;
8118 register enum dwarf_location_atom op;
8120 if (TREE_CODE (decl) == TREE_VEC)
8121 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8123 offset = field_byte_offset (decl);
8125 /* The DWARF2 standard says that we should assume that the structure address
8126 is already on the stack, so we can specify a structure field address
8127 by using DW_OP_plus_uconst. */
8129 #ifdef MIPS_DEBUGGING_INFO
8130 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8131 correctly. It works only if we leave the offset on the stack. */
8134 op = DW_OP_plus_uconst;
8137 loc_descr = new_loc_descr (op, offset, 0);
8138 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8141 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8142 does not have a "location" either in memory or in a register. These
8143 things can arise in GNU C when a constant is passed as an actual parameter
8144 to an inlined function. They can also arise in C++ where declared
8145 constants do not necessarily get memory "homes". */
8148 add_const_value_attribute (die, rtl)
8149 register dw_die_ref die;
8152 switch (GET_CODE (rtl))
8155 /* Note that a CONST_INT rtx could represent either an integer
8156 or a floating-point constant. A CONST_INT is used whenever
8157 the constant will fit into a single word. In all such
8158 cases, the original mode of the constant value is wiped
8159 out, and the CONST_INT rtx is assigned VOIDmode. */
8161 HOST_WIDE_INT val = INTVAL (rtl);
8163 /* ??? We really should be using HOST_WIDE_INT throughout. */
8166 if ((long) val != val)
8168 add_AT_int (die, DW_AT_const_value, (long) val);
8172 if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
8174 add_AT_int (die, DW_AT_const_value, (unsigned long) val);
8180 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8181 floating-point constant. A CONST_DOUBLE is used whenever the
8182 constant requires more than one word in order to be adequately
8183 represented. We output CONST_DOUBLEs as blocks. */
8185 register enum machine_mode mode = GET_MODE (rtl);
8187 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8189 register unsigned length = GET_MODE_SIZE (mode) / 4;
8190 long *array = (long *) xmalloc (sizeof (long) * length);
8193 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8197 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8201 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8206 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8213 add_AT_float (die, DW_AT_const_value, length, array);
8217 /* ??? We really should be using HOST_WIDE_INT throughout. */
8218 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8220 add_AT_long_long (die, DW_AT_const_value,
8221 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8227 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8233 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8237 /* In cases where an inlined instance of an inline function is passed
8238 the address of an `auto' variable (which is local to the caller) we
8239 can get a situation where the DECL_RTL of the artificial local
8240 variable (for the inlining) which acts as a stand-in for the
8241 corresponding formal parameter (of the inline function) will look
8242 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8243 exactly a compile-time constant expression, but it isn't the address
8244 of the (artificial) local variable either. Rather, it represents the
8245 *value* which the artificial local variable always has during its
8246 lifetime. We currently have no way to represent such quasi-constant
8247 values in Dwarf, so for now we just punt and generate nothing. */
8251 /* No other kinds of rtx should be possible here. */
8258 rtl_for_decl_location (decl)
8263 /* Here we have to decide where we are going to say the parameter "lives"
8264 (as far as the debugger is concerned). We only have a couple of
8265 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8267 DECL_RTL normally indicates where the parameter lives during most of the
8268 activation of the function. If optimization is enabled however, this
8269 could be either NULL or else a pseudo-reg. Both of those cases indicate
8270 that the parameter doesn't really live anywhere (as far as the code
8271 generation parts of GCC are concerned) during most of the function's
8272 activation. That will happen (for example) if the parameter is never
8273 referenced within the function.
8275 We could just generate a location descriptor here for all non-NULL
8276 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8277 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8278 where DECL_RTL is NULL or is a pseudo-reg.
8280 Note however that we can only get away with using DECL_INCOMING_RTL as
8281 a backup substitute for DECL_RTL in certain limited cases. In cases
8282 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8283 we can be sure that the parameter was passed using the same type as it is
8284 declared to have within the function, and that its DECL_INCOMING_RTL
8285 points us to a place where a value of that type is passed.
8287 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8288 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8289 because in these cases DECL_INCOMING_RTL points us to a value of some
8290 type which is *different* from the type of the parameter itself. Thus,
8291 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8292 such cases, the debugger would end up (for example) trying to fetch a
8293 `float' from a place which actually contains the first part of a
8294 `double'. That would lead to really incorrect and confusing
8295 output at debug-time.
8297 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8298 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8299 are a couple of exceptions however. On little-endian machines we can
8300 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8301 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8302 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8303 when (on a little-endian machine) a non-prototyped function has a
8304 parameter declared to be of type `short' or `char'. In such cases,
8305 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8306 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8307 passed `int' value. If the debugger then uses that address to fetch
8308 a `short' or a `char' (on a little-endian machine) the result will be
8309 the correct data, so we allow for such exceptional cases below.
8311 Note that our goal here is to describe the place where the given formal
8312 parameter lives during most of the function's activation (i.e. between
8313 the end of the prologue and the start of the epilogue). We'll do that
8314 as best as we can. Note however that if the given formal parameter is
8315 modified sometime during the execution of the function, then a stack
8316 backtrace (at debug-time) will show the function as having been
8317 called with the *new* value rather than the value which was
8318 originally passed in. This happens rarely enough that it is not
8319 a major problem, but it *is* a problem, and I'd like to fix it.
8321 A future version of dwarf2out.c may generate two additional
8322 attributes for any given DW_TAG_formal_parameter DIE which will
8323 describe the "passed type" and the "passed location" for the
8324 given formal parameter in addition to the attributes we now
8325 generate to indicate the "declared type" and the "active
8326 location" for each parameter. This additional set of attributes
8327 could be used by debuggers for stack backtraces. Separately, note
8328 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8329 NULL also. This happens (for example) for inlined-instances of
8330 inline function formal parameters which are never referenced.
8331 This really shouldn't be happening. All PARM_DECL nodes should
8332 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8333 doesn't currently generate these values for inlined instances of
8334 inline function parameters, so when we see such cases, we are
8335 just out-of-luck for the time being (until integrate.c
8338 /* Use DECL_RTL as the "location" unless we find something better. */
8339 rtl = DECL_RTL_IF_SET (decl);
8341 if (TREE_CODE (decl) == PARM_DECL)
8343 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8345 tree declared_type = type_main_variant (TREE_TYPE (decl));
8346 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8348 /* This decl represents a formal parameter which was optimized out.
8349 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8350 all* cases where (rtl == NULL_RTX) just below. */
8351 if (declared_type == passed_type)
8352 rtl = DECL_INCOMING_RTL (decl);
8353 else if (! BYTES_BIG_ENDIAN
8354 && TREE_CODE (declared_type) == INTEGER_TYPE
8355 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8356 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8357 rtl = DECL_INCOMING_RTL (decl);
8360 /* If the parm was passed in registers, but lives on the stack, then
8361 make a big endian correction if the mode of the type of the
8362 parameter is not the same as the mode of the rtl. */
8363 /* ??? This is the same series of checks that are made in dbxout.c before
8364 we reach the big endian correction code there. It isn't clear if all
8365 of these checks are necessary here, but keeping them all is the safe
8367 else if (GET_CODE (rtl) == MEM
8368 && XEXP (rtl, 0) != const0_rtx
8369 && ! CONSTANT_P (XEXP (rtl, 0))
8370 /* Not passed in memory. */
8371 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8372 /* Not passed by invisible reference. */
8373 && (GET_CODE (XEXP (rtl, 0)) != REG
8374 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8375 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8376 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8377 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8380 /* Big endian correction check. */
8382 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8383 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8386 int offset = (UNITS_PER_WORD
8387 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8388 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8389 plus_constant (XEXP (rtl, 0), offset));
8393 if (rtl != NULL_RTX)
8395 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8396 #ifdef LEAF_REG_REMAP
8397 if (current_function_uses_only_leaf_regs)
8398 leaf_renumber_regs_insn (rtl);
8405 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8406 data attribute for a variable or a parameter. We generate the
8407 DW_AT_const_value attribute only in those cases where the given variable
8408 or parameter does not have a true "location" either in memory or in a
8409 register. This can happen (for example) when a constant is passed as an
8410 actual argument in a call to an inline function. (It's possible that
8411 these things can crop up in other ways also.) Note that one type of
8412 constant value which can be passed into an inlined function is a constant
8413 pointer. This can happen for example if an actual argument in an inlined
8414 function call evaluates to a compile-time constant address. */
8417 add_location_or_const_value_attribute (die, decl)
8418 register dw_die_ref die;
8423 if (TREE_CODE (decl) == ERROR_MARK)
8426 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8429 rtl = rtl_for_decl_location (decl);
8430 if (rtl == NULL_RTX)
8433 switch (GET_CODE (rtl))
8436 /* The address of a variable that was optimized away; don't emit
8447 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8448 add_const_value_attribute (die, rtl);
8455 add_AT_location_description (die, DW_AT_location, rtl);
8463 /* If we don't have a copy of this variable in memory for some reason (such
8464 as a C++ member constant that doesn't have an out-of-line definition),
8465 we should tell the debugger about the constant value. */
8468 tree_add_const_value_attribute (var_die, decl)
8472 tree init = DECL_INITIAL (decl);
8473 tree type = TREE_TYPE (decl);
8475 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8476 && initializer_constant_valid_p (init, type) == null_pointer_node)
8481 switch (TREE_CODE (type))
8484 if (host_integerp (init, 0))
8485 add_AT_unsigned (var_die, DW_AT_const_value,
8486 TREE_INT_CST_LOW (init));
8488 add_AT_long_long (var_die, DW_AT_const_value,
8489 TREE_INT_CST_HIGH (init),
8490 TREE_INT_CST_LOW (init));
8497 /* Generate an DW_AT_name attribute given some string value to be included as
8498 the value of the attribute. */
8501 add_name_attribute (die, name_string)
8502 register dw_die_ref die;
8503 register const char *name_string;
8505 if (name_string != NULL && *name_string != 0)
8507 if (demangle_name_func)
8508 name_string = (*demangle_name_func) (name_string);
8510 add_AT_string (die, DW_AT_name, name_string);
8514 /* Given a tree node describing an array bound (either lower or upper) output
8515 a representation for that bound. */
8518 add_bound_info (subrange_die, bound_attr, bound)
8519 register dw_die_ref subrange_die;
8520 register enum dwarf_attribute bound_attr;
8521 register tree bound;
8523 /* If this is an Ada unconstrained array type, then don't emit any debug
8524 info because the array bounds are unknown. They are parameterized when
8525 the type is instantiated. */
8526 if (contains_placeholder_p (bound))
8529 switch (TREE_CODE (bound))
8534 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8536 if (! host_integerp (bound, 0)
8537 || (bound_attr == DW_AT_lower_bound
8538 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8539 || (is_fortran () && integer_onep (bound)))))
8540 /* use the default */
8543 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8548 case NON_LVALUE_EXPR:
8549 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8553 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8554 access the upper bound values may be bogus. If they refer to a
8555 register, they may only describe how to get at these values at the
8556 points in the generated code right after they have just been
8557 computed. Worse yet, in the typical case, the upper bound values
8558 will not even *be* computed in the optimized code (though the
8559 number of elements will), so these SAVE_EXPRs are entirely
8560 bogus. In order to compensate for this fact, we check here to see
8561 if optimization is enabled, and if so, we don't add an attribute
8562 for the (unknown and unknowable) upper bound. This should not
8563 cause too much trouble for existing (stupid?) debuggers because
8564 they have to deal with empty upper bounds location descriptions
8565 anyway in order to be able to deal with incomplete array types.
8566 Of course an intelligent debugger (GDB?) should be able to
8567 comprehend that a missing upper bound specification in a array
8568 type used for a storage class `auto' local array variable
8569 indicates that the upper bound is both unknown (at compile- time)
8570 and unknowable (at run-time) due to optimization.
8572 We assume that a MEM rtx is safe because gcc wouldn't put the
8573 value there unless it was going to be used repeatedly in the
8574 function, i.e. for cleanups. */
8575 if (SAVE_EXPR_RTL (bound)
8576 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8578 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8579 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8580 register rtx loc = SAVE_EXPR_RTL (bound);
8582 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8583 it references an outer function's frame. */
8585 if (GET_CODE (loc) == MEM)
8587 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8589 if (XEXP (loc, 0) != new_addr)
8590 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8593 add_AT_flag (decl_die, DW_AT_artificial, 1);
8594 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8595 add_AT_location_description (decl_die, DW_AT_location, loc);
8596 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8599 /* Else leave out the attribute. */
8605 dw_die_ref decl_die = lookup_decl_die (bound);
8607 /* ??? Can this happen, or should the variable have been bound
8608 first? Probably it can, since I imagine that we try to create
8609 the types of parameters in the order in which they exist in
8610 the list, and won't have created a forward reference to a
8612 if (decl_die != NULL)
8613 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8619 /* Otherwise try to create a stack operation procedure to
8620 evaluate the value of the array bound. */
8622 dw_die_ref ctx, decl_die;
8623 dw_loc_descr_ref loc;
8625 loc = loc_descriptor_from_tree (bound, 0);
8629 ctx = lookup_decl_die (current_function_decl);
8631 decl_die = new_die (DW_TAG_variable, ctx);
8632 add_AT_flag (decl_die, DW_AT_artificial, 1);
8633 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8634 add_AT_loc (decl_die, DW_AT_location, loc);
8636 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8642 /* Note that the block of subscript information for an array type also
8643 includes information about the element type of type given array type. */
8646 add_subscript_info (type_die, type)
8647 register dw_die_ref type_die;
8650 #ifndef MIPS_DEBUGGING_INFO
8651 register unsigned dimension_number;
8653 register tree lower, upper;
8654 register dw_die_ref subrange_die;
8656 /* The GNU compilers represent multidimensional array types as sequences of
8657 one dimensional array types whose element types are themselves array
8658 types. Here we squish that down, so that each multidimensional array
8659 type gets only one array_type DIE in the Dwarf debugging info. The draft
8660 Dwarf specification say that we are allowed to do this kind of
8661 compression in C (because there is no difference between an array or
8662 arrays and a multidimensional array in C) but for other source languages
8663 (e.g. Ada) we probably shouldn't do this. */
8665 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8666 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8667 We work around this by disabling this feature. See also
8668 gen_array_type_die. */
8669 #ifndef MIPS_DEBUGGING_INFO
8670 for (dimension_number = 0;
8671 TREE_CODE (type) == ARRAY_TYPE;
8672 type = TREE_TYPE (type), dimension_number++)
8675 register tree domain = TYPE_DOMAIN (type);
8677 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8678 and (in GNU C only) variable bounds. Handle all three forms
8680 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8683 /* We have an array type with specified bounds. */
8684 lower = TYPE_MIN_VALUE (domain);
8685 upper = TYPE_MAX_VALUE (domain);
8687 /* define the index type. */
8688 if (TREE_TYPE (domain))
8690 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8691 TREE_TYPE field. We can't emit debug info for this
8692 because it is an unnamed integral type. */
8693 if (TREE_CODE (domain) == INTEGER_TYPE
8694 && TYPE_NAME (domain) == NULL_TREE
8695 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8696 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8699 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8703 /* ??? If upper is NULL, the array has unspecified length,
8704 but it does have a lower bound. This happens with Fortran
8706 Since the debugger is definitely going to need to know N
8707 to produce useful results, go ahead and output the lower
8708 bound solo, and hope the debugger can cope. */
8710 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8712 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8715 /* We have an array type with an unspecified length. The DWARF-2
8716 spec does not say how to handle this; let's just leave out the
8720 #ifndef MIPS_DEBUGGING_INFO
8726 add_byte_size_attribute (die, tree_node)
8728 register tree tree_node;
8730 register unsigned size;
8732 switch (TREE_CODE (tree_node))
8740 case QUAL_UNION_TYPE:
8741 size = int_size_in_bytes (tree_node);
8744 /* For a data member of a struct or union, the DW_AT_byte_size is
8745 generally given as the number of bytes normally allocated for an
8746 object of the *declared* type of the member itself. This is true
8747 even for bit-fields. */
8748 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8754 /* Note that `size' might be -1 when we get to this point. If it is, that
8755 indicates that the byte size of the entity in question is variable. We
8756 have no good way of expressing this fact in Dwarf at the present time,
8757 so just let the -1 pass on through. */
8759 add_AT_unsigned (die, DW_AT_byte_size, size);
8762 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8763 which specifies the distance in bits from the highest order bit of the
8764 "containing object" for the bit-field to the highest order bit of the
8767 For any given bit-field, the "containing object" is a hypothetical
8768 object (of some integral or enum type) within which the given bit-field
8769 lives. The type of this hypothetical "containing object" is always the
8770 same as the declared type of the individual bit-field itself. The
8771 determination of the exact location of the "containing object" for a
8772 bit-field is rather complicated. It's handled by the
8773 `field_byte_offset' function (above).
8775 Note that it is the size (in bytes) of the hypothetical "containing object"
8776 which will be given in the DW_AT_byte_size attribute for this bit-field.
8777 (See `byte_size_attribute' above). */
8780 add_bit_offset_attribute (die, decl)
8781 register dw_die_ref die;
8784 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8785 tree type = DECL_BIT_FIELD_TYPE (decl);
8786 HOST_WIDE_INT bitpos_int;
8787 HOST_WIDE_INT highest_order_object_bit_offset;
8788 HOST_WIDE_INT highest_order_field_bit_offset;
8789 HOST_WIDE_INT unsigned bit_offset;
8791 /* Must be a field and a bit field. */
8793 || TREE_CODE (decl) != FIELD_DECL)
8796 /* We can't yet handle bit-fields whose offsets are variable, so if we
8797 encounter such things, just return without generating any attribute
8798 whatsoever. Likewise for variable or too large size. */
8799 if (! host_integerp (bit_position (decl), 0)
8800 || ! host_integerp (DECL_SIZE (decl), 1))
8803 bitpos_int = int_bit_position (decl);
8805 /* Note that the bit offset is always the distance (in bits) from the
8806 highest-order bit of the "containing object" to the highest-order bit of
8807 the bit-field itself. Since the "high-order end" of any object or field
8808 is different on big-endian and little-endian machines, the computation
8809 below must take account of these differences. */
8810 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8811 highest_order_field_bit_offset = bitpos_int;
8813 if (! BYTES_BIG_ENDIAN)
8815 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8816 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8820 = (! BYTES_BIG_ENDIAN
8821 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8822 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8824 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8827 /* For a FIELD_DECL node which represents a bit field, output an attribute
8828 which specifies the length in bits of the given field. */
8831 add_bit_size_attribute (die, decl)
8832 register dw_die_ref die;
8835 /* Must be a field and a bit field. */
8836 if (TREE_CODE (decl) != FIELD_DECL
8837 || ! DECL_BIT_FIELD_TYPE (decl))
8840 if (host_integerp (DECL_SIZE (decl), 1))
8841 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8844 /* If the compiled language is ANSI C, then add a 'prototyped'
8845 attribute, if arg types are given for the parameters of a function. */
8848 add_prototyped_attribute (die, func_type)
8849 register dw_die_ref die;
8850 register tree func_type;
8852 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8853 && TYPE_ARG_TYPES (func_type) != NULL)
8854 add_AT_flag (die, DW_AT_prototyped, 1);
8857 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8858 by looking in either the type declaration or object declaration
8862 add_abstract_origin_attribute (die, origin)
8863 register dw_die_ref die;
8864 register tree origin;
8866 dw_die_ref origin_die = NULL;
8868 if (TREE_CODE (origin) != FUNCTION_DECL)
8870 /* We may have gotten separated from the block for the inlined
8871 function, if we're in an exception handler or some such; make
8872 sure that the abstract function has been written out.
8874 Doing this for nested functions is wrong, however; functions are
8875 distinct units, and our context might not even be inline. */
8878 fn = TYPE_STUB_DECL (fn);
8879 fn = decl_function_context (fn);
8881 dwarf2out_abstract_function (fn);
8884 if (DECL_P (origin))
8885 origin_die = lookup_decl_die (origin);
8886 else if (TYPE_P (origin))
8887 origin_die = lookup_type_die (origin);
8889 if (origin_die == NULL)
8892 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8895 /* We do not currently support the pure_virtual attribute. */
8898 add_pure_or_virtual_attribute (die, func_decl)
8899 register dw_die_ref die;
8900 register tree func_decl;
8902 if (DECL_VINDEX (func_decl))
8904 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8906 if (host_integerp (DECL_VINDEX (func_decl), 0))
8907 add_AT_loc (die, DW_AT_vtable_elem_location,
8908 new_loc_descr (DW_OP_constu,
8909 tree_low_cst (DECL_VINDEX (func_decl), 0),
8912 /* GNU extension: Record what type this method came from originally. */
8913 if (debug_info_level > DINFO_LEVEL_TERSE)
8914 add_AT_die_ref (die, DW_AT_containing_type,
8915 lookup_type_die (DECL_CONTEXT (func_decl)));
8919 /* Add source coordinate attributes for the given decl. */
8922 add_src_coords_attributes (die, decl)
8923 register dw_die_ref die;
8926 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
8928 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8929 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8932 /* Add an DW_AT_name attribute and source coordinate attribute for the
8933 given decl, but only if it actually has a name. */
8936 add_name_and_src_coords_attributes (die, decl)
8937 register dw_die_ref die;
8940 register tree decl_name;
8942 decl_name = DECL_NAME (decl);
8943 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8945 add_name_attribute (die, dwarf2_name (decl, 0));
8946 if (! DECL_ARTIFICIAL (decl))
8947 add_src_coords_attributes (die, decl);
8949 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8950 && TREE_PUBLIC (decl)
8951 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
8952 && !DECL_ABSTRACT (decl))
8953 add_AT_string (die, DW_AT_MIPS_linkage_name,
8954 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8958 /* Push a new declaration scope. */
8961 push_decl_scope (scope)
8964 /* Make room in the decl_scope_table, if necessary. */
8965 if (decl_scope_table_allocated == decl_scope_depth)
8967 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
8969 = (tree *) xrealloc (decl_scope_table,
8970 decl_scope_table_allocated * sizeof (tree));
8973 decl_scope_table[decl_scope_depth] = scope;
8977 /* Pop a declaration scope. */
8981 if (decl_scope_depth <= 0)
8986 /* Return the DIE for the scope that immediately contains this type.
8987 Non-named types get global scope. Named types nested in other
8988 types get their containing scope if it's open, or global scope
8989 otherwise. All other types (i.e. function-local named types) get
8990 the current active scope. */
8993 scope_die_for (t, context_die)
8995 register dw_die_ref context_die;
8997 register dw_die_ref scope_die = NULL;
8998 register tree containing_scope;
9001 /* Non-types always go in the current scope. */
9005 containing_scope = TYPE_CONTEXT (t);
9007 /* Ignore namespaces for the moment. */
9008 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9009 containing_scope = NULL_TREE;
9011 /* Ignore function type "scopes" from the C frontend. They mean that
9012 a tagged type is local to a parmlist of a function declarator, but
9013 that isn't useful to DWARF. */
9014 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9015 containing_scope = NULL_TREE;
9017 if (containing_scope == NULL_TREE)
9018 scope_die = comp_unit_die;
9019 else if (TYPE_P (containing_scope))
9021 /* For types, we can just look up the appropriate DIE. But
9022 first we check to see if we're in the middle of emitting it
9023 so we know where the new DIE should go. */
9025 for (i = decl_scope_depth - 1; i >= 0; --i)
9026 if (decl_scope_table[i] == containing_scope)
9031 if (debug_info_level > DINFO_LEVEL_TERSE
9032 && !TREE_ASM_WRITTEN (containing_scope))
9035 /* If none of the current dies are suitable, we get file scope. */
9036 scope_die = comp_unit_die;
9039 scope_die = lookup_type_die (containing_scope);
9042 scope_die = context_die;
9047 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9049 static inline int local_scope_p PARAMS ((dw_die_ref));
9051 local_scope_p (context_die)
9052 dw_die_ref context_die;
9054 for (; context_die; context_die = context_die->die_parent)
9055 if (context_die->die_tag == DW_TAG_inlined_subroutine
9056 || context_die->die_tag == DW_TAG_subprogram)
9061 /* Returns nonzero iff CONTEXT_DIE is a class. */
9063 static inline int class_scope_p PARAMS ((dw_die_ref));
9065 class_scope_p (context_die)
9066 dw_die_ref context_die;
9069 && (context_die->die_tag == DW_TAG_structure_type
9070 || context_die->die_tag == DW_TAG_union_type));
9073 /* Many forms of DIEs require a "type description" attribute. This
9074 routine locates the proper "type descriptor" die for the type given
9075 by 'type', and adds an DW_AT_type attribute below the given die. */
9078 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9079 register dw_die_ref object_die;
9081 register int decl_const;
9082 register int decl_volatile;
9083 register dw_die_ref context_die;
9085 register enum tree_code code = TREE_CODE (type);
9086 register dw_die_ref type_die = NULL;
9088 /* ??? If this type is an unnamed subrange type of an integral or
9089 floating-point type, use the inner type. This is because we have no
9090 support for unnamed types in base_type_die. This can happen if this is
9091 an Ada subrange type. Correct solution is emit a subrange type die. */
9092 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9093 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9094 type = TREE_TYPE (type), code = TREE_CODE (type);
9096 if (code == ERROR_MARK)
9099 /* Handle a special case. For functions whose return type is void, we
9100 generate *no* type attribute. (Note that no object may have type
9101 `void', so this only applies to function return types). */
9102 if (code == VOID_TYPE)
9105 type_die = modified_type_die (type,
9106 decl_const || TYPE_READONLY (type),
9107 decl_volatile || TYPE_VOLATILE (type),
9109 if (type_die != NULL)
9110 add_AT_die_ref (object_die, DW_AT_type, type_die);
9113 /* Given a tree pointer to a struct, class, union, or enum type node, return
9114 a pointer to the (string) tag name for the given type, or zero if the type
9115 was declared without a tag. */
9121 register const char *name = 0;
9123 if (TYPE_NAME (type) != 0)
9125 register tree t = 0;
9127 /* Find the IDENTIFIER_NODE for the type name. */
9128 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9129 t = TYPE_NAME (type);
9131 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9132 a TYPE_DECL node, regardless of whether or not a `typedef' was
9134 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9135 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9136 t = DECL_NAME (TYPE_NAME (type));
9138 /* Now get the name as a string, or invent one. */
9140 name = IDENTIFIER_POINTER (t);
9143 return (name == 0 || *name == '\0') ? 0 : name;
9146 /* Return the type associated with a data member, make a special check
9147 for bit field types. */
9150 member_declared_type (member)
9151 register tree member;
9153 return (DECL_BIT_FIELD_TYPE (member)
9154 ? DECL_BIT_FIELD_TYPE (member)
9155 : TREE_TYPE (member));
9158 /* Get the decl's label, as described by its RTL. This may be different
9159 from the DECL_NAME name used in the source file. */
9163 decl_start_label (decl)
9168 x = DECL_RTL (decl);
9169 if (GET_CODE (x) != MEM)
9173 if (GET_CODE (x) != SYMBOL_REF)
9176 fnname = XSTR (x, 0);
9181 /* These routines generate the internal representation of the DIE's for
9182 the compilation unit. Debugging information is collected by walking
9183 the declaration trees passed in from dwarf2out_decl(). */
9186 gen_array_type_die (type, context_die)
9188 register dw_die_ref context_die;
9190 register dw_die_ref scope_die = scope_die_for (type, context_die);
9191 register dw_die_ref array_die;
9192 register tree element_type;
9194 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9195 the inner array type comes before the outer array type. Thus we must
9196 call gen_type_die before we call new_die. See below also. */
9197 #ifdef MIPS_DEBUGGING_INFO
9198 gen_type_die (TREE_TYPE (type), context_die);
9201 array_die = new_die (DW_TAG_array_type, scope_die);
9204 /* We default the array ordering. SDB will probably do
9205 the right things even if DW_AT_ordering is not present. It's not even
9206 an issue until we start to get into multidimensional arrays anyway. If
9207 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9208 then we'll have to put the DW_AT_ordering attribute back in. (But if
9209 and when we find out that we need to put these in, we will only do so
9210 for multidimensional arrays. */
9211 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9214 #ifdef MIPS_DEBUGGING_INFO
9215 /* The SGI compilers handle arrays of unknown bound by setting
9216 AT_declaration and not emitting any subrange DIEs. */
9217 if (! TYPE_DOMAIN (type))
9218 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9221 add_subscript_info (array_die, type);
9223 add_name_attribute (array_die, type_tag (type));
9224 equate_type_number_to_die (type, array_die);
9226 /* Add representation of the type of the elements of this array type. */
9227 element_type = TREE_TYPE (type);
9229 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9230 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9231 We work around this by disabling this feature. See also
9232 add_subscript_info. */
9233 #ifndef MIPS_DEBUGGING_INFO
9234 while (TREE_CODE (element_type) == ARRAY_TYPE)
9235 element_type = TREE_TYPE (element_type);
9237 gen_type_die (element_type, context_die);
9240 add_type_attribute (array_die, element_type, 0, 0, context_die);
9244 gen_set_type_die (type, context_die)
9246 register dw_die_ref context_die;
9248 register dw_die_ref type_die
9249 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9251 equate_type_number_to_die (type, type_die);
9252 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9257 gen_entry_point_die (decl, context_die)
9259 register dw_die_ref context_die;
9261 register tree origin = decl_ultimate_origin (decl);
9262 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9264 add_abstract_origin_attribute (decl_die, origin);
9267 add_name_and_src_coords_attributes (decl_die, decl);
9268 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9272 if (DECL_ABSTRACT (decl))
9273 equate_decl_number_to_die (decl, decl_die);
9275 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9279 /* Remember a type in the incomplete_types_list. */
9282 add_incomplete_type (type)
9285 if (incomplete_types == incomplete_types_allocated)
9287 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9288 incomplete_types_list
9289 = (tree *) xrealloc (incomplete_types_list,
9290 sizeof (tree) * incomplete_types_allocated);
9293 incomplete_types_list[incomplete_types++] = type;
9296 /* Walk through the list of incomplete types again, trying once more to
9297 emit full debugging info for them. */
9300 retry_incomplete_types ()
9304 while (incomplete_types)
9307 type = incomplete_types_list[incomplete_types];
9308 gen_type_die (type, comp_unit_die);
9312 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9315 gen_inlined_enumeration_type_die (type, context_die)
9317 register dw_die_ref context_die;
9319 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9321 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9322 be incomplete and such types are not marked. */
9323 add_abstract_origin_attribute (type_die, type);
9326 /* Generate a DIE to represent an inlined instance of a structure type. */
9329 gen_inlined_structure_type_die (type, context_die)
9331 register dw_die_ref context_die;
9333 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9335 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9336 be incomplete and such types are not marked. */
9337 add_abstract_origin_attribute (type_die, type);
9340 /* Generate a DIE to represent an inlined instance of a union type. */
9343 gen_inlined_union_type_die (type, context_die)
9345 register dw_die_ref context_die;
9347 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9349 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9350 be incomplete and such types are not marked. */
9351 add_abstract_origin_attribute (type_die, type);
9354 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9355 include all of the information about the enumeration values also. Each
9356 enumerated type name/value is listed as a child of the enumerated type
9360 gen_enumeration_type_die (type, context_die)
9362 register dw_die_ref context_die;
9364 register dw_die_ref type_die = lookup_type_die (type);
9366 if (type_die == NULL)
9368 type_die = new_die (DW_TAG_enumeration_type,
9369 scope_die_for (type, context_die));
9370 equate_type_number_to_die (type, type_die);
9371 add_name_attribute (type_die, type_tag (type));
9373 else if (! TYPE_SIZE (type))
9376 remove_AT (type_die, DW_AT_declaration);
9378 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9379 given enum type is incomplete, do not generate the DW_AT_byte_size
9380 attribute or the DW_AT_element_list attribute. */
9381 if (TYPE_SIZE (type))
9385 TREE_ASM_WRITTEN (type) = 1;
9386 add_byte_size_attribute (type_die, type);
9387 if (TYPE_STUB_DECL (type) != NULL_TREE)
9388 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9390 /* If the first reference to this type was as the return type of an
9391 inline function, then it may not have a parent. Fix this now. */
9392 if (type_die->die_parent == NULL)
9393 add_child_die (scope_die_for (type, context_die), type_die);
9395 for (link = TYPE_FIELDS (type);
9396 link != NULL; link = TREE_CHAIN (link))
9398 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9400 add_name_attribute (enum_die,
9401 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9403 if (host_integerp (TREE_VALUE (link), 0))
9405 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9406 add_AT_int (enum_die, DW_AT_const_value,
9407 tree_low_cst (TREE_VALUE (link), 0));
9409 add_AT_unsigned (enum_die, DW_AT_const_value,
9410 tree_low_cst (TREE_VALUE (link), 0));
9415 add_AT_flag (type_die, DW_AT_declaration, 1);
9418 /* Generate a DIE to represent either a real live formal parameter decl or to
9419 represent just the type of some formal parameter position in some function
9422 Note that this routine is a bit unusual because its argument may be a
9423 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9424 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9425 node. If it's the former then this function is being called to output a
9426 DIE to represent a formal parameter object (or some inlining thereof). If
9427 it's the latter, then this function is only being called to output a
9428 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9429 argument type of some subprogram type. */
9432 gen_formal_parameter_die (node, context_die)
9434 register dw_die_ref context_die;
9436 register dw_die_ref parm_die
9437 = new_die (DW_TAG_formal_parameter, context_die);
9438 register tree origin;
9440 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9443 origin = decl_ultimate_origin (node);
9445 add_abstract_origin_attribute (parm_die, origin);
9448 add_name_and_src_coords_attributes (parm_die, node);
9449 add_type_attribute (parm_die, TREE_TYPE (node),
9450 TREE_READONLY (node),
9451 TREE_THIS_VOLATILE (node),
9453 if (DECL_ARTIFICIAL (node))
9454 add_AT_flag (parm_die, DW_AT_artificial, 1);
9457 equate_decl_number_to_die (node, parm_die);
9458 if (! DECL_ABSTRACT (node))
9459 add_location_or_const_value_attribute (parm_die, node);
9464 /* We were called with some kind of a ..._TYPE node. */
9465 add_type_attribute (parm_die, node, 0, 0, context_die);
9475 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9476 at the end of an (ANSI prototyped) formal parameters list. */
9479 gen_unspecified_parameters_die (decl_or_type, context_die)
9480 register tree decl_or_type ATTRIBUTE_UNUSED;
9481 register dw_die_ref context_die;
9483 new_die (DW_TAG_unspecified_parameters, context_die);
9486 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9487 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9488 parameters as specified in some function type specification (except for
9489 those which appear as part of a function *definition*). */
9492 gen_formal_types_die (function_or_method_type, context_die)
9493 register tree function_or_method_type;
9494 register dw_die_ref context_die;
9497 register tree formal_type = NULL;
9498 register tree first_parm_type;
9501 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9503 arg = DECL_ARGUMENTS (function_or_method_type);
9504 function_or_method_type = TREE_TYPE (function_or_method_type);
9509 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9511 /* Make our first pass over the list of formal parameter types and output a
9512 DW_TAG_formal_parameter DIE for each one. */
9513 for (link = first_parm_type; link; )
9515 register dw_die_ref parm_die;
9517 formal_type = TREE_VALUE (link);
9518 if (formal_type == void_type_node)
9521 /* Output a (nameless) DIE to represent the formal parameter itself. */
9522 parm_die = gen_formal_parameter_die (formal_type, context_die);
9523 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9524 && link == first_parm_type)
9525 || (arg && DECL_ARTIFICIAL (arg)))
9526 add_AT_flag (parm_die, DW_AT_artificial, 1);
9528 link = TREE_CHAIN (link);
9530 arg = TREE_CHAIN (arg);
9533 /* If this function type has an ellipsis, add a
9534 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9535 if (formal_type != void_type_node)
9536 gen_unspecified_parameters_die (function_or_method_type, context_die);
9538 /* Make our second (and final) pass over the list of formal parameter types
9539 and output DIEs to represent those types (as necessary). */
9540 for (link = TYPE_ARG_TYPES (function_or_method_type);
9542 link = TREE_CHAIN (link))
9544 formal_type = TREE_VALUE (link);
9545 if (formal_type == void_type_node)
9548 gen_type_die (formal_type, context_die);
9552 /* We want to generate the DIE for TYPE so that we can generate the
9553 die for MEMBER, which has been defined; we will need to refer back
9554 to the member declaration nested within TYPE. If we're trying to
9555 generate minimal debug info for TYPE, processing TYPE won't do the
9556 trick; we need to attach the member declaration by hand. */
9559 gen_type_die_for_member (type, member, context_die)
9561 dw_die_ref context_die;
9563 gen_type_die (type, context_die);
9565 /* If we're trying to avoid duplicate debug info, we may not have
9566 emitted the member decl for this function. Emit it now. */
9567 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9568 && ! lookup_decl_die (member))
9570 if (decl_ultimate_origin (member))
9573 push_decl_scope (type);
9574 if (TREE_CODE (member) == FUNCTION_DECL)
9575 gen_subprogram_die (member, lookup_type_die (type));
9577 gen_variable_die (member, lookup_type_die (type));
9582 /* Generate the DWARF2 info for the "abstract" instance
9583 of a function which we may later generate inlined and/or
9584 out-of-line instances of. */
9587 dwarf2out_abstract_function (decl)
9590 register dw_die_ref old_die;
9593 int was_abstract = DECL_ABSTRACT (decl);
9595 /* Make sure we have the actual abstract inline, not a clone. */
9596 decl = DECL_ORIGIN (decl);
9598 old_die = lookup_decl_die (decl);
9599 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9600 /* We've already generated the abstract instance. */
9603 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9604 we don't get confused by DECL_ABSTRACT. */
9605 context = decl_class_context (decl);
9607 gen_type_die_for_member
9608 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9610 /* Pretend we've just finished compiling this function. */
9611 save_fn = current_function_decl;
9612 current_function_decl = decl;
9614 set_decl_abstract_flags (decl, 1);
9615 dwarf2out_decl (decl);
9617 set_decl_abstract_flags (decl, 0);
9619 current_function_decl = save_fn;
9622 /* Generate a DIE to represent a declared function (either file-scope or
9626 gen_subprogram_die (decl, context_die)
9628 register dw_die_ref context_die;
9630 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9631 register tree origin = decl_ultimate_origin (decl);
9632 register dw_die_ref subr_die;
9633 register rtx fp_reg;
9634 register tree fn_arg_types;
9635 register tree outer_scope;
9636 register dw_die_ref old_die = lookup_decl_die (decl);
9637 register int declaration = (current_function_decl != decl
9638 || class_scope_p (context_die));
9640 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9641 be true, if we started to generate the abstract instance of an inline,
9642 decided to output its containing class, and proceeded to emit the
9643 declaration of the inline from the member list for the class. In that
9644 case, `declaration' takes priority; we'll get back to the abstract
9645 instance when we're done with the class. */
9647 /* The class-scope declaration DIE must be the primary DIE. */
9648 if (origin && declaration && class_scope_p (context_die))
9657 if (declaration && ! local_scope_p (context_die))
9660 /* Fixup die_parent for the abstract instance of a nested
9662 if (old_die && old_die->die_parent == NULL)
9663 add_child_die (context_die, old_die);
9665 subr_die = new_die (DW_TAG_subprogram, context_die);
9666 add_abstract_origin_attribute (subr_die, origin);
9670 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9672 if (!get_AT_flag (old_die, DW_AT_declaration)
9673 /* We can have a normal definition following an inline one in the
9674 case of redefinition of GNU C extern inlines.
9675 It seems reasonable to use AT_specification in this case. */
9676 && !get_AT_unsigned (old_die, DW_AT_inline))
9678 /* ??? This can happen if there is a bug in the program, for
9679 instance, if it has duplicate function definitions. Ideally,
9680 we should detect this case and ignore it. For now, if we have
9681 already reported an error, any error at all, then assume that
9682 we got here because of a input error, not a dwarf2 bug. */
9688 /* If the definition comes from the same place as the declaration,
9689 maybe use the old DIE. We always want the DIE for this function
9690 that has the *_pc attributes to be under comp_unit_die so the
9691 debugger can find it. We also need to do this for abstract
9692 instances of inlines, since the spec requires the out-of-line copy
9693 to have the same parent. For local class methods, this doesn't
9694 apply; we just use the old DIE. */
9695 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9696 && (DECL_ARTIFICIAL (decl)
9697 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9698 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9699 == (unsigned) DECL_SOURCE_LINE (decl)))))
9703 /* Clear out the declaration attribute and the parm types. */
9704 remove_AT (subr_die, DW_AT_declaration);
9705 remove_children (subr_die);
9709 subr_die = new_die (DW_TAG_subprogram, context_die);
9710 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9711 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9712 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9713 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9714 != (unsigned) DECL_SOURCE_LINE (decl))
9716 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9721 subr_die = new_die (DW_TAG_subprogram, context_die);
9723 if (TREE_PUBLIC (decl))
9724 add_AT_flag (subr_die, DW_AT_external, 1);
9726 add_name_and_src_coords_attributes (subr_die, decl);
9727 if (debug_info_level > DINFO_LEVEL_TERSE)
9729 register tree type = TREE_TYPE (decl);
9731 add_prototyped_attribute (subr_die, type);
9732 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9735 add_pure_or_virtual_attribute (subr_die, decl);
9736 if (DECL_ARTIFICIAL (decl))
9737 add_AT_flag (subr_die, DW_AT_artificial, 1);
9738 if (TREE_PROTECTED (decl))
9739 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9740 else if (TREE_PRIVATE (decl))
9741 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9746 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9748 add_AT_flag (subr_die, DW_AT_declaration, 1);
9750 /* The first time we see a member function, it is in the context of
9751 the class to which it belongs. We make sure of this by emitting
9752 the class first. The next time is the definition, which is
9753 handled above. The two may come from the same source text. */
9754 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9755 equate_decl_number_to_die (decl, subr_die);
9758 else if (DECL_ABSTRACT (decl))
9760 if (DECL_INLINE (decl) && !flag_no_inline)
9762 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9763 inline functions, but not for extern inline functions.
9764 We can't get this completely correct because information
9765 about whether the function was declared inline is not
9767 if (DECL_DEFER_OUTPUT (decl))
9768 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9770 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9773 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9775 equate_decl_number_to_die (decl, subr_die);
9777 else if (!DECL_EXTERNAL (decl))
9779 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9780 equate_decl_number_to_die (decl, subr_die);
9782 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9783 current_funcdef_number);
9784 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9785 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9786 current_funcdef_number);
9787 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9789 add_pubname (decl, subr_die);
9790 add_arange (decl, subr_die);
9792 #ifdef MIPS_DEBUGGING_INFO
9793 /* Add a reference to the FDE for this routine. */
9794 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9797 /* Define the "frame base" location for this routine. We use the
9798 frame pointer or stack pointer registers, since the RTL for local
9799 variables is relative to one of them. */
9801 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9802 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9805 /* ??? This fails for nested inline functions, because context_display
9806 is not part of the state saved/restored for inline functions. */
9807 if (current_function_needs_context)
9808 add_AT_location_description (subr_die, DW_AT_static_link,
9809 lookup_static_chain (decl));
9813 /* Now output descriptions of the arguments for this function. This gets
9814 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9815 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9816 `...' at the end of the formal parameter list. In order to find out if
9817 there was a trailing ellipsis or not, we must instead look at the type
9818 associated with the FUNCTION_DECL. This will be a node of type
9819 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9820 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9821 an ellipsis at the end. */
9823 /* In the case where we are describing a mere function declaration, all we
9824 need to do here (and all we *can* do here) is to describe the *types* of
9825 its formal parameters. */
9826 if (debug_info_level <= DINFO_LEVEL_TERSE)
9828 else if (declaration)
9829 gen_formal_types_die (decl, subr_die);
9832 /* Generate DIEs to represent all known formal parameters */
9833 register tree arg_decls = DECL_ARGUMENTS (decl);
9836 /* When generating DIEs, generate the unspecified_parameters DIE
9837 instead if we come across the arg "__builtin_va_alist" */
9838 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9839 if (TREE_CODE (parm) == PARM_DECL)
9841 if (DECL_NAME (parm)
9842 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9843 "__builtin_va_alist"))
9844 gen_unspecified_parameters_die (parm, subr_die);
9846 gen_decl_die (parm, subr_die);
9849 /* Decide whether we need a unspecified_parameters DIE at the end.
9850 There are 2 more cases to do this for: 1) the ansi ... declaration -
9851 this is detectable when the end of the arg list is not a
9852 void_type_node 2) an unprototyped function declaration (not a
9853 definition). This just means that we have no info about the
9854 parameters at all. */
9855 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9856 if (fn_arg_types != NULL)
9858 /* this is the prototyped case, check for ... */
9859 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9860 gen_unspecified_parameters_die (decl, subr_die);
9862 else if (DECL_INITIAL (decl) == NULL_TREE)
9863 gen_unspecified_parameters_die (decl, subr_die);
9866 /* Output Dwarf info for all of the stuff within the body of the function
9867 (if it has one - it may be just a declaration). */
9868 outer_scope = DECL_INITIAL (decl);
9870 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9871 node created to represent a function. This outermost BLOCK actually
9872 represents the outermost binding contour for the function, i.e. the
9873 contour in which the function's formal parameters and labels get
9874 declared. Curiously, it appears that the front end doesn't actually
9875 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9876 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9877 list for the function instead.) The BLOCK_VARS list for the
9878 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9879 the function however, and we output DWARF info for those in
9880 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9881 node representing the function's outermost pair of curly braces, and
9882 any blocks used for the base and member initializers of a C++
9883 constructor function. */
9884 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9886 current_function_has_inlines = 0;
9887 decls_for_scope (outer_scope, subr_die, 0);
9889 #if 0 && defined (MIPS_DEBUGGING_INFO)
9890 if (current_function_has_inlines)
9892 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9893 if (! comp_unit_has_inlines)
9895 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9896 comp_unit_has_inlines = 1;
9903 /* Generate a DIE to represent a declared data object. */
9906 gen_variable_die (decl, context_die)
9908 register dw_die_ref context_die;
9910 register tree origin = decl_ultimate_origin (decl);
9911 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9913 dw_die_ref old_die = lookup_decl_die (decl);
9914 int declaration = (DECL_EXTERNAL (decl)
9915 || class_scope_p (context_die));
9918 add_abstract_origin_attribute (var_die, origin);
9919 /* Loop unrolling can create multiple blocks that refer to the same
9920 static variable, so we must test for the DW_AT_declaration flag. */
9921 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9922 copy decls and set the DECL_ABSTRACT flag on them instead of
9924 else if (old_die && TREE_STATIC (decl)
9925 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9927 /* This is a definition of a C++ class level static. */
9928 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9929 if (DECL_NAME (decl))
9931 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9933 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9934 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9936 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9937 != (unsigned) DECL_SOURCE_LINE (decl))
9939 add_AT_unsigned (var_die, DW_AT_decl_line,
9940 DECL_SOURCE_LINE (decl));
9945 add_name_and_src_coords_attributes (var_die, decl);
9946 add_type_attribute (var_die, TREE_TYPE (decl),
9947 TREE_READONLY (decl),
9948 TREE_THIS_VOLATILE (decl), context_die);
9950 if (TREE_PUBLIC (decl))
9951 add_AT_flag (var_die, DW_AT_external, 1);
9953 if (DECL_ARTIFICIAL (decl))
9954 add_AT_flag (var_die, DW_AT_artificial, 1);
9956 if (TREE_PROTECTED (decl))
9957 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9959 else if (TREE_PRIVATE (decl))
9960 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9964 add_AT_flag (var_die, DW_AT_declaration, 1);
9966 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9967 equate_decl_number_to_die (decl, var_die);
9969 if (! declaration && ! DECL_ABSTRACT (decl))
9971 add_location_or_const_value_attribute (var_die, decl);
9972 add_pubname (decl, var_die);
9975 tree_add_const_value_attribute (var_die, decl);
9978 /* Generate a DIE to represent a label identifier. */
9981 gen_label_die (decl, context_die)
9983 register dw_die_ref context_die;
9985 register tree origin = decl_ultimate_origin (decl);
9986 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
9988 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9991 add_abstract_origin_attribute (lbl_die, origin);
9993 add_name_and_src_coords_attributes (lbl_die, decl);
9995 if (DECL_ABSTRACT (decl))
9996 equate_decl_number_to_die (decl, lbl_die);
9999 insn = DECL_RTL (decl);
10001 /* Deleted labels are programmer specified labels which have been
10002 eliminated because of various optimisations. We still emit them
10003 here so that it is possible to put breakpoints on them. */
10004 if (GET_CODE (insn) == CODE_LABEL
10005 || ((GET_CODE (insn) == NOTE
10006 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10008 /* When optimization is enabled (via -O) some parts of the compiler
10009 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10010 represent source-level labels which were explicitly declared by
10011 the user. This really shouldn't be happening though, so catch
10012 it if it ever does happen. */
10013 if (INSN_DELETED_P (insn))
10016 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10017 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10022 /* Generate a DIE for a lexical block. */
10025 gen_lexical_block_die (stmt, context_die, depth)
10026 register tree stmt;
10027 register dw_die_ref context_die;
10030 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10031 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10033 if (! BLOCK_ABSTRACT (stmt))
10035 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10036 BLOCK_NUMBER (stmt));
10037 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10038 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10039 BLOCK_NUMBER (stmt));
10040 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10043 decls_for_scope (stmt, stmt_die, depth);
10046 /* Generate a DIE for an inlined subprogram. */
10049 gen_inlined_subroutine_die (stmt, context_die, depth)
10050 register tree stmt;
10051 register dw_die_ref context_die;
10054 if (! BLOCK_ABSTRACT (stmt))
10056 register dw_die_ref subr_die
10057 = new_die (DW_TAG_inlined_subroutine, context_die);
10058 register tree decl = block_ultimate_origin (stmt);
10059 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10061 /* Emit info for the abstract instance first, if we haven't yet. */
10062 dwarf2out_abstract_function (decl);
10064 add_abstract_origin_attribute (subr_die, decl);
10065 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10066 BLOCK_NUMBER (stmt));
10067 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10068 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10069 BLOCK_NUMBER (stmt));
10070 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10071 decls_for_scope (stmt, subr_die, depth);
10072 current_function_has_inlines = 1;
10076 /* Generate a DIE for a field in a record, or structure. */
10079 gen_field_die (decl, context_die)
10080 register tree decl;
10081 register dw_die_ref context_die;
10083 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10085 add_name_and_src_coords_attributes (decl_die, decl);
10086 add_type_attribute (decl_die, member_declared_type (decl),
10087 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10090 /* If this is a bit field... */
10091 if (DECL_BIT_FIELD_TYPE (decl))
10093 add_byte_size_attribute (decl_die, decl);
10094 add_bit_size_attribute (decl_die, decl);
10095 add_bit_offset_attribute (decl_die, decl);
10098 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10099 add_data_member_location_attribute (decl_die, decl);
10101 if (DECL_ARTIFICIAL (decl))
10102 add_AT_flag (decl_die, DW_AT_artificial, 1);
10104 if (TREE_PROTECTED (decl))
10105 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10107 else if (TREE_PRIVATE (decl))
10108 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10112 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10113 Use modified_type_die instead.
10114 We keep this code here just in case these types of DIEs may be needed to
10115 represent certain things in other languages (e.g. Pascal) someday. */
10117 gen_pointer_type_die (type, context_die)
10118 register tree type;
10119 register dw_die_ref context_die;
10121 register dw_die_ref ptr_die
10122 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10124 equate_type_number_to_die (type, ptr_die);
10125 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10126 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10129 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10130 Use modified_type_die instead.
10131 We keep this code here just in case these types of DIEs may be needed to
10132 represent certain things in other languages (e.g. Pascal) someday. */
10134 gen_reference_type_die (type, context_die)
10135 register tree type;
10136 register dw_die_ref context_die;
10138 register dw_die_ref ref_die
10139 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10141 equate_type_number_to_die (type, ref_die);
10142 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10143 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10147 /* Generate a DIE for a pointer to a member type. */
10149 gen_ptr_to_mbr_type_die (type, context_die)
10150 register tree type;
10151 register dw_die_ref context_die;
10153 register dw_die_ref ptr_die
10154 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10156 equate_type_number_to_die (type, ptr_die);
10157 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10158 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10159 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10162 /* Generate the DIE for the compilation unit. */
10165 gen_compile_unit_die (filename)
10166 register const char *filename;
10168 register dw_die_ref die;
10169 char producer[250];
10170 const char *wd = getpwd ();
10173 die = new_die (DW_TAG_compile_unit, NULL);
10174 add_name_attribute (die, filename);
10176 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10177 add_AT_string (die, DW_AT_comp_dir, wd);
10179 sprintf (producer, "%s %s", language_string, version_string);
10181 #ifdef MIPS_DEBUGGING_INFO
10182 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10183 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10184 not appear in the producer string, the debugger reaches the conclusion
10185 that the object file is stripped and has no debugging information.
10186 To get the MIPS/SGI debugger to believe that there is debugging
10187 information in the object file, we add a -g to the producer string. */
10188 if (debug_info_level > DINFO_LEVEL_TERSE)
10189 strcat (producer, " -g");
10192 add_AT_string (die, DW_AT_producer, producer);
10194 if (strcmp (language_string, "GNU C++") == 0)
10195 language = DW_LANG_C_plus_plus;
10196 else if (strcmp (language_string, "GNU Ada") == 0)
10197 language = DW_LANG_Ada83;
10198 else if (strcmp (language_string, "GNU F77") == 0)
10199 language = DW_LANG_Fortran77;
10200 else if (strcmp (language_string, "GNU Pascal") == 0)
10201 language = DW_LANG_Pascal83;
10202 else if (strcmp (language_string, "GNU Java") == 0)
10203 language = DW_LANG_Java;
10204 else if (flag_traditional)
10205 language = DW_LANG_C;
10207 language = DW_LANG_C89;
10209 add_AT_unsigned (die, DW_AT_language, language);
10214 /* Generate a DIE for a string type. */
10217 gen_string_type_die (type, context_die)
10218 register tree type;
10219 register dw_die_ref context_die;
10221 register dw_die_ref type_die
10222 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10224 equate_type_number_to_die (type, type_die);
10226 /* Fudge the string length attribute for now. */
10228 /* TODO: add string length info.
10229 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10230 bound_representation (upper_bound, 0, 'u'); */
10233 /* Generate the DIE for a base class. */
10236 gen_inheritance_die (binfo, context_die)
10237 register tree binfo;
10238 register dw_die_ref context_die;
10240 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10242 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10243 add_data_member_location_attribute (die, binfo);
10245 if (TREE_VIA_VIRTUAL (binfo))
10246 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10247 if (TREE_VIA_PUBLIC (binfo))
10248 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10249 else if (TREE_VIA_PROTECTED (binfo))
10250 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10253 /* Generate a DIE for a class member. */
10256 gen_member_die (type, context_die)
10257 register tree type;
10258 register dw_die_ref context_die;
10260 register tree member;
10263 /* If this is not an incomplete type, output descriptions of each of its
10264 members. Note that as we output the DIEs necessary to represent the
10265 members of this record or union type, we will also be trying to output
10266 DIEs to represent the *types* of those members. However the `type'
10267 function (above) will specifically avoid generating type DIEs for member
10268 types *within* the list of member DIEs for this (containing) type execpt
10269 for those types (of members) which are explicitly marked as also being
10270 members of this (containing) type themselves. The g++ front- end can
10271 force any given type to be treated as a member of some other
10272 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10273 to point to the TREE node representing the appropriate (containing)
10276 /* First output info about the base classes. */
10277 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10279 register tree bases = TYPE_BINFO_BASETYPES (type);
10280 register int n_bases = TREE_VEC_LENGTH (bases);
10283 for (i = 0; i < n_bases; i++)
10284 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10287 /* Now output info about the data members and type members. */
10288 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10290 /* If we thought we were generating minimal debug info for TYPE
10291 and then changed our minds, some of the member declarations
10292 may have already been defined. Don't define them again, but
10293 do put them in the right order. */
10295 child = lookup_decl_die (member);
10297 splice_child_die (context_die, child);
10299 gen_decl_die (member, context_die);
10302 /* Now output info about the function members (if any). */
10303 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10305 /* Don't include clones in the member list. */
10306 if (DECL_ABSTRACT_ORIGIN (member))
10309 child = lookup_decl_die (member);
10311 splice_child_die (context_die, child);
10313 gen_decl_die (member, context_die);
10317 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10318 is set, we pretend that the type was never defined, so we only get the
10319 member DIEs needed by later specification DIEs. */
10322 gen_struct_or_union_type_die (type, context_die)
10323 register tree type;
10324 register dw_die_ref context_die;
10326 register dw_die_ref type_die = lookup_type_die (type);
10327 register dw_die_ref scope_die = 0;
10328 register int nested = 0;
10329 int complete = (TYPE_SIZE (type)
10330 && (! TYPE_STUB_DECL (type)
10331 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10333 if (type_die && ! complete)
10336 if (TYPE_CONTEXT (type) != NULL_TREE
10337 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10340 scope_die = scope_die_for (type, context_die);
10342 if (! type_die || (nested && scope_die == comp_unit_die))
10343 /* First occurrence of type or toplevel definition of nested class. */
10345 register dw_die_ref old_die = type_die;
10347 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10348 ? DW_TAG_structure_type : DW_TAG_union_type,
10350 equate_type_number_to_die (type, type_die);
10352 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10354 add_name_attribute (type_die, type_tag (type));
10357 remove_AT (type_die, DW_AT_declaration);
10359 /* If this type has been completed, then give it a byte_size attribute and
10360 then give a list of members. */
10363 /* Prevent infinite recursion in cases where the type of some member of
10364 this type is expressed in terms of this type itself. */
10365 TREE_ASM_WRITTEN (type) = 1;
10366 add_byte_size_attribute (type_die, type);
10367 if (TYPE_STUB_DECL (type) != NULL_TREE)
10368 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10370 /* If the first reference to this type was as the return type of an
10371 inline function, then it may not have a parent. Fix this now. */
10372 if (type_die->die_parent == NULL)
10373 add_child_die (scope_die, type_die);
10375 push_decl_scope (type);
10376 gen_member_die (type, type_die);
10379 /* GNU extension: Record what type our vtable lives in. */
10380 if (TYPE_VFIELD (type))
10382 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10384 gen_type_die (vtype, context_die);
10385 add_AT_die_ref (type_die, DW_AT_containing_type,
10386 lookup_type_die (vtype));
10391 add_AT_flag (type_die, DW_AT_declaration, 1);
10393 /* We don't need to do this for function-local types. */
10394 if (! decl_function_context (TYPE_STUB_DECL (type)))
10395 add_incomplete_type (type);
10399 /* Generate a DIE for a subroutine _type_. */
10402 gen_subroutine_type_die (type, context_die)
10403 register tree type;
10404 register dw_die_ref context_die;
10406 register tree return_type = TREE_TYPE (type);
10407 register dw_die_ref subr_die
10408 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10410 equate_type_number_to_die (type, subr_die);
10411 add_prototyped_attribute (subr_die, type);
10412 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10413 gen_formal_types_die (type, subr_die);
10416 /* Generate a DIE for a type definition */
10419 gen_typedef_die (decl, context_die)
10420 register tree decl;
10421 register dw_die_ref context_die;
10423 register dw_die_ref type_die;
10424 register tree origin;
10426 if (TREE_ASM_WRITTEN (decl))
10428 TREE_ASM_WRITTEN (decl) = 1;
10430 type_die = new_die (DW_TAG_typedef, context_die);
10431 origin = decl_ultimate_origin (decl);
10432 if (origin != NULL)
10433 add_abstract_origin_attribute (type_die, origin);
10436 register tree type;
10437 add_name_and_src_coords_attributes (type_die, decl);
10438 if (DECL_ORIGINAL_TYPE (decl))
10440 type = DECL_ORIGINAL_TYPE (decl);
10442 if (type == TREE_TYPE (decl))
10445 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10448 type = TREE_TYPE (decl);
10449 add_type_attribute (type_die, type, TREE_READONLY (decl),
10450 TREE_THIS_VOLATILE (decl), context_die);
10453 if (DECL_ABSTRACT (decl))
10454 equate_decl_number_to_die (decl, type_die);
10457 /* Generate a type description DIE. */
10460 gen_type_die (type, context_die)
10461 register tree type;
10462 register dw_die_ref context_die;
10466 if (type == NULL_TREE || type == error_mark_node)
10469 /* We are going to output a DIE to represent the unqualified version of
10470 this type (i.e. without any const or volatile qualifiers) so get the
10471 main variant (i.e. the unqualified version) of this type now. */
10472 type = type_main_variant (type);
10474 if (TREE_ASM_WRITTEN (type))
10477 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10478 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10480 TREE_ASM_WRITTEN (type) = 1;
10481 gen_decl_die (TYPE_NAME (type), context_die);
10485 switch (TREE_CODE (type))
10491 case REFERENCE_TYPE:
10492 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10493 ensures that the gen_type_die recursion will terminate even if the
10494 type is recursive. Recursive types are possible in Ada. */
10495 /* ??? We could perhaps do this for all types before the switch
10497 TREE_ASM_WRITTEN (type) = 1;
10499 /* For these types, all that is required is that we output a DIE (or a
10500 set of DIEs) to represent the "basis" type. */
10501 gen_type_die (TREE_TYPE (type), context_die);
10505 /* This code is used for C++ pointer-to-data-member types.
10506 Output a description of the relevant class type. */
10507 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10509 /* Output a description of the type of the object pointed to. */
10510 gen_type_die (TREE_TYPE (type), context_die);
10512 /* Now output a DIE to represent this pointer-to-data-member type
10514 gen_ptr_to_mbr_type_die (type, context_die);
10518 gen_type_die (TYPE_DOMAIN (type), context_die);
10519 gen_set_type_die (type, context_die);
10523 gen_type_die (TREE_TYPE (type), context_die);
10524 abort (); /* No way to represent these in Dwarf yet! */
10527 case FUNCTION_TYPE:
10528 /* Force out return type (in case it wasn't forced out already). */
10529 gen_type_die (TREE_TYPE (type), context_die);
10530 gen_subroutine_type_die (type, context_die);
10534 /* Force out return type (in case it wasn't forced out already). */
10535 gen_type_die (TREE_TYPE (type), context_die);
10536 gen_subroutine_type_die (type, context_die);
10540 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10542 gen_type_die (TREE_TYPE (type), context_die);
10543 gen_string_type_die (type, context_die);
10546 gen_array_type_die (type, context_die);
10550 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10553 case ENUMERAL_TYPE:
10556 case QUAL_UNION_TYPE:
10557 /* If this is a nested type whose containing class hasn't been
10558 written out yet, writing it out will cover this one, too.
10559 This does not apply to instantiations of member class templates;
10560 they need to be added to the containing class as they are
10561 generated. FIXME: This hurts the idea of combining type decls
10562 from multiple TUs, since we can't predict what set of template
10563 instantiations we'll get. */
10564 if (TYPE_CONTEXT (type)
10565 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10566 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10568 gen_type_die (TYPE_CONTEXT (type), context_die);
10570 if (TREE_ASM_WRITTEN (type))
10573 /* If that failed, attach ourselves to the stub. */
10574 push_decl_scope (TYPE_CONTEXT (type));
10575 context_die = lookup_type_die (TYPE_CONTEXT (type));
10581 if (TREE_CODE (type) == ENUMERAL_TYPE)
10582 gen_enumeration_type_die (type, context_die);
10584 gen_struct_or_union_type_die (type, context_die);
10589 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10590 it up if it is ever completed. gen_*_type_die will set it for us
10591 when appropriate. */
10600 /* No DIEs needed for fundamental types. */
10604 /* No Dwarf representation currently defined. */
10611 TREE_ASM_WRITTEN (type) = 1;
10614 /* Generate a DIE for a tagged type instantiation. */
10617 gen_tagged_type_instantiation_die (type, context_die)
10618 register tree type;
10619 register dw_die_ref context_die;
10621 if (type == NULL_TREE || type == error_mark_node)
10624 /* We are going to output a DIE to represent the unqualified version of
10625 this type (i.e. without any const or volatile qualifiers) so make sure
10626 that we have the main variant (i.e. the unqualified version) of this
10628 if (type != type_main_variant (type))
10631 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10632 an instance of an unresolved type. */
10634 switch (TREE_CODE (type))
10639 case ENUMERAL_TYPE:
10640 gen_inlined_enumeration_type_die (type, context_die);
10644 gen_inlined_structure_type_die (type, context_die);
10648 case QUAL_UNION_TYPE:
10649 gen_inlined_union_type_die (type, context_die);
10657 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10658 things which are local to the given block. */
10661 gen_block_die (stmt, context_die, depth)
10662 register tree stmt;
10663 register dw_die_ref context_die;
10666 register int must_output_die = 0;
10667 register tree origin;
10668 register tree decl;
10669 register enum tree_code origin_code;
10671 /* Ignore blocks never really used to make RTL. */
10673 if (stmt == NULL_TREE || !TREE_USED (stmt)
10674 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10677 /* Determine the "ultimate origin" of this block. This block may be an
10678 inlined instance of an inlined instance of inline function, so we have
10679 to trace all of the way back through the origin chain to find out what
10680 sort of node actually served as the original seed for the creation of
10681 the current block. */
10682 origin = block_ultimate_origin (stmt);
10683 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10685 /* Determine if we need to output any Dwarf DIEs at all to represent this
10687 if (origin_code == FUNCTION_DECL)
10688 /* The outer scopes for inlinings *must* always be represented. We
10689 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10690 must_output_die = 1;
10693 /* In the case where the current block represents an inlining of the
10694 "body block" of an inline function, we must *NOT* output any DIE for
10695 this block because we have already output a DIE to represent the
10696 whole inlined function scope and the "body block" of any function
10697 doesn't really represent a different scope according to ANSI C
10698 rules. So we check here to make sure that this block does not
10699 represent a "body block inlining" before trying to set the
10700 `must_output_die' flag. */
10701 if (! is_body_block (origin ? origin : stmt))
10703 /* Determine if this block directly contains any "significant"
10704 local declarations which we will need to output DIEs for. */
10705 if (debug_info_level > DINFO_LEVEL_TERSE)
10706 /* We are not in terse mode so *any* local declaration counts
10707 as being a "significant" one. */
10708 must_output_die = (BLOCK_VARS (stmt) != NULL);
10710 /* We are in terse mode, so only local (nested) function
10711 definitions count as "significant" local declarations. */
10712 for (decl = BLOCK_VARS (stmt);
10713 decl != NULL; decl = TREE_CHAIN (decl))
10714 if (TREE_CODE (decl) == FUNCTION_DECL
10715 && DECL_INITIAL (decl))
10717 must_output_die = 1;
10723 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10724 DIE for any block which contains no significant local declarations at
10725 all. Rather, in such cases we just call `decls_for_scope' so that any
10726 needed Dwarf info for any sub-blocks will get properly generated. Note
10727 that in terse mode, our definition of what constitutes a "significant"
10728 local declaration gets restricted to include only inlined function
10729 instances and local (nested) function definitions. */
10730 if (must_output_die)
10732 if (origin_code == FUNCTION_DECL)
10733 gen_inlined_subroutine_die (stmt, context_die, depth);
10735 gen_lexical_block_die (stmt, context_die, depth);
10738 decls_for_scope (stmt, context_die, depth);
10741 /* Generate all of the decls declared within a given scope and (recursively)
10742 all of its sub-blocks. */
10745 decls_for_scope (stmt, context_die, depth)
10746 register tree stmt;
10747 register dw_die_ref context_die;
10750 register tree decl;
10751 register tree subblocks;
10753 /* Ignore blocks never really used to make RTL. */
10754 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10757 /* Output the DIEs to represent all of the data objects and typedefs
10758 declared directly within this block but not within any nested
10759 sub-blocks. Also, nested function and tag DIEs have been
10760 generated with a parent of NULL; fix that up now. */
10761 for (decl = BLOCK_VARS (stmt);
10762 decl != NULL; decl = TREE_CHAIN (decl))
10764 register dw_die_ref die;
10766 if (TREE_CODE (decl) == FUNCTION_DECL)
10767 die = lookup_decl_die (decl);
10768 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10769 die = lookup_type_die (TREE_TYPE (decl));
10773 if (die != NULL && die->die_parent == NULL)
10774 add_child_die (context_die, die);
10776 gen_decl_die (decl, context_die);
10779 /* Output the DIEs to represent all sub-blocks (and the items declared
10780 therein) of this block. */
10781 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10783 subblocks = BLOCK_CHAIN (subblocks))
10784 gen_block_die (subblocks, context_die, depth + 1);
10787 /* Is this a typedef we can avoid emitting? */
10790 is_redundant_typedef (decl)
10791 register tree decl;
10793 if (TYPE_DECL_IS_STUB (decl))
10796 if (DECL_ARTIFICIAL (decl)
10797 && DECL_CONTEXT (decl)
10798 && is_tagged_type (DECL_CONTEXT (decl))
10799 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10800 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10801 /* Also ignore the artificial member typedef for the class name. */
10807 /* Generate Dwarf debug information for a decl described by DECL. */
10810 gen_decl_die (decl, context_die)
10811 register tree decl;
10812 register dw_die_ref context_die;
10814 register tree origin;
10816 if (TREE_CODE (decl) == ERROR_MARK)
10819 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10820 if (DECL_IGNORED_P (decl))
10823 switch (TREE_CODE (decl))
10826 /* The individual enumerators of an enum type get output when we output
10827 the Dwarf representation of the relevant enum type itself. */
10830 case FUNCTION_DECL:
10831 /* Don't output any DIEs to represent mere function declarations,
10832 unless they are class members or explicit block externs. */
10833 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10834 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10837 /* If we're emitting a clone, emit info for the abstract instance. */
10838 if (DECL_ORIGIN (decl) != decl)
10839 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
10840 /* If we're emitting an out-of-line copy of an inline function,
10841 emit info for the abstract instance and set up to refer to it. */
10842 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10843 && ! class_scope_p (context_die)
10844 /* dwarf2out_abstract_function won't emit a die if this is just
10845 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10846 that case, because that works only if we have a die. */
10847 && DECL_INITIAL (decl) != NULL_TREE)
10849 dwarf2out_abstract_function (decl);
10850 set_decl_origin_self (decl);
10852 /* Otherwise we're emitting the primary DIE for this decl. */
10853 else if (debug_info_level > DINFO_LEVEL_TERSE)
10855 /* Before we describe the FUNCTION_DECL itself, make sure that we
10856 have described its return type. */
10857 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10859 /* And its virtual context. */
10860 if (DECL_VINDEX (decl) != NULL_TREE)
10861 gen_type_die (DECL_CONTEXT (decl), context_die);
10863 /* And its containing type. */
10864 origin = decl_class_context (decl);
10865 if (origin != NULL_TREE)
10866 gen_type_die_for_member (origin, decl, context_die);
10869 /* Now output a DIE to represent the function itself. */
10870 gen_subprogram_die (decl, context_die);
10874 /* If we are in terse mode, don't generate any DIEs to represent any
10875 actual typedefs. */
10876 if (debug_info_level <= DINFO_LEVEL_TERSE)
10879 /* In the special case of a TYPE_DECL node representing the
10880 declaration of some type tag, if the given TYPE_DECL is marked as
10881 having been instantiated from some other (original) TYPE_DECL node
10882 (e.g. one which was generated within the original definition of an
10883 inline function) we have to generate a special (abbreviated)
10884 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10886 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10888 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10892 if (is_redundant_typedef (decl))
10893 gen_type_die (TREE_TYPE (decl), context_die);
10895 /* Output a DIE to represent the typedef itself. */
10896 gen_typedef_die (decl, context_die);
10900 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10901 gen_label_die (decl, context_die);
10905 /* If we are in terse mode, don't generate any DIEs to represent any
10906 variable declarations or definitions. */
10907 if (debug_info_level <= DINFO_LEVEL_TERSE)
10910 /* Output any DIEs that are needed to specify the type of this data
10912 gen_type_die (TREE_TYPE (decl), context_die);
10914 /* And its containing type. */
10915 origin = decl_class_context (decl);
10916 if (origin != NULL_TREE)
10917 gen_type_die_for_member (origin, decl, context_die);
10919 /* Now output the DIE to represent the data object itself. This gets
10920 complicated because of the possibility that the VAR_DECL really
10921 represents an inlined instance of a formal parameter for an inline
10923 origin = decl_ultimate_origin (decl);
10924 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10925 gen_formal_parameter_die (decl, context_die);
10927 gen_variable_die (decl, context_die);
10931 /* Ignore the nameless fields that are used to skip bits, but
10932 handle C++ anonymous unions. */
10933 if (DECL_NAME (decl) != NULL_TREE
10934 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10936 gen_type_die (member_declared_type (decl), context_die);
10937 gen_field_die (decl, context_die);
10942 gen_type_die (TREE_TYPE (decl), context_die);
10943 gen_formal_parameter_die (decl, context_die);
10946 case NAMESPACE_DECL:
10947 /* Ignore for now. */
10955 /* Add Ada "use" clause information for SGI Workshop debugger. */
10958 dwarf2out_add_library_unit_info (filename, context_list)
10959 const char *filename;
10960 const char *context_list;
10962 unsigned int file_index;
10964 if (filename != NULL)
10966 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10967 tree context_list_decl
10968 = build_decl (LABEL_DECL, get_identifier (context_list),
10971 TREE_PUBLIC (context_list_decl) = TRUE;
10972 add_name_attribute (unit_die, context_list);
10973 file_index = lookup_filename (filename);
10974 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10975 add_pubname (context_list_decl, unit_die);
10979 /* Write the debugging output for DECL. */
10982 dwarf2out_decl (decl)
10983 register tree decl;
10985 register dw_die_ref context_die = comp_unit_die;
10987 if (TREE_CODE (decl) == ERROR_MARK)
10990 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10991 if (DECL_IGNORED_P (decl))
10994 switch (TREE_CODE (decl))
10996 case FUNCTION_DECL:
10997 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
10998 builtin function. Explicit programmer-supplied declarations of
10999 these same functions should NOT be ignored however. */
11000 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11003 /* What we would really like to do here is to filter out all mere
11004 file-scope declarations of file-scope functions which are never
11005 referenced later within this translation unit (and keep all of ones
11006 that *are* referenced later on) but we aren't clairvoyant, so we have
11007 no idea which functions will be referenced in the future (i.e. later
11008 on within the current translation unit). So here we just ignore all
11009 file-scope function declarations which are not also definitions. If
11010 and when the debugger needs to know something about these functions,
11011 it will have to hunt around and find the DWARF information associated
11012 with the definition of the function. Note that we can't just check
11013 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11014 definitions and which ones represent mere declarations. We have to
11015 check `DECL_INITIAL' instead. That's because the C front-end
11016 supports some weird semantics for "extern inline" function
11017 definitions. These can get inlined within the current translation
11018 unit (an thus, we need to generate DWARF info for their abstract
11019 instances so that the DWARF info for the concrete inlined instances
11020 can have something to refer to) but the compiler never generates any
11021 out-of-lines instances of such things (despite the fact that they
11022 *are* definitions). The important point is that the C front-end
11023 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11024 to generate DWARF for them anyway. Note that the C++ front-end also
11025 plays some similar games for inline function definitions appearing
11026 within include files which also contain
11027 `#pragma interface' pragmas. */
11028 if (DECL_INITIAL (decl) == NULL_TREE)
11031 /* If we're a nested function, initially use a parent of NULL; if we're
11032 a plain function, this will be fixed up in decls_for_scope. If
11033 we're a method, it will be ignored, since we already have a DIE. */
11034 if (decl_function_context (decl))
11035 context_die = NULL;
11040 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11041 declaration and if the declaration was never even referenced from
11042 within this entire compilation unit. We suppress these DIEs in
11043 order to save space in the .debug section (by eliminating entries
11044 which are probably useless). Note that we must not suppress
11045 block-local extern declarations (whether used or not) because that
11046 would screw-up the debugger's name lookup mechanism and cause it to
11047 miss things which really ought to be in scope at a given point. */
11048 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11051 /* If we are in terse mode, don't generate any DIEs to represent any
11052 variable declarations or definitions. */
11053 if (debug_info_level <= DINFO_LEVEL_TERSE)
11058 /* Don't emit stubs for types unless they are needed by other DIEs. */
11059 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11062 /* Don't bother trying to generate any DIEs to represent any of the
11063 normal built-in types for the language we are compiling. */
11064 if (DECL_SOURCE_LINE (decl) == 0)
11066 /* OK, we need to generate one for `bool' so GDB knows what type
11067 comparisons have. */
11068 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11069 == DW_LANG_C_plus_plus)
11070 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11071 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11076 /* If we are in terse mode, don't generate any DIEs for types. */
11077 if (debug_info_level <= DINFO_LEVEL_TERSE)
11080 /* If we're a function-scope tag, initially use a parent of NULL;
11081 this will be fixed up in decls_for_scope. */
11082 if (decl_function_context (decl))
11083 context_die = NULL;
11091 gen_decl_die (decl, context_die);
11094 /* Output a marker (i.e. a label) for the beginning of the generated code for
11095 a lexical block. */
11098 dwarf2out_begin_block (blocknum)
11099 register unsigned blocknum;
11101 function_section (current_function_decl);
11102 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11105 /* Output a marker (i.e. a label) for the end of the generated code for a
11109 dwarf2out_end_block (blocknum)
11110 register unsigned blocknum;
11112 function_section (current_function_decl);
11113 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11116 /* Returns nonzero if it is appropriate not to emit any debugging
11117 information for BLOCK, because it doesn't contain any instructions.
11119 Don't allow this for blocks with nested functions or local classes
11120 as we would end up with orphans, and in the presence of scheduling
11121 we may end up calling them anyway. */
11124 dwarf2out_ignore_block (block)
11128 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11129 if (TREE_CODE (decl) == FUNCTION_DECL
11130 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11135 /* Lookup a filename (in the list of filenames that we know about here in
11136 dwarf2out.c) and return its "index". The index of each (known) filename is
11137 just a unique number which is associated with only that one filename.
11138 We need such numbers for the sake of generating labels
11139 (in the .debug_sfnames section) and references to those
11140 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11141 If the filename given as an argument is not found in our current list,
11142 add it to the list and assign it the next available unique index number.
11143 In order to speed up searches, we remember the index of the filename
11144 was looked up last. This handles the majority of all searches. */
11147 lookup_filename (file_name)
11148 const char *file_name;
11150 register unsigned i;
11152 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11153 if (strcmp (file_name, "<internal>") == 0
11154 || strcmp (file_name, "<built-in>") == 0)
11157 /* Check to see if the file name that was searched on the previous
11158 call matches this file name. If so, return the index. */
11159 if (file_table.last_lookup_index != 0)
11160 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
11161 return file_table.last_lookup_index;
11163 /* Didn't match the previous lookup, search the table */
11164 for (i = 1; i < file_table.in_use; ++i)
11165 if (strcmp (file_name, file_table.table[i]) == 0)
11167 file_table.last_lookup_index = i;
11171 /* Prepare to add a new table entry by making sure there is enough space in
11172 the table to do so. If not, expand the current table. */
11173 if (i == file_table.allocated)
11175 file_table.allocated = i + FILE_TABLE_INCREMENT;
11176 file_table.table = (char **)
11177 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11180 /* Add the new entry to the end of the filename table. */
11181 file_table.table[i] = xstrdup (file_name);
11182 file_table.in_use = i + 1;
11183 file_table.last_lookup_index = i;
11185 if (DWARF2_ASM_LINE_DEBUG_INFO)
11186 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11194 /* Allocate the initial hunk of the file_table. */
11195 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11196 file_table.allocated = FILE_TABLE_INCREMENT;
11198 /* Skip the first entry - file numbers begin at 1. */
11199 file_table.in_use = 1;
11200 file_table.last_lookup_index = 0;
11203 /* Output a label to mark the beginning of a source code line entry
11204 and record information relating to this source line, in
11205 'line_info_table' for later output of the .debug_line section. */
11208 dwarf2out_line (filename, line)
11209 register const char *filename;
11210 register unsigned line;
11212 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11214 function_section (current_function_decl);
11216 /* If requested, emit something human-readable. */
11217 if (flag_debug_asm)
11218 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11221 if (DWARF2_ASM_LINE_DEBUG_INFO)
11223 unsigned file_num = lookup_filename (filename);
11225 /* Emit the .loc directive understood by GNU as. */
11226 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11228 /* Indicate that line number info exists. */
11229 ++line_info_table_in_use;
11231 /* Indicate that multiple line number tables exist. */
11232 if (DECL_SECTION_NAME (current_function_decl))
11233 ++separate_line_info_table_in_use;
11235 else if (DECL_SECTION_NAME (current_function_decl))
11237 register dw_separate_line_info_ref line_info;
11238 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11239 separate_line_info_table_in_use);
11241 /* expand the line info table if necessary */
11242 if (separate_line_info_table_in_use
11243 == separate_line_info_table_allocated)
11245 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11246 separate_line_info_table
11247 = (dw_separate_line_info_ref)
11248 xrealloc (separate_line_info_table,
11249 separate_line_info_table_allocated
11250 * sizeof (dw_separate_line_info_entry));
11253 /* Add the new entry at the end of the line_info_table. */
11255 = &separate_line_info_table[separate_line_info_table_in_use++];
11256 line_info->dw_file_num = lookup_filename (filename);
11257 line_info->dw_line_num = line;
11258 line_info->function = current_funcdef_number;
11262 register dw_line_info_ref line_info;
11264 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11265 line_info_table_in_use);
11267 /* Expand the line info table if necessary. */
11268 if (line_info_table_in_use == line_info_table_allocated)
11270 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11272 = (dw_line_info_ref)
11273 xrealloc (line_info_table,
11274 (line_info_table_allocated
11275 * sizeof (dw_line_info_entry)));
11278 /* Add the new entry at the end of the line_info_table. */
11279 line_info = &line_info_table[line_info_table_in_use++];
11280 line_info->dw_file_num = lookup_filename (filename);
11281 line_info->dw_line_num = line;
11286 /* Record the beginning of a new source file. */
11289 dwarf2out_start_source_file (lineno, filename)
11290 register unsigned int lineno ATTRIBUTE_UNUSED;
11291 register const char *filename ATTRIBUTE_UNUSED;
11293 if (flag_eliminate_dwarf2_dups)
11295 /* Record the beginning of the file for break_out_includes. */
11296 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11297 add_AT_string (bincl_die, DW_AT_name, filename);
11299 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11301 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11302 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11303 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", lineno);
11304 dw2_asm_output_data_uleb128 (lookup_filename (filename), "Filename we just started");
11308 /* Record the end of a source file. */
11311 dwarf2out_end_source_file ()
11313 if (flag_eliminate_dwarf2_dups)
11315 /* Record the end of the file for break_out_includes. */
11316 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11318 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11320 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11321 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11325 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11326 the tail part of the directive line, i.e. the part which is past the
11327 initial whitespace, #, whitespace, directive-name, whitespace part. */
11330 dwarf2out_define (lineno, buffer)
11331 register unsigned lineno ATTRIBUTE_UNUSED;
11332 register const char *buffer ATTRIBUTE_UNUSED;
11334 static int initialized = 0;
11337 dwarf2out_start_source_file (0, primary_filename);
11340 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11342 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11343 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11344 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11345 dw2_asm_output_nstring (buffer, -1, "The macro");
11349 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11350 the tail part of the directive line, i.e. the part which is past the
11351 initial whitespace, #, whitespace, directive-name, whitespace part. */
11354 dwarf2out_undef (lineno, buffer)
11355 register unsigned lineno ATTRIBUTE_UNUSED;
11356 register const char *buffer ATTRIBUTE_UNUSED;
11358 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11360 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11361 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
11362 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11363 dw2_asm_output_nstring (buffer, -1, "The macro");
11367 /* Set up for Dwarf output at the start of compilation. */
11370 dwarf2out_init (asm_out_file, main_input_filename)
11371 register FILE *asm_out_file;
11372 register const char *main_input_filename;
11374 init_file_table ();
11376 /* Remember the name of the primary input file. */
11377 primary_filename = main_input_filename;
11379 /* Add it to the file table first, under the assumption that we'll
11380 be emitting line number data for it first, which avoids having
11381 to add an initial DW_LNS_set_file. */
11382 lookup_filename (main_input_filename);
11384 /* Allocate the initial hunk of the decl_die_table. */
11386 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11387 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11388 decl_die_table_in_use = 0;
11390 /* Allocate the initial hunk of the decl_scope_table. */
11392 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11393 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11394 decl_scope_depth = 0;
11396 /* Allocate the initial hunk of the abbrev_die_table. */
11398 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11399 sizeof (dw_die_ref));
11400 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11401 /* Zero-th entry is allocated, but unused */
11402 abbrev_die_table_in_use = 1;
11404 /* Allocate the initial hunk of the line_info_table. */
11406 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11407 sizeof (dw_line_info_entry));
11408 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11409 /* Zero-th entry is allocated, but unused */
11410 line_info_table_in_use = 1;
11412 /* Generate the initial DIE for the .debug section. Note that the (string)
11413 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11414 will (typically) be a relative pathname and that this pathname should be
11415 taken as being relative to the directory from which the compiler was
11416 invoked when the given (base) source file was compiled. */
11417 comp_unit_die = gen_compile_unit_die (main_input_filename);
11419 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11420 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11422 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11423 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
11424 DEBUG_ABBREV_SECTION_LABEL, 0);
11425 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11426 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11428 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11429 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11430 DEBUG_INFO_SECTION_LABEL, 0);
11431 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11432 DEBUG_LINE_SECTION_LABEL, 0);
11433 ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, 0);
11434 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION);
11435 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
11436 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION);
11437 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11438 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11440 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11441 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11443 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11444 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11445 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11446 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11447 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11449 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11450 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
11451 DEBUG_MACINFO_SECTION_LABEL, 0);
11452 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
11456 /* Output stuff that dwarf requires at the end of every file,
11457 and generate the DWARF-2 debugging info. */
11460 dwarf2out_finish (asm_out_file, input_filename)
11461 register FILE *asm_out_file;
11462 register const char *input_filename ATTRIBUTE_UNUSED;
11464 limbo_die_node *node, *next_node;
11465 dw_die_ref die = 0;
11467 /* Traverse the limbo die list, and add parent/child links. The only
11468 dies without parents that should be here are concrete instances of
11469 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11470 For concrete instances, we can get the parent die from the abstract
11472 for (node = limbo_die_list; node; node = next_node)
11474 next_node = node->next;
11477 if (die->die_parent == NULL)
11479 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11481 add_child_die (origin->die_parent, die);
11482 else if (die == comp_unit_die)
11489 limbo_die_list = NULL;
11491 /* Walk through the list of incomplete types again, trying once more to
11492 emit full debugging info for them. */
11493 retry_incomplete_types ();
11495 /* We need to reverse all the dies before break_out_includes, or
11496 we'll see the end of an include file before the beginning. */
11497 reverse_all_dies (comp_unit_die);
11499 /* Generate separate CUs for each of the include files we've seen.
11500 They will go into limbo_die_list. */
11501 if (flag_eliminate_dwarf2_dups)
11502 break_out_includes (comp_unit_die);
11504 /* Traverse the DIE's and add add sibling attributes to those DIE's
11505 that have children. */
11506 add_sibling_attributes (comp_unit_die);
11507 for (node = limbo_die_list; node; node = node->next)
11508 add_sibling_attributes (node->die);
11510 /* Output a terminator label for the .text section. */
11511 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11512 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11515 /* Output a terminator label for the .data section. */
11516 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11517 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11519 /* Output a terminator label for the .bss section. */
11520 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11521 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11524 /* Output the source line correspondence table. We must do this
11525 even if there is no line information. Otherwise, on an empty
11526 translation unit, we will generate a present, but empty,
11527 .debug_info section. IRIX 6.5 `nm' will then complain when
11528 examining the file. */
11529 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11531 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11532 output_line_info ();
11535 /* We can only use the low/high_pc attributes if all of the code was
11537 if (separate_line_info_table_in_use == 0)
11539 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11540 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11543 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11544 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11545 debug_line_section_label);
11547 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11548 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
11550 /* Output all of the compilation units. We put the main one last so that
11551 the offsets are available to output_pubnames. */
11552 for (node = limbo_die_list; node; node = node->next)
11553 output_comp_unit (node->die);
11554 output_comp_unit (comp_unit_die);
11556 /* Output the abbreviation table. */
11557 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION);
11558 output_abbrev_section ();
11560 if (pubname_table_in_use)
11562 /* Output public names table. */
11563 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
11564 output_pubnames ();
11567 /* We only put functions in the arange table, so don't write it out if
11568 we don't have any. */
11569 if (fde_table_in_use)
11571 /* Output the address range information. */
11572 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
11575 /* Output location list section if necessary */
11576 if (have_location_lists)
11578 /* Output the location lists info. */
11579 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION);
11580 output_location_lists (die);
11581 have_location_lists = 0;
11584 /* Have to end the primary source file. */
11585 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11587 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11588 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11592 #endif /* DWARF2_DEBUGGING_INFO */