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 #ifdef DWARF2_DEBUGGING_INFO
63 static void dwarf2out_source_line PARAMS ((unsigned int, const char *));
66 /* DWARF2 Abbreviation Glossary:
67 CFA = Canonical Frame Address
68 a fixed address on the stack which identifies a call frame.
69 We define it to be the value of SP just before the call insn.
70 The CFA register and offset, which may change during the course
71 of the function, are used to calculate its value at runtime.
72 CFI = Call Frame Instruction
73 an instruction for the DWARF2 abstract machine
74 CIE = Common Information Entry
75 information describing information common to one or more FDEs
76 DIE = Debugging Information Entry
77 FDE = Frame Description Entry
78 information describing the stack call frame, in particular,
79 how to restore registers
81 DW_CFA_... = DWARF2 CFA call frame instruction
82 DW_TAG_... = DWARF2 DIE tag */
84 /* Decide whether we want to emit frame unwind information for the current
90 return (write_symbols == DWARF2_DEBUG
91 #ifdef DWARF2_FRAME_INFO
94 #ifdef DWARF2_UNWIND_INFO
96 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
101 /* The number of the current function definition for which debugging
102 information is being generated. These numbers range from 1 up to the
103 maximum number of function definitions contained within the current
104 compilation unit. These numbers are used to create unique label id's
105 unique to each function definition. */
106 unsigned current_funcdef_number = 0;
108 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
110 /* How to start an assembler comment. */
111 #ifndef ASM_COMMENT_START
112 #define ASM_COMMENT_START ";#"
115 typedef struct dw_cfi_struct *dw_cfi_ref;
116 typedef struct dw_fde_struct *dw_fde_ref;
117 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
119 /* Call frames are described using a sequence of Call Frame
120 Information instructions. The register number, offset
121 and address fields are provided as possible operands;
122 their use is selected by the opcode field. */
124 typedef union dw_cfi_oprnd_struct
126 unsigned long dw_cfi_reg_num;
127 long int dw_cfi_offset;
128 const char *dw_cfi_addr;
129 struct dw_loc_descr_struct *dw_cfi_loc;
133 typedef struct dw_cfi_struct
135 dw_cfi_ref dw_cfi_next;
136 enum dwarf_call_frame_info dw_cfi_opc;
137 dw_cfi_oprnd dw_cfi_oprnd1;
138 dw_cfi_oprnd dw_cfi_oprnd2;
142 /* This is how we define the location of the CFA. We use to handle it
143 as REG + OFFSET all the time, but now it can be more complex.
144 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
145 Instead of passing around REG and OFFSET, we pass a copy
146 of this structure. */
147 typedef struct cfa_loc
152 int indirect; /* 1 if CFA is accessed via a dereference. */
155 /* All call frame descriptions (FDE's) in the GCC generated DWARF
156 refer to a single Common Information Entry (CIE), defined at
157 the beginning of the .debug_frame section. This used of a single
158 CIE obviates the need to keep track of multiple CIE's
159 in the DWARF generation routines below. */
161 typedef struct dw_fde_struct
163 const char *dw_fde_begin;
164 const char *dw_fde_current_label;
165 const char *dw_fde_end;
166 dw_cfi_ref dw_fde_cfi;
167 unsigned funcdef_number;
168 unsigned nothrow : 1;
169 unsigned uses_eh_lsda : 1;
173 /* Maximum size (in bytes) of an artificially generated label. */
174 #define MAX_ARTIFICIAL_LABEL_BYTES 30
176 /* The size of the target's pointer type. */
178 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
181 /* The size of addresses as they appear in the Dwarf 2 data.
182 Some architectures use word addresses to refer to code locations,
183 but Dwarf 2 info always uses byte addresses. On such machines,
184 Dwarf 2 addresses need to be larger than the architecture's
186 #ifndef DWARF2_ADDR_SIZE
187 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
190 /* The size in bytes of a DWARF field indicating an offset or length
191 relative to a debug info section, specified to be 4 bytes in the
192 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
195 #ifndef DWARF_OFFSET_SIZE
196 #define DWARF_OFFSET_SIZE 4
199 #define DWARF_VERSION 2
201 /* Round SIZE up to the nearest BOUNDARY. */
202 #define DWARF_ROUND(SIZE,BOUNDARY) \
203 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
205 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
206 #ifndef DWARF_CIE_DATA_ALIGNMENT
207 #ifdef STACK_GROWS_DOWNWARD
208 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
210 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
212 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
214 /* A pointer to the base of a table that contains frame description
215 information for each routine. */
216 static dw_fde_ref fde_table;
218 /* Number of elements currently allocated for fde_table. */
219 static unsigned fde_table_allocated;
221 /* Number of elements in fde_table currently in use. */
222 static unsigned fde_table_in_use;
224 /* Size (in elements) of increments by which we may expand the
226 #define FDE_TABLE_INCREMENT 256
228 /* A list of call frame insns for the CIE. */
229 static dw_cfi_ref cie_cfi_head;
231 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
232 attribute that accelerates the lookup of the FDE associated
233 with the subprogram. This variable holds the table index of the FDE
234 associated with the current function (body) definition. */
235 static unsigned current_funcdef_fde;
237 /* Forward declarations for functions defined in this file. */
239 static char *stripattributes PARAMS ((const char *));
240 static const char *dwarf_cfi_name PARAMS ((unsigned));
241 static dw_cfi_ref new_cfi PARAMS ((void));
242 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
243 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
244 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
245 static void lookup_cfa PARAMS ((dw_cfa_location *));
246 static void reg_save PARAMS ((const char *, unsigned,
248 static void initial_return_save PARAMS ((rtx));
249 static long stack_adjust_offset PARAMS ((rtx));
250 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
251 static void output_call_frame_info PARAMS ((int));
252 static void dwarf2out_stack_adjust PARAMS ((rtx));
253 static void queue_reg_save PARAMS ((const char *, rtx, long));
254 static void flush_queued_reg_saves PARAMS ((void));
255 static bool clobbers_queued_reg_save PARAMS ((rtx));
256 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
258 /* Support for complex CFA locations. */
259 static void output_cfa_loc PARAMS ((dw_cfi_ref));
260 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
261 struct dw_loc_descr_struct *));
262 static struct dw_loc_descr_struct *build_cfa_loc
263 PARAMS ((dw_cfa_location *));
264 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
266 /* How to start an assembler comment. */
267 #ifndef ASM_COMMENT_START
268 #define ASM_COMMENT_START ";#"
271 /* Data and reference forms for relocatable data. */
272 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
273 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
275 /* Pseudo-op for defining a new section. */
276 #ifndef SECTION_ASM_OP
277 #define SECTION_ASM_OP "\t.section\t"
280 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
281 print the SECTION_ASM_OP and the section name. The default here works for
282 almost all svr4 assemblers, except for the sparc, where the section name
283 must be enclosed in double quotes. (See sparcv4.h). */
284 #ifndef SECTION_FORMAT
285 #ifdef PUSHSECTION_FORMAT
286 #define SECTION_FORMAT PUSHSECTION_FORMAT
288 #define SECTION_FORMAT "%s%s\n"
292 #ifndef DEBUG_FRAME_SECTION
293 #define DEBUG_FRAME_SECTION ".debug_frame"
296 #ifndef FUNC_BEGIN_LABEL
297 #define FUNC_BEGIN_LABEL "LFB"
299 #ifndef FUNC_END_LABEL
300 #define FUNC_END_LABEL "LFE"
302 #define CIE_AFTER_SIZE_LABEL "LSCIE"
303 #define CIE_END_LABEL "LECIE"
304 #define CIE_LENGTH_LABEL "LLCIE"
305 #define FDE_LABEL "LSFDE"
306 #define FDE_AFTER_SIZE_LABEL "LASFDE"
307 #define FDE_END_LABEL "LEFDE"
308 #define FDE_LENGTH_LABEL "LLFDE"
309 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
310 #define LINE_NUMBER_END_LABEL "LELT"
311 #define LN_PROLOG_AS_LABEL "LASLTP"
312 #define LN_PROLOG_END_LABEL "LELTP"
313 #define DIE_LABEL_PREFIX "DW"
315 /* Definitions of defaults for various types of primitive assembly language
316 output operations. These may be overridden from within the tm.h file,
317 but typically, that is unnecessary. */
319 #ifndef ASM_OUTPUT_SECTION
320 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
321 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
325 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
326 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
328 fprintf (FILE, "%s", SET_ASM_OP); \
329 assemble_name (FILE, SY); \
331 assemble_name (FILE, HI); \
333 assemble_name (FILE, LO); \
336 #endif /* SET_ASM_OP */
338 /* The DWARF 2 CFA column which tracks the return address. Normally this
339 is the column for PC, or the first column after all of the hard
341 #ifndef DWARF_FRAME_RETURN_COLUMN
343 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
345 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
349 /* The mapping from gcc register number to DWARF 2 CFA column number. By
350 default, we just provide columns for all registers. */
351 #ifndef DWARF_FRAME_REGNUM
352 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
355 /* Hook used by __throw. */
358 expand_builtin_dwarf_fp_regnum ()
360 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
363 /* The offset from the incoming value of %sp to the top of the stack frame
364 for the current function. */
365 #ifndef INCOMING_FRAME_SP_OFFSET
366 #define INCOMING_FRAME_SP_OFFSET 0
369 /* Return a pointer to a copy of the section string name S with all
370 attributes stripped off, and an asterisk prepended (for assemble_name). */
376 char *stripped = xmalloc (strlen (s) + 2);
381 while (*s && *s != ',')
388 /* Generate code to initialize the register size table. */
391 expand_builtin_init_dwarf_reg_sizes (address)
395 enum machine_mode mode = TYPE_MODE (char_type_node);
396 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
397 rtx mem = gen_rtx_MEM (mode, addr);
399 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
401 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
402 int size = GET_MODE_SIZE (reg_raw_mode[i]);
407 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
411 /* Convert a DWARF call frame info. operation to its string name */
414 dwarf_cfi_name (cfi_opc)
415 register unsigned cfi_opc;
419 case DW_CFA_advance_loc:
420 return "DW_CFA_advance_loc";
422 return "DW_CFA_offset";
424 return "DW_CFA_restore";
428 return "DW_CFA_set_loc";
429 case DW_CFA_advance_loc1:
430 return "DW_CFA_advance_loc1";
431 case DW_CFA_advance_loc2:
432 return "DW_CFA_advance_loc2";
433 case DW_CFA_advance_loc4:
434 return "DW_CFA_advance_loc4";
435 case DW_CFA_offset_extended:
436 return "DW_CFA_offset_extended";
437 case DW_CFA_restore_extended:
438 return "DW_CFA_restore_extended";
439 case DW_CFA_undefined:
440 return "DW_CFA_undefined";
441 case DW_CFA_same_value:
442 return "DW_CFA_same_value";
443 case DW_CFA_register:
444 return "DW_CFA_register";
445 case DW_CFA_remember_state:
446 return "DW_CFA_remember_state";
447 case DW_CFA_restore_state:
448 return "DW_CFA_restore_state";
450 return "DW_CFA_def_cfa";
451 case DW_CFA_def_cfa_register:
452 return "DW_CFA_def_cfa_register";
453 case DW_CFA_def_cfa_offset:
454 return "DW_CFA_def_cfa_offset";
455 case DW_CFA_def_cfa_expression:
456 return "DW_CFA_def_cfa_expression";
458 /* SGI/MIPS specific */
459 case DW_CFA_MIPS_advance_loc8:
460 return "DW_CFA_MIPS_advance_loc8";
463 case DW_CFA_GNU_window_save:
464 return "DW_CFA_GNU_window_save";
465 case DW_CFA_GNU_args_size:
466 return "DW_CFA_GNU_args_size";
467 case DW_CFA_GNU_negative_offset_extended:
468 return "DW_CFA_GNU_negative_offset_extended";
471 return "DW_CFA_<unknown>";
475 /* Return a pointer to a newly allocated Call Frame Instruction. */
477 static inline dw_cfi_ref
480 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
482 cfi->dw_cfi_next = NULL;
483 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
484 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
489 /* Add a Call Frame Instruction to list of instructions. */
492 add_cfi (list_head, cfi)
493 register dw_cfi_ref *list_head;
494 register dw_cfi_ref cfi;
496 register dw_cfi_ref *p;
498 /* Find the end of the chain. */
499 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
505 /* Generate a new label for the CFI info to refer to. */
508 dwarf2out_cfi_label ()
510 static char label[20];
511 static unsigned long label_num = 0;
513 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
514 ASM_OUTPUT_LABEL (asm_out_file, label);
519 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
520 or to the CIE if LABEL is NULL. */
523 add_fde_cfi (label, cfi)
524 register const char *label;
525 register dw_cfi_ref cfi;
529 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
532 label = dwarf2out_cfi_label ();
534 if (fde->dw_fde_current_label == NULL
535 || strcmp (label, fde->dw_fde_current_label) != 0)
537 register dw_cfi_ref xcfi;
539 fde->dw_fde_current_label = label = xstrdup (label);
541 /* Set the location counter to the new label. */
543 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
544 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
545 add_cfi (&fde->dw_fde_cfi, xcfi);
548 add_cfi (&fde->dw_fde_cfi, cfi);
552 add_cfi (&cie_cfi_head, cfi);
555 /* Subroutine of lookup_cfa. */
558 lookup_cfa_1 (cfi, loc)
559 register dw_cfi_ref cfi;
560 register dw_cfa_location *loc;
562 switch (cfi->dw_cfi_opc)
564 case DW_CFA_def_cfa_offset:
565 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
567 case DW_CFA_def_cfa_register:
568 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
571 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
572 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
574 case DW_CFA_def_cfa_expression:
575 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
582 /* Find the previous value for the CFA. */
586 register dw_cfa_location *loc;
588 register dw_cfi_ref cfi;
590 loc->reg = (unsigned long) -1;
593 loc->base_offset = 0;
595 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
596 lookup_cfa_1 (cfi, loc);
598 if (fde_table_in_use)
600 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
601 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
602 lookup_cfa_1 (cfi, loc);
606 /* The current rule for calculating the DWARF2 canonical frame address. */
607 static dw_cfa_location cfa;
609 /* The register used for saving registers to the stack, and its offset
611 static dw_cfa_location cfa_store;
613 /* The running total of the size of arguments pushed onto the stack. */
614 static long args_size;
616 /* The last args_size we actually output. */
617 static long old_args_size;
619 /* Entry point to update the canonical frame address (CFA).
620 LABEL is passed to add_fde_cfi. The value of CFA is now to be
621 calculated from REG+OFFSET. */
624 dwarf2out_def_cfa (label, reg, offset)
625 register const char *label;
634 def_cfa_1 (label, &loc);
637 /* This routine does the actual work. The CFA is now calculated from
638 the dw_cfa_location structure. */
640 def_cfa_1 (label, loc_p)
641 register const char *label;
642 dw_cfa_location *loc_p;
644 register dw_cfi_ref cfi;
645 dw_cfa_location old_cfa, loc;
650 if (cfa_store.reg == loc.reg && loc.indirect == 0)
651 cfa_store.offset = loc.offset;
653 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
654 lookup_cfa (&old_cfa);
656 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
657 loc.indirect == old_cfa.indirect)
659 if (loc.indirect == 0
660 || loc.base_offset == old_cfa.base_offset)
661 /* Nothing changed so no need to issue any call frame
668 if (loc.reg == old_cfa.reg && !loc.indirect)
670 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
671 indicating the CFA register did not change but the offset
673 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
674 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
677 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
678 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
681 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
682 indicating the CFA register has changed to <register> but the
683 offset has not changed. */
684 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
685 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
689 else if (loc.indirect == 0)
691 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
692 indicating the CFA register has changed to <register> with
693 the specified offset. */
694 cfi->dw_cfi_opc = DW_CFA_def_cfa;
695 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
696 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
700 /* Construct a DW_CFA_def_cfa_expression instruction to
701 calculate the CFA using a full location expression since no
702 register-offset pair is available. */
703 struct dw_loc_descr_struct *loc_list;
704 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
705 loc_list = build_cfa_loc (&loc);
706 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
709 add_fde_cfi (label, cfi);
712 /* Add the CFI for saving a register. REG is the CFA column number.
713 LABEL is passed to add_fde_cfi.
714 If SREG is -1, the register is saved at OFFSET from the CFA;
715 otherwise it is saved in SREG. */
718 reg_save (label, reg, sreg, offset)
719 register const char *label;
720 register unsigned reg;
721 register unsigned sreg;
722 register long offset;
724 register dw_cfi_ref cfi = new_cfi ();
726 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
728 /* The following comparison is correct. -1 is used to indicate that
729 the value isn't a register number. */
730 if (sreg == (unsigned int) -1)
733 /* The register number won't fit in 6 bits, so we have to use
735 cfi->dw_cfi_opc = DW_CFA_offset_extended;
737 cfi->dw_cfi_opc = DW_CFA_offset;
739 #ifdef ENABLE_CHECKING
741 /* If we get an offset that is not a multiple of
742 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
743 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
745 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
747 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
751 offset /= DWARF_CIE_DATA_ALIGNMENT;
754 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
757 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
759 else if (sreg == reg)
760 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
764 cfi->dw_cfi_opc = DW_CFA_register;
765 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
768 add_fde_cfi (label, cfi);
771 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
772 This CFI tells the unwinder that it needs to restore the window registers
773 from the previous frame's window save area.
775 ??? Perhaps we should note in the CIE where windows are saved (instead of
776 assuming 0(cfa)) and what registers are in the window. */
779 dwarf2out_window_save (label)
780 register const char *label;
782 register dw_cfi_ref cfi = new_cfi ();
783 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
784 add_fde_cfi (label, cfi);
787 /* Add a CFI to update the running total of the size of arguments
788 pushed onto the stack. */
791 dwarf2out_args_size (label, size)
795 register dw_cfi_ref cfi;
797 if (size == old_args_size)
799 old_args_size = size;
802 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
803 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
804 add_fde_cfi (label, cfi);
807 /* Entry point for saving a register to the stack. REG is the GCC register
808 number. LABEL and OFFSET are passed to reg_save. */
811 dwarf2out_reg_save (label, reg, offset)
812 register const char *label;
813 register unsigned reg;
814 register long offset;
816 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
819 /* Entry point for saving the return address in the stack.
820 LABEL and OFFSET are passed to reg_save. */
823 dwarf2out_return_save (label, offset)
824 register const char *label;
825 register long offset;
827 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
830 /* Entry point for saving the return address in a register.
831 LABEL and SREG are passed to reg_save. */
834 dwarf2out_return_reg (label, sreg)
835 register const char *label;
836 register unsigned sreg;
838 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
841 /* Record the initial position of the return address. RTL is
842 INCOMING_RETURN_ADDR_RTX. */
845 initial_return_save (rtl)
848 unsigned int reg = (unsigned int) -1;
851 switch (GET_CODE (rtl))
854 /* RA is in a register. */
855 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
858 /* RA is on the stack. */
860 switch (GET_CODE (rtl))
863 if (REGNO (rtl) != STACK_POINTER_REGNUM)
868 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
870 offset = INTVAL (XEXP (rtl, 1));
873 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
875 offset = -INTVAL (XEXP (rtl, 1));
882 /* The return address is at some offset from any value we can
883 actually load. For instance, on the SPARC it is in %i7+8. Just
884 ignore the offset for now; it doesn't matter for unwinding frames. */
885 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
887 initial_return_save (XEXP (rtl, 0));
893 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
896 /* Given a SET, calculate the amount of stack adjustment it
900 stack_adjust_offset (pattern)
903 rtx src = SET_SRC (pattern);
904 rtx dest = SET_DEST (pattern);
908 if (dest == stack_pointer_rtx)
910 /* (set (reg sp) (plus (reg sp) (const_int))) */
911 code = GET_CODE (src);
912 if (! (code == PLUS || code == MINUS)
913 || XEXP (src, 0) != stack_pointer_rtx
914 || GET_CODE (XEXP (src, 1)) != CONST_INT)
917 offset = INTVAL (XEXP (src, 1));
919 else if (GET_CODE (dest) == MEM)
921 /* (set (mem (pre_dec (reg sp))) (foo)) */
922 src = XEXP (dest, 0);
923 code = GET_CODE (src);
925 if (! (code == PRE_DEC || code == PRE_INC
926 || code == PRE_MODIFY)
927 || XEXP (src, 0) != stack_pointer_rtx)
930 if (code == PRE_MODIFY)
932 rtx val = XEXP (XEXP (src, 1), 1);
933 /* We handle only adjustments by constant amount. */
934 if (GET_CODE (XEXP (src, 1)) != PLUS ||
935 GET_CODE (val) != CONST_INT)
937 offset = -INTVAL (val);
939 else offset = GET_MODE_SIZE (GET_MODE (dest));
944 if (code == PLUS || code == PRE_INC)
950 /* Check INSN to see if it looks like a push or a stack adjustment, and
951 make a note of it if it does. EH uses this information to find out how
952 much extra space it needs to pop off the stack. */
955 dwarf2out_stack_adjust (insn)
961 if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN)
963 /* Extract the size of the args from the CALL rtx itself. */
965 insn = PATTERN (insn);
966 if (GET_CODE (insn) == PARALLEL)
967 insn = XVECEXP (insn, 0, 0);
968 if (GET_CODE (insn) == SET)
969 insn = SET_SRC (insn);
970 if (GET_CODE (insn) != CALL)
972 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
976 /* If only calls can throw, and we have a frame pointer,
977 save up adjustments until we see the CALL_INSN. */
978 else if (! flag_non_call_exceptions
979 && cfa.reg != STACK_POINTER_REGNUM)
982 if (GET_CODE (insn) == BARRIER)
984 /* When we see a BARRIER, we know to reset args_size to 0. Usually
985 the compiler will have already emitted a stack adjustment, but
986 doesn't bother for calls to noreturn functions. */
987 #ifdef STACK_GROWS_DOWNWARD
993 else if (GET_CODE (PATTERN (insn)) == SET)
995 offset = stack_adjust_offset (PATTERN (insn));
997 else if (GET_CODE (PATTERN (insn)) == PARALLEL
998 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1000 /* There may be stack adjustments inside compound insns. Search
1005 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1007 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1008 if (GET_CODE (pattern) == SET)
1009 offset += stack_adjust_offset (pattern);
1018 if (cfa.reg == STACK_POINTER_REGNUM)
1019 cfa.offset += offset;
1021 #ifndef STACK_GROWS_DOWNWARD
1024 args_size += offset;
1028 label = dwarf2out_cfi_label ();
1029 def_cfa_1 (label, &cfa);
1030 dwarf2out_args_size (label, args_size);
1033 /* We delay emitting a register save until either (a) we reach the end
1034 of the prologue or (b) the register is clobbered. This clusters
1035 register saves so that there are fewer pc advances. */
1037 struct queued_reg_save
1039 struct queued_reg_save *next;
1044 static struct queued_reg_save *queued_reg_saves;
1045 static const char *last_reg_save_label;
1048 queue_reg_save (label, reg, offset)
1053 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1055 q->next = queued_reg_saves;
1057 q->cfa_offset = offset;
1058 queued_reg_saves = q;
1060 last_reg_save_label = label;
1064 flush_queued_reg_saves ()
1066 struct queued_reg_save *q, *next;
1068 for (q = queued_reg_saves; q ; q = next)
1070 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1075 queued_reg_saves = NULL;
1076 last_reg_save_label = NULL;
1080 clobbers_queued_reg_save (insn)
1083 struct queued_reg_save *q;
1085 for (q = queued_reg_saves; q ; q = q->next)
1086 if (modified_in_p (q->reg, insn))
1093 /* A temporary register holding an integral value used in adjusting SP
1094 or setting up the store_reg. The "offset" field holds the integer
1095 value, not an offset. */
1096 static dw_cfa_location cfa_temp;
1098 /* Record call frame debugging information for an expression EXPR,
1099 which either sets SP or FP (adjusting how we calculate the frame
1100 address) or saves a register to the stack. LABEL indicates the
1103 This function encodes a state machine mapping rtxes to actions on
1104 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1105 users need not read the source code.
1107 The High-Level Picture
1109 Changes in the register we use to calculate the CFA: Currently we
1110 assume that if you copy the CFA register into another register, we
1111 should take the other one as the new CFA register; this seems to
1112 work pretty well. If it's wrong for some target, it's simple
1113 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1115 Changes in the register we use for saving registers to the stack:
1116 This is usually SP, but not always. Again, we deduce that if you
1117 copy SP into another register (and SP is not the CFA register),
1118 then the new register is the one we will be using for register
1119 saves. This also seems to work.
1121 Register saves: There's not much guesswork about this one; if
1122 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1123 register save, and the register used to calculate the destination
1124 had better be the one we think we're using for this purpose.
1126 Except: If the register being saved is the CFA register, and the
1127 offset is non-zero, we are saving the CFA, so we assume we have to
1128 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1129 the intent is to save the value of SP from the previous frame.
1131 Invariants / Summaries of Rules
1133 cfa current rule for calculating the CFA. It usually
1134 consists of a register and an offset.
1135 cfa_store register used by prologue code to save things to the stack
1136 cfa_store.offset is the offset from the value of
1137 cfa_store.reg to the actual CFA
1138 cfa_temp register holding an integral value. cfa_temp.offset
1139 stores the value, which will be used to adjust the
1140 stack pointer. cfa_temp is also used like cfa_store,
1141 to track stores to the stack via fp or a temp reg.
1143 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1144 with cfa.reg as the first operand changes the cfa.reg and its
1145 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1148 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1149 expression yielding a constant. This sets cfa_temp.reg
1150 and cfa_temp.offset.
1152 Rule 5: Create a new register cfa_store used to save items to the
1155 Rules 10-14: Save a register to the stack. Define offset as the
1156 difference of the original location and cfa_store's
1157 location (or cfa_temp's location if cfa_temp is used).
1161 "{a,b}" indicates a choice of a xor b.
1162 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1165 (set <reg1> <reg2>:cfa.reg)
1166 effects: cfa.reg = <reg1>
1167 cfa.offset unchanged
1168 cfa_temp.reg = <reg1>
1169 cfa_temp.offset = cfa.offset
1172 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1173 effects: cfa.reg = sp if fp used
1174 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1175 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1176 if cfa_store.reg==sp
1179 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1180 effects: cfa.reg = fp
1181 cfa_offset += +/- <const_int>
1184 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1185 constraints: <reg1> != fp
1187 effects: cfa.reg = <reg1>
1188 cfa_temp.reg = <reg1>
1189 cfa_temp.offset = cfa.offset
1192 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1193 constraints: <reg1> != fp
1195 effects: cfa_store.reg = <reg1>
1196 cfa_store.offset = cfa.offset - cfa_temp.offset
1199 (set <reg> <const_int>)
1200 effects: cfa_temp.reg = <reg>
1201 cfa_temp.offset = <const_int>
1204 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1205 effects: cfa_temp.reg = <reg1>
1206 cfa_temp.offset |= <const_int>
1209 (set <reg> (high <exp>))
1213 (set <reg> (lo_sum <exp> <const_int>))
1214 effects: cfa_temp.reg = <reg>
1215 cfa_temp.offset = <const_int>
1218 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1219 effects: cfa_store.offset -= <const_int>
1220 cfa.offset = cfa_store.offset if cfa.reg == sp
1222 cfa.base_offset = -cfa_store.offset
1225 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1226 effects: cfa_store.offset += -/+ mode_size(mem)
1227 cfa.offset = cfa_store.offset if cfa.reg == sp
1229 cfa.base_offset = -cfa_store.offset
1232 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>)
1233 effects: cfa.reg = <reg1>
1234 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1237 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1238 effects: cfa.reg = <reg1>
1239 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1242 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1243 effects: cfa.reg = <reg1>
1244 cfa.base_offset = -cfa_temp.offset
1245 cfa_temp.offset -= mode_size(mem) */
1248 dwarf2out_frame_debug_expr (expr, label)
1255 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1256 the PARALLEL independently. The first element is always processed if
1257 it is a SET. This is for backward compatibility. Other elements
1258 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1259 flag is set in them. */
1261 if (GET_CODE (expr) == PARALLEL
1262 || GET_CODE (expr) == SEQUENCE)
1265 int limit = XVECLEN (expr, 0);
1267 for (par_index = 0; par_index < limit; par_index++)
1269 rtx x = XVECEXP (expr, 0, par_index);
1271 if (GET_CODE (x) == SET &&
1272 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1273 dwarf2out_frame_debug_expr (x, label);
1278 if (GET_CODE (expr) != SET)
1281 src = SET_SRC (expr);
1282 dest = SET_DEST (expr);
1284 switch (GET_CODE (dest))
1288 /* Update the CFA rule wrt SP or FP. Make sure src is
1289 relative to the current CFA register. */
1290 switch (GET_CODE (src))
1292 /* Setting FP from SP. */
1294 if (cfa.reg == (unsigned) REGNO (src))
1300 /* We used to require that dest be either SP or FP, but the
1301 ARM copies SP to a temporary register, and from there to
1302 FP. So we just rely on the backends to only set
1303 RTX_FRAME_RELATED_P on appropriate insns. */
1304 cfa.reg = REGNO (dest);
1305 cfa_temp.reg = cfa.reg;
1306 cfa_temp.offset = cfa.offset;
1312 if (dest == stack_pointer_rtx)
1316 switch (GET_CODE (XEXP (src, 1)))
1319 offset = INTVAL (XEXP (src, 1));
1322 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1324 offset = cfa_temp.offset;
1330 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1332 /* Restoring SP from FP in the epilogue. */
1333 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1335 cfa.reg = STACK_POINTER_REGNUM;
1337 else if (GET_CODE (src) == LO_SUM)
1338 /* Assume we've set the source reg of the LO_SUM from sp. */
1340 else if (XEXP (src, 0) != stack_pointer_rtx)
1343 if (GET_CODE (src) != MINUS)
1345 if (cfa.reg == STACK_POINTER_REGNUM)
1346 cfa.offset += offset;
1347 if (cfa_store.reg == STACK_POINTER_REGNUM)
1348 cfa_store.offset += offset;
1350 else if (dest == hard_frame_pointer_rtx)
1353 /* Either setting the FP from an offset of the SP,
1354 or adjusting the FP */
1355 if (! frame_pointer_needed)
1358 if (GET_CODE (XEXP (src, 0)) == REG
1359 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1360 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1362 offset = INTVAL (XEXP (src, 1));
1363 if (GET_CODE (src) != MINUS)
1365 cfa.offset += offset;
1366 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1373 if (GET_CODE (src) == MINUS)
1377 if (GET_CODE (XEXP (src, 0)) == REG
1378 && REGNO (XEXP (src, 0)) == cfa.reg
1379 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1381 /* Setting a temporary CFA register that will be copied
1382 into the FP later on. */
1383 offset = - INTVAL (XEXP (src, 1));
1384 cfa.offset += offset;
1385 cfa.reg = REGNO (dest);
1386 /* Or used to save regs to the stack. */
1387 cfa_temp.reg = cfa.reg;
1388 cfa_temp.offset = cfa.offset;
1391 else if (GET_CODE (XEXP (src, 0)) == REG
1392 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1393 && XEXP (src, 1) == stack_pointer_rtx)
1395 /* Setting a scratch register that we will use instead
1396 of SP for saving registers to the stack. */
1397 if (cfa.reg != STACK_POINTER_REGNUM)
1399 cfa_store.reg = REGNO (dest);
1400 cfa_store.offset = cfa.offset - cfa_temp.offset;
1403 else if (GET_CODE (src) == LO_SUM
1404 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1406 cfa_temp.reg = REGNO (dest);
1407 cfa_temp.offset = INTVAL (XEXP (src, 1));
1416 cfa_temp.reg = REGNO (dest);
1417 cfa_temp.offset = INTVAL (src);
1422 if (GET_CODE (XEXP (src, 0)) != REG
1423 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1424 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1426 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1427 cfa_temp.reg = REGNO (dest);
1428 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1431 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1432 which will fill in all of the bits. */
1440 def_cfa_1 (label, &cfa);
1444 if (GET_CODE (src) != REG)
1447 /* Saving a register to the stack. Make sure dest is relative to the
1449 switch (GET_CODE (XEXP (dest, 0)))
1454 /* We can't handle variable size modifications. */
1455 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1457 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1459 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1460 || cfa_store.reg != STACK_POINTER_REGNUM)
1462 cfa_store.offset += offset;
1463 if (cfa.reg == STACK_POINTER_REGNUM)
1464 cfa.offset = cfa_store.offset;
1466 offset = -cfa_store.offset;
1471 offset = GET_MODE_SIZE (GET_MODE (dest));
1472 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1475 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1476 || cfa_store.reg != STACK_POINTER_REGNUM)
1478 cfa_store.offset += offset;
1479 if (cfa.reg == STACK_POINTER_REGNUM)
1480 cfa.offset = cfa_store.offset;
1482 offset = -cfa_store.offset;
1486 /* With an offset. */
1490 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1492 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1493 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1496 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1497 offset -= cfa_store.offset;
1498 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1499 offset -= cfa_temp.offset;
1505 /* Without an offset. */
1507 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1508 offset = -cfa_store.offset;
1509 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1510 offset = -cfa_temp.offset;
1517 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1519 offset = -cfa_temp.offset;
1520 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1527 if (REGNO (src) != STACK_POINTER_REGNUM
1528 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1529 && (unsigned) REGNO (src) == cfa.reg)
1531 /* We're storing the current CFA reg into the stack. */
1533 if (cfa.offset == 0)
1535 /* If the source register is exactly the CFA, assume
1536 we're saving SP like any other register; this happens
1539 def_cfa_1 (label, &cfa);
1540 queue_reg_save (label, stack_pointer_rtx, offset);
1545 /* Otherwise, we'll need to look in the stack to
1546 calculate the CFA. */
1548 rtx x = XEXP (dest, 0);
1549 if (GET_CODE (x) != REG)
1551 if (GET_CODE (x) != REG)
1553 cfa.reg = (unsigned) REGNO (x);
1554 cfa.base_offset = offset;
1556 def_cfa_1 (label, &cfa);
1561 def_cfa_1 (label, &cfa);
1562 queue_reg_save (label, src, offset);
1570 /* Record call frame debugging information for INSN, which either
1571 sets SP or FP (adjusting how we calculate the frame address) or saves a
1572 register to the stack. If INSN is NULL_RTX, initialize our state. */
1575 dwarf2out_frame_debug (insn)
1581 if (insn == NULL_RTX)
1583 /* Flush any queued register saves. */
1584 flush_queued_reg_saves ();
1586 /* Set up state for generating call frame debug info. */
1588 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1590 cfa.reg = STACK_POINTER_REGNUM;
1593 cfa_temp.offset = 0;
1597 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1598 flush_queued_reg_saves ();
1600 if (! RTX_FRAME_RELATED_P (insn))
1602 if (!ACCUMULATE_OUTGOING_ARGS)
1603 dwarf2out_stack_adjust (insn);
1607 label = dwarf2out_cfi_label ();
1609 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1611 insn = XEXP (src, 0);
1613 insn = PATTERN (insn);
1615 dwarf2out_frame_debug_expr (insn, label);
1618 /* Output a Call Frame Information opcode and its operand(s). */
1621 output_cfi (cfi, fde, for_eh)
1622 register dw_cfi_ref cfi;
1623 register dw_fde_ref fde;
1626 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1628 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1629 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1630 "DW_CFA_advance_loc 0x%lx",
1631 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1633 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1635 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1636 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1637 "DW_CFA_offset, column 0x%lx",
1638 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1639 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1641 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1643 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1644 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1645 "DW_CFA_restore, column 0x%lx",
1646 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1650 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1651 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1653 switch (cfi->dw_cfi_opc)
1655 case DW_CFA_set_loc:
1657 dw2_asm_output_encoded_addr_rtx (
1658 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1659 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1662 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1663 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1665 case DW_CFA_advance_loc1:
1666 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1667 fde->dw_fde_current_label, NULL);
1668 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1670 case DW_CFA_advance_loc2:
1671 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1672 fde->dw_fde_current_label, NULL);
1673 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1675 case DW_CFA_advance_loc4:
1676 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1677 fde->dw_fde_current_label, NULL);
1678 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1680 case DW_CFA_MIPS_advance_loc8:
1681 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1682 fde->dw_fde_current_label, NULL);
1683 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1685 case DW_CFA_offset_extended:
1686 case DW_CFA_GNU_negative_offset_extended:
1687 case DW_CFA_def_cfa:
1688 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1689 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1691 case DW_CFA_restore_extended:
1692 case DW_CFA_undefined:
1693 case DW_CFA_same_value:
1694 case DW_CFA_def_cfa_register:
1695 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1697 case DW_CFA_register:
1698 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1699 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1701 case DW_CFA_def_cfa_offset:
1702 case DW_CFA_GNU_args_size:
1703 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1705 case DW_CFA_GNU_window_save:
1707 case DW_CFA_def_cfa_expression:
1708 output_cfa_loc (cfi);
1716 /* Output the call frame information used to used to record information
1717 that relates to calculating the frame pointer, and records the
1718 location of saved registers. */
1721 output_call_frame_info (for_eh)
1724 register unsigned int i;
1725 register dw_fde_ref fde;
1726 register dw_cfi_ref cfi;
1727 char l1[20], l2[20];
1728 int any_lsda_needed = 0;
1729 char augmentation[6];
1730 int augmentation_size;
1731 int fde_encoding = DW_EH_PE_absptr;
1732 int per_encoding = DW_EH_PE_absptr;
1733 int lsda_encoding = DW_EH_PE_absptr;
1735 /* If we don't have any functions we'll want to unwind out of, don't
1736 emit any EH unwind information. */
1739 int any_eh_needed = 0;
1740 for (i = 0; i < fde_table_in_use; ++i)
1741 if (fde_table[i].uses_eh_lsda)
1742 any_eh_needed = any_lsda_needed = 1;
1743 else if (! fde_table[i].nothrow)
1746 if (! any_eh_needed)
1750 /* We're going to be generating comments, so turn on app. */
1756 #ifdef EH_FRAME_SECTION
1757 EH_FRAME_SECTION ();
1759 tree label = get_file_function_name ('F');
1761 force_data_section ();
1762 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1763 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1764 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1766 assemble_label ("__FRAME_BEGIN__");
1769 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_FRAME_SECTION);
1771 /* Output the CIE. */
1772 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1773 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1774 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1775 "Length of Common Information Entry");
1776 ASM_OUTPUT_LABEL (asm_out_file, l1);
1778 /* Now that the CIE pointer is PC-relative for EH,
1779 use 0 to identify the CIE. */
1780 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1781 (for_eh ? 0 : DW_CIE_ID),
1782 "CIE Identifier Tag");
1784 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1786 augmentation[0] = 0;
1787 augmentation_size = 0;
1793 z Indicates that a uleb128 is present to size the
1794 augmentation section.
1795 L Indicates the encoding (and thus presence) of
1796 an LSDA pointer in the FDE augmentation.
1797 R Indicates a non-default pointer encoding for
1799 P Indicates the presence of an encoding + language
1800 personality routine in the CIE augmentation. */
1802 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1803 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1804 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1806 p = augmentation + 1;
1807 if (eh_personality_libfunc)
1810 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1812 if (any_lsda_needed)
1815 augmentation_size += 1;
1817 if (fde_encoding != DW_EH_PE_absptr)
1820 augmentation_size += 1;
1822 if (p > augmentation + 1)
1824 augmentation[0] = 'z';
1828 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1829 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1831 int offset = ( 4 /* Length */
1833 + 1 /* CIE version */
1834 + strlen (augmentation) + 1 /* Augmentation */
1835 + size_of_uleb128 (1) /* Code alignment */
1836 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1838 + 1 /* Augmentation size */
1839 + 1 /* Personality encoding */ );
1840 int pad = -offset & (PTR_SIZE - 1);
1842 augmentation_size += pad;
1844 /* Augmentations should be small, so there's scarce need to
1845 iterate for a solution. Die if we exceed one uleb128 byte. */
1846 if (size_of_uleb128 (augmentation_size) != 1)
1850 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1852 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1854 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1855 "CIE Data Alignment Factor");
1857 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1859 if (augmentation[0])
1861 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1862 if (eh_personality_libfunc)
1864 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1865 eh_data_format_name (per_encoding));
1866 dw2_asm_output_encoded_addr_rtx (per_encoding,
1867 eh_personality_libfunc, NULL);
1869 if (any_lsda_needed)
1870 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1871 eh_data_format_name (lsda_encoding));
1872 if (fde_encoding != DW_EH_PE_absptr)
1873 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1874 eh_data_format_name (fde_encoding));
1877 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1878 output_cfi (cfi, NULL, for_eh);
1880 /* Pad the CIE out to an address sized boundary. */
1881 ASM_OUTPUT_ALIGN (asm_out_file,
1882 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1883 ASM_OUTPUT_LABEL (asm_out_file, l2);
1885 /* Loop through all of the FDE's. */
1886 for (i = 0; i < fde_table_in_use; ++i)
1888 fde = &fde_table[i];
1890 /* Don't emit EH unwind info for leaf functions that don't need it. */
1891 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1894 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1895 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1896 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1897 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1899 ASM_OUTPUT_LABEL (asm_out_file, l1);
1901 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1902 emits a target dependent sized offset when for_eh is not true.
1903 This inconsistency may confuse gdb. The only case where we need a
1904 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1905 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1906 though in order to be compatible with the dwarf_fde struct in frame.c.
1907 If the for_eh case is changed, then the struct in frame.c has
1908 to be adjusted appropriately. */
1910 dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset");
1912 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
1913 stripattributes (DEBUG_FRAME_SECTION),
1918 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1919 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1920 "FDE initial location");
1921 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1922 fde->dw_fde_end, fde->dw_fde_begin,
1923 "FDE address range");
1927 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1928 "FDE initial location");
1929 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1930 fde->dw_fde_end, fde->dw_fde_begin,
1931 "FDE address range");
1934 if (augmentation[0])
1936 if (any_lsda_needed)
1938 int size = size_of_encoded_value (lsda_encoding);
1940 if (lsda_encoding == DW_EH_PE_aligned)
1942 int offset = ( 4 /* Length */
1943 + 4 /* CIE offset */
1944 + 2 * size_of_encoded_value (fde_encoding)
1945 + 1 /* Augmentation size */ );
1946 int pad = -offset & (PTR_SIZE - 1);
1949 if (size_of_uleb128 (size) != 1)
1953 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1955 if (fde->uses_eh_lsda)
1957 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
1958 fde->funcdef_number);
1959 dw2_asm_output_encoded_addr_rtx (
1960 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
1961 "Language Specific Data Area");
1965 if (lsda_encoding == DW_EH_PE_aligned)
1966 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1967 dw2_asm_output_data (size_of_encoded_value (lsda_encoding),
1968 0, "Language Specific Data Area (none)");
1972 dw2_asm_output_data_uleb128 (0, "Augmentation size");
1975 /* Loop through the Call Frame Instructions associated with
1977 fde->dw_fde_current_label = fde->dw_fde_begin;
1978 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1979 output_cfi (cfi, fde, for_eh);
1981 /* Pad the FDE out to an address sized boundary. */
1982 ASM_OUTPUT_ALIGN (asm_out_file,
1983 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1984 ASM_OUTPUT_LABEL (asm_out_file, l2);
1987 #ifndef EH_FRAME_SECTION
1989 dw2_asm_output_data (4, 0, "End of Table");
1991 #ifdef MIPS_DEBUGGING_INFO
1992 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1993 get a value of 0. Putting .align 0 after the label fixes it. */
1994 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1997 /* Turn off app to make assembly quicker. */
2002 /* Output a marker (i.e. a label) for the beginning of a function, before
2006 dwarf2out_begin_prologue (line, file)
2007 unsigned int line ATTRIBUTE_UNUSED;
2008 const char *file ATTRIBUTE_UNUSED;
2010 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2011 register dw_fde_ref fde;
2013 current_function_func_begin_label = 0;
2015 #ifdef IA64_UNWIND_INFO
2016 /* ??? current_function_func_begin_label is also used by except.c
2017 for call-site information. We must emit this label if it might
2019 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2020 && ! dwarf2out_do_frame ())
2023 if (! dwarf2out_do_frame ())
2027 ++current_funcdef_number;
2029 function_section (current_function_decl);
2030 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2031 current_funcdef_number);
2032 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2033 current_funcdef_number);
2034 current_function_func_begin_label = get_identifier (label);
2036 #ifdef IA64_UNWIND_INFO
2037 /* We can elide the fde allocation if we're not emitting debug info. */
2038 if (! dwarf2out_do_frame ())
2042 /* Expand the fde table if necessary. */
2043 if (fde_table_in_use == fde_table_allocated)
2045 fde_table_allocated += FDE_TABLE_INCREMENT;
2047 = (dw_fde_ref) xrealloc (fde_table,
2048 fde_table_allocated * sizeof (dw_fde_node));
2051 /* Record the FDE associated with this function. */
2052 current_funcdef_fde = fde_table_in_use;
2054 /* Add the new FDE at the end of the fde_table. */
2055 fde = &fde_table[fde_table_in_use++];
2056 fde->dw_fde_begin = xstrdup (label);
2057 fde->dw_fde_current_label = NULL;
2058 fde->dw_fde_end = NULL;
2059 fde->dw_fde_cfi = NULL;
2060 fde->funcdef_number = current_funcdef_number;
2061 fde->nothrow = current_function_nothrow;
2062 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2064 args_size = old_args_size = 0;
2066 /* We only want to output line number information for the genuine
2067 dwarf2 prologue case, not the eh frame case. */
2068 #ifdef DWARF2_DEBUGGING_INFO
2070 dwarf2out_source_line (line, file);
2074 /* Output a marker (i.e. a label) for the absolute end of the generated code
2075 for a function definition. This gets called *after* the epilogue code has
2079 dwarf2out_end_epilogue ()
2082 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2084 /* Output a label to mark the endpoint of the code generated for this
2086 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2087 ASM_OUTPUT_LABEL (asm_out_file, label);
2088 fde = &fde_table[fde_table_in_use - 1];
2089 fde->dw_fde_end = xstrdup (label);
2093 dwarf2out_frame_init ()
2095 /* Allocate the initial hunk of the fde_table. */
2096 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2097 fde_table_allocated = FDE_TABLE_INCREMENT;
2098 fde_table_in_use = 0;
2100 /* Generate the CFA instructions common to all FDE's. Do it now for the
2101 sake of lookup_cfa. */
2103 #ifdef DWARF2_UNWIND_INFO
2104 /* On entry, the Canonical Frame Address is at SP. */
2105 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2106 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2111 dwarf2out_frame_finish ()
2113 /* Output call frame information. */
2114 #ifdef MIPS_DEBUGGING_INFO
2115 if (write_symbols == DWARF2_DEBUG)
2116 output_call_frame_info (0);
2117 if (flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
2118 output_call_frame_info (1);
2120 if (write_symbols == DWARF2_DEBUG
2121 || flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
2122 output_call_frame_info (1);
2126 /* And now, the subset of the debugging information support code necessary
2127 for emitting location expressions. */
2129 typedef struct dw_val_struct *dw_val_ref;
2130 typedef struct die_struct *dw_die_ref;
2131 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2132 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2134 /* Each DIE may have a series of attribute/value pairs. Values
2135 can take on several forms. The forms that are used in this
2136 implementation are listed below. */
2141 dw_val_class_offset,
2143 dw_val_class_loc_list,
2145 dw_val_class_unsigned_const,
2146 dw_val_class_long_long,
2149 dw_val_class_die_ref,
2150 dw_val_class_fde_ref,
2151 dw_val_class_lbl_id,
2152 dw_val_class_lbl_offset,
2157 /* Describe a double word constant value. */
2158 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2160 typedef struct dw_long_long_struct
2167 /* Describe a floating point constant value. */
2169 typedef struct dw_fp_struct
2176 /* The dw_val_node describes an attribute's value, as it is
2177 represented internally. */
2179 typedef struct dw_val_struct
2181 dw_val_class val_class;
2185 long unsigned val_offset;
2186 dw_loc_list_ref val_loc_list;
2187 dw_loc_descr_ref val_loc;
2189 long unsigned val_unsigned;
2190 dw_long_long_const val_long_long;
2191 dw_float_const val_float;
2196 unsigned val_fde_index;
2199 unsigned char val_flag;
2205 /* Locations in memory are described using a sequence of stack machine
2208 typedef struct dw_loc_descr_struct
2210 dw_loc_descr_ref dw_loc_next;
2211 enum dwarf_location_atom dw_loc_opc;
2212 dw_val_node dw_loc_oprnd1;
2213 dw_val_node dw_loc_oprnd2;
2218 /* Location lists are ranges + location descriptions for that range,
2219 so you can track variables that are in different places over
2220 their entire life. */
2221 typedef struct dw_loc_list_struct
2223 dw_loc_list_ref dw_loc_next;
2224 const char *begin; /* Label for begin address of range */
2225 const char *end; /* Label for end address of range */
2226 char *ll_symbol; /* Label for beginning of location list. Only on head of list */
2227 const char *section; /* Section this loclist is relative to */
2228 dw_loc_descr_ref expr;
2231 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2232 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2235 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2237 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2238 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2239 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2240 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2242 /* Convert a DWARF stack opcode into its string name. */
2245 dwarf_stack_op_name (op)
2246 register unsigned op;
2251 return "DW_OP_addr";
2253 return "DW_OP_deref";
2255 return "DW_OP_const1u";
2257 return "DW_OP_const1s";
2259 return "DW_OP_const2u";
2261 return "DW_OP_const2s";
2263 return "DW_OP_const4u";
2265 return "DW_OP_const4s";
2267 return "DW_OP_const8u";
2269 return "DW_OP_const8s";
2271 return "DW_OP_constu";
2273 return "DW_OP_consts";
2277 return "DW_OP_drop";
2279 return "DW_OP_over";
2281 return "DW_OP_pick";
2283 return "DW_OP_swap";
2287 return "DW_OP_xderef";
2295 return "DW_OP_minus";
2307 return "DW_OP_plus";
2308 case DW_OP_plus_uconst:
2309 return "DW_OP_plus_uconst";
2315 return "DW_OP_shra";
2333 return "DW_OP_skip";
2335 return "DW_OP_lit0";
2337 return "DW_OP_lit1";
2339 return "DW_OP_lit2";
2341 return "DW_OP_lit3";
2343 return "DW_OP_lit4";
2345 return "DW_OP_lit5";
2347 return "DW_OP_lit6";
2349 return "DW_OP_lit7";
2351 return "DW_OP_lit8";
2353 return "DW_OP_lit9";
2355 return "DW_OP_lit10";
2357 return "DW_OP_lit11";
2359 return "DW_OP_lit12";
2361 return "DW_OP_lit13";
2363 return "DW_OP_lit14";
2365 return "DW_OP_lit15";
2367 return "DW_OP_lit16";
2369 return "DW_OP_lit17";
2371 return "DW_OP_lit18";
2373 return "DW_OP_lit19";
2375 return "DW_OP_lit20";
2377 return "DW_OP_lit21";
2379 return "DW_OP_lit22";
2381 return "DW_OP_lit23";
2383 return "DW_OP_lit24";
2385 return "DW_OP_lit25";
2387 return "DW_OP_lit26";
2389 return "DW_OP_lit27";
2391 return "DW_OP_lit28";
2393 return "DW_OP_lit29";
2395 return "DW_OP_lit30";
2397 return "DW_OP_lit31";
2399 return "DW_OP_reg0";
2401 return "DW_OP_reg1";
2403 return "DW_OP_reg2";
2405 return "DW_OP_reg3";
2407 return "DW_OP_reg4";
2409 return "DW_OP_reg5";
2411 return "DW_OP_reg6";
2413 return "DW_OP_reg7";
2415 return "DW_OP_reg8";
2417 return "DW_OP_reg9";
2419 return "DW_OP_reg10";
2421 return "DW_OP_reg11";
2423 return "DW_OP_reg12";
2425 return "DW_OP_reg13";
2427 return "DW_OP_reg14";
2429 return "DW_OP_reg15";
2431 return "DW_OP_reg16";
2433 return "DW_OP_reg17";
2435 return "DW_OP_reg18";
2437 return "DW_OP_reg19";
2439 return "DW_OP_reg20";
2441 return "DW_OP_reg21";
2443 return "DW_OP_reg22";
2445 return "DW_OP_reg23";
2447 return "DW_OP_reg24";
2449 return "DW_OP_reg25";
2451 return "DW_OP_reg26";
2453 return "DW_OP_reg27";
2455 return "DW_OP_reg28";
2457 return "DW_OP_reg29";
2459 return "DW_OP_reg30";
2461 return "DW_OP_reg31";
2463 return "DW_OP_breg0";
2465 return "DW_OP_breg1";
2467 return "DW_OP_breg2";
2469 return "DW_OP_breg3";
2471 return "DW_OP_breg4";
2473 return "DW_OP_breg5";
2475 return "DW_OP_breg6";
2477 return "DW_OP_breg7";
2479 return "DW_OP_breg8";
2481 return "DW_OP_breg9";
2483 return "DW_OP_breg10";
2485 return "DW_OP_breg11";
2487 return "DW_OP_breg12";
2489 return "DW_OP_breg13";
2491 return "DW_OP_breg14";
2493 return "DW_OP_breg15";
2495 return "DW_OP_breg16";
2497 return "DW_OP_breg17";
2499 return "DW_OP_breg18";
2501 return "DW_OP_breg19";
2503 return "DW_OP_breg20";
2505 return "DW_OP_breg21";
2507 return "DW_OP_breg22";
2509 return "DW_OP_breg23";
2511 return "DW_OP_breg24";
2513 return "DW_OP_breg25";
2515 return "DW_OP_breg26";
2517 return "DW_OP_breg27";
2519 return "DW_OP_breg28";
2521 return "DW_OP_breg29";
2523 return "DW_OP_breg30";
2525 return "DW_OP_breg31";
2527 return "DW_OP_regx";
2529 return "DW_OP_fbreg";
2531 return "DW_OP_bregx";
2533 return "DW_OP_piece";
2534 case DW_OP_deref_size:
2535 return "DW_OP_deref_size";
2536 case DW_OP_xderef_size:
2537 return "DW_OP_xderef_size";
2541 return "OP_<unknown>";
2545 /* Return a pointer to a newly allocated location description. Location
2546 descriptions are simple expression terms that can be strung
2547 together to form more complicated location (address) descriptions. */
2549 static inline dw_loc_descr_ref
2550 new_loc_descr (op, oprnd1, oprnd2)
2551 register enum dwarf_location_atom op;
2552 register unsigned long oprnd1;
2553 register unsigned long oprnd2;
2555 /* Use xcalloc here so we clear out all of the long_long constant in
2557 register dw_loc_descr_ref descr
2558 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2560 descr->dw_loc_opc = op;
2561 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2562 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2563 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2564 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2570 /* Add a location description term to a location description expression. */
2573 add_loc_descr (list_head, descr)
2574 register dw_loc_descr_ref *list_head;
2575 register dw_loc_descr_ref descr;
2577 register dw_loc_descr_ref *d;
2579 /* Find the end of the chain. */
2580 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2586 /* Return the size of a location descriptor. */
2588 static unsigned long
2589 size_of_loc_descr (loc)
2590 register dw_loc_descr_ref loc;
2592 register unsigned long size = 1;
2594 switch (loc->dw_loc_opc)
2597 size += DWARF2_ADDR_SIZE;
2616 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2619 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2624 case DW_OP_plus_uconst:
2625 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2663 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2666 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2669 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2672 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2673 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2676 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2678 case DW_OP_deref_size:
2679 case DW_OP_xderef_size:
2689 /* Return the size of a series of location descriptors. */
2691 static unsigned long
2693 register dw_loc_descr_ref loc;
2695 register unsigned long size = 0;
2697 for (; loc != NULL; loc = loc->dw_loc_next)
2699 loc->dw_loc_addr = size;
2700 size += size_of_loc_descr (loc);
2706 /* Output location description stack opcode's operands (if any). */
2709 output_loc_operands (loc)
2710 register dw_loc_descr_ref loc;
2712 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2713 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2715 switch (loc->dw_loc_opc)
2717 #ifdef DWARF2_DEBUGGING_INFO
2719 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2723 dw2_asm_output_data (2, val1->v.val_int, NULL);
2727 dw2_asm_output_data (4, val1->v.val_int, NULL);
2731 if (HOST_BITS_PER_LONG < 64)
2733 dw2_asm_output_data (8, val1->v.val_int, NULL);
2740 if (val1->val_class == dw_val_class_loc)
2741 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2745 dw2_asm_output_data (2, offset, NULL);
2758 /* We currently don't make any attempt to make sure these are
2759 aligned properly like we do for the main unwind info, so
2760 don't support emitting things larger than a byte if we're
2761 only doing unwinding. */
2766 dw2_asm_output_data (1, val1->v.val_int, NULL);
2769 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2772 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2775 dw2_asm_output_data (1, val1->v.val_int, NULL);
2777 case DW_OP_plus_uconst:
2778 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2812 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2815 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2818 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2821 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2822 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2825 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2827 case DW_OP_deref_size:
2828 case DW_OP_xderef_size:
2829 dw2_asm_output_data (1, val1->v.val_int, NULL);
2832 /* Other codes have no operands. */
2837 /* Output a sequence of location operations. */
2840 output_loc_sequence (loc)
2841 dw_loc_descr_ref loc;
2843 for (; loc != NULL; loc = loc->dw_loc_next)
2845 /* Output the opcode. */
2846 dw2_asm_output_data (1, loc->dw_loc_opc,
2847 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2849 /* Output the operand(s) (if any). */
2850 output_loc_operands (loc);
2854 /* This routine will generate the correct assembly data for a location
2855 description based on a cfi entry with a complex address. */
2858 output_cfa_loc (cfi)
2861 dw_loc_descr_ref loc;
2864 /* Output the size of the block. */
2865 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2866 size = size_of_locs (loc);
2867 dw2_asm_output_data_uleb128 (size, NULL);
2869 /* Now output the operations themselves. */
2870 output_loc_sequence (loc);
2873 /* This function builds a dwarf location descriptor seqeunce from
2874 a dw_cfa_location. */
2876 static struct dw_loc_descr_struct *
2878 dw_cfa_location *cfa;
2880 struct dw_loc_descr_struct *head, *tmp;
2882 if (cfa->indirect == 0)
2885 if (cfa->base_offset)
2888 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2890 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2892 else if (cfa->reg <= 31)
2893 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2895 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2896 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2897 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2898 add_loc_descr (&head, tmp);
2899 if (cfa->offset != 0)
2901 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2902 add_loc_descr (&head, tmp);
2907 /* This function fills in aa dw_cfa_location structure from a
2908 dwarf location descriptor sequence. */
2911 get_cfa_from_loc_descr (cfa, loc)
2912 dw_cfa_location *cfa;
2913 struct dw_loc_descr_struct *loc;
2915 struct dw_loc_descr_struct *ptr;
2917 cfa->base_offset = 0;
2921 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2923 enum dwarf_location_atom op = ptr->dw_loc_opc;
2958 cfa->reg = op - DW_OP_reg0;
2961 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2995 cfa->reg = op - DW_OP_breg0;
2996 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2999 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3000 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3005 case DW_OP_plus_uconst:
3006 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3009 internal_error ("DW_LOC_OP %s not implememnted\n",
3010 dwarf_stack_op_name (ptr->dw_loc_opc));
3014 #endif /* .debug_frame support */
3016 /* And now, the support for symbolic debugging information. */
3017 #ifdef DWARF2_DEBUGGING_INFO
3019 static void dwarf2out_init PARAMS ((const char *));
3020 static void dwarf2out_finish PARAMS ((const char *));
3021 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3022 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3023 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3024 static void dwarf2out_end_source_file PARAMS ((unsigned));
3025 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3026 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3027 static bool dwarf2out_ignore_block PARAMS ((tree));
3028 static void dwarf2out_global_decl PARAMS ((tree));
3029 static void dwarf2out_abstract_function PARAMS ((tree));
3031 /* The debug hooks structure. */
3033 struct gcc_debug_hooks dwarf2_debug_hooks =
3039 dwarf2out_start_source_file,
3040 dwarf2out_end_source_file,
3041 dwarf2out_begin_block,
3042 dwarf2out_end_block,
3043 dwarf2out_ignore_block,
3044 dwarf2out_source_line,
3045 dwarf2out_begin_prologue,
3046 debug_nothing_int, /* end_prologue */
3047 dwarf2out_end_epilogue,
3048 debug_nothing_tree, /* begin_function */
3049 debug_nothing_int, /* end_function */
3050 dwarf2out_decl, /* function_decl */
3051 dwarf2out_global_decl,
3052 debug_nothing_tree, /* deferred_inline_function */
3053 /* The DWARF 2 backend tries to reduce debugging bloat by not
3054 emitting the abstract description of inline functions until
3055 something tries to reference them. */
3056 dwarf2out_abstract_function, /* outlining_inline_function */
3057 debug_nothing_rtx /* label */
3060 /* NOTE: In the comments in this file, many references are made to
3061 "Debugging Information Entries". This term is abbreviated as `DIE'
3062 throughout the remainder of this file. */
3064 /* An internal representation of the DWARF output is built, and then
3065 walked to generate the DWARF debugging info. The walk of the internal
3066 representation is done after the entire program has been compiled.
3067 The types below are used to describe the internal representation. */
3069 /* Various DIE's use offsets relative to the beginning of the
3070 .debug_info section to refer to each other. */
3072 typedef long int dw_offset;
3074 /* Define typedefs here to avoid circular dependencies. */
3076 typedef struct dw_attr_struct *dw_attr_ref;
3077 typedef struct dw_line_info_struct *dw_line_info_ref;
3078 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3079 typedef struct pubname_struct *pubname_ref;
3080 typedef struct dw_ranges_struct *dw_ranges_ref;
3082 /* Each entry in the line_info_table maintains the file and
3083 line number associated with the label generated for that
3084 entry. The label gives the PC value associated with
3085 the line number entry. */
3087 typedef struct dw_line_info_struct
3089 unsigned long dw_file_num;
3090 unsigned long dw_line_num;
3094 /* Line information for functions in separate sections; each one gets its
3096 typedef struct dw_separate_line_info_struct
3098 unsigned long dw_file_num;
3099 unsigned long dw_line_num;
3100 unsigned long function;
3102 dw_separate_line_info_entry;
3104 /* Each DIE attribute has a field specifying the attribute kind,
3105 a link to the next attribute in the chain, and an attribute value.
3106 Attributes are typically linked below the DIE they modify. */
3108 typedef struct dw_attr_struct
3110 enum dwarf_attribute dw_attr;
3111 dw_attr_ref dw_attr_next;
3112 dw_val_node dw_attr_val;
3116 /* The Debugging Information Entry (DIE) structure */
3118 typedef struct die_struct
3120 enum dwarf_tag die_tag;
3122 dw_attr_ref die_attr;
3123 dw_die_ref die_parent;
3124 dw_die_ref die_child;
3126 dw_offset die_offset;
3127 unsigned long die_abbrev;
3132 /* The pubname structure */
3134 typedef struct pubname_struct
3141 struct dw_ranges_struct
3146 /* The limbo die list structure. */
3147 typedef struct limbo_die_struct
3150 struct limbo_die_struct *next;
3154 /* How to start an assembler comment. */
3155 #ifndef ASM_COMMENT_START
3156 #define ASM_COMMENT_START ";#"
3159 /* Define a macro which returns non-zero for a TYPE_DECL which was
3160 implicitly generated for a tagged type.
3162 Note that unlike the gcc front end (which generates a NULL named
3163 TYPE_DECL node for each complete tagged type, each array type, and
3164 each function type node created) the g++ front end generates a
3165 _named_ TYPE_DECL node for each tagged type node created.
3166 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3167 generate a DW_TAG_typedef DIE for them. */
3169 #define TYPE_DECL_IS_STUB(decl) \
3170 (DECL_NAME (decl) == NULL_TREE \
3171 || (DECL_ARTIFICIAL (decl) \
3172 && is_tagged_type (TREE_TYPE (decl)) \
3173 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3174 /* This is necessary for stub decls that \
3175 appear in nested inline functions. */ \
3176 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3177 && (decl_ultimate_origin (decl) \
3178 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3180 /* Information concerning the compilation unit's programming
3181 language, and compiler version. */
3183 extern int flag_traditional;
3185 /* Fixed size portion of the DWARF compilation unit header. */
3186 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3188 /* Fixed size portion of debugging line information prolog. */
3189 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3191 /* Fixed size portion of public names info. */
3192 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3194 /* Fixed size portion of the address range info. */
3195 #define DWARF_ARANGES_HEADER_SIZE \
3196 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3197 - DWARF_OFFSET_SIZE)
3199 /* Size of padding portion in the address range info. It must be
3200 aligned to twice the pointer size. */
3201 #define DWARF_ARANGES_PAD_SIZE \
3202 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3203 - (2 * DWARF_OFFSET_SIZE + 4))
3205 /* Use assembler line directives if available. */
3206 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3207 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3208 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3210 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3214 /* Define the architecture-dependent minimum instruction length (in bytes).
3215 In this implementation of DWARF, this field is used for information
3216 purposes only. Since GCC generates assembly language, we have
3217 no a priori knowledge of how many instruction bytes are generated
3218 for each source line, and therefore can use only the DW_LNE_set_address
3219 and DW_LNS_fixed_advance_pc line information commands. */
3221 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3222 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3225 /* Minimum line offset in a special line info. opcode.
3226 This value was chosen to give a reasonable range of values. */
3227 #define DWARF_LINE_BASE -10
3229 /* First special line opcde - leave room for the standard opcodes. */
3230 #define DWARF_LINE_OPCODE_BASE 10
3232 /* Range of line offsets in a special line info. opcode. */
3233 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3235 /* Flag that indicates the initial value of the is_stmt_start flag.
3236 In the present implementation, we do not mark any lines as
3237 the beginning of a source statement, because that information
3238 is not made available by the GCC front-end. */
3239 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3241 /* This location is used by calc_die_sizes() to keep track
3242 the offset of each DIE within the .debug_info section. */
3243 static unsigned long next_die_offset;
3245 /* Record the root of the DIE's built for the current compilation unit. */
3246 static dw_die_ref comp_unit_die;
3248 /* A list of DIEs with a NULL parent waiting to be relocated. */
3249 static limbo_die_node *limbo_die_list = 0;
3251 /* Structure used by lookup_filename to manage sets of filenames. */
3257 unsigned last_lookup_index;
3260 /* Size (in elements) of increments by which we may expand the filename
3262 #define FILE_TABLE_INCREMENT 64
3264 /* Filenames referenced by this compilation unit. */
3265 static struct file_table file_table;
3267 /* Local pointer to the name of the main input file. Initialized in
3269 static const char *primary_filename;
3271 /* A pointer to the base of a table of references to DIE's that describe
3272 declarations. The table is indexed by DECL_UID() which is a unique
3273 number identifying each decl. */
3274 static dw_die_ref *decl_die_table;
3276 /* Number of elements currently allocated for the decl_die_table. */
3277 static unsigned decl_die_table_allocated;
3279 /* Number of elements in decl_die_table currently in use. */
3280 static unsigned decl_die_table_in_use;
3282 /* Size (in elements) of increments by which we may expand the
3284 #define DECL_DIE_TABLE_INCREMENT 256
3286 /* A pointer to the base of a table of references to declaration
3287 scopes. This table is a display which tracks the nesting
3288 of declaration scopes at the current scope and containing
3289 scopes. This table is used to find the proper place to
3290 define type declaration DIE's. */
3291 static tree *decl_scope_table;
3293 /* Number of elements currently allocated for the decl_scope_table. */
3294 static int decl_scope_table_allocated;
3296 /* Current level of nesting of declaration scopes. */
3297 static int decl_scope_depth;
3299 /* Size (in elements) of increments by which we may expand the
3300 decl_scope_table. */
3301 #define DECL_SCOPE_TABLE_INCREMENT 64
3303 /* A pointer to the base of a list of references to DIE's that
3304 are uniquely identified by their tag, presence/absence of
3305 children DIE's, and list of attribute/value pairs. */
3306 static dw_die_ref *abbrev_die_table;
3308 /* Number of elements currently allocated for abbrev_die_table. */
3309 static unsigned abbrev_die_table_allocated;
3311 /* Number of elements in type_die_table currently in use. */
3312 static unsigned abbrev_die_table_in_use;
3314 /* Size (in elements) of increments by which we may expand the
3315 abbrev_die_table. */
3316 #define ABBREV_DIE_TABLE_INCREMENT 256
3318 /* A pointer to the base of a table that contains line information
3319 for each source code line in .text in the compilation unit. */
3320 static dw_line_info_ref line_info_table;
3322 /* Number of elements currently allocated for line_info_table. */
3323 static unsigned line_info_table_allocated;
3325 /* Number of elements in separate_line_info_table currently in use. */
3326 static unsigned separate_line_info_table_in_use;
3328 /* A pointer to the base of a table that contains line information
3329 for each source code line outside of .text in the compilation unit. */
3330 static dw_separate_line_info_ref separate_line_info_table;
3332 /* Number of elements currently allocated for separate_line_info_table. */
3333 static unsigned separate_line_info_table_allocated;
3335 /* Number of elements in line_info_table currently in use. */
3336 static unsigned line_info_table_in_use;
3338 /* Size (in elements) of increments by which we may expand the
3340 #define LINE_INFO_TABLE_INCREMENT 1024
3342 /* A pointer to the base of a table that contains a list of publicly
3343 accessible names. */
3344 static pubname_ref pubname_table;
3346 /* Number of elements currently allocated for pubname_table. */
3347 static unsigned pubname_table_allocated;
3349 /* Number of elements in pubname_table currently in use. */
3350 static unsigned pubname_table_in_use;
3352 /* Size (in elements) of increments by which we may expand the
3354 #define PUBNAME_TABLE_INCREMENT 64
3356 /* Array of dies for which we should generate .debug_arange info. */
3357 static dw_die_ref *arange_table;
3359 /* Number of elements currently allocated for arange_table. */
3360 static unsigned arange_table_allocated;
3362 /* Number of elements in arange_table currently in use. */
3363 static unsigned arange_table_in_use;
3365 /* Size (in elements) of increments by which we may expand the
3367 #define ARANGE_TABLE_INCREMENT 64
3369 /* Array of dies for which we should generate .debug_ranges info. */
3370 static dw_ranges_ref ranges_table;
3372 /* Number of elements currently allocated for ranges_table. */
3373 static unsigned ranges_table_allocated;
3375 /* Number of elements in ranges_table currently in use. */
3376 static unsigned ranges_table_in_use;
3378 /* Size (in elements) of increments by which we may expand the
3380 #define RANGES_TABLE_INCREMENT 64
3382 /* Whether we have location lists that need outputting */
3383 static unsigned have_location_lists;
3385 /* A pointer to the base of a list of incomplete types which might be
3386 completed at some later time. */
3388 static tree *incomplete_types_list;
3390 /* Number of elements currently allocated for the incomplete_types_list. */
3391 static unsigned incomplete_types_allocated;
3393 /* Number of elements of incomplete_types_list currently in use. */
3394 static unsigned incomplete_types;
3396 /* Size (in elements) of increments by which we may expand the incomplete
3397 types list. Actually, a single hunk of space of this size should
3398 be enough for most typical programs. */
3399 #define INCOMPLETE_TYPES_INCREMENT 64
3401 /* Record whether the function being analyzed contains inlined functions. */
3402 static int current_function_has_inlines;
3403 #if 0 && defined (MIPS_DEBUGGING_INFO)
3404 static int comp_unit_has_inlines;
3407 /* Array of RTXes referenced by the debugging information, which therefore
3408 must be kept around forever. We do this rather than perform GC on
3409 the dwarf info because almost all of the dwarf info lives forever, and
3410 it's easier to support non-GC frontends this way. */
3411 static varray_type used_rtx_varray;
3413 /* Forward declarations for functions defined in this file. */
3415 static int is_pseudo_reg PARAMS ((rtx));
3416 static tree type_main_variant PARAMS ((tree));
3417 static int is_tagged_type PARAMS ((tree));
3418 static const char *dwarf_tag_name PARAMS ((unsigned));
3419 static const char *dwarf_attr_name PARAMS ((unsigned));
3420 static const char *dwarf_form_name PARAMS ((unsigned));
3422 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3424 static tree decl_ultimate_origin PARAMS ((tree));
3425 static tree block_ultimate_origin PARAMS ((tree));
3426 static tree decl_class_context PARAMS ((tree));
3427 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3428 static void add_AT_flag PARAMS ((dw_die_ref,
3429 enum dwarf_attribute,
3431 static void add_AT_int PARAMS ((dw_die_ref,
3432 enum dwarf_attribute, long));
3433 static void add_AT_unsigned PARAMS ((dw_die_ref,
3434 enum dwarf_attribute,
3436 static void add_AT_long_long PARAMS ((dw_die_ref,
3437 enum dwarf_attribute,
3440 static void add_AT_float PARAMS ((dw_die_ref,
3441 enum dwarf_attribute,
3443 static void add_AT_string PARAMS ((dw_die_ref,
3444 enum dwarf_attribute,
3446 static void add_AT_die_ref PARAMS ((dw_die_ref,
3447 enum dwarf_attribute,
3449 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3450 enum dwarf_attribute,
3452 static void add_AT_loc PARAMS ((dw_die_ref,
3453 enum dwarf_attribute,
3455 static void add_AT_loc_list PARAMS ((dw_die_ref,
3456 enum dwarf_attribute,
3458 static void add_AT_addr PARAMS ((dw_die_ref,
3459 enum dwarf_attribute,
3461 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3462 enum dwarf_attribute,
3464 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3465 enum dwarf_attribute,
3467 static void add_AT_offset PARAMS ((dw_die_ref,
3468 enum dwarf_attribute,
3470 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3471 enum dwarf_attribute));
3472 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3473 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3474 static const char *get_AT_string PARAMS ((dw_die_ref,
3475 enum dwarf_attribute));
3476 static int get_AT_flag PARAMS ((dw_die_ref,
3477 enum dwarf_attribute));
3478 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3479 enum dwarf_attribute));
3480 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3481 enum dwarf_attribute));
3482 static int is_c_family PARAMS ((void));
3483 static int is_java PARAMS ((void));
3484 static int is_fortran PARAMS ((void));
3485 static void remove_AT PARAMS ((dw_die_ref,
3486 enum dwarf_attribute));
3487 static void remove_children PARAMS ((dw_die_ref));
3488 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3489 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3490 static dw_die_ref lookup_type_die PARAMS ((tree));
3491 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3492 static dw_die_ref lookup_decl_die PARAMS ((tree));
3493 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3494 static void print_spaces PARAMS ((FILE *));
3495 static void print_die PARAMS ((dw_die_ref, FILE *));
3496 static void print_dwarf_line_table PARAMS ((FILE *));
3497 static void reverse_die_lists PARAMS ((dw_die_ref));
3498 static void reverse_all_dies PARAMS ((dw_die_ref));
3499 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3500 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3501 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3502 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3503 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3504 static void compute_section_prefix PARAMS ((dw_die_ref));
3505 static int is_type_die PARAMS ((dw_die_ref));
3506 static int is_comdat_die PARAMS ((dw_die_ref));
3507 static int is_symbol_die PARAMS ((dw_die_ref));
3508 static void assign_symbol_names PARAMS ((dw_die_ref));
3509 static void break_out_includes PARAMS ((dw_die_ref));
3510 static void add_sibling_attributes PARAMS ((dw_die_ref));
3511 static void build_abbrev_table PARAMS ((dw_die_ref));
3512 static void output_location_lists PARAMS ((dw_die_ref));
3513 static unsigned long size_of_string PARAMS ((const char *));
3514 static int constant_size PARAMS ((long unsigned));
3515 static unsigned long size_of_die PARAMS ((dw_die_ref));
3516 static void calc_die_sizes PARAMS ((dw_die_ref));
3517 static void mark_dies PARAMS ((dw_die_ref));
3518 static void unmark_dies PARAMS ((dw_die_ref));
3519 static unsigned long size_of_pubnames PARAMS ((void));
3520 static unsigned long size_of_aranges PARAMS ((void));
3521 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3522 static void output_value_format PARAMS ((dw_attr_ref));
3523 static void output_abbrev_section PARAMS ((void));
3524 static void output_die_symbol PARAMS ((dw_die_ref));
3525 static void output_die PARAMS ((dw_die_ref));
3526 static void output_compilation_unit_header PARAMS ((void));
3527 static void output_comp_unit PARAMS ((dw_die_ref));
3528 static const char *dwarf2_name PARAMS ((tree, int));
3529 static void add_pubname PARAMS ((tree, dw_die_ref));
3530 static void output_pubnames PARAMS ((void));
3531 static void add_arange PARAMS ((tree, dw_die_ref));
3532 static void output_aranges PARAMS ((void));
3533 static unsigned int add_ranges PARAMS ((tree));
3534 static void output_ranges PARAMS ((void));
3535 static void output_line_info PARAMS ((void));
3536 static void output_file_names PARAMS ((void));
3537 static dw_die_ref base_type_die PARAMS ((tree));
3538 static tree root_type PARAMS ((tree));
3539 static int is_base_type PARAMS ((tree));
3540 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3541 static int type_is_enum PARAMS ((tree));
3542 static unsigned int reg_number PARAMS ((rtx));
3543 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3544 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3545 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3546 static int is_based_loc PARAMS ((rtx));
3547 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3548 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3549 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3550 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3551 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3552 static tree field_type PARAMS ((tree));
3553 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3554 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3555 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3556 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3557 static void add_AT_location_description PARAMS ((dw_die_ref,
3558 enum dwarf_attribute, rtx));
3559 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3560 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3561 static rtx rtl_for_decl_location PARAMS ((tree));
3562 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3563 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3564 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3565 static void add_bound_info PARAMS ((dw_die_ref,
3566 enum dwarf_attribute, tree));
3567 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3568 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3569 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3570 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3571 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3572 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3573 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3574 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3575 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3576 static void push_decl_scope PARAMS ((tree));
3577 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3578 static void pop_decl_scope PARAMS ((void));
3579 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3581 static const char *type_tag PARAMS ((tree));
3582 static tree member_declared_type PARAMS ((tree));
3584 static const char *decl_start_label PARAMS ((tree));
3586 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3587 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3589 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3591 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3592 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3593 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3594 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3595 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3596 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3597 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3598 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3599 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3600 static void gen_label_die PARAMS ((tree, dw_die_ref));
3601 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3602 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3603 static void gen_field_die PARAMS ((tree, dw_die_ref));
3604 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3605 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3606 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3607 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3608 static void gen_member_die PARAMS ((tree, dw_die_ref));
3609 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3610 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3611 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3612 static void gen_type_die PARAMS ((tree, dw_die_ref));
3613 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3614 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3615 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3616 static int is_redundant_typedef PARAMS ((tree));
3617 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3618 static unsigned lookup_filename PARAMS ((const char *));
3619 static void init_file_table PARAMS ((void));
3620 static void add_incomplete_type PARAMS ((tree));
3621 static void retry_incomplete_types PARAMS ((void));
3622 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3623 static rtx save_rtx PARAMS ((rtx));
3624 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3625 static int file_info_cmp PARAMS ((const void *, const void *));
3626 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3627 const char *, const char *,
3628 const char *, unsigned));
3629 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3631 const char *, const char *, const char *));
3632 static void output_loc_list PARAMS ((dw_loc_list_ref));
3633 static char *gen_internal_sym PARAMS ((const char *));
3635 /* Section names used to hold DWARF debugging information. */
3636 #ifndef DEBUG_INFO_SECTION
3637 #define DEBUG_INFO_SECTION ".debug_info"
3639 #ifndef DEBUG_ABBREV_SECTION
3640 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3642 #ifndef DEBUG_ARANGES_SECTION
3643 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3645 #ifndef DEBUG_MACINFO_SECTION
3646 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3648 #ifndef DEBUG_LINE_SECTION
3649 #define DEBUG_LINE_SECTION ".debug_line"
3651 #ifndef DEBUG_LOC_SECTION
3652 #define DEBUG_LOC_SECTION ".debug_loc"
3654 #ifndef DEBUG_PUBNAMES_SECTION
3655 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3657 #ifndef DEBUG_STR_SECTION
3658 #define DEBUG_STR_SECTION ".debug_str"
3660 #ifndef DEBUG_RANGES_SECTION
3661 #define DEBUG_RANGES_SECTION ".debug_ranges"
3664 /* Standard ELF section names for compiled code and data. */
3665 #ifndef TEXT_SECTION
3666 #define TEXT_SECTION ".text"
3668 #ifndef DATA_SECTION
3669 #define DATA_SECTION ".data"
3672 #define BSS_SECTION ".bss"
3675 /* Labels we insert at beginning sections we can reference instead of
3676 the section names themselves. */
3678 #ifndef TEXT_SECTION_LABEL
3679 #define TEXT_SECTION_LABEL "Ltext"
3681 #ifndef DEBUG_LINE_SECTION_LABEL
3682 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3684 #ifndef DEBUG_INFO_SECTION_LABEL
3685 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3687 #ifndef DEBUG_ABBREV_SECTION_LABEL
3688 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3690 #ifndef DEBUG_LOC_SECTION_LABEL
3691 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3693 #ifndef DEBUG_MACINFO_SECTION_LABEL
3694 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3697 /* Definitions of defaults for formats and names of various special
3698 (artificial) labels which may be generated within this file (when the -g
3699 options is used and DWARF_DEBUGGING_INFO is in effect.
3700 If necessary, these may be overridden from within the tm.h file, but
3701 typically, overriding these defaults is unnecessary. */
3703 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3704 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3705 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3706 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3707 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3708 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3709 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3710 #ifndef TEXT_END_LABEL
3711 #define TEXT_END_LABEL "Letext"
3713 #ifndef DATA_END_LABEL
3714 #define DATA_END_LABEL "Ledata"
3716 #ifndef BSS_END_LABEL
3717 #define BSS_END_LABEL "Lebss"
3719 #ifndef BLOCK_BEGIN_LABEL
3720 #define BLOCK_BEGIN_LABEL "LBB"
3722 #ifndef BLOCK_END_LABEL
3723 #define BLOCK_END_LABEL "LBE"
3725 #ifndef BODY_BEGIN_LABEL
3726 #define BODY_BEGIN_LABEL "Lbb"
3728 #ifndef BODY_END_LABEL
3729 #define BODY_END_LABEL "Lbe"
3731 #ifndef LINE_CODE_LABEL
3732 #define LINE_CODE_LABEL "LM"
3734 #ifndef SEPARATE_LINE_CODE_LABEL
3735 #define SEPARATE_LINE_CODE_LABEL "LSM"
3738 /* We allow a language front-end to designate a function that is to be
3739 called to "demangle" any name before it it put into a DIE. */
3741 static const char *(*demangle_name_func) PARAMS ((const char *));
3744 dwarf2out_set_demangle_name_func (func)
3745 const char *(*func) PARAMS ((const char *));
3747 demangle_name_func = func;
3750 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3751 that means adding it to used_rtx_varray. If not, that means making
3752 a copy on the permanent_obstack. */
3758 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3763 /* Test if rtl node points to a pseudo register. */
3769 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3770 || (GET_CODE (rtl) == SUBREG
3771 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3774 /* Return a reference to a type, with its const and volatile qualifiers
3778 type_main_variant (type)
3781 type = TYPE_MAIN_VARIANT (type);
3783 /* There really should be only one main variant among any group of variants
3784 of a given type (and all of the MAIN_VARIANT values for all members of
3785 the group should point to that one type) but sometimes the C front-end
3786 messes this up for array types, so we work around that bug here. */
3788 if (TREE_CODE (type) == ARRAY_TYPE)
3789 while (type != TYPE_MAIN_VARIANT (type))
3790 type = TYPE_MAIN_VARIANT (type);
3795 /* Return non-zero if the given type node represents a tagged type. */
3798 is_tagged_type (type)
3801 register enum tree_code code = TREE_CODE (type);
3803 return (code == RECORD_TYPE || code == UNION_TYPE
3804 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3807 /* Convert a DIE tag into its string name. */
3810 dwarf_tag_name (tag)
3811 register unsigned tag;
3815 case DW_TAG_padding:
3816 return "DW_TAG_padding";
3817 case DW_TAG_array_type:
3818 return "DW_TAG_array_type";
3819 case DW_TAG_class_type:
3820 return "DW_TAG_class_type";
3821 case DW_TAG_entry_point:
3822 return "DW_TAG_entry_point";
3823 case DW_TAG_enumeration_type:
3824 return "DW_TAG_enumeration_type";
3825 case DW_TAG_formal_parameter:
3826 return "DW_TAG_formal_parameter";
3827 case DW_TAG_imported_declaration:
3828 return "DW_TAG_imported_declaration";
3830 return "DW_TAG_label";
3831 case DW_TAG_lexical_block:
3832 return "DW_TAG_lexical_block";
3834 return "DW_TAG_member";
3835 case DW_TAG_pointer_type:
3836 return "DW_TAG_pointer_type";
3837 case DW_TAG_reference_type:
3838 return "DW_TAG_reference_type";
3839 case DW_TAG_compile_unit:
3840 return "DW_TAG_compile_unit";
3841 case DW_TAG_string_type:
3842 return "DW_TAG_string_type";
3843 case DW_TAG_structure_type:
3844 return "DW_TAG_structure_type";
3845 case DW_TAG_subroutine_type:
3846 return "DW_TAG_subroutine_type";
3847 case DW_TAG_typedef:
3848 return "DW_TAG_typedef";
3849 case DW_TAG_union_type:
3850 return "DW_TAG_union_type";
3851 case DW_TAG_unspecified_parameters:
3852 return "DW_TAG_unspecified_parameters";
3853 case DW_TAG_variant:
3854 return "DW_TAG_variant";
3855 case DW_TAG_common_block:
3856 return "DW_TAG_common_block";
3857 case DW_TAG_common_inclusion:
3858 return "DW_TAG_common_inclusion";
3859 case DW_TAG_inheritance:
3860 return "DW_TAG_inheritance";
3861 case DW_TAG_inlined_subroutine:
3862 return "DW_TAG_inlined_subroutine";
3864 return "DW_TAG_module";
3865 case DW_TAG_ptr_to_member_type:
3866 return "DW_TAG_ptr_to_member_type";
3867 case DW_TAG_set_type:
3868 return "DW_TAG_set_type";
3869 case DW_TAG_subrange_type:
3870 return "DW_TAG_subrange_type";
3871 case DW_TAG_with_stmt:
3872 return "DW_TAG_with_stmt";
3873 case DW_TAG_access_declaration:
3874 return "DW_TAG_access_declaration";
3875 case DW_TAG_base_type:
3876 return "DW_TAG_base_type";
3877 case DW_TAG_catch_block:
3878 return "DW_TAG_catch_block";
3879 case DW_TAG_const_type:
3880 return "DW_TAG_const_type";
3881 case DW_TAG_constant:
3882 return "DW_TAG_constant";
3883 case DW_TAG_enumerator:
3884 return "DW_TAG_enumerator";
3885 case DW_TAG_file_type:
3886 return "DW_TAG_file_type";
3888 return "DW_TAG_friend";
3889 case DW_TAG_namelist:
3890 return "DW_TAG_namelist";
3891 case DW_TAG_namelist_item:
3892 return "DW_TAG_namelist_item";
3893 case DW_TAG_packed_type:
3894 return "DW_TAG_packed_type";
3895 case DW_TAG_subprogram:
3896 return "DW_TAG_subprogram";
3897 case DW_TAG_template_type_param:
3898 return "DW_TAG_template_type_param";
3899 case DW_TAG_template_value_param:
3900 return "DW_TAG_template_value_param";
3901 case DW_TAG_thrown_type:
3902 return "DW_TAG_thrown_type";
3903 case DW_TAG_try_block:
3904 return "DW_TAG_try_block";
3905 case DW_TAG_variant_part:
3906 return "DW_TAG_variant_part";
3907 case DW_TAG_variable:
3908 return "DW_TAG_variable";
3909 case DW_TAG_volatile_type:
3910 return "DW_TAG_volatile_type";
3911 case DW_TAG_MIPS_loop:
3912 return "DW_TAG_MIPS_loop";
3913 case DW_TAG_format_label:
3914 return "DW_TAG_format_label";
3915 case DW_TAG_function_template:
3916 return "DW_TAG_function_template";
3917 case DW_TAG_class_template:
3918 return "DW_TAG_class_template";
3919 case DW_TAG_GNU_BINCL:
3920 return "DW_TAG_GNU_BINCL";
3921 case DW_TAG_GNU_EINCL:
3922 return "DW_TAG_GNU_EINCL";
3924 return "DW_TAG_<unknown>";
3928 /* Convert a DWARF attribute code into its string name. */
3931 dwarf_attr_name (attr)
3932 register unsigned attr;
3937 return "DW_AT_sibling";
3938 case DW_AT_location:
3939 return "DW_AT_location";
3941 return "DW_AT_name";
3942 case DW_AT_ordering:
3943 return "DW_AT_ordering";
3944 case DW_AT_subscr_data:
3945 return "DW_AT_subscr_data";
3946 case DW_AT_byte_size:
3947 return "DW_AT_byte_size";
3948 case DW_AT_bit_offset:
3949 return "DW_AT_bit_offset";
3950 case DW_AT_bit_size:
3951 return "DW_AT_bit_size";
3952 case DW_AT_element_list:
3953 return "DW_AT_element_list";
3954 case DW_AT_stmt_list:
3955 return "DW_AT_stmt_list";
3957 return "DW_AT_low_pc";
3959 return "DW_AT_high_pc";
3960 case DW_AT_language:
3961 return "DW_AT_language";
3963 return "DW_AT_member";
3965 return "DW_AT_discr";
3966 case DW_AT_discr_value:
3967 return "DW_AT_discr_value";
3968 case DW_AT_visibility:
3969 return "DW_AT_visibility";
3971 return "DW_AT_import";
3972 case DW_AT_string_length:
3973 return "DW_AT_string_length";
3974 case DW_AT_common_reference:
3975 return "DW_AT_common_reference";
3976 case DW_AT_comp_dir:
3977 return "DW_AT_comp_dir";
3978 case DW_AT_const_value:
3979 return "DW_AT_const_value";
3980 case DW_AT_containing_type:
3981 return "DW_AT_containing_type";
3982 case DW_AT_default_value:
3983 return "DW_AT_default_value";
3985 return "DW_AT_inline";
3986 case DW_AT_is_optional:
3987 return "DW_AT_is_optional";
3988 case DW_AT_lower_bound:
3989 return "DW_AT_lower_bound";
3990 case DW_AT_producer:
3991 return "DW_AT_producer";
3992 case DW_AT_prototyped:
3993 return "DW_AT_prototyped";
3994 case DW_AT_return_addr:
3995 return "DW_AT_return_addr";
3996 case DW_AT_start_scope:
3997 return "DW_AT_start_scope";
3998 case DW_AT_stride_size:
3999 return "DW_AT_stride_size";
4000 case DW_AT_upper_bound:
4001 return "DW_AT_upper_bound";
4002 case DW_AT_abstract_origin:
4003 return "DW_AT_abstract_origin";
4004 case DW_AT_accessibility:
4005 return "DW_AT_accessibility";
4006 case DW_AT_address_class:
4007 return "DW_AT_address_class";
4008 case DW_AT_artificial:
4009 return "DW_AT_artificial";
4010 case DW_AT_base_types:
4011 return "DW_AT_base_types";
4012 case DW_AT_calling_convention:
4013 return "DW_AT_calling_convention";
4015 return "DW_AT_count";
4016 case DW_AT_data_member_location:
4017 return "DW_AT_data_member_location";
4018 case DW_AT_decl_column:
4019 return "DW_AT_decl_column";
4020 case DW_AT_decl_file:
4021 return "DW_AT_decl_file";
4022 case DW_AT_decl_line:
4023 return "DW_AT_decl_line";
4024 case DW_AT_declaration:
4025 return "DW_AT_declaration";
4026 case DW_AT_discr_list:
4027 return "DW_AT_discr_list";
4028 case DW_AT_encoding:
4029 return "DW_AT_encoding";
4030 case DW_AT_external:
4031 return "DW_AT_external";
4032 case DW_AT_frame_base:
4033 return "DW_AT_frame_base";
4035 return "DW_AT_friend";
4036 case DW_AT_identifier_case:
4037 return "DW_AT_identifier_case";
4038 case DW_AT_macro_info:
4039 return "DW_AT_macro_info";
4040 case DW_AT_namelist_items:
4041 return "DW_AT_namelist_items";
4042 case DW_AT_priority:
4043 return "DW_AT_priority";
4045 return "DW_AT_segment";
4046 case DW_AT_specification:
4047 return "DW_AT_specification";
4048 case DW_AT_static_link:
4049 return "DW_AT_static_link";
4051 return "DW_AT_type";
4052 case DW_AT_use_location:
4053 return "DW_AT_use_location";
4054 case DW_AT_variable_parameter:
4055 return "DW_AT_variable_parameter";
4056 case DW_AT_virtuality:
4057 return "DW_AT_virtuality";
4058 case DW_AT_vtable_elem_location:
4059 return "DW_AT_vtable_elem_location";
4061 case DW_AT_allocated:
4062 return "DW_AT_allocated";
4063 case DW_AT_associated:
4064 return "DW_AT_associated";
4065 case DW_AT_data_location:
4066 return "DW_AT_data_location";
4068 return "DW_AT_stride";
4069 case DW_AT_entry_pc:
4070 return "DW_AT_entry_pc";
4071 case DW_AT_use_UTF8:
4072 return "DW_AT_use_UTF8";
4073 case DW_AT_extension:
4074 return "DW_AT_extension";
4076 return "DW_AT_ranges";
4077 case DW_AT_trampoline:
4078 return "DW_AT_trampoline";
4079 case DW_AT_call_column:
4080 return "DW_AT_call_column";
4081 case DW_AT_call_file:
4082 return "DW_AT_call_file";
4083 case DW_AT_call_line:
4084 return "DW_AT_call_line";
4086 case DW_AT_MIPS_fde:
4087 return "DW_AT_MIPS_fde";
4088 case DW_AT_MIPS_loop_begin:
4089 return "DW_AT_MIPS_loop_begin";
4090 case DW_AT_MIPS_tail_loop_begin:
4091 return "DW_AT_MIPS_tail_loop_begin";
4092 case DW_AT_MIPS_epilog_begin:
4093 return "DW_AT_MIPS_epilog_begin";
4094 case DW_AT_MIPS_loop_unroll_factor:
4095 return "DW_AT_MIPS_loop_unroll_factor";
4096 case DW_AT_MIPS_software_pipeline_depth:
4097 return "DW_AT_MIPS_software_pipeline_depth";
4098 case DW_AT_MIPS_linkage_name:
4099 return "DW_AT_MIPS_linkage_name";
4100 case DW_AT_MIPS_stride:
4101 return "DW_AT_MIPS_stride";
4102 case DW_AT_MIPS_abstract_name:
4103 return "DW_AT_MIPS_abstract_name";
4104 case DW_AT_MIPS_clone_origin:
4105 return "DW_AT_MIPS_clone_origin";
4106 case DW_AT_MIPS_has_inlines:
4107 return "DW_AT_MIPS_has_inlines";
4109 case DW_AT_sf_names:
4110 return "DW_AT_sf_names";
4111 case DW_AT_src_info:
4112 return "DW_AT_src_info";
4113 case DW_AT_mac_info:
4114 return "DW_AT_mac_info";
4115 case DW_AT_src_coords:
4116 return "DW_AT_src_coords";
4117 case DW_AT_body_begin:
4118 return "DW_AT_body_begin";
4119 case DW_AT_body_end:
4120 return "DW_AT_body_end";
4122 return "DW_AT_<unknown>";
4126 /* Convert a DWARF value form code into its string name. */
4129 dwarf_form_name (form)
4130 register unsigned form;
4135 return "DW_FORM_addr";
4136 case DW_FORM_block2:
4137 return "DW_FORM_block2";
4138 case DW_FORM_block4:
4139 return "DW_FORM_block4";
4141 return "DW_FORM_data2";
4143 return "DW_FORM_data4";
4145 return "DW_FORM_data8";
4146 case DW_FORM_string:
4147 return "DW_FORM_string";
4149 return "DW_FORM_block";
4150 case DW_FORM_block1:
4151 return "DW_FORM_block1";
4153 return "DW_FORM_data1";
4155 return "DW_FORM_flag";
4157 return "DW_FORM_sdata";
4159 return "DW_FORM_strp";
4161 return "DW_FORM_udata";
4162 case DW_FORM_ref_addr:
4163 return "DW_FORM_ref_addr";
4165 return "DW_FORM_ref1";
4167 return "DW_FORM_ref2";
4169 return "DW_FORM_ref4";
4171 return "DW_FORM_ref8";
4172 case DW_FORM_ref_udata:
4173 return "DW_FORM_ref_udata";
4174 case DW_FORM_indirect:
4175 return "DW_FORM_indirect";
4177 return "DW_FORM_<unknown>";
4181 /* Convert a DWARF type code into its string name. */
4185 dwarf_type_encoding_name (enc)
4186 register unsigned enc;
4190 case DW_ATE_address:
4191 return "DW_ATE_address";
4192 case DW_ATE_boolean:
4193 return "DW_ATE_boolean";
4194 case DW_ATE_complex_float:
4195 return "DW_ATE_complex_float";
4197 return "DW_ATE_float";
4199 return "DW_ATE_signed";
4200 case DW_ATE_signed_char:
4201 return "DW_ATE_signed_char";
4202 case DW_ATE_unsigned:
4203 return "DW_ATE_unsigned";
4204 case DW_ATE_unsigned_char:
4205 return "DW_ATE_unsigned_char";
4207 return "DW_ATE_<unknown>";
4212 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4213 instance of an inlined instance of a decl which is local to an inline
4214 function, so we have to trace all of the way back through the origin chain
4215 to find out what sort of node actually served as the original seed for the
4219 decl_ultimate_origin (decl)
4222 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4223 nodes in the function to point to themselves; ignore that if
4224 we're trying to output the abstract instance of this function. */
4225 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4228 #ifdef ENABLE_CHECKING
4229 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4230 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4231 most distant ancestor, this should never happen. */
4235 return DECL_ABSTRACT_ORIGIN (decl);
4238 /* Determine the "ultimate origin" of a block. The block may be an inlined
4239 instance of an inlined instance of a block which is local to an inline
4240 function, so we have to trace all of the way back through the origin chain
4241 to find out what sort of node actually served as the original seed for the
4245 block_ultimate_origin (block)
4246 register tree block;
4248 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4250 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4251 nodes in the function to point to themselves; ignore that if
4252 we're trying to output the abstract instance of this function. */
4253 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4256 if (immediate_origin == NULL_TREE)
4260 register tree ret_val;
4261 register tree lookahead = immediate_origin;
4265 ret_val = lookahead;
4266 lookahead = (TREE_CODE (ret_val) == BLOCK)
4267 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4270 while (lookahead != NULL && lookahead != ret_val);
4276 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4277 of a virtual function may refer to a base class, so we check the 'this'
4281 decl_class_context (decl)
4284 tree context = NULL_TREE;
4286 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4287 context = DECL_CONTEXT (decl);
4289 context = TYPE_MAIN_VARIANT
4290 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4292 if (context && !TYPE_P (context))
4293 context = NULL_TREE;
4298 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4299 addition order, and correct that in reverse_all_dies. */
4302 add_dwarf_attr (die, attr)
4303 register dw_die_ref die;
4304 register dw_attr_ref attr;
4306 if (die != NULL && attr != NULL)
4308 attr->dw_attr_next = die->die_attr;
4309 die->die_attr = attr;
4313 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4314 static inline dw_val_class
4318 return a->dw_attr_val.val_class;
4321 /* Add a flag value attribute to a DIE. */
4324 add_AT_flag (die, attr_kind, flag)
4325 register dw_die_ref die;
4326 register enum dwarf_attribute attr_kind;
4327 register unsigned flag;
4329 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4331 attr->dw_attr_next = NULL;
4332 attr->dw_attr = attr_kind;
4333 attr->dw_attr_val.val_class = dw_val_class_flag;
4334 attr->dw_attr_val.v.val_flag = flag;
4335 add_dwarf_attr (die, attr);
4338 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4339 static inline unsigned
4341 register dw_attr_ref a;
4343 if (a && AT_class (a) == dw_val_class_flag)
4344 return a->dw_attr_val.v.val_flag;
4349 /* Add a signed integer attribute value to a DIE. */
4352 add_AT_int (die, attr_kind, int_val)
4353 register dw_die_ref die;
4354 register enum dwarf_attribute attr_kind;
4355 register long int int_val;
4357 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4359 attr->dw_attr_next = NULL;
4360 attr->dw_attr = attr_kind;
4361 attr->dw_attr_val.val_class = dw_val_class_const;
4362 attr->dw_attr_val.v.val_int = int_val;
4363 add_dwarf_attr (die, attr);
4366 static inline long int AT_int PARAMS ((dw_attr_ref));
4367 static inline long int
4369 register dw_attr_ref a;
4371 if (a && AT_class (a) == dw_val_class_const)
4372 return a->dw_attr_val.v.val_int;
4377 /* Add an unsigned integer attribute value to a DIE. */
4380 add_AT_unsigned (die, attr_kind, unsigned_val)
4381 register dw_die_ref die;
4382 register enum dwarf_attribute attr_kind;
4383 register unsigned long unsigned_val;
4385 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4387 attr->dw_attr_next = NULL;
4388 attr->dw_attr = attr_kind;
4389 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4390 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4391 add_dwarf_attr (die, attr);
4394 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4395 static inline unsigned long
4397 register dw_attr_ref a;
4399 if (a && AT_class (a) == dw_val_class_unsigned_const)
4400 return a->dw_attr_val.v.val_unsigned;
4405 /* Add an unsigned double integer attribute value to a DIE. */
4408 add_AT_long_long (die, attr_kind, val_hi, val_low)
4409 register dw_die_ref die;
4410 register enum dwarf_attribute attr_kind;
4411 register unsigned long val_hi;
4412 register unsigned long val_low;
4414 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4416 attr->dw_attr_next = NULL;
4417 attr->dw_attr = attr_kind;
4418 attr->dw_attr_val.val_class = dw_val_class_long_long;
4419 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4420 attr->dw_attr_val.v.val_long_long.low = val_low;
4421 add_dwarf_attr (die, attr);
4424 /* Add a floating point attribute value to a DIE and return it. */
4427 add_AT_float (die, attr_kind, length, array)
4428 register dw_die_ref die;
4429 register enum dwarf_attribute attr_kind;
4430 register unsigned length;
4431 register long *array;
4433 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4435 attr->dw_attr_next = NULL;
4436 attr->dw_attr = attr_kind;
4437 attr->dw_attr_val.val_class = dw_val_class_float;
4438 attr->dw_attr_val.v.val_float.length = length;
4439 attr->dw_attr_val.v.val_float.array = array;
4440 add_dwarf_attr (die, attr);
4443 /* Add a string attribute value to a DIE. */
4446 add_AT_string (die, attr_kind, str)
4447 register dw_die_ref die;
4448 register enum dwarf_attribute attr_kind;
4449 register const char *str;
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_str;
4456 attr->dw_attr_val.v.val_str = xstrdup (str);
4457 add_dwarf_attr (die, attr);
4460 static inline const char *AT_string PARAMS ((dw_attr_ref));
4461 static inline const char *
4463 register dw_attr_ref a;
4465 if (a && AT_class (a) == dw_val_class_str)
4466 return a->dw_attr_val.v.val_str;
4471 /* Add a DIE reference attribute value to a DIE. */
4474 add_AT_die_ref (die, attr_kind, targ_die)
4475 register dw_die_ref die;
4476 register enum dwarf_attribute attr_kind;
4477 register dw_die_ref targ_die;
4479 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4481 attr->dw_attr_next = NULL;
4482 attr->dw_attr = attr_kind;
4483 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4484 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4485 attr->dw_attr_val.v.val_die_ref.external = 0;
4486 add_dwarf_attr (die, attr);
4489 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4490 static inline dw_die_ref
4492 register dw_attr_ref a;
4494 if (a && AT_class (a) == dw_val_class_die_ref)
4495 return a->dw_attr_val.v.val_die_ref.die;
4500 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4503 register dw_attr_ref a;
4505 if (a && AT_class (a) == dw_val_class_die_ref)
4506 return a->dw_attr_val.v.val_die_ref.external;
4511 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4513 set_AT_ref_external (a, i)
4514 register dw_attr_ref a;
4517 if (a && AT_class (a) == dw_val_class_die_ref)
4518 a->dw_attr_val.v.val_die_ref.external = i;
4523 /* Add an FDE reference attribute value to a DIE. */
4526 add_AT_fde_ref (die, attr_kind, targ_fde)
4527 register dw_die_ref die;
4528 register enum dwarf_attribute attr_kind;
4529 register unsigned targ_fde;
4531 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4533 attr->dw_attr_next = NULL;
4534 attr->dw_attr = attr_kind;
4535 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4536 attr->dw_attr_val.v.val_fde_index = targ_fde;
4537 add_dwarf_attr (die, attr);
4540 /* Add a location description attribute value to a DIE. */
4543 add_AT_loc (die, attr_kind, loc)
4544 register dw_die_ref die;
4545 register enum dwarf_attribute attr_kind;
4546 register dw_loc_descr_ref loc;
4548 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4550 attr->dw_attr_next = NULL;
4551 attr->dw_attr = attr_kind;
4552 attr->dw_attr_val.val_class = dw_val_class_loc;
4553 attr->dw_attr_val.v.val_loc = loc;
4554 add_dwarf_attr (die, attr);
4557 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4558 static inline dw_loc_descr_ref
4560 register dw_attr_ref a;
4562 if (a && AT_class (a) == dw_val_class_loc)
4563 return a->dw_attr_val.v.val_loc;
4569 add_AT_loc_list (die, attr_kind, loc_list)
4570 register dw_die_ref die;
4571 register enum dwarf_attribute attr_kind;
4572 register dw_loc_list_ref loc_list;
4574 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4576 attr->dw_attr_next = NULL;
4577 attr->dw_attr = attr_kind;
4578 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4579 attr->dw_attr_val.v.val_loc_list = loc_list;
4580 add_dwarf_attr (die, attr);
4581 have_location_lists = 1;
4584 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
4586 static inline dw_loc_list_ref
4588 register dw_attr_ref a;
4590 if (a && AT_class (a) == dw_val_class_loc_list)
4591 return a->dw_attr_val.v.val_loc_list;
4596 /* Add an address constant attribute value to a DIE. */
4599 add_AT_addr (die, attr_kind, addr)
4600 register dw_die_ref die;
4601 register enum dwarf_attribute attr_kind;
4604 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4606 attr->dw_attr_next = NULL;
4607 attr->dw_attr = attr_kind;
4608 attr->dw_attr_val.val_class = dw_val_class_addr;
4609 attr->dw_attr_val.v.val_addr = addr;
4610 add_dwarf_attr (die, attr);
4613 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4616 register dw_attr_ref a;
4618 if (a && AT_class (a) == dw_val_class_addr)
4619 return a->dw_attr_val.v.val_addr;
4624 /* Add a label identifier attribute value to a DIE. */
4627 add_AT_lbl_id (die, attr_kind, lbl_id)
4628 register dw_die_ref die;
4629 register enum dwarf_attribute attr_kind;
4630 register const char *lbl_id;
4632 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4634 attr->dw_attr_next = NULL;
4635 attr->dw_attr = attr_kind;
4636 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4637 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4638 add_dwarf_attr (die, attr);
4641 /* Add a section offset attribute value to a DIE. */
4644 add_AT_lbl_offset (die, attr_kind, label)
4645 register dw_die_ref die;
4646 register enum dwarf_attribute attr_kind;
4647 register const char *label;
4649 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4651 attr->dw_attr_next = NULL;
4652 attr->dw_attr = attr_kind;
4653 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4654 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4655 add_dwarf_attr (die, attr);
4658 /* Add an offset attribute value to a DIE. */
4661 add_AT_offset (die, attr_kind, offset)
4662 register dw_die_ref die;
4663 register enum dwarf_attribute attr_kind;
4664 register unsigned long offset;
4666 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4668 attr->dw_attr_next = NULL;
4669 attr->dw_attr = attr_kind;
4670 attr->dw_attr_val.val_class = dw_val_class_offset;
4671 attr->dw_attr_val.v.val_offset = offset;
4672 add_dwarf_attr (die, attr);
4675 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4676 static inline const char *
4678 register dw_attr_ref a;
4680 if (a && (AT_class (a) == dw_val_class_lbl_id
4681 || AT_class (a) == dw_val_class_lbl_offset))
4682 return a->dw_attr_val.v.val_lbl_id;
4687 /* Get the attribute of type attr_kind. */
4689 static inline dw_attr_ref
4690 get_AT (die, attr_kind)
4691 register dw_die_ref die;
4692 register enum dwarf_attribute attr_kind;
4694 register dw_attr_ref a;
4695 register dw_die_ref spec = NULL;
4699 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4701 if (a->dw_attr == attr_kind)
4704 if (a->dw_attr == DW_AT_specification
4705 || a->dw_attr == DW_AT_abstract_origin)
4710 return get_AT (spec, attr_kind);
4716 /* Return the "low pc" attribute value, typically associated with
4717 a subprogram DIE. Return null if the "low pc" attribute is
4718 either not prsent, or if it cannot be represented as an
4719 assembler label identifier. */
4721 static inline const char *
4723 register dw_die_ref die;
4725 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4726 return a ? AT_lbl (a) : NULL;
4729 /* Return the "high pc" attribute value, typically associated with
4730 a subprogram DIE. Return null if the "high pc" attribute is
4731 either not prsent, or if it cannot be represented as an
4732 assembler label identifier. */
4734 static inline const char *
4736 register dw_die_ref die;
4738 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4739 return a ? AT_lbl (a) : NULL;
4742 /* Return the value of the string attribute designated by ATTR_KIND, or
4743 NULL if it is not present. */
4745 static inline const char *
4746 get_AT_string (die, attr_kind)
4747 register dw_die_ref die;
4748 register enum dwarf_attribute attr_kind;
4750 register dw_attr_ref a = get_AT (die, attr_kind);
4751 return a ? AT_string (a) : NULL;
4754 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4755 if it is not present. */
4758 get_AT_flag (die, attr_kind)
4759 register dw_die_ref die;
4760 register enum dwarf_attribute attr_kind;
4762 register dw_attr_ref a = get_AT (die, attr_kind);
4763 return a ? AT_flag (a) : 0;
4766 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4767 if it is not present. */
4769 static inline unsigned
4770 get_AT_unsigned (die, attr_kind)
4771 register dw_die_ref die;
4772 register enum dwarf_attribute attr_kind;
4774 register dw_attr_ref a = get_AT (die, attr_kind);
4775 return a ? AT_unsigned (a) : 0;
4778 static inline dw_die_ref
4779 get_AT_ref (die, attr_kind)
4781 register enum dwarf_attribute attr_kind;
4783 register dw_attr_ref a = get_AT (die, attr_kind);
4784 return a ? AT_ref (a) : NULL;
4790 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4792 return (lang == DW_LANG_C || lang == DW_LANG_C89
4793 || lang == DW_LANG_C_plus_plus);
4799 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4801 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4807 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4809 return (lang == DW_LANG_Java);
4812 /* Free up the memory used by A. */
4814 static inline void free_AT PARAMS ((dw_attr_ref));
4819 switch (AT_class (a))
4821 case dw_val_class_str:
4822 case dw_val_class_lbl_id:
4823 case dw_val_class_lbl_offset:
4824 free (a->dw_attr_val.v.val_str);
4827 case dw_val_class_float:
4828 free (a->dw_attr_val.v.val_float.array);
4838 /* Remove the specified attribute if present. */
4841 remove_AT (die, attr_kind)
4842 register dw_die_ref die;
4843 register enum dwarf_attribute attr_kind;
4845 register dw_attr_ref *p;
4846 register dw_attr_ref removed = NULL;
4850 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4851 if ((*p)->dw_attr == attr_kind)
4854 *p = (*p)->dw_attr_next;
4863 /* Free up the memory used by DIE. */
4865 static inline void free_die PARAMS ((dw_die_ref));
4870 remove_children (die);
4874 /* Discard the children of this DIE. */
4877 remove_children (die)
4878 register dw_die_ref die;
4880 register dw_die_ref child_die = die->die_child;
4882 die->die_child = NULL;
4884 while (child_die != NULL)
4886 register dw_die_ref tmp_die = child_die;
4887 register dw_attr_ref a;
4889 child_die = child_die->die_sib;
4891 for (a = tmp_die->die_attr; a != NULL;)
4893 register dw_attr_ref tmp_a = a;
4895 a = a->dw_attr_next;
4903 /* Add a child DIE below its parent. We build the lists up in reverse
4904 addition order, and correct that in reverse_all_dies. */
4907 add_child_die (die, child_die)
4908 register dw_die_ref die;
4909 register dw_die_ref child_die;
4911 if (die != NULL && child_die != NULL)
4913 if (die == child_die)
4915 child_die->die_parent = die;
4916 child_die->die_sib = die->die_child;
4917 die->die_child = child_die;
4921 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4922 is the specification, to the front of PARENT's list of children. */
4925 splice_child_die (parent, child)
4926 dw_die_ref parent, child;
4930 /* We want the declaration DIE from inside the class, not the
4931 specification DIE at toplevel. */
4932 if (child->die_parent != parent)
4934 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4939 if (child->die_parent != parent
4940 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4943 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4946 *p = child->die_sib;
4950 child->die_sib = parent->die_child;
4951 parent->die_child = child;
4954 /* Return a pointer to a newly created DIE node. */
4956 static inline dw_die_ref
4957 new_die (tag_value, parent_die)
4958 register enum dwarf_tag tag_value;
4959 register dw_die_ref parent_die;
4961 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4963 die->die_tag = tag_value;
4965 if (parent_die != NULL)
4966 add_child_die (parent_die, die);
4969 limbo_die_node *limbo_node;
4971 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4972 limbo_node->die = die;
4973 limbo_node->next = limbo_die_list;
4974 limbo_die_list = limbo_node;
4980 /* Return the DIE associated with the given type specifier. */
4982 static inline dw_die_ref
4983 lookup_type_die (type)
4986 if (TREE_CODE (type) == VECTOR_TYPE)
4987 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4988 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4991 /* Equate a DIE to a given type specifier. */
4994 equate_type_number_to_die (type, type_die)
4996 register dw_die_ref type_die;
4998 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
5001 /* Return the DIE associated with a given declaration. */
5003 static inline dw_die_ref
5004 lookup_decl_die (decl)
5007 register unsigned decl_id = DECL_UID (decl);
5009 return (decl_id < decl_die_table_in_use
5010 ? decl_die_table[decl_id] : NULL);
5013 /* Equate a DIE to a particular declaration. */
5016 equate_decl_number_to_die (decl, decl_die)
5018 register dw_die_ref decl_die;
5020 register unsigned decl_id = DECL_UID (decl);
5021 register unsigned num_allocated;
5023 if (decl_id >= decl_die_table_allocated)
5026 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5027 / DECL_DIE_TABLE_INCREMENT)
5028 * DECL_DIE_TABLE_INCREMENT;
5031 = (dw_die_ref *) xrealloc (decl_die_table,
5032 sizeof (dw_die_ref) * num_allocated);
5034 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5035 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5036 decl_die_table_allocated = num_allocated;
5039 if (decl_id >= decl_die_table_in_use)
5040 decl_die_table_in_use = (decl_id + 1);
5042 decl_die_table[decl_id] = decl_die;
5045 /* Keep track of the number of spaces used to indent the
5046 output of the debugging routines that print the structure of
5047 the DIE internal representation. */
5048 static int print_indent;
5050 /* Indent the line the number of spaces given by print_indent. */
5053 print_spaces (outfile)
5056 fprintf (outfile, "%*s", print_indent, "");
5059 /* Print the information associated with a given DIE, and its children.
5060 This routine is a debugging aid only. */
5063 print_die (die, outfile)
5067 register dw_attr_ref a;
5068 register dw_die_ref c;
5070 print_spaces (outfile);
5071 fprintf (outfile, "DIE %4lu: %s\n",
5072 die->die_offset, dwarf_tag_name (die->die_tag));
5073 print_spaces (outfile);
5074 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5075 fprintf (outfile, " offset: %lu\n", die->die_offset);
5077 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5079 print_spaces (outfile);
5080 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5082 switch (AT_class (a))
5084 case dw_val_class_addr:
5085 fprintf (outfile, "address");
5087 case dw_val_class_offset:
5088 fprintf (outfile, "offset");
5090 case dw_val_class_loc:
5091 fprintf (outfile, "location descriptor");
5093 case dw_val_class_loc_list:
5094 fprintf (outfile, "location list -> label:%s",
5095 AT_loc_list (a)->ll_symbol);
5097 case dw_val_class_const:
5098 fprintf (outfile, "%ld", AT_int (a));
5100 case dw_val_class_unsigned_const:
5101 fprintf (outfile, "%lu", AT_unsigned (a));
5103 case dw_val_class_long_long:
5104 fprintf (outfile, "constant (%lu,%lu)",
5105 a->dw_attr_val.v.val_long_long.hi,
5106 a->dw_attr_val.v.val_long_long.low);
5108 case dw_val_class_float:
5109 fprintf (outfile, "floating-point constant");
5111 case dw_val_class_flag:
5112 fprintf (outfile, "%u", AT_flag (a));
5114 case dw_val_class_die_ref:
5115 if (AT_ref (a) != NULL)
5117 if (AT_ref (a)->die_symbol)
5118 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5120 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5123 fprintf (outfile, "die -> <null>");
5125 case dw_val_class_lbl_id:
5126 case dw_val_class_lbl_offset:
5127 fprintf (outfile, "label: %s", AT_lbl (a));
5129 case dw_val_class_str:
5130 if (AT_string (a) != NULL)
5131 fprintf (outfile, "\"%s\"", AT_string (a));
5133 fprintf (outfile, "<null>");
5139 fprintf (outfile, "\n");
5142 if (die->die_child != NULL)
5145 for (c = die->die_child; c != NULL; c = c->die_sib)
5146 print_die (c, outfile);
5150 if (print_indent == 0)
5151 fprintf (outfile, "\n");
5154 /* Print the contents of the source code line number correspondence table.
5155 This routine is a debugging aid only. */
5158 print_dwarf_line_table (outfile)
5161 register unsigned i;
5162 register dw_line_info_ref line_info;
5164 fprintf (outfile, "\n\nDWARF source line information\n");
5165 for (i = 1; i < line_info_table_in_use; ++i)
5167 line_info = &line_info_table[i];
5168 fprintf (outfile, "%5d: ", i);
5169 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5170 fprintf (outfile, "%6ld", line_info->dw_line_num);
5171 fprintf (outfile, "\n");
5174 fprintf (outfile, "\n\n");
5177 /* Print the information collected for a given DIE. */
5180 debug_dwarf_die (die)
5183 print_die (die, stderr);
5186 /* Print all DWARF information collected for the compilation unit.
5187 This routine is a debugging aid only. */
5193 print_die (comp_unit_die, stderr);
5194 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5195 print_dwarf_line_table (stderr);
5198 /* We build up the lists of children and attributes by pushing new ones
5199 onto the beginning of the list. Reverse the lists for DIE so that
5200 they are in order of addition. */
5203 reverse_die_lists (die)
5204 register dw_die_ref die;
5206 register dw_die_ref c, cp, cn;
5207 register dw_attr_ref a, ap, an;
5209 for (a = die->die_attr, ap = 0; a; a = an)
5211 an = a->dw_attr_next;
5212 a->dw_attr_next = ap;
5217 for (c = die->die_child, cp = 0; c; c = cn)
5223 die->die_child = cp;
5226 /* reverse_die_lists only reverses the single die you pass it. Since
5227 we used to reverse all dies in add_sibling_attributes, which runs
5228 through all the dies, it would reverse all the dies. Now, however,
5229 since we don't call reverse_die_lists in add_sibling_attributes, we
5230 need a routine to recursively reverse all the dies. This is that
5234 reverse_all_dies (die)
5235 register dw_die_ref die;
5237 register dw_die_ref c;
5239 reverse_die_lists (die);
5241 for (c = die->die_child; c; c = c->die_sib)
5242 reverse_all_dies (c);
5245 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5246 the CU for the enclosing include file, if any. BINCL_DIE is the
5247 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5251 push_new_compile_unit (old_unit, bincl_die)
5252 dw_die_ref old_unit, bincl_die;
5254 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5255 dw_die_ref new_unit = gen_compile_unit_die (filename);
5256 new_unit->die_sib = old_unit;
5260 /* Close an include-file CU and reopen the enclosing one. */
5263 pop_compile_unit (old_unit)
5264 dw_die_ref old_unit;
5266 dw_die_ref new_unit = old_unit->die_sib;
5267 old_unit->die_sib = NULL;
5271 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5272 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5274 /* Calculate the checksum of a location expression. */
5277 loc_checksum (loc, ctx)
5278 dw_loc_descr_ref loc;
5279 struct md5_ctx *ctx;
5281 PROCESS (loc->dw_loc_opc);
5282 PROCESS (loc->dw_loc_oprnd1);
5283 PROCESS (loc->dw_loc_oprnd2);
5286 /* Calculate the checksum of an attribute. */
5289 attr_checksum (at, ctx)
5291 struct md5_ctx *ctx;
5293 dw_loc_descr_ref loc;
5296 PROCESS (at->dw_attr);
5298 /* We don't care about differences in file numbering. */
5299 if (at->dw_attr == DW_AT_decl_file
5300 /* Or that this was compiled with a different compiler snapshot; if
5301 the output is the same, that's what matters. */
5302 || at->dw_attr == DW_AT_producer)
5305 switch (AT_class (at))
5307 case dw_val_class_const:
5308 PROCESS (at->dw_attr_val.v.val_int);
5310 case dw_val_class_unsigned_const:
5311 PROCESS (at->dw_attr_val.v.val_unsigned);
5313 case dw_val_class_long_long:
5314 PROCESS (at->dw_attr_val.v.val_long_long);
5316 case dw_val_class_float:
5317 PROCESS (at->dw_attr_val.v.val_float);
5319 case dw_val_class_flag:
5320 PROCESS (at->dw_attr_val.v.val_flag);
5323 case dw_val_class_str:
5324 PROCESS_STRING (AT_string (at));
5327 case dw_val_class_addr:
5329 switch (GET_CODE (r))
5332 PROCESS_STRING (XSTR (r, 0));
5340 case dw_val_class_offset:
5341 PROCESS (at->dw_attr_val.v.val_offset);
5344 case dw_val_class_loc:
5345 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5346 loc_checksum (loc, ctx);
5349 case dw_val_class_die_ref:
5350 if (AT_ref (at)->die_offset)
5351 PROCESS (AT_ref (at)->die_offset);
5352 /* FIXME else use target die name or something. */
5354 case dw_val_class_fde_ref:
5355 case dw_val_class_lbl_id:
5356 case dw_val_class_lbl_offset:
5364 /* Calculate the checksum of a DIE. */
5367 die_checksum (die, ctx)
5369 struct md5_ctx *ctx;
5374 PROCESS (die->die_tag);
5376 for (a = die->die_attr; a; a = a->dw_attr_next)
5377 attr_checksum (a, ctx);
5379 for (c = die->die_child; c; c = c->die_sib)
5380 die_checksum (c, ctx);
5384 #undef PROCESS_STRING
5386 /* The prefix to attach to symbols on DIEs in the current comdat debug
5388 static char *comdat_symbol_id;
5390 /* The index of the current symbol within the current comdat CU. */
5391 static unsigned int comdat_symbol_number;
5393 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5394 children, and set comdat_symbol_id accordingly. */
5397 compute_section_prefix (unit_die)
5398 dw_die_ref unit_die;
5402 unsigned char checksum[16];
5405 md5_init_ctx (&ctx);
5406 die_checksum (unit_die, &ctx);
5407 md5_finish_ctx (&ctx, checksum);
5410 const char *p = lbasename (get_AT_string (unit_die, DW_AT_name));
5411 name = (char *) alloca (strlen (p) + 64);
5412 sprintf (name, "%s.", p);
5415 clean_symbol_name (name);
5418 char *p = name + strlen (name);
5419 for (i = 0; i < 4; ++i)
5421 sprintf (p, "%.2x", checksum[i]);
5426 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5427 comdat_symbol_number = 0;
5430 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5436 switch (die->die_tag)
5438 case DW_TAG_array_type:
5439 case DW_TAG_class_type:
5440 case DW_TAG_enumeration_type:
5441 case DW_TAG_pointer_type:
5442 case DW_TAG_reference_type:
5443 case DW_TAG_string_type:
5444 case DW_TAG_structure_type:
5445 case DW_TAG_subroutine_type:
5446 case DW_TAG_union_type:
5447 case DW_TAG_ptr_to_member_type:
5448 case DW_TAG_set_type:
5449 case DW_TAG_subrange_type:
5450 case DW_TAG_base_type:
5451 case DW_TAG_const_type:
5452 case DW_TAG_file_type:
5453 case DW_TAG_packed_type:
5454 case DW_TAG_volatile_type:
5461 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5462 Basically, we want to choose the bits that are likely to be shared between
5463 compilations (types) and leave out the bits that are specific to individual
5464 compilations (functions). */
5471 /* I think we want to leave base types and __vtbl_ptr_type in the
5472 main CU, as we do for stabs. The advantage is a greater
5473 likelihood of sharing between objects that don't include headers
5474 in the same order (and therefore would put the base types in a
5475 different comdat). jason 8/28/00 */
5476 if (c->die_tag == DW_TAG_base_type)
5479 if (c->die_tag == DW_TAG_pointer_type
5480 || c->die_tag == DW_TAG_reference_type
5481 || c->die_tag == DW_TAG_const_type
5482 || c->die_tag == DW_TAG_volatile_type)
5484 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5485 return t ? is_comdat_die (t) : 0;
5489 return is_type_die (c);
5492 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5493 compilation unit. */
5499 if (is_type_die (c))
5501 if (get_AT (c, DW_AT_declaration)
5502 && ! get_AT (c, DW_AT_specification))
5508 gen_internal_sym (prefix)
5512 static int label_num;
5513 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5514 return xstrdup (buf);
5517 /* Assign symbols to all worthy DIEs under DIE. */
5520 assign_symbol_names (die)
5521 register dw_die_ref die;
5523 register dw_die_ref c;
5525 if (is_symbol_die (die))
5527 if (comdat_symbol_id)
5529 char *p = alloca (strlen (comdat_symbol_id) + 64);
5530 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5531 comdat_symbol_id, comdat_symbol_number++);
5532 die->die_symbol = xstrdup (p);
5535 die->die_symbol = gen_internal_sym ("LDIE");
5538 for (c = die->die_child; c != NULL; c = c->die_sib)
5539 assign_symbol_names (c);
5542 /* Traverse the DIE (which is always comp_unit_die), and set up
5543 additional compilation units for each of the include files we see
5544 bracketed by BINCL/EINCL. */
5547 break_out_includes (die)
5548 register dw_die_ref die;
5551 register dw_die_ref unit = NULL;
5552 limbo_die_node *node;
5554 for (ptr = &(die->die_child); *ptr; )
5556 register dw_die_ref c = *ptr;
5558 if (c->die_tag == DW_TAG_GNU_BINCL
5559 || c->die_tag == DW_TAG_GNU_EINCL
5560 || (unit && is_comdat_die (c)))
5562 /* This DIE is for a secondary CU; remove it from the main one. */
5565 if (c->die_tag == DW_TAG_GNU_BINCL)
5567 unit = push_new_compile_unit (unit, c);
5570 else if (c->die_tag == DW_TAG_GNU_EINCL)
5572 unit = pop_compile_unit (unit);
5576 add_child_die (unit, c);
5580 /* Leave this DIE in the main CU. */
5581 ptr = &(c->die_sib);
5587 /* We can only use this in debugging, since the frontend doesn't check
5588 to make sure that we leave every include file we enter. */
5593 assign_symbol_names (die);
5594 for (node = limbo_die_list; node; node = node->next)
5596 compute_section_prefix (node->die);
5597 assign_symbol_names (node->die);
5601 /* Traverse the DIE and add a sibling attribute if it may have the
5602 effect of speeding up access to siblings. To save some space,
5603 avoid generating sibling attributes for DIE's without children. */
5606 add_sibling_attributes (die)
5607 register dw_die_ref die;
5609 register dw_die_ref c;
5611 if (die->die_tag != DW_TAG_compile_unit
5612 && die->die_sib && die->die_child != NULL)
5613 /* Add the sibling link to the front of the attribute list. */
5614 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5616 for (c = die->die_child; c != NULL; c = c->die_sib)
5617 add_sibling_attributes (c);
5620 /* Output all location lists for the DIE and it's children */
5622 output_location_lists (die)
5623 register dw_die_ref die;
5627 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5629 if (AT_class (d_attr) == dw_val_class_loc_list)
5631 output_loc_list (AT_loc_list (d_attr));
5634 for (c = die->die_child; c != NULL; c = c->die_sib)
5635 output_location_lists (c);
5638 /* The format of each DIE (and its attribute value pairs)
5639 is encoded in an abbreviation table. This routine builds the
5640 abbreviation table and assigns a unique abbreviation id for
5641 each abbreviation entry. The children of each die are visited
5645 build_abbrev_table (die)
5646 register dw_die_ref die;
5648 register unsigned long abbrev_id;
5649 register unsigned int n_alloc;
5650 register dw_die_ref c;
5651 register dw_attr_ref d_attr, a_attr;
5653 /* Scan the DIE references, and mark as external any that refer to
5654 DIEs from other CUs (i.e. those which are not marked). */
5655 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5657 if (AT_class (d_attr) == dw_val_class_die_ref
5658 && AT_ref (d_attr)->die_mark == 0)
5660 if (AT_ref (d_attr)->die_symbol == 0)
5662 set_AT_ref_external (d_attr, 1);
5666 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5668 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5670 if (abbrev->die_tag == die->die_tag)
5672 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5674 a_attr = abbrev->die_attr;
5675 d_attr = die->die_attr;
5677 while (a_attr != NULL && d_attr != NULL)
5679 if ((a_attr->dw_attr != d_attr->dw_attr)
5680 || (value_format (a_attr) != value_format (d_attr)))
5683 a_attr = a_attr->dw_attr_next;
5684 d_attr = d_attr->dw_attr_next;
5687 if (a_attr == NULL && d_attr == NULL)
5693 if (abbrev_id >= abbrev_die_table_in_use)
5695 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5697 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5699 = (dw_die_ref *) xrealloc (abbrev_die_table,
5700 sizeof (dw_die_ref) * n_alloc);
5702 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5703 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5704 abbrev_die_table_allocated = n_alloc;
5707 ++abbrev_die_table_in_use;
5708 abbrev_die_table[abbrev_id] = die;
5711 die->die_abbrev = abbrev_id;
5712 for (c = die->die_child; c != NULL; c = c->die_sib)
5713 build_abbrev_table (c);
5716 /* Return the size of a string, including the null byte.
5718 This used to treat backslashes as escapes, and hence they were not included
5719 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5720 which treats a backslash as a backslash, escaping it if necessary, and hence
5721 we must include them in the count. */
5723 static unsigned long
5724 size_of_string (str)
5725 register const char *str;
5727 return strlen (str) + 1;
5730 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5733 constant_size (value)
5734 long unsigned value;
5741 log = floor_log2 (value);
5744 log = 1 << (floor_log2 (log) + 1);
5749 /* Return the size of a DIE, as it is represented in the
5750 .debug_info section. */
5752 static unsigned long
5754 register dw_die_ref die;
5756 register unsigned long size = 0;
5757 register dw_attr_ref a;
5759 size += size_of_uleb128 (die->die_abbrev);
5760 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5762 switch (AT_class (a))
5764 case dw_val_class_addr:
5765 size += DWARF2_ADDR_SIZE;
5767 case dw_val_class_offset:
5768 size += DWARF_OFFSET_SIZE;
5770 case dw_val_class_loc:
5772 register unsigned long lsize = size_of_locs (AT_loc (a));
5775 size += constant_size (lsize);
5779 case dw_val_class_loc_list:
5780 size += DWARF_OFFSET_SIZE;
5782 case dw_val_class_const:
5783 size += size_of_sleb128 (AT_int (a));
5785 case dw_val_class_unsigned_const:
5786 size += constant_size (AT_unsigned (a));
5788 case dw_val_class_long_long:
5789 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5791 case dw_val_class_float:
5792 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5794 case dw_val_class_flag:
5797 case dw_val_class_die_ref:
5798 size += DWARF_OFFSET_SIZE;
5800 case dw_val_class_fde_ref:
5801 size += DWARF_OFFSET_SIZE;
5803 case dw_val_class_lbl_id:
5804 size += DWARF2_ADDR_SIZE;
5806 case dw_val_class_lbl_offset:
5807 size += DWARF_OFFSET_SIZE;
5809 case dw_val_class_str:
5810 size += size_of_string (AT_string (a));
5820 /* Size the debugging information associated with a given DIE.
5821 Visits the DIE's children recursively. Updates the global
5822 variable next_die_offset, on each time through. Uses the
5823 current value of next_die_offset to update the die_offset
5824 field in each DIE. */
5827 calc_die_sizes (die)
5830 register dw_die_ref c;
5831 die->die_offset = next_die_offset;
5832 next_die_offset += size_of_die (die);
5834 for (c = die->die_child; c != NULL; c = c->die_sib)
5837 if (die->die_child != NULL)
5838 /* Count the null byte used to terminate sibling lists. */
5839 next_die_offset += 1;
5842 /* Set the marks for a die and its children. We do this so
5843 that we know whether or not a reference needs to use FORM_ref_addr; only
5844 DIEs in the same CU will be marked. We used to clear out the offset
5845 and use that as the flag, but ran into ordering problems. */
5851 register dw_die_ref c;
5853 for (c = die->die_child; c; c = c->die_sib)
5857 /* Clear the marks for a die and its children. */
5863 register dw_die_ref c;
5865 for (c = die->die_child; c; c = c->die_sib)
5869 /* Return the size of the .debug_pubnames table generated for the
5870 compilation unit. */
5872 static unsigned long
5875 register unsigned long size;
5876 register unsigned i;
5878 size = DWARF_PUBNAMES_HEADER_SIZE;
5879 for (i = 0; i < pubname_table_in_use; ++i)
5881 register pubname_ref p = &pubname_table[i];
5882 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5885 size += DWARF_OFFSET_SIZE;
5889 /* Return the size of the information in the .debug_aranges section. */
5891 static unsigned long
5894 register unsigned long size;
5896 size = DWARF_ARANGES_HEADER_SIZE;
5898 /* Count the address/length pair for this compilation unit. */
5899 size += 2 * DWARF2_ADDR_SIZE;
5900 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5902 /* Count the two zero words used to terminated the address range table. */
5903 size += 2 * DWARF2_ADDR_SIZE;
5907 /* Select the encoding of an attribute value. */
5909 static enum dwarf_form
5913 switch (a->dw_attr_val.val_class)
5915 case dw_val_class_addr:
5916 return DW_FORM_addr;
5917 case dw_val_class_offset:
5918 if (DWARF_OFFSET_SIZE == 4)
5919 return DW_FORM_data4;
5920 if (DWARF_OFFSET_SIZE == 8)
5921 return DW_FORM_data8;
5923 case dw_val_class_loc_list:
5924 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
5925 .debug_loc section */
5926 return DW_FORM_data4;
5927 case dw_val_class_loc:
5928 switch (constant_size (size_of_locs (AT_loc (a))))
5931 return DW_FORM_block1;
5933 return DW_FORM_block2;
5937 case dw_val_class_const:
5938 return DW_FORM_sdata;
5939 case dw_val_class_unsigned_const:
5940 switch (constant_size (AT_unsigned (a)))
5943 return DW_FORM_data1;
5945 return DW_FORM_data2;
5947 return DW_FORM_data4;
5949 return DW_FORM_data8;
5953 case dw_val_class_long_long:
5954 return DW_FORM_block1;
5955 case dw_val_class_float:
5956 return DW_FORM_block1;
5957 case dw_val_class_flag:
5958 return DW_FORM_flag;
5959 case dw_val_class_die_ref:
5960 if (AT_ref_external (a))
5961 return DW_FORM_ref_addr;
5964 case dw_val_class_fde_ref:
5965 return DW_FORM_data;
5966 case dw_val_class_lbl_id:
5967 return DW_FORM_addr;
5968 case dw_val_class_lbl_offset:
5969 return DW_FORM_data;
5970 case dw_val_class_str:
5971 return DW_FORM_string;
5978 /* Output the encoding of an attribute value. */
5981 output_value_format (a)
5984 enum dwarf_form form = value_format (a);
5985 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
5988 /* Output the .debug_abbrev section which defines the DIE abbreviation
5992 output_abbrev_section ()
5994 unsigned long abbrev_id;
5997 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5999 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6001 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6003 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6004 dwarf_tag_name (abbrev->die_tag));
6006 if (abbrev->die_child != NULL)
6007 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6009 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6011 for (a_attr = abbrev->die_attr; a_attr != NULL;
6012 a_attr = a_attr->dw_attr_next)
6014 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6015 dwarf_attr_name (a_attr->dw_attr));
6016 output_value_format (a_attr);
6019 dw2_asm_output_data (1, 0, NULL);
6020 dw2_asm_output_data (1, 0, NULL);
6023 /* Terminate the table. */
6024 dw2_asm_output_data (1, 0, NULL);
6027 /* Output a symbol we can use to refer to this DIE from another CU. */
6030 output_die_symbol (die)
6031 register dw_die_ref die;
6033 char *sym = die->die_symbol;
6038 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6039 /* We make these global, not weak; if the target doesn't support
6040 .linkonce, it doesn't support combining the sections, so debugging
6042 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6043 ASM_OUTPUT_LABEL (asm_out_file, sym);
6046 /* Return a new location list, given the begin and end range, and the
6047 expression. gensym tells us whether to generate a new internal
6048 symbol for this location list node, which is done for the head of
6050 static inline dw_loc_list_ref
6051 new_loc_list (expr, begin, end, section, gensym)
6052 register dw_loc_descr_ref expr;
6053 register const char *begin;
6054 register const char *end;
6055 register const char *section;
6056 register unsigned gensym;
6058 register dw_loc_list_ref retlist
6059 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6060 retlist->begin = begin;
6062 retlist->expr = expr;
6063 retlist->section = section;
6065 retlist->ll_symbol = gen_internal_sym ("LLST");
6069 /* Add a location description expression to a location list */
6071 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6072 register dw_loc_list_ref *list_head;
6073 register dw_loc_descr_ref descr;
6074 register const char *begin;
6075 register const char *end;
6076 register const char *section;
6078 register dw_loc_list_ref *d;
6080 /* Find the end of the chain. */
6081 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6083 /* Add a new location list node to the list */
6084 *d = new_loc_list (descr, begin, end, section, 0);
6087 /* Output the location list given to us */
6089 output_loc_list (list_head)
6090 register dw_loc_list_ref list_head;
6092 register dw_loc_list_ref curr=list_head;
6093 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6095 /* ??? This shouldn't be needed now that we've forced the
6096 compilation unit base address to zero when there is code
6097 in more than one section. */
6098 if (strcmp (curr->section, ".text") == 0)
6100 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6101 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT)0,
6102 "Location list base address specifier fake entry");
6103 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6104 "Location list base address specifier base");
6106 for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
6109 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6110 "Location list begin address (%s)",
6111 list_head->ll_symbol);
6112 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6113 "Location list end address (%s)",
6114 list_head->ll_symbol);
6115 size = size_of_locs (curr->expr);
6117 /* Output the block length for this list of location operations. */
6118 dw2_asm_output_data (constant_size (size), size, "%s",
6119 "Location expression size");
6121 output_loc_sequence (curr->expr);
6123 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6124 "Location list terminator begin (%s)",
6125 list_head->ll_symbol);
6126 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6127 "Location list terminator end (%s)",
6128 list_head->ll_symbol);
6130 /* Output the DIE and its attributes. Called recursively to generate
6131 the definitions of each child DIE. */
6135 register dw_die_ref die;
6137 register dw_attr_ref a;
6138 register dw_die_ref c;
6139 register unsigned long size;
6141 /* If someone in another CU might refer to us, set up a symbol for
6142 them to point to. */
6143 if (die->die_symbol)
6144 output_die_symbol (die);
6146 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6147 die->die_offset, dwarf_tag_name (die->die_tag));
6149 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6151 const char *name = dwarf_attr_name (a->dw_attr);
6153 switch (AT_class (a))
6155 case dw_val_class_addr:
6156 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6159 case dw_val_class_offset:
6160 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6164 case dw_val_class_loc:
6165 size = size_of_locs (AT_loc (a));
6167 /* Output the block length for this list of location operations. */
6168 dw2_asm_output_data (constant_size (size), size, "%s", name);
6170 output_loc_sequence (AT_loc (a));
6173 case dw_val_class_const:
6174 /* ??? It would be slightly more efficient to use a scheme like is
6175 used for unsigned constants below, but gdb 4.x does not sign
6176 extend. Gdb 5.x does sign extend. */
6177 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6180 case dw_val_class_unsigned_const:
6181 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6182 AT_unsigned (a), "%s", name);
6185 case dw_val_class_long_long:
6187 unsigned HOST_WIDE_INT first, second;
6189 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6192 if (WORDS_BIG_ENDIAN)
6194 first = a->dw_attr_val.v.val_long_long.hi;
6195 second = a->dw_attr_val.v.val_long_long.low;
6199 first = a->dw_attr_val.v.val_long_long.low;
6200 second = a->dw_attr_val.v.val_long_long.hi;
6202 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6203 first, "long long constant");
6204 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6209 case dw_val_class_float:
6211 register unsigned int i;
6213 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6216 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6217 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6218 "fp constant word %u", i);
6222 case dw_val_class_flag:
6223 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6226 case dw_val_class_loc_list:
6228 char *sym = AT_loc_list (a)->ll_symbol;
6231 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6232 loc_section_label, "%s", name);
6236 case dw_val_class_die_ref:
6237 if (AT_ref_external (a))
6239 char *sym = AT_ref (a)->die_symbol;
6242 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6244 else if (AT_ref (a)->die_offset == 0)
6247 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6251 case dw_val_class_fde_ref:
6254 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6255 a->dw_attr_val.v.val_fde_index * 2);
6256 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6260 case dw_val_class_lbl_id:
6261 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6264 case dw_val_class_lbl_offset:
6265 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6268 case dw_val_class_str:
6269 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6277 for (c = die->die_child; c != NULL; c = c->die_sib)
6280 if (die->die_child != NULL)
6282 /* Add null byte to terminate sibling list. */
6283 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6288 /* Output the compilation unit that appears at the beginning of the
6289 .debug_info section, and precedes the DIE descriptions. */
6292 output_compilation_unit_header ()
6294 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6295 "Length of Compilation Unit Info");
6297 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6299 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6300 "Offset Into Abbrev. Section");
6302 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6305 /* Output the compilation unit DIE and its children. */
6308 output_comp_unit (die)
6311 const char *secname;
6313 /* Even if there are no children of this DIE, we must output the
6314 information about the compilation unit. Otherwise, on an empty
6315 translation unit, we will generate a present, but empty,
6316 .debug_info section. IRIX 6.5 `nm' will then complain when
6319 Mark all the DIEs in this CU so we know which get local refs. */
6322 build_abbrev_table (die);
6324 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6325 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6326 calc_die_sizes (die);
6328 if (die->die_symbol)
6330 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6331 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6333 die->die_symbol = NULL;
6336 secname = (const char *) DEBUG_INFO_SECTION;
6338 /* Output debugging information. */
6339 ASM_OUTPUT_SECTION (asm_out_file, secname);
6340 output_compilation_unit_header ();
6343 /* Leave the marks on the main CU, so we can check them in
6345 if (die->die_symbol)
6349 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6350 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6351 argument list, and maybe the scope. */
6354 dwarf2_name (decl, scope)
6358 return (*decl_printable_name) (decl, scope ? 1 : 0);
6361 /* Add a new entry to .debug_pubnames if appropriate. */
6364 add_pubname (decl, die)
6370 if (! TREE_PUBLIC (decl))
6373 if (pubname_table_in_use == pubname_table_allocated)
6375 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6376 pubname_table = (pubname_ref) xrealloc
6377 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6380 p = &pubname_table[pubname_table_in_use++];
6383 p->name = xstrdup (dwarf2_name (decl, 1));
6386 /* Output the public names table used to speed up access to externally
6387 visible names. For now, only generate entries for externally
6388 visible procedures. */
6393 register unsigned i;
6394 register unsigned long pubnames_length = size_of_pubnames ();
6396 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6397 "Length of Public Names Info");
6399 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6401 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6402 "Offset of Compilation Unit Info");
6404 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6405 "Compilation Unit Length");
6407 for (i = 0; i < pubname_table_in_use; ++i)
6409 register pubname_ref pub = &pubname_table[i];
6411 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6412 if (pub->die->die_mark == 0)
6415 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6418 dw2_asm_output_nstring (pub->name, -1, "external name");
6421 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6424 /* Add a new entry to .debug_aranges if appropriate. */
6427 add_arange (decl, die)
6431 if (! DECL_SECTION_NAME (decl))
6434 if (arange_table_in_use == arange_table_allocated)
6436 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6437 arange_table = (dw_die_ref *)
6438 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6441 arange_table[arange_table_in_use++] = die;
6444 /* Output the information that goes into the .debug_aranges table.
6445 Namely, define the beginning and ending address range of the
6446 text section generated for this compilation unit. */
6451 register unsigned i;
6452 register unsigned long aranges_length = size_of_aranges ();
6454 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6455 "Length of Address Ranges Info");
6457 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6459 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6460 "Offset of Compilation Unit Info");
6462 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6464 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6466 /* We need to align to twice the pointer size here. */
6467 if (DWARF_ARANGES_PAD_SIZE)
6469 /* Pad using a 2 byte words so that padding is correct for any
6471 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6472 2 * DWARF2_ADDR_SIZE);
6473 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6474 dw2_asm_output_data (2, 0, NULL);
6477 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6478 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6479 text_section_label, "Length");
6481 for (i = 0; i < arange_table_in_use; ++i)
6483 dw_die_ref die = arange_table[i];
6485 /* We shouldn't see aranges for DIEs outside of the main CU. */
6486 if (die->die_mark == 0)
6489 if (die->die_tag == DW_TAG_subprogram)
6491 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6493 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6494 get_AT_low_pc (die), "Length");
6498 /* A static variable; extract the symbol from DW_AT_location.
6499 Note that this code isn't currently hit, as we only emit
6500 aranges for functions (jason 9/23/99). */
6502 dw_attr_ref a = get_AT (die, DW_AT_location);
6503 dw_loc_descr_ref loc;
6504 if (! a || AT_class (a) != dw_val_class_loc)
6508 if (loc->dw_loc_opc != DW_OP_addr)
6511 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6512 loc->dw_loc_oprnd1.v.val_addr, "Address");
6513 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6514 get_AT_unsigned (die, DW_AT_byte_size),
6519 /* Output the terminator words. */
6520 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6521 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6524 /* Add a new entry to .debug_ranges. Return the offset at which it
6531 unsigned int in_use = ranges_table_in_use;
6533 if (in_use == ranges_table_allocated)
6535 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6536 ranges_table = (dw_ranges_ref)
6537 xrealloc (ranges_table, (ranges_table_allocated
6538 * sizeof (struct dw_ranges_struct)));
6541 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6542 ranges_table_in_use = in_use + 1;
6544 return in_use * 2 * DWARF2_ADDR_SIZE;
6550 register unsigned i;
6551 const char *start_fmt = "Offset 0x%x";
6552 const char *fmt = start_fmt;
6554 for (i = 0; i < ranges_table_in_use; ++i)
6556 int block_num = ranges_table[i].block_num;
6560 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6561 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6563 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6564 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6566 /* If all code is in the text section, then the compilation
6567 unit base address defaults to DW_AT_low_pc, which is the
6568 base of the text section. */
6569 if (separate_line_info_table_in_use == 0)
6571 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6573 fmt, i * 2 * DWARF2_ADDR_SIZE);
6574 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6575 text_section_label, NULL);
6577 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6578 compilation unit base address to zero, which allows us to
6579 use absolute addresses, and not worry about whether the
6580 target supports cross-section arithmetic. */
6583 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6584 fmt, i * 2 * DWARF2_ADDR_SIZE);
6585 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6592 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6593 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6599 /* Data structure containing information about input files. */
6602 char *path; /* Complete file name. */
6603 char *fname; /* File name part. */
6604 int length; /* Length of entire string. */
6605 int file_idx; /* Index in input file table. */
6606 int dir_idx; /* Index in directory table. */
6609 /* Data structure containing information about directories with source
6613 char *path; /* Path including directory name. */
6614 int length; /* Path length. */
6615 int prefix; /* Index of directory entry which is a prefix. */
6616 int count; /* Number of files in this directory. */
6617 int dir_idx; /* Index of directory used as base. */
6618 int used; /* Used in the end? */
6621 /* Callback function for file_info comparison. We sort by looking at
6622 the directories in the path. */
6624 file_info_cmp (p1, p2)
6628 const struct file_info *s1 = p1;
6629 const struct file_info *s2 = p2;
6633 /* Take care of file names without directories. */
6634 if (s1->path == s1->fname)
6636 else if (s2->path == s2->fname)
6639 cp1 = (unsigned char *) s1->path;
6640 cp2 = (unsigned char *) s2->path;
6646 /* Reached the end of the first path? */
6647 if (cp1 == (unsigned char *) s1->fname)
6648 /* It doesn't really matter in which order files from the
6649 same directory are sorted in. Therefore don't test for
6650 the second path reaching the end. */
6652 else if (cp2 == (unsigned char *) s2->fname)
6655 /* Character of current path component the same? */
6661 /* Output the directory table and the file name table. We try to minimize
6662 the total amount of memory needed. A heuristic is used to avoid large
6663 slowdowns with many input files. */
6665 output_file_names ()
6667 struct file_info *files;
6668 struct dir_info *dirs;
6677 /* Allocate the various arrays we need. */
6678 files = (struct file_info *) alloca (file_table.in_use
6679 * sizeof (struct file_info));
6680 dirs = (struct dir_info *) alloca (file_table.in_use
6681 * sizeof (struct dir_info));
6683 /* Sort the file names. */
6684 for (i = 1; i < (int) file_table.in_use; ++i)
6688 /* Skip all leading "./". */
6689 f = file_table.table[i];
6690 while (f[0] == '.' && f[1] == '/')
6693 /* Create a new array entry. */
6695 files[i].length = strlen (f);
6696 files[i].file_idx = i;
6698 /* Search for the file name part. */
6699 f = strrchr (f, '/');
6700 files[i].fname = f == NULL ? files[i].path : f + 1;
6702 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6704 /* Find all the different directories used. */
6705 dirs[0].path = files[1].path;
6706 dirs[0].length = files[1].fname - files[1].path;
6707 dirs[0].prefix = -1;
6709 dirs[0].dir_idx = 0;
6711 files[1].dir_idx = 0;
6714 for (i = 2; i < (int) file_table.in_use; ++i)
6715 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6716 && memcmp (dirs[ndirs - 1].path, files[i].path,
6717 dirs[ndirs - 1].length) == 0)
6719 /* Same directory as last entry. */
6720 files[i].dir_idx = ndirs - 1;
6721 ++dirs[ndirs - 1].count;
6727 /* This is a new directory. */
6728 dirs[ndirs].path = files[i].path;
6729 dirs[ndirs].length = files[i].fname - files[i].path;
6730 dirs[ndirs].count = 1;
6731 dirs[ndirs].dir_idx = ndirs;
6732 dirs[ndirs].used = 0;
6733 files[i].dir_idx = ndirs;
6735 /* Search for a prefix. */
6736 dirs[ndirs].prefix = -1;
6737 for (j = 0; j < ndirs; ++j)
6738 if (dirs[j].length < dirs[ndirs].length
6739 && dirs[j].length > 1
6740 && (dirs[ndirs].prefix == -1
6741 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6742 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6743 dirs[ndirs].prefix = j;
6748 /* Now to the actual work. We have to find a subset of the
6749 directories which allow expressing the file name using references
6750 to the directory table with the least amount of characters. We
6751 do not do an exhaustive search where we would have to check out
6752 every combination of every single possible prefix. Instead we
6753 use a heuristic which provides nearly optimal results in most
6754 cases and never is much off. */
6755 saved = (int *) alloca (ndirs * sizeof (int));
6756 savehere = (int *) alloca (ndirs * sizeof (int));
6758 memset (saved, '\0', ndirs * sizeof (saved[0]));
6759 for (i = 0; i < ndirs; ++i)
6764 /* We can always save some space for the current directory. But
6765 this does not mean it will be enough to justify adding the
6767 savehere[i] = dirs[i].length;
6768 total = (savehere[i] - saved[i]) * dirs[i].count;
6770 for (j = i + 1; j < ndirs; ++j)
6774 if (saved[j] < dirs[i].length)
6776 /* Determine whether the dirs[i] path is a prefix of the
6781 while (k != -1 && k != i)
6786 /* Yes it is. We can possibly safe some memory but
6787 writing the filenames in dirs[j] relative to
6789 savehere[j] = dirs[i].length;
6790 total += (savehere[j] - saved[j]) * dirs[j].count;
6795 /* Check whether we can safe enough to justify adding the dirs[i]
6797 if (total > dirs[i].length + 1)
6799 /* It's worthwhile adding. */
6800 for (j = i; j < ndirs; ++j)
6801 if (savehere[j] > 0)
6803 /* Remember how much we saved for this directory so far. */
6804 saved[j] = savehere[j];
6806 /* Remember the prefix directory. */
6807 dirs[j].dir_idx = i;
6812 /* We have to emit them in the order they appear in the file_table
6813 array since the index is used in the debug info generation. To
6814 do this efficiently we generate a back-mapping of the indices
6816 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6817 for (i = 1; i < (int) file_table.in_use; ++i)
6819 backmap[files[i].file_idx] = i;
6820 /* Mark this directory as used. */
6821 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6824 /* That was it. We are ready to emit the information. First the
6825 directory name table. Here we have to make sure that the first
6826 actually emitted directory name has the index one. Zero is
6827 reserved for the current working directory. Make sure we do not
6828 confuse these indices with the one for the constructed table
6829 (even though most of the time they are identical). */
6831 idx_offset = dirs[0].length > 0 ? 1 : 0;
6832 for (i = 1 - idx_offset; i < ndirs; ++i)
6833 if (dirs[i].used != 0)
6835 dirs[i].used = idx++;
6836 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6837 "Directory Entry: 0x%x", dirs[i].used);
6839 dw2_asm_output_data (1, 0, "End directory table");
6841 /* Correct the index for the current working directory entry if it
6843 if (idx_offset == 0)
6846 /* Now write all the file names. */
6847 for (i = 1; i < (int) file_table.in_use; ++i)
6849 int file_idx = backmap[i];
6850 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6852 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6853 "File Entry: 0x%x", i);
6855 /* Include directory index. */
6856 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6858 /* Modification time. */
6859 dw2_asm_output_data_uleb128 (0, NULL);
6861 /* File length in bytes. */
6862 dw2_asm_output_data_uleb128 (0, NULL);
6864 dw2_asm_output_data (1, 0, "End file name table");
6868 /* Output the source line number correspondence information. This
6869 information goes into the .debug_line section. */
6874 char l1[20], l2[20], p1[20], p2[20];
6875 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6876 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6877 register unsigned opc;
6878 register unsigned n_op_args;
6879 register unsigned long lt_index;
6880 register unsigned long current_line;
6881 register long line_offset;
6882 register long line_delta;
6883 register unsigned long current_file;
6884 register unsigned long function;
6886 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6887 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6888 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6889 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6891 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6892 "Length of Source Line Info");
6893 ASM_OUTPUT_LABEL (asm_out_file, l1);
6895 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6897 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6898 ASM_OUTPUT_LABEL (asm_out_file, p1);
6900 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6901 "Minimum Instruction Length");
6903 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6904 "Default is_stmt_start flag");
6906 dw2_asm_output_data (1, DWARF_LINE_BASE,
6907 "Line Base Value (Special Opcodes)");
6909 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6910 "Line Range Value (Special Opcodes)");
6912 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6913 "Special Opcode Base");
6915 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6919 case DW_LNS_advance_pc:
6920 case DW_LNS_advance_line:
6921 case DW_LNS_set_file:
6922 case DW_LNS_set_column:
6923 case DW_LNS_fixed_advance_pc:
6931 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6935 /* Write out the information about the files we use. */
6936 output_file_names ();
6937 ASM_OUTPUT_LABEL (asm_out_file, p2);
6939 /* We used to set the address register to the first location in the text
6940 section here, but that didn't accomplish anything since we already
6941 have a line note for the opening brace of the first function. */
6943 /* Generate the line number to PC correspondence table, encoded as
6944 a series of state machine operations. */
6947 strcpy (prev_line_label, text_section_label);
6948 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6950 register dw_line_info_ref line_info = &line_info_table[lt_index];
6953 /* Disable this optimization for now; GDB wants to see two line notes
6954 at the beginning of a function so it can find the end of the
6957 /* Don't emit anything for redundant notes. Just updating the
6958 address doesn't accomplish anything, because we already assume
6959 that anything after the last address is this line. */
6960 if (line_info->dw_line_num == current_line
6961 && line_info->dw_file_num == current_file)
6965 /* Emit debug info for the address of the current line.
6967 Unfortunately, we have little choice here currently, and must always
6968 use the most general form. Gcc does not know the address delta
6969 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
6970 attributes which will give an upper bound on the address range. We
6971 could perhaps use length attributes to determine when it is safe to
6972 use DW_LNS_fixed_advance_pc. */
6974 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6977 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6978 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6979 "DW_LNS_fixed_advance_pc");
6980 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6984 /* This can handle any delta. This takes
6985 4+DWARF2_ADDR_SIZE bytes. */
6986 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6987 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6988 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6989 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6991 strcpy (prev_line_label, line_label);
6993 /* Emit debug info for the source file of the current line, if
6994 different from the previous line. */
6995 if (line_info->dw_file_num != current_file)
6997 current_file = line_info->dw_file_num;
6998 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6999 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7000 file_table.table[current_file]);
7003 /* Emit debug info for the current line number, choosing the encoding
7004 that uses the least amount of space. */
7005 if (line_info->dw_line_num != current_line)
7007 line_offset = line_info->dw_line_num - current_line;
7008 line_delta = line_offset - DWARF_LINE_BASE;
7009 current_line = line_info->dw_line_num;
7010 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7012 /* This can handle deltas from -10 to 234, using the current
7013 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7015 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7016 "line %lu", current_line);
7020 /* This can handle any delta. This takes at least 4 bytes,
7021 depending on the value being encoded. */
7022 dw2_asm_output_data (1, DW_LNS_advance_line,
7023 "advance to line %lu", current_line);
7024 dw2_asm_output_data_sleb128 (line_offset, NULL);
7025 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7030 /* We still need to start a new row, so output a copy insn. */
7031 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7035 /* Emit debug info for the address of the end of the function. */
7038 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7039 "DW_LNS_fixed_advance_pc");
7040 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7044 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7045 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7046 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7047 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7050 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7051 dw2_asm_output_data_uleb128 (1, NULL);
7052 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7057 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7059 register dw_separate_line_info_ref line_info
7060 = &separate_line_info_table[lt_index];
7063 /* Don't emit anything for redundant notes. */
7064 if (line_info->dw_line_num == current_line
7065 && line_info->dw_file_num == current_file
7066 && line_info->function == function)
7070 /* Emit debug info for the address of the current line. If this is
7071 a new function, or the first line of a function, then we need
7072 to handle it differently. */
7073 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7075 if (function != line_info->function)
7077 function = line_info->function;
7079 /* Set the address register to the first line in the function */
7080 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7081 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7082 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7083 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7087 /* ??? See the DW_LNS_advance_pc comment above. */
7090 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7091 "DW_LNS_fixed_advance_pc");
7092 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7096 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7097 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7098 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7099 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7102 strcpy (prev_line_label, line_label);
7104 /* Emit debug info for the source file of the current line, if
7105 different from the previous line. */
7106 if (line_info->dw_file_num != current_file)
7108 current_file = line_info->dw_file_num;
7109 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7110 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7111 file_table.table[current_file]);
7114 /* Emit debug info for the current line number, choosing the encoding
7115 that uses the least amount of space. */
7116 if (line_info->dw_line_num != current_line)
7118 line_offset = line_info->dw_line_num - current_line;
7119 line_delta = line_offset - DWARF_LINE_BASE;
7120 current_line = line_info->dw_line_num;
7121 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7122 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7123 "line %lu", current_line);
7126 dw2_asm_output_data (1, DW_LNS_advance_line,
7127 "advance to line %lu", current_line);
7128 dw2_asm_output_data_sleb128 (line_offset, NULL);
7129 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7133 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7140 /* If we're done with a function, end its sequence. */
7141 if (lt_index == separate_line_info_table_in_use
7142 || separate_line_info_table[lt_index].function != function)
7147 /* Emit debug info for the address of the end of the function. */
7148 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7151 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7152 "DW_LNS_fixed_advance_pc");
7153 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7157 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7158 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7159 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7160 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7163 /* Output the marker for the end of this sequence. */
7164 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7165 dw2_asm_output_data_uleb128 (1, NULL);
7166 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7170 /* Output the marker for the end of the line number info. */
7171 ASM_OUTPUT_LABEL (asm_out_file, l2);
7174 /* Given a pointer to a tree node for some base type, return a pointer to
7175 a DIE that describes the given type.
7177 This routine must only be called for GCC type nodes that correspond to
7178 Dwarf base (fundamental) types. */
7181 base_type_die (type)
7184 register dw_die_ref base_type_result;
7185 register const char *type_name;
7186 register enum dwarf_type encoding;
7187 register tree name = TYPE_NAME (type);
7189 if (TREE_CODE (type) == ERROR_MARK
7190 || TREE_CODE (type) == VOID_TYPE)
7195 if (TREE_CODE (name) == TYPE_DECL)
7196 name = DECL_NAME (name);
7198 type_name = IDENTIFIER_POINTER (name);
7201 type_name = "__unknown__";
7203 switch (TREE_CODE (type))
7206 /* Carefully distinguish the C character types, without messing
7207 up if the language is not C. Note that we check only for the names
7208 that contain spaces; other names might occur by coincidence in other
7210 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7211 && (type == char_type_node
7212 || ! strcmp (type_name, "signed char")
7213 || ! strcmp (type_name, "unsigned char"))))
7215 if (TREE_UNSIGNED (type))
7216 encoding = DW_ATE_unsigned;
7218 encoding = DW_ATE_signed;
7221 /* else fall through. */
7224 /* GNU Pascal/Ada CHAR type. Not used in C. */
7225 if (TREE_UNSIGNED (type))
7226 encoding = DW_ATE_unsigned_char;
7228 encoding = DW_ATE_signed_char;
7232 encoding = DW_ATE_float;
7235 /* Dwarf2 doesn't know anything about complex ints, so use
7236 a user defined type for it. */
7238 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7239 encoding = DW_ATE_complex_float;
7241 encoding = DW_ATE_lo_user;
7245 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7246 encoding = DW_ATE_boolean;
7250 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7253 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7254 if (demangle_name_func)
7255 type_name = (*demangle_name_func) (type_name);
7257 add_AT_string (base_type_result, DW_AT_name, type_name);
7258 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7259 int_size_in_bytes (type));
7260 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7262 return base_type_result;
7265 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7266 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7267 a given type is generally the same as the given type, except that if the
7268 given type is a pointer or reference type, then the root type of the given
7269 type is the root type of the "basis" type for the pointer or reference
7270 type. (This definition of the "root" type is recursive.) Also, the root
7271 type of a `const' qualified type or a `volatile' qualified type is the
7272 root type of the given type without the qualifiers. */
7278 if (TREE_CODE (type) == ERROR_MARK)
7279 return error_mark_node;
7281 switch (TREE_CODE (type))
7284 return error_mark_node;
7287 case REFERENCE_TYPE:
7288 return type_main_variant (root_type (TREE_TYPE (type)));
7291 return type_main_variant (type);
7295 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7296 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7302 switch (TREE_CODE (type))
7317 case QUAL_UNION_TYPE:
7322 case REFERENCE_TYPE:
7336 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7337 entry that chains various modifiers in front of the given type. */
7340 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7342 register int is_const_type;
7343 register int is_volatile_type;
7344 register dw_die_ref context_die;
7346 register enum tree_code code = TREE_CODE (type);
7347 register dw_die_ref mod_type_die = NULL;
7348 register dw_die_ref sub_die = NULL;
7349 register tree item_type = NULL;
7351 if (code != ERROR_MARK)
7353 tree qualified_type;
7355 /* See if we already have the appropriately qualified variant of
7358 = get_qualified_type (type,
7359 ((is_const_type ? TYPE_QUAL_CONST : 0)
7361 ? TYPE_QUAL_VOLATILE : 0)));
7362 /* If we do, then we can just use its DIE, if it exists. */
7365 mod_type_die = lookup_type_die (qualified_type);
7367 return mod_type_die;
7370 /* Handle C typedef types. */
7371 if (qualified_type && TYPE_NAME (qualified_type)
7372 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7373 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7375 tree type_name = TYPE_NAME (qualified_type);
7376 tree dtype = TREE_TYPE (type_name);
7377 if (qualified_type == dtype)
7379 /* For a named type, use the typedef. */
7380 gen_type_die (qualified_type, context_die);
7381 mod_type_die = lookup_type_die (qualified_type);
7384 else if (is_const_type < TYPE_READONLY (dtype)
7385 || is_volatile_type < TYPE_VOLATILE (dtype))
7386 /* cv-unqualified version of named type. Just use the unnamed
7387 type to which it refers. */
7389 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7390 is_const_type, is_volatile_type,
7392 /* Else cv-qualified version of named type; fall through. */
7398 else if (is_const_type)
7400 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7401 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7403 else if (is_volatile_type)
7405 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7406 sub_die = modified_type_die (type, 0, 0, context_die);
7408 else if (code == POINTER_TYPE)
7410 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7411 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7413 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7415 item_type = TREE_TYPE (type);
7417 else if (code == REFERENCE_TYPE)
7419 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7420 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7422 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7424 item_type = TREE_TYPE (type);
7426 else if (is_base_type (type))
7427 mod_type_die = base_type_die (type);
7430 gen_type_die (type, context_die);
7432 /* We have to get the type_main_variant here (and pass that to the
7433 `lookup_type_die' routine) because the ..._TYPE node we have
7434 might simply be a *copy* of some original type node (where the
7435 copy was created to help us keep track of typedef names) and
7436 that copy might have a different TYPE_UID from the original
7438 mod_type_die = lookup_type_die (type_main_variant (type));
7439 if (mod_type_die == NULL)
7443 /* We want to equate the qualified type to the die below. */
7445 type = qualified_type;
7448 equate_type_number_to_die (type, mod_type_die);
7450 /* We must do this after the equate_type_number_to_die call, in case
7451 this is a recursive type. This ensures that the modified_type_die
7452 recursion will terminate even if the type is recursive. Recursive
7453 types are possible in Ada. */
7454 sub_die = modified_type_die (item_type,
7455 TYPE_READONLY (item_type),
7456 TYPE_VOLATILE (item_type),
7459 if (sub_die != NULL)
7460 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7462 return mod_type_die;
7465 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7466 an enumerated type. */
7472 return TREE_CODE (type) == ENUMERAL_TYPE;
7475 /* Return the register number described by a given RTL node. */
7481 register unsigned regno = REGNO (rtl);
7483 if (regno >= FIRST_PSEUDO_REGISTER)
7485 warning ("internal regno botch: regno = %d\n", regno);
7489 regno = DBX_REGISTER_NUMBER (regno);
7493 /* Return a location descriptor that designates a machine register. */
7495 static dw_loc_descr_ref
7496 reg_loc_descriptor (rtl)
7499 register dw_loc_descr_ref loc_result = NULL;
7500 register unsigned reg = reg_number (rtl);
7503 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7505 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7510 /* Return a location descriptor that designates a constant. */
7512 static dw_loc_descr_ref
7513 int_loc_descriptor (i)
7516 enum dwarf_location_atom op;
7518 /* Pick the smallest representation of a constant, rather than just
7519 defaulting to the LEB encoding. */
7523 op = DW_OP_lit0 + i;
7526 else if (i <= 0xffff)
7528 else if (HOST_BITS_PER_WIDE_INT == 32
7538 else if (i >= -0x8000)
7540 else if (HOST_BITS_PER_WIDE_INT == 32
7541 || i >= -0x80000000)
7547 return new_loc_descr (op, i, 0);
7550 /* Return a location descriptor that designates a base+offset location. */
7552 static dw_loc_descr_ref
7553 based_loc_descr (reg, offset)
7557 register dw_loc_descr_ref loc_result;
7558 /* For the "frame base", we use the frame pointer or stack pointer
7559 registers, since the RTL for local variables is relative to one of
7561 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7562 ? HARD_FRAME_POINTER_REGNUM
7563 : STACK_POINTER_REGNUM);
7566 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7568 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7570 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7575 /* Return true if this RTL expression describes a base+offset calculation. */
7581 return (GET_CODE (rtl) == PLUS
7582 && ((GET_CODE (XEXP (rtl, 0)) == REG
7583 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7586 /* The following routine converts the RTL for a variable or parameter
7587 (resident in memory) into an equivalent Dwarf representation of a
7588 mechanism for getting the address of that same variable onto the top of a
7589 hypothetical "address evaluation" stack.
7591 When creating memory location descriptors, we are effectively transforming
7592 the RTL for a memory-resident object into its Dwarf postfix expression
7593 equivalent. This routine recursively descends an RTL tree, turning
7594 it into Dwarf postfix code as it goes.
7596 MODE is the mode of the memory reference, needed to handle some
7597 autoincrement addressing modes. */
7599 static dw_loc_descr_ref
7600 mem_loc_descriptor (rtl, mode)
7602 enum machine_mode mode;
7604 dw_loc_descr_ref mem_loc_result = NULL;
7605 /* Note that for a dynamically sized array, the location we will generate a
7606 description of here will be the lowest numbered location which is
7607 actually within the array. That's *not* necessarily the same as the
7608 zeroth element of the array. */
7610 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7611 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7614 switch (GET_CODE (rtl))
7619 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7620 just fall into the SUBREG code. */
7625 /* The case of a subreg may arise when we have a local (register)
7626 variable or a formal (register) parameter which doesn't quite fill
7627 up an entire register. For now, just assume that it is
7628 legitimate to make the Dwarf info refer to the whole register which
7629 contains the given subreg. */
7630 rtl = SUBREG_REG (rtl);
7635 /* Whenever a register number forms a part of the description of the
7636 method for calculating the (dynamic) address of a memory resident
7637 object, DWARF rules require the register number be referred to as
7638 a "base register". This distinction is not based in any way upon
7639 what category of register the hardware believes the given register
7640 belongs to. This is strictly DWARF terminology we're dealing with
7641 here. Note that in cases where the location of a memory-resident
7642 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7643 OP_CONST (0)) the actual DWARF location descriptor that we generate
7644 may just be OP_BASEREG (basereg). This may look deceptively like
7645 the object in question was allocated to a register (rather than in
7646 memory) so DWARF consumers need to be aware of the subtle
7647 distinction between OP_REG and OP_BASEREG. */
7648 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7652 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7653 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7657 /* Some ports can transform a symbol ref into a label ref, because
7658 the symbol ref is too far away and has to be dumped into a constant
7662 /* Alternatively, the symbol in the constant pool might be referenced
7663 by a different symbol. */
7664 if (GET_CODE (rtl) == SYMBOL_REF
7665 && CONSTANT_POOL_ADDRESS_P (rtl))
7667 rtx tmp = get_pool_constant (rtl);
7668 if (GET_CODE (tmp) == SYMBOL_REF)
7672 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7673 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7674 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7678 /* Extract the PLUS expression nested inside and fall into
7680 rtl = XEXP (rtl, 1);
7685 /* Turn these into a PLUS expression and fall into the PLUS code
7687 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7688 GEN_INT (GET_CODE (rtl) == PRE_INC
7689 ? GET_MODE_UNIT_SIZE (mode)
7690 : -GET_MODE_UNIT_SIZE (mode)));
7696 if (is_based_loc (rtl))
7697 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7698 INTVAL (XEXP (rtl, 1)));
7701 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7703 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7704 && INTVAL (XEXP (rtl, 1)) >= 0)
7706 add_loc_descr (&mem_loc_result,
7707 new_loc_descr (DW_OP_plus_uconst,
7708 INTVAL (XEXP (rtl, 1)), 0));
7712 add_loc_descr (&mem_loc_result,
7713 mem_loc_descriptor (XEXP (rtl, 1), mode));
7714 add_loc_descr (&mem_loc_result,
7715 new_loc_descr (DW_OP_plus, 0, 0));
7721 /* If a pseudo-reg is optimized away, it is possible for it to
7722 be replaced with a MEM containing a multiply. */
7723 add_loc_descr (&mem_loc_result,
7724 mem_loc_descriptor (XEXP (rtl, 0), mode));
7725 add_loc_descr (&mem_loc_result,
7726 mem_loc_descriptor (XEXP (rtl, 1), mode));
7727 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7731 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7738 return mem_loc_result;
7741 /* Return a descriptor that describes the concatenation of two locations.
7742 This is typically a complex variable. */
7744 static dw_loc_descr_ref
7745 concat_loc_descriptor (x0, x1)
7746 register rtx x0, x1;
7748 dw_loc_descr_ref cc_loc_result = NULL;
7750 if (!is_pseudo_reg (x0)
7751 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7752 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7753 add_loc_descr (&cc_loc_result,
7754 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7756 if (!is_pseudo_reg (x1)
7757 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7758 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7759 add_loc_descr (&cc_loc_result,
7760 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7762 return cc_loc_result;
7765 /* Output a proper Dwarf location descriptor for a variable or parameter
7766 which is either allocated in a register or in a memory location. For a
7767 register, we just generate an OP_REG and the register number. For a
7768 memory location we provide a Dwarf postfix expression describing how to
7769 generate the (dynamic) address of the object onto the address stack. */
7771 static dw_loc_descr_ref
7772 loc_descriptor (rtl)
7775 dw_loc_descr_ref loc_result = NULL;
7776 switch (GET_CODE (rtl))
7779 /* The case of a subreg may arise when we have a local (register)
7780 variable or a formal (register) parameter which doesn't quite fill
7781 up an entire register. For now, just assume that it is
7782 legitimate to make the Dwarf info refer to the whole register which
7783 contains the given subreg. */
7784 rtl = SUBREG_REG (rtl);
7789 loc_result = reg_loc_descriptor (rtl);
7793 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7797 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7807 /* Similar, but generate the descriptor from trees instead of rtl.
7808 This comes up particularly with variable length arrays. */
7810 static dw_loc_descr_ref
7811 loc_descriptor_from_tree (loc, addressp)
7815 dw_loc_descr_ref ret = NULL;
7816 int indirect_size = 0;
7817 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7818 enum dwarf_location_atom op;
7820 /* ??? Most of the time we do not take proper care for sign/zero
7821 extending the values properly. Hopefully this won't be a real
7824 switch (TREE_CODE (loc))
7829 case WITH_RECORD_EXPR:
7830 /* This case involves extracting fields from an object to determine the
7831 position of other fields. We don't try to encode this here. The
7832 only user of this is Ada, which encodes the needed information using
7833 the names of types. */
7839 rtx rtl = rtl_for_decl_location (loc);
7840 enum machine_mode mode = DECL_MODE (loc);
7842 if (rtl == NULL_RTX)
7844 else if (CONSTANT_P (rtl))
7846 ret = new_loc_descr (DW_OP_addr, 0, 0);
7847 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7848 ret->dw_loc_oprnd1.v.val_addr = rtl;
7849 indirect_size = GET_MODE_SIZE (mode);
7853 if (GET_CODE (rtl) == MEM)
7855 indirect_size = GET_MODE_SIZE (mode);
7856 rtl = XEXP (rtl, 0);
7858 ret = mem_loc_descriptor (rtl, mode);
7864 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7865 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7870 case NON_LVALUE_EXPR:
7872 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7877 case ARRAY_RANGE_REF:
7880 HOST_WIDE_INT bitsize, bitpos, bytepos;
7881 enum machine_mode mode;
7883 unsigned int alignment;
7885 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7886 &unsignedp, &volatilep, &alignment);
7887 ret = loc_descriptor_from_tree (obj, 1);
7889 if (offset != NULL_TREE)
7891 /* Variable offset. */
7892 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7893 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7898 /* We cannot address anything not on a unit boundary. */
7899 if (bitpos % BITS_PER_UNIT != 0)
7904 if (bitpos % BITS_PER_UNIT != 0
7905 || bitsize % BITS_PER_UNIT != 0)
7907 /* ??? We could handle this by loading and shifting etc.
7908 Wait until someone needs it before expending the effort. */
7912 indirect_size = bitsize / BITS_PER_UNIT;
7915 bytepos = bitpos / BITS_PER_UNIT;
7917 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7918 else if (bytepos < 0)
7920 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7921 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7927 if (host_integerp (loc, 0))
7928 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7940 case TRUNC_DIV_EXPR:
7946 case TRUNC_MOD_EXPR:
7956 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7959 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7960 && host_integerp (TREE_OPERAND (loc, 1), 0))
7962 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7963 add_loc_descr (&ret,
7964 new_loc_descr (DW_OP_plus_uconst,
7965 tree_low_cst (TREE_OPERAND (loc, 1),
7973 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7978 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7983 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7988 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8000 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8001 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
8002 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8016 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8017 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8021 loc = build (COND_EXPR, TREE_TYPE (loc),
8022 build (LT_EXPR, integer_type_node,
8023 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8024 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8029 dw_loc_descr_ref bra_node, jump_node, tmp;
8031 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8032 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8033 add_loc_descr (&ret, bra_node);
8035 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8036 add_loc_descr (&ret, tmp);
8037 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8038 add_loc_descr (&ret, jump_node);
8040 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8041 add_loc_descr (&ret, tmp);
8042 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8043 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
8045 /* ??? Need a node to point the skip at. Use a nop. */
8046 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8047 add_loc_descr (&ret, tmp);
8048 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8049 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8057 /* If we can't fill the request for an address, die. */
8058 if (addressp && indirect_size == 0)
8061 /* If we've got an address and don't want one, dereference. */
8062 if (!addressp && indirect_size > 0)
8064 if (indirect_size > DWARF2_ADDR_SIZE)
8066 if (indirect_size == DWARF2_ADDR_SIZE)
8069 op = DW_OP_deref_size;
8070 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
8076 /* Given a value, round it up to the lowest multiple of `boundary'
8077 which is not less than the value itself. */
8079 static inline HOST_WIDE_INT
8080 ceiling (value, boundary)
8081 HOST_WIDE_INT value;
8082 unsigned int boundary;
8084 return (((value + boundary - 1) / boundary) * boundary);
8087 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8088 pointer to the declared type for the relevant field variable, or return
8089 `integer_type_node' if the given node turns out to be an
8098 if (TREE_CODE (decl) == ERROR_MARK)
8099 return integer_type_node;
8101 type = DECL_BIT_FIELD_TYPE (decl);
8102 if (type == NULL_TREE)
8103 type = TREE_TYPE (decl);
8108 /* Given a pointer to a tree node, return the alignment in bits for
8109 it, or else return BITS_PER_WORD if the node actually turns out to
8110 be an ERROR_MARK node. */
8112 static inline unsigned
8113 simple_type_align_in_bits (type)
8116 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8119 static inline unsigned
8120 simple_decl_align_in_bits (decl)
8123 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8126 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8127 node, return the size in bits for the type if it is a constant, or else
8128 return the alignment for the type if the type's size is not constant, or
8129 else return BITS_PER_WORD if the type actually turns out to be an
8132 static inline unsigned HOST_WIDE_INT
8133 simple_type_size_in_bits (type)
8136 tree type_size_tree;
8138 if (TREE_CODE (type) == ERROR_MARK)
8139 return BITS_PER_WORD;
8140 type_size_tree = TYPE_SIZE (type);
8142 if (type_size_tree == NULL_TREE)
8144 if (! host_integerp (type_size_tree, 1))
8145 return TYPE_ALIGN (type);
8146 return tree_low_cst (type_size_tree, 1);
8149 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8150 return the byte offset of the lowest addressed byte of the "containing
8151 object" for the given FIELD_DECL, or return 0 if we are unable to
8152 determine what that offset is, either because the argument turns out to
8153 be a pointer to an ERROR_MARK node, or because the offset is actually
8154 variable. (We can't handle the latter case just yet). */
8156 static HOST_WIDE_INT
8157 field_byte_offset (decl)
8160 unsigned int type_align_in_bits;
8161 unsigned int decl_align_in_bits;
8162 unsigned HOST_WIDE_INT type_size_in_bits;
8163 HOST_WIDE_INT object_offset_in_bits;
8164 HOST_WIDE_INT object_offset_in_bytes;
8166 tree field_size_tree;
8167 HOST_WIDE_INT bitpos_int;
8168 HOST_WIDE_INT deepest_bitpos;
8169 unsigned HOST_WIDE_INT field_size_in_bits;
8171 if (TREE_CODE (decl) == ERROR_MARK)
8174 if (TREE_CODE (decl) != FIELD_DECL)
8177 type = field_type (decl);
8178 field_size_tree = DECL_SIZE (decl);
8180 /* The size could be unspecified if there was an error, or for
8181 a flexible array member. */
8182 if (! field_size_tree)
8183 field_size_tree = bitsize_zero_node;
8185 /* We cannot yet cope with fields whose positions are variable, so
8186 for now, when we see such things, we simply return 0. Someday, we may
8187 be able to handle such cases, but it will be damn difficult. */
8188 if (! host_integerp (bit_position (decl), 0))
8191 bitpos_int = int_bit_position (decl);
8193 /* If we don't know the size of the field, pretend it's a full word. */
8194 if (host_integerp (field_size_tree, 1))
8195 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8197 field_size_in_bits = BITS_PER_WORD;
8199 type_size_in_bits = simple_type_size_in_bits (type);
8200 type_align_in_bits = simple_type_align_in_bits (type);
8201 decl_align_in_bits = simple_decl_align_in_bits (decl);
8203 /* Note that the GCC front-end doesn't make any attempt to keep track of
8204 the starting bit offset (relative to the start of the containing
8205 structure type) of the hypothetical "containing object" for a bit-
8206 field. Thus, when computing the byte offset value for the start of the
8207 "containing object" of a bit-field, we must deduce this information on
8208 our own. This can be rather tricky to do in some cases. For example,
8209 handling the following structure type definition when compiling for an
8210 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8213 struct S { int field1; long long field2:31; };
8215 Fortunately, there is a simple rule-of-thumb which can be
8216 used in such cases. When compiling for an i386/i486, GCC will allocate
8217 8 bytes for the structure shown above. It decides to do this based upon
8218 one simple rule for bit-field allocation. Quite simply, GCC allocates
8219 each "containing object" for each bit-field at the first (i.e. lowest
8220 addressed) legitimate alignment boundary (based upon the required
8221 minimum alignment for the declared type of the field) which it can
8222 possibly use, subject to the condition that there is still enough
8223 available space remaining in the containing object (when allocated at
8224 the selected point) to fully accommodate all of the bits of the
8225 bit-field itself. This simple rule makes it obvious why GCC allocates
8226 8 bytes for each object of the structure type shown above. When looking
8227 for a place to allocate the "containing object" for `field2', the
8228 compiler simply tries to allocate a 64-bit "containing object" at each
8229 successive 32-bit boundary (starting at zero) until it finds a place to
8230 allocate that 64- bit field such that at least 31 contiguous (and
8231 previously unallocated) bits remain within that selected 64 bit field.
8232 (As it turns out, for the example above, the compiler finds that it is
8233 OK to allocate the "containing object" 64-bit field at bit-offset zero
8234 within the structure type.) Here we attempt to work backwards from the
8235 limited set of facts we're given, and we try to deduce from those facts,
8236 where GCC must have believed that the containing object started (within
8237 the structure type). The value we deduce is then used (by the callers of
8238 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8239 for fields (both bit-fields and, in the case of DW_AT_location, regular
8242 /* Figure out the bit-distance from the start of the structure to the
8243 "deepest" bit of the bit-field. */
8244 deepest_bitpos = bitpos_int + field_size_in_bits;
8246 /* This is the tricky part. Use some fancy footwork to deduce where the
8247 lowest addressed bit of the containing object must be. */
8248 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8250 /* Round up to type_align by default. This works best for bitfields. */
8251 object_offset_in_bits += type_align_in_bits - 1;
8252 object_offset_in_bits /= type_align_in_bits;
8253 object_offset_in_bits *= type_align_in_bits;
8255 if (object_offset_in_bits > bitpos_int)
8257 /* Sigh, the decl must be packed. */
8258 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8260 /* Round up to decl_align instead. */
8261 object_offset_in_bits += decl_align_in_bits - 1;
8262 object_offset_in_bits /= decl_align_in_bits;
8263 object_offset_in_bits *= decl_align_in_bits;
8266 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8268 return object_offset_in_bytes;
8271 /* The following routines define various Dwarf attributes and any data
8272 associated with them. */
8274 /* Add a location description attribute value to a DIE.
8276 This emits location attributes suitable for whole variables and
8277 whole parameters. Note that the location attributes for struct fields are
8278 generated by the routine `data_member_location_attribute' below. */
8281 add_AT_location_description (die, attr_kind, rtl)
8283 enum dwarf_attribute attr_kind;
8286 /* Handle a special case. If we are about to output a location descriptor
8287 for a variable or parameter which has been optimized out of existence,
8288 don't do that. A variable which has been optimized out
8289 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8290 Currently, in some rare cases, variables can have DECL_RTL values which
8291 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8292 elsewhere in the compiler. We treat such cases as if the variable(s) in
8293 question had been optimized out of existence. */
8295 if (is_pseudo_reg (rtl)
8296 || (GET_CODE (rtl) == MEM
8297 && is_pseudo_reg (XEXP (rtl, 0)))
8298 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8299 references the internal argument pointer (a pseudo) in a function
8300 where all references to the internal argument pointer were
8301 eliminated via the optimizers. */
8302 || (GET_CODE (rtl) == MEM
8303 && GET_CODE (XEXP (rtl, 0)) == PLUS
8304 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8305 || (GET_CODE (rtl) == CONCAT
8306 && is_pseudo_reg (XEXP (rtl, 0))
8307 && is_pseudo_reg (XEXP (rtl, 1))))
8310 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8313 /* Attach the specialized form of location attribute used for data
8314 members of struct and union types. In the special case of a
8315 FIELD_DECL node which represents a bit-field, the "offset" part
8316 of this special location descriptor must indicate the distance
8317 in bytes from the lowest-addressed byte of the containing struct
8318 or union type to the lowest-addressed byte of the "containing
8319 object" for the bit-field. (See the `field_byte_offset' function
8320 above).. For any given bit-field, the "containing object" is a
8321 hypothetical object (of some integral or enum type) within which
8322 the given bit-field lives. The type of this hypothetical
8323 "containing object" is always the same as the declared type of
8324 the individual bit-field itself (for GCC anyway... the DWARF
8325 spec doesn't actually mandate this). Note that it is the size
8326 (in bytes) of the hypothetical "containing object" which will
8327 be given in the DW_AT_byte_size attribute for this bit-field.
8328 (See the `byte_size_attribute' function below.) It is also used
8329 when calculating the value of the DW_AT_bit_offset attribute.
8330 (See the `bit_offset_attribute' function below). */
8333 add_data_member_location_attribute (die, decl)
8334 register dw_die_ref die;
8337 register unsigned long offset;
8338 register dw_loc_descr_ref loc_descr;
8339 register enum dwarf_location_atom op;
8341 if (TREE_CODE (decl) == TREE_VEC)
8342 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8344 offset = field_byte_offset (decl);
8346 /* The DWARF2 standard says that we should assume that the structure address
8347 is already on the stack, so we can specify a structure field address
8348 by using DW_OP_plus_uconst. */
8350 #ifdef MIPS_DEBUGGING_INFO
8351 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8352 correctly. It works only if we leave the offset on the stack. */
8355 op = DW_OP_plus_uconst;
8358 loc_descr = new_loc_descr (op, offset, 0);
8359 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8362 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8363 does not have a "location" either in memory or in a register. These
8364 things can arise in GNU C when a constant is passed as an actual parameter
8365 to an inlined function. They can also arise in C++ where declared
8366 constants do not necessarily get memory "homes". */
8369 add_const_value_attribute (die, rtl)
8370 register dw_die_ref die;
8373 switch (GET_CODE (rtl))
8376 /* Note that a CONST_INT rtx could represent either an integer
8377 or a floating-point constant. A CONST_INT is used whenever
8378 the constant will fit into a single word. In all such
8379 cases, the original mode of the constant value is wiped
8380 out, and the CONST_INT rtx is assigned VOIDmode. */
8382 HOST_WIDE_INT val = INTVAL (rtl);
8384 /* ??? We really should be using HOST_WIDE_INT throughout. */
8387 if ((long) val != val)
8389 add_AT_int (die, DW_AT_const_value, (long) val);
8393 if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
8395 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8401 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8402 floating-point constant. A CONST_DOUBLE is used whenever the
8403 constant requires more than one word in order to be adequately
8404 represented. We output CONST_DOUBLEs as blocks. */
8406 register enum machine_mode mode = GET_MODE (rtl);
8408 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8410 register unsigned length = GET_MODE_SIZE (mode) / 4;
8411 long *array = (long *) xmalloc (sizeof (long) * length);
8414 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8418 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8422 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8427 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8434 add_AT_float (die, DW_AT_const_value, length, array);
8438 /* ??? We really should be using HOST_WIDE_INT throughout. */
8439 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8441 add_AT_long_long (die, DW_AT_const_value,
8442 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8448 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8454 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8458 /* In cases where an inlined instance of an inline function is passed
8459 the address of an `auto' variable (which is local to the caller) we
8460 can get a situation where the DECL_RTL of the artificial local
8461 variable (for the inlining) which acts as a stand-in for the
8462 corresponding formal parameter (of the inline function) will look
8463 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8464 exactly a compile-time constant expression, but it isn't the address
8465 of the (artificial) local variable either. Rather, it represents the
8466 *value* which the artificial local variable always has during its
8467 lifetime. We currently have no way to represent such quasi-constant
8468 values in Dwarf, so for now we just punt and generate nothing. */
8472 /* No other kinds of rtx should be possible here. */
8479 rtl_for_decl_location (decl)
8484 /* Here we have to decide where we are going to say the parameter "lives"
8485 (as far as the debugger is concerned). We only have a couple of
8486 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8488 DECL_RTL normally indicates where the parameter lives during most of the
8489 activation of the function. If optimization is enabled however, this
8490 could be either NULL or else a pseudo-reg. Both of those cases indicate
8491 that the parameter doesn't really live anywhere (as far as the code
8492 generation parts of GCC are concerned) during most of the function's
8493 activation. That will happen (for example) if the parameter is never
8494 referenced within the function.
8496 We could just generate a location descriptor here for all non-NULL
8497 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8498 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8499 where DECL_RTL is NULL or is a pseudo-reg.
8501 Note however that we can only get away with using DECL_INCOMING_RTL as
8502 a backup substitute for DECL_RTL in certain limited cases. In cases
8503 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8504 we can be sure that the parameter was passed using the same type as it is
8505 declared to have within the function, and that its DECL_INCOMING_RTL
8506 points us to a place where a value of that type is passed.
8508 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8509 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8510 because in these cases DECL_INCOMING_RTL points us to a value of some
8511 type which is *different* from the type of the parameter itself. Thus,
8512 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8513 such cases, the debugger would end up (for example) trying to fetch a
8514 `float' from a place which actually contains the first part of a
8515 `double'. That would lead to really incorrect and confusing
8516 output at debug-time.
8518 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8519 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8520 are a couple of exceptions however. On little-endian machines we can
8521 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8522 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8523 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8524 when (on a little-endian machine) a non-prototyped function has a
8525 parameter declared to be of type `short' or `char'. In such cases,
8526 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8527 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8528 passed `int' value. If the debugger then uses that address to fetch
8529 a `short' or a `char' (on a little-endian machine) the result will be
8530 the correct data, so we allow for such exceptional cases below.
8532 Note that our goal here is to describe the place where the given formal
8533 parameter lives during most of the function's activation (i.e. between
8534 the end of the prologue and the start of the epilogue). We'll do that
8535 as best as we can. Note however that if the given formal parameter is
8536 modified sometime during the execution of the function, then a stack
8537 backtrace (at debug-time) will show the function as having been
8538 called with the *new* value rather than the value which was
8539 originally passed in. This happens rarely enough that it is not
8540 a major problem, but it *is* a problem, and I'd like to fix it.
8542 A future version of dwarf2out.c may generate two additional
8543 attributes for any given DW_TAG_formal_parameter DIE which will
8544 describe the "passed type" and the "passed location" for the
8545 given formal parameter in addition to the attributes we now
8546 generate to indicate the "declared type" and the "active
8547 location" for each parameter. This additional set of attributes
8548 could be used by debuggers for stack backtraces. Separately, note
8549 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8550 NULL also. This happens (for example) for inlined-instances of
8551 inline function formal parameters which are never referenced.
8552 This really shouldn't be happening. All PARM_DECL nodes should
8553 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8554 doesn't currently generate these values for inlined instances of
8555 inline function parameters, so when we see such cases, we are
8556 just out-of-luck for the time being (until integrate.c
8559 /* Use DECL_RTL as the "location" unless we find something better. */
8560 rtl = DECL_RTL_IF_SET (decl);
8562 if (TREE_CODE (decl) == PARM_DECL)
8564 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8566 tree declared_type = type_main_variant (TREE_TYPE (decl));
8567 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8569 /* This decl represents a formal parameter which was optimized out.
8570 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8571 all* cases where (rtl == NULL_RTX) just below. */
8572 if (declared_type == passed_type)
8573 rtl = DECL_INCOMING_RTL (decl);
8574 else if (! BYTES_BIG_ENDIAN
8575 && TREE_CODE (declared_type) == INTEGER_TYPE
8576 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8577 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8578 rtl = DECL_INCOMING_RTL (decl);
8581 /* If the parm was passed in registers, but lives on the stack, then
8582 make a big endian correction if the mode of the type of the
8583 parameter is not the same as the mode of the rtl. */
8584 /* ??? This is the same series of checks that are made in dbxout.c before
8585 we reach the big endian correction code there. It isn't clear if all
8586 of these checks are necessary here, but keeping them all is the safe
8588 else if (GET_CODE (rtl) == MEM
8589 && XEXP (rtl, 0) != const0_rtx
8590 && ! CONSTANT_P (XEXP (rtl, 0))
8591 /* Not passed in memory. */
8592 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8593 /* Not passed by invisible reference. */
8594 && (GET_CODE (XEXP (rtl, 0)) != REG
8595 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8596 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8597 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8598 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8601 /* Big endian correction check. */
8603 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8604 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8607 int offset = (UNITS_PER_WORD
8608 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8609 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8610 plus_constant (XEXP (rtl, 0), offset));
8614 if (rtl != NULL_RTX)
8616 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8617 #ifdef LEAF_REG_REMAP
8618 if (current_function_uses_only_leaf_regs)
8619 leaf_renumber_regs_insn (rtl);
8626 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8627 data attribute for a variable or a parameter. We generate the
8628 DW_AT_const_value attribute only in those cases where the given variable
8629 or parameter does not have a true "location" either in memory or in a
8630 register. This can happen (for example) when a constant is passed as an
8631 actual argument in a call to an inline function. (It's possible that
8632 these things can crop up in other ways also.) Note that one type of
8633 constant value which can be passed into an inlined function is a constant
8634 pointer. This can happen for example if an actual argument in an inlined
8635 function call evaluates to a compile-time constant address. */
8638 add_location_or_const_value_attribute (die, decl)
8639 register dw_die_ref die;
8644 if (TREE_CODE (decl) == ERROR_MARK)
8647 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8650 rtl = rtl_for_decl_location (decl);
8651 if (rtl == NULL_RTX)
8654 /* If we don't look past the constant pool, we risk emitting a
8655 reference to a constant pool entry that isn't referenced from
8656 code, and thus is not emitted. */
8657 rtl = avoid_constant_pool_reference (rtl);
8659 switch (GET_CODE (rtl))
8662 /* The address of a variable that was optimized away; don't emit
8673 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8674 add_const_value_attribute (die, rtl);
8681 add_AT_location_description (die, DW_AT_location, rtl);
8689 /* If we don't have a copy of this variable in memory for some reason (such
8690 as a C++ member constant that doesn't have an out-of-line definition),
8691 we should tell the debugger about the constant value. */
8694 tree_add_const_value_attribute (var_die, decl)
8698 tree init = DECL_INITIAL (decl);
8699 tree type = TREE_TYPE (decl);
8701 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8702 && initializer_constant_valid_p (init, type) == null_pointer_node)
8707 switch (TREE_CODE (type))
8710 if (host_integerp (init, 0))
8711 add_AT_unsigned (var_die, DW_AT_const_value,
8712 TREE_INT_CST_LOW (init));
8714 add_AT_long_long (var_die, DW_AT_const_value,
8715 TREE_INT_CST_HIGH (init),
8716 TREE_INT_CST_LOW (init));
8723 /* Generate an DW_AT_name attribute given some string value to be included as
8724 the value of the attribute. */
8727 add_name_attribute (die, name_string)
8728 register dw_die_ref die;
8729 register const char *name_string;
8731 if (name_string != NULL && *name_string != 0)
8733 if (demangle_name_func)
8734 name_string = (*demangle_name_func) (name_string);
8736 add_AT_string (die, DW_AT_name, name_string);
8740 /* Given a tree node describing an array bound (either lower or upper) output
8741 a representation for that bound. */
8744 add_bound_info (subrange_die, bound_attr, bound)
8745 register dw_die_ref subrange_die;
8746 register enum dwarf_attribute bound_attr;
8747 register tree bound;
8749 /* If this is an Ada unconstrained array type, then don't emit any debug
8750 info because the array bounds are unknown. They are parameterized when
8751 the type is instantiated. */
8752 if (contains_placeholder_p (bound))
8755 switch (TREE_CODE (bound))
8760 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8762 if (! host_integerp (bound, 0)
8763 || (bound_attr == DW_AT_lower_bound
8764 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8765 || (is_fortran () && integer_onep (bound)))))
8766 /* use the default */
8769 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8774 case NON_LVALUE_EXPR:
8775 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8779 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8780 access the upper bound values may be bogus. If they refer to a
8781 register, they may only describe how to get at these values at the
8782 points in the generated code right after they have just been
8783 computed. Worse yet, in the typical case, the upper bound values
8784 will not even *be* computed in the optimized code (though the
8785 number of elements will), so these SAVE_EXPRs are entirely
8786 bogus. In order to compensate for this fact, we check here to see
8787 if optimization is enabled, and if so, we don't add an attribute
8788 for the (unknown and unknowable) upper bound. This should not
8789 cause too much trouble for existing (stupid?) debuggers because
8790 they have to deal with empty upper bounds location descriptions
8791 anyway in order to be able to deal with incomplete array types.
8792 Of course an intelligent debugger (GDB?) should be able to
8793 comprehend that a missing upper bound specification in a array
8794 type used for a storage class `auto' local array variable
8795 indicates that the upper bound is both unknown (at compile- time)
8796 and unknowable (at run-time) due to optimization.
8798 We assume that a MEM rtx is safe because gcc wouldn't put the
8799 value there unless it was going to be used repeatedly in the
8800 function, i.e. for cleanups. */
8801 if (SAVE_EXPR_RTL (bound)
8802 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8804 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8805 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8806 register rtx loc = SAVE_EXPR_RTL (bound);
8808 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8809 it references an outer function's frame. */
8811 if (GET_CODE (loc) == MEM)
8813 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8815 if (XEXP (loc, 0) != new_addr)
8816 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8819 add_AT_flag (decl_die, DW_AT_artificial, 1);
8820 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8821 add_AT_location_description (decl_die, DW_AT_location, loc);
8822 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8825 /* Else leave out the attribute. */
8831 dw_die_ref decl_die = lookup_decl_die (bound);
8833 /* ??? Can this happen, or should the variable have been bound
8834 first? Probably it can, since I imagine that we try to create
8835 the types of parameters in the order in which they exist in
8836 the list, and won't have created a forward reference to a
8838 if (decl_die != NULL)
8839 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8845 /* Otherwise try to create a stack operation procedure to
8846 evaluate the value of the array bound. */
8848 dw_die_ref ctx, decl_die;
8849 dw_loc_descr_ref loc;
8851 loc = loc_descriptor_from_tree (bound, 0);
8855 ctx = lookup_decl_die (current_function_decl);
8857 decl_die = new_die (DW_TAG_variable, ctx);
8858 add_AT_flag (decl_die, DW_AT_artificial, 1);
8859 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8860 add_AT_loc (decl_die, DW_AT_location, loc);
8862 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8868 /* Note that the block of subscript information for an array type also
8869 includes information about the element type of type given array type. */
8872 add_subscript_info (type_die, type)
8873 register dw_die_ref type_die;
8876 #ifndef MIPS_DEBUGGING_INFO
8877 register unsigned dimension_number;
8879 register tree lower, upper;
8880 register dw_die_ref subrange_die;
8882 /* The GNU compilers represent multidimensional array types as sequences of
8883 one dimensional array types whose element types are themselves array
8884 types. Here we squish that down, so that each multidimensional array
8885 type gets only one array_type DIE in the Dwarf debugging info. The draft
8886 Dwarf specification say that we are allowed to do this kind of
8887 compression in C (because there is no difference between an array or
8888 arrays and a multidimensional array in C) but for other source languages
8889 (e.g. Ada) we probably shouldn't do this. */
8891 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8892 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8893 We work around this by disabling this feature. See also
8894 gen_array_type_die. */
8895 #ifndef MIPS_DEBUGGING_INFO
8896 for (dimension_number = 0;
8897 TREE_CODE (type) == ARRAY_TYPE;
8898 type = TREE_TYPE (type), dimension_number++)
8901 register tree domain = TYPE_DOMAIN (type);
8903 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8904 and (in GNU C only) variable bounds. Handle all three forms
8906 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8909 /* We have an array type with specified bounds. */
8910 lower = TYPE_MIN_VALUE (domain);
8911 upper = TYPE_MAX_VALUE (domain);
8913 /* define the index type. */
8914 if (TREE_TYPE (domain))
8916 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8917 TREE_TYPE field. We can't emit debug info for this
8918 because it is an unnamed integral type. */
8919 if (TREE_CODE (domain) == INTEGER_TYPE
8920 && TYPE_NAME (domain) == NULL_TREE
8921 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8922 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8925 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8929 /* ??? If upper is NULL, the array has unspecified length,
8930 but it does have a lower bound. This happens with Fortran
8932 Since the debugger is definitely going to need to know N
8933 to produce useful results, go ahead and output the lower
8934 bound solo, and hope the debugger can cope. */
8936 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8938 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8941 /* We have an array type with an unspecified length. The DWARF-2
8942 spec does not say how to handle this; let's just leave out the
8946 #ifndef MIPS_DEBUGGING_INFO
8952 add_byte_size_attribute (die, tree_node)
8954 register tree tree_node;
8956 register unsigned size;
8958 switch (TREE_CODE (tree_node))
8966 case QUAL_UNION_TYPE:
8967 size = int_size_in_bytes (tree_node);
8970 /* For a data member of a struct or union, the DW_AT_byte_size is
8971 generally given as the number of bytes normally allocated for an
8972 object of the *declared* type of the member itself. This is true
8973 even for bit-fields. */
8974 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8980 /* Note that `size' might be -1 when we get to this point. If it is, that
8981 indicates that the byte size of the entity in question is variable. We
8982 have no good way of expressing this fact in Dwarf at the present time,
8983 so just let the -1 pass on through. */
8985 add_AT_unsigned (die, DW_AT_byte_size, size);
8988 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8989 which specifies the distance in bits from the highest order bit of the
8990 "containing object" for the bit-field to the highest order bit of the
8993 For any given bit-field, the "containing object" is a hypothetical
8994 object (of some integral or enum type) within which the given bit-field
8995 lives. The type of this hypothetical "containing object" is always the
8996 same as the declared type of the individual bit-field itself. The
8997 determination of the exact location of the "containing object" for a
8998 bit-field is rather complicated. It's handled by the
8999 `field_byte_offset' function (above).
9001 Note that it is the size (in bytes) of the hypothetical "containing object"
9002 which will be given in the DW_AT_byte_size attribute for this bit-field.
9003 (See `byte_size_attribute' above). */
9006 add_bit_offset_attribute (die, decl)
9007 register dw_die_ref die;
9010 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9011 tree type = DECL_BIT_FIELD_TYPE (decl);
9012 HOST_WIDE_INT bitpos_int;
9013 HOST_WIDE_INT highest_order_object_bit_offset;
9014 HOST_WIDE_INT highest_order_field_bit_offset;
9015 HOST_WIDE_INT unsigned bit_offset;
9017 /* Must be a field and a bit field. */
9019 || TREE_CODE (decl) != FIELD_DECL)
9022 /* We can't yet handle bit-fields whose offsets are variable, so if we
9023 encounter such things, just return without generating any attribute
9024 whatsoever. Likewise for variable or too large size. */
9025 if (! host_integerp (bit_position (decl), 0)
9026 || ! host_integerp (DECL_SIZE (decl), 1))
9029 bitpos_int = int_bit_position (decl);
9031 /* Note that the bit offset is always the distance (in bits) from the
9032 highest-order bit of the "containing object" to the highest-order bit of
9033 the bit-field itself. Since the "high-order end" of any object or field
9034 is different on big-endian and little-endian machines, the computation
9035 below must take account of these differences. */
9036 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9037 highest_order_field_bit_offset = bitpos_int;
9039 if (! BYTES_BIG_ENDIAN)
9041 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9042 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9046 = (! BYTES_BIG_ENDIAN
9047 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9048 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9050 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9053 /* For a FIELD_DECL node which represents a bit field, output an attribute
9054 which specifies the length in bits of the given field. */
9057 add_bit_size_attribute (die, decl)
9058 register dw_die_ref die;
9061 /* Must be a field and a bit field. */
9062 if (TREE_CODE (decl) != FIELD_DECL
9063 || ! DECL_BIT_FIELD_TYPE (decl))
9066 if (host_integerp (DECL_SIZE (decl), 1))
9067 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9070 /* If the compiled language is ANSI C, then add a 'prototyped'
9071 attribute, if arg types are given for the parameters of a function. */
9074 add_prototyped_attribute (die, func_type)
9075 register dw_die_ref die;
9076 register tree func_type;
9078 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9079 && TYPE_ARG_TYPES (func_type) != NULL)
9080 add_AT_flag (die, DW_AT_prototyped, 1);
9083 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9084 by looking in either the type declaration or object declaration
9088 add_abstract_origin_attribute (die, origin)
9089 register dw_die_ref die;
9090 register tree origin;
9092 dw_die_ref origin_die = NULL;
9094 if (TREE_CODE (origin) != FUNCTION_DECL)
9096 /* We may have gotten separated from the block for the inlined
9097 function, if we're in an exception handler or some such; make
9098 sure that the abstract function has been written out.
9100 Doing this for nested functions is wrong, however; functions are
9101 distinct units, and our context might not even be inline. */
9104 fn = TYPE_STUB_DECL (fn);
9105 fn = decl_function_context (fn);
9107 dwarf2out_abstract_function (fn);
9110 if (DECL_P (origin))
9111 origin_die = lookup_decl_die (origin);
9112 else if (TYPE_P (origin))
9113 origin_die = lookup_type_die (origin);
9115 if (origin_die == NULL)
9118 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9121 /* We do not currently support the pure_virtual attribute. */
9124 add_pure_or_virtual_attribute (die, func_decl)
9125 register dw_die_ref die;
9126 register tree func_decl;
9128 if (DECL_VINDEX (func_decl))
9130 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9132 if (host_integerp (DECL_VINDEX (func_decl), 0))
9133 add_AT_loc (die, DW_AT_vtable_elem_location,
9134 new_loc_descr (DW_OP_constu,
9135 tree_low_cst (DECL_VINDEX (func_decl), 0),
9138 /* GNU extension: Record what type this method came from originally. */
9139 if (debug_info_level > DINFO_LEVEL_TERSE)
9140 add_AT_die_ref (die, DW_AT_containing_type,
9141 lookup_type_die (DECL_CONTEXT (func_decl)));
9145 /* Add source coordinate attributes for the given decl. */
9148 add_src_coords_attributes (die, decl)
9149 register dw_die_ref die;
9152 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9154 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9155 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9158 /* Add an DW_AT_name attribute and source coordinate attribute for the
9159 given decl, but only if it actually has a name. */
9162 add_name_and_src_coords_attributes (die, decl)
9163 register dw_die_ref die;
9166 register tree decl_name;
9168 decl_name = DECL_NAME (decl);
9169 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9171 add_name_attribute (die, dwarf2_name (decl, 0));
9172 if (! DECL_ARTIFICIAL (decl))
9173 add_src_coords_attributes (die, decl);
9175 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9176 && TREE_PUBLIC (decl)
9177 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9178 && !DECL_ABSTRACT (decl))
9179 add_AT_string (die, DW_AT_MIPS_linkage_name,
9180 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9184 /* Push a new declaration scope. */
9187 push_decl_scope (scope)
9190 /* Make room in the decl_scope_table, if necessary. */
9191 if (decl_scope_table_allocated == decl_scope_depth)
9193 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
9195 = (tree *) xrealloc (decl_scope_table,
9196 decl_scope_table_allocated * sizeof (tree));
9199 decl_scope_table[decl_scope_depth] = scope;
9203 /* Pop a declaration scope. */
9207 if (decl_scope_depth <= 0)
9212 /* Return the DIE for the scope that immediately contains this type.
9213 Non-named types get global scope. Named types nested in other
9214 types get their containing scope if it's open, or global scope
9215 otherwise. All other types (i.e. function-local named types) get
9216 the current active scope. */
9219 scope_die_for (t, context_die)
9221 register dw_die_ref context_die;
9223 register dw_die_ref scope_die = NULL;
9224 register tree containing_scope;
9227 /* Non-types always go in the current scope. */
9231 containing_scope = TYPE_CONTEXT (t);
9233 /* Ignore namespaces for the moment. */
9234 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9235 containing_scope = NULL_TREE;
9237 /* Ignore function type "scopes" from the C frontend. They mean that
9238 a tagged type is local to a parmlist of a function declarator, but
9239 that isn't useful to DWARF. */
9240 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9241 containing_scope = NULL_TREE;
9243 if (containing_scope == NULL_TREE)
9244 scope_die = comp_unit_die;
9245 else if (TYPE_P (containing_scope))
9247 /* For types, we can just look up the appropriate DIE. But
9248 first we check to see if we're in the middle of emitting it
9249 so we know where the new DIE should go. */
9251 for (i = decl_scope_depth - 1; i >= 0; --i)
9252 if (decl_scope_table[i] == containing_scope)
9257 if (debug_info_level > DINFO_LEVEL_TERSE
9258 && !TREE_ASM_WRITTEN (containing_scope))
9261 /* If none of the current dies are suitable, we get file scope. */
9262 scope_die = comp_unit_die;
9265 scope_die = lookup_type_die (containing_scope);
9268 scope_die = context_die;
9273 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9275 static inline int local_scope_p PARAMS ((dw_die_ref));
9277 local_scope_p (context_die)
9278 dw_die_ref context_die;
9280 for (; context_die; context_die = context_die->die_parent)
9281 if (context_die->die_tag == DW_TAG_inlined_subroutine
9282 || context_die->die_tag == DW_TAG_subprogram)
9287 /* Returns nonzero iff CONTEXT_DIE is a class. */
9289 static inline int class_scope_p PARAMS ((dw_die_ref));
9291 class_scope_p (context_die)
9292 dw_die_ref context_die;
9295 && (context_die->die_tag == DW_TAG_structure_type
9296 || context_die->die_tag == DW_TAG_union_type));
9299 /* Many forms of DIEs require a "type description" attribute. This
9300 routine locates the proper "type descriptor" die for the type given
9301 by 'type', and adds an DW_AT_type attribute below the given die. */
9304 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9305 register dw_die_ref object_die;
9307 register int decl_const;
9308 register int decl_volatile;
9309 register dw_die_ref context_die;
9311 register enum tree_code code = TREE_CODE (type);
9312 register dw_die_ref type_die = NULL;
9314 /* ??? If this type is an unnamed subrange type of an integral or
9315 floating-point type, use the inner type. This is because we have no
9316 support for unnamed types in base_type_die. This can happen if this is
9317 an Ada subrange type. Correct solution is emit a subrange type die. */
9318 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9319 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9320 type = TREE_TYPE (type), code = TREE_CODE (type);
9322 if (code == ERROR_MARK)
9325 /* Handle a special case. For functions whose return type is void, we
9326 generate *no* type attribute. (Note that no object may have type
9327 `void', so this only applies to function return types). */
9328 if (code == VOID_TYPE)
9331 type_die = modified_type_die (type,
9332 decl_const || TYPE_READONLY (type),
9333 decl_volatile || TYPE_VOLATILE (type),
9335 if (type_die != NULL)
9336 add_AT_die_ref (object_die, DW_AT_type, type_die);
9339 /* Given a tree pointer to a struct, class, union, or enum type node, return
9340 a pointer to the (string) tag name for the given type, or zero if the type
9341 was declared without a tag. */
9347 register const char *name = 0;
9349 if (TYPE_NAME (type) != 0)
9351 register tree t = 0;
9353 /* Find the IDENTIFIER_NODE for the type name. */
9354 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9355 t = TYPE_NAME (type);
9357 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9358 a TYPE_DECL node, regardless of whether or not a `typedef' was
9360 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9361 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9362 t = DECL_NAME (TYPE_NAME (type));
9364 /* Now get the name as a string, or invent one. */
9366 name = IDENTIFIER_POINTER (t);
9369 return (name == 0 || *name == '\0') ? 0 : name;
9372 /* Return the type associated with a data member, make a special check
9373 for bit field types. */
9376 member_declared_type (member)
9377 register tree member;
9379 return (DECL_BIT_FIELD_TYPE (member)
9380 ? DECL_BIT_FIELD_TYPE (member)
9381 : TREE_TYPE (member));
9384 /* Get the decl's label, as described by its RTL. This may be different
9385 from the DECL_NAME name used in the source file. */
9389 decl_start_label (decl)
9394 x = DECL_RTL (decl);
9395 if (GET_CODE (x) != MEM)
9399 if (GET_CODE (x) != SYMBOL_REF)
9402 fnname = XSTR (x, 0);
9407 /* These routines generate the internal representation of the DIE's for
9408 the compilation unit. Debugging information is collected by walking
9409 the declaration trees passed in from dwarf2out_decl(). */
9412 gen_array_type_die (type, context_die)
9414 register dw_die_ref context_die;
9416 register dw_die_ref scope_die = scope_die_for (type, context_die);
9417 register dw_die_ref array_die;
9418 register tree element_type;
9420 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9421 the inner array type comes before the outer array type. Thus we must
9422 call gen_type_die before we call new_die. See below also. */
9423 #ifdef MIPS_DEBUGGING_INFO
9424 gen_type_die (TREE_TYPE (type), context_die);
9427 array_die = new_die (DW_TAG_array_type, scope_die);
9430 /* We default the array ordering. SDB will probably do
9431 the right things even if DW_AT_ordering is not present. It's not even
9432 an issue until we start to get into multidimensional arrays anyway. If
9433 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9434 then we'll have to put the DW_AT_ordering attribute back in. (But if
9435 and when we find out that we need to put these in, we will only do so
9436 for multidimensional arrays. */
9437 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9440 #ifdef MIPS_DEBUGGING_INFO
9441 /* The SGI compilers handle arrays of unknown bound by setting
9442 AT_declaration and not emitting any subrange DIEs. */
9443 if (! TYPE_DOMAIN (type))
9444 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9447 add_subscript_info (array_die, type);
9449 add_name_attribute (array_die, type_tag (type));
9450 equate_type_number_to_die (type, array_die);
9452 /* Add representation of the type of the elements of this array type. */
9453 element_type = TREE_TYPE (type);
9455 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9456 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9457 We work around this by disabling this feature. See also
9458 add_subscript_info. */
9459 #ifndef MIPS_DEBUGGING_INFO
9460 while (TREE_CODE (element_type) == ARRAY_TYPE)
9461 element_type = TREE_TYPE (element_type);
9463 gen_type_die (element_type, context_die);
9466 add_type_attribute (array_die, element_type, 0, 0, context_die);
9470 gen_set_type_die (type, context_die)
9472 register dw_die_ref context_die;
9474 register dw_die_ref type_die
9475 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9477 equate_type_number_to_die (type, type_die);
9478 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9483 gen_entry_point_die (decl, context_die)
9485 register dw_die_ref context_die;
9487 register tree origin = decl_ultimate_origin (decl);
9488 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9490 add_abstract_origin_attribute (decl_die, origin);
9493 add_name_and_src_coords_attributes (decl_die, decl);
9494 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9498 if (DECL_ABSTRACT (decl))
9499 equate_decl_number_to_die (decl, decl_die);
9501 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9505 /* Remember a type in the incomplete_types_list. */
9508 add_incomplete_type (type)
9511 if (incomplete_types == incomplete_types_allocated)
9513 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9514 incomplete_types_list
9515 = (tree *) xrealloc (incomplete_types_list,
9516 sizeof (tree) * incomplete_types_allocated);
9519 incomplete_types_list[incomplete_types++] = type;
9522 /* Walk through the list of incomplete types again, trying once more to
9523 emit full debugging info for them. */
9526 retry_incomplete_types ()
9530 while (incomplete_types)
9533 type = incomplete_types_list[incomplete_types];
9534 gen_type_die (type, comp_unit_die);
9538 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9541 gen_inlined_enumeration_type_die (type, context_die)
9543 register dw_die_ref context_die;
9545 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9547 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9548 be incomplete and such types are not marked. */
9549 add_abstract_origin_attribute (type_die, type);
9552 /* Generate a DIE to represent an inlined instance of a structure type. */
9555 gen_inlined_structure_type_die (type, context_die)
9557 register dw_die_ref context_die;
9559 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9561 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9562 be incomplete and such types are not marked. */
9563 add_abstract_origin_attribute (type_die, type);
9566 /* Generate a DIE to represent an inlined instance of a union type. */
9569 gen_inlined_union_type_die (type, context_die)
9571 register dw_die_ref context_die;
9573 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9575 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9576 be incomplete and such types are not marked. */
9577 add_abstract_origin_attribute (type_die, type);
9580 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9581 include all of the information about the enumeration values also. Each
9582 enumerated type name/value is listed as a child of the enumerated type
9586 gen_enumeration_type_die (type, context_die)
9588 register dw_die_ref context_die;
9590 register dw_die_ref type_die = lookup_type_die (type);
9592 if (type_die == NULL)
9594 type_die = new_die (DW_TAG_enumeration_type,
9595 scope_die_for (type, context_die));
9596 equate_type_number_to_die (type, type_die);
9597 add_name_attribute (type_die, type_tag (type));
9599 else if (! TYPE_SIZE (type))
9602 remove_AT (type_die, DW_AT_declaration);
9604 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9605 given enum type is incomplete, do not generate the DW_AT_byte_size
9606 attribute or the DW_AT_element_list attribute. */
9607 if (TYPE_SIZE (type))
9611 TREE_ASM_WRITTEN (type) = 1;
9612 add_byte_size_attribute (type_die, type);
9613 if (TYPE_STUB_DECL (type) != NULL_TREE)
9614 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9616 /* If the first reference to this type was as the return type of an
9617 inline function, then it may not have a parent. Fix this now. */
9618 if (type_die->die_parent == NULL)
9619 add_child_die (scope_die_for (type, context_die), type_die);
9621 for (link = TYPE_FIELDS (type);
9622 link != NULL; link = TREE_CHAIN (link))
9624 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9626 add_name_attribute (enum_die,
9627 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9629 if (host_integerp (TREE_VALUE (link), 0))
9631 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9632 add_AT_int (enum_die, DW_AT_const_value,
9633 tree_low_cst (TREE_VALUE (link), 0));
9635 add_AT_unsigned (enum_die, DW_AT_const_value,
9636 tree_low_cst (TREE_VALUE (link), 0));
9641 add_AT_flag (type_die, DW_AT_declaration, 1);
9644 /* Generate a DIE to represent either a real live formal parameter decl or to
9645 represent just the type of some formal parameter position in some function
9648 Note that this routine is a bit unusual because its argument may be a
9649 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9650 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9651 node. If it's the former then this function is being called to output a
9652 DIE to represent a formal parameter object (or some inlining thereof). If
9653 it's the latter, then this function is only being called to output a
9654 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9655 argument type of some subprogram type. */
9658 gen_formal_parameter_die (node, context_die)
9660 register dw_die_ref context_die;
9662 register dw_die_ref parm_die
9663 = new_die (DW_TAG_formal_parameter, context_die);
9664 register tree origin;
9666 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9669 origin = decl_ultimate_origin (node);
9671 add_abstract_origin_attribute (parm_die, origin);
9674 add_name_and_src_coords_attributes (parm_die, node);
9675 add_type_attribute (parm_die, TREE_TYPE (node),
9676 TREE_READONLY (node),
9677 TREE_THIS_VOLATILE (node),
9679 if (DECL_ARTIFICIAL (node))
9680 add_AT_flag (parm_die, DW_AT_artificial, 1);
9683 equate_decl_number_to_die (node, parm_die);
9684 if (! DECL_ABSTRACT (node))
9685 add_location_or_const_value_attribute (parm_die, node);
9690 /* We were called with some kind of a ..._TYPE node. */
9691 add_type_attribute (parm_die, node, 0, 0, context_die);
9701 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9702 at the end of an (ANSI prototyped) formal parameters list. */
9705 gen_unspecified_parameters_die (decl_or_type, context_die)
9706 register tree decl_or_type ATTRIBUTE_UNUSED;
9707 register dw_die_ref context_die;
9709 new_die (DW_TAG_unspecified_parameters, context_die);
9712 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9713 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9714 parameters as specified in some function type specification (except for
9715 those which appear as part of a function *definition*). */
9718 gen_formal_types_die (function_or_method_type, context_die)
9719 register tree function_or_method_type;
9720 register dw_die_ref context_die;
9723 register tree formal_type = NULL;
9724 register tree first_parm_type;
9727 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9729 arg = DECL_ARGUMENTS (function_or_method_type);
9730 function_or_method_type = TREE_TYPE (function_or_method_type);
9735 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9737 /* Make our first pass over the list of formal parameter types and output a
9738 DW_TAG_formal_parameter DIE for each one. */
9739 for (link = first_parm_type; link; )
9741 register dw_die_ref parm_die;
9743 formal_type = TREE_VALUE (link);
9744 if (formal_type == void_type_node)
9747 /* Output a (nameless) DIE to represent the formal parameter itself. */
9748 parm_die = gen_formal_parameter_die (formal_type, context_die);
9749 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9750 && link == first_parm_type)
9751 || (arg && DECL_ARTIFICIAL (arg)))
9752 add_AT_flag (parm_die, DW_AT_artificial, 1);
9754 link = TREE_CHAIN (link);
9756 arg = TREE_CHAIN (arg);
9759 /* If this function type has an ellipsis, add a
9760 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9761 if (formal_type != void_type_node)
9762 gen_unspecified_parameters_die (function_or_method_type, context_die);
9764 /* Make our second (and final) pass over the list of formal parameter types
9765 and output DIEs to represent those types (as necessary). */
9766 for (link = TYPE_ARG_TYPES (function_or_method_type);
9768 link = TREE_CHAIN (link))
9770 formal_type = TREE_VALUE (link);
9771 if (formal_type == void_type_node)
9774 gen_type_die (formal_type, context_die);
9778 /* We want to generate the DIE for TYPE so that we can generate the
9779 die for MEMBER, which has been defined; we will need to refer back
9780 to the member declaration nested within TYPE. If we're trying to
9781 generate minimal debug info for TYPE, processing TYPE won't do the
9782 trick; we need to attach the member declaration by hand. */
9785 gen_type_die_for_member (type, member, context_die)
9787 dw_die_ref context_die;
9789 gen_type_die (type, context_die);
9791 /* If we're trying to avoid duplicate debug info, we may not have
9792 emitted the member decl for this function. Emit it now. */
9793 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9794 && ! lookup_decl_die (member))
9796 if (decl_ultimate_origin (member))
9799 push_decl_scope (type);
9800 if (TREE_CODE (member) == FUNCTION_DECL)
9801 gen_subprogram_die (member, lookup_type_die (type));
9803 gen_variable_die (member, lookup_type_die (type));
9808 /* Generate the DWARF2 info for the "abstract" instance
9809 of a function which we may later generate inlined and/or
9810 out-of-line instances of. */
9813 dwarf2out_abstract_function (decl)
9816 register dw_die_ref old_die;
9819 int was_abstract = DECL_ABSTRACT (decl);
9821 /* Make sure we have the actual abstract inline, not a clone. */
9822 decl = DECL_ORIGIN (decl);
9824 old_die = lookup_decl_die (decl);
9825 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9826 /* We've already generated the abstract instance. */
9829 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9830 we don't get confused by DECL_ABSTRACT. */
9831 if (debug_info_level > DINFO_LEVEL_TERSE)
9833 context = decl_class_context (decl);
9835 gen_type_die_for_member
9836 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9839 /* Pretend we've just finished compiling this function. */
9840 save_fn = current_function_decl;
9841 current_function_decl = decl;
9843 set_decl_abstract_flags (decl, 1);
9844 dwarf2out_decl (decl);
9846 set_decl_abstract_flags (decl, 0);
9848 current_function_decl = save_fn;
9851 /* Generate a DIE to represent a declared function (either file-scope or
9855 gen_subprogram_die (decl, context_die)
9857 register dw_die_ref context_die;
9859 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9860 register tree origin = decl_ultimate_origin (decl);
9861 register dw_die_ref subr_die;
9862 register rtx fp_reg;
9863 register tree fn_arg_types;
9864 register tree outer_scope;
9865 register dw_die_ref old_die = lookup_decl_die (decl);
9866 register int declaration = (current_function_decl != decl
9867 || class_scope_p (context_die));
9869 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9870 be true, if we started to generate the abstract instance of an inline,
9871 decided to output its containing class, and proceeded to emit the
9872 declaration of the inline from the member list for the class. In that
9873 case, `declaration' takes priority; we'll get back to the abstract
9874 instance when we're done with the class. */
9876 /* The class-scope declaration DIE must be the primary DIE. */
9877 if (origin && declaration && class_scope_p (context_die))
9886 if (declaration && ! local_scope_p (context_die))
9889 /* Fixup die_parent for the abstract instance of a nested
9891 if (old_die && old_die->die_parent == NULL)
9892 add_child_die (context_die, old_die);
9894 subr_die = new_die (DW_TAG_subprogram, context_die);
9895 add_abstract_origin_attribute (subr_die, origin);
9899 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9901 if (!get_AT_flag (old_die, DW_AT_declaration)
9902 /* We can have a normal definition following an inline one in the
9903 case of redefinition of GNU C extern inlines.
9904 It seems reasonable to use AT_specification in this case. */
9905 && !get_AT_unsigned (old_die, DW_AT_inline))
9907 /* ??? This can happen if there is a bug in the program, for
9908 instance, if it has duplicate function definitions. Ideally,
9909 we should detect this case and ignore it. For now, if we have
9910 already reported an error, any error at all, then assume that
9911 we got here because of a input error, not a dwarf2 bug. */
9917 /* If the definition comes from the same place as the declaration,
9918 maybe use the old DIE. We always want the DIE for this function
9919 that has the *_pc attributes to be under comp_unit_die so the
9920 debugger can find it. We also need to do this for abstract
9921 instances of inlines, since the spec requires the out-of-line copy
9922 to have the same parent. For local class methods, this doesn't
9923 apply; we just use the old DIE. */
9924 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9925 && (DECL_ARTIFICIAL (decl)
9926 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9927 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9928 == (unsigned) DECL_SOURCE_LINE (decl)))))
9932 /* Clear out the declaration attribute and the parm types. */
9933 remove_AT (subr_die, DW_AT_declaration);
9934 remove_children (subr_die);
9938 subr_die = new_die (DW_TAG_subprogram, context_die);
9939 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9940 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9941 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9942 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9943 != (unsigned) DECL_SOURCE_LINE (decl))
9945 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9950 subr_die = new_die (DW_TAG_subprogram, context_die);
9952 if (TREE_PUBLIC (decl))
9953 add_AT_flag (subr_die, DW_AT_external, 1);
9955 add_name_and_src_coords_attributes (subr_die, decl);
9956 if (debug_info_level > DINFO_LEVEL_TERSE)
9958 register tree type = TREE_TYPE (decl);
9960 add_prototyped_attribute (subr_die, type);
9961 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9964 add_pure_or_virtual_attribute (subr_die, decl);
9965 if (DECL_ARTIFICIAL (decl))
9966 add_AT_flag (subr_die, DW_AT_artificial, 1);
9967 if (TREE_PROTECTED (decl))
9968 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9969 else if (TREE_PRIVATE (decl))
9970 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9975 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9977 add_AT_flag (subr_die, DW_AT_declaration, 1);
9979 /* The first time we see a member function, it is in the context of
9980 the class to which it belongs. We make sure of this by emitting
9981 the class first. The next time is the definition, which is
9982 handled above. The two may come from the same source text. */
9983 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9984 equate_decl_number_to_die (decl, subr_die);
9987 else if (DECL_ABSTRACT (decl))
9989 if (DECL_INLINE (decl) && !flag_no_inline)
9991 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9992 inline functions, but not for extern inline functions.
9993 We can't get this completely correct because information
9994 about whether the function was declared inline is not
9996 if (DECL_DEFER_OUTPUT (decl))
9997 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9999 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10002 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10004 equate_decl_number_to_die (decl, subr_die);
10006 else if (!DECL_EXTERNAL (decl))
10008 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
10009 equate_decl_number_to_die (decl, subr_die);
10011 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10012 current_funcdef_number);
10013 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10014 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10015 current_funcdef_number);
10016 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10018 add_pubname (decl, subr_die);
10019 add_arange (decl, subr_die);
10021 #ifdef MIPS_DEBUGGING_INFO
10022 /* Add a reference to the FDE for this routine. */
10023 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10026 /* Define the "frame base" location for this routine. We use the
10027 frame pointer or stack pointer registers, since the RTL for local
10028 variables is relative to one of them. */
10030 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10031 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10034 /* ??? This fails for nested inline functions, because context_display
10035 is not part of the state saved/restored for inline functions. */
10036 if (current_function_needs_context)
10037 add_AT_location_description (subr_die, DW_AT_static_link,
10038 lookup_static_chain (decl));
10042 /* Now output descriptions of the arguments for this function. This gets
10043 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10044 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10045 `...' at the end of the formal parameter list. In order to find out if
10046 there was a trailing ellipsis or not, we must instead look at the type
10047 associated with the FUNCTION_DECL. This will be a node of type
10048 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10049 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10050 an ellipsis at the end. */
10052 /* In the case where we are describing a mere function declaration, all we
10053 need to do here (and all we *can* do here) is to describe the *types* of
10054 its formal parameters. */
10055 if (debug_info_level <= DINFO_LEVEL_TERSE)
10057 else if (declaration)
10058 gen_formal_types_die (decl, subr_die);
10061 /* Generate DIEs to represent all known formal parameters */
10062 register tree arg_decls = DECL_ARGUMENTS (decl);
10063 register tree parm;
10065 /* When generating DIEs, generate the unspecified_parameters DIE
10066 instead if we come across the arg "__builtin_va_alist" */
10067 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10068 if (TREE_CODE (parm) == PARM_DECL)
10070 if (DECL_NAME (parm)
10071 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10072 "__builtin_va_alist"))
10073 gen_unspecified_parameters_die (parm, subr_die);
10075 gen_decl_die (parm, subr_die);
10078 /* Decide whether we need a unspecified_parameters DIE at the end.
10079 There are 2 more cases to do this for: 1) the ansi ... declaration -
10080 this is detectable when the end of the arg list is not a
10081 void_type_node 2) an unprototyped function declaration (not a
10082 definition). This just means that we have no info about the
10083 parameters at all. */
10084 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10085 if (fn_arg_types != NULL)
10087 /* this is the prototyped case, check for ... */
10088 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10089 gen_unspecified_parameters_die (decl, subr_die);
10091 else if (DECL_INITIAL (decl) == NULL_TREE)
10092 gen_unspecified_parameters_die (decl, subr_die);
10095 /* Output Dwarf info for all of the stuff within the body of the function
10096 (if it has one - it may be just a declaration). */
10097 outer_scope = DECL_INITIAL (decl);
10099 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
10100 node created to represent a function. This outermost BLOCK actually
10101 represents the outermost binding contour for the function, i.e. the
10102 contour in which the function's formal parameters and labels get
10103 declared. Curiously, it appears that the front end doesn't actually
10104 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
10105 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
10106 list for the function instead.) The BLOCK_VARS list for the
10107 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
10108 the function however, and we output DWARF info for those in
10109 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
10110 node representing the function's outermost pair of curly braces, and
10111 any blocks used for the base and member initializers of a C++
10112 constructor function. */
10113 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10115 current_function_has_inlines = 0;
10116 decls_for_scope (outer_scope, subr_die, 0);
10118 #if 0 && defined (MIPS_DEBUGGING_INFO)
10119 if (current_function_has_inlines)
10121 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10122 if (! comp_unit_has_inlines)
10124 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10125 comp_unit_has_inlines = 1;
10132 /* Generate a DIE to represent a declared data object. */
10135 gen_variable_die (decl, context_die)
10136 register tree decl;
10137 register dw_die_ref context_die;
10139 register tree origin = decl_ultimate_origin (decl);
10140 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
10142 dw_die_ref old_die = lookup_decl_die (decl);
10143 int declaration = (DECL_EXTERNAL (decl)
10144 || class_scope_p (context_die));
10146 if (origin != NULL)
10147 add_abstract_origin_attribute (var_die, origin);
10148 /* Loop unrolling can create multiple blocks that refer to the same
10149 static variable, so we must test for the DW_AT_declaration flag. */
10150 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10151 copy decls and set the DECL_ABSTRACT flag on them instead of
10153 /* ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10154 else if (old_die && TREE_STATIC (decl)
10155 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10157 /* This is a definition of a C++ class level static. */
10158 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10159 if (DECL_NAME (decl))
10161 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10163 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10164 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10166 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10167 != (unsigned) DECL_SOURCE_LINE (decl))
10169 add_AT_unsigned (var_die, DW_AT_decl_line,
10170 DECL_SOURCE_LINE (decl));
10175 add_name_and_src_coords_attributes (var_die, decl);
10176 add_type_attribute (var_die, TREE_TYPE (decl),
10177 TREE_READONLY (decl),
10178 TREE_THIS_VOLATILE (decl), context_die);
10180 if (TREE_PUBLIC (decl))
10181 add_AT_flag (var_die, DW_AT_external, 1);
10183 if (DECL_ARTIFICIAL (decl))
10184 add_AT_flag (var_die, DW_AT_artificial, 1);
10186 if (TREE_PROTECTED (decl))
10187 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10189 else if (TREE_PRIVATE (decl))
10190 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10194 add_AT_flag (var_die, DW_AT_declaration, 1);
10196 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10197 equate_decl_number_to_die (decl, var_die);
10199 if (! declaration && ! DECL_ABSTRACT (decl))
10201 add_location_or_const_value_attribute (var_die, decl);
10202 add_pubname (decl, var_die);
10205 tree_add_const_value_attribute (var_die, decl);
10208 /* Generate a DIE to represent a label identifier. */
10211 gen_label_die (decl, context_die)
10212 register tree decl;
10213 register dw_die_ref context_die;
10215 register tree origin = decl_ultimate_origin (decl);
10216 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10218 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10220 if (origin != NULL)
10221 add_abstract_origin_attribute (lbl_die, origin);
10223 add_name_and_src_coords_attributes (lbl_die, decl);
10225 if (DECL_ABSTRACT (decl))
10226 equate_decl_number_to_die (decl, lbl_die);
10229 insn = DECL_RTL (decl);
10231 /* Deleted labels are programmer specified labels which have been
10232 eliminated because of various optimisations. We still emit them
10233 here so that it is possible to put breakpoints on them. */
10234 if (GET_CODE (insn) == CODE_LABEL
10235 || ((GET_CODE (insn) == NOTE
10236 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10238 /* When optimization is enabled (via -O) some parts of the compiler
10239 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10240 represent source-level labels which were explicitly declared by
10241 the user. This really shouldn't be happening though, so catch
10242 it if it ever does happen. */
10243 if (INSN_DELETED_P (insn))
10246 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10247 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10252 /* Generate a DIE for a lexical block. */
10255 gen_lexical_block_die (stmt, context_die, depth)
10256 register tree stmt;
10257 register dw_die_ref context_die;
10260 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10261 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10263 if (! BLOCK_ABSTRACT (stmt))
10265 if (BLOCK_FRAGMENT_CHAIN (stmt))
10269 add_AT_offset (stmt_die, DW_AT_ranges, add_ranges (stmt));
10271 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10274 add_ranges (chain);
10275 chain = BLOCK_FRAGMENT_CHAIN (chain);
10282 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10283 BLOCK_NUMBER (stmt));
10284 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10285 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10286 BLOCK_NUMBER (stmt));
10287 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10291 decls_for_scope (stmt, stmt_die, depth);
10294 /* Generate a DIE for an inlined subprogram. */
10297 gen_inlined_subroutine_die (stmt, context_die, depth)
10298 register tree stmt;
10299 register dw_die_ref context_die;
10302 if (! BLOCK_ABSTRACT (stmt))
10304 register dw_die_ref subr_die
10305 = new_die (DW_TAG_inlined_subroutine, context_die);
10306 register tree decl = block_ultimate_origin (stmt);
10307 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10309 /* Emit info for the abstract instance first, if we haven't yet. */
10310 dwarf2out_abstract_function (decl);
10312 add_abstract_origin_attribute (subr_die, decl);
10313 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10314 BLOCK_NUMBER (stmt));
10315 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10316 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10317 BLOCK_NUMBER (stmt));
10318 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10319 decls_for_scope (stmt, subr_die, depth);
10320 current_function_has_inlines = 1;
10324 /* Generate a DIE for a field in a record, or structure. */
10327 gen_field_die (decl, context_die)
10328 register tree decl;
10329 register dw_die_ref context_die;
10331 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10333 add_name_and_src_coords_attributes (decl_die, decl);
10334 add_type_attribute (decl_die, member_declared_type (decl),
10335 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10338 /* If this is a bit field... */
10339 if (DECL_BIT_FIELD_TYPE (decl))
10341 add_byte_size_attribute (decl_die, decl);
10342 add_bit_size_attribute (decl_die, decl);
10343 add_bit_offset_attribute (decl_die, decl);
10346 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10347 add_data_member_location_attribute (decl_die, decl);
10349 if (DECL_ARTIFICIAL (decl))
10350 add_AT_flag (decl_die, DW_AT_artificial, 1);
10352 if (TREE_PROTECTED (decl))
10353 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10355 else if (TREE_PRIVATE (decl))
10356 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10360 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10361 Use modified_type_die instead.
10362 We keep this code here just in case these types of DIEs may be needed to
10363 represent certain things in other languages (e.g. Pascal) someday. */
10365 gen_pointer_type_die (type, context_die)
10366 register tree type;
10367 register dw_die_ref context_die;
10369 register dw_die_ref ptr_die
10370 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10372 equate_type_number_to_die (type, ptr_die);
10373 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10374 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10377 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10378 Use modified_type_die instead.
10379 We keep this code here just in case these types of DIEs may be needed to
10380 represent certain things in other languages (e.g. Pascal) someday. */
10382 gen_reference_type_die (type, context_die)
10383 register tree type;
10384 register dw_die_ref context_die;
10386 register dw_die_ref ref_die
10387 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10389 equate_type_number_to_die (type, ref_die);
10390 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10391 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10395 /* Generate a DIE for a pointer to a member type. */
10397 gen_ptr_to_mbr_type_die (type, context_die)
10398 register tree type;
10399 register dw_die_ref context_die;
10401 register dw_die_ref ptr_die
10402 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10404 equate_type_number_to_die (type, ptr_die);
10405 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10406 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10407 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10410 /* Generate the DIE for the compilation unit. */
10413 gen_compile_unit_die (filename)
10414 register const char *filename;
10416 register dw_die_ref die;
10417 char producer[250];
10418 const char *wd = getpwd ();
10421 die = new_die (DW_TAG_compile_unit, NULL);
10422 add_name_attribute (die, filename);
10424 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10425 add_AT_string (die, DW_AT_comp_dir, wd);
10427 sprintf (producer, "%s %s", language_string, version_string);
10429 #ifdef MIPS_DEBUGGING_INFO
10430 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10431 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10432 not appear in the producer string, the debugger reaches the conclusion
10433 that the object file is stripped and has no debugging information.
10434 To get the MIPS/SGI debugger to believe that there is debugging
10435 information in the object file, we add a -g to the producer string. */
10436 if (debug_info_level > DINFO_LEVEL_TERSE)
10437 strcat (producer, " -g");
10440 add_AT_string (die, DW_AT_producer, producer);
10442 if (strcmp (language_string, "GNU C++") == 0)
10443 language = DW_LANG_C_plus_plus;
10444 else if (strcmp (language_string, "GNU Ada") == 0)
10445 language = DW_LANG_Ada83;
10446 else if (strcmp (language_string, "GNU F77") == 0)
10447 language = DW_LANG_Fortran77;
10448 else if (strcmp (language_string, "GNU Pascal") == 0)
10449 language = DW_LANG_Pascal83;
10450 else if (strcmp (language_string, "GNU Java") == 0)
10451 language = DW_LANG_Java;
10452 else if (flag_traditional)
10453 language = DW_LANG_C;
10455 language = DW_LANG_C89;
10457 add_AT_unsigned (die, DW_AT_language, language);
10462 /* Generate a DIE for a string type. */
10465 gen_string_type_die (type, context_die)
10466 register tree type;
10467 register dw_die_ref context_die;
10469 register dw_die_ref type_die
10470 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10472 equate_type_number_to_die (type, type_die);
10474 /* Fudge the string length attribute for now. */
10476 /* TODO: add string length info.
10477 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10478 bound_representation (upper_bound, 0, 'u'); */
10481 /* Generate the DIE for a base class. */
10484 gen_inheritance_die (binfo, context_die)
10485 register tree binfo;
10486 register dw_die_ref context_die;
10488 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10490 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10491 add_data_member_location_attribute (die, binfo);
10493 if (TREE_VIA_VIRTUAL (binfo))
10494 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10495 if (TREE_VIA_PUBLIC (binfo))
10496 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10497 else if (TREE_VIA_PROTECTED (binfo))
10498 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10501 /* Generate a DIE for a class member. */
10504 gen_member_die (type, context_die)
10505 register tree type;
10506 register dw_die_ref context_die;
10508 register tree member;
10511 /* If this is not an incomplete type, output descriptions of each of its
10512 members. Note that as we output the DIEs necessary to represent the
10513 members of this record or union type, we will also be trying to output
10514 DIEs to represent the *types* of those members. However the `type'
10515 function (above) will specifically avoid generating type DIEs for member
10516 types *within* the list of member DIEs for this (containing) type execpt
10517 for those types (of members) which are explicitly marked as also being
10518 members of this (containing) type themselves. The g++ front- end can
10519 force any given type to be treated as a member of some other
10520 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10521 to point to the TREE node representing the appropriate (containing)
10524 /* First output info about the base classes. */
10525 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10527 register tree bases = TYPE_BINFO_BASETYPES (type);
10528 register int n_bases = TREE_VEC_LENGTH (bases);
10531 for (i = 0; i < n_bases; i++)
10532 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10535 /* Now output info about the data members and type members. */
10536 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10538 /* If we thought we were generating minimal debug info for TYPE
10539 and then changed our minds, some of the member declarations
10540 may have already been defined. Don't define them again, but
10541 do put them in the right order. */
10543 child = lookup_decl_die (member);
10545 splice_child_die (context_die, child);
10547 gen_decl_die (member, context_die);
10550 /* Now output info about the function members (if any). */
10551 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10553 /* Don't include clones in the member list. */
10554 if (DECL_ABSTRACT_ORIGIN (member))
10557 child = lookup_decl_die (member);
10559 splice_child_die (context_die, child);
10561 gen_decl_die (member, context_die);
10565 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10566 is set, we pretend that the type was never defined, so we only get the
10567 member DIEs needed by later specification DIEs. */
10570 gen_struct_or_union_type_die (type, context_die)
10571 register tree type;
10572 register dw_die_ref context_die;
10574 register dw_die_ref type_die = lookup_type_die (type);
10575 register dw_die_ref scope_die = 0;
10576 register int nested = 0;
10577 int complete = (TYPE_SIZE (type)
10578 && (! TYPE_STUB_DECL (type)
10579 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10581 if (type_die && ! complete)
10584 if (TYPE_CONTEXT (type) != NULL_TREE
10585 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10588 scope_die = scope_die_for (type, context_die);
10590 if (! type_die || (nested && scope_die == comp_unit_die))
10591 /* First occurrence of type or toplevel definition of nested class. */
10593 register dw_die_ref old_die = type_die;
10595 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10596 ? DW_TAG_structure_type : DW_TAG_union_type,
10598 equate_type_number_to_die (type, type_die);
10600 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10602 add_name_attribute (type_die, type_tag (type));
10605 remove_AT (type_die, DW_AT_declaration);
10607 /* If this type has been completed, then give it a byte_size attribute and
10608 then give a list of members. */
10611 /* Prevent infinite recursion in cases where the type of some member of
10612 this type is expressed in terms of this type itself. */
10613 TREE_ASM_WRITTEN (type) = 1;
10614 add_byte_size_attribute (type_die, type);
10615 if (TYPE_STUB_DECL (type) != NULL_TREE)
10616 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10618 /* If the first reference to this type was as the return type of an
10619 inline function, then it may not have a parent. Fix this now. */
10620 if (type_die->die_parent == NULL)
10621 add_child_die (scope_die, type_die);
10623 push_decl_scope (type);
10624 gen_member_die (type, type_die);
10627 /* GNU extension: Record what type our vtable lives in. */
10628 if (TYPE_VFIELD (type))
10630 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10632 gen_type_die (vtype, context_die);
10633 add_AT_die_ref (type_die, DW_AT_containing_type,
10634 lookup_type_die (vtype));
10639 add_AT_flag (type_die, DW_AT_declaration, 1);
10641 /* We don't need to do this for function-local types. */
10642 if (! decl_function_context (TYPE_STUB_DECL (type)))
10643 add_incomplete_type (type);
10647 /* Generate a DIE for a subroutine _type_. */
10650 gen_subroutine_type_die (type, context_die)
10651 register tree type;
10652 register dw_die_ref context_die;
10654 register tree return_type = TREE_TYPE (type);
10655 register dw_die_ref subr_die
10656 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10658 equate_type_number_to_die (type, subr_die);
10659 add_prototyped_attribute (subr_die, type);
10660 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10661 gen_formal_types_die (type, subr_die);
10664 /* Generate a DIE for a type definition */
10667 gen_typedef_die (decl, context_die)
10668 register tree decl;
10669 register dw_die_ref context_die;
10671 register dw_die_ref type_die;
10672 register tree origin;
10674 if (TREE_ASM_WRITTEN (decl))
10676 TREE_ASM_WRITTEN (decl) = 1;
10678 type_die = new_die (DW_TAG_typedef, context_die);
10679 origin = decl_ultimate_origin (decl);
10680 if (origin != NULL)
10681 add_abstract_origin_attribute (type_die, origin);
10684 register tree type;
10685 add_name_and_src_coords_attributes (type_die, decl);
10686 if (DECL_ORIGINAL_TYPE (decl))
10688 type = DECL_ORIGINAL_TYPE (decl);
10690 if (type == TREE_TYPE (decl))
10693 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10696 type = TREE_TYPE (decl);
10697 add_type_attribute (type_die, type, TREE_READONLY (decl),
10698 TREE_THIS_VOLATILE (decl), context_die);
10701 if (DECL_ABSTRACT (decl))
10702 equate_decl_number_to_die (decl, type_die);
10705 /* Generate a type description DIE. */
10708 gen_type_die (type, context_die)
10709 register tree type;
10710 register dw_die_ref context_die;
10714 if (type == NULL_TREE || type == error_mark_node)
10717 /* We are going to output a DIE to represent the unqualified version of
10718 this type (i.e. without any const or volatile qualifiers) so get the
10719 main variant (i.e. the unqualified version) of this type now. */
10720 type = type_main_variant (type);
10722 if (TREE_ASM_WRITTEN (type))
10725 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10726 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10728 TREE_ASM_WRITTEN (type) = 1;
10729 gen_decl_die (TYPE_NAME (type), context_die);
10733 switch (TREE_CODE (type))
10739 case REFERENCE_TYPE:
10740 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10741 ensures that the gen_type_die recursion will terminate even if the
10742 type is recursive. Recursive types are possible in Ada. */
10743 /* ??? We could perhaps do this for all types before the switch
10745 TREE_ASM_WRITTEN (type) = 1;
10747 /* For these types, all that is required is that we output a DIE (or a
10748 set of DIEs) to represent the "basis" type. */
10749 gen_type_die (TREE_TYPE (type), context_die);
10753 /* This code is used for C++ pointer-to-data-member types.
10754 Output a description of the relevant class type. */
10755 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10757 /* Output a description of the type of the object pointed to. */
10758 gen_type_die (TREE_TYPE (type), context_die);
10760 /* Now output a DIE to represent this pointer-to-data-member type
10762 gen_ptr_to_mbr_type_die (type, context_die);
10766 gen_type_die (TYPE_DOMAIN (type), context_die);
10767 gen_set_type_die (type, context_die);
10771 gen_type_die (TREE_TYPE (type), context_die);
10772 abort (); /* No way to represent these in Dwarf yet! */
10775 case FUNCTION_TYPE:
10776 /* Force out return type (in case it wasn't forced out already). */
10777 gen_type_die (TREE_TYPE (type), context_die);
10778 gen_subroutine_type_die (type, context_die);
10782 /* Force out return type (in case it wasn't forced out already). */
10783 gen_type_die (TREE_TYPE (type), context_die);
10784 gen_subroutine_type_die (type, context_die);
10788 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10790 gen_type_die (TREE_TYPE (type), context_die);
10791 gen_string_type_die (type, context_die);
10794 gen_array_type_die (type, context_die);
10798 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10801 case ENUMERAL_TYPE:
10804 case QUAL_UNION_TYPE:
10805 /* If this is a nested type whose containing class hasn't been
10806 written out yet, writing it out will cover this one, too.
10807 This does not apply to instantiations of member class templates;
10808 they need to be added to the containing class as they are
10809 generated. FIXME: This hurts the idea of combining type decls
10810 from multiple TUs, since we can't predict what set of template
10811 instantiations we'll get. */
10812 if (TYPE_CONTEXT (type)
10813 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10814 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10816 gen_type_die (TYPE_CONTEXT (type), context_die);
10818 if (TREE_ASM_WRITTEN (type))
10821 /* If that failed, attach ourselves to the stub. */
10822 push_decl_scope (TYPE_CONTEXT (type));
10823 context_die = lookup_type_die (TYPE_CONTEXT (type));
10829 if (TREE_CODE (type) == ENUMERAL_TYPE)
10830 gen_enumeration_type_die (type, context_die);
10832 gen_struct_or_union_type_die (type, context_die);
10837 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10838 it up if it is ever completed. gen_*_type_die will set it for us
10839 when appropriate. */
10848 /* No DIEs needed for fundamental types. */
10852 /* No Dwarf representation currently defined. */
10859 TREE_ASM_WRITTEN (type) = 1;
10862 /* Generate a DIE for a tagged type instantiation. */
10865 gen_tagged_type_instantiation_die (type, context_die)
10866 register tree type;
10867 register dw_die_ref context_die;
10869 if (type == NULL_TREE || type == error_mark_node)
10872 /* We are going to output a DIE to represent the unqualified version of
10873 this type (i.e. without any const or volatile qualifiers) so make sure
10874 that we have the main variant (i.e. the unqualified version) of this
10876 if (type != type_main_variant (type))
10879 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10880 an instance of an unresolved type. */
10882 switch (TREE_CODE (type))
10887 case ENUMERAL_TYPE:
10888 gen_inlined_enumeration_type_die (type, context_die);
10892 gen_inlined_structure_type_die (type, context_die);
10896 case QUAL_UNION_TYPE:
10897 gen_inlined_union_type_die (type, context_die);
10905 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10906 things which are local to the given block. */
10909 gen_block_die (stmt, context_die, depth)
10910 register tree stmt;
10911 register dw_die_ref context_die;
10914 register int must_output_die = 0;
10915 register tree origin;
10916 register tree decl;
10917 register enum tree_code origin_code;
10919 /* Ignore blocks never really used to make RTL. */
10920 if (stmt == NULL_TREE || !TREE_USED (stmt)
10921 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10924 /* If the block is one fragment of a non-contiguous block, do not
10925 process the variables, since they will have been done by the
10926 origin block. Do process subblocks. */
10927 if (BLOCK_FRAGMENT_ORIGIN (stmt))
10931 for (sub= BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
10932 gen_block_die (sub, context_die, depth + 1);
10936 /* Determine the "ultimate origin" of this block. This block may be an
10937 inlined instance of an inlined instance of inline function, so we have
10938 to trace all of the way back through the origin chain to find out what
10939 sort of node actually served as the original seed for the creation of
10940 the current block. */
10941 origin = block_ultimate_origin (stmt);
10942 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10944 /* Determine if we need to output any Dwarf DIEs at all to represent this
10946 if (origin_code == FUNCTION_DECL)
10947 /* The outer scopes for inlinings *must* always be represented. We
10948 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10949 must_output_die = 1;
10952 /* In the case where the current block represents an inlining of the
10953 "body block" of an inline function, we must *NOT* output any DIE for
10954 this block because we have already output a DIE to represent the
10955 whole inlined function scope and the "body block" of any function
10956 doesn't really represent a different scope according to ANSI C
10957 rules. So we check here to make sure that this block does not
10958 represent a "body block inlining" before trying to set the
10959 `must_output_die' flag. */
10960 if (! is_body_block (origin ? origin : stmt))
10962 /* Determine if this block directly contains any "significant"
10963 local declarations which we will need to output DIEs for. */
10964 if (debug_info_level > DINFO_LEVEL_TERSE)
10965 /* We are not in terse mode so *any* local declaration counts
10966 as being a "significant" one. */
10967 must_output_die = (BLOCK_VARS (stmt) != NULL);
10969 /* We are in terse mode, so only local (nested) function
10970 definitions count as "significant" local declarations. */
10971 for (decl = BLOCK_VARS (stmt);
10972 decl != NULL; decl = TREE_CHAIN (decl))
10973 if (TREE_CODE (decl) == FUNCTION_DECL
10974 && DECL_INITIAL (decl))
10976 must_output_die = 1;
10982 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10983 DIE for any block which contains no significant local declarations at
10984 all. Rather, in such cases we just call `decls_for_scope' so that any
10985 needed Dwarf info for any sub-blocks will get properly generated. Note
10986 that in terse mode, our definition of what constitutes a "significant"
10987 local declaration gets restricted to include only inlined function
10988 instances and local (nested) function definitions. */
10989 if (must_output_die)
10991 if (origin_code == FUNCTION_DECL)
10992 gen_inlined_subroutine_die (stmt, context_die, depth);
10994 gen_lexical_block_die (stmt, context_die, depth);
10997 decls_for_scope (stmt, context_die, depth);
11000 /* Generate all of the decls declared within a given scope and (recursively)
11001 all of its sub-blocks. */
11004 decls_for_scope (stmt, context_die, depth)
11005 register tree stmt;
11006 register dw_die_ref context_die;
11009 register tree decl;
11010 register tree subblocks;
11012 /* Ignore blocks never really used to make RTL. */
11013 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11016 /* Output the DIEs to represent all of the data objects and typedefs
11017 declared directly within this block but not within any nested
11018 sub-blocks. Also, nested function and tag DIEs have been
11019 generated with a parent of NULL; fix that up now. */
11020 for (decl = BLOCK_VARS (stmt);
11021 decl != NULL; decl = TREE_CHAIN (decl))
11023 register dw_die_ref die;
11025 if (TREE_CODE (decl) == FUNCTION_DECL)
11026 die = lookup_decl_die (decl);
11027 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11028 die = lookup_type_die (TREE_TYPE (decl));
11032 if (die != NULL && die->die_parent == NULL)
11033 add_child_die (context_die, die);
11035 gen_decl_die (decl, context_die);
11038 /* Output the DIEs to represent all sub-blocks (and the items declared
11039 therein) of this block. */
11040 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11042 subblocks = BLOCK_CHAIN (subblocks))
11043 gen_block_die (subblocks, context_die, depth + 1);
11046 /* Is this a typedef we can avoid emitting? */
11049 is_redundant_typedef (decl)
11050 register tree decl;
11052 if (TYPE_DECL_IS_STUB (decl))
11055 if (DECL_ARTIFICIAL (decl)
11056 && DECL_CONTEXT (decl)
11057 && is_tagged_type (DECL_CONTEXT (decl))
11058 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11059 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11060 /* Also ignore the artificial member typedef for the class name. */
11066 /* Generate Dwarf debug information for a decl described by DECL. */
11069 gen_decl_die (decl, context_die)
11070 register tree decl;
11071 register dw_die_ref context_die;
11073 register tree origin;
11075 if (TREE_CODE (decl) == ERROR_MARK)
11078 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11079 if (DECL_IGNORED_P (decl))
11082 switch (TREE_CODE (decl))
11085 /* The individual enumerators of an enum type get output when we output
11086 the Dwarf representation of the relevant enum type itself. */
11089 case FUNCTION_DECL:
11090 /* Don't output any DIEs to represent mere function declarations,
11091 unless they are class members or explicit block externs. */
11092 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11093 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11096 /* If we're emitting a clone, emit info for the abstract instance. */
11097 if (DECL_ORIGIN (decl) != decl)
11098 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11099 /* If we're emitting an out-of-line copy of an inline function,
11100 emit info for the abstract instance and set up to refer to it. */
11101 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11102 && ! class_scope_p (context_die)
11103 /* dwarf2out_abstract_function won't emit a die if this is just
11104 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11105 that case, because that works only if we have a die. */
11106 && DECL_INITIAL (decl) != NULL_TREE)
11108 dwarf2out_abstract_function (decl);
11109 set_decl_origin_self (decl);
11111 /* Otherwise we're emitting the primary DIE for this decl. */
11112 else if (debug_info_level > DINFO_LEVEL_TERSE)
11114 /* Before we describe the FUNCTION_DECL itself, make sure that we
11115 have described its return type. */
11116 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11118 /* And its virtual context. */
11119 if (DECL_VINDEX (decl) != NULL_TREE)
11120 gen_type_die (DECL_CONTEXT (decl), context_die);
11122 /* And its containing type. */
11123 origin = decl_class_context (decl);
11124 if (origin != NULL_TREE)
11125 gen_type_die_for_member (origin, decl, context_die);
11128 /* Now output a DIE to represent the function itself. */
11129 gen_subprogram_die (decl, context_die);
11133 /* If we are in terse mode, don't generate any DIEs to represent any
11134 actual typedefs. */
11135 if (debug_info_level <= DINFO_LEVEL_TERSE)
11138 /* In the special case of a TYPE_DECL node representing the
11139 declaration of some type tag, if the given TYPE_DECL is marked as
11140 having been instantiated from some other (original) TYPE_DECL node
11141 (e.g. one which was generated within the original definition of an
11142 inline function) we have to generate a special (abbreviated)
11143 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
11145 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11147 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11151 if (is_redundant_typedef (decl))
11152 gen_type_die (TREE_TYPE (decl), context_die);
11154 /* Output a DIE to represent the typedef itself. */
11155 gen_typedef_die (decl, context_die);
11159 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11160 gen_label_die (decl, context_die);
11164 /* If we are in terse mode, don't generate any DIEs to represent any
11165 variable declarations or definitions. */
11166 if (debug_info_level <= DINFO_LEVEL_TERSE)
11169 /* Output any DIEs that are needed to specify the type of this data
11171 gen_type_die (TREE_TYPE (decl), context_die);
11173 /* And its containing type. */
11174 origin = decl_class_context (decl);
11175 if (origin != NULL_TREE)
11176 gen_type_die_for_member (origin, decl, context_die);
11178 /* Now output the DIE to represent the data object itself. This gets
11179 complicated because of the possibility that the VAR_DECL really
11180 represents an inlined instance of a formal parameter for an inline
11182 origin = decl_ultimate_origin (decl);
11183 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11184 gen_formal_parameter_die (decl, context_die);
11186 gen_variable_die (decl, context_die);
11190 /* Ignore the nameless fields that are used to skip bits, but
11191 handle C++ anonymous unions. */
11192 if (DECL_NAME (decl) != NULL_TREE
11193 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11195 gen_type_die (member_declared_type (decl), context_die);
11196 gen_field_die (decl, context_die);
11201 gen_type_die (TREE_TYPE (decl), context_die);
11202 gen_formal_parameter_die (decl, context_die);
11205 case NAMESPACE_DECL:
11206 /* Ignore for now. */
11214 /* Add Ada "use" clause information for SGI Workshop debugger. */
11217 dwarf2out_add_library_unit_info (filename, context_list)
11218 const char *filename;
11219 const char *context_list;
11221 unsigned int file_index;
11223 if (filename != NULL)
11225 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
11226 tree context_list_decl
11227 = build_decl (LABEL_DECL, get_identifier (context_list),
11230 TREE_PUBLIC (context_list_decl) = TRUE;
11231 add_name_attribute (unit_die, context_list);
11232 file_index = lookup_filename (filename);
11233 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11234 add_pubname (context_list_decl, unit_die);
11238 /* Debug information for a global DECL. Called from toplev.c after
11239 compilation proper has finished. */
11241 dwarf2out_global_decl (decl)
11244 /* Output DWARF2 information for file-scope tentative data object
11245 declarations, file-scope (extern) function declarations (which
11246 had no corresponding body) and file-scope tagged type
11247 declarations and definitions which have not yet been forced out. */
11249 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11250 dwarf2out_decl (decl);
11253 /* Write the debugging output for DECL. */
11256 dwarf2out_decl (decl)
11257 register tree decl;
11259 register dw_die_ref context_die = comp_unit_die;
11261 if (TREE_CODE (decl) == ERROR_MARK)
11264 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11265 if (DECL_IGNORED_P (decl))
11268 switch (TREE_CODE (decl))
11270 case FUNCTION_DECL:
11271 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11272 builtin function. Explicit programmer-supplied declarations of
11273 these same functions should NOT be ignored however. */
11274 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11277 /* What we would really like to do here is to filter out all mere
11278 file-scope declarations of file-scope functions which are never
11279 referenced later within this translation unit (and keep all of ones
11280 that *are* referenced later on) but we aren't clairvoyant, so we have
11281 no idea which functions will be referenced in the future (i.e. later
11282 on within the current translation unit). So here we just ignore all
11283 file-scope function declarations which are not also definitions. If
11284 and when the debugger needs to know something about these functions,
11285 it will have to hunt around and find the DWARF information associated
11286 with the definition of the function. Note that we can't just check
11287 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11288 definitions and which ones represent mere declarations. We have to
11289 check `DECL_INITIAL' instead. That's because the C front-end
11290 supports some weird semantics for "extern inline" function
11291 definitions. These can get inlined within the current translation
11292 unit (an thus, we need to generate DWARF info for their abstract
11293 instances so that the DWARF info for the concrete inlined instances
11294 can have something to refer to) but the compiler never generates any
11295 out-of-lines instances of such things (despite the fact that they
11296 *are* definitions). The important point is that the C front-end
11297 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11298 to generate DWARF for them anyway. Note that the C++ front-end also
11299 plays some similar games for inline function definitions appearing
11300 within include files which also contain
11301 `#pragma interface' pragmas. */
11302 if (DECL_INITIAL (decl) == NULL_TREE)
11305 /* If we're a nested function, initially use a parent of NULL; if we're
11306 a plain function, this will be fixed up in decls_for_scope. If
11307 we're a method, it will be ignored, since we already have a DIE. */
11308 if (decl_function_context (decl))
11309 context_die = NULL;
11314 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11315 declaration and if the declaration was never even referenced from
11316 within this entire compilation unit. We suppress these DIEs in
11317 order to save space in the .debug section (by eliminating entries
11318 which are probably useless). Note that we must not suppress
11319 block-local extern declarations (whether used or not) because that
11320 would screw-up the debugger's name lookup mechanism and cause it to
11321 miss things which really ought to be in scope at a given point. */
11322 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11325 /* If we are in terse mode, don't generate any DIEs to represent any
11326 variable declarations or definitions. */
11327 if (debug_info_level <= DINFO_LEVEL_TERSE)
11332 /* Don't emit stubs for types unless they are needed by other DIEs. */
11333 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11336 /* Don't bother trying to generate any DIEs to represent any of the
11337 normal built-in types for the language we are compiling. */
11338 if (DECL_SOURCE_LINE (decl) == 0)
11340 /* OK, we need to generate one for `bool' so GDB knows what type
11341 comparisons have. */
11342 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11343 == DW_LANG_C_plus_plus)
11344 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11345 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11350 /* If we are in terse mode, don't generate any DIEs for types. */
11351 if (debug_info_level <= DINFO_LEVEL_TERSE)
11354 /* If we're a function-scope tag, initially use a parent of NULL;
11355 this will be fixed up in decls_for_scope. */
11356 if (decl_function_context (decl))
11357 context_die = NULL;
11365 gen_decl_die (decl, context_die);
11368 /* Output a marker (i.e. a label) for the beginning of the generated code for
11369 a lexical block. */
11372 dwarf2out_begin_block (line, blocknum)
11373 unsigned int line ATTRIBUTE_UNUSED;
11374 unsigned int blocknum;
11376 function_section (current_function_decl);
11377 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11380 /* Output a marker (i.e. a label) for the end of the generated code for a
11384 dwarf2out_end_block (line, blocknum)
11385 unsigned int line ATTRIBUTE_UNUSED;
11386 unsigned int blocknum;
11388 function_section (current_function_decl);
11389 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11392 /* Returns nonzero if it is appropriate not to emit any debugging
11393 information for BLOCK, because it doesn't contain any instructions.
11395 Don't allow this for blocks with nested functions or local classes
11396 as we would end up with orphans, and in the presence of scheduling
11397 we may end up calling them anyway. */
11400 dwarf2out_ignore_block (block)
11404 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11405 if (TREE_CODE (decl) == FUNCTION_DECL
11406 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11411 /* Lookup a filename (in the list of filenames that we know about here in
11412 dwarf2out.c) and return its "index". The index of each (known) filename is
11413 just a unique number which is associated with only that one filename.
11414 We need such numbers for the sake of generating labels
11415 (in the .debug_sfnames section) and references to those
11416 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11417 If the filename given as an argument is not found in our current list,
11418 add it to the list and assign it the next available unique index number.
11419 In order to speed up searches, we remember the index of the filename
11420 was looked up last. This handles the majority of all searches. */
11423 lookup_filename (file_name)
11424 const char *file_name;
11426 register unsigned i;
11428 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11429 if (strcmp (file_name, "<internal>") == 0
11430 || strcmp (file_name, "<built-in>") == 0)
11433 /* Check to see if the file name that was searched on the previous
11434 call matches this file name. If so, return the index. */
11435 if (file_table.last_lookup_index != 0)
11436 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
11437 return file_table.last_lookup_index;
11439 /* Didn't match the previous lookup, search the table */
11440 for (i = 1; i < file_table.in_use; ++i)
11441 if (strcmp (file_name, file_table.table[i]) == 0)
11443 file_table.last_lookup_index = i;
11447 /* Prepare to add a new table entry by making sure there is enough space in
11448 the table to do so. If not, expand the current table. */
11449 if (i == file_table.allocated)
11451 file_table.allocated = i + FILE_TABLE_INCREMENT;
11452 file_table.table = (char **)
11453 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11456 /* Add the new entry to the end of the filename table. */
11457 file_table.table[i] = xstrdup (file_name);
11458 file_table.in_use = i + 1;
11459 file_table.last_lookup_index = i;
11461 if (DWARF2_ASM_LINE_DEBUG_INFO)
11462 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11470 /* Allocate the initial hunk of the file_table. */
11471 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11472 file_table.allocated = FILE_TABLE_INCREMENT;
11474 /* Skip the first entry - file numbers begin at 1. */
11475 file_table.in_use = 1;
11476 file_table.last_lookup_index = 0;
11479 /* Output a label to mark the beginning of a source code line entry
11480 and record information relating to this source line, in
11481 'line_info_table' for later output of the .debug_line section. */
11484 dwarf2out_source_line (line, filename)
11486 register const char *filename;
11488 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11490 function_section (current_function_decl);
11492 /* If requested, emit something human-readable. */
11493 if (flag_debug_asm)
11494 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11497 if (DWARF2_ASM_LINE_DEBUG_INFO)
11499 unsigned file_num = lookup_filename (filename);
11501 /* Emit the .loc directive understood by GNU as. */
11502 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11504 /* Indicate that line number info exists. */
11505 ++line_info_table_in_use;
11507 /* Indicate that multiple line number tables exist. */
11508 if (DECL_SECTION_NAME (current_function_decl))
11509 ++separate_line_info_table_in_use;
11511 else if (DECL_SECTION_NAME (current_function_decl))
11513 register dw_separate_line_info_ref line_info;
11514 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11515 separate_line_info_table_in_use);
11517 /* expand the line info table if necessary */
11518 if (separate_line_info_table_in_use
11519 == separate_line_info_table_allocated)
11521 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11522 separate_line_info_table
11523 = (dw_separate_line_info_ref)
11524 xrealloc (separate_line_info_table,
11525 separate_line_info_table_allocated
11526 * sizeof (dw_separate_line_info_entry));
11529 /* Add the new entry at the end of the line_info_table. */
11531 = &separate_line_info_table[separate_line_info_table_in_use++];
11532 line_info->dw_file_num = lookup_filename (filename);
11533 line_info->dw_line_num = line;
11534 line_info->function = current_funcdef_number;
11538 register dw_line_info_ref line_info;
11540 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11541 line_info_table_in_use);
11543 /* Expand the line info table if necessary. */
11544 if (line_info_table_in_use == line_info_table_allocated)
11546 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11548 = (dw_line_info_ref)
11549 xrealloc (line_info_table,
11550 (line_info_table_allocated
11551 * sizeof (dw_line_info_entry)));
11554 /* Add the new entry at the end of the line_info_table. */
11555 line_info = &line_info_table[line_info_table_in_use++];
11556 line_info->dw_file_num = lookup_filename (filename);
11557 line_info->dw_line_num = line;
11562 /* Record the beginning of a new source file. */
11565 dwarf2out_start_source_file (lineno, filename)
11566 register unsigned int lineno;
11567 register const char *filename;
11569 if (flag_eliminate_dwarf2_dups)
11571 /* Record the beginning of the file for break_out_includes. */
11572 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11573 add_AT_string (bincl_die, DW_AT_name, filename);
11575 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11577 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11578 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11579 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", lineno);
11580 dw2_asm_output_data_uleb128 (lookup_filename (filename), "Filename we just started");
11584 /* Record the end of a source file. */
11587 dwarf2out_end_source_file (lineno)
11588 unsigned int lineno ATTRIBUTE_UNUSED;
11590 if (flag_eliminate_dwarf2_dups)
11592 /* Record the end of the file for break_out_includes. */
11593 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11595 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11597 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11598 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11602 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11603 the tail part of the directive line, i.e. the part which is past the
11604 initial whitespace, #, whitespace, directive-name, whitespace part. */
11607 dwarf2out_define (lineno, buffer)
11608 register unsigned lineno ATTRIBUTE_UNUSED;
11609 register const char *buffer ATTRIBUTE_UNUSED;
11611 static int initialized = 0;
11614 dwarf2out_start_source_file (0, primary_filename);
11617 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11619 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11620 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11621 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11622 dw2_asm_output_nstring (buffer, -1, "The macro");
11626 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11627 the tail part of the directive line, i.e. the part which is past the
11628 initial whitespace, #, whitespace, directive-name, whitespace part. */
11631 dwarf2out_undef (lineno, buffer)
11632 register unsigned lineno ATTRIBUTE_UNUSED;
11633 register const char *buffer ATTRIBUTE_UNUSED;
11635 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11637 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11638 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
11639 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11640 dw2_asm_output_nstring (buffer, -1, "The macro");
11644 /* Set up for Dwarf output at the start of compilation. */
11647 dwarf2out_init (main_input_filename)
11648 register const char *main_input_filename;
11650 init_file_table ();
11652 /* Remember the name of the primary input file. */
11653 primary_filename = main_input_filename;
11655 /* Add it to the file table first, under the assumption that we'll
11656 be emitting line number data for it first, which avoids having
11657 to add an initial DW_LNS_set_file. */
11658 lookup_filename (main_input_filename);
11660 /* Allocate the initial hunk of the decl_die_table. */
11662 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11663 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11664 decl_die_table_in_use = 0;
11666 /* Allocate the initial hunk of the decl_scope_table. */
11668 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11669 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11670 decl_scope_depth = 0;
11672 /* Allocate the initial hunk of the abbrev_die_table. */
11674 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11675 sizeof (dw_die_ref));
11676 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11677 /* Zero-th entry is allocated, but unused */
11678 abbrev_die_table_in_use = 1;
11680 /* Allocate the initial hunk of the line_info_table. */
11682 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11683 sizeof (dw_line_info_entry));
11684 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11685 /* Zero-th entry is allocated, but unused */
11686 line_info_table_in_use = 1;
11688 /* Generate the initial DIE for the .debug section. Note that the (string)
11689 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11690 will (typically) be a relative pathname and that this pathname should be
11691 taken as being relative to the directory from which the compiler was
11692 invoked when the given (base) source file was compiled. */
11693 comp_unit_die = gen_compile_unit_die (main_input_filename);
11695 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11696 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11698 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11699 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
11700 DEBUG_ABBREV_SECTION_LABEL, 0);
11701 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11702 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11704 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11705 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11706 DEBUG_INFO_SECTION_LABEL, 0);
11707 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11708 DEBUG_LINE_SECTION_LABEL, 0);
11709 ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, 0);
11710 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION);
11711 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
11712 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION);
11713 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11714 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11716 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11717 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11719 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11720 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11721 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11722 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11723 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11725 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11726 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
11727 DEBUG_MACINFO_SECTION_LABEL, 0);
11728 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
11732 /* Output stuff that dwarf requires at the end of every file,
11733 and generate the DWARF-2 debugging info. */
11736 dwarf2out_finish (input_filename)
11737 register const char *input_filename ATTRIBUTE_UNUSED;
11739 limbo_die_node *node, *next_node;
11740 dw_die_ref die = 0;
11742 /* Traverse the limbo die list, and add parent/child links. The only
11743 dies without parents that should be here are concrete instances of
11744 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11745 For concrete instances, we can get the parent die from the abstract
11747 for (node = limbo_die_list; node; node = next_node)
11749 next_node = node->next;
11752 if (die->die_parent == NULL)
11754 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11756 add_child_die (origin->die_parent, die);
11757 else if (die == comp_unit_die)
11764 limbo_die_list = NULL;
11766 /* Walk through the list of incomplete types again, trying once more to
11767 emit full debugging info for them. */
11768 retry_incomplete_types ();
11770 /* We need to reverse all the dies before break_out_includes, or
11771 we'll see the end of an include file before the beginning. */
11772 reverse_all_dies (comp_unit_die);
11774 /* Generate separate CUs for each of the include files we've seen.
11775 They will go into limbo_die_list. */
11776 if (flag_eliminate_dwarf2_dups)
11777 break_out_includes (comp_unit_die);
11779 /* Traverse the DIE's and add add sibling attributes to those DIE's
11780 that have children. */
11781 add_sibling_attributes (comp_unit_die);
11782 for (node = limbo_die_list; node; node = node->next)
11783 add_sibling_attributes (node->die);
11785 /* Output a terminator label for the .text section. */
11786 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11787 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11790 /* Output a terminator label for the .data section. */
11791 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11792 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11794 /* Output a terminator label for the .bss section. */
11795 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11796 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11799 /* Output the source line correspondence table. We must do this
11800 even if there is no line information. Otherwise, on an empty
11801 translation unit, we will generate a present, but empty,
11802 .debug_info section. IRIX 6.5 `nm' will then complain when
11803 examining the file. */
11804 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11806 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11807 output_line_info ();
11810 /* We can only use the low/high_pc attributes if all of the code was
11812 if (separate_line_info_table_in_use == 0)
11814 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11815 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11817 /* And if it wasn't, we need to give .debug_loc and .debug_ranges
11818 an appropriate "base address". Use zero so that these addresses
11819 become absolute. */
11820 else if (have_location_lists || ranges_table_in_use)
11821 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
11823 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11824 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11825 debug_line_section_label);
11827 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11828 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
11830 /* Output all of the compilation units. We put the main one last so that
11831 the offsets are available to output_pubnames. */
11832 for (node = limbo_die_list; node; node = node->next)
11833 output_comp_unit (node->die);
11834 output_comp_unit (comp_unit_die);
11836 /* Output the abbreviation table. */
11837 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION);
11838 output_abbrev_section ();
11840 if (pubname_table_in_use)
11842 /* Output public names table. */
11843 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
11844 output_pubnames ();
11847 /* We only put functions in the arange table, so don't write it out if
11848 we don't have any. */
11849 if (fde_table_in_use)
11851 /* Output the address range information. */
11852 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
11856 /* Output location list section if necessary. */
11857 if (have_location_lists)
11859 /* Output the location lists info. */
11860 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION);
11861 output_location_lists (die);
11862 have_location_lists = 0;
11865 /* Output ranges section if necessary. */
11866 if (ranges_table_in_use)
11868 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_RANGES_SECTION);
11872 /* Have to end the primary source file. */
11873 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11875 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11876 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11879 #endif /* DWARF2_DEBUGGING_INFO */