1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Emit .debug_line header even when there are no functions, since
27 the file numbers are used by .debug_info. Alternately, leave
28 out locations for types and decls.
29 Avoid talking about ctors and op= for PODs.
30 Factor out common prologue sequences into multiple CIEs. */
32 /* The first part of this file deals with the DWARF 2 frame unwind
33 information, which is also used by the GCC efficient exception handling
34 mechanism. The second part, controlled only by an #ifdef
35 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
43 #include "hard-reg-set.h"
45 #include "insn-config.h"
52 #include "dwarf2out.h"
53 #include "dwarf2asm.h"
59 #include "diagnostic.h"
62 /* DWARF2 Abbreviation Glossary:
63 CFA = Canonical Frame Address
64 a fixed address on the stack which identifies a call frame.
65 We define it to be the value of SP just before the call insn.
66 The CFA register and offset, which may change during the course
67 of the function, are used to calculate its value at runtime.
68 CFI = Call Frame Instruction
69 an instruction for the DWARF2 abstract machine
70 CIE = Common Information Entry
71 information describing information common to one or more FDEs
72 DIE = Debugging Information Entry
73 FDE = Frame Description Entry
74 information describing the stack call frame, in particular,
75 how to restore registers
77 DW_CFA_... = DWARF2 CFA call frame instruction
78 DW_TAG_... = DWARF2 DIE tag */
80 /* Decide whether we want to emit frame unwind information for the current
86 return (write_symbols == DWARF2_DEBUG
87 #ifdef DWARF2_FRAME_INFO
90 #ifdef DWARF2_UNWIND_INFO
92 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
97 /* The number of the current function definition for which debugging
98 information is being generated. These numbers range from 1 up to the
99 maximum number of function definitions contained within the current
100 compilation unit. These numbers are used to create unique label id's
101 unique to each function definition. */
102 unsigned current_funcdef_number = 0;
104 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
106 /* How to start an assembler comment. */
107 #ifndef ASM_COMMENT_START
108 #define ASM_COMMENT_START ";#"
111 typedef struct dw_cfi_struct *dw_cfi_ref;
112 typedef struct dw_fde_struct *dw_fde_ref;
113 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
115 /* Call frames are described using a sequence of Call Frame
116 Information instructions. The register number, offset
117 and address fields are provided as possible operands;
118 their use is selected by the opcode field. */
120 typedef union dw_cfi_oprnd_struct
122 unsigned long dw_cfi_reg_num;
123 long int dw_cfi_offset;
124 const char *dw_cfi_addr;
125 struct dw_loc_descr_struct *dw_cfi_loc;
129 typedef struct dw_cfi_struct
131 dw_cfi_ref dw_cfi_next;
132 enum dwarf_call_frame_info dw_cfi_opc;
133 dw_cfi_oprnd dw_cfi_oprnd1;
134 dw_cfi_oprnd dw_cfi_oprnd2;
138 /* This is how we define the location of the CFA. We use to handle it
139 as REG + OFFSET all the time, but now it can be more complex.
140 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
141 Instead of passing around REG and OFFSET, we pass a copy
142 of this structure. */
143 typedef struct cfa_loc
148 int indirect; /* 1 if CFA is accessed via a dereference. */
151 /* All call frame descriptions (FDE's) in the GCC generated DWARF
152 refer to a single Common Information Entry (CIE), defined at
153 the beginning of the .debug_frame section. This used of a single
154 CIE obviates the need to keep track of multiple CIE's
155 in the DWARF generation routines below. */
157 typedef struct dw_fde_struct
159 const char *dw_fde_begin;
160 const char *dw_fde_current_label;
161 const char *dw_fde_end;
162 dw_cfi_ref dw_fde_cfi;
163 unsigned funcdef_number;
164 unsigned nothrow : 1;
165 unsigned uses_eh_lsda : 1;
169 /* Maximum size (in bytes) of an artificially generated label. */
170 #define MAX_ARTIFICIAL_LABEL_BYTES 30
172 /* The size of the target's pointer type. */
174 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
177 /* The size of addresses as they appear in the Dwarf 2 data.
178 Some architectures use word addresses to refer to code locations,
179 but Dwarf 2 info always uses byte addresses. On such machines,
180 Dwarf 2 addresses need to be larger than the architecture's
182 #ifndef DWARF2_ADDR_SIZE
183 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
186 /* The size in bytes of a DWARF field indicating an offset or length
187 relative to a debug info section, specified to be 4 bytes in the
188 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
191 #ifndef DWARF_OFFSET_SIZE
192 #define DWARF_OFFSET_SIZE 4
195 #define DWARF_VERSION 2
197 /* Round SIZE up to the nearest BOUNDARY. */
198 #define DWARF_ROUND(SIZE,BOUNDARY) \
199 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
201 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
202 #ifndef DWARF_CIE_DATA_ALIGNMENT
203 #ifdef STACK_GROWS_DOWNWARD
204 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
206 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
208 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
210 /* A pointer to the base of a table that contains frame description
211 information for each routine. */
212 static dw_fde_ref fde_table;
214 /* Number of elements currently allocated for fde_table. */
215 static unsigned fde_table_allocated;
217 /* Number of elements in fde_table currently in use. */
218 static unsigned fde_table_in_use;
220 /* Size (in elements) of increments by which we may expand the
222 #define FDE_TABLE_INCREMENT 256
224 /* A list of call frame insns for the CIE. */
225 static dw_cfi_ref cie_cfi_head;
227 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
228 attribute that accelerates the lookup of the FDE associated
229 with the subprogram. This variable holds the table index of the FDE
230 associated with the current function (body) definition. */
231 static unsigned current_funcdef_fde;
233 /* Forward declarations for functions defined in this file. */
235 static void dwarf2out_init PARAMS ((FILE *, const char *));
236 static void dwarf2out_finish PARAMS ((FILE *, const char *));
237 static char *stripattributes PARAMS ((const char *));
238 static const char *dwarf_cfi_name PARAMS ((unsigned));
239 static dw_cfi_ref new_cfi PARAMS ((void));
240 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
241 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
242 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
243 static void lookup_cfa PARAMS ((dw_cfa_location *));
244 static void reg_save PARAMS ((const char *, unsigned,
246 static void initial_return_save PARAMS ((rtx));
247 static long stack_adjust_offset PARAMS ((rtx));
248 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
249 static void output_call_frame_info PARAMS ((int));
250 static void dwarf2out_stack_adjust PARAMS ((rtx));
251 static void queue_reg_save PARAMS ((const char *, rtx, long));
252 static void flush_queued_reg_saves PARAMS ((void));
253 static bool clobbers_queued_reg_save PARAMS ((rtx));
254 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
256 /* Support for complex CFA locations. */
257 static void output_cfa_loc PARAMS ((dw_cfi_ref));
258 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
259 struct dw_loc_descr_struct *));
260 static struct dw_loc_descr_struct *build_cfa_loc
261 PARAMS ((dw_cfa_location *));
262 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
264 /* How to start an assembler comment. */
265 #ifndef ASM_COMMENT_START
266 #define ASM_COMMENT_START ";#"
269 /* Data and reference forms for relocatable data. */
270 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
271 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
273 /* Pseudo-op for defining a new section. */
274 #ifndef SECTION_ASM_OP
275 #define SECTION_ASM_OP "\t.section\t"
278 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
279 print the SECTION_ASM_OP and the section name. The default here works for
280 almost all svr4 assemblers, except for the sparc, where the section name
281 must be enclosed in double quotes. (See sparcv4.h). */
282 #ifndef SECTION_FORMAT
283 #ifdef PUSHSECTION_FORMAT
284 #define SECTION_FORMAT PUSHSECTION_FORMAT
286 #define SECTION_FORMAT "%s%s\n"
290 #ifndef DEBUG_FRAME_SECTION
291 #define DEBUG_FRAME_SECTION ".debug_frame"
294 #ifndef FUNC_BEGIN_LABEL
295 #define FUNC_BEGIN_LABEL "LFB"
297 #ifndef FUNC_END_LABEL
298 #define FUNC_END_LABEL "LFE"
300 #define CIE_AFTER_SIZE_LABEL "LSCIE"
301 #define CIE_END_LABEL "LECIE"
302 #define CIE_LENGTH_LABEL "LLCIE"
303 #define FDE_LABEL "LSFDE"
304 #define FDE_AFTER_SIZE_LABEL "LASFDE"
305 #define FDE_END_LABEL "LEFDE"
306 #define FDE_LENGTH_LABEL "LLFDE"
307 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
308 #define LINE_NUMBER_END_LABEL "LELT"
309 #define LN_PROLOG_AS_LABEL "LASLTP"
310 #define LN_PROLOG_END_LABEL "LELTP"
311 #define DIE_LABEL_PREFIX "DW"
313 /* Definitions of defaults for various types of primitive assembly language
314 output operations. These may be overridden from within the tm.h file,
315 but typically, that is unnecessary. */
317 #ifndef ASM_OUTPUT_SECTION
318 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
319 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
323 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
324 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
326 fprintf (FILE, "%s", SET_ASM_OP); \
327 assemble_name (FILE, SY); \
329 assemble_name (FILE, HI); \
331 assemble_name (FILE, LO); \
334 #endif /* SET_ASM_OP */
336 /* The DWARF 2 CFA column which tracks the return address. Normally this
337 is the column for PC, or the first column after all of the hard
339 #ifndef DWARF_FRAME_RETURN_COLUMN
341 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
343 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
347 /* The mapping from gcc register number to DWARF 2 CFA column number. By
348 default, we just provide columns for all registers. */
349 #ifndef DWARF_FRAME_REGNUM
350 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
353 /* Hook used by __throw. */
356 expand_builtin_dwarf_fp_regnum ()
358 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
361 /* The offset from the incoming value of %sp to the top of the stack frame
362 for the current function. */
363 #ifndef INCOMING_FRAME_SP_OFFSET
364 #define INCOMING_FRAME_SP_OFFSET 0
367 /* The target debug structure. */
369 struct gcc_debug_hooks dwarf2_debug_hooks
370 = {dwarf2out_init, dwarf2out_finish
373 /* Return a pointer to a copy of the section string name S with all
374 attributes stripped off, and an asterisk prepended (for assemble_name). */
380 char *stripped = xmalloc (strlen (s) + 2);
385 while (*s && *s != ',')
392 /* Generate code to initialize the register size table. */
395 expand_builtin_init_dwarf_reg_sizes (address)
399 enum machine_mode mode = TYPE_MODE (char_type_node);
400 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
401 rtx mem = gen_rtx_MEM (mode, addr);
403 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
405 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
406 int size = GET_MODE_SIZE (reg_raw_mode[i]);
411 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
415 /* Convert a DWARF call frame info. operation to its string name */
418 dwarf_cfi_name (cfi_opc)
419 register unsigned cfi_opc;
423 case DW_CFA_advance_loc:
424 return "DW_CFA_advance_loc";
426 return "DW_CFA_offset";
428 return "DW_CFA_restore";
432 return "DW_CFA_set_loc";
433 case DW_CFA_advance_loc1:
434 return "DW_CFA_advance_loc1";
435 case DW_CFA_advance_loc2:
436 return "DW_CFA_advance_loc2";
437 case DW_CFA_advance_loc4:
438 return "DW_CFA_advance_loc4";
439 case DW_CFA_offset_extended:
440 return "DW_CFA_offset_extended";
441 case DW_CFA_restore_extended:
442 return "DW_CFA_restore_extended";
443 case DW_CFA_undefined:
444 return "DW_CFA_undefined";
445 case DW_CFA_same_value:
446 return "DW_CFA_same_value";
447 case DW_CFA_register:
448 return "DW_CFA_register";
449 case DW_CFA_remember_state:
450 return "DW_CFA_remember_state";
451 case DW_CFA_restore_state:
452 return "DW_CFA_restore_state";
454 return "DW_CFA_def_cfa";
455 case DW_CFA_def_cfa_register:
456 return "DW_CFA_def_cfa_register";
457 case DW_CFA_def_cfa_offset:
458 return "DW_CFA_def_cfa_offset";
459 case DW_CFA_def_cfa_expression:
460 return "DW_CFA_def_cfa_expression";
462 /* SGI/MIPS specific */
463 case DW_CFA_MIPS_advance_loc8:
464 return "DW_CFA_MIPS_advance_loc8";
467 case DW_CFA_GNU_window_save:
468 return "DW_CFA_GNU_window_save";
469 case DW_CFA_GNU_args_size:
470 return "DW_CFA_GNU_args_size";
471 case DW_CFA_GNU_negative_offset_extended:
472 return "DW_CFA_GNU_negative_offset_extended";
475 return "DW_CFA_<unknown>";
479 /* Return a pointer to a newly allocated Call Frame Instruction. */
481 static inline dw_cfi_ref
484 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
486 cfi->dw_cfi_next = NULL;
487 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
488 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
493 /* Add a Call Frame Instruction to list of instructions. */
496 add_cfi (list_head, cfi)
497 register dw_cfi_ref *list_head;
498 register dw_cfi_ref cfi;
500 register dw_cfi_ref *p;
502 /* Find the end of the chain. */
503 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
509 /* Generate a new label for the CFI info to refer to. */
512 dwarf2out_cfi_label ()
514 static char label[20];
515 static unsigned long label_num = 0;
517 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
518 ASM_OUTPUT_LABEL (asm_out_file, label);
523 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
524 or to the CIE if LABEL is NULL. */
527 add_fde_cfi (label, cfi)
528 register const char *label;
529 register dw_cfi_ref cfi;
533 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
536 label = dwarf2out_cfi_label ();
538 if (fde->dw_fde_current_label == NULL
539 || strcmp (label, fde->dw_fde_current_label) != 0)
541 register dw_cfi_ref xcfi;
543 fde->dw_fde_current_label = label = xstrdup (label);
545 /* Set the location counter to the new label. */
547 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
548 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
549 add_cfi (&fde->dw_fde_cfi, xcfi);
552 add_cfi (&fde->dw_fde_cfi, cfi);
556 add_cfi (&cie_cfi_head, cfi);
559 /* Subroutine of lookup_cfa. */
562 lookup_cfa_1 (cfi, loc)
563 register dw_cfi_ref cfi;
564 register dw_cfa_location *loc;
566 switch (cfi->dw_cfi_opc)
568 case DW_CFA_def_cfa_offset:
569 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
571 case DW_CFA_def_cfa_register:
572 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
575 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
576 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
578 case DW_CFA_def_cfa_expression:
579 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
586 /* Find the previous value for the CFA. */
590 register dw_cfa_location *loc;
592 register dw_cfi_ref cfi;
594 loc->reg = (unsigned long) -1;
597 loc->base_offset = 0;
599 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
600 lookup_cfa_1 (cfi, loc);
602 if (fde_table_in_use)
604 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
605 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
606 lookup_cfa_1 (cfi, loc);
610 /* The current rule for calculating the DWARF2 canonical frame address. */
611 static dw_cfa_location cfa;
613 /* The register used for saving registers to the stack, and its offset
615 static dw_cfa_location cfa_store;
617 /* The running total of the size of arguments pushed onto the stack. */
618 static long args_size;
620 /* The last args_size we actually output. */
621 static long old_args_size;
623 /* Entry point to update the canonical frame address (CFA).
624 LABEL is passed to add_fde_cfi. The value of CFA is now to be
625 calculated from REG+OFFSET. */
628 dwarf2out_def_cfa (label, reg, offset)
629 register const char *label;
638 def_cfa_1 (label, &loc);
641 /* This routine does the actual work. The CFA is now calculated from
642 the dw_cfa_location structure. */
644 def_cfa_1 (label, loc_p)
645 register const char *label;
646 dw_cfa_location *loc_p;
648 register dw_cfi_ref cfi;
649 dw_cfa_location old_cfa, loc;
654 if (cfa_store.reg == loc.reg && loc.indirect == 0)
655 cfa_store.offset = loc.offset;
657 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
658 lookup_cfa (&old_cfa);
660 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
661 loc.indirect == old_cfa.indirect)
663 if (loc.indirect == 0
664 || loc.base_offset == old_cfa.base_offset)
665 /* Nothing changed so no need to issue any call frame
672 if (loc.reg == old_cfa.reg && !loc.indirect)
674 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
675 indicating the CFA register did not change but the offset
677 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
678 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
681 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
682 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
685 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
686 indicating the CFA register has changed to <register> but the
687 offset has not changed. */
688 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
689 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
693 else if (loc.indirect == 0)
695 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
696 indicating the CFA register has changed to <register> with
697 the specified offset. */
698 cfi->dw_cfi_opc = DW_CFA_def_cfa;
699 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
700 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
704 /* Construct a DW_CFA_def_cfa_expression instruction to
705 calculate the CFA using a full location expression since no
706 register-offset pair is available. */
707 struct dw_loc_descr_struct *loc_list;
708 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
709 loc_list = build_cfa_loc (&loc);
710 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
713 add_fde_cfi (label, cfi);
716 /* Add the CFI for saving a register. REG is the CFA column number.
717 LABEL is passed to add_fde_cfi.
718 If SREG is -1, the register is saved at OFFSET from the CFA;
719 otherwise it is saved in SREG. */
722 reg_save (label, reg, sreg, offset)
723 register const char *label;
724 register unsigned reg;
725 register unsigned sreg;
726 register long offset;
728 register dw_cfi_ref cfi = new_cfi ();
730 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
732 /* The following comparison is correct. -1 is used to indicate that
733 the value isn't a register number. */
734 if (sreg == (unsigned int) -1)
737 /* The register number won't fit in 6 bits, so we have to use
739 cfi->dw_cfi_opc = DW_CFA_offset_extended;
741 cfi->dw_cfi_opc = DW_CFA_offset;
743 #ifdef ENABLE_CHECKING
745 /* If we get an offset that is not a multiple of
746 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
747 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
749 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
751 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
755 offset /= DWARF_CIE_DATA_ALIGNMENT;
758 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
761 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
763 else if (sreg == reg)
764 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
768 cfi->dw_cfi_opc = DW_CFA_register;
769 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
772 add_fde_cfi (label, cfi);
775 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
776 This CFI tells the unwinder that it needs to restore the window registers
777 from the previous frame's window save area.
779 ??? Perhaps we should note in the CIE where windows are saved (instead of
780 assuming 0(cfa)) and what registers are in the window. */
783 dwarf2out_window_save (label)
784 register const char *label;
786 register dw_cfi_ref cfi = new_cfi ();
787 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
788 add_fde_cfi (label, cfi);
791 /* Add a CFI to update the running total of the size of arguments
792 pushed onto the stack. */
795 dwarf2out_args_size (label, size)
799 register dw_cfi_ref cfi;
801 if (size == old_args_size)
803 old_args_size = size;
806 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
807 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
808 add_fde_cfi (label, cfi);
811 /* Entry point for saving a register to the stack. REG is the GCC register
812 number. LABEL and OFFSET are passed to reg_save. */
815 dwarf2out_reg_save (label, reg, offset)
816 register const char *label;
817 register unsigned reg;
818 register long offset;
820 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
823 /* Entry point for saving the return address in the stack.
824 LABEL and OFFSET are passed to reg_save. */
827 dwarf2out_return_save (label, offset)
828 register const char *label;
829 register long offset;
831 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
834 /* Entry point for saving the return address in a register.
835 LABEL and SREG are passed to reg_save. */
838 dwarf2out_return_reg (label, sreg)
839 register const char *label;
840 register unsigned sreg;
842 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
845 /* Record the initial position of the return address. RTL is
846 INCOMING_RETURN_ADDR_RTX. */
849 initial_return_save (rtl)
852 unsigned int reg = (unsigned int) -1;
855 switch (GET_CODE (rtl))
858 /* RA is in a register. */
859 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
862 /* RA is on the stack. */
864 switch (GET_CODE (rtl))
867 if (REGNO (rtl) != STACK_POINTER_REGNUM)
872 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
874 offset = INTVAL (XEXP (rtl, 1));
877 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
879 offset = -INTVAL (XEXP (rtl, 1));
886 /* The return address is at some offset from any value we can
887 actually load. For instance, on the SPARC it is in %i7+8. Just
888 ignore the offset for now; it doesn't matter for unwinding frames. */
889 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
891 initial_return_save (XEXP (rtl, 0));
897 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
900 /* Given a SET, calculate the amount of stack adjustment it
904 stack_adjust_offset (pattern)
907 rtx src = SET_SRC (pattern);
908 rtx dest = SET_DEST (pattern);
912 if (dest == stack_pointer_rtx)
914 /* (set (reg sp) (plus (reg sp) (const_int))) */
915 code = GET_CODE (src);
916 if (! (code == PLUS || code == MINUS)
917 || XEXP (src, 0) != stack_pointer_rtx
918 || GET_CODE (XEXP (src, 1)) != CONST_INT)
921 offset = INTVAL (XEXP (src, 1));
923 else if (GET_CODE (dest) == MEM)
925 /* (set (mem (pre_dec (reg sp))) (foo)) */
926 src = XEXP (dest, 0);
927 code = GET_CODE (src);
929 if (! (code == PRE_DEC || code == PRE_INC
930 || code == PRE_MODIFY)
931 || XEXP (src, 0) != stack_pointer_rtx)
934 if (code == PRE_MODIFY)
936 rtx val = XEXP (XEXP (src, 1), 1);
937 /* We handle only adjustments by constant amount. */
938 if (GET_CODE (XEXP (src, 1)) != PLUS ||
939 GET_CODE (val) != CONST_INT)
941 offset = -INTVAL (val);
943 else offset = GET_MODE_SIZE (GET_MODE (dest));
948 if (code == PLUS || code == PRE_INC)
954 /* Check INSN to see if it looks like a push or a stack adjustment, and
955 make a note of it if it does. EH uses this information to find out how
956 much extra space it needs to pop off the stack. */
959 dwarf2out_stack_adjust (insn)
965 if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN)
967 /* Extract the size of the args from the CALL rtx itself. */
969 insn = PATTERN (insn);
970 if (GET_CODE (insn) == PARALLEL)
971 insn = XVECEXP (insn, 0, 0);
972 if (GET_CODE (insn) == SET)
973 insn = SET_SRC (insn);
974 if (GET_CODE (insn) != CALL)
976 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
980 /* If only calls can throw, and we have a frame pointer,
981 save up adjustments until we see the CALL_INSN. */
982 else if (! flag_non_call_exceptions
983 && cfa.reg != STACK_POINTER_REGNUM)
986 if (GET_CODE (insn) == BARRIER)
988 /* When we see a BARRIER, we know to reset args_size to 0. Usually
989 the compiler will have already emitted a stack adjustment, but
990 doesn't bother for calls to noreturn functions. */
991 #ifdef STACK_GROWS_DOWNWARD
997 else if (GET_CODE (PATTERN (insn)) == SET)
999 offset = stack_adjust_offset (PATTERN (insn));
1001 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1002 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1004 /* There may be stack adjustments inside compound insns. Search
1009 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1011 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1012 if (GET_CODE (pattern) == SET)
1013 offset += stack_adjust_offset (pattern);
1022 if (cfa.reg == STACK_POINTER_REGNUM)
1023 cfa.offset += offset;
1025 #ifndef STACK_GROWS_DOWNWARD
1028 args_size += offset;
1032 label = dwarf2out_cfi_label ();
1033 def_cfa_1 (label, &cfa);
1034 dwarf2out_args_size (label, args_size);
1037 /* We delay emitting a register save until either (a) we reach the end
1038 of the prologue or (b) the register is clobbered. This clusters
1039 register saves so that there are fewer pc advances. */
1041 struct queued_reg_save
1043 struct queued_reg_save *next;
1048 static struct queued_reg_save *queued_reg_saves;
1049 static const char *last_reg_save_label;
1052 queue_reg_save (label, reg, offset)
1057 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1059 q->next = queued_reg_saves;
1061 q->cfa_offset = offset;
1062 queued_reg_saves = q;
1064 last_reg_save_label = label;
1068 flush_queued_reg_saves ()
1070 struct queued_reg_save *q, *next;
1072 for (q = queued_reg_saves; q ; q = next)
1074 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1079 queued_reg_saves = NULL;
1080 last_reg_save_label = NULL;
1084 clobbers_queued_reg_save (insn)
1087 struct queued_reg_save *q;
1089 for (q = queued_reg_saves; q ; q = q->next)
1090 if (modified_in_p (q->reg, insn))
1097 /* A temporary register holding an integral value used in adjusting SP
1098 or setting up the store_reg. The "offset" field holds the integer
1099 value, not an offset. */
1100 static dw_cfa_location cfa_temp;
1102 /* Record call frame debugging information for an expression EXPR,
1103 which either sets SP or FP (adjusting how we calculate the frame
1104 address) or saves a register to the stack. LABEL indicates the
1107 This function encodes a state machine mapping rtxes to actions on
1108 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1109 users need not read the source code.
1111 The High-Level Picture
1113 Changes in the register we use to calculate the CFA: Currently we
1114 assume that if you copy the CFA register into another register, we
1115 should take the other one as the new CFA register; this seems to
1116 work pretty well. If it's wrong for some target, it's simple
1117 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1119 Changes in the register we use for saving registers to the stack:
1120 This is usually SP, but not always. Again, we deduce that if you
1121 copy SP into another register (and SP is not the CFA register),
1122 then the new register is the one we will be using for register
1123 saves. This also seems to work.
1125 Register saves: There's not much guesswork about this one; if
1126 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1127 register save, and the register used to calculate the destination
1128 had better be the one we think we're using for this purpose.
1130 Except: If the register being saved is the CFA register, and the
1131 offset is non-zero, we are saving the CFA, so we assume we have to
1132 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1133 the intent is to save the value of SP from the previous frame.
1135 Invariants / Summaries of Rules
1137 cfa current rule for calculating the CFA. It usually
1138 consists of a register and an offset.
1139 cfa_store register used by prologue code to save things to the stack
1140 cfa_store.offset is the offset from the value of
1141 cfa_store.reg to the actual CFA
1142 cfa_temp register holding an integral value. cfa_temp.offset
1143 stores the value, which will be used to adjust the
1144 stack pointer. cfa_temp is also used like cfa_store,
1145 to track stores to the stack via fp or a temp reg.
1147 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1148 with cfa.reg as the first operand changes the cfa.reg and its
1149 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1152 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1153 expression yielding a constant. This sets cfa_temp.reg
1154 and cfa_temp.offset.
1156 Rule 5: Create a new register cfa_store used to save items to the
1159 Rules 10-14: Save a register to the stack. Define offset as the
1160 difference of the original location and cfa_store's
1161 location (or cfa_temp's location if cfa_temp is used).
1165 "{a,b}" indicates a choice of a xor b.
1166 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1169 (set <reg1> <reg2>:cfa.reg)
1170 effects: cfa.reg = <reg1>
1171 cfa.offset unchanged
1172 cfa_temp.reg = <reg1>
1173 cfa_temp.offset = cfa.offset
1176 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1177 effects: cfa.reg = sp if fp used
1178 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1179 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1180 if cfa_store.reg==sp
1183 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1184 effects: cfa.reg = fp
1185 cfa_offset += +/- <const_int>
1188 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1189 constraints: <reg1> != fp
1191 effects: cfa.reg = <reg1>
1192 cfa_temp.reg = <reg1>
1193 cfa_temp.offset = cfa.offset
1196 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1197 constraints: <reg1> != fp
1199 effects: cfa_store.reg = <reg1>
1200 cfa_store.offset = cfa.offset - cfa_temp.offset
1203 (set <reg> <const_int>)
1204 effects: cfa_temp.reg = <reg>
1205 cfa_temp.offset = <const_int>
1208 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1209 effects: cfa_temp.reg = <reg1>
1210 cfa_temp.offset |= <const_int>
1213 (set <reg> (high <exp>))
1217 (set <reg> (lo_sum <exp> <const_int>))
1218 effects: cfa_temp.reg = <reg>
1219 cfa_temp.offset = <const_int>
1222 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1223 effects: cfa_store.offset -= <const_int>
1224 cfa.offset = cfa_store.offset if cfa.reg == sp
1226 cfa.base_offset = -cfa_store.offset
1229 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1230 effects: cfa_store.offset += -/+ mode_size(mem)
1231 cfa.offset = cfa_store.offset if cfa.reg == sp
1233 cfa.base_offset = -cfa_store.offset
1236 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>)
1237 effects: cfa.reg = <reg1>
1238 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1241 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1242 effects: cfa.reg = <reg1>
1243 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1246 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1247 effects: cfa.reg = <reg1>
1248 cfa.base_offset = -cfa_temp.offset
1249 cfa_temp.offset -= mode_size(mem) */
1252 dwarf2out_frame_debug_expr (expr, label)
1259 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1260 the PARALLEL independently. The first element is always processed if
1261 it is a SET. This is for backward compatibility. Other elements
1262 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1263 flag is set in them. */
1265 if (GET_CODE (expr) == PARALLEL
1266 || GET_CODE (expr) == SEQUENCE)
1269 int limit = XVECLEN (expr, 0);
1271 for (par_index = 0; par_index < limit; par_index++)
1273 rtx x = XVECEXP (expr, 0, par_index);
1275 if (GET_CODE (x) == SET &&
1276 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1277 dwarf2out_frame_debug_expr (x, label);
1282 if (GET_CODE (expr) != SET)
1285 src = SET_SRC (expr);
1286 dest = SET_DEST (expr);
1288 switch (GET_CODE (dest))
1292 /* Update the CFA rule wrt SP or FP. Make sure src is
1293 relative to the current CFA register. */
1294 switch (GET_CODE (src))
1296 /* Setting FP from SP. */
1298 if (cfa.reg == (unsigned) REGNO (src))
1304 /* We used to require that dest be either SP or FP, but the
1305 ARM copies SP to a temporary register, and from there to
1306 FP. So we just rely on the backends to only set
1307 RTX_FRAME_RELATED_P on appropriate insns. */
1308 cfa.reg = REGNO (dest);
1309 cfa_temp.reg = cfa.reg;
1310 cfa_temp.offset = cfa.offset;
1316 if (dest == stack_pointer_rtx)
1320 switch (GET_CODE (XEXP (src, 1)))
1323 offset = INTVAL (XEXP (src, 1));
1326 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1328 offset = cfa_temp.offset;
1334 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1336 /* Restoring SP from FP in the epilogue. */
1337 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1339 cfa.reg = STACK_POINTER_REGNUM;
1341 else if (GET_CODE (src) == LO_SUM)
1342 /* Assume we've set the source reg of the LO_SUM from sp. */
1344 else if (XEXP (src, 0) != stack_pointer_rtx)
1347 if (GET_CODE (src) != MINUS)
1349 if (cfa.reg == STACK_POINTER_REGNUM)
1350 cfa.offset += offset;
1351 if (cfa_store.reg == STACK_POINTER_REGNUM)
1352 cfa_store.offset += offset;
1354 else if (dest == hard_frame_pointer_rtx)
1357 /* Either setting the FP from an offset of the SP,
1358 or adjusting the FP */
1359 if (! frame_pointer_needed)
1362 if (GET_CODE (XEXP (src, 0)) == REG
1363 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1364 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1366 offset = INTVAL (XEXP (src, 1));
1367 if (GET_CODE (src) != MINUS)
1369 cfa.offset += offset;
1370 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1377 if (GET_CODE (src) == MINUS)
1381 if (GET_CODE (XEXP (src, 0)) == REG
1382 && REGNO (XEXP (src, 0)) == cfa.reg
1383 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1385 /* Setting a temporary CFA register that will be copied
1386 into the FP later on. */
1387 offset = - INTVAL (XEXP (src, 1));
1388 cfa.offset += offset;
1389 cfa.reg = REGNO (dest);
1390 /* Or used to save regs to the stack. */
1391 cfa_temp.reg = cfa.reg;
1392 cfa_temp.offset = cfa.offset;
1395 else if (GET_CODE (XEXP (src, 0)) == REG
1396 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1397 && XEXP (src, 1) == stack_pointer_rtx)
1399 /* Setting a scratch register that we will use instead
1400 of SP for saving registers to the stack. */
1401 if (cfa.reg != STACK_POINTER_REGNUM)
1403 cfa_store.reg = REGNO (dest);
1404 cfa_store.offset = cfa.offset - cfa_temp.offset;
1407 else if (GET_CODE (src) == LO_SUM
1408 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1410 cfa_temp.reg = REGNO (dest);
1411 cfa_temp.offset = INTVAL (XEXP (src, 1));
1420 cfa_temp.reg = REGNO (dest);
1421 cfa_temp.offset = INTVAL (src);
1426 if (GET_CODE (XEXP (src, 0)) != REG
1427 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1428 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1430 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1431 cfa_temp.reg = REGNO (dest);
1432 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1435 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1436 which will fill in all of the bits. */
1444 def_cfa_1 (label, &cfa);
1448 if (GET_CODE (src) != REG)
1451 /* Saving a register to the stack. Make sure dest is relative to the
1453 switch (GET_CODE (XEXP (dest, 0)))
1458 /* We can't handle variable size modifications. */
1459 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1461 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1463 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1464 || cfa_store.reg != STACK_POINTER_REGNUM)
1466 cfa_store.offset += offset;
1467 if (cfa.reg == STACK_POINTER_REGNUM)
1468 cfa.offset = cfa_store.offset;
1470 offset = -cfa_store.offset;
1475 offset = GET_MODE_SIZE (GET_MODE (dest));
1476 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1479 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1480 || cfa_store.reg != STACK_POINTER_REGNUM)
1482 cfa_store.offset += offset;
1483 if (cfa.reg == STACK_POINTER_REGNUM)
1484 cfa.offset = cfa_store.offset;
1486 offset = -cfa_store.offset;
1490 /* With an offset. */
1494 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1496 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1497 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1500 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1501 offset -= cfa_store.offset;
1502 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1503 offset -= cfa_temp.offset;
1509 /* Without an offset. */
1511 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1512 offset = -cfa_store.offset;
1513 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1514 offset = -cfa_temp.offset;
1521 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1523 offset = -cfa_temp.offset;
1524 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1531 if (REGNO (src) != STACK_POINTER_REGNUM
1532 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1533 && (unsigned) REGNO (src) == cfa.reg)
1535 /* We're storing the current CFA reg into the stack. */
1537 if (cfa.offset == 0)
1539 /* If the source register is exactly the CFA, assume
1540 we're saving SP like any other register; this happens
1543 def_cfa_1 (label, &cfa);
1544 queue_reg_save (label, stack_pointer_rtx, offset);
1549 /* Otherwise, we'll need to look in the stack to
1550 calculate the CFA. */
1552 rtx x = XEXP (dest, 0);
1553 if (GET_CODE (x) != REG)
1555 if (GET_CODE (x) != REG)
1557 cfa.reg = (unsigned) REGNO (x);
1558 cfa.base_offset = offset;
1560 def_cfa_1 (label, &cfa);
1565 def_cfa_1 (label, &cfa);
1566 queue_reg_save (label, src, offset);
1574 /* Record call frame debugging information for INSN, which either
1575 sets SP or FP (adjusting how we calculate the frame address) or saves a
1576 register to the stack. If INSN is NULL_RTX, initialize our state. */
1579 dwarf2out_frame_debug (insn)
1585 if (insn == NULL_RTX)
1587 /* Flush any queued register saves. */
1588 flush_queued_reg_saves ();
1590 /* Set up state for generating call frame debug info. */
1592 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1594 cfa.reg = STACK_POINTER_REGNUM;
1597 cfa_temp.offset = 0;
1601 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1602 flush_queued_reg_saves ();
1604 if (! RTX_FRAME_RELATED_P (insn))
1606 if (!ACCUMULATE_OUTGOING_ARGS)
1607 dwarf2out_stack_adjust (insn);
1611 label = dwarf2out_cfi_label ();
1613 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1615 insn = XEXP (src, 0);
1617 insn = PATTERN (insn);
1619 dwarf2out_frame_debug_expr (insn, label);
1622 /* Output a Call Frame Information opcode and its operand(s). */
1625 output_cfi (cfi, fde, for_eh)
1626 register dw_cfi_ref cfi;
1627 register dw_fde_ref fde;
1630 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1632 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1633 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1634 "DW_CFA_advance_loc 0x%lx",
1635 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1637 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1639 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1640 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1641 "DW_CFA_offset, column 0x%lx",
1642 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1643 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1645 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1647 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1648 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1649 "DW_CFA_restore, column 0x%lx",
1650 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1654 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1655 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1657 switch (cfi->dw_cfi_opc)
1659 case DW_CFA_set_loc:
1661 dw2_asm_output_encoded_addr_rtx (
1662 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1663 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1666 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1667 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1669 case DW_CFA_advance_loc1:
1670 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1671 fde->dw_fde_current_label, NULL);
1672 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1674 case DW_CFA_advance_loc2:
1675 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1676 fde->dw_fde_current_label, NULL);
1677 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1679 case DW_CFA_advance_loc4:
1680 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1681 fde->dw_fde_current_label, NULL);
1682 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1684 case DW_CFA_MIPS_advance_loc8:
1685 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1686 fde->dw_fde_current_label, NULL);
1687 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1689 case DW_CFA_offset_extended:
1690 case DW_CFA_GNU_negative_offset_extended:
1691 case DW_CFA_def_cfa:
1692 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1693 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1695 case DW_CFA_restore_extended:
1696 case DW_CFA_undefined:
1697 case DW_CFA_same_value:
1698 case DW_CFA_def_cfa_register:
1699 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1701 case DW_CFA_register:
1702 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1703 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1705 case DW_CFA_def_cfa_offset:
1706 case DW_CFA_GNU_args_size:
1707 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1709 case DW_CFA_GNU_window_save:
1711 case DW_CFA_def_cfa_expression:
1712 output_cfa_loc (cfi);
1720 /* Output the call frame information used to used to record information
1721 that relates to calculating the frame pointer, and records the
1722 location of saved registers. */
1725 output_call_frame_info (for_eh)
1728 register unsigned int i;
1729 register dw_fde_ref fde;
1730 register dw_cfi_ref cfi;
1731 char l1[20], l2[20];
1732 int any_lsda_needed = 0;
1733 char augmentation[6];
1734 int augmentation_size;
1735 int fde_encoding = DW_EH_PE_absptr;
1736 int per_encoding = DW_EH_PE_absptr;
1737 int lsda_encoding = DW_EH_PE_absptr;
1739 /* If we don't have any functions we'll want to unwind out of, don't
1740 emit any EH unwind information. */
1743 int any_eh_needed = 0;
1744 for (i = 0; i < fde_table_in_use; ++i)
1745 if (fde_table[i].uses_eh_lsda)
1746 any_eh_needed = any_lsda_needed = 1;
1747 else if (! fde_table[i].nothrow)
1750 if (! any_eh_needed)
1754 /* We're going to be generating comments, so turn on app. */
1760 #ifdef EH_FRAME_SECTION
1761 EH_FRAME_SECTION ();
1763 tree label = get_file_function_name ('F');
1765 force_data_section ();
1766 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1767 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1768 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1770 assemble_label ("__FRAME_BEGIN__");
1773 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_FRAME_SECTION);
1775 /* Output the CIE. */
1776 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1777 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1778 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1779 "Length of Common Information Entry");
1780 ASM_OUTPUT_LABEL (asm_out_file, l1);
1782 /* Now that the CIE pointer is PC-relative for EH,
1783 use 0 to identify the CIE. */
1784 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1785 (for_eh ? 0 : DW_CIE_ID),
1786 "CIE Identifier Tag");
1788 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1790 augmentation[0] = 0;
1791 augmentation_size = 0;
1797 z Indicates that a uleb128 is present to size the
1798 augmentation section.
1799 L Indicates the encoding (and thus presence) of
1800 an LSDA pointer in the FDE augmentation.
1801 R Indicates a non-default pointer encoding for
1803 P Indicates the presence of an encoding + language
1804 personality routine in the CIE augmentation. */
1806 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1807 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1808 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1810 p = augmentation + 1;
1811 if (eh_personality_libfunc)
1814 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1816 if (any_lsda_needed)
1819 augmentation_size += 1;
1821 if (fde_encoding != DW_EH_PE_absptr)
1824 augmentation_size += 1;
1826 if (p > augmentation + 1)
1828 augmentation[0] = 'z';
1832 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1833 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1835 int offset = ( 4 /* Length */
1837 + 1 /* CIE version */
1838 + strlen (augmentation) + 1 /* Augmentation */
1839 + size_of_uleb128 (1) /* Code alignment */
1840 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1842 + 1 /* Augmentation size */
1843 + 1 /* Personality encoding */ );
1844 int pad = -offset & (PTR_SIZE - 1);
1846 augmentation_size += pad;
1848 /* Augmentations should be small, so there's scarce need to
1849 iterate for a solution. Die if we exceed one uleb128 byte. */
1850 if (size_of_uleb128 (augmentation_size) != 1)
1854 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1856 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1858 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1859 "CIE Data Alignment Factor");
1861 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1863 if (augmentation[0])
1865 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1866 if (eh_personality_libfunc)
1868 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1869 eh_data_format_name (per_encoding));
1870 dw2_asm_output_encoded_addr_rtx (per_encoding,
1871 eh_personality_libfunc, NULL);
1873 if (any_lsda_needed)
1874 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1875 eh_data_format_name (lsda_encoding));
1876 if (fde_encoding != DW_EH_PE_absptr)
1877 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1878 eh_data_format_name (fde_encoding));
1881 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1882 output_cfi (cfi, NULL, for_eh);
1884 /* Pad the CIE out to an address sized boundary. */
1885 ASM_OUTPUT_ALIGN (asm_out_file,
1886 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1887 ASM_OUTPUT_LABEL (asm_out_file, l2);
1889 /* Loop through all of the FDE's. */
1890 for (i = 0; i < fde_table_in_use; ++i)
1892 fde = &fde_table[i];
1894 /* Don't emit EH unwind info for leaf functions that don't need it. */
1895 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1898 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1899 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1900 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1901 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1903 ASM_OUTPUT_LABEL (asm_out_file, l1);
1905 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1906 emits a target dependent sized offset when for_eh is not true.
1907 This inconsistency may confuse gdb. The only case where we need a
1908 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1909 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1910 though in order to be compatible with the dwarf_fde struct in frame.c.
1911 If the for_eh case is changed, then the struct in frame.c has
1912 to be adjusted appropriately. */
1914 dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset");
1916 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
1917 stripattributes (DEBUG_FRAME_SECTION),
1922 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1923 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1924 "FDE initial location");
1925 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1926 fde->dw_fde_end, fde->dw_fde_begin,
1927 "FDE address range");
1931 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1932 "FDE initial location");
1933 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1934 fde->dw_fde_end, fde->dw_fde_begin,
1935 "FDE address range");
1938 if (augmentation[0])
1940 if (any_lsda_needed)
1942 int size = size_of_encoded_value (lsda_encoding);
1944 if (lsda_encoding == DW_EH_PE_aligned)
1946 int offset = ( 4 /* Length */
1947 + 4 /* CIE offset */
1948 + 2 * size_of_encoded_value (fde_encoding)
1949 + 1 /* Augmentation size */ );
1950 int pad = -offset & (PTR_SIZE - 1);
1953 if (size_of_uleb128 (size) != 1)
1957 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1959 if (fde->uses_eh_lsda)
1961 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
1962 fde->funcdef_number);
1963 dw2_asm_output_encoded_addr_rtx (
1964 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
1965 "Language Specific Data Area");
1969 if (lsda_encoding == DW_EH_PE_aligned)
1970 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1971 dw2_asm_output_data (size_of_encoded_value (lsda_encoding),
1972 0, "Language Specific Data Area (none)");
1976 dw2_asm_output_data_uleb128 (0, "Augmentation size");
1979 /* Loop through the Call Frame Instructions associated with
1981 fde->dw_fde_current_label = fde->dw_fde_begin;
1982 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1983 output_cfi (cfi, fde, for_eh);
1985 /* Pad the FDE out to an address sized boundary. */
1986 ASM_OUTPUT_ALIGN (asm_out_file,
1987 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1988 ASM_OUTPUT_LABEL (asm_out_file, l2);
1991 #ifndef EH_FRAME_SECTION
1993 dw2_asm_output_data (4, 0, "End of Table");
1995 #ifdef MIPS_DEBUGGING_INFO
1996 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1997 get a value of 0. Putting .align 0 after the label fixes it. */
1998 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2001 /* Turn off app to make assembly quicker. */
2006 /* Output a marker (i.e. a label) for the beginning of a function, before
2010 dwarf2out_begin_prologue ()
2012 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2013 register dw_fde_ref fde;
2015 current_function_func_begin_label = 0;
2017 #ifdef IA64_UNWIND_INFO
2018 /* ??? current_function_func_begin_label is also used by except.c
2019 for call-site information. We must emit this label if it might
2021 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2022 && ! dwarf2out_do_frame ())
2025 if (! dwarf2out_do_frame ())
2029 ++current_funcdef_number;
2031 function_section (current_function_decl);
2032 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2033 current_funcdef_number);
2034 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2035 current_funcdef_number);
2036 current_function_func_begin_label = get_identifier (label);
2038 #ifdef IA64_UNWIND_INFO
2039 /* We can elide the fde allocation if we're not emitting debug info. */
2040 if (! dwarf2out_do_frame ())
2044 /* Expand the fde table if necessary. */
2045 if (fde_table_in_use == fde_table_allocated)
2047 fde_table_allocated += FDE_TABLE_INCREMENT;
2049 = (dw_fde_ref) xrealloc (fde_table,
2050 fde_table_allocated * sizeof (dw_fde_node));
2053 /* Record the FDE associated with this function. */
2054 current_funcdef_fde = fde_table_in_use;
2056 /* Add the new FDE at the end of the fde_table. */
2057 fde = &fde_table[fde_table_in_use++];
2058 fde->dw_fde_begin = xstrdup (label);
2059 fde->dw_fde_current_label = NULL;
2060 fde->dw_fde_end = NULL;
2061 fde->dw_fde_cfi = NULL;
2062 fde->funcdef_number = current_funcdef_number;
2063 fde->nothrow = current_function_nothrow;
2064 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2066 args_size = old_args_size = 0;
2069 /* Output a marker (i.e. a label) for the absolute end of the generated code
2070 for a function definition. This gets called *after* the epilogue code has
2074 dwarf2out_end_epilogue ()
2077 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2079 /* Output a label to mark the endpoint of the code generated for this
2081 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2082 ASM_OUTPUT_LABEL (asm_out_file, label);
2083 fde = &fde_table[fde_table_in_use - 1];
2084 fde->dw_fde_end = xstrdup (label);
2088 dwarf2out_frame_init ()
2090 /* Allocate the initial hunk of the fde_table. */
2091 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2092 fde_table_allocated = FDE_TABLE_INCREMENT;
2093 fde_table_in_use = 0;
2095 /* Generate the CFA instructions common to all FDE's. Do it now for the
2096 sake of lookup_cfa. */
2098 #ifdef DWARF2_UNWIND_INFO
2099 /* On entry, the Canonical Frame Address is at SP. */
2100 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2101 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2106 dwarf2out_frame_finish ()
2108 /* Output call frame information. */
2109 #ifdef MIPS_DEBUGGING_INFO
2110 if (write_symbols == DWARF2_DEBUG)
2111 output_call_frame_info (0);
2112 if (flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
2113 output_call_frame_info (1);
2115 if (write_symbols == DWARF2_DEBUG
2116 || flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
2117 output_call_frame_info (1);
2121 /* And now, the subset of the debugging information support code necessary
2122 for emitting location expressions. */
2124 typedef struct dw_val_struct *dw_val_ref;
2125 typedef struct die_struct *dw_die_ref;
2126 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2127 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2129 /* Each DIE may have a series of attribute/value pairs. Values
2130 can take on several forms. The forms that are used in this
2131 implementation are listed below. */
2137 dw_val_class_loc_list,
2139 dw_val_class_unsigned_const,
2140 dw_val_class_long_long,
2143 dw_val_class_die_ref,
2144 dw_val_class_fde_ref,
2145 dw_val_class_lbl_id,
2146 dw_val_class_lbl_offset,
2151 /* Describe a double word constant value. */
2152 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2154 typedef struct dw_long_long_struct
2161 /* Describe a floating point constant value. */
2163 typedef struct dw_fp_struct
2170 /* The dw_val_node describes an attribute's value, as it is
2171 represented internally. */
2173 typedef struct dw_val_struct
2175 dw_val_class val_class;
2179 dw_loc_list_ref val_loc_list;
2180 dw_loc_descr_ref val_loc;
2182 long unsigned val_unsigned;
2183 dw_long_long_const val_long_long;
2184 dw_float_const val_float;
2189 unsigned val_fde_index;
2192 unsigned char val_flag;
2198 /* Locations in memory are described using a sequence of stack machine
2201 typedef struct dw_loc_descr_struct
2203 dw_loc_descr_ref dw_loc_next;
2204 enum dwarf_location_atom dw_loc_opc;
2205 dw_val_node dw_loc_oprnd1;
2206 dw_val_node dw_loc_oprnd2;
2211 /* Location lists are ranges + location descriptions for that range,
2212 so you can track variables that are in different places over
2213 their entire life. */
2214 typedef struct dw_loc_list_struct
2216 dw_loc_list_ref dw_loc_next;
2217 const char *begin; /* Label for begin address of range */
2218 const char *end; /* Label for end address of range */
2219 char *ll_symbol; /* Label for beginning of location list. Only on head of list */
2220 const char *section; /* Section this loclist is relative to */
2221 dw_loc_descr_ref expr;
2224 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2225 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2228 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2230 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2231 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2232 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2233 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2235 /* Convert a DWARF stack opcode into its string name. */
2238 dwarf_stack_op_name (op)
2239 register unsigned op;
2244 return "DW_OP_addr";
2246 return "DW_OP_deref";
2248 return "DW_OP_const1u";
2250 return "DW_OP_const1s";
2252 return "DW_OP_const2u";
2254 return "DW_OP_const2s";
2256 return "DW_OP_const4u";
2258 return "DW_OP_const4s";
2260 return "DW_OP_const8u";
2262 return "DW_OP_const8s";
2264 return "DW_OP_constu";
2266 return "DW_OP_consts";
2270 return "DW_OP_drop";
2272 return "DW_OP_over";
2274 return "DW_OP_pick";
2276 return "DW_OP_swap";
2280 return "DW_OP_xderef";
2288 return "DW_OP_minus";
2300 return "DW_OP_plus";
2301 case DW_OP_plus_uconst:
2302 return "DW_OP_plus_uconst";
2308 return "DW_OP_shra";
2326 return "DW_OP_skip";
2328 return "DW_OP_lit0";
2330 return "DW_OP_lit1";
2332 return "DW_OP_lit2";
2334 return "DW_OP_lit3";
2336 return "DW_OP_lit4";
2338 return "DW_OP_lit5";
2340 return "DW_OP_lit6";
2342 return "DW_OP_lit7";
2344 return "DW_OP_lit8";
2346 return "DW_OP_lit9";
2348 return "DW_OP_lit10";
2350 return "DW_OP_lit11";
2352 return "DW_OP_lit12";
2354 return "DW_OP_lit13";
2356 return "DW_OP_lit14";
2358 return "DW_OP_lit15";
2360 return "DW_OP_lit16";
2362 return "DW_OP_lit17";
2364 return "DW_OP_lit18";
2366 return "DW_OP_lit19";
2368 return "DW_OP_lit20";
2370 return "DW_OP_lit21";
2372 return "DW_OP_lit22";
2374 return "DW_OP_lit23";
2376 return "DW_OP_lit24";
2378 return "DW_OP_lit25";
2380 return "DW_OP_lit26";
2382 return "DW_OP_lit27";
2384 return "DW_OP_lit28";
2386 return "DW_OP_lit29";
2388 return "DW_OP_lit30";
2390 return "DW_OP_lit31";
2392 return "DW_OP_reg0";
2394 return "DW_OP_reg1";
2396 return "DW_OP_reg2";
2398 return "DW_OP_reg3";
2400 return "DW_OP_reg4";
2402 return "DW_OP_reg5";
2404 return "DW_OP_reg6";
2406 return "DW_OP_reg7";
2408 return "DW_OP_reg8";
2410 return "DW_OP_reg9";
2412 return "DW_OP_reg10";
2414 return "DW_OP_reg11";
2416 return "DW_OP_reg12";
2418 return "DW_OP_reg13";
2420 return "DW_OP_reg14";
2422 return "DW_OP_reg15";
2424 return "DW_OP_reg16";
2426 return "DW_OP_reg17";
2428 return "DW_OP_reg18";
2430 return "DW_OP_reg19";
2432 return "DW_OP_reg20";
2434 return "DW_OP_reg21";
2436 return "DW_OP_reg22";
2438 return "DW_OP_reg23";
2440 return "DW_OP_reg24";
2442 return "DW_OP_reg25";
2444 return "DW_OP_reg26";
2446 return "DW_OP_reg27";
2448 return "DW_OP_reg28";
2450 return "DW_OP_reg29";
2452 return "DW_OP_reg30";
2454 return "DW_OP_reg31";
2456 return "DW_OP_breg0";
2458 return "DW_OP_breg1";
2460 return "DW_OP_breg2";
2462 return "DW_OP_breg3";
2464 return "DW_OP_breg4";
2466 return "DW_OP_breg5";
2468 return "DW_OP_breg6";
2470 return "DW_OP_breg7";
2472 return "DW_OP_breg8";
2474 return "DW_OP_breg9";
2476 return "DW_OP_breg10";
2478 return "DW_OP_breg11";
2480 return "DW_OP_breg12";
2482 return "DW_OP_breg13";
2484 return "DW_OP_breg14";
2486 return "DW_OP_breg15";
2488 return "DW_OP_breg16";
2490 return "DW_OP_breg17";
2492 return "DW_OP_breg18";
2494 return "DW_OP_breg19";
2496 return "DW_OP_breg20";
2498 return "DW_OP_breg21";
2500 return "DW_OP_breg22";
2502 return "DW_OP_breg23";
2504 return "DW_OP_breg24";
2506 return "DW_OP_breg25";
2508 return "DW_OP_breg26";
2510 return "DW_OP_breg27";
2512 return "DW_OP_breg28";
2514 return "DW_OP_breg29";
2516 return "DW_OP_breg30";
2518 return "DW_OP_breg31";
2520 return "DW_OP_regx";
2522 return "DW_OP_fbreg";
2524 return "DW_OP_bregx";
2526 return "DW_OP_piece";
2527 case DW_OP_deref_size:
2528 return "DW_OP_deref_size";
2529 case DW_OP_xderef_size:
2530 return "DW_OP_xderef_size";
2534 return "OP_<unknown>";
2538 /* Return a pointer to a newly allocated location description. Location
2539 descriptions are simple expression terms that can be strung
2540 together to form more complicated location (address) descriptions. */
2542 static inline dw_loc_descr_ref
2543 new_loc_descr (op, oprnd1, oprnd2)
2544 register enum dwarf_location_atom op;
2545 register unsigned long oprnd1;
2546 register unsigned long oprnd2;
2548 /* Use xcalloc here so we clear out all of the long_long constant in
2550 register dw_loc_descr_ref descr
2551 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2553 descr->dw_loc_opc = op;
2554 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2555 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2556 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2557 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2563 /* Add a location description term to a location description expression. */
2566 add_loc_descr (list_head, descr)
2567 register dw_loc_descr_ref *list_head;
2568 register dw_loc_descr_ref descr;
2570 register dw_loc_descr_ref *d;
2572 /* Find the end of the chain. */
2573 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2579 /* Return the size of a location descriptor. */
2581 static unsigned long
2582 size_of_loc_descr (loc)
2583 register dw_loc_descr_ref loc;
2585 register unsigned long size = 1;
2587 switch (loc->dw_loc_opc)
2590 size += DWARF2_ADDR_SIZE;
2609 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2612 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2617 case DW_OP_plus_uconst:
2618 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2656 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2659 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2662 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2665 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2666 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2669 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2671 case DW_OP_deref_size:
2672 case DW_OP_xderef_size:
2682 /* Return the size of a series of location descriptors. */
2684 static unsigned long
2686 register dw_loc_descr_ref loc;
2688 register unsigned long size = 0;
2690 for (; loc != NULL; loc = loc->dw_loc_next)
2692 loc->dw_loc_addr = size;
2693 size += size_of_loc_descr (loc);
2699 /* Output location description stack opcode's operands (if any). */
2702 output_loc_operands (loc)
2703 register dw_loc_descr_ref loc;
2705 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2706 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2708 switch (loc->dw_loc_opc)
2710 #ifdef DWARF2_DEBUGGING_INFO
2712 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2716 dw2_asm_output_data (2, val1->v.val_int, NULL);
2720 dw2_asm_output_data (4, val1->v.val_int, NULL);
2724 if (HOST_BITS_PER_LONG < 64)
2726 dw2_asm_output_data (8, val1->v.val_int, NULL);
2733 if (val1->val_class == dw_val_class_loc)
2734 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2738 dw2_asm_output_data (2, offset, NULL);
2751 /* We currently don't make any attempt to make sure these are
2752 aligned properly like we do for the main unwind info, so
2753 don't support emitting things larger than a byte if we're
2754 only doing unwinding. */
2759 dw2_asm_output_data (1, val1->v.val_int, NULL);
2762 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2765 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2768 dw2_asm_output_data (1, val1->v.val_int, NULL);
2770 case DW_OP_plus_uconst:
2771 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2805 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2808 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2811 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2814 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2815 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2818 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2820 case DW_OP_deref_size:
2821 case DW_OP_xderef_size:
2822 dw2_asm_output_data (1, val1->v.val_int, NULL);
2825 /* Other codes have no operands. */
2830 /* Output a sequence of location operations. */
2833 output_loc_sequence (loc)
2834 dw_loc_descr_ref loc;
2836 for (; loc != NULL; loc = loc->dw_loc_next)
2838 /* Output the opcode. */
2839 dw2_asm_output_data (1, loc->dw_loc_opc,
2840 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2842 /* Output the operand(s) (if any). */
2843 output_loc_operands (loc);
2847 /* This routine will generate the correct assembly data for a location
2848 description based on a cfi entry with a complex address. */
2851 output_cfa_loc (cfi)
2854 dw_loc_descr_ref loc;
2857 /* Output the size of the block. */
2858 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2859 size = size_of_locs (loc);
2860 dw2_asm_output_data_uleb128 (size, NULL);
2862 /* Now output the operations themselves. */
2863 output_loc_sequence (loc);
2866 /* This function builds a dwarf location descriptor seqeunce from
2867 a dw_cfa_location. */
2869 static struct dw_loc_descr_struct *
2871 dw_cfa_location *cfa;
2873 struct dw_loc_descr_struct *head, *tmp;
2875 if (cfa->indirect == 0)
2878 if (cfa->base_offset)
2881 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2883 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2885 else if (cfa->reg <= 31)
2886 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2888 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2889 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2890 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2891 add_loc_descr (&head, tmp);
2892 if (cfa->offset != 0)
2894 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2895 add_loc_descr (&head, tmp);
2900 /* This function fills in aa dw_cfa_location structure from a
2901 dwarf location descriptor sequence. */
2904 get_cfa_from_loc_descr (cfa, loc)
2905 dw_cfa_location *cfa;
2906 struct dw_loc_descr_struct *loc;
2908 struct dw_loc_descr_struct *ptr;
2910 cfa->base_offset = 0;
2914 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2916 enum dwarf_location_atom op = ptr->dw_loc_opc;
2951 cfa->reg = op - DW_OP_reg0;
2954 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2988 cfa->reg = op - DW_OP_breg0;
2989 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2992 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2993 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2998 case DW_OP_plus_uconst:
2999 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3002 internal_error ("DW_LOC_OP %s not implememnted\n",
3003 dwarf_stack_op_name (ptr->dw_loc_opc));
3007 #endif /* .debug_frame support */
3009 /* And now, the support for symbolic debugging information. */
3010 #ifdef DWARF2_DEBUGGING_INFO
3012 /* NOTE: In the comments in this file, many references are made to
3013 "Debugging Information Entries". This term is abbreviated as `DIE'
3014 throughout the remainder of this file. */
3016 /* An internal representation of the DWARF output is built, and then
3017 walked to generate the DWARF debugging info. The walk of the internal
3018 representation is done after the entire program has been compiled.
3019 The types below are used to describe the internal representation. */
3021 /* Various DIE's use offsets relative to the beginning of the
3022 .debug_info section to refer to each other. */
3024 typedef long int dw_offset;
3026 /* Define typedefs here to avoid circular dependencies. */
3028 typedef struct dw_attr_struct *dw_attr_ref;
3029 typedef struct dw_line_info_struct *dw_line_info_ref;
3030 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3031 typedef struct pubname_struct *pubname_ref;
3032 typedef dw_die_ref *arange_ref;
3034 /* Each entry in the line_info_table maintains the file and
3035 line number associated with the label generated for that
3036 entry. The label gives the PC value associated with
3037 the line number entry. */
3039 typedef struct dw_line_info_struct
3041 unsigned long dw_file_num;
3042 unsigned long dw_line_num;
3046 /* Line information for functions in separate sections; each one gets its
3048 typedef struct dw_separate_line_info_struct
3050 unsigned long dw_file_num;
3051 unsigned long dw_line_num;
3052 unsigned long function;
3054 dw_separate_line_info_entry;
3056 /* Each DIE attribute has a field specifying the attribute kind,
3057 a link to the next attribute in the chain, and an attribute value.
3058 Attributes are typically linked below the DIE they modify. */
3060 typedef struct dw_attr_struct
3062 enum dwarf_attribute dw_attr;
3063 dw_attr_ref dw_attr_next;
3064 dw_val_node dw_attr_val;
3068 /* The Debugging Information Entry (DIE) structure */
3070 typedef struct die_struct
3072 enum dwarf_tag die_tag;
3074 dw_attr_ref die_attr;
3075 dw_die_ref die_parent;
3076 dw_die_ref die_child;
3078 dw_offset die_offset;
3079 unsigned long die_abbrev;
3084 /* The pubname structure */
3086 typedef struct pubname_struct
3093 /* The limbo die list structure. */
3094 typedef struct limbo_die_struct
3097 struct limbo_die_struct *next;
3101 /* How to start an assembler comment. */
3102 #ifndef ASM_COMMENT_START
3103 #define ASM_COMMENT_START ";#"
3106 /* Define a macro which returns non-zero for a TYPE_DECL which was
3107 implicitly generated for a tagged type.
3109 Note that unlike the gcc front end (which generates a NULL named
3110 TYPE_DECL node for each complete tagged type, each array type, and
3111 each function type node created) the g++ front end generates a
3112 _named_ TYPE_DECL node for each tagged type node created.
3113 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3114 generate a DW_TAG_typedef DIE for them. */
3116 #define TYPE_DECL_IS_STUB(decl) \
3117 (DECL_NAME (decl) == NULL_TREE \
3118 || (DECL_ARTIFICIAL (decl) \
3119 && is_tagged_type (TREE_TYPE (decl)) \
3120 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3121 /* This is necessary for stub decls that \
3122 appear in nested inline functions. */ \
3123 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3124 && (decl_ultimate_origin (decl) \
3125 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3127 /* Information concerning the compilation unit's programming
3128 language, and compiler version. */
3130 extern int flag_traditional;
3132 /* Fixed size portion of the DWARF compilation unit header. */
3133 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3135 /* Fixed size portion of debugging line information prolog. */
3136 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3138 /* Fixed size portion of public names info. */
3139 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3141 /* Fixed size portion of the address range info. */
3142 #define DWARF_ARANGES_HEADER_SIZE \
3143 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3144 - DWARF_OFFSET_SIZE)
3146 /* Size of padding portion in the address range info. It must be
3147 aligned to twice the pointer size. */
3148 #define DWARF_ARANGES_PAD_SIZE \
3149 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3150 - (2 * DWARF_OFFSET_SIZE + 4))
3152 /* Use assembler line directives if available. */
3153 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3154 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3155 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3157 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3161 /* Define the architecture-dependent minimum instruction length (in bytes).
3162 In this implementation of DWARF, this field is used for information
3163 purposes only. Since GCC generates assembly language, we have
3164 no a priori knowledge of how many instruction bytes are generated
3165 for each source line, and therefore can use only the DW_LNE_set_address
3166 and DW_LNS_fixed_advance_pc line information commands. */
3168 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3169 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3172 /* Minimum line offset in a special line info. opcode.
3173 This value was chosen to give a reasonable range of values. */
3174 #define DWARF_LINE_BASE -10
3176 /* First special line opcde - leave room for the standard opcodes. */
3177 #define DWARF_LINE_OPCODE_BASE 10
3179 /* Range of line offsets in a special line info. opcode. */
3180 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3182 /* Flag that indicates the initial value of the is_stmt_start flag.
3183 In the present implementation, we do not mark any lines as
3184 the beginning of a source statement, because that information
3185 is not made available by the GCC front-end. */
3186 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3188 /* This location is used by calc_die_sizes() to keep track
3189 the offset of each DIE within the .debug_info section. */
3190 static unsigned long next_die_offset;
3192 /* Record the root of the DIE's built for the current compilation unit. */
3193 static dw_die_ref comp_unit_die;
3195 /* A list of DIEs with a NULL parent waiting to be relocated. */
3196 static limbo_die_node *limbo_die_list = 0;
3198 /* Structure used by lookup_filename to manage sets of filenames. */
3204 unsigned last_lookup_index;
3207 /* Size (in elements) of increments by which we may expand the filename
3209 #define FILE_TABLE_INCREMENT 64
3211 /* Filenames referenced by this compilation unit. */
3212 static struct file_table file_table;
3214 /* Local pointer to the name of the main input file. Initialized in
3216 static const char *primary_filename;
3218 /* A pointer to the base of a table of references to DIE's that describe
3219 declarations. The table is indexed by DECL_UID() which is a unique
3220 number identifying each decl. */
3221 static dw_die_ref *decl_die_table;
3223 /* Number of elements currently allocated for the decl_die_table. */
3224 static unsigned decl_die_table_allocated;
3226 /* Number of elements in decl_die_table currently in use. */
3227 static unsigned decl_die_table_in_use;
3229 /* Size (in elements) of increments by which we may expand the
3231 #define DECL_DIE_TABLE_INCREMENT 256
3233 /* A pointer to the base of a table of references to declaration
3234 scopes. This table is a display which tracks the nesting
3235 of declaration scopes at the current scope and containing
3236 scopes. This table is used to find the proper place to
3237 define type declaration DIE's. */
3238 static tree *decl_scope_table;
3240 /* Number of elements currently allocated for the decl_scope_table. */
3241 static int decl_scope_table_allocated;
3243 /* Current level of nesting of declaration scopes. */
3244 static int decl_scope_depth;
3246 /* Size (in elements) of increments by which we may expand the
3247 decl_scope_table. */
3248 #define DECL_SCOPE_TABLE_INCREMENT 64
3250 /* A pointer to the base of a list of references to DIE's that
3251 are uniquely identified by their tag, presence/absence of
3252 children DIE's, and list of attribute/value pairs. */
3253 static dw_die_ref *abbrev_die_table;
3255 /* Number of elements currently allocated for abbrev_die_table. */
3256 static unsigned abbrev_die_table_allocated;
3258 /* Number of elements in type_die_table currently in use. */
3259 static unsigned abbrev_die_table_in_use;
3261 /* Size (in elements) of increments by which we may expand the
3262 abbrev_die_table. */
3263 #define ABBREV_DIE_TABLE_INCREMENT 256
3265 /* A pointer to the base of a table that contains line information
3266 for each source code line in .text in the compilation unit. */
3267 static dw_line_info_ref line_info_table;
3269 /* Number of elements currently allocated for line_info_table. */
3270 static unsigned line_info_table_allocated;
3272 /* Number of elements in separate_line_info_table currently in use. */
3273 static unsigned separate_line_info_table_in_use;
3275 /* A pointer to the base of a table that contains line information
3276 for each source code line outside of .text in the compilation unit. */
3277 static dw_separate_line_info_ref separate_line_info_table;
3279 /* Number of elements currently allocated for separate_line_info_table. */
3280 static unsigned separate_line_info_table_allocated;
3282 /* Number of elements in line_info_table currently in use. */
3283 static unsigned line_info_table_in_use;
3285 /* Size (in elements) of increments by which we may expand the
3287 #define LINE_INFO_TABLE_INCREMENT 1024
3289 /* A pointer to the base of a table that contains a list of publicly
3290 accessible names. */
3291 static pubname_ref pubname_table;
3293 /* Number of elements currently allocated for pubname_table. */
3294 static unsigned pubname_table_allocated;
3296 /* Number of elements in pubname_table currently in use. */
3297 static unsigned pubname_table_in_use;
3299 /* Size (in elements) of increments by which we may expand the
3301 #define PUBNAME_TABLE_INCREMENT 64
3303 /* A pointer to the base of a table that contains a list of publicly
3304 accessible names. */
3305 static arange_ref arange_table;
3307 /* Number of elements currently allocated for arange_table. */
3308 static unsigned arange_table_allocated;
3310 /* Number of elements in arange_table currently in use. */
3311 static unsigned arange_table_in_use;
3313 /* Size (in elements) of increments by which we may expand the
3315 #define ARANGE_TABLE_INCREMENT 64
3317 /* Whether we have location lists that need outputting */
3318 static unsigned have_location_lists;
3320 /* A pointer to the base of a list of incomplete types which might be
3321 completed at some later time. */
3323 static tree *incomplete_types_list;
3325 /* Number of elements currently allocated for the incomplete_types_list. */
3326 static unsigned incomplete_types_allocated;
3328 /* Number of elements of incomplete_types_list currently in use. */
3329 static unsigned incomplete_types;
3331 /* Size (in elements) of increments by which we may expand the incomplete
3332 types list. Actually, a single hunk of space of this size should
3333 be enough for most typical programs. */
3334 #define INCOMPLETE_TYPES_INCREMENT 64
3336 /* Record whether the function being analyzed contains inlined functions. */
3337 static int current_function_has_inlines;
3338 #if 0 && defined (MIPS_DEBUGGING_INFO)
3339 static int comp_unit_has_inlines;
3342 /* Array of RTXes referenced by the debugging information, which therefore
3343 must be kept around forever. We do this rather than perform GC on
3344 the dwarf info because almost all of the dwarf info lives forever, and
3345 it's easier to support non-GC frontends this way. */
3346 static varray_type used_rtx_varray;
3348 /* Forward declarations for functions defined in this file. */
3350 static int is_pseudo_reg PARAMS ((rtx));
3351 static tree type_main_variant PARAMS ((tree));
3352 static int is_tagged_type PARAMS ((tree));
3353 static const char *dwarf_tag_name PARAMS ((unsigned));
3354 static const char *dwarf_attr_name PARAMS ((unsigned));
3355 static const char *dwarf_form_name PARAMS ((unsigned));
3357 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3359 static tree decl_ultimate_origin PARAMS ((tree));
3360 static tree block_ultimate_origin PARAMS ((tree));
3361 static tree decl_class_context PARAMS ((tree));
3362 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3363 static void add_AT_flag PARAMS ((dw_die_ref,
3364 enum dwarf_attribute,
3366 static void add_AT_int PARAMS ((dw_die_ref,
3367 enum dwarf_attribute, long));
3368 static void add_AT_unsigned PARAMS ((dw_die_ref,
3369 enum dwarf_attribute,
3371 static void add_AT_long_long PARAMS ((dw_die_ref,
3372 enum dwarf_attribute,
3375 static void add_AT_float PARAMS ((dw_die_ref,
3376 enum dwarf_attribute,
3378 static void add_AT_string PARAMS ((dw_die_ref,
3379 enum dwarf_attribute,
3381 static void add_AT_die_ref PARAMS ((dw_die_ref,
3382 enum dwarf_attribute,
3384 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3385 enum dwarf_attribute,
3387 static void add_AT_loc PARAMS ((dw_die_ref,
3388 enum dwarf_attribute,
3390 static void add_AT_loc_list PARAMS ((dw_die_ref,
3391 enum dwarf_attribute,
3393 static void add_AT_addr PARAMS ((dw_die_ref,
3394 enum dwarf_attribute,
3396 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3397 enum dwarf_attribute,
3399 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3400 enum dwarf_attribute,
3402 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3403 enum dwarf_attribute));
3404 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3405 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3406 static const char *get_AT_string PARAMS ((dw_die_ref,
3407 enum dwarf_attribute));
3408 static int get_AT_flag PARAMS ((dw_die_ref,
3409 enum dwarf_attribute));
3410 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3411 enum dwarf_attribute));
3412 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3413 enum dwarf_attribute));
3414 static int is_c_family PARAMS ((void));
3415 static int is_java PARAMS ((void));
3416 static int is_fortran PARAMS ((void));
3417 static void remove_AT PARAMS ((dw_die_ref,
3418 enum dwarf_attribute));
3419 static void remove_children PARAMS ((dw_die_ref));
3420 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3421 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3422 static dw_die_ref lookup_type_die PARAMS ((tree));
3423 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3424 static dw_die_ref lookup_decl_die PARAMS ((tree));
3425 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3426 static void print_spaces PARAMS ((FILE *));
3427 static void print_die PARAMS ((dw_die_ref, FILE *));
3428 static void print_dwarf_line_table PARAMS ((FILE *));
3429 static void reverse_die_lists PARAMS ((dw_die_ref));
3430 static void reverse_all_dies PARAMS ((dw_die_ref));
3431 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3432 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3433 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3434 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3435 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3436 static void compute_section_prefix PARAMS ((dw_die_ref));
3437 static int is_type_die PARAMS ((dw_die_ref));
3438 static int is_comdat_die PARAMS ((dw_die_ref));
3439 static int is_symbol_die PARAMS ((dw_die_ref));
3440 static void assign_symbol_names PARAMS ((dw_die_ref));
3441 static void break_out_includes PARAMS ((dw_die_ref));
3442 static void add_sibling_attributes PARAMS ((dw_die_ref));
3443 static void build_abbrev_table PARAMS ((dw_die_ref));
3444 static void output_location_lists PARAMS ((dw_die_ref));
3445 static unsigned long size_of_string PARAMS ((const char *));
3446 static int constant_size PARAMS ((long unsigned));
3447 static unsigned long size_of_die PARAMS ((dw_die_ref));
3448 static void calc_die_sizes PARAMS ((dw_die_ref));
3449 static void mark_dies PARAMS ((dw_die_ref));
3450 static void unmark_dies PARAMS ((dw_die_ref));
3451 static unsigned long size_of_pubnames PARAMS ((void));
3452 static unsigned long size_of_aranges PARAMS ((void));
3453 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3454 static void output_value_format PARAMS ((dw_attr_ref));
3455 static void output_abbrev_section PARAMS ((void));
3456 static void output_die_symbol PARAMS ((dw_die_ref));
3457 static void output_die PARAMS ((dw_die_ref));
3458 static void output_compilation_unit_header PARAMS ((void));
3459 static void output_comp_unit PARAMS ((dw_die_ref));
3460 static const char *dwarf2_name PARAMS ((tree, int));
3461 static void add_pubname PARAMS ((tree, dw_die_ref));
3462 static void output_pubnames PARAMS ((void));
3463 static void add_arange PARAMS ((tree, dw_die_ref));
3464 static void output_aranges PARAMS ((void));
3465 static void output_line_info PARAMS ((void));
3466 static void output_file_names PARAMS ((void));
3467 static dw_die_ref base_type_die PARAMS ((tree));
3468 static tree root_type PARAMS ((tree));
3469 static int is_base_type PARAMS ((tree));
3470 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3471 static int type_is_enum PARAMS ((tree));
3472 static unsigned int reg_number PARAMS ((rtx));
3473 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3474 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3475 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3476 static int is_based_loc PARAMS ((rtx));
3477 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3478 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3479 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3480 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3481 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3482 static tree field_type PARAMS ((tree));
3483 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3484 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3485 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3486 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3487 static void add_AT_location_description PARAMS ((dw_die_ref,
3488 enum dwarf_attribute, rtx));
3489 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3490 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3491 static rtx rtl_for_decl_location PARAMS ((tree));
3492 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3493 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3494 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3495 static void add_bound_info PARAMS ((dw_die_ref,
3496 enum dwarf_attribute, tree));
3497 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3498 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3499 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3500 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3501 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3502 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3503 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3504 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3505 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3506 static void push_decl_scope PARAMS ((tree));
3507 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3508 static void pop_decl_scope PARAMS ((void));
3509 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3511 static const char *type_tag PARAMS ((tree));
3512 static tree member_declared_type PARAMS ((tree));
3514 static const char *decl_start_label PARAMS ((tree));
3516 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3517 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3519 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3521 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3522 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3523 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3524 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3525 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3526 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3527 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3528 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3529 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3530 static void gen_label_die PARAMS ((tree, dw_die_ref));
3531 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3532 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3533 static void gen_field_die PARAMS ((tree, dw_die_ref));
3534 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3535 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3536 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3537 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3538 static void gen_member_die PARAMS ((tree, dw_die_ref));
3539 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3540 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3541 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3542 static void gen_type_die PARAMS ((tree, dw_die_ref));
3543 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3544 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3545 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3546 static int is_redundant_typedef PARAMS ((tree));
3547 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3548 static unsigned lookup_filename PARAMS ((const char *));
3549 static void init_file_table PARAMS ((void));
3550 static void add_incomplete_type PARAMS ((tree));
3551 static void retry_incomplete_types PARAMS ((void));
3552 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3553 static rtx save_rtx PARAMS ((rtx));
3554 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3555 static int file_info_cmp PARAMS ((const void *, const void *));
3556 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3557 const char *, const char *,
3558 const char *, unsigned));
3559 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3561 const char *, const char *, const char *));
3562 static void output_loc_list PARAMS ((dw_loc_list_ref));
3563 static char *gen_internal_sym PARAMS ((const char *));
3565 /* Section names used to hold DWARF debugging information. */
3566 #ifndef DEBUG_INFO_SECTION
3567 #define DEBUG_INFO_SECTION ".debug_info"
3569 #ifndef DEBUG_ABBREV_SECTION
3570 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3572 #ifndef DEBUG_ARANGES_SECTION
3573 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3575 #ifndef DEBUG_MACINFO_SECTION
3576 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3578 #ifndef DEBUG_LINE_SECTION
3579 #define DEBUG_LINE_SECTION ".debug_line"
3581 #ifndef DEBUG_LOC_SECTION
3582 #define DEBUG_LOC_SECTION ".debug_loc"
3584 #ifndef DEBUG_PUBNAMES_SECTION
3585 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3587 #ifndef DEBUG_STR_SECTION
3588 #define DEBUG_STR_SECTION ".debug_str"
3591 /* Standard ELF section names for compiled code and data. */
3592 #ifndef TEXT_SECTION
3593 #define TEXT_SECTION ".text"
3595 #ifndef DATA_SECTION
3596 #define DATA_SECTION ".data"
3599 #define BSS_SECTION ".bss"
3602 /* Labels we insert at beginning sections we can reference instead of
3603 the section names themselves. */
3605 #ifndef TEXT_SECTION_LABEL
3606 #define TEXT_SECTION_LABEL "Ltext"
3608 #ifndef DEBUG_LINE_SECTION_LABEL
3609 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3611 #ifndef DEBUG_INFO_SECTION_LABEL
3612 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3614 #ifndef DEBUG_ABBREV_SECTION_LABEL
3615 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3617 #ifndef DEBUG_LOC_SECTION_LABEL
3618 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3620 #ifndef DEBUG_MACINFO_SECTION_LABEL
3621 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3623 /* Definitions of defaults for formats and names of various special
3624 (artificial) labels which may be generated within this file (when the -g
3625 options is used and DWARF_DEBUGGING_INFO is in effect.
3626 If necessary, these may be overridden from within the tm.h file, but
3627 typically, overriding these defaults is unnecessary. */
3629 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3630 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3631 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3632 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3633 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3634 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3635 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3636 #ifndef TEXT_END_LABEL
3637 #define TEXT_END_LABEL "Letext"
3639 #ifndef DATA_END_LABEL
3640 #define DATA_END_LABEL "Ledata"
3642 #ifndef BSS_END_LABEL
3643 #define BSS_END_LABEL "Lebss"
3645 #ifndef BLOCK_BEGIN_LABEL
3646 #define BLOCK_BEGIN_LABEL "LBB"
3648 #ifndef BLOCK_END_LABEL
3649 #define BLOCK_END_LABEL "LBE"
3651 #ifndef BODY_BEGIN_LABEL
3652 #define BODY_BEGIN_LABEL "Lbb"
3654 #ifndef BODY_END_LABEL
3655 #define BODY_END_LABEL "Lbe"
3657 #ifndef LINE_CODE_LABEL
3658 #define LINE_CODE_LABEL "LM"
3660 #ifndef SEPARATE_LINE_CODE_LABEL
3661 #define SEPARATE_LINE_CODE_LABEL "LSM"
3664 /* We allow a language front-end to designate a function that is to be
3665 called to "demangle" any name before it it put into a DIE. */
3667 static const char *(*demangle_name_func) PARAMS ((const char *));
3670 dwarf2out_set_demangle_name_func (func)
3671 const char *(*func) PARAMS ((const char *));
3673 demangle_name_func = func;
3676 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3677 that means adding it to used_rtx_varray. If not, that means making
3678 a copy on the permanent_obstack. */
3684 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3689 /* Test if rtl node points to a pseudo register. */
3695 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3696 || (GET_CODE (rtl) == SUBREG
3697 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3700 /* Return a reference to a type, with its const and volatile qualifiers
3704 type_main_variant (type)
3707 type = TYPE_MAIN_VARIANT (type);
3709 /* There really should be only one main variant among any group of variants
3710 of a given type (and all of the MAIN_VARIANT values for all members of
3711 the group should point to that one type) but sometimes the C front-end
3712 messes this up for array types, so we work around that bug here. */
3714 if (TREE_CODE (type) == ARRAY_TYPE)
3715 while (type != TYPE_MAIN_VARIANT (type))
3716 type = TYPE_MAIN_VARIANT (type);
3721 /* Return non-zero if the given type node represents a tagged type. */
3724 is_tagged_type (type)
3727 register enum tree_code code = TREE_CODE (type);
3729 return (code == RECORD_TYPE || code == UNION_TYPE
3730 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3733 /* Convert a DIE tag into its string name. */
3736 dwarf_tag_name (tag)
3737 register unsigned tag;
3741 case DW_TAG_padding:
3742 return "DW_TAG_padding";
3743 case DW_TAG_array_type:
3744 return "DW_TAG_array_type";
3745 case DW_TAG_class_type:
3746 return "DW_TAG_class_type";
3747 case DW_TAG_entry_point:
3748 return "DW_TAG_entry_point";
3749 case DW_TAG_enumeration_type:
3750 return "DW_TAG_enumeration_type";
3751 case DW_TAG_formal_parameter:
3752 return "DW_TAG_formal_parameter";
3753 case DW_TAG_imported_declaration:
3754 return "DW_TAG_imported_declaration";
3756 return "DW_TAG_label";
3757 case DW_TAG_lexical_block:
3758 return "DW_TAG_lexical_block";
3760 return "DW_TAG_member";
3761 case DW_TAG_pointer_type:
3762 return "DW_TAG_pointer_type";
3763 case DW_TAG_reference_type:
3764 return "DW_TAG_reference_type";
3765 case DW_TAG_compile_unit:
3766 return "DW_TAG_compile_unit";
3767 case DW_TAG_string_type:
3768 return "DW_TAG_string_type";
3769 case DW_TAG_structure_type:
3770 return "DW_TAG_structure_type";
3771 case DW_TAG_subroutine_type:
3772 return "DW_TAG_subroutine_type";
3773 case DW_TAG_typedef:
3774 return "DW_TAG_typedef";
3775 case DW_TAG_union_type:
3776 return "DW_TAG_union_type";
3777 case DW_TAG_unspecified_parameters:
3778 return "DW_TAG_unspecified_parameters";
3779 case DW_TAG_variant:
3780 return "DW_TAG_variant";
3781 case DW_TAG_common_block:
3782 return "DW_TAG_common_block";
3783 case DW_TAG_common_inclusion:
3784 return "DW_TAG_common_inclusion";
3785 case DW_TAG_inheritance:
3786 return "DW_TAG_inheritance";
3787 case DW_TAG_inlined_subroutine:
3788 return "DW_TAG_inlined_subroutine";
3790 return "DW_TAG_module";
3791 case DW_TAG_ptr_to_member_type:
3792 return "DW_TAG_ptr_to_member_type";
3793 case DW_TAG_set_type:
3794 return "DW_TAG_set_type";
3795 case DW_TAG_subrange_type:
3796 return "DW_TAG_subrange_type";
3797 case DW_TAG_with_stmt:
3798 return "DW_TAG_with_stmt";
3799 case DW_TAG_access_declaration:
3800 return "DW_TAG_access_declaration";
3801 case DW_TAG_base_type:
3802 return "DW_TAG_base_type";
3803 case DW_TAG_catch_block:
3804 return "DW_TAG_catch_block";
3805 case DW_TAG_const_type:
3806 return "DW_TAG_const_type";
3807 case DW_TAG_constant:
3808 return "DW_TAG_constant";
3809 case DW_TAG_enumerator:
3810 return "DW_TAG_enumerator";
3811 case DW_TAG_file_type:
3812 return "DW_TAG_file_type";
3814 return "DW_TAG_friend";
3815 case DW_TAG_namelist:
3816 return "DW_TAG_namelist";
3817 case DW_TAG_namelist_item:
3818 return "DW_TAG_namelist_item";
3819 case DW_TAG_packed_type:
3820 return "DW_TAG_packed_type";
3821 case DW_TAG_subprogram:
3822 return "DW_TAG_subprogram";
3823 case DW_TAG_template_type_param:
3824 return "DW_TAG_template_type_param";
3825 case DW_TAG_template_value_param:
3826 return "DW_TAG_template_value_param";
3827 case DW_TAG_thrown_type:
3828 return "DW_TAG_thrown_type";
3829 case DW_TAG_try_block:
3830 return "DW_TAG_try_block";
3831 case DW_TAG_variant_part:
3832 return "DW_TAG_variant_part";
3833 case DW_TAG_variable:
3834 return "DW_TAG_variable";
3835 case DW_TAG_volatile_type:
3836 return "DW_TAG_volatile_type";
3837 case DW_TAG_MIPS_loop:
3838 return "DW_TAG_MIPS_loop";
3839 case DW_TAG_format_label:
3840 return "DW_TAG_format_label";
3841 case DW_TAG_function_template:
3842 return "DW_TAG_function_template";
3843 case DW_TAG_class_template:
3844 return "DW_TAG_class_template";
3845 case DW_TAG_GNU_BINCL:
3846 return "DW_TAG_GNU_BINCL";
3847 case DW_TAG_GNU_EINCL:
3848 return "DW_TAG_GNU_EINCL";
3850 return "DW_TAG_<unknown>";
3854 /* Convert a DWARF attribute code into its string name. */
3857 dwarf_attr_name (attr)
3858 register unsigned attr;
3863 return "DW_AT_sibling";
3864 case DW_AT_location:
3865 return "DW_AT_location";
3867 return "DW_AT_name";
3868 case DW_AT_ordering:
3869 return "DW_AT_ordering";
3870 case DW_AT_subscr_data:
3871 return "DW_AT_subscr_data";
3872 case DW_AT_byte_size:
3873 return "DW_AT_byte_size";
3874 case DW_AT_bit_offset:
3875 return "DW_AT_bit_offset";
3876 case DW_AT_bit_size:
3877 return "DW_AT_bit_size";
3878 case DW_AT_element_list:
3879 return "DW_AT_element_list";
3880 case DW_AT_stmt_list:
3881 return "DW_AT_stmt_list";
3883 return "DW_AT_low_pc";
3885 return "DW_AT_high_pc";
3886 case DW_AT_language:
3887 return "DW_AT_language";
3889 return "DW_AT_member";
3891 return "DW_AT_discr";
3892 case DW_AT_discr_value:
3893 return "DW_AT_discr_value";
3894 case DW_AT_visibility:
3895 return "DW_AT_visibility";
3897 return "DW_AT_import";
3898 case DW_AT_string_length:
3899 return "DW_AT_string_length";
3900 case DW_AT_common_reference:
3901 return "DW_AT_common_reference";
3902 case DW_AT_comp_dir:
3903 return "DW_AT_comp_dir";
3904 case DW_AT_const_value:
3905 return "DW_AT_const_value";
3906 case DW_AT_containing_type:
3907 return "DW_AT_containing_type";
3908 case DW_AT_default_value:
3909 return "DW_AT_default_value";
3911 return "DW_AT_inline";
3912 case DW_AT_is_optional:
3913 return "DW_AT_is_optional";
3914 case DW_AT_lower_bound:
3915 return "DW_AT_lower_bound";
3916 case DW_AT_producer:
3917 return "DW_AT_producer";
3918 case DW_AT_prototyped:
3919 return "DW_AT_prototyped";
3920 case DW_AT_return_addr:
3921 return "DW_AT_return_addr";
3922 case DW_AT_start_scope:
3923 return "DW_AT_start_scope";
3924 case DW_AT_stride_size:
3925 return "DW_AT_stride_size";
3926 case DW_AT_upper_bound:
3927 return "DW_AT_upper_bound";
3928 case DW_AT_abstract_origin:
3929 return "DW_AT_abstract_origin";
3930 case DW_AT_accessibility:
3931 return "DW_AT_accessibility";
3932 case DW_AT_address_class:
3933 return "DW_AT_address_class";
3934 case DW_AT_artificial:
3935 return "DW_AT_artificial";
3936 case DW_AT_base_types:
3937 return "DW_AT_base_types";
3938 case DW_AT_calling_convention:
3939 return "DW_AT_calling_convention";
3941 return "DW_AT_count";
3942 case DW_AT_data_member_location:
3943 return "DW_AT_data_member_location";
3944 case DW_AT_decl_column:
3945 return "DW_AT_decl_column";
3946 case DW_AT_decl_file:
3947 return "DW_AT_decl_file";
3948 case DW_AT_decl_line:
3949 return "DW_AT_decl_line";
3950 case DW_AT_declaration:
3951 return "DW_AT_declaration";
3952 case DW_AT_discr_list:
3953 return "DW_AT_discr_list";
3954 case DW_AT_encoding:
3955 return "DW_AT_encoding";
3956 case DW_AT_external:
3957 return "DW_AT_external";
3958 case DW_AT_frame_base:
3959 return "DW_AT_frame_base";
3961 return "DW_AT_friend";
3962 case DW_AT_identifier_case:
3963 return "DW_AT_identifier_case";
3964 case DW_AT_macro_info:
3965 return "DW_AT_macro_info";
3966 case DW_AT_namelist_items:
3967 return "DW_AT_namelist_items";
3968 case DW_AT_priority:
3969 return "DW_AT_priority";
3971 return "DW_AT_segment";
3972 case DW_AT_specification:
3973 return "DW_AT_specification";
3974 case DW_AT_static_link:
3975 return "DW_AT_static_link";
3977 return "DW_AT_type";
3978 case DW_AT_use_location:
3979 return "DW_AT_use_location";
3980 case DW_AT_variable_parameter:
3981 return "DW_AT_variable_parameter";
3982 case DW_AT_virtuality:
3983 return "DW_AT_virtuality";
3984 case DW_AT_vtable_elem_location:
3985 return "DW_AT_vtable_elem_location";
3987 case DW_AT_MIPS_fde:
3988 return "DW_AT_MIPS_fde";
3989 case DW_AT_MIPS_loop_begin:
3990 return "DW_AT_MIPS_loop_begin";
3991 case DW_AT_MIPS_tail_loop_begin:
3992 return "DW_AT_MIPS_tail_loop_begin";
3993 case DW_AT_MIPS_epilog_begin:
3994 return "DW_AT_MIPS_epilog_begin";
3995 case DW_AT_MIPS_loop_unroll_factor:
3996 return "DW_AT_MIPS_loop_unroll_factor";
3997 case DW_AT_MIPS_software_pipeline_depth:
3998 return "DW_AT_MIPS_software_pipeline_depth";
3999 case DW_AT_MIPS_linkage_name:
4000 return "DW_AT_MIPS_linkage_name";
4001 case DW_AT_MIPS_stride:
4002 return "DW_AT_MIPS_stride";
4003 case DW_AT_MIPS_abstract_name:
4004 return "DW_AT_MIPS_abstract_name";
4005 case DW_AT_MIPS_clone_origin:
4006 return "DW_AT_MIPS_clone_origin";
4007 case DW_AT_MIPS_has_inlines:
4008 return "DW_AT_MIPS_has_inlines";
4010 case DW_AT_sf_names:
4011 return "DW_AT_sf_names";
4012 case DW_AT_src_info:
4013 return "DW_AT_src_info";
4014 case DW_AT_mac_info:
4015 return "DW_AT_mac_info";
4016 case DW_AT_src_coords:
4017 return "DW_AT_src_coords";
4018 case DW_AT_body_begin:
4019 return "DW_AT_body_begin";
4020 case DW_AT_body_end:
4021 return "DW_AT_body_end";
4023 return "DW_AT_<unknown>";
4027 /* Convert a DWARF value form code into its string name. */
4030 dwarf_form_name (form)
4031 register unsigned form;
4036 return "DW_FORM_addr";
4037 case DW_FORM_block2:
4038 return "DW_FORM_block2";
4039 case DW_FORM_block4:
4040 return "DW_FORM_block4";
4042 return "DW_FORM_data2";
4044 return "DW_FORM_data4";
4046 return "DW_FORM_data8";
4047 case DW_FORM_string:
4048 return "DW_FORM_string";
4050 return "DW_FORM_block";
4051 case DW_FORM_block1:
4052 return "DW_FORM_block1";
4054 return "DW_FORM_data1";
4056 return "DW_FORM_flag";
4058 return "DW_FORM_sdata";
4060 return "DW_FORM_strp";
4062 return "DW_FORM_udata";
4063 case DW_FORM_ref_addr:
4064 return "DW_FORM_ref_addr";
4066 return "DW_FORM_ref1";
4068 return "DW_FORM_ref2";
4070 return "DW_FORM_ref4";
4072 return "DW_FORM_ref8";
4073 case DW_FORM_ref_udata:
4074 return "DW_FORM_ref_udata";
4075 case DW_FORM_indirect:
4076 return "DW_FORM_indirect";
4078 return "DW_FORM_<unknown>";
4082 /* Convert a DWARF type code into its string name. */
4086 dwarf_type_encoding_name (enc)
4087 register unsigned enc;
4091 case DW_ATE_address:
4092 return "DW_ATE_address";
4093 case DW_ATE_boolean:
4094 return "DW_ATE_boolean";
4095 case DW_ATE_complex_float:
4096 return "DW_ATE_complex_float";
4098 return "DW_ATE_float";
4100 return "DW_ATE_signed";
4101 case DW_ATE_signed_char:
4102 return "DW_ATE_signed_char";
4103 case DW_ATE_unsigned:
4104 return "DW_ATE_unsigned";
4105 case DW_ATE_unsigned_char:
4106 return "DW_ATE_unsigned_char";
4108 return "DW_ATE_<unknown>";
4113 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4114 instance of an inlined instance of a decl which is local to an inline
4115 function, so we have to trace all of the way back through the origin chain
4116 to find out what sort of node actually served as the original seed for the
4120 decl_ultimate_origin (decl)
4123 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4124 nodes in the function to point to themselves; ignore that if
4125 we're trying to output the abstract instance of this function. */
4126 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4129 #ifdef ENABLE_CHECKING
4130 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4131 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4132 most distant ancestor, this should never happen. */
4136 return DECL_ABSTRACT_ORIGIN (decl);
4139 /* Determine the "ultimate origin" of a block. The block may be an inlined
4140 instance of an inlined instance of a block which is local to an inline
4141 function, so we have to trace all of the way back through the origin chain
4142 to find out what sort of node actually served as the original seed for the
4146 block_ultimate_origin (block)
4147 register tree block;
4149 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4151 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4152 nodes in the function to point to themselves; ignore that if
4153 we're trying to output the abstract instance of this function. */
4154 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4157 if (immediate_origin == NULL_TREE)
4161 register tree ret_val;
4162 register tree lookahead = immediate_origin;
4166 ret_val = lookahead;
4167 lookahead = (TREE_CODE (ret_val) == BLOCK)
4168 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4171 while (lookahead != NULL && lookahead != ret_val);
4177 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4178 of a virtual function may refer to a base class, so we check the 'this'
4182 decl_class_context (decl)
4185 tree context = NULL_TREE;
4187 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4188 context = DECL_CONTEXT (decl);
4190 context = TYPE_MAIN_VARIANT
4191 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4193 if (context && !TYPE_P (context))
4194 context = NULL_TREE;
4199 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4200 addition order, and correct that in reverse_all_dies. */
4203 add_dwarf_attr (die, attr)
4204 register dw_die_ref die;
4205 register dw_attr_ref attr;
4207 if (die != NULL && attr != NULL)
4209 attr->dw_attr_next = die->die_attr;
4210 die->die_attr = attr;
4214 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4215 static inline dw_val_class
4219 return a->dw_attr_val.val_class;
4222 /* Add a flag value attribute to a DIE. */
4225 add_AT_flag (die, attr_kind, flag)
4226 register dw_die_ref die;
4227 register enum dwarf_attribute attr_kind;
4228 register unsigned flag;
4230 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4232 attr->dw_attr_next = NULL;
4233 attr->dw_attr = attr_kind;
4234 attr->dw_attr_val.val_class = dw_val_class_flag;
4235 attr->dw_attr_val.v.val_flag = flag;
4236 add_dwarf_attr (die, attr);
4239 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4240 static inline unsigned
4242 register dw_attr_ref a;
4244 if (a && AT_class (a) == dw_val_class_flag)
4245 return a->dw_attr_val.v.val_flag;
4250 /* Add a signed integer attribute value to a DIE. */
4253 add_AT_int (die, attr_kind, int_val)
4254 register dw_die_ref die;
4255 register enum dwarf_attribute attr_kind;
4256 register long int int_val;
4258 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4260 attr->dw_attr_next = NULL;
4261 attr->dw_attr = attr_kind;
4262 attr->dw_attr_val.val_class = dw_val_class_const;
4263 attr->dw_attr_val.v.val_int = int_val;
4264 add_dwarf_attr (die, attr);
4267 static inline long int AT_int PARAMS ((dw_attr_ref));
4268 static inline long int
4270 register dw_attr_ref a;
4272 if (a && AT_class (a) == dw_val_class_const)
4273 return a->dw_attr_val.v.val_int;
4278 /* Add an unsigned integer attribute value to a DIE. */
4281 add_AT_unsigned (die, attr_kind, unsigned_val)
4282 register dw_die_ref die;
4283 register enum dwarf_attribute attr_kind;
4284 register unsigned long unsigned_val;
4286 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4288 attr->dw_attr_next = NULL;
4289 attr->dw_attr = attr_kind;
4290 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4291 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4292 add_dwarf_attr (die, attr);
4295 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4296 static inline unsigned long
4298 register dw_attr_ref a;
4300 if (a && AT_class (a) == dw_val_class_unsigned_const)
4301 return a->dw_attr_val.v.val_unsigned;
4306 /* Add an unsigned double integer attribute value to a DIE. */
4309 add_AT_long_long (die, attr_kind, val_hi, val_low)
4310 register dw_die_ref die;
4311 register enum dwarf_attribute attr_kind;
4312 register unsigned long val_hi;
4313 register unsigned long val_low;
4315 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4317 attr->dw_attr_next = NULL;
4318 attr->dw_attr = attr_kind;
4319 attr->dw_attr_val.val_class = dw_val_class_long_long;
4320 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4321 attr->dw_attr_val.v.val_long_long.low = val_low;
4322 add_dwarf_attr (die, attr);
4325 /* Add a floating point attribute value to a DIE and return it. */
4328 add_AT_float (die, attr_kind, length, array)
4329 register dw_die_ref die;
4330 register enum dwarf_attribute attr_kind;
4331 register unsigned length;
4332 register long *array;
4334 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4336 attr->dw_attr_next = NULL;
4337 attr->dw_attr = attr_kind;
4338 attr->dw_attr_val.val_class = dw_val_class_float;
4339 attr->dw_attr_val.v.val_float.length = length;
4340 attr->dw_attr_val.v.val_float.array = array;
4341 add_dwarf_attr (die, attr);
4344 /* Add a string attribute value to a DIE. */
4347 add_AT_string (die, attr_kind, str)
4348 register dw_die_ref die;
4349 register enum dwarf_attribute attr_kind;
4350 register const char *str;
4352 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4354 attr->dw_attr_next = NULL;
4355 attr->dw_attr = attr_kind;
4356 attr->dw_attr_val.val_class = dw_val_class_str;
4357 attr->dw_attr_val.v.val_str = xstrdup (str);
4358 add_dwarf_attr (die, attr);
4361 static inline const char *AT_string PARAMS ((dw_attr_ref));
4362 static inline const char *
4364 register dw_attr_ref a;
4366 if (a && AT_class (a) == dw_val_class_str)
4367 return a->dw_attr_val.v.val_str;
4372 /* Add a DIE reference attribute value to a DIE. */
4375 add_AT_die_ref (die, attr_kind, targ_die)
4376 register dw_die_ref die;
4377 register enum dwarf_attribute attr_kind;
4378 register dw_die_ref targ_die;
4380 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4382 attr->dw_attr_next = NULL;
4383 attr->dw_attr = attr_kind;
4384 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4385 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4386 attr->dw_attr_val.v.val_die_ref.external = 0;
4387 add_dwarf_attr (die, attr);
4390 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4391 static inline dw_die_ref
4393 register dw_attr_ref a;
4395 if (a && AT_class (a) == dw_val_class_die_ref)
4396 return a->dw_attr_val.v.val_die_ref.die;
4401 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4404 register dw_attr_ref a;
4406 if (a && AT_class (a) == dw_val_class_die_ref)
4407 return a->dw_attr_val.v.val_die_ref.external;
4412 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4414 set_AT_ref_external (a, i)
4415 register dw_attr_ref a;
4418 if (a && AT_class (a) == dw_val_class_die_ref)
4419 a->dw_attr_val.v.val_die_ref.external = i;
4424 /* Add an FDE reference attribute value to a DIE. */
4427 add_AT_fde_ref (die, attr_kind, targ_fde)
4428 register dw_die_ref die;
4429 register enum dwarf_attribute attr_kind;
4430 register unsigned targ_fde;
4432 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4434 attr->dw_attr_next = NULL;
4435 attr->dw_attr = attr_kind;
4436 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4437 attr->dw_attr_val.v.val_fde_index = targ_fde;
4438 add_dwarf_attr (die, attr);
4441 /* Add a location description attribute value to a DIE. */
4444 add_AT_loc (die, attr_kind, loc)
4445 register dw_die_ref die;
4446 register enum dwarf_attribute attr_kind;
4447 register dw_loc_descr_ref loc;
4449 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4451 attr->dw_attr_next = NULL;
4452 attr->dw_attr = attr_kind;
4453 attr->dw_attr_val.val_class = dw_val_class_loc;
4454 attr->dw_attr_val.v.val_loc = loc;
4455 add_dwarf_attr (die, attr);
4458 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4459 static inline dw_loc_descr_ref
4461 register dw_attr_ref a;
4463 if (a && AT_class (a) == dw_val_class_loc)
4464 return a->dw_attr_val.v.val_loc;
4470 add_AT_loc_list (die, attr_kind, loc_list)
4471 register dw_die_ref die;
4472 register enum dwarf_attribute attr_kind;
4473 register dw_loc_list_ref loc_list;
4475 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4477 attr->dw_attr_next = NULL;
4478 attr->dw_attr = attr_kind;
4479 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4480 attr->dw_attr_val.v.val_loc_list = loc_list;
4481 add_dwarf_attr (die, attr);
4482 have_location_lists = 1;
4485 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
4487 static inline dw_loc_list_ref
4489 register dw_attr_ref a;
4491 if (a && AT_class (a) == dw_val_class_loc_list)
4492 return a->dw_attr_val.v.val_loc_list;
4497 /* Add an address constant attribute value to a DIE. */
4500 add_AT_addr (die, attr_kind, addr)
4501 register dw_die_ref die;
4502 register enum dwarf_attribute attr_kind;
4505 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4507 attr->dw_attr_next = NULL;
4508 attr->dw_attr = attr_kind;
4509 attr->dw_attr_val.val_class = dw_val_class_addr;
4510 attr->dw_attr_val.v.val_addr = addr;
4511 add_dwarf_attr (die, attr);
4514 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4517 register dw_attr_ref a;
4519 if (a && AT_class (a) == dw_val_class_addr)
4520 return a->dw_attr_val.v.val_addr;
4525 /* Add a label identifier attribute value to a DIE. */
4528 add_AT_lbl_id (die, attr_kind, lbl_id)
4529 register dw_die_ref die;
4530 register enum dwarf_attribute attr_kind;
4531 register const char *lbl_id;
4533 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4535 attr->dw_attr_next = NULL;
4536 attr->dw_attr = attr_kind;
4537 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4538 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4539 add_dwarf_attr (die, attr);
4542 /* Add a section offset attribute value to a DIE. */
4545 add_AT_lbl_offset (die, attr_kind, label)
4546 register dw_die_ref die;
4547 register enum dwarf_attribute attr_kind;
4548 register const char *label;
4550 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4552 attr->dw_attr_next = NULL;
4553 attr->dw_attr = attr_kind;
4554 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4555 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4556 add_dwarf_attr (die, attr);
4559 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4560 static inline const char *
4562 register dw_attr_ref a;
4564 if (a && (AT_class (a) == dw_val_class_lbl_id
4565 || AT_class (a) == dw_val_class_lbl_offset))
4566 return a->dw_attr_val.v.val_lbl_id;
4571 /* Get the attribute of type attr_kind. */
4573 static inline dw_attr_ref
4574 get_AT (die, attr_kind)
4575 register dw_die_ref die;
4576 register enum dwarf_attribute attr_kind;
4578 register dw_attr_ref a;
4579 register dw_die_ref spec = NULL;
4583 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4585 if (a->dw_attr == attr_kind)
4588 if (a->dw_attr == DW_AT_specification
4589 || a->dw_attr == DW_AT_abstract_origin)
4594 return get_AT (spec, attr_kind);
4600 /* Return the "low pc" attribute value, typically associated with
4601 a subprogram DIE. Return null if the "low pc" attribute is
4602 either not prsent, or if it cannot be represented as an
4603 assembler label identifier. */
4605 static inline const char *
4607 register dw_die_ref die;
4609 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4610 return a ? AT_lbl (a) : NULL;
4613 /* Return the "high pc" attribute value, typically associated with
4614 a subprogram DIE. Return null if the "high pc" attribute is
4615 either not prsent, or if it cannot be represented as an
4616 assembler label identifier. */
4618 static inline const char *
4620 register dw_die_ref die;
4622 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4623 return a ? AT_lbl (a) : NULL;
4626 /* Return the value of the string attribute designated by ATTR_KIND, or
4627 NULL if it is not present. */
4629 static inline const char *
4630 get_AT_string (die, attr_kind)
4631 register dw_die_ref die;
4632 register enum dwarf_attribute attr_kind;
4634 register dw_attr_ref a = get_AT (die, attr_kind);
4635 return a ? AT_string (a) : NULL;
4638 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4639 if it is not present. */
4642 get_AT_flag (die, attr_kind)
4643 register dw_die_ref die;
4644 register enum dwarf_attribute attr_kind;
4646 register dw_attr_ref a = get_AT (die, attr_kind);
4647 return a ? AT_flag (a) : 0;
4650 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4651 if it is not present. */
4653 static inline unsigned
4654 get_AT_unsigned (die, attr_kind)
4655 register dw_die_ref die;
4656 register enum dwarf_attribute attr_kind;
4658 register dw_attr_ref a = get_AT (die, attr_kind);
4659 return a ? AT_unsigned (a) : 0;
4662 static inline dw_die_ref
4663 get_AT_ref (die, attr_kind)
4665 register enum dwarf_attribute attr_kind;
4667 register dw_attr_ref a = get_AT (die, attr_kind);
4668 return a ? AT_ref (a) : NULL;
4674 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4676 return (lang == DW_LANG_C || lang == DW_LANG_C89
4677 || lang == DW_LANG_C_plus_plus);
4683 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4685 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4691 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4693 return (lang == DW_LANG_Java);
4696 /* Free up the memory used by A. */
4698 static inline void free_AT PARAMS ((dw_attr_ref));
4703 switch (AT_class (a))
4705 case dw_val_class_str:
4706 case dw_val_class_lbl_id:
4707 case dw_val_class_lbl_offset:
4708 free (a->dw_attr_val.v.val_str);
4711 case dw_val_class_float:
4712 free (a->dw_attr_val.v.val_float.array);
4722 /* Remove the specified attribute if present. */
4725 remove_AT (die, attr_kind)
4726 register dw_die_ref die;
4727 register enum dwarf_attribute attr_kind;
4729 register dw_attr_ref *p;
4730 register dw_attr_ref removed = NULL;
4734 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4735 if ((*p)->dw_attr == attr_kind)
4738 *p = (*p)->dw_attr_next;
4747 /* Free up the memory used by DIE. */
4749 static inline void free_die PARAMS ((dw_die_ref));
4754 remove_children (die);
4758 /* Discard the children of this DIE. */
4761 remove_children (die)
4762 register dw_die_ref die;
4764 register dw_die_ref child_die = die->die_child;
4766 die->die_child = NULL;
4768 while (child_die != NULL)
4770 register dw_die_ref tmp_die = child_die;
4771 register dw_attr_ref a;
4773 child_die = child_die->die_sib;
4775 for (a = tmp_die->die_attr; a != NULL;)
4777 register dw_attr_ref tmp_a = a;
4779 a = a->dw_attr_next;
4787 /* Add a child DIE below its parent. We build the lists up in reverse
4788 addition order, and correct that in reverse_all_dies. */
4791 add_child_die (die, child_die)
4792 register dw_die_ref die;
4793 register dw_die_ref child_die;
4795 if (die != NULL && child_die != NULL)
4797 if (die == child_die)
4799 child_die->die_parent = die;
4800 child_die->die_sib = die->die_child;
4801 die->die_child = child_die;
4805 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4806 is the specification, to the front of PARENT's list of children. */
4809 splice_child_die (parent, child)
4810 dw_die_ref parent, child;
4814 /* We want the declaration DIE from inside the class, not the
4815 specification DIE at toplevel. */
4816 if (child->die_parent != parent)
4818 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4823 if (child->die_parent != parent
4824 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4827 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4830 *p = child->die_sib;
4834 child->die_sib = parent->die_child;
4835 parent->die_child = child;
4838 /* Return a pointer to a newly created DIE node. */
4840 static inline dw_die_ref
4841 new_die (tag_value, parent_die)
4842 register enum dwarf_tag tag_value;
4843 register dw_die_ref parent_die;
4845 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4847 die->die_tag = tag_value;
4849 if (parent_die != NULL)
4850 add_child_die (parent_die, die);
4853 limbo_die_node *limbo_node;
4855 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4856 limbo_node->die = die;
4857 limbo_node->next = limbo_die_list;
4858 limbo_die_list = limbo_node;
4864 /* Return the DIE associated with the given type specifier. */
4866 static inline dw_die_ref
4867 lookup_type_die (type)
4870 if (TREE_CODE (type) == VECTOR_TYPE)
4871 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4872 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4875 /* Equate a DIE to a given type specifier. */
4878 equate_type_number_to_die (type, type_die)
4880 register dw_die_ref type_die;
4882 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4885 /* Return the DIE associated with a given declaration. */
4887 static inline dw_die_ref
4888 lookup_decl_die (decl)
4891 register unsigned decl_id = DECL_UID (decl);
4893 return (decl_id < decl_die_table_in_use
4894 ? decl_die_table[decl_id] : NULL);
4897 /* Equate a DIE to a particular declaration. */
4900 equate_decl_number_to_die (decl, decl_die)
4902 register dw_die_ref decl_die;
4904 register unsigned decl_id = DECL_UID (decl);
4905 register unsigned num_allocated;
4907 if (decl_id >= decl_die_table_allocated)
4910 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4911 / DECL_DIE_TABLE_INCREMENT)
4912 * DECL_DIE_TABLE_INCREMENT;
4915 = (dw_die_ref *) xrealloc (decl_die_table,
4916 sizeof (dw_die_ref) * num_allocated);
4918 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4919 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4920 decl_die_table_allocated = num_allocated;
4923 if (decl_id >= decl_die_table_in_use)
4924 decl_die_table_in_use = (decl_id + 1);
4926 decl_die_table[decl_id] = decl_die;
4929 /* Keep track of the number of spaces used to indent the
4930 output of the debugging routines that print the structure of
4931 the DIE internal representation. */
4932 static int print_indent;
4934 /* Indent the line the number of spaces given by print_indent. */
4937 print_spaces (outfile)
4940 fprintf (outfile, "%*s", print_indent, "");
4943 /* Print the information associated with a given DIE, and its children.
4944 This routine is a debugging aid only. */
4947 print_die (die, outfile)
4951 register dw_attr_ref a;
4952 register dw_die_ref c;
4954 print_spaces (outfile);
4955 fprintf (outfile, "DIE %4lu: %s\n",
4956 die->die_offset, dwarf_tag_name (die->die_tag));
4957 print_spaces (outfile);
4958 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4959 fprintf (outfile, " offset: %lu\n", die->die_offset);
4961 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4963 print_spaces (outfile);
4964 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4966 switch (AT_class (a))
4968 case dw_val_class_addr:
4969 fprintf (outfile, "address");
4971 case dw_val_class_loc:
4972 fprintf (outfile, "location descriptor");
4974 case dw_val_class_loc_list:
4975 fprintf (outfile, "location list -> label:%s", AT_loc_list (a)->ll_symbol);
4977 case dw_val_class_const:
4978 fprintf (outfile, "%ld", AT_int (a));
4980 case dw_val_class_unsigned_const:
4981 fprintf (outfile, "%lu", AT_unsigned (a));
4983 case dw_val_class_long_long:
4984 fprintf (outfile, "constant (%lu,%lu)",
4985 a->dw_attr_val.v.val_long_long.hi,
4986 a->dw_attr_val.v.val_long_long.low);
4988 case dw_val_class_float:
4989 fprintf (outfile, "floating-point constant");
4991 case dw_val_class_flag:
4992 fprintf (outfile, "%u", AT_flag (a));
4994 case dw_val_class_die_ref:
4995 if (AT_ref (a) != NULL)
4997 if (AT_ref (a)->die_symbol)
4998 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5000 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5003 fprintf (outfile, "die -> <null>");
5005 case dw_val_class_lbl_id:
5006 case dw_val_class_lbl_offset:
5007 fprintf (outfile, "label: %s", AT_lbl (a));
5009 case dw_val_class_str:
5010 if (AT_string (a) != NULL)
5011 fprintf (outfile, "\"%s\"", AT_string (a));
5013 fprintf (outfile, "<null>");
5019 fprintf (outfile, "\n");
5022 if (die->die_child != NULL)
5025 for (c = die->die_child; c != NULL; c = c->die_sib)
5026 print_die (c, outfile);
5030 if (print_indent == 0)
5031 fprintf (outfile, "\n");
5034 /* Print the contents of the source code line number correspondence table.
5035 This routine is a debugging aid only. */
5038 print_dwarf_line_table (outfile)
5041 register unsigned i;
5042 register dw_line_info_ref line_info;
5044 fprintf (outfile, "\n\nDWARF source line information\n");
5045 for (i = 1; i < line_info_table_in_use; ++i)
5047 line_info = &line_info_table[i];
5048 fprintf (outfile, "%5d: ", i);
5049 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5050 fprintf (outfile, "%6ld", line_info->dw_line_num);
5051 fprintf (outfile, "\n");
5054 fprintf (outfile, "\n\n");
5057 /* Print the information collected for a given DIE. */
5060 debug_dwarf_die (die)
5063 print_die (die, stderr);
5066 /* Print all DWARF information collected for the compilation unit.
5067 This routine is a debugging aid only. */
5073 print_die (comp_unit_die, stderr);
5074 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5075 print_dwarf_line_table (stderr);
5078 /* We build up the lists of children and attributes by pushing new ones
5079 onto the beginning of the list. Reverse the lists for DIE so that
5080 they are in order of addition. */
5083 reverse_die_lists (die)
5084 register dw_die_ref die;
5086 register dw_die_ref c, cp, cn;
5087 register dw_attr_ref a, ap, an;
5089 for (a = die->die_attr, ap = 0; a; a = an)
5091 an = a->dw_attr_next;
5092 a->dw_attr_next = ap;
5097 for (c = die->die_child, cp = 0; c; c = cn)
5103 die->die_child = cp;
5106 /* reverse_die_lists only reverses the single die you pass it. Since
5107 we used to reverse all dies in add_sibling_attributes, which runs
5108 through all the dies, it would reverse all the dies. Now, however,
5109 since we don't call reverse_die_lists in add_sibling_attributes, we
5110 need a routine to recursively reverse all the dies. This is that
5114 reverse_all_dies (die)
5115 register dw_die_ref die;
5117 register dw_die_ref c;
5119 reverse_die_lists (die);
5121 for (c = die->die_child; c; c = c->die_sib)
5122 reverse_all_dies (c);
5125 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5126 the CU for the enclosing include file, if any. BINCL_DIE is the
5127 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5131 push_new_compile_unit (old_unit, bincl_die)
5132 dw_die_ref old_unit, bincl_die;
5134 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5135 dw_die_ref new_unit = gen_compile_unit_die (filename);
5136 new_unit->die_sib = old_unit;
5140 /* Close an include-file CU and reopen the enclosing one. */
5143 pop_compile_unit (old_unit)
5144 dw_die_ref old_unit;
5146 dw_die_ref new_unit = old_unit->die_sib;
5147 old_unit->die_sib = NULL;
5151 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5152 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5154 /* Calculate the checksum of a location expression. */
5157 loc_checksum (loc, ctx)
5158 dw_loc_descr_ref loc;
5159 struct md5_ctx *ctx;
5161 PROCESS (loc->dw_loc_opc);
5162 PROCESS (loc->dw_loc_oprnd1);
5163 PROCESS (loc->dw_loc_oprnd2);
5166 /* Calculate the checksum of an attribute. */
5169 attr_checksum (at, ctx)
5171 struct md5_ctx *ctx;
5173 dw_loc_descr_ref loc;
5176 PROCESS (at->dw_attr);
5178 /* We don't care about differences in file numbering. */
5179 if (at->dw_attr == DW_AT_decl_file
5180 /* Or that this was compiled with a different compiler snapshot; if
5181 the output is the same, that's what matters. */
5182 || at->dw_attr == DW_AT_producer)
5185 switch (AT_class (at))
5187 case dw_val_class_const:
5188 PROCESS (at->dw_attr_val.v.val_int);
5190 case dw_val_class_unsigned_const:
5191 PROCESS (at->dw_attr_val.v.val_unsigned);
5193 case dw_val_class_long_long:
5194 PROCESS (at->dw_attr_val.v.val_long_long);
5196 case dw_val_class_float:
5197 PROCESS (at->dw_attr_val.v.val_float);
5199 case dw_val_class_flag:
5200 PROCESS (at->dw_attr_val.v.val_flag);
5203 case dw_val_class_str:
5204 PROCESS_STRING (AT_string (at));
5206 case dw_val_class_addr:
5208 switch (GET_CODE (r))
5211 PROCESS_STRING (XSTR (r, 0));
5219 case dw_val_class_loc:
5220 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5221 loc_checksum (loc, ctx);
5224 case dw_val_class_die_ref:
5225 if (AT_ref (at)->die_offset)
5226 PROCESS (AT_ref (at)->die_offset);
5227 /* FIXME else use target die name or something. */
5229 case dw_val_class_fde_ref:
5230 case dw_val_class_lbl_id:
5231 case dw_val_class_lbl_offset:
5238 /* Calculate the checksum of a DIE. */
5241 die_checksum (die, ctx)
5243 struct md5_ctx *ctx;
5248 PROCESS (die->die_tag);
5250 for (a = die->die_attr; a; a = a->dw_attr_next)
5251 attr_checksum (a, ctx);
5253 for (c = die->die_child; c; c = c->die_sib)
5254 die_checksum (c, ctx);
5258 #undef PROCESS_STRING
5260 /* The prefix to attach to symbols on DIEs in the current comdat debug
5262 static char *comdat_symbol_id;
5264 /* The index of the current symbol within the current comdat CU. */
5265 static unsigned int comdat_symbol_number;
5267 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5268 children, and set comdat_symbol_id accordingly. */
5271 compute_section_prefix (unit_die)
5272 dw_die_ref unit_die;
5276 unsigned char checksum[16];
5279 md5_init_ctx (&ctx);
5280 die_checksum (unit_die, &ctx);
5281 md5_finish_ctx (&ctx, checksum);
5283 p = lbasename (get_AT_string (unit_die, DW_AT_name));
5284 name = (char *) alloca (strlen (p) + 64);
5285 sprintf (name, "%s.", p);
5287 clean_symbol_name (name);
5289 p = name + strlen (name);
5290 for (i = 0; i < 4; ++i)
5292 sprintf (p, "%.2x", checksum[i]);
5296 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5297 comdat_symbol_number = 0;
5300 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5306 switch (die->die_tag)
5308 case DW_TAG_array_type:
5309 case DW_TAG_class_type:
5310 case DW_TAG_enumeration_type:
5311 case DW_TAG_pointer_type:
5312 case DW_TAG_reference_type:
5313 case DW_TAG_string_type:
5314 case DW_TAG_structure_type:
5315 case DW_TAG_subroutine_type:
5316 case DW_TAG_union_type:
5317 case DW_TAG_ptr_to_member_type:
5318 case DW_TAG_set_type:
5319 case DW_TAG_subrange_type:
5320 case DW_TAG_base_type:
5321 case DW_TAG_const_type:
5322 case DW_TAG_file_type:
5323 case DW_TAG_packed_type:
5324 case DW_TAG_volatile_type:
5331 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5332 Basically, we want to choose the bits that are likely to be shared between
5333 compilations (types) and leave out the bits that are specific to individual
5334 compilations (functions). */
5341 /* I think we want to leave base types and __vtbl_ptr_type in the
5342 main CU, as we do for stabs. The advantage is a greater
5343 likelihood of sharing between objects that don't include headers
5344 in the same order (and therefore would put the base types in a
5345 different comdat). jason 8/28/00 */
5346 if (c->die_tag == DW_TAG_base_type)
5349 if (c->die_tag == DW_TAG_pointer_type
5350 || c->die_tag == DW_TAG_reference_type
5351 || c->die_tag == DW_TAG_const_type
5352 || c->die_tag == DW_TAG_volatile_type)
5354 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5355 return t ? is_comdat_die (t) : 0;
5359 return is_type_die (c);
5362 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5363 compilation unit. */
5369 if (is_type_die (c))
5371 if (get_AT (c, DW_AT_declaration)
5372 && ! get_AT (c, DW_AT_specification))
5378 gen_internal_sym (prefix)
5382 static int label_num;
5383 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5384 return xstrdup (buf);
5387 /* Assign symbols to all worthy DIEs under DIE. */
5390 assign_symbol_names (die)
5391 register dw_die_ref die;
5393 register dw_die_ref c;
5395 if (is_symbol_die (die))
5397 if (comdat_symbol_id)
5399 char *p = alloca (strlen (comdat_symbol_id) + 64);
5400 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5401 comdat_symbol_id, comdat_symbol_number++);
5402 die->die_symbol = xstrdup (p);
5405 die->die_symbol = gen_internal_sym ("LDIE");
5408 for (c = die->die_child; c != NULL; c = c->die_sib)
5409 assign_symbol_names (c);
5412 /* Traverse the DIE (which is always comp_unit_die), and set up
5413 additional compilation units for each of the include files we see
5414 bracketed by BINCL/EINCL. */
5417 break_out_includes (die)
5418 register dw_die_ref die;
5421 register dw_die_ref unit = NULL;
5422 limbo_die_node *node;
5424 for (ptr = &(die->die_child); *ptr; )
5426 register dw_die_ref c = *ptr;
5428 if (c->die_tag == DW_TAG_GNU_BINCL
5429 || c->die_tag == DW_TAG_GNU_EINCL
5430 || (unit && is_comdat_die (c)))
5432 /* This DIE is for a secondary CU; remove it from the main one. */
5435 if (c->die_tag == DW_TAG_GNU_BINCL)
5437 unit = push_new_compile_unit (unit, c);
5440 else if (c->die_tag == DW_TAG_GNU_EINCL)
5442 unit = pop_compile_unit (unit);
5446 add_child_die (unit, c);
5450 /* Leave this DIE in the main CU. */
5451 ptr = &(c->die_sib);
5457 /* We can only use this in debugging, since the frontend doesn't check
5458 to make sure that we leave every include file we enter. */
5463 assign_symbol_names (die);
5464 for (node = limbo_die_list; node; node = node->next)
5466 compute_section_prefix (node->die);
5467 assign_symbol_names (node->die);
5471 /* Traverse the DIE and add a sibling attribute if it may have the
5472 effect of speeding up access to siblings. To save some space,
5473 avoid generating sibling attributes for DIE's without children. */
5476 add_sibling_attributes (die)
5477 register dw_die_ref die;
5479 register dw_die_ref c;
5481 if (die->die_tag != DW_TAG_compile_unit
5482 && die->die_sib && die->die_child != NULL)
5483 /* Add the sibling link to the front of the attribute list. */
5484 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5486 for (c = die->die_child; c != NULL; c = c->die_sib)
5487 add_sibling_attributes (c);
5490 /* Output all location lists for the DIE and it's children */
5492 output_location_lists (die)
5493 register dw_die_ref die;
5497 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5499 if (AT_class (d_attr) == dw_val_class_loc_list)
5501 output_loc_list (AT_loc_list (d_attr));
5504 for (c = die->die_child; c != NULL; c = c->die_sib)
5505 output_location_lists (c);
5508 /* The format of each DIE (and its attribute value pairs)
5509 is encoded in an abbreviation table. This routine builds the
5510 abbreviation table and assigns a unique abbreviation id for
5511 each abbreviation entry. The children of each die are visited
5515 build_abbrev_table (die)
5516 register dw_die_ref die;
5518 register unsigned long abbrev_id;
5519 register unsigned int n_alloc;
5520 register dw_die_ref c;
5521 register dw_attr_ref d_attr, a_attr;
5523 /* Scan the DIE references, and mark as external any that refer to
5524 DIEs from other CUs (i.e. those which are not marked). */
5525 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5527 if (AT_class (d_attr) == dw_val_class_die_ref
5528 && AT_ref (d_attr)->die_mark == 0)
5530 if (AT_ref (d_attr)->die_symbol == 0)
5532 set_AT_ref_external (d_attr, 1);
5536 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5538 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5540 if (abbrev->die_tag == die->die_tag)
5542 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5544 a_attr = abbrev->die_attr;
5545 d_attr = die->die_attr;
5547 while (a_attr != NULL && d_attr != NULL)
5549 if ((a_attr->dw_attr != d_attr->dw_attr)
5550 || (value_format (a_attr) != value_format (d_attr)))
5553 a_attr = a_attr->dw_attr_next;
5554 d_attr = d_attr->dw_attr_next;
5557 if (a_attr == NULL && d_attr == NULL)
5563 if (abbrev_id >= abbrev_die_table_in_use)
5565 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5567 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5569 = (dw_die_ref *) xrealloc (abbrev_die_table,
5570 sizeof (dw_die_ref) * n_alloc);
5572 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5573 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5574 abbrev_die_table_allocated = n_alloc;
5577 ++abbrev_die_table_in_use;
5578 abbrev_die_table[abbrev_id] = die;
5581 die->die_abbrev = abbrev_id;
5582 for (c = die->die_child; c != NULL; c = c->die_sib)
5583 build_abbrev_table (c);
5586 /* Return the size of a string, including the null byte.
5588 This used to treat backslashes as escapes, and hence they were not included
5589 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5590 which treats a backslash as a backslash, escaping it if necessary, and hence
5591 we must include them in the count. */
5593 static unsigned long
5594 size_of_string (str)
5595 register const char *str;
5597 return strlen (str) + 1;
5600 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5603 constant_size (value)
5604 long unsigned value;
5611 log = floor_log2 (value);
5614 log = 1 << (floor_log2 (log) + 1);
5619 /* Return the size of a DIE, as it is represented in the
5620 .debug_info section. */
5622 static unsigned long
5624 register dw_die_ref die;
5626 register unsigned long size = 0;
5627 register dw_attr_ref a;
5629 size += size_of_uleb128 (die->die_abbrev);
5630 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5632 switch (AT_class (a))
5634 case dw_val_class_addr:
5635 size += DWARF2_ADDR_SIZE;
5637 case dw_val_class_loc:
5639 register unsigned long lsize = size_of_locs (AT_loc (a));
5642 size += constant_size (lsize);
5646 case dw_val_class_loc_list:
5647 size += DWARF_OFFSET_SIZE;
5649 case dw_val_class_const:
5650 size += size_of_sleb128 (AT_int (a));
5652 case dw_val_class_unsigned_const:
5653 size += constant_size (AT_unsigned (a));
5655 case dw_val_class_long_long:
5656 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5658 case dw_val_class_float:
5659 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5661 case dw_val_class_flag:
5664 case dw_val_class_die_ref:
5665 size += DWARF_OFFSET_SIZE;
5667 case dw_val_class_fde_ref:
5668 size += DWARF_OFFSET_SIZE;
5670 case dw_val_class_lbl_id:
5671 size += DWARF2_ADDR_SIZE;
5673 case dw_val_class_lbl_offset:
5674 size += DWARF_OFFSET_SIZE;
5676 case dw_val_class_str:
5677 size += size_of_string (AT_string (a));
5687 /* Size the debugging information associated with a given DIE.
5688 Visits the DIE's children recursively. Updates the global
5689 variable next_die_offset, on each time through. Uses the
5690 current value of next_die_offset to update the die_offset
5691 field in each DIE. */
5694 calc_die_sizes (die)
5697 register dw_die_ref c;
5698 die->die_offset = next_die_offset;
5699 next_die_offset += size_of_die (die);
5701 for (c = die->die_child; c != NULL; c = c->die_sib)
5704 if (die->die_child != NULL)
5705 /* Count the null byte used to terminate sibling lists. */
5706 next_die_offset += 1;
5709 /* Set the marks for a die and its children. We do this so
5710 that we know whether or not a reference needs to use FORM_ref_addr; only
5711 DIEs in the same CU will be marked. We used to clear out the offset
5712 and use that as the flag, but ran into ordering problems. */
5718 register dw_die_ref c;
5720 for (c = die->die_child; c; c = c->die_sib)
5724 /* Clear the marks for a die and its children. */
5730 register dw_die_ref c;
5732 for (c = die->die_child; c; c = c->die_sib)
5736 /* Return the size of the .debug_pubnames table generated for the
5737 compilation unit. */
5739 static unsigned long
5742 register unsigned long size;
5743 register unsigned i;
5745 size = DWARF_PUBNAMES_HEADER_SIZE;
5746 for (i = 0; i < pubname_table_in_use; ++i)
5748 register pubname_ref p = &pubname_table[i];
5749 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5752 size += DWARF_OFFSET_SIZE;
5756 /* Return the size of the information in the .debug_aranges section. */
5758 static unsigned long
5761 register unsigned long size;
5763 size = DWARF_ARANGES_HEADER_SIZE;
5765 /* Count the address/length pair for this compilation unit. */
5766 size += 2 * DWARF2_ADDR_SIZE;
5767 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5769 /* Count the two zero words used to terminated the address range table. */
5770 size += 2 * DWARF2_ADDR_SIZE;
5774 /* Select the encoding of an attribute value. */
5776 static enum dwarf_form
5780 switch (a->dw_attr_val.val_class)
5782 case dw_val_class_addr:
5783 return DW_FORM_addr;
5784 case dw_val_class_loc_list:
5785 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
5786 .debug_loc section */
5787 return DW_FORM_data4;
5788 case dw_val_class_loc:
5789 switch (constant_size (size_of_locs (AT_loc (a))))
5792 return DW_FORM_block1;
5794 return DW_FORM_block2;
5798 case dw_val_class_const:
5799 return DW_FORM_sdata;
5800 case dw_val_class_unsigned_const:
5801 switch (constant_size (AT_unsigned (a)))
5804 return DW_FORM_data1;
5806 return DW_FORM_data2;
5808 return DW_FORM_data4;
5810 return DW_FORM_data8;
5814 case dw_val_class_long_long:
5815 return DW_FORM_block1;
5816 case dw_val_class_float:
5817 return DW_FORM_block1;
5818 case dw_val_class_flag:
5819 return DW_FORM_flag;
5820 case dw_val_class_die_ref:
5821 if (AT_ref_external (a))
5822 return DW_FORM_ref_addr;
5825 case dw_val_class_fde_ref:
5826 return DW_FORM_data;
5827 case dw_val_class_lbl_id:
5828 return DW_FORM_addr;
5829 case dw_val_class_lbl_offset:
5830 return DW_FORM_data;
5831 case dw_val_class_str:
5832 return DW_FORM_string;
5838 /* Output the encoding of an attribute value. */
5841 output_value_format (a)
5844 enum dwarf_form form = value_format (a);
5845 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
5848 /* Output the .debug_abbrev section which defines the DIE abbreviation
5852 output_abbrev_section ()
5854 unsigned long abbrev_id;
5857 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5859 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5861 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
5863 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
5864 dwarf_tag_name (abbrev->die_tag));
5866 if (abbrev->die_child != NULL)
5867 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
5869 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
5871 for (a_attr = abbrev->die_attr; a_attr != NULL;
5872 a_attr = a_attr->dw_attr_next)
5874 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
5875 dwarf_attr_name (a_attr->dw_attr));
5876 output_value_format (a_attr);
5879 dw2_asm_output_data (1, 0, NULL);
5880 dw2_asm_output_data (1, 0, NULL);
5883 /* Terminate the table. */
5884 dw2_asm_output_data (1, 0, NULL);
5887 /* Output a symbol we can use to refer to this DIE from another CU. */
5890 output_die_symbol (die)
5891 register dw_die_ref die;
5893 char *sym = die->die_symbol;
5898 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5899 /* We make these global, not weak; if the target doesn't support
5900 .linkonce, it doesn't support combining the sections, so debugging
5902 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5903 ASM_OUTPUT_LABEL (asm_out_file, sym);
5906 /* Return a new location list, given the begin and end range, and the
5907 expression. gensym tells us whether to generate a new internal
5908 symbol for this location list node, which is done for the head of
5910 static inline dw_loc_list_ref
5911 new_loc_list (expr, begin, end, section, gensym)
5912 register dw_loc_descr_ref expr;
5913 register const char *begin;
5914 register const char *end;
5915 register const char *section;
5916 register unsigned gensym;
5918 register dw_loc_list_ref retlist
5919 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
5920 retlist->begin = begin;
5922 retlist->expr = expr;
5923 retlist->section = section;
5925 retlist->ll_symbol = gen_internal_sym ("LLST");
5929 /* Add a location description expression to a location list */
5931 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
5932 register dw_loc_list_ref *list_head;
5933 register dw_loc_descr_ref descr;
5934 register const char *begin;
5935 register const char *end;
5936 register const char *section;
5938 register dw_loc_list_ref *d;
5940 /* Find the end of the chain. */
5941 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
5943 /* Add a new location list node to the list */
5944 *d = new_loc_list (descr, begin, end, section, 0);
5949 /* Output the location list given to us */
5951 output_loc_list (list_head)
5952 register dw_loc_list_ref list_head;
5954 register dw_loc_list_ref curr=list_head;
5955 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
5956 if (strcmp (curr->section, ".text") == 0)
5958 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
5959 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT)0,
5960 "Location list base address specifier fake entry");
5961 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
5962 "Location list base address specifier base");
5964 for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
5967 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
5968 "Location list begin address (%s)",
5969 list_head->ll_symbol);
5970 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
5971 "Location list end address (%s)",
5972 list_head->ll_symbol);
5973 size = size_of_locs (curr->expr);
5975 /* Output the block length for this list of location operations. */
5976 dw2_asm_output_data (constant_size (size), size, "%s",
5977 "Location expression size");
5979 output_loc_sequence (curr->expr);
5981 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
5982 "Location list terminator begin (%s)",
5983 list_head->ll_symbol);
5984 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
5985 "Location list terminator end (%s)",
5986 list_head->ll_symbol);
5988 /* Output the DIE and its attributes. Called recursively to generate
5989 the definitions of each child DIE. */
5993 register dw_die_ref die;
5995 register dw_attr_ref a;
5996 register dw_die_ref c;
5997 register unsigned long size;
5999 /* If someone in another CU might refer to us, set up a symbol for
6000 them to point to. */
6001 if (die->die_symbol)
6002 output_die_symbol (die);
6004 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6005 die->die_offset, dwarf_tag_name (die->die_tag));
6007 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6009 const char *name = dwarf_attr_name (a->dw_attr);
6011 switch (AT_class (a))
6013 case dw_val_class_addr:
6014 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6017 case dw_val_class_loc:
6018 size = size_of_locs (AT_loc (a));
6020 /* Output the block length for this list of location operations. */
6021 dw2_asm_output_data (constant_size (size), size, "%s", name);
6023 output_loc_sequence (AT_loc (a));
6026 case dw_val_class_const:
6027 /* ??? It would be slightly more efficient to use a scheme like is
6028 used for unsigned constants below, but gdb 4.x does not sign
6029 extend. Gdb 5.x does sign extend. */
6030 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6033 case dw_val_class_unsigned_const:
6034 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6035 AT_unsigned (a), "%s", name);
6038 case dw_val_class_long_long:
6040 unsigned HOST_WIDE_INT first, second;
6042 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6045 if (WORDS_BIG_ENDIAN)
6047 first = a->dw_attr_val.v.val_long_long.hi;
6048 second = a->dw_attr_val.v.val_long_long.low;
6052 first = a->dw_attr_val.v.val_long_long.low;
6053 second = a->dw_attr_val.v.val_long_long.hi;
6055 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6056 first, "long long constant");
6057 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6062 case dw_val_class_float:
6064 register unsigned int i;
6066 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6069 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6070 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6071 "fp constant word %u", i);
6075 case dw_val_class_flag:
6076 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6078 case dw_val_class_loc_list:
6080 char *sym = AT_loc_list (a)->ll_symbol;
6083 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label, name);
6086 case dw_val_class_die_ref:
6087 if (AT_ref_external (a))
6089 char *sym = AT_ref (a)->die_symbol;
6092 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6094 else if (AT_ref (a)->die_offset == 0)
6097 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6101 case dw_val_class_fde_ref:
6104 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6105 a->dw_attr_val.v.val_fde_index * 2);
6106 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6110 case dw_val_class_lbl_id:
6111 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6114 case dw_val_class_lbl_offset:
6115 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6118 case dw_val_class_str:
6119 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6127 for (c = die->die_child; c != NULL; c = c->die_sib)
6130 if (die->die_child != NULL)
6132 /* Add null byte to terminate sibling list. */
6133 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6138 /* Output the compilation unit that appears at the beginning of the
6139 .debug_info section, and precedes the DIE descriptions. */
6142 output_compilation_unit_header ()
6144 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6145 "Length of Compilation Unit Info");
6147 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6149 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6150 "Offset Into Abbrev. Section");
6152 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6155 /* Output the compilation unit DIE and its children. */
6158 output_comp_unit (die)
6161 const char *secname;
6163 /* Even if there are no children of this DIE, we must output the
6164 information about the compilation unit. Otherwise, on an empty
6165 translation unit, we will generate a present, but empty,
6166 .debug_info section. IRIX 6.5 `nm' will then complain when
6169 Mark all the DIEs in this CU so we know which get local refs. */
6172 build_abbrev_table (die);
6174 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6175 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6176 calc_die_sizes (die);
6178 if (die->die_symbol)
6180 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6181 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6183 die->die_symbol = NULL;
6186 secname = (const char *) DEBUG_INFO_SECTION;
6188 /* Output debugging information. */
6189 ASM_OUTPUT_SECTION (asm_out_file, secname);
6190 output_compilation_unit_header ();
6193 /* Leave the marks on the main CU, so we can check them in
6195 if (die->die_symbol)
6199 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6200 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6201 argument list, and maybe the scope. */
6204 dwarf2_name (decl, scope)
6208 return (*decl_printable_name) (decl, scope ? 1 : 0);
6211 /* Add a new entry to .debug_pubnames if appropriate. */
6214 add_pubname (decl, die)
6220 if (! TREE_PUBLIC (decl))
6223 if (pubname_table_in_use == pubname_table_allocated)
6225 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6226 pubname_table = (pubname_ref) xrealloc
6227 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6230 p = &pubname_table[pubname_table_in_use++];
6233 p->name = xstrdup (dwarf2_name (decl, 1));
6236 /* Output the public names table used to speed up access to externally
6237 visible names. For now, only generate entries for externally
6238 visible procedures. */
6243 register unsigned i;
6244 register unsigned long pubnames_length = size_of_pubnames ();
6246 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6247 "Length of Public Names Info");
6249 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6251 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6252 "Offset of Compilation Unit Info");
6254 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6255 "Compilation Unit Length");
6257 for (i = 0; i < pubname_table_in_use; ++i)
6259 register pubname_ref pub = &pubname_table[i];
6261 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6262 if (pub->die->die_mark == 0)
6265 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6268 dw2_asm_output_nstring (pub->name, -1, "external name");
6271 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6274 /* Add a new entry to .debug_aranges if appropriate. */
6277 add_arange (decl, die)
6281 if (! DECL_SECTION_NAME (decl))
6284 if (arange_table_in_use == arange_table_allocated)
6286 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6288 = (arange_ref) xrealloc (arange_table,
6289 arange_table_allocated * sizeof (dw_die_ref));
6292 arange_table[arange_table_in_use++] = die;
6295 /* Output the information that goes into the .debug_aranges table.
6296 Namely, define the beginning and ending address range of the
6297 text section generated for this compilation unit. */
6302 register unsigned i;
6303 register unsigned long aranges_length = size_of_aranges ();
6305 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6306 "Length of Address Ranges Info");
6308 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6310 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6311 "Offset of Compilation Unit Info");
6313 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6315 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6317 /* We need to align to twice the pointer size here. */
6318 if (DWARF_ARANGES_PAD_SIZE)
6320 /* Pad using a 2 byte words so that padding is correct for any
6322 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6323 2 * DWARF2_ADDR_SIZE);
6324 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6325 dw2_asm_output_data (2, 0, NULL);
6328 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6329 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6330 text_section_label, "Length");
6332 for (i = 0; i < arange_table_in_use; ++i)
6334 dw_die_ref die = arange_table[i];
6336 /* We shouldn't see aranges for DIEs outside of the main CU. */
6337 if (die->die_mark == 0)
6340 if (die->die_tag == DW_TAG_subprogram)
6342 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6344 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6345 get_AT_low_pc (die), "Length");
6349 /* A static variable; extract the symbol from DW_AT_location.
6350 Note that this code isn't currently hit, as we only emit
6351 aranges for functions (jason 9/23/99). */
6353 dw_attr_ref a = get_AT (die, DW_AT_location);
6354 dw_loc_descr_ref loc;
6355 if (! a || AT_class (a) != dw_val_class_loc)
6359 if (loc->dw_loc_opc != DW_OP_addr)
6362 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6363 loc->dw_loc_oprnd1.v.val_addr, "Address");
6364 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6365 get_AT_unsigned (die, DW_AT_byte_size),
6370 /* Output the terminator words. */
6371 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6372 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6376 /* Data structure containing information about input files. */
6379 char *path; /* Complete file name. */
6380 char *fname; /* File name part. */
6381 int length; /* Length of entire string. */
6382 int file_idx; /* Index in input file table. */
6383 int dir_idx; /* Index in directory table. */
6386 /* Data structure containing information about directories with source
6390 char *path; /* Path including directory name. */
6391 int length; /* Path length. */
6392 int prefix; /* Index of directory entry which is a prefix. */
6393 int count; /* Number of files in this directory. */
6394 int dir_idx; /* Index of directory used as base. */
6395 int used; /* Used in the end? */
6398 /* Callback function for file_info comparison. We sort by looking at
6399 the directories in the path. */
6401 file_info_cmp (p1, p2)
6405 const struct file_info *s1 = p1;
6406 const struct file_info *s2 = p2;
6410 /* Take care of file names without directories. */
6411 if (s1->path == s1->fname)
6413 else if (s2->path == s2->fname)
6416 cp1 = (unsigned char *) s1->path;
6417 cp2 = (unsigned char *) s2->path;
6423 /* Reached the end of the first path? */
6424 if (cp1 == (unsigned char *) s1->fname)
6425 /* It doesn't really matter in which order files from the
6426 same directory are sorted in. Therefore don't test for
6427 the second path reaching the end. */
6429 else if (cp2 == (unsigned char *) s2->fname)
6432 /* Character of current path component the same? */
6438 /* Output the directory table and the file name table. We try to minimize
6439 the total amount of memory needed. A heuristic is used to avoid large
6440 slowdowns with many input files. */
6442 output_file_names ()
6444 struct file_info *files;
6445 struct dir_info *dirs;
6454 /* Allocate the various arrays we need. */
6455 files = (struct file_info *) alloca (file_table.in_use
6456 * sizeof (struct file_info));
6457 dirs = (struct dir_info *) alloca (file_table.in_use
6458 * sizeof (struct dir_info));
6460 /* Sort the file names. */
6461 for (i = 1; i < (int) file_table.in_use; ++i)
6465 /* Skip all leading "./". */
6466 f = file_table.table[i];
6467 while (f[0] == '.' && f[1] == '/')
6470 /* Create a new array entry. */
6472 files[i].length = strlen (f);
6473 files[i].file_idx = i;
6475 /* Search for the file name part. */
6476 f = strrchr (f, '/');
6477 files[i].fname = f == NULL ? files[i].path : f + 1;
6479 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6481 /* Find all the different directories used. */
6482 dirs[0].path = files[1].path;
6483 dirs[0].length = files[1].fname - files[1].path;
6484 dirs[0].prefix = -1;
6486 dirs[0].dir_idx = 0;
6488 files[1].dir_idx = 0;
6491 for (i = 2; i < (int) file_table.in_use; ++i)
6492 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6493 && memcmp (dirs[ndirs - 1].path, files[i].path,
6494 dirs[ndirs - 1].length) == 0)
6496 /* Same directory as last entry. */
6497 files[i].dir_idx = ndirs - 1;
6498 ++dirs[ndirs - 1].count;
6504 /* This is a new directory. */
6505 dirs[ndirs].path = files[i].path;
6506 dirs[ndirs].length = files[i].fname - files[i].path;
6507 dirs[ndirs].count = 1;
6508 dirs[ndirs].dir_idx = ndirs;
6509 dirs[ndirs].used = 0;
6510 files[i].dir_idx = ndirs;
6512 /* Search for a prefix. */
6513 dirs[ndirs].prefix = -1;
6514 for (j = 0; j < ndirs; ++j)
6515 if (dirs[j].length < dirs[ndirs].length
6516 && dirs[j].length > 1
6517 && (dirs[ndirs].prefix == -1
6518 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6519 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6520 dirs[ndirs].prefix = j;
6525 /* Now to the actual work. We have to find a subset of the
6526 directories which allow expressing the file name using references
6527 to the directory table with the least amount of characters. We
6528 do not do an exhaustive search where we would have to check out
6529 every combination of every single possible prefix. Instead we
6530 use a heuristic which provides nearly optimal results in most
6531 cases and never is much off. */
6532 saved = (int *) alloca (ndirs * sizeof (int));
6533 savehere = (int *) alloca (ndirs * sizeof (int));
6535 memset (saved, '\0', ndirs * sizeof (saved[0]));
6536 for (i = 0; i < ndirs; ++i)
6541 /* We can always save some space for the current directory. But
6542 this does not mean it will be enough to justify adding the
6544 savehere[i] = dirs[i].length;
6545 total = (savehere[i] - saved[i]) * dirs[i].count;
6547 for (j = i + 1; j < ndirs; ++j)
6551 if (saved[j] < dirs[i].length)
6553 /* Determine whether the dirs[i] path is a prefix of the
6558 while (k != -1 && k != i)
6563 /* Yes it is. We can possibly safe some memory but
6564 writing the filenames in dirs[j] relative to
6566 savehere[j] = dirs[i].length;
6567 total += (savehere[j] - saved[j]) * dirs[j].count;
6572 /* Check whether we can safe enough to justify adding the dirs[i]
6574 if (total > dirs[i].length + 1)
6576 /* It's worthwhile adding. */
6577 for (j = i; j < ndirs; ++j)
6578 if (savehere[j] > 0)
6580 /* Remember how much we saved for this directory so far. */
6581 saved[j] = savehere[j];
6583 /* Remember the prefix directory. */
6584 dirs[j].dir_idx = i;
6589 /* We have to emit them in the order they appear in the file_table
6590 array since the index is used in the debug info generation. To
6591 do this efficiently we generate a back-mapping of the indices
6593 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6594 for (i = 1; i < (int) file_table.in_use; ++i)
6596 backmap[files[i].file_idx] = i;
6597 /* Mark this directory as used. */
6598 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6601 /* That was it. We are ready to emit the information. First the
6602 directory name table. Here we have to make sure that the first
6603 actually emitted directory name has the index one. Zero is
6604 reserved for the current working directory. Make sure we do not
6605 confuse these indices with the one for the constructed table
6606 (even though most of the time they are identical). */
6608 idx_offset = dirs[0].length > 0 ? 1 : 0;
6609 for (i = 1 - idx_offset; i < ndirs; ++i)
6610 if (dirs[i].used != 0)
6612 dirs[i].used = idx++;
6613 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6614 "Directory Entry: 0x%x", dirs[i].used);
6616 dw2_asm_output_data (1, 0, "End directory table");
6618 /* Correct the index for the current working directory entry if it
6620 if (idx_offset == 0)
6623 /* Now write all the file names. */
6624 for (i = 1; i < (int) file_table.in_use; ++i)
6626 int file_idx = backmap[i];
6627 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6629 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6630 "File Entry: 0x%x", i);
6632 /* Include directory index. */
6633 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6635 /* Modification time. */
6636 dw2_asm_output_data_uleb128 (0, NULL);
6638 /* File length in bytes. */
6639 dw2_asm_output_data_uleb128 (0, NULL);
6641 dw2_asm_output_data (1, 0, "End file name table");
6645 /* Output the source line number correspondence information. This
6646 information goes into the .debug_line section. */
6651 char l1[20], l2[20], p1[20], p2[20];
6652 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6653 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6654 register unsigned opc;
6655 register unsigned n_op_args;
6656 register unsigned long lt_index;
6657 register unsigned long current_line;
6658 register long line_offset;
6659 register long line_delta;
6660 register unsigned long current_file;
6661 register unsigned long function;
6663 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6664 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6665 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6666 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6668 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6669 "Length of Source Line Info");
6670 ASM_OUTPUT_LABEL (asm_out_file, l1);
6672 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6674 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6675 ASM_OUTPUT_LABEL (asm_out_file, p1);
6677 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6678 "Minimum Instruction Length");
6680 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6681 "Default is_stmt_start flag");
6683 dw2_asm_output_data (1, DWARF_LINE_BASE,
6684 "Line Base Value (Special Opcodes)");
6686 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6687 "Line Range Value (Special Opcodes)");
6689 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6690 "Special Opcode Base");
6692 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6696 case DW_LNS_advance_pc:
6697 case DW_LNS_advance_line:
6698 case DW_LNS_set_file:
6699 case DW_LNS_set_column:
6700 case DW_LNS_fixed_advance_pc:
6708 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6712 /* Write out the information about the files we use. */
6713 output_file_names ();
6714 ASM_OUTPUT_LABEL (asm_out_file, p2);
6716 /* We used to set the address register to the first location in the text
6717 section here, but that didn't accomplish anything since we already
6718 have a line note for the opening brace of the first function. */
6720 /* Generate the line number to PC correspondence table, encoded as
6721 a series of state machine operations. */
6724 strcpy (prev_line_label, text_section_label);
6725 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6727 register dw_line_info_ref line_info = &line_info_table[lt_index];
6730 /* Disable this optimization for now; GDB wants to see two line notes
6731 at the beginning of a function so it can find the end of the
6734 /* Don't emit anything for redundant notes. Just updating the
6735 address doesn't accomplish anything, because we already assume
6736 that anything after the last address is this line. */
6737 if (line_info->dw_line_num == current_line
6738 && line_info->dw_file_num == current_file)
6742 /* Emit debug info for the address of the current line.
6744 Unfortunately, we have little choice here currently, and must always
6745 use the most general form. Gcc does not know the address delta
6746 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
6747 attributes which will give an upper bound on the address range. We
6748 could perhaps use length attributes to determine when it is safe to
6749 use DW_LNS_fixed_advance_pc. */
6751 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6754 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6755 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6756 "DW_LNS_fixed_advance_pc");
6757 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6761 /* This can handle any delta. This takes
6762 4+DWARF2_ADDR_SIZE bytes. */
6763 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6764 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6765 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6766 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6768 strcpy (prev_line_label, line_label);
6770 /* Emit debug info for the source file of the current line, if
6771 different from the previous line. */
6772 if (line_info->dw_file_num != current_file)
6774 current_file = line_info->dw_file_num;
6775 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6776 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6777 file_table.table[current_file]);
6780 /* Emit debug info for the current line number, choosing the encoding
6781 that uses the least amount of space. */
6782 if (line_info->dw_line_num != current_line)
6784 line_offset = line_info->dw_line_num - current_line;
6785 line_delta = line_offset - DWARF_LINE_BASE;
6786 current_line = line_info->dw_line_num;
6787 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6789 /* This can handle deltas from -10 to 234, using the current
6790 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6792 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6793 "line %lu", current_line);
6797 /* This can handle any delta. This takes at least 4 bytes,
6798 depending on the value being encoded. */
6799 dw2_asm_output_data (1, DW_LNS_advance_line,
6800 "advance to line %lu", current_line);
6801 dw2_asm_output_data_sleb128 (line_offset, NULL);
6802 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6807 /* We still need to start a new row, so output a copy insn. */
6808 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6812 /* Emit debug info for the address of the end of the function. */
6815 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6816 "DW_LNS_fixed_advance_pc");
6817 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
6821 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6822 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6823 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6824 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
6827 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6828 dw2_asm_output_data_uleb128 (1, NULL);
6829 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6834 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6836 register dw_separate_line_info_ref line_info
6837 = &separate_line_info_table[lt_index];
6840 /* Don't emit anything for redundant notes. */
6841 if (line_info->dw_line_num == current_line
6842 && line_info->dw_file_num == current_file
6843 && line_info->function == function)
6847 /* Emit debug info for the address of the current line. If this is
6848 a new function, or the first line of a function, then we need
6849 to handle it differently. */
6850 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6852 if (function != line_info->function)
6854 function = line_info->function;
6856 /* Set the address register to the first line in the function */
6857 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6858 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6859 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6860 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6864 /* ??? See the DW_LNS_advance_pc comment above. */
6867 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6868 "DW_LNS_fixed_advance_pc");
6869 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6873 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6874 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6875 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6876 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6879 strcpy (prev_line_label, line_label);
6881 /* Emit debug info for the source file of the current line, if
6882 different from the previous line. */
6883 if (line_info->dw_file_num != current_file)
6885 current_file = line_info->dw_file_num;
6886 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6887 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6888 file_table.table[current_file]);
6891 /* Emit debug info for the current line number, choosing the encoding
6892 that uses the least amount of space. */
6893 if (line_info->dw_line_num != current_line)
6895 line_offset = line_info->dw_line_num - current_line;
6896 line_delta = line_offset - DWARF_LINE_BASE;
6897 current_line = line_info->dw_line_num;
6898 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6899 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6900 "line %lu", current_line);
6903 dw2_asm_output_data (1, DW_LNS_advance_line,
6904 "advance to line %lu", current_line);
6905 dw2_asm_output_data_sleb128 (line_offset, NULL);
6906 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6910 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6917 /* If we're done with a function, end its sequence. */
6918 if (lt_index == separate_line_info_table_in_use
6919 || separate_line_info_table[lt_index].function != function)
6924 /* Emit debug info for the address of the end of the function. */
6925 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6928 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6929 "DW_LNS_fixed_advance_pc");
6930 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6934 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6935 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6936 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6937 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6940 /* Output the marker for the end of this sequence. */
6941 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6942 dw2_asm_output_data_uleb128 (1, NULL);
6943 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6947 /* Output the marker for the end of the line number info. */
6948 ASM_OUTPUT_LABEL (asm_out_file, l2);
6951 /* Given a pointer to a tree node for some base type, return a pointer to
6952 a DIE that describes the given type.
6954 This routine must only be called for GCC type nodes that correspond to
6955 Dwarf base (fundamental) types. */
6958 base_type_die (type)
6961 register dw_die_ref base_type_result;
6962 register const char *type_name;
6963 register enum dwarf_type encoding;
6964 register tree name = TYPE_NAME (type);
6966 if (TREE_CODE (type) == ERROR_MARK
6967 || TREE_CODE (type) == VOID_TYPE)
6972 if (TREE_CODE (name) == TYPE_DECL)
6973 name = DECL_NAME (name);
6975 type_name = IDENTIFIER_POINTER (name);
6978 type_name = "__unknown__";
6980 switch (TREE_CODE (type))
6983 /* Carefully distinguish the C character types, without messing
6984 up if the language is not C. Note that we check only for the names
6985 that contain spaces; other names might occur by coincidence in other
6987 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6988 && (type == char_type_node
6989 || ! strcmp (type_name, "signed char")
6990 || ! strcmp (type_name, "unsigned char"))))
6992 if (TREE_UNSIGNED (type))
6993 encoding = DW_ATE_unsigned;
6995 encoding = DW_ATE_signed;
6998 /* else fall through. */
7001 /* GNU Pascal/Ada CHAR type. Not used in C. */
7002 if (TREE_UNSIGNED (type))
7003 encoding = DW_ATE_unsigned_char;
7005 encoding = DW_ATE_signed_char;
7009 encoding = DW_ATE_float;
7012 /* Dwarf2 doesn't know anything about complex ints, so use
7013 a user defined type for it. */
7015 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7016 encoding = DW_ATE_complex_float;
7018 encoding = DW_ATE_lo_user;
7022 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7023 encoding = DW_ATE_boolean;
7027 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7030 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7031 if (demangle_name_func)
7032 type_name = (*demangle_name_func) (type_name);
7034 add_AT_string (base_type_result, DW_AT_name, type_name);
7035 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7036 int_size_in_bytes (type));
7037 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7039 return base_type_result;
7042 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7043 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7044 a given type is generally the same as the given type, except that if the
7045 given type is a pointer or reference type, then the root type of the given
7046 type is the root type of the "basis" type for the pointer or reference
7047 type. (This definition of the "root" type is recursive.) Also, the root
7048 type of a `const' qualified type or a `volatile' qualified type is the
7049 root type of the given type without the qualifiers. */
7055 if (TREE_CODE (type) == ERROR_MARK)
7056 return error_mark_node;
7058 switch (TREE_CODE (type))
7061 return error_mark_node;
7064 case REFERENCE_TYPE:
7065 return type_main_variant (root_type (TREE_TYPE (type)));
7068 return type_main_variant (type);
7072 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7073 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7079 switch (TREE_CODE (type))
7094 case QUAL_UNION_TYPE:
7099 case REFERENCE_TYPE:
7113 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7114 entry that chains various modifiers in front of the given type. */
7117 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7119 register int is_const_type;
7120 register int is_volatile_type;
7121 register dw_die_ref context_die;
7123 register enum tree_code code = TREE_CODE (type);
7124 register dw_die_ref mod_type_die = NULL;
7125 register dw_die_ref sub_die = NULL;
7126 register tree item_type = NULL;
7128 if (code != ERROR_MARK)
7130 tree qualified_type;
7132 /* See if we already have the appropriately qualified variant of
7135 = get_qualified_type (type,
7136 ((is_const_type ? TYPE_QUAL_CONST : 0)
7138 ? TYPE_QUAL_VOLATILE : 0)));
7139 /* If we do, then we can just use its DIE, if it exists. */
7142 mod_type_die = lookup_type_die (qualified_type);
7144 return mod_type_die;
7147 /* Handle C typedef types. */
7148 if (qualified_type && TYPE_NAME (qualified_type)
7149 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7150 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7152 tree type_name = TYPE_NAME (qualified_type);
7153 tree dtype = TREE_TYPE (type_name);
7154 if (qualified_type == dtype)
7156 /* For a named type, use the typedef. */
7157 gen_type_die (qualified_type, context_die);
7158 mod_type_die = lookup_type_die (qualified_type);
7161 else if (is_const_type < TYPE_READONLY (dtype)
7162 || is_volatile_type < TYPE_VOLATILE (dtype))
7163 /* cv-unqualified version of named type. Just use the unnamed
7164 type to which it refers. */
7166 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7167 is_const_type, is_volatile_type,
7169 /* Else cv-qualified version of named type; fall through. */
7175 else if (is_const_type)
7177 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7178 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7180 else if (is_volatile_type)
7182 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7183 sub_die = modified_type_die (type, 0, 0, context_die);
7185 else if (code == POINTER_TYPE)
7187 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7188 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7190 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7192 item_type = TREE_TYPE (type);
7194 else if (code == REFERENCE_TYPE)
7196 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7197 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7199 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7201 item_type = TREE_TYPE (type);
7203 else if (is_base_type (type))
7204 mod_type_die = base_type_die (type);
7207 gen_type_die (type, context_die);
7209 /* We have to get the type_main_variant here (and pass that to the
7210 `lookup_type_die' routine) because the ..._TYPE node we have
7211 might simply be a *copy* of some original type node (where the
7212 copy was created to help us keep track of typedef names) and
7213 that copy might have a different TYPE_UID from the original
7215 mod_type_die = lookup_type_die (type_main_variant (type));
7216 if (mod_type_die == NULL)
7220 /* We want to equate the qualified type to the die below. */
7222 type = qualified_type;
7225 equate_type_number_to_die (type, mod_type_die);
7227 /* We must do this after the equate_type_number_to_die call, in case
7228 this is a recursive type. This ensures that the modified_type_die
7229 recursion will terminate even if the type is recursive. Recursive
7230 types are possible in Ada. */
7231 sub_die = modified_type_die (item_type,
7232 TYPE_READONLY (item_type),
7233 TYPE_VOLATILE (item_type),
7236 if (sub_die != NULL)
7237 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7239 return mod_type_die;
7242 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7243 an enumerated type. */
7249 return TREE_CODE (type) == ENUMERAL_TYPE;
7252 /* Return the register number described by a given RTL node. */
7258 register unsigned regno = REGNO (rtl);
7260 if (regno >= FIRST_PSEUDO_REGISTER)
7262 warning ("internal regno botch: regno = %d\n", regno);
7266 regno = DBX_REGISTER_NUMBER (regno);
7270 /* Return a location descriptor that designates a machine register. */
7272 static dw_loc_descr_ref
7273 reg_loc_descriptor (rtl)
7276 register dw_loc_descr_ref loc_result = NULL;
7277 register unsigned reg = reg_number (rtl);
7280 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7282 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7287 /* Return a location descriptor that designates a constant. */
7289 static dw_loc_descr_ref
7290 int_loc_descriptor (i)
7293 enum dwarf_location_atom op;
7295 /* Pick the smallest representation of a constant, rather than just
7296 defaulting to the LEB encoding. */
7300 op = DW_OP_lit0 + i;
7303 else if (i <= 0xffff)
7305 else if (HOST_BITS_PER_WIDE_INT == 32
7315 else if (i >= -0x8000)
7317 else if (HOST_BITS_PER_WIDE_INT == 32
7318 || i >= -0x80000000)
7324 return new_loc_descr (op, i, 0);
7327 /* Return a location descriptor that designates a base+offset location. */
7329 static dw_loc_descr_ref
7330 based_loc_descr (reg, offset)
7334 register dw_loc_descr_ref loc_result;
7335 /* For the "frame base", we use the frame pointer or stack pointer
7336 registers, since the RTL for local variables is relative to one of
7338 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7339 ? HARD_FRAME_POINTER_REGNUM
7340 : STACK_POINTER_REGNUM);
7343 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7345 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7347 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7352 /* Return true if this RTL expression describes a base+offset calculation. */
7358 return (GET_CODE (rtl) == PLUS
7359 && ((GET_CODE (XEXP (rtl, 0)) == REG
7360 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7363 /* The following routine converts the RTL for a variable or parameter
7364 (resident in memory) into an equivalent Dwarf representation of a
7365 mechanism for getting the address of that same variable onto the top of a
7366 hypothetical "address evaluation" stack.
7368 When creating memory location descriptors, we are effectively transforming
7369 the RTL for a memory-resident object into its Dwarf postfix expression
7370 equivalent. This routine recursively descends an RTL tree, turning
7371 it into Dwarf postfix code as it goes.
7373 MODE is the mode of the memory reference, needed to handle some
7374 autoincrement addressing modes. */
7376 static dw_loc_descr_ref
7377 mem_loc_descriptor (rtl, mode)
7379 enum machine_mode mode;
7381 dw_loc_descr_ref mem_loc_result = NULL;
7382 /* Note that for a dynamically sized array, the location we will generate a
7383 description of here will be the lowest numbered location which is
7384 actually within the array. That's *not* necessarily the same as the
7385 zeroth element of the array. */
7387 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7388 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7391 switch (GET_CODE (rtl))
7396 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7397 just fall into the SUBREG code. */
7402 /* The case of a subreg may arise when we have a local (register)
7403 variable or a formal (register) parameter which doesn't quite fill
7404 up an entire register. For now, just assume that it is
7405 legitimate to make the Dwarf info refer to the whole register which
7406 contains the given subreg. */
7407 rtl = SUBREG_REG (rtl);
7412 /* Whenever a register number forms a part of the description of the
7413 method for calculating the (dynamic) address of a memory resident
7414 object, DWARF rules require the register number be referred to as
7415 a "base register". This distinction is not based in any way upon
7416 what category of register the hardware believes the given register
7417 belongs to. This is strictly DWARF terminology we're dealing with
7418 here. Note that in cases where the location of a memory-resident
7419 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7420 OP_CONST (0)) the actual DWARF location descriptor that we generate
7421 may just be OP_BASEREG (basereg). This may look deceptively like
7422 the object in question was allocated to a register (rather than in
7423 memory) so DWARF consumers need to be aware of the subtle
7424 distinction between OP_REG and OP_BASEREG. */
7425 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7429 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7430 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7434 /* Some ports can transform a symbol ref into a label ref, because
7435 the symbol ref is too far away and has to be dumped into a constant
7439 /* Alternatively, the symbol in the constant pool might be referenced
7440 by a different symbol. */
7441 if (GET_CODE (rtl) == SYMBOL_REF
7442 && CONSTANT_POOL_ADDRESS_P (rtl))
7444 rtx tmp = get_pool_constant (rtl);
7445 if (GET_CODE (tmp) == SYMBOL_REF)
7449 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7450 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7451 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7455 /* Extract the PLUS expression nested inside and fall into
7457 rtl = XEXP (rtl, 1);
7462 /* Turn these into a PLUS expression and fall into the PLUS code
7464 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7465 GEN_INT (GET_CODE (rtl) == PRE_INC
7466 ? GET_MODE_UNIT_SIZE (mode)
7467 : -GET_MODE_UNIT_SIZE (mode)));
7473 if (is_based_loc (rtl))
7474 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7475 INTVAL (XEXP (rtl, 1)));
7478 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7480 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7481 && INTVAL (XEXP (rtl, 1)) >= 0)
7483 add_loc_descr (&mem_loc_result,
7484 new_loc_descr (DW_OP_plus_uconst,
7485 INTVAL (XEXP (rtl, 1)), 0));
7489 add_loc_descr (&mem_loc_result,
7490 mem_loc_descriptor (XEXP (rtl, 1), mode));
7491 add_loc_descr (&mem_loc_result,
7492 new_loc_descr (DW_OP_plus, 0, 0));
7498 /* If a pseudo-reg is optimized away, it is possible for it to
7499 be replaced with a MEM containing a multiply. */
7500 add_loc_descr (&mem_loc_result,
7501 mem_loc_descriptor (XEXP (rtl, 0), mode));
7502 add_loc_descr (&mem_loc_result,
7503 mem_loc_descriptor (XEXP (rtl, 1), mode));
7504 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7508 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7515 return mem_loc_result;
7518 /* Return a descriptor that describes the concatenation of two locations.
7519 This is typically a complex variable. */
7521 static dw_loc_descr_ref
7522 concat_loc_descriptor (x0, x1)
7523 register rtx x0, x1;
7525 dw_loc_descr_ref cc_loc_result = NULL;
7527 if (!is_pseudo_reg (x0)
7528 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7529 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7530 add_loc_descr (&cc_loc_result,
7531 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7533 if (!is_pseudo_reg (x1)
7534 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7535 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7536 add_loc_descr (&cc_loc_result,
7537 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7539 return cc_loc_result;
7542 /* Output a proper Dwarf location descriptor for a variable or parameter
7543 which is either allocated in a register or in a memory location. For a
7544 register, we just generate an OP_REG and the register number. For a
7545 memory location we provide a Dwarf postfix expression describing how to
7546 generate the (dynamic) address of the object onto the address stack. */
7548 static dw_loc_descr_ref
7549 loc_descriptor (rtl)
7552 dw_loc_descr_ref loc_result = NULL;
7553 switch (GET_CODE (rtl))
7556 /* The case of a subreg may arise when we have a local (register)
7557 variable or a formal (register) parameter which doesn't quite fill
7558 up an entire register. For now, just assume that it is
7559 legitimate to make the Dwarf info refer to the whole register which
7560 contains the given subreg. */
7561 rtl = SUBREG_REG (rtl);
7566 loc_result = reg_loc_descriptor (rtl);
7570 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7574 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7584 /* Similar, but generate the descriptor from trees instead of rtl.
7585 This comes up particularly with variable length arrays. */
7587 static dw_loc_descr_ref
7588 loc_descriptor_from_tree (loc, addressp)
7592 dw_loc_descr_ref ret = NULL;
7593 int indirect_size = 0;
7594 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7595 enum dwarf_location_atom op;
7597 /* ??? Most of the time we do not take proper care for sign/zero
7598 extending the values properly. Hopefully this won't be a real
7601 switch (TREE_CODE (loc))
7606 case WITH_RECORD_EXPR:
7607 /* This case involves extracting fields from an object to determine the
7608 position of other fields. We don't try to encode this here. The
7609 only user of this is Ada, which encodes the needed information using
7610 the names of types. */
7616 rtx rtl = rtl_for_decl_location (loc);
7617 enum machine_mode mode = DECL_MODE (loc);
7619 if (rtl == NULL_RTX)
7621 else if (CONSTANT_P (rtl))
7623 ret = new_loc_descr (DW_OP_addr, 0, 0);
7624 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7625 ret->dw_loc_oprnd1.v.val_addr = rtl;
7626 indirect_size = GET_MODE_SIZE (mode);
7630 if (GET_CODE (rtl) == MEM)
7632 indirect_size = GET_MODE_SIZE (mode);
7633 rtl = XEXP (rtl, 0);
7635 ret = mem_loc_descriptor (rtl, mode);
7641 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7642 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7647 case NON_LVALUE_EXPR:
7649 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7654 case ARRAY_RANGE_REF:
7657 HOST_WIDE_INT bitsize, bitpos, bytepos;
7658 enum machine_mode mode;
7660 unsigned int alignment;
7662 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7663 &unsignedp, &volatilep, &alignment);
7664 ret = loc_descriptor_from_tree (obj, 1);
7666 if (offset != NULL_TREE)
7668 /* Variable offset. */
7669 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7670 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7675 /* We cannot address anything not on a unit boundary. */
7676 if (bitpos % BITS_PER_UNIT != 0)
7681 if (bitpos % BITS_PER_UNIT != 0
7682 || bitsize % BITS_PER_UNIT != 0)
7684 /* ??? We could handle this by loading and shifting etc.
7685 Wait until someone needs it before expending the effort. */
7689 indirect_size = bitsize / BITS_PER_UNIT;
7692 bytepos = bitpos / BITS_PER_UNIT;
7694 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7695 else if (bytepos < 0)
7697 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7698 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7704 if (host_integerp (loc, 0))
7705 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7717 case TRUNC_DIV_EXPR:
7723 case TRUNC_MOD_EXPR:
7733 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7736 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7737 && host_integerp (TREE_OPERAND (loc, 1), 0))
7739 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7740 add_loc_descr (&ret,
7741 new_loc_descr (DW_OP_plus_uconst,
7742 tree_low_cst (TREE_OPERAND (loc, 1),
7750 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7755 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7760 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7765 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7777 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7778 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7779 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7793 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7794 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7798 loc = build (COND_EXPR, TREE_TYPE (loc),
7799 build (LT_EXPR, integer_type_node,
7800 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
7801 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
7806 dw_loc_descr_ref bra_node, jump_node, tmp;
7808 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7809 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
7810 add_loc_descr (&ret, bra_node);
7812 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
7813 add_loc_descr (&ret, tmp);
7814 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
7815 add_loc_descr (&ret, jump_node);
7817 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
7818 add_loc_descr (&ret, tmp);
7819 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7820 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
7822 /* ??? Need a node to point the skip at. Use a nop. */
7823 tmp = new_loc_descr (DW_OP_nop, 0, 0);
7824 add_loc_descr (&ret, tmp);
7825 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7826 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
7834 /* If we can't fill the request for an address, die. */
7835 if (addressp && indirect_size == 0)
7838 /* If we've got an address and don't want one, dereference. */
7839 if (!addressp && indirect_size > 0)
7841 if (indirect_size > DWARF2_ADDR_SIZE)
7843 if (indirect_size == DWARF2_ADDR_SIZE)
7846 op = DW_OP_deref_size;
7847 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
7853 /* Given a value, round it up to the lowest multiple of `boundary'
7854 which is not less than the value itself. */
7856 static inline HOST_WIDE_INT
7857 ceiling (value, boundary)
7858 HOST_WIDE_INT value;
7859 unsigned int boundary;
7861 return (((value + boundary - 1) / boundary) * boundary);
7864 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7865 pointer to the declared type for the relevant field variable, or return
7866 `integer_type_node' if the given node turns out to be an
7875 if (TREE_CODE (decl) == ERROR_MARK)
7876 return integer_type_node;
7878 type = DECL_BIT_FIELD_TYPE (decl);
7879 if (type == NULL_TREE)
7880 type = TREE_TYPE (decl);
7885 /* Given a pointer to a tree node, return the alignment in bits for
7886 it, or else return BITS_PER_WORD if the node actually turns out to
7887 be an ERROR_MARK node. */
7889 static inline unsigned
7890 simple_type_align_in_bits (type)
7893 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7896 static inline unsigned
7897 simple_decl_align_in_bits (decl)
7900 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
7903 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7904 node, return the size in bits for the type if it is a constant, or else
7905 return the alignment for the type if the type's size is not constant, or
7906 else return BITS_PER_WORD if the type actually turns out to be an
7909 static inline unsigned HOST_WIDE_INT
7910 simple_type_size_in_bits (type)
7913 tree type_size_tree;
7915 if (TREE_CODE (type) == ERROR_MARK)
7916 return BITS_PER_WORD;
7917 type_size_tree = TYPE_SIZE (type);
7919 if (type_size_tree == NULL_TREE)
7921 if (! host_integerp (type_size_tree, 1))
7922 return TYPE_ALIGN (type);
7923 return tree_low_cst (type_size_tree, 1);
7926 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7927 return the byte offset of the lowest addressed byte of the "containing
7928 object" for the given FIELD_DECL, or return 0 if we are unable to
7929 determine what that offset is, either because the argument turns out to
7930 be a pointer to an ERROR_MARK node, or because the offset is actually
7931 variable. (We can't handle the latter case just yet). */
7933 static HOST_WIDE_INT
7934 field_byte_offset (decl)
7937 unsigned int type_align_in_bits;
7938 unsigned int decl_align_in_bits;
7939 unsigned HOST_WIDE_INT type_size_in_bits;
7940 HOST_WIDE_INT object_offset_in_bits;
7941 HOST_WIDE_INT object_offset_in_bytes;
7943 tree field_size_tree;
7944 HOST_WIDE_INT bitpos_int;
7945 HOST_WIDE_INT deepest_bitpos;
7946 unsigned HOST_WIDE_INT field_size_in_bits;
7948 if (TREE_CODE (decl) == ERROR_MARK)
7951 if (TREE_CODE (decl) != FIELD_DECL)
7954 type = field_type (decl);
7955 field_size_tree = DECL_SIZE (decl);
7957 /* The size could be unspecified if there was an error, or for
7958 a flexible array member. */
7959 if (! field_size_tree)
7960 field_size_tree = bitsize_zero_node;
7962 /* We cannot yet cope with fields whose positions are variable, so
7963 for now, when we see such things, we simply return 0. Someday, we may
7964 be able to handle such cases, but it will be damn difficult. */
7965 if (! host_integerp (bit_position (decl), 0))
7968 bitpos_int = int_bit_position (decl);
7970 /* If we don't know the size of the field, pretend it's a full word. */
7971 if (host_integerp (field_size_tree, 1))
7972 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7974 field_size_in_bits = BITS_PER_WORD;
7976 type_size_in_bits = simple_type_size_in_bits (type);
7977 type_align_in_bits = simple_type_align_in_bits (type);
7978 decl_align_in_bits = simple_decl_align_in_bits (decl);
7980 /* Note that the GCC front-end doesn't make any attempt to keep track of
7981 the starting bit offset (relative to the start of the containing
7982 structure type) of the hypothetical "containing object" for a bit-
7983 field. Thus, when computing the byte offset value for the start of the
7984 "containing object" of a bit-field, we must deduce this information on
7985 our own. This can be rather tricky to do in some cases. For example,
7986 handling the following structure type definition when compiling for an
7987 i386/i486 target (which only aligns long long's to 32-bit boundaries)
7990 struct S { int field1; long long field2:31; };
7992 Fortunately, there is a simple rule-of-thumb which can be
7993 used in such cases. When compiling for an i386/i486, GCC will allocate
7994 8 bytes for the structure shown above. It decides to do this based upon
7995 one simple rule for bit-field allocation. Quite simply, GCC allocates
7996 each "containing object" for each bit-field at the first (i.e. lowest
7997 addressed) legitimate alignment boundary (based upon the required
7998 minimum alignment for the declared type of the field) which it can
7999 possibly use, subject to the condition that there is still enough
8000 available space remaining in the containing object (when allocated at
8001 the selected point) to fully accommodate all of the bits of the
8002 bit-field itself. This simple rule makes it obvious why GCC allocates
8003 8 bytes for each object of the structure type shown above. When looking
8004 for a place to allocate the "containing object" for `field2', the
8005 compiler simply tries to allocate a 64-bit "containing object" at each
8006 successive 32-bit boundary (starting at zero) until it finds a place to
8007 allocate that 64- bit field such that at least 31 contiguous (and
8008 previously unallocated) bits remain within that selected 64 bit field.
8009 (As it turns out, for the example above, the compiler finds that it is
8010 OK to allocate the "containing object" 64-bit field at bit-offset zero
8011 within the structure type.) Here we attempt to work backwards from the
8012 limited set of facts we're given, and we try to deduce from those facts,
8013 where GCC must have believed that the containing object started (within
8014 the structure type). The value we deduce is then used (by the callers of
8015 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8016 for fields (both bit-fields and, in the case of DW_AT_location, regular
8019 /* Figure out the bit-distance from the start of the structure to the
8020 "deepest" bit of the bit-field. */
8021 deepest_bitpos = bitpos_int + field_size_in_bits;
8023 /* This is the tricky part. Use some fancy footwork to deduce where the
8024 lowest addressed bit of the containing object must be. */
8025 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8027 /* Round up to type_align by default. This works best for bitfields. */
8028 object_offset_in_bits += type_align_in_bits - 1;
8029 object_offset_in_bits /= type_align_in_bits;
8030 object_offset_in_bits *= type_align_in_bits;
8032 if (object_offset_in_bits > bitpos_int)
8034 /* Sigh, the decl must be packed. */
8035 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8037 /* Round up to decl_align instead. */
8038 object_offset_in_bits += decl_align_in_bits - 1;
8039 object_offset_in_bits /= decl_align_in_bits;
8040 object_offset_in_bits *= decl_align_in_bits;
8043 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8045 return object_offset_in_bytes;
8048 /* The following routines define various Dwarf attributes and any data
8049 associated with them. */
8051 /* Add a location description attribute value to a DIE.
8053 This emits location attributes suitable for whole variables and
8054 whole parameters. Note that the location attributes for struct fields are
8055 generated by the routine `data_member_location_attribute' below. */
8058 add_AT_location_description (die, attr_kind, rtl)
8060 enum dwarf_attribute attr_kind;
8063 /* Handle a special case. If we are about to output a location descriptor
8064 for a variable or parameter which has been optimized out of existence,
8065 don't do that. A variable which has been optimized out
8066 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8067 Currently, in some rare cases, variables can have DECL_RTL values which
8068 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8069 elsewhere in the compiler. We treat such cases as if the variable(s) in
8070 question had been optimized out of existence. */
8072 if (is_pseudo_reg (rtl)
8073 || (GET_CODE (rtl) == MEM
8074 && is_pseudo_reg (XEXP (rtl, 0)))
8075 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8076 references the internal argument pointer (a pseudo) in a function
8077 where all references to the internal argument pointer were
8078 eliminated via the optimizers. */
8079 || (GET_CODE (rtl) == MEM
8080 && GET_CODE (XEXP (rtl, 0)) == PLUS
8081 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8082 || (GET_CODE (rtl) == CONCAT
8083 && is_pseudo_reg (XEXP (rtl, 0))
8084 && is_pseudo_reg (XEXP (rtl, 1))))
8087 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8090 /* Attach the specialized form of location attribute used for data
8091 members of struct and union types. In the special case of a
8092 FIELD_DECL node which represents a bit-field, the "offset" part
8093 of this special location descriptor must indicate the distance
8094 in bytes from the lowest-addressed byte of the containing struct
8095 or union type to the lowest-addressed byte of the "containing
8096 object" for the bit-field. (See the `field_byte_offset' function
8097 above).. For any given bit-field, the "containing object" is a
8098 hypothetical object (of some integral or enum type) within which
8099 the given bit-field lives. The type of this hypothetical
8100 "containing object" is always the same as the declared type of
8101 the individual bit-field itself (for GCC anyway... the DWARF
8102 spec doesn't actually mandate this). Note that it is the size
8103 (in bytes) of the hypothetical "containing object" which will
8104 be given in the DW_AT_byte_size attribute for this bit-field.
8105 (See the `byte_size_attribute' function below.) It is also used
8106 when calculating the value of the DW_AT_bit_offset attribute.
8107 (See the `bit_offset_attribute' function below). */
8110 add_data_member_location_attribute (die, decl)
8111 register dw_die_ref die;
8114 register unsigned long offset;
8115 register dw_loc_descr_ref loc_descr;
8116 register enum dwarf_location_atom op;
8118 if (TREE_CODE (decl) == TREE_VEC)
8119 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8121 offset = field_byte_offset (decl);
8123 /* The DWARF2 standard says that we should assume that the structure address
8124 is already on the stack, so we can specify a structure field address
8125 by using DW_OP_plus_uconst. */
8127 #ifdef MIPS_DEBUGGING_INFO
8128 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8129 correctly. It works only if we leave the offset on the stack. */
8132 op = DW_OP_plus_uconst;
8135 loc_descr = new_loc_descr (op, offset, 0);
8136 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8139 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8140 does not have a "location" either in memory or in a register. These
8141 things can arise in GNU C when a constant is passed as an actual parameter
8142 to an inlined function. They can also arise in C++ where declared
8143 constants do not necessarily get memory "homes". */
8146 add_const_value_attribute (die, rtl)
8147 register dw_die_ref die;
8150 switch (GET_CODE (rtl))
8153 /* Note that a CONST_INT rtx could represent either an integer
8154 or a floating-point constant. A CONST_INT is used whenever
8155 the constant will fit into a single word. In all such
8156 cases, the original mode of the constant value is wiped
8157 out, and the CONST_INT rtx is assigned VOIDmode. */
8159 HOST_WIDE_INT val = INTVAL (rtl);
8161 /* ??? We really should be using HOST_WIDE_INT throughout. */
8164 if ((long) val != val)
8166 add_AT_int (die, DW_AT_const_value, (long) val);
8170 if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
8172 add_AT_int (die, DW_AT_const_value, (unsigned long) val);
8178 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8179 floating-point constant. A CONST_DOUBLE is used whenever the
8180 constant requires more than one word in order to be adequately
8181 represented. We output CONST_DOUBLEs as blocks. */
8183 register enum machine_mode mode = GET_MODE (rtl);
8185 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8187 register unsigned length = GET_MODE_SIZE (mode) / 4;
8188 long *array = (long *) xmalloc (sizeof (long) * length);
8191 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8195 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8199 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8204 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8211 add_AT_float (die, DW_AT_const_value, length, array);
8215 /* ??? We really should be using HOST_WIDE_INT throughout. */
8216 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8218 add_AT_long_long (die, DW_AT_const_value,
8219 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8225 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8231 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8235 /* In cases where an inlined instance of an inline function is passed
8236 the address of an `auto' variable (which is local to the caller) we
8237 can get a situation where the DECL_RTL of the artificial local
8238 variable (for the inlining) which acts as a stand-in for the
8239 corresponding formal parameter (of the inline function) will look
8240 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8241 exactly a compile-time constant expression, but it isn't the address
8242 of the (artificial) local variable either. Rather, it represents the
8243 *value* which the artificial local variable always has during its
8244 lifetime. We currently have no way to represent such quasi-constant
8245 values in Dwarf, so for now we just punt and generate nothing. */
8249 /* No other kinds of rtx should be possible here. */
8256 rtl_for_decl_location (decl)
8261 /* Here we have to decide where we are going to say the parameter "lives"
8262 (as far as the debugger is concerned). We only have a couple of
8263 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8265 DECL_RTL normally indicates where the parameter lives during most of the
8266 activation of the function. If optimization is enabled however, this
8267 could be either NULL or else a pseudo-reg. Both of those cases indicate
8268 that the parameter doesn't really live anywhere (as far as the code
8269 generation parts of GCC are concerned) during most of the function's
8270 activation. That will happen (for example) if the parameter is never
8271 referenced within the function.
8273 We could just generate a location descriptor here for all non-NULL
8274 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8275 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8276 where DECL_RTL is NULL or is a pseudo-reg.
8278 Note however that we can only get away with using DECL_INCOMING_RTL as
8279 a backup substitute for DECL_RTL in certain limited cases. In cases
8280 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8281 we can be sure that the parameter was passed using the same type as it is
8282 declared to have within the function, and that its DECL_INCOMING_RTL
8283 points us to a place where a value of that type is passed.
8285 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8286 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8287 because in these cases DECL_INCOMING_RTL points us to a value of some
8288 type which is *different* from the type of the parameter itself. Thus,
8289 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8290 such cases, the debugger would end up (for example) trying to fetch a
8291 `float' from a place which actually contains the first part of a
8292 `double'. That would lead to really incorrect and confusing
8293 output at debug-time.
8295 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8296 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8297 are a couple of exceptions however. On little-endian machines we can
8298 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8299 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8300 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8301 when (on a little-endian machine) a non-prototyped function has a
8302 parameter declared to be of type `short' or `char'. In such cases,
8303 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8304 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8305 passed `int' value. If the debugger then uses that address to fetch
8306 a `short' or a `char' (on a little-endian machine) the result will be
8307 the correct data, so we allow for such exceptional cases below.
8309 Note that our goal here is to describe the place where the given formal
8310 parameter lives during most of the function's activation (i.e. between
8311 the end of the prologue and the start of the epilogue). We'll do that
8312 as best as we can. Note however that if the given formal parameter is
8313 modified sometime during the execution of the function, then a stack
8314 backtrace (at debug-time) will show the function as having been
8315 called with the *new* value rather than the value which was
8316 originally passed in. This happens rarely enough that it is not
8317 a major problem, but it *is* a problem, and I'd like to fix it.
8319 A future version of dwarf2out.c may generate two additional
8320 attributes for any given DW_TAG_formal_parameter DIE which will
8321 describe the "passed type" and the "passed location" for the
8322 given formal parameter in addition to the attributes we now
8323 generate to indicate the "declared type" and the "active
8324 location" for each parameter. This additional set of attributes
8325 could be used by debuggers for stack backtraces. Separately, note
8326 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8327 NULL also. This happens (for example) for inlined-instances of
8328 inline function formal parameters which are never referenced.
8329 This really shouldn't be happening. All PARM_DECL nodes should
8330 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8331 doesn't currently generate these values for inlined instances of
8332 inline function parameters, so when we see such cases, we are
8333 just out-of-luck for the time being (until integrate.c
8336 /* Use DECL_RTL as the "location" unless we find something better. */
8337 rtl = DECL_RTL_IF_SET (decl);
8339 if (TREE_CODE (decl) == PARM_DECL)
8341 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8343 tree declared_type = type_main_variant (TREE_TYPE (decl));
8344 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8346 /* This decl represents a formal parameter which was optimized out.
8347 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8348 all* cases where (rtl == NULL_RTX) just below. */
8349 if (declared_type == passed_type)
8350 rtl = DECL_INCOMING_RTL (decl);
8351 else if (! BYTES_BIG_ENDIAN
8352 && TREE_CODE (declared_type) == INTEGER_TYPE
8353 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8354 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8355 rtl = DECL_INCOMING_RTL (decl);
8358 /* If the parm was passed in registers, but lives on the stack, then
8359 make a big endian correction if the mode of the type of the
8360 parameter is not the same as the mode of the rtl. */
8361 /* ??? This is the same series of checks that are made in dbxout.c before
8362 we reach the big endian correction code there. It isn't clear if all
8363 of these checks are necessary here, but keeping them all is the safe
8365 else if (GET_CODE (rtl) == MEM
8366 && XEXP (rtl, 0) != const0_rtx
8367 && ! CONSTANT_P (XEXP (rtl, 0))
8368 /* Not passed in memory. */
8369 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8370 /* Not passed by invisible reference. */
8371 && (GET_CODE (XEXP (rtl, 0)) != REG
8372 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8373 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8374 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8375 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8378 /* Big endian correction check. */
8380 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8381 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8384 int offset = (UNITS_PER_WORD
8385 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8386 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8387 plus_constant (XEXP (rtl, 0), offset));
8391 if (rtl != NULL_RTX)
8393 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8394 #ifdef LEAF_REG_REMAP
8395 if (current_function_uses_only_leaf_regs)
8396 leaf_renumber_regs_insn (rtl);
8403 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8404 data attribute for a variable or a parameter. We generate the
8405 DW_AT_const_value attribute only in those cases where the given variable
8406 or parameter does not have a true "location" either in memory or in a
8407 register. This can happen (for example) when a constant is passed as an
8408 actual argument in a call to an inline function. (It's possible that
8409 these things can crop up in other ways also.) Note that one type of
8410 constant value which can be passed into an inlined function is a constant
8411 pointer. This can happen for example if an actual argument in an inlined
8412 function call evaluates to a compile-time constant address. */
8415 add_location_or_const_value_attribute (die, decl)
8416 register dw_die_ref die;
8421 if (TREE_CODE (decl) == ERROR_MARK)
8424 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8427 rtl = rtl_for_decl_location (decl);
8428 if (rtl == NULL_RTX)
8431 switch (GET_CODE (rtl))
8434 /* The address of a variable that was optimized away; don't emit
8445 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8446 add_const_value_attribute (die, rtl);
8453 add_AT_location_description (die, DW_AT_location, rtl);
8461 /* If we don't have a copy of this variable in memory for some reason (such
8462 as a C++ member constant that doesn't have an out-of-line definition),
8463 we should tell the debugger about the constant value. */
8466 tree_add_const_value_attribute (var_die, decl)
8470 tree init = DECL_INITIAL (decl);
8471 tree type = TREE_TYPE (decl);
8473 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8474 && initializer_constant_valid_p (init, type) == null_pointer_node)
8479 switch (TREE_CODE (type))
8482 if (host_integerp (init, 0))
8483 add_AT_unsigned (var_die, DW_AT_const_value,
8484 TREE_INT_CST_LOW (init));
8486 add_AT_long_long (var_die, DW_AT_const_value,
8487 TREE_INT_CST_HIGH (init),
8488 TREE_INT_CST_LOW (init));
8495 /* Generate an DW_AT_name attribute given some string value to be included as
8496 the value of the attribute. */
8499 add_name_attribute (die, name_string)
8500 register dw_die_ref die;
8501 register const char *name_string;
8503 if (name_string != NULL && *name_string != 0)
8505 if (demangle_name_func)
8506 name_string = (*demangle_name_func) (name_string);
8508 add_AT_string (die, DW_AT_name, name_string);
8512 /* Given a tree node describing an array bound (either lower or upper) output
8513 a representation for that bound. */
8516 add_bound_info (subrange_die, bound_attr, bound)
8517 register dw_die_ref subrange_die;
8518 register enum dwarf_attribute bound_attr;
8519 register tree bound;
8521 /* If this is an Ada unconstrained array type, then don't emit any debug
8522 info because the array bounds are unknown. They are parameterized when
8523 the type is instantiated. */
8524 if (contains_placeholder_p (bound))
8527 switch (TREE_CODE (bound))
8532 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8534 if (! host_integerp (bound, 0)
8535 || (bound_attr == DW_AT_lower_bound
8536 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8537 || (is_fortran () && integer_onep (bound)))))
8538 /* use the default */
8541 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8546 case NON_LVALUE_EXPR:
8547 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8551 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8552 access the upper bound values may be bogus. If they refer to a
8553 register, they may only describe how to get at these values at the
8554 points in the generated code right after they have just been
8555 computed. Worse yet, in the typical case, the upper bound values
8556 will not even *be* computed in the optimized code (though the
8557 number of elements will), so these SAVE_EXPRs are entirely
8558 bogus. In order to compensate for this fact, we check here to see
8559 if optimization is enabled, and if so, we don't add an attribute
8560 for the (unknown and unknowable) upper bound. This should not
8561 cause too much trouble for existing (stupid?) debuggers because
8562 they have to deal with empty upper bounds location descriptions
8563 anyway in order to be able to deal with incomplete array types.
8564 Of course an intelligent debugger (GDB?) should be able to
8565 comprehend that a missing upper bound specification in a array
8566 type used for a storage class `auto' local array variable
8567 indicates that the upper bound is both unknown (at compile- time)
8568 and unknowable (at run-time) due to optimization.
8570 We assume that a MEM rtx is safe because gcc wouldn't put the
8571 value there unless it was going to be used repeatedly in the
8572 function, i.e. for cleanups. */
8573 if (SAVE_EXPR_RTL (bound)
8574 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8576 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8577 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8578 register rtx loc = SAVE_EXPR_RTL (bound);
8580 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8581 it references an outer function's frame. */
8583 if (GET_CODE (loc) == MEM)
8585 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8587 if (XEXP (loc, 0) != new_addr)
8588 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8591 add_AT_flag (decl_die, DW_AT_artificial, 1);
8592 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8593 add_AT_location_description (decl_die, DW_AT_location, loc);
8594 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8597 /* Else leave out the attribute. */
8603 dw_die_ref decl_die = lookup_decl_die (bound);
8605 /* ??? Can this happen, or should the variable have been bound
8606 first? Probably it can, since I imagine that we try to create
8607 the types of parameters in the order in which they exist in
8608 the list, and won't have created a forward reference to a
8610 if (decl_die != NULL)
8611 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8617 /* Otherwise try to create a stack operation procedure to
8618 evaluate the value of the array bound. */
8620 dw_die_ref ctx, decl_die;
8621 dw_loc_descr_ref loc;
8623 loc = loc_descriptor_from_tree (bound, 0);
8627 ctx = lookup_decl_die (current_function_decl);
8629 decl_die = new_die (DW_TAG_variable, ctx);
8630 add_AT_flag (decl_die, DW_AT_artificial, 1);
8631 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8632 add_AT_loc (decl_die, DW_AT_location, loc);
8634 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8640 /* Note that the block of subscript information for an array type also
8641 includes information about the element type of type given array type. */
8644 add_subscript_info (type_die, type)
8645 register dw_die_ref type_die;
8648 #ifndef MIPS_DEBUGGING_INFO
8649 register unsigned dimension_number;
8651 register tree lower, upper;
8652 register dw_die_ref subrange_die;
8654 /* The GNU compilers represent multidimensional array types as sequences of
8655 one dimensional array types whose element types are themselves array
8656 types. Here we squish that down, so that each multidimensional array
8657 type gets only one array_type DIE in the Dwarf debugging info. The draft
8658 Dwarf specification say that we are allowed to do this kind of
8659 compression in C (because there is no difference between an array or
8660 arrays and a multidimensional array in C) but for other source languages
8661 (e.g. Ada) we probably shouldn't do this. */
8663 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8664 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8665 We work around this by disabling this feature. See also
8666 gen_array_type_die. */
8667 #ifndef MIPS_DEBUGGING_INFO
8668 for (dimension_number = 0;
8669 TREE_CODE (type) == ARRAY_TYPE;
8670 type = TREE_TYPE (type), dimension_number++)
8673 register tree domain = TYPE_DOMAIN (type);
8675 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8676 and (in GNU C only) variable bounds. Handle all three forms
8678 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8681 /* We have an array type with specified bounds. */
8682 lower = TYPE_MIN_VALUE (domain);
8683 upper = TYPE_MAX_VALUE (domain);
8685 /* define the index type. */
8686 if (TREE_TYPE (domain))
8688 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8689 TREE_TYPE field. We can't emit debug info for this
8690 because it is an unnamed integral type. */
8691 if (TREE_CODE (domain) == INTEGER_TYPE
8692 && TYPE_NAME (domain) == NULL_TREE
8693 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8694 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8697 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8701 /* ??? If upper is NULL, the array has unspecified length,
8702 but it does have a lower bound. This happens with Fortran
8704 Since the debugger is definitely going to need to know N
8705 to produce useful results, go ahead and output the lower
8706 bound solo, and hope the debugger can cope. */
8708 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8710 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8713 /* We have an array type with an unspecified length. The DWARF-2
8714 spec does not say how to handle this; let's just leave out the
8718 #ifndef MIPS_DEBUGGING_INFO
8724 add_byte_size_attribute (die, tree_node)
8726 register tree tree_node;
8728 register unsigned size;
8730 switch (TREE_CODE (tree_node))
8738 case QUAL_UNION_TYPE:
8739 size = int_size_in_bytes (tree_node);
8742 /* For a data member of a struct or union, the DW_AT_byte_size is
8743 generally given as the number of bytes normally allocated for an
8744 object of the *declared* type of the member itself. This is true
8745 even for bit-fields. */
8746 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8752 /* Note that `size' might be -1 when we get to this point. If it is, that
8753 indicates that the byte size of the entity in question is variable. We
8754 have no good way of expressing this fact in Dwarf at the present time,
8755 so just let the -1 pass on through. */
8757 add_AT_unsigned (die, DW_AT_byte_size, size);
8760 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8761 which specifies the distance in bits from the highest order bit of the
8762 "containing object" for the bit-field to the highest order bit of the
8765 For any given bit-field, the "containing object" is a hypothetical
8766 object (of some integral or enum type) within which the given bit-field
8767 lives. The type of this hypothetical "containing object" is always the
8768 same as the declared type of the individual bit-field itself. The
8769 determination of the exact location of the "containing object" for a
8770 bit-field is rather complicated. It's handled by the
8771 `field_byte_offset' function (above).
8773 Note that it is the size (in bytes) of the hypothetical "containing object"
8774 which will be given in the DW_AT_byte_size attribute for this bit-field.
8775 (See `byte_size_attribute' above). */
8778 add_bit_offset_attribute (die, decl)
8779 register dw_die_ref die;
8782 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8783 tree type = DECL_BIT_FIELD_TYPE (decl);
8784 HOST_WIDE_INT bitpos_int;
8785 HOST_WIDE_INT highest_order_object_bit_offset;
8786 HOST_WIDE_INT highest_order_field_bit_offset;
8787 HOST_WIDE_INT unsigned bit_offset;
8789 /* Must be a field and a bit field. */
8791 || TREE_CODE (decl) != FIELD_DECL)
8794 /* We can't yet handle bit-fields whose offsets are variable, so if we
8795 encounter such things, just return without generating any attribute
8796 whatsoever. Likewise for variable or too large size. */
8797 if (! host_integerp (bit_position (decl), 0)
8798 || ! host_integerp (DECL_SIZE (decl), 1))
8801 bitpos_int = int_bit_position (decl);
8803 /* Note that the bit offset is always the distance (in bits) from the
8804 highest-order bit of the "containing object" to the highest-order bit of
8805 the bit-field itself. Since the "high-order end" of any object or field
8806 is different on big-endian and little-endian machines, the computation
8807 below must take account of these differences. */
8808 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8809 highest_order_field_bit_offset = bitpos_int;
8811 if (! BYTES_BIG_ENDIAN)
8813 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8814 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8818 = (! BYTES_BIG_ENDIAN
8819 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8820 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8822 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8825 /* For a FIELD_DECL node which represents a bit field, output an attribute
8826 which specifies the length in bits of the given field. */
8829 add_bit_size_attribute (die, decl)
8830 register dw_die_ref die;
8833 /* Must be a field and a bit field. */
8834 if (TREE_CODE (decl) != FIELD_DECL
8835 || ! DECL_BIT_FIELD_TYPE (decl))
8838 if (host_integerp (DECL_SIZE (decl), 1))
8839 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8842 /* If the compiled language is ANSI C, then add a 'prototyped'
8843 attribute, if arg types are given for the parameters of a function. */
8846 add_prototyped_attribute (die, func_type)
8847 register dw_die_ref die;
8848 register tree func_type;
8850 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8851 && TYPE_ARG_TYPES (func_type) != NULL)
8852 add_AT_flag (die, DW_AT_prototyped, 1);
8855 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8856 by looking in either the type declaration or object declaration
8860 add_abstract_origin_attribute (die, origin)
8861 register dw_die_ref die;
8862 register tree origin;
8864 dw_die_ref origin_die = NULL;
8866 if (TREE_CODE (origin) != FUNCTION_DECL)
8868 /* We may have gotten separated from the block for the inlined
8869 function, if we're in an exception handler or some such; make
8870 sure that the abstract function has been written out.
8872 Doing this for nested functions is wrong, however; functions are
8873 distinct units, and our context might not even be inline. */
8876 fn = TYPE_STUB_DECL (fn);
8877 fn = decl_function_context (fn);
8879 dwarf2out_abstract_function (fn);
8882 if (DECL_P (origin))
8883 origin_die = lookup_decl_die (origin);
8884 else if (TYPE_P (origin))
8885 origin_die = lookup_type_die (origin);
8887 if (origin_die == NULL)
8890 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8893 /* We do not currently support the pure_virtual attribute. */
8896 add_pure_or_virtual_attribute (die, func_decl)
8897 register dw_die_ref die;
8898 register tree func_decl;
8900 if (DECL_VINDEX (func_decl))
8902 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8904 if (host_integerp (DECL_VINDEX (func_decl), 0))
8905 add_AT_loc (die, DW_AT_vtable_elem_location,
8906 new_loc_descr (DW_OP_constu,
8907 tree_low_cst (DECL_VINDEX (func_decl), 0),
8910 /* GNU extension: Record what type this method came from originally. */
8911 if (debug_info_level > DINFO_LEVEL_TERSE)
8912 add_AT_die_ref (die, DW_AT_containing_type,
8913 lookup_type_die (DECL_CONTEXT (func_decl)));
8917 /* Add source coordinate attributes for the given decl. */
8920 add_src_coords_attributes (die, decl)
8921 register dw_die_ref die;
8924 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
8926 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8927 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8930 /* Add an DW_AT_name attribute and source coordinate attribute for the
8931 given decl, but only if it actually has a name. */
8934 add_name_and_src_coords_attributes (die, decl)
8935 register dw_die_ref die;
8938 register tree decl_name;
8940 decl_name = DECL_NAME (decl);
8941 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8943 add_name_attribute (die, dwarf2_name (decl, 0));
8944 if (! DECL_ARTIFICIAL (decl))
8945 add_src_coords_attributes (die, decl);
8947 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8948 && TREE_PUBLIC (decl)
8949 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
8950 && !DECL_ABSTRACT (decl))
8951 add_AT_string (die, DW_AT_MIPS_linkage_name,
8952 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8956 /* Push a new declaration scope. */
8959 push_decl_scope (scope)
8962 /* Make room in the decl_scope_table, if necessary. */
8963 if (decl_scope_table_allocated == decl_scope_depth)
8965 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
8967 = (tree *) xrealloc (decl_scope_table,
8968 decl_scope_table_allocated * sizeof (tree));
8971 decl_scope_table[decl_scope_depth] = scope;
8975 /* Pop a declaration scope. */
8979 if (decl_scope_depth <= 0)
8984 /* Return the DIE for the scope that immediately contains this type.
8985 Non-named types get global scope. Named types nested in other
8986 types get their containing scope if it's open, or global scope
8987 otherwise. All other types (i.e. function-local named types) get
8988 the current active scope. */
8991 scope_die_for (t, context_die)
8993 register dw_die_ref context_die;
8995 register dw_die_ref scope_die = NULL;
8996 register tree containing_scope;
8999 /* Non-types always go in the current scope. */
9003 containing_scope = TYPE_CONTEXT (t);
9005 /* Ignore namespaces for the moment. */
9006 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9007 containing_scope = NULL_TREE;
9009 /* Ignore function type "scopes" from the C frontend. They mean that
9010 a tagged type is local to a parmlist of a function declarator, but
9011 that isn't useful to DWARF. */
9012 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9013 containing_scope = NULL_TREE;
9015 if (containing_scope == NULL_TREE)
9016 scope_die = comp_unit_die;
9017 else if (TYPE_P (containing_scope))
9019 /* For types, we can just look up the appropriate DIE. But
9020 first we check to see if we're in the middle of emitting it
9021 so we know where the new DIE should go. */
9023 for (i = decl_scope_depth - 1; i >= 0; --i)
9024 if (decl_scope_table[i] == containing_scope)
9029 if (debug_info_level > DINFO_LEVEL_TERSE
9030 && !TREE_ASM_WRITTEN (containing_scope))
9033 /* If none of the current dies are suitable, we get file scope. */
9034 scope_die = comp_unit_die;
9037 scope_die = lookup_type_die (containing_scope);
9040 scope_die = context_die;
9045 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9047 static inline int local_scope_p PARAMS ((dw_die_ref));
9049 local_scope_p (context_die)
9050 dw_die_ref context_die;
9052 for (; context_die; context_die = context_die->die_parent)
9053 if (context_die->die_tag == DW_TAG_inlined_subroutine
9054 || context_die->die_tag == DW_TAG_subprogram)
9059 /* Returns nonzero iff CONTEXT_DIE is a class. */
9061 static inline int class_scope_p PARAMS ((dw_die_ref));
9063 class_scope_p (context_die)
9064 dw_die_ref context_die;
9067 && (context_die->die_tag == DW_TAG_structure_type
9068 || context_die->die_tag == DW_TAG_union_type));
9071 /* Many forms of DIEs require a "type description" attribute. This
9072 routine locates the proper "type descriptor" die for the type given
9073 by 'type', and adds an DW_AT_type attribute below the given die. */
9076 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9077 register dw_die_ref object_die;
9079 register int decl_const;
9080 register int decl_volatile;
9081 register dw_die_ref context_die;
9083 register enum tree_code code = TREE_CODE (type);
9084 register dw_die_ref type_die = NULL;
9086 /* ??? If this type is an unnamed subrange type of an integral or
9087 floating-point type, use the inner type. This is because we have no
9088 support for unnamed types in base_type_die. This can happen if this is
9089 an Ada subrange type. Correct solution is emit a subrange type die. */
9090 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9091 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9092 type = TREE_TYPE (type), code = TREE_CODE (type);
9094 if (code == ERROR_MARK)
9097 /* Handle a special case. For functions whose return type is void, we
9098 generate *no* type attribute. (Note that no object may have type
9099 `void', so this only applies to function return types). */
9100 if (code == VOID_TYPE)
9103 type_die = modified_type_die (type,
9104 decl_const || TYPE_READONLY (type),
9105 decl_volatile || TYPE_VOLATILE (type),
9107 if (type_die != NULL)
9108 add_AT_die_ref (object_die, DW_AT_type, type_die);
9111 /* Given a tree pointer to a struct, class, union, or enum type node, return
9112 a pointer to the (string) tag name for the given type, or zero if the type
9113 was declared without a tag. */
9119 register const char *name = 0;
9121 if (TYPE_NAME (type) != 0)
9123 register tree t = 0;
9125 /* Find the IDENTIFIER_NODE for the type name. */
9126 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9127 t = TYPE_NAME (type);
9129 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9130 a TYPE_DECL node, regardless of whether or not a `typedef' was
9132 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9133 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9134 t = DECL_NAME (TYPE_NAME (type));
9136 /* Now get the name as a string, or invent one. */
9138 name = IDENTIFIER_POINTER (t);
9141 return (name == 0 || *name == '\0') ? 0 : name;
9144 /* Return the type associated with a data member, make a special check
9145 for bit field types. */
9148 member_declared_type (member)
9149 register tree member;
9151 return (DECL_BIT_FIELD_TYPE (member)
9152 ? DECL_BIT_FIELD_TYPE (member)
9153 : TREE_TYPE (member));
9156 /* Get the decl's label, as described by its RTL. This may be different
9157 from the DECL_NAME name used in the source file. */
9161 decl_start_label (decl)
9166 x = DECL_RTL (decl);
9167 if (GET_CODE (x) != MEM)
9171 if (GET_CODE (x) != SYMBOL_REF)
9174 fnname = XSTR (x, 0);
9179 /* These routines generate the internal representation of the DIE's for
9180 the compilation unit. Debugging information is collected by walking
9181 the declaration trees passed in from dwarf2out_decl(). */
9184 gen_array_type_die (type, context_die)
9186 register dw_die_ref context_die;
9188 register dw_die_ref scope_die = scope_die_for (type, context_die);
9189 register dw_die_ref array_die;
9190 register tree element_type;
9192 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9193 the inner array type comes before the outer array type. Thus we must
9194 call gen_type_die before we call new_die. See below also. */
9195 #ifdef MIPS_DEBUGGING_INFO
9196 gen_type_die (TREE_TYPE (type), context_die);
9199 array_die = new_die (DW_TAG_array_type, scope_die);
9202 /* We default the array ordering. SDB will probably do
9203 the right things even if DW_AT_ordering is not present. It's not even
9204 an issue until we start to get into multidimensional arrays anyway. If
9205 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9206 then we'll have to put the DW_AT_ordering attribute back in. (But if
9207 and when we find out that we need to put these in, we will only do so
9208 for multidimensional arrays. */
9209 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9212 #ifdef MIPS_DEBUGGING_INFO
9213 /* The SGI compilers handle arrays of unknown bound by setting
9214 AT_declaration and not emitting any subrange DIEs. */
9215 if (! TYPE_DOMAIN (type))
9216 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9219 add_subscript_info (array_die, type);
9221 add_name_attribute (array_die, type_tag (type));
9222 equate_type_number_to_die (type, array_die);
9224 /* Add representation of the type of the elements of this array type. */
9225 element_type = TREE_TYPE (type);
9227 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9228 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9229 We work around this by disabling this feature. See also
9230 add_subscript_info. */
9231 #ifndef MIPS_DEBUGGING_INFO
9232 while (TREE_CODE (element_type) == ARRAY_TYPE)
9233 element_type = TREE_TYPE (element_type);
9235 gen_type_die (element_type, context_die);
9238 add_type_attribute (array_die, element_type, 0, 0, context_die);
9242 gen_set_type_die (type, context_die)
9244 register dw_die_ref context_die;
9246 register dw_die_ref type_die
9247 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9249 equate_type_number_to_die (type, type_die);
9250 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9255 gen_entry_point_die (decl, context_die)
9257 register dw_die_ref context_die;
9259 register tree origin = decl_ultimate_origin (decl);
9260 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9262 add_abstract_origin_attribute (decl_die, origin);
9265 add_name_and_src_coords_attributes (decl_die, decl);
9266 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9270 if (DECL_ABSTRACT (decl))
9271 equate_decl_number_to_die (decl, decl_die);
9273 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9277 /* Remember a type in the incomplete_types_list. */
9280 add_incomplete_type (type)
9283 if (incomplete_types == incomplete_types_allocated)
9285 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9286 incomplete_types_list
9287 = (tree *) xrealloc (incomplete_types_list,
9288 sizeof (tree) * incomplete_types_allocated);
9291 incomplete_types_list[incomplete_types++] = type;
9294 /* Walk through the list of incomplete types again, trying once more to
9295 emit full debugging info for them. */
9298 retry_incomplete_types ()
9302 while (incomplete_types)
9305 type = incomplete_types_list[incomplete_types];
9306 gen_type_die (type, comp_unit_die);
9310 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9313 gen_inlined_enumeration_type_die (type, context_die)
9315 register dw_die_ref context_die;
9317 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9319 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9320 be incomplete and such types are not marked. */
9321 add_abstract_origin_attribute (type_die, type);
9324 /* Generate a DIE to represent an inlined instance of a structure type. */
9327 gen_inlined_structure_type_die (type, context_die)
9329 register dw_die_ref context_die;
9331 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9333 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9334 be incomplete and such types are not marked. */
9335 add_abstract_origin_attribute (type_die, type);
9338 /* Generate a DIE to represent an inlined instance of a union type. */
9341 gen_inlined_union_type_die (type, context_die)
9343 register dw_die_ref context_die;
9345 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9347 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9348 be incomplete and such types are not marked. */
9349 add_abstract_origin_attribute (type_die, type);
9352 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9353 include all of the information about the enumeration values also. Each
9354 enumerated type name/value is listed as a child of the enumerated type
9358 gen_enumeration_type_die (type, context_die)
9360 register dw_die_ref context_die;
9362 register dw_die_ref type_die = lookup_type_die (type);
9364 if (type_die == NULL)
9366 type_die = new_die (DW_TAG_enumeration_type,
9367 scope_die_for (type, context_die));
9368 equate_type_number_to_die (type, type_die);
9369 add_name_attribute (type_die, type_tag (type));
9371 else if (! TYPE_SIZE (type))
9374 remove_AT (type_die, DW_AT_declaration);
9376 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9377 given enum type is incomplete, do not generate the DW_AT_byte_size
9378 attribute or the DW_AT_element_list attribute. */
9379 if (TYPE_SIZE (type))
9383 TREE_ASM_WRITTEN (type) = 1;
9384 add_byte_size_attribute (type_die, type);
9385 if (TYPE_STUB_DECL (type) != NULL_TREE)
9386 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9388 /* If the first reference to this type was as the return type of an
9389 inline function, then it may not have a parent. Fix this now. */
9390 if (type_die->die_parent == NULL)
9391 add_child_die (scope_die_for (type, context_die), type_die);
9393 for (link = TYPE_FIELDS (type);
9394 link != NULL; link = TREE_CHAIN (link))
9396 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9398 add_name_attribute (enum_die,
9399 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9401 if (host_integerp (TREE_VALUE (link), 0))
9403 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9404 add_AT_int (enum_die, DW_AT_const_value,
9405 tree_low_cst (TREE_VALUE (link), 0));
9407 add_AT_unsigned (enum_die, DW_AT_const_value,
9408 tree_low_cst (TREE_VALUE (link), 0));
9413 add_AT_flag (type_die, DW_AT_declaration, 1);
9416 /* Generate a DIE to represent either a real live formal parameter decl or to
9417 represent just the type of some formal parameter position in some function
9420 Note that this routine is a bit unusual because its argument may be a
9421 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9422 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9423 node. If it's the former then this function is being called to output a
9424 DIE to represent a formal parameter object (or some inlining thereof). If
9425 it's the latter, then this function is only being called to output a
9426 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9427 argument type of some subprogram type. */
9430 gen_formal_parameter_die (node, context_die)
9432 register dw_die_ref context_die;
9434 register dw_die_ref parm_die
9435 = new_die (DW_TAG_formal_parameter, context_die);
9436 register tree origin;
9438 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9441 origin = decl_ultimate_origin (node);
9443 add_abstract_origin_attribute (parm_die, origin);
9446 add_name_and_src_coords_attributes (parm_die, node);
9447 add_type_attribute (parm_die, TREE_TYPE (node),
9448 TREE_READONLY (node),
9449 TREE_THIS_VOLATILE (node),
9451 if (DECL_ARTIFICIAL (node))
9452 add_AT_flag (parm_die, DW_AT_artificial, 1);
9455 equate_decl_number_to_die (node, parm_die);
9456 if (! DECL_ABSTRACT (node))
9457 add_location_or_const_value_attribute (parm_die, node);
9462 /* We were called with some kind of a ..._TYPE node. */
9463 add_type_attribute (parm_die, node, 0, 0, context_die);
9473 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9474 at the end of an (ANSI prototyped) formal parameters list. */
9477 gen_unspecified_parameters_die (decl_or_type, context_die)
9478 register tree decl_or_type ATTRIBUTE_UNUSED;
9479 register dw_die_ref context_die;
9481 new_die (DW_TAG_unspecified_parameters, context_die);
9484 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9485 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9486 parameters as specified in some function type specification (except for
9487 those which appear as part of a function *definition*). */
9490 gen_formal_types_die (function_or_method_type, context_die)
9491 register tree function_or_method_type;
9492 register dw_die_ref context_die;
9495 register tree formal_type = NULL;
9496 register tree first_parm_type;
9499 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9501 arg = DECL_ARGUMENTS (function_or_method_type);
9502 function_or_method_type = TREE_TYPE (function_or_method_type);
9507 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9509 /* Make our first pass over the list of formal parameter types and output a
9510 DW_TAG_formal_parameter DIE for each one. */
9511 for (link = first_parm_type; link; )
9513 register dw_die_ref parm_die;
9515 formal_type = TREE_VALUE (link);
9516 if (formal_type == void_type_node)
9519 /* Output a (nameless) DIE to represent the formal parameter itself. */
9520 parm_die = gen_formal_parameter_die (formal_type, context_die);
9521 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9522 && link == first_parm_type)
9523 || (arg && DECL_ARTIFICIAL (arg)))
9524 add_AT_flag (parm_die, DW_AT_artificial, 1);
9526 link = TREE_CHAIN (link);
9528 arg = TREE_CHAIN (arg);
9531 /* If this function type has an ellipsis, add a
9532 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9533 if (formal_type != void_type_node)
9534 gen_unspecified_parameters_die (function_or_method_type, context_die);
9536 /* Make our second (and final) pass over the list of formal parameter types
9537 and output DIEs to represent those types (as necessary). */
9538 for (link = TYPE_ARG_TYPES (function_or_method_type);
9540 link = TREE_CHAIN (link))
9542 formal_type = TREE_VALUE (link);
9543 if (formal_type == void_type_node)
9546 gen_type_die (formal_type, context_die);
9550 /* We want to generate the DIE for TYPE so that we can generate the
9551 die for MEMBER, which has been defined; we will need to refer back
9552 to the member declaration nested within TYPE. If we're trying to
9553 generate minimal debug info for TYPE, processing TYPE won't do the
9554 trick; we need to attach the member declaration by hand. */
9557 gen_type_die_for_member (type, member, context_die)
9559 dw_die_ref context_die;
9561 gen_type_die (type, context_die);
9563 /* If we're trying to avoid duplicate debug info, we may not have
9564 emitted the member decl for this function. Emit it now. */
9565 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9566 && ! lookup_decl_die (member))
9568 if (decl_ultimate_origin (member))
9571 push_decl_scope (type);
9572 if (TREE_CODE (member) == FUNCTION_DECL)
9573 gen_subprogram_die (member, lookup_type_die (type));
9575 gen_variable_die (member, lookup_type_die (type));
9580 /* Generate the DWARF2 info for the "abstract" instance
9581 of a function which we may later generate inlined and/or
9582 out-of-line instances of. */
9585 dwarf2out_abstract_function (decl)
9588 register dw_die_ref old_die;
9591 int was_abstract = DECL_ABSTRACT (decl);
9593 /* Make sure we have the actual abstract inline, not a clone. */
9594 decl = DECL_ORIGIN (decl);
9596 old_die = lookup_decl_die (decl);
9597 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9598 /* We've already generated the abstract instance. */
9601 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9602 we don't get confused by DECL_ABSTRACT. */
9603 context = decl_class_context (decl);
9605 gen_type_die_for_member
9606 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9608 /* Pretend we've just finished compiling this function. */
9609 save_fn = current_function_decl;
9610 current_function_decl = decl;
9612 set_decl_abstract_flags (decl, 1);
9613 dwarf2out_decl (decl);
9615 set_decl_abstract_flags (decl, 0);
9617 current_function_decl = save_fn;
9620 /* Generate a DIE to represent a declared function (either file-scope or
9624 gen_subprogram_die (decl, context_die)
9626 register dw_die_ref context_die;
9628 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9629 register tree origin = decl_ultimate_origin (decl);
9630 register dw_die_ref subr_die;
9631 register rtx fp_reg;
9632 register tree fn_arg_types;
9633 register tree outer_scope;
9634 register dw_die_ref old_die = lookup_decl_die (decl);
9635 register int declaration = (current_function_decl != decl
9636 || class_scope_p (context_die));
9638 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9639 be true, if we started to generate the abstract instance of an inline,
9640 decided to output its containing class, and proceeded to emit the
9641 declaration of the inline from the member list for the class. In that
9642 case, `declaration' takes priority; we'll get back to the abstract
9643 instance when we're done with the class. */
9645 /* The class-scope declaration DIE must be the primary DIE. */
9646 if (origin && declaration && class_scope_p (context_die))
9655 if (declaration && ! local_scope_p (context_die))
9658 /* Fixup die_parent for the abstract instance of a nested
9660 if (old_die && old_die->die_parent == NULL)
9661 add_child_die (context_die, old_die);
9663 subr_die = new_die (DW_TAG_subprogram, context_die);
9664 add_abstract_origin_attribute (subr_die, origin);
9668 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9670 if (!get_AT_flag (old_die, DW_AT_declaration)
9671 /* We can have a normal definition following an inline one in the
9672 case of redefinition of GNU C extern inlines.
9673 It seems reasonable to use AT_specification in this case. */
9674 && !get_AT_unsigned (old_die, DW_AT_inline))
9676 /* ??? This can happen if there is a bug in the program, for
9677 instance, if it has duplicate function definitions. Ideally,
9678 we should detect this case and ignore it. For now, if we have
9679 already reported an error, any error at all, then assume that
9680 we got here because of a input error, not a dwarf2 bug. */
9686 /* If the definition comes from the same place as the declaration,
9687 maybe use the old DIE. We always want the DIE for this function
9688 that has the *_pc attributes to be under comp_unit_die so the
9689 debugger can find it. We also need to do this for abstract
9690 instances of inlines, since the spec requires the out-of-line copy
9691 to have the same parent. For local class methods, this doesn't
9692 apply; we just use the old DIE. */
9693 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9694 && (DECL_ARTIFICIAL (decl)
9695 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9696 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9697 == (unsigned) DECL_SOURCE_LINE (decl)))))
9701 /* Clear out the declaration attribute and the parm types. */
9702 remove_AT (subr_die, DW_AT_declaration);
9703 remove_children (subr_die);
9707 subr_die = new_die (DW_TAG_subprogram, context_die);
9708 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9709 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9710 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9711 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9712 != (unsigned) DECL_SOURCE_LINE (decl))
9714 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9719 subr_die = new_die (DW_TAG_subprogram, context_die);
9721 if (TREE_PUBLIC (decl))
9722 add_AT_flag (subr_die, DW_AT_external, 1);
9724 add_name_and_src_coords_attributes (subr_die, decl);
9725 if (debug_info_level > DINFO_LEVEL_TERSE)
9727 register tree type = TREE_TYPE (decl);
9729 add_prototyped_attribute (subr_die, type);
9730 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9733 add_pure_or_virtual_attribute (subr_die, decl);
9734 if (DECL_ARTIFICIAL (decl))
9735 add_AT_flag (subr_die, DW_AT_artificial, 1);
9736 if (TREE_PROTECTED (decl))
9737 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9738 else if (TREE_PRIVATE (decl))
9739 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9744 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9746 add_AT_flag (subr_die, DW_AT_declaration, 1);
9748 /* The first time we see a member function, it is in the context of
9749 the class to which it belongs. We make sure of this by emitting
9750 the class first. The next time is the definition, which is
9751 handled above. The two may come from the same source text. */
9752 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9753 equate_decl_number_to_die (decl, subr_die);
9756 else if (DECL_ABSTRACT (decl))
9758 if (DECL_INLINE (decl) && !flag_no_inline)
9760 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9761 inline functions, but not for extern inline functions.
9762 We can't get this completely correct because information
9763 about whether the function was declared inline is not
9765 if (DECL_DEFER_OUTPUT (decl))
9766 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9768 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9771 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9773 equate_decl_number_to_die (decl, subr_die);
9775 else if (!DECL_EXTERNAL (decl))
9777 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9778 equate_decl_number_to_die (decl, subr_die);
9780 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9781 current_funcdef_number);
9782 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9783 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9784 current_funcdef_number);
9785 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9787 add_pubname (decl, subr_die);
9788 add_arange (decl, subr_die);
9790 #ifdef MIPS_DEBUGGING_INFO
9791 /* Add a reference to the FDE for this routine. */
9792 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9795 /* Define the "frame base" location for this routine. We use the
9796 frame pointer or stack pointer registers, since the RTL for local
9797 variables is relative to one of them. */
9799 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9800 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9803 /* ??? This fails for nested inline functions, because context_display
9804 is not part of the state saved/restored for inline functions. */
9805 if (current_function_needs_context)
9806 add_AT_location_description (subr_die, DW_AT_static_link,
9807 lookup_static_chain (decl));
9811 /* Now output descriptions of the arguments for this function. This gets
9812 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9813 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9814 `...' at the end of the formal parameter list. In order to find out if
9815 there was a trailing ellipsis or not, we must instead look at the type
9816 associated with the FUNCTION_DECL. This will be a node of type
9817 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9818 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9819 an ellipsis at the end. */
9821 /* In the case where we are describing a mere function declaration, all we
9822 need to do here (and all we *can* do here) is to describe the *types* of
9823 its formal parameters. */
9824 if (debug_info_level <= DINFO_LEVEL_TERSE)
9826 else if (declaration)
9827 gen_formal_types_die (decl, subr_die);
9830 /* Generate DIEs to represent all known formal parameters */
9831 register tree arg_decls = DECL_ARGUMENTS (decl);
9834 /* When generating DIEs, generate the unspecified_parameters DIE
9835 instead if we come across the arg "__builtin_va_alist" */
9836 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9837 if (TREE_CODE (parm) == PARM_DECL)
9839 if (DECL_NAME (parm)
9840 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9841 "__builtin_va_alist"))
9842 gen_unspecified_parameters_die (parm, subr_die);
9844 gen_decl_die (parm, subr_die);
9847 /* Decide whether we need a unspecified_parameters DIE at the end.
9848 There are 2 more cases to do this for: 1) the ansi ... declaration -
9849 this is detectable when the end of the arg list is not a
9850 void_type_node 2) an unprototyped function declaration (not a
9851 definition). This just means that we have no info about the
9852 parameters at all. */
9853 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9854 if (fn_arg_types != NULL)
9856 /* this is the prototyped case, check for ... */
9857 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9858 gen_unspecified_parameters_die (decl, subr_die);
9860 else if (DECL_INITIAL (decl) == NULL_TREE)
9861 gen_unspecified_parameters_die (decl, subr_die);
9864 /* Output Dwarf info for all of the stuff within the body of the function
9865 (if it has one - it may be just a declaration). */
9866 outer_scope = DECL_INITIAL (decl);
9868 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9869 node created to represent a function. This outermost BLOCK actually
9870 represents the outermost binding contour for the function, i.e. the
9871 contour in which the function's formal parameters and labels get
9872 declared. Curiously, it appears that the front end doesn't actually
9873 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9874 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9875 list for the function instead.) The BLOCK_VARS list for the
9876 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9877 the function however, and we output DWARF info for those in
9878 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9879 node representing the function's outermost pair of curly braces, and
9880 any blocks used for the base and member initializers of a C++
9881 constructor function. */
9882 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9884 current_function_has_inlines = 0;
9885 decls_for_scope (outer_scope, subr_die, 0);
9887 #if 0 && defined (MIPS_DEBUGGING_INFO)
9888 if (current_function_has_inlines)
9890 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9891 if (! comp_unit_has_inlines)
9893 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9894 comp_unit_has_inlines = 1;
9901 /* Generate a DIE to represent a declared data object. */
9904 gen_variable_die (decl, context_die)
9906 register dw_die_ref context_die;
9908 register tree origin = decl_ultimate_origin (decl);
9909 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9911 dw_die_ref old_die = lookup_decl_die (decl);
9912 int declaration = (DECL_EXTERNAL (decl)
9913 || class_scope_p (context_die));
9916 add_abstract_origin_attribute (var_die, origin);
9917 /* Loop unrolling can create multiple blocks that refer to the same
9918 static variable, so we must test for the DW_AT_declaration flag. */
9919 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9920 copy decls and set the DECL_ABSTRACT flag on them instead of
9922 else if (old_die && TREE_STATIC (decl)
9923 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9925 /* This is a definition of a C++ class level static. */
9926 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9927 if (DECL_NAME (decl))
9929 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9931 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9932 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9934 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9935 != (unsigned) DECL_SOURCE_LINE (decl))
9937 add_AT_unsigned (var_die, DW_AT_decl_line,
9938 DECL_SOURCE_LINE (decl));
9943 add_name_and_src_coords_attributes (var_die, decl);
9944 add_type_attribute (var_die, TREE_TYPE (decl),
9945 TREE_READONLY (decl),
9946 TREE_THIS_VOLATILE (decl), context_die);
9948 if (TREE_PUBLIC (decl))
9949 add_AT_flag (var_die, DW_AT_external, 1);
9951 if (DECL_ARTIFICIAL (decl))
9952 add_AT_flag (var_die, DW_AT_artificial, 1);
9954 if (TREE_PROTECTED (decl))
9955 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9957 else if (TREE_PRIVATE (decl))
9958 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9962 add_AT_flag (var_die, DW_AT_declaration, 1);
9964 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9965 equate_decl_number_to_die (decl, var_die);
9967 if (! declaration && ! DECL_ABSTRACT (decl))
9969 add_location_or_const_value_attribute (var_die, decl);
9970 add_pubname (decl, var_die);
9973 tree_add_const_value_attribute (var_die, decl);
9976 /* Generate a DIE to represent a label identifier. */
9979 gen_label_die (decl, context_die)
9981 register dw_die_ref context_die;
9983 register tree origin = decl_ultimate_origin (decl);
9984 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
9986 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9989 add_abstract_origin_attribute (lbl_die, origin);
9991 add_name_and_src_coords_attributes (lbl_die, decl);
9993 if (DECL_ABSTRACT (decl))
9994 equate_decl_number_to_die (decl, lbl_die);
9997 insn = DECL_RTL (decl);
9999 /* Deleted labels are programmer specified labels which have been
10000 eliminated because of various optimisations. We still emit them
10001 here so that it is possible to put breakpoints on them. */
10002 if (GET_CODE (insn) == CODE_LABEL
10003 || ((GET_CODE (insn) == NOTE
10004 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10006 /* When optimization is enabled (via -O) some parts of the compiler
10007 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10008 represent source-level labels which were explicitly declared by
10009 the user. This really shouldn't be happening though, so catch
10010 it if it ever does happen. */
10011 if (INSN_DELETED_P (insn))
10014 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10015 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10020 /* Generate a DIE for a lexical block. */
10023 gen_lexical_block_die (stmt, context_die, depth)
10024 register tree stmt;
10025 register dw_die_ref context_die;
10028 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10029 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10031 if (! BLOCK_ABSTRACT (stmt))
10033 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10034 BLOCK_NUMBER (stmt));
10035 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10036 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10037 BLOCK_NUMBER (stmt));
10038 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10041 decls_for_scope (stmt, stmt_die, depth);
10044 /* Generate a DIE for an inlined subprogram. */
10047 gen_inlined_subroutine_die (stmt, context_die, depth)
10048 register tree stmt;
10049 register dw_die_ref context_die;
10052 if (! BLOCK_ABSTRACT (stmt))
10054 register dw_die_ref subr_die
10055 = new_die (DW_TAG_inlined_subroutine, context_die);
10056 register tree decl = block_ultimate_origin (stmt);
10057 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10059 /* Emit info for the abstract instance first, if we haven't yet. */
10060 dwarf2out_abstract_function (decl);
10062 add_abstract_origin_attribute (subr_die, decl);
10063 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10064 BLOCK_NUMBER (stmt));
10065 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10066 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10067 BLOCK_NUMBER (stmt));
10068 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10069 decls_for_scope (stmt, subr_die, depth);
10070 current_function_has_inlines = 1;
10074 /* Generate a DIE for a field in a record, or structure. */
10077 gen_field_die (decl, context_die)
10078 register tree decl;
10079 register dw_die_ref context_die;
10081 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10083 add_name_and_src_coords_attributes (decl_die, decl);
10084 add_type_attribute (decl_die, member_declared_type (decl),
10085 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10088 /* If this is a bit field... */
10089 if (DECL_BIT_FIELD_TYPE (decl))
10091 add_byte_size_attribute (decl_die, decl);
10092 add_bit_size_attribute (decl_die, decl);
10093 add_bit_offset_attribute (decl_die, decl);
10096 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10097 add_data_member_location_attribute (decl_die, decl);
10099 if (DECL_ARTIFICIAL (decl))
10100 add_AT_flag (decl_die, DW_AT_artificial, 1);
10102 if (TREE_PROTECTED (decl))
10103 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10105 else if (TREE_PRIVATE (decl))
10106 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10110 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10111 Use modified_type_die instead.
10112 We keep this code here just in case these types of DIEs may be needed to
10113 represent certain things in other languages (e.g. Pascal) someday. */
10115 gen_pointer_type_die (type, context_die)
10116 register tree type;
10117 register dw_die_ref context_die;
10119 register dw_die_ref ptr_die
10120 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10122 equate_type_number_to_die (type, ptr_die);
10123 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10124 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10127 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10128 Use modified_type_die instead.
10129 We keep this code here just in case these types of DIEs may be needed to
10130 represent certain things in other languages (e.g. Pascal) someday. */
10132 gen_reference_type_die (type, context_die)
10133 register tree type;
10134 register dw_die_ref context_die;
10136 register dw_die_ref ref_die
10137 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10139 equate_type_number_to_die (type, ref_die);
10140 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10141 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10145 /* Generate a DIE for a pointer to a member type. */
10147 gen_ptr_to_mbr_type_die (type, context_die)
10148 register tree type;
10149 register dw_die_ref context_die;
10151 register dw_die_ref ptr_die
10152 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10154 equate_type_number_to_die (type, ptr_die);
10155 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10156 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10157 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10160 /* Generate the DIE for the compilation unit. */
10163 gen_compile_unit_die (filename)
10164 register const char *filename;
10166 register dw_die_ref die;
10167 char producer[250];
10168 const char *wd = getpwd ();
10171 die = new_die (DW_TAG_compile_unit, NULL);
10172 add_name_attribute (die, filename);
10174 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10175 add_AT_string (die, DW_AT_comp_dir, wd);
10177 sprintf (producer, "%s %s", language_string, version_string);
10179 #ifdef MIPS_DEBUGGING_INFO
10180 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10181 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10182 not appear in the producer string, the debugger reaches the conclusion
10183 that the object file is stripped and has no debugging information.
10184 To get the MIPS/SGI debugger to believe that there is debugging
10185 information in the object file, we add a -g to the producer string. */
10186 if (debug_info_level > DINFO_LEVEL_TERSE)
10187 strcat (producer, " -g");
10190 add_AT_string (die, DW_AT_producer, producer);
10192 if (strcmp (language_string, "GNU C++") == 0)
10193 language = DW_LANG_C_plus_plus;
10194 else if (strcmp (language_string, "GNU Ada") == 0)
10195 language = DW_LANG_Ada83;
10196 else if (strcmp (language_string, "GNU F77") == 0)
10197 language = DW_LANG_Fortran77;
10198 else if (strcmp (language_string, "GNU Pascal") == 0)
10199 language = DW_LANG_Pascal83;
10200 else if (strcmp (language_string, "GNU Java") == 0)
10201 language = DW_LANG_Java;
10202 else if (flag_traditional)
10203 language = DW_LANG_C;
10205 language = DW_LANG_C89;
10207 add_AT_unsigned (die, DW_AT_language, language);
10212 /* Generate a DIE for a string type. */
10215 gen_string_type_die (type, context_die)
10216 register tree type;
10217 register dw_die_ref context_die;
10219 register dw_die_ref type_die
10220 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10222 equate_type_number_to_die (type, type_die);
10224 /* Fudge the string length attribute for now. */
10226 /* TODO: add string length info.
10227 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10228 bound_representation (upper_bound, 0, 'u'); */
10231 /* Generate the DIE for a base class. */
10234 gen_inheritance_die (binfo, context_die)
10235 register tree binfo;
10236 register dw_die_ref context_die;
10238 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10240 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10241 add_data_member_location_attribute (die, binfo);
10243 if (TREE_VIA_VIRTUAL (binfo))
10244 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10245 if (TREE_VIA_PUBLIC (binfo))
10246 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10247 else if (TREE_VIA_PROTECTED (binfo))
10248 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10251 /* Generate a DIE for a class member. */
10254 gen_member_die (type, context_die)
10255 register tree type;
10256 register dw_die_ref context_die;
10258 register tree member;
10261 /* If this is not an incomplete type, output descriptions of each of its
10262 members. Note that as we output the DIEs necessary to represent the
10263 members of this record or union type, we will also be trying to output
10264 DIEs to represent the *types* of those members. However the `type'
10265 function (above) will specifically avoid generating type DIEs for member
10266 types *within* the list of member DIEs for this (containing) type execpt
10267 for those types (of members) which are explicitly marked as also being
10268 members of this (containing) type themselves. The g++ front- end can
10269 force any given type to be treated as a member of some other
10270 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10271 to point to the TREE node representing the appropriate (containing)
10274 /* First output info about the base classes. */
10275 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10277 register tree bases = TYPE_BINFO_BASETYPES (type);
10278 register int n_bases = TREE_VEC_LENGTH (bases);
10281 for (i = 0; i < n_bases; i++)
10282 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10285 /* Now output info about the data members and type members. */
10286 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10288 /* If we thought we were generating minimal debug info for TYPE
10289 and then changed our minds, some of the member declarations
10290 may have already been defined. Don't define them again, but
10291 do put them in the right order. */
10293 child = lookup_decl_die (member);
10295 splice_child_die (context_die, child);
10297 gen_decl_die (member, context_die);
10300 /* Now output info about the function members (if any). */
10301 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10303 /* Don't include clones in the member list. */
10304 if (DECL_ABSTRACT_ORIGIN (member))
10307 child = lookup_decl_die (member);
10309 splice_child_die (context_die, child);
10311 gen_decl_die (member, context_die);
10315 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10316 is set, we pretend that the type was never defined, so we only get the
10317 member DIEs needed by later specification DIEs. */
10320 gen_struct_or_union_type_die (type, context_die)
10321 register tree type;
10322 register dw_die_ref context_die;
10324 register dw_die_ref type_die = lookup_type_die (type);
10325 register dw_die_ref scope_die = 0;
10326 register int nested = 0;
10327 int complete = (TYPE_SIZE (type)
10328 && (! TYPE_STUB_DECL (type)
10329 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10331 if (type_die && ! complete)
10334 if (TYPE_CONTEXT (type) != NULL_TREE
10335 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10338 scope_die = scope_die_for (type, context_die);
10340 if (! type_die || (nested && scope_die == comp_unit_die))
10341 /* First occurrence of type or toplevel definition of nested class. */
10343 register dw_die_ref old_die = type_die;
10345 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10346 ? DW_TAG_structure_type : DW_TAG_union_type,
10348 equate_type_number_to_die (type, type_die);
10350 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10352 add_name_attribute (type_die, type_tag (type));
10355 remove_AT (type_die, DW_AT_declaration);
10357 /* If this type has been completed, then give it a byte_size attribute and
10358 then give a list of members. */
10361 /* Prevent infinite recursion in cases where the type of some member of
10362 this type is expressed in terms of this type itself. */
10363 TREE_ASM_WRITTEN (type) = 1;
10364 add_byte_size_attribute (type_die, type);
10365 if (TYPE_STUB_DECL (type) != NULL_TREE)
10366 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10368 /* If the first reference to this type was as the return type of an
10369 inline function, then it may not have a parent. Fix this now. */
10370 if (type_die->die_parent == NULL)
10371 add_child_die (scope_die, type_die);
10373 push_decl_scope (type);
10374 gen_member_die (type, type_die);
10377 /* GNU extension: Record what type our vtable lives in. */
10378 if (TYPE_VFIELD (type))
10380 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10382 gen_type_die (vtype, context_die);
10383 add_AT_die_ref (type_die, DW_AT_containing_type,
10384 lookup_type_die (vtype));
10389 add_AT_flag (type_die, DW_AT_declaration, 1);
10391 /* We don't need to do this for function-local types. */
10392 if (! decl_function_context (TYPE_STUB_DECL (type)))
10393 add_incomplete_type (type);
10397 /* Generate a DIE for a subroutine _type_. */
10400 gen_subroutine_type_die (type, context_die)
10401 register tree type;
10402 register dw_die_ref context_die;
10404 register tree return_type = TREE_TYPE (type);
10405 register dw_die_ref subr_die
10406 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10408 equate_type_number_to_die (type, subr_die);
10409 add_prototyped_attribute (subr_die, type);
10410 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10411 gen_formal_types_die (type, subr_die);
10414 /* Generate a DIE for a type definition */
10417 gen_typedef_die (decl, context_die)
10418 register tree decl;
10419 register dw_die_ref context_die;
10421 register dw_die_ref type_die;
10422 register tree origin;
10424 if (TREE_ASM_WRITTEN (decl))
10426 TREE_ASM_WRITTEN (decl) = 1;
10428 type_die = new_die (DW_TAG_typedef, context_die);
10429 origin = decl_ultimate_origin (decl);
10430 if (origin != NULL)
10431 add_abstract_origin_attribute (type_die, origin);
10434 register tree type;
10435 add_name_and_src_coords_attributes (type_die, decl);
10436 if (DECL_ORIGINAL_TYPE (decl))
10438 type = DECL_ORIGINAL_TYPE (decl);
10440 if (type == TREE_TYPE (decl))
10443 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10446 type = TREE_TYPE (decl);
10447 add_type_attribute (type_die, type, TREE_READONLY (decl),
10448 TREE_THIS_VOLATILE (decl), context_die);
10451 if (DECL_ABSTRACT (decl))
10452 equate_decl_number_to_die (decl, type_die);
10455 /* Generate a type description DIE. */
10458 gen_type_die (type, context_die)
10459 register tree type;
10460 register dw_die_ref context_die;
10464 if (type == NULL_TREE || type == error_mark_node)
10467 /* We are going to output a DIE to represent the unqualified version of
10468 this type (i.e. without any const or volatile qualifiers) so get the
10469 main variant (i.e. the unqualified version) of this type now. */
10470 type = type_main_variant (type);
10472 if (TREE_ASM_WRITTEN (type))
10475 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10476 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10478 TREE_ASM_WRITTEN (type) = 1;
10479 gen_decl_die (TYPE_NAME (type), context_die);
10483 switch (TREE_CODE (type))
10489 case REFERENCE_TYPE:
10490 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10491 ensures that the gen_type_die recursion will terminate even if the
10492 type is recursive. Recursive types are possible in Ada. */
10493 /* ??? We could perhaps do this for all types before the switch
10495 TREE_ASM_WRITTEN (type) = 1;
10497 /* For these types, all that is required is that we output a DIE (or a
10498 set of DIEs) to represent the "basis" type. */
10499 gen_type_die (TREE_TYPE (type), context_die);
10503 /* This code is used for C++ pointer-to-data-member types.
10504 Output a description of the relevant class type. */
10505 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10507 /* Output a description of the type of the object pointed to. */
10508 gen_type_die (TREE_TYPE (type), context_die);
10510 /* Now output a DIE to represent this pointer-to-data-member type
10512 gen_ptr_to_mbr_type_die (type, context_die);
10516 gen_type_die (TYPE_DOMAIN (type), context_die);
10517 gen_set_type_die (type, context_die);
10521 gen_type_die (TREE_TYPE (type), context_die);
10522 abort (); /* No way to represent these in Dwarf yet! */
10525 case FUNCTION_TYPE:
10526 /* Force out return type (in case it wasn't forced out already). */
10527 gen_type_die (TREE_TYPE (type), context_die);
10528 gen_subroutine_type_die (type, context_die);
10532 /* Force out return type (in case it wasn't forced out already). */
10533 gen_type_die (TREE_TYPE (type), context_die);
10534 gen_subroutine_type_die (type, context_die);
10538 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10540 gen_type_die (TREE_TYPE (type), context_die);
10541 gen_string_type_die (type, context_die);
10544 gen_array_type_die (type, context_die);
10548 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10551 case ENUMERAL_TYPE:
10554 case QUAL_UNION_TYPE:
10555 /* If this is a nested type whose containing class hasn't been
10556 written out yet, writing it out will cover this one, too.
10557 This does not apply to instantiations of member class templates;
10558 they need to be added to the containing class as they are
10559 generated. FIXME: This hurts the idea of combining type decls
10560 from multiple TUs, since we can't predict what set of template
10561 instantiations we'll get. */
10562 if (TYPE_CONTEXT (type)
10563 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10564 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10566 gen_type_die (TYPE_CONTEXT (type), context_die);
10568 if (TREE_ASM_WRITTEN (type))
10571 /* If that failed, attach ourselves to the stub. */
10572 push_decl_scope (TYPE_CONTEXT (type));
10573 context_die = lookup_type_die (TYPE_CONTEXT (type));
10579 if (TREE_CODE (type) == ENUMERAL_TYPE)
10580 gen_enumeration_type_die (type, context_die);
10582 gen_struct_or_union_type_die (type, context_die);
10587 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10588 it up if it is ever completed. gen_*_type_die will set it for us
10589 when appropriate. */
10598 /* No DIEs needed for fundamental types. */
10602 /* No Dwarf representation currently defined. */
10609 TREE_ASM_WRITTEN (type) = 1;
10612 /* Generate a DIE for a tagged type instantiation. */
10615 gen_tagged_type_instantiation_die (type, context_die)
10616 register tree type;
10617 register dw_die_ref context_die;
10619 if (type == NULL_TREE || type == error_mark_node)
10622 /* We are going to output a DIE to represent the unqualified version of
10623 this type (i.e. without any const or volatile qualifiers) so make sure
10624 that we have the main variant (i.e. the unqualified version) of this
10626 if (type != type_main_variant (type))
10629 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10630 an instance of an unresolved type. */
10632 switch (TREE_CODE (type))
10637 case ENUMERAL_TYPE:
10638 gen_inlined_enumeration_type_die (type, context_die);
10642 gen_inlined_structure_type_die (type, context_die);
10646 case QUAL_UNION_TYPE:
10647 gen_inlined_union_type_die (type, context_die);
10655 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10656 things which are local to the given block. */
10659 gen_block_die (stmt, context_die, depth)
10660 register tree stmt;
10661 register dw_die_ref context_die;
10664 register int must_output_die = 0;
10665 register tree origin;
10666 register tree decl;
10667 register enum tree_code origin_code;
10669 /* Ignore blocks never really used to make RTL. */
10671 if (stmt == NULL_TREE || !TREE_USED (stmt)
10672 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10675 /* Determine the "ultimate origin" of this block. This block may be an
10676 inlined instance of an inlined instance of inline function, so we have
10677 to trace all of the way back through the origin chain to find out what
10678 sort of node actually served as the original seed for the creation of
10679 the current block. */
10680 origin = block_ultimate_origin (stmt);
10681 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10683 /* Determine if we need to output any Dwarf DIEs at all to represent this
10685 if (origin_code == FUNCTION_DECL)
10686 /* The outer scopes for inlinings *must* always be represented. We
10687 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10688 must_output_die = 1;
10691 /* In the case where the current block represents an inlining of the
10692 "body block" of an inline function, we must *NOT* output any DIE for
10693 this block because we have already output a DIE to represent the
10694 whole inlined function scope and the "body block" of any function
10695 doesn't really represent a different scope according to ANSI C
10696 rules. So we check here to make sure that this block does not
10697 represent a "body block inlining" before trying to set the
10698 `must_output_die' flag. */
10699 if (! is_body_block (origin ? origin : stmt))
10701 /* Determine if this block directly contains any "significant"
10702 local declarations which we will need to output DIEs for. */
10703 if (debug_info_level > DINFO_LEVEL_TERSE)
10704 /* We are not in terse mode so *any* local declaration counts
10705 as being a "significant" one. */
10706 must_output_die = (BLOCK_VARS (stmt) != NULL);
10708 /* We are in terse mode, so only local (nested) function
10709 definitions count as "significant" local declarations. */
10710 for (decl = BLOCK_VARS (stmt);
10711 decl != NULL; decl = TREE_CHAIN (decl))
10712 if (TREE_CODE (decl) == FUNCTION_DECL
10713 && DECL_INITIAL (decl))
10715 must_output_die = 1;
10721 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10722 DIE for any block which contains no significant local declarations at
10723 all. Rather, in such cases we just call `decls_for_scope' so that any
10724 needed Dwarf info for any sub-blocks will get properly generated. Note
10725 that in terse mode, our definition of what constitutes a "significant"
10726 local declaration gets restricted to include only inlined function
10727 instances and local (nested) function definitions. */
10728 if (must_output_die)
10730 if (origin_code == FUNCTION_DECL)
10731 gen_inlined_subroutine_die (stmt, context_die, depth);
10733 gen_lexical_block_die (stmt, context_die, depth);
10736 decls_for_scope (stmt, context_die, depth);
10739 /* Generate all of the decls declared within a given scope and (recursively)
10740 all of its sub-blocks. */
10743 decls_for_scope (stmt, context_die, depth)
10744 register tree stmt;
10745 register dw_die_ref context_die;
10748 register tree decl;
10749 register tree subblocks;
10751 /* Ignore blocks never really used to make RTL. */
10752 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10755 /* Output the DIEs to represent all of the data objects and typedefs
10756 declared directly within this block but not within any nested
10757 sub-blocks. Also, nested function and tag DIEs have been
10758 generated with a parent of NULL; fix that up now. */
10759 for (decl = BLOCK_VARS (stmt);
10760 decl != NULL; decl = TREE_CHAIN (decl))
10762 register dw_die_ref die;
10764 if (TREE_CODE (decl) == FUNCTION_DECL)
10765 die = lookup_decl_die (decl);
10766 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10767 die = lookup_type_die (TREE_TYPE (decl));
10771 if (die != NULL && die->die_parent == NULL)
10772 add_child_die (context_die, die);
10774 gen_decl_die (decl, context_die);
10777 /* Output the DIEs to represent all sub-blocks (and the items declared
10778 therein) of this block. */
10779 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10781 subblocks = BLOCK_CHAIN (subblocks))
10782 gen_block_die (subblocks, context_die, depth + 1);
10785 /* Is this a typedef we can avoid emitting? */
10788 is_redundant_typedef (decl)
10789 register tree decl;
10791 if (TYPE_DECL_IS_STUB (decl))
10794 if (DECL_ARTIFICIAL (decl)
10795 && DECL_CONTEXT (decl)
10796 && is_tagged_type (DECL_CONTEXT (decl))
10797 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10798 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10799 /* Also ignore the artificial member typedef for the class name. */
10805 /* Generate Dwarf debug information for a decl described by DECL. */
10808 gen_decl_die (decl, context_die)
10809 register tree decl;
10810 register dw_die_ref context_die;
10812 register tree origin;
10814 if (TREE_CODE (decl) == ERROR_MARK)
10817 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10818 if (DECL_IGNORED_P (decl))
10821 switch (TREE_CODE (decl))
10824 /* The individual enumerators of an enum type get output when we output
10825 the Dwarf representation of the relevant enum type itself. */
10828 case FUNCTION_DECL:
10829 /* Don't output any DIEs to represent mere function declarations,
10830 unless they are class members or explicit block externs. */
10831 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10832 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10835 /* If we're emitting a clone, emit info for the abstract instance. */
10836 if (DECL_ORIGIN (decl) != decl)
10837 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
10838 /* If we're emitting an out-of-line copy of an inline function,
10839 emit info for the abstract instance and set up to refer to it. */
10840 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10841 && ! class_scope_p (context_die)
10842 /* dwarf2out_abstract_function won't emit a die if this is just
10843 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10844 that case, because that works only if we have a die. */
10845 && DECL_INITIAL (decl) != NULL_TREE)
10847 dwarf2out_abstract_function (decl);
10848 set_decl_origin_self (decl);
10850 /* Otherwise we're emitting the primary DIE for this decl. */
10851 else if (debug_info_level > DINFO_LEVEL_TERSE)
10853 /* Before we describe the FUNCTION_DECL itself, make sure that we
10854 have described its return type. */
10855 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10857 /* And its virtual context. */
10858 if (DECL_VINDEX (decl) != NULL_TREE)
10859 gen_type_die (DECL_CONTEXT (decl), context_die);
10861 /* And its containing type. */
10862 origin = decl_class_context (decl);
10863 if (origin != NULL_TREE)
10864 gen_type_die_for_member (origin, decl, context_die);
10867 /* Now output a DIE to represent the function itself. */
10868 gen_subprogram_die (decl, context_die);
10872 /* If we are in terse mode, don't generate any DIEs to represent any
10873 actual typedefs. */
10874 if (debug_info_level <= DINFO_LEVEL_TERSE)
10877 /* In the special case of a TYPE_DECL node representing the
10878 declaration of some type tag, if the given TYPE_DECL is marked as
10879 having been instantiated from some other (original) TYPE_DECL node
10880 (e.g. one which was generated within the original definition of an
10881 inline function) we have to generate a special (abbreviated)
10882 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10884 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10886 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10890 if (is_redundant_typedef (decl))
10891 gen_type_die (TREE_TYPE (decl), context_die);
10893 /* Output a DIE to represent the typedef itself. */
10894 gen_typedef_die (decl, context_die);
10898 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10899 gen_label_die (decl, context_die);
10903 /* If we are in terse mode, don't generate any DIEs to represent any
10904 variable declarations or definitions. */
10905 if (debug_info_level <= DINFO_LEVEL_TERSE)
10908 /* Output any DIEs that are needed to specify the type of this data
10910 gen_type_die (TREE_TYPE (decl), context_die);
10912 /* And its containing type. */
10913 origin = decl_class_context (decl);
10914 if (origin != NULL_TREE)
10915 gen_type_die_for_member (origin, decl, context_die);
10917 /* Now output the DIE to represent the data object itself. This gets
10918 complicated because of the possibility that the VAR_DECL really
10919 represents an inlined instance of a formal parameter for an inline
10921 origin = decl_ultimate_origin (decl);
10922 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10923 gen_formal_parameter_die (decl, context_die);
10925 gen_variable_die (decl, context_die);
10929 /* Ignore the nameless fields that are used to skip bits, but
10930 handle C++ anonymous unions. */
10931 if (DECL_NAME (decl) != NULL_TREE
10932 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10934 gen_type_die (member_declared_type (decl), context_die);
10935 gen_field_die (decl, context_die);
10940 gen_type_die (TREE_TYPE (decl), context_die);
10941 gen_formal_parameter_die (decl, context_die);
10944 case NAMESPACE_DECL:
10945 /* Ignore for now. */
10953 /* Add Ada "use" clause information for SGI Workshop debugger. */
10956 dwarf2out_add_library_unit_info (filename, context_list)
10957 const char *filename;
10958 const char *context_list;
10960 unsigned int file_index;
10962 if (filename != NULL)
10964 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10965 tree context_list_decl
10966 = build_decl (LABEL_DECL, get_identifier (context_list),
10969 TREE_PUBLIC (context_list_decl) = TRUE;
10970 add_name_attribute (unit_die, context_list);
10971 file_index = lookup_filename (filename);
10972 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10973 add_pubname (context_list_decl, unit_die);
10977 /* Write the debugging output for DECL. */
10980 dwarf2out_decl (decl)
10981 register tree decl;
10983 register dw_die_ref context_die = comp_unit_die;
10985 if (TREE_CODE (decl) == ERROR_MARK)
10988 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10989 if (DECL_IGNORED_P (decl))
10992 switch (TREE_CODE (decl))
10994 case FUNCTION_DECL:
10995 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
10996 builtin function. Explicit programmer-supplied declarations of
10997 these same functions should NOT be ignored however. */
10998 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11001 /* What we would really like to do here is to filter out all mere
11002 file-scope declarations of file-scope functions which are never
11003 referenced later within this translation unit (and keep all of ones
11004 that *are* referenced later on) but we aren't clairvoyant, so we have
11005 no idea which functions will be referenced in the future (i.e. later
11006 on within the current translation unit). So here we just ignore all
11007 file-scope function declarations which are not also definitions. If
11008 and when the debugger needs to know something about these functions,
11009 it will have to hunt around and find the DWARF information associated
11010 with the definition of the function. Note that we can't just check
11011 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11012 definitions and which ones represent mere declarations. We have to
11013 check `DECL_INITIAL' instead. That's because the C front-end
11014 supports some weird semantics for "extern inline" function
11015 definitions. These can get inlined within the current translation
11016 unit (an thus, we need to generate DWARF info for their abstract
11017 instances so that the DWARF info for the concrete inlined instances
11018 can have something to refer to) but the compiler never generates any
11019 out-of-lines instances of such things (despite the fact that they
11020 *are* definitions). The important point is that the C front-end
11021 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11022 to generate DWARF for them anyway. Note that the C++ front-end also
11023 plays some similar games for inline function definitions appearing
11024 within include files which also contain
11025 `#pragma interface' pragmas. */
11026 if (DECL_INITIAL (decl) == NULL_TREE)
11029 /* If we're a nested function, initially use a parent of NULL; if we're
11030 a plain function, this will be fixed up in decls_for_scope. If
11031 we're a method, it will be ignored, since we already have a DIE. */
11032 if (decl_function_context (decl))
11033 context_die = NULL;
11038 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11039 declaration and if the declaration was never even referenced from
11040 within this entire compilation unit. We suppress these DIEs in
11041 order to save space in the .debug section (by eliminating entries
11042 which are probably useless). Note that we must not suppress
11043 block-local extern declarations (whether used or not) because that
11044 would screw-up the debugger's name lookup mechanism and cause it to
11045 miss things which really ought to be in scope at a given point. */
11046 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11049 /* If we are in terse mode, don't generate any DIEs to represent any
11050 variable declarations or definitions. */
11051 if (debug_info_level <= DINFO_LEVEL_TERSE)
11056 /* Don't emit stubs for types unless they are needed by other DIEs. */
11057 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11060 /* Don't bother trying to generate any DIEs to represent any of the
11061 normal built-in types for the language we are compiling. */
11062 if (DECL_SOURCE_LINE (decl) == 0)
11064 /* OK, we need to generate one for `bool' so GDB knows what type
11065 comparisons have. */
11066 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11067 == DW_LANG_C_plus_plus)
11068 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11069 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11074 /* If we are in terse mode, don't generate any DIEs for types. */
11075 if (debug_info_level <= DINFO_LEVEL_TERSE)
11078 /* If we're a function-scope tag, initially use a parent of NULL;
11079 this will be fixed up in decls_for_scope. */
11080 if (decl_function_context (decl))
11081 context_die = NULL;
11089 gen_decl_die (decl, context_die);
11092 /* Output a marker (i.e. a label) for the beginning of the generated code for
11093 a lexical block. */
11096 dwarf2out_begin_block (blocknum)
11097 register unsigned blocknum;
11099 function_section (current_function_decl);
11100 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11103 /* Output a marker (i.e. a label) for the end of the generated code for a
11107 dwarf2out_end_block (blocknum)
11108 register unsigned blocknum;
11110 function_section (current_function_decl);
11111 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11114 /* Returns nonzero if it is appropriate not to emit any debugging
11115 information for BLOCK, because it doesn't contain any instructions.
11117 Don't allow this for blocks with nested functions or local classes
11118 as we would end up with orphans, and in the presence of scheduling
11119 we may end up calling them anyway. */
11122 dwarf2out_ignore_block (block)
11126 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11127 if (TREE_CODE (decl) == FUNCTION_DECL
11128 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11133 /* Lookup a filename (in the list of filenames that we know about here in
11134 dwarf2out.c) and return its "index". The index of each (known) filename is
11135 just a unique number which is associated with only that one filename.
11136 We need such numbers for the sake of generating labels
11137 (in the .debug_sfnames section) and references to those
11138 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11139 If the filename given as an argument is not found in our current list,
11140 add it to the list and assign it the next available unique index number.
11141 In order to speed up searches, we remember the index of the filename
11142 was looked up last. This handles the majority of all searches. */
11145 lookup_filename (file_name)
11146 const char *file_name;
11148 register unsigned i;
11150 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11151 if (strcmp (file_name, "<internal>") == 0
11152 || strcmp (file_name, "<built-in>") == 0)
11155 /* Check to see if the file name that was searched on the previous
11156 call matches this file name. If so, return the index. */
11157 if (file_table.last_lookup_index != 0)
11158 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
11159 return file_table.last_lookup_index;
11161 /* Didn't match the previous lookup, search the table */
11162 for (i = 1; i < file_table.in_use; ++i)
11163 if (strcmp (file_name, file_table.table[i]) == 0)
11165 file_table.last_lookup_index = i;
11169 /* Prepare to add a new table entry by making sure there is enough space in
11170 the table to do so. If not, expand the current table. */
11171 if (i == file_table.allocated)
11173 file_table.allocated = i + FILE_TABLE_INCREMENT;
11174 file_table.table = (char **)
11175 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11178 /* Add the new entry to the end of the filename table. */
11179 file_table.table[i] = xstrdup (file_name);
11180 file_table.in_use = i + 1;
11181 file_table.last_lookup_index = i;
11183 if (DWARF2_ASM_LINE_DEBUG_INFO)
11184 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11192 /* Allocate the initial hunk of the file_table. */
11193 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11194 file_table.allocated = FILE_TABLE_INCREMENT;
11196 /* Skip the first entry - file numbers begin at 1. */
11197 file_table.in_use = 1;
11198 file_table.last_lookup_index = 0;
11201 /* Output a label to mark the beginning of a source code line entry
11202 and record information relating to this source line, in
11203 'line_info_table' for later output of the .debug_line section. */
11206 dwarf2out_line (filename, line)
11207 register const char *filename;
11208 register unsigned line;
11210 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11212 function_section (current_function_decl);
11214 /* If requested, emit something human-readable. */
11215 if (flag_debug_asm)
11216 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11219 if (DWARF2_ASM_LINE_DEBUG_INFO)
11221 unsigned file_num = lookup_filename (filename);
11223 /* Emit the .loc directive understood by GNU as. */
11224 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11226 /* Indicate that line number info exists. */
11227 ++line_info_table_in_use;
11229 /* Indicate that multiple line number tables exist. */
11230 if (DECL_SECTION_NAME (current_function_decl))
11231 ++separate_line_info_table_in_use;
11233 else if (DECL_SECTION_NAME (current_function_decl))
11235 register dw_separate_line_info_ref line_info;
11236 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11237 separate_line_info_table_in_use);
11239 /* expand the line info table if necessary */
11240 if (separate_line_info_table_in_use
11241 == separate_line_info_table_allocated)
11243 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11244 separate_line_info_table
11245 = (dw_separate_line_info_ref)
11246 xrealloc (separate_line_info_table,
11247 separate_line_info_table_allocated
11248 * sizeof (dw_separate_line_info_entry));
11251 /* Add the new entry at the end of the line_info_table. */
11253 = &separate_line_info_table[separate_line_info_table_in_use++];
11254 line_info->dw_file_num = lookup_filename (filename);
11255 line_info->dw_line_num = line;
11256 line_info->function = current_funcdef_number;
11260 register dw_line_info_ref line_info;
11262 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11263 line_info_table_in_use);
11265 /* Expand the line info table if necessary. */
11266 if (line_info_table_in_use == line_info_table_allocated)
11268 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11270 = (dw_line_info_ref)
11271 xrealloc (line_info_table,
11272 (line_info_table_allocated
11273 * sizeof (dw_line_info_entry)));
11276 /* Add the new entry at the end of the line_info_table. */
11277 line_info = &line_info_table[line_info_table_in_use++];
11278 line_info->dw_file_num = lookup_filename (filename);
11279 line_info->dw_line_num = line;
11284 /* Record the beginning of a new source file. */
11287 dwarf2out_start_source_file (lineno, filename)
11288 register unsigned int lineno ATTRIBUTE_UNUSED;
11289 register const char *filename ATTRIBUTE_UNUSED;
11291 if (flag_eliminate_dwarf2_dups)
11293 /* Record the beginning of the file for break_out_includes. */
11294 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11295 add_AT_string (bincl_die, DW_AT_name, filename);
11297 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11299 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11300 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11301 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", lineno);
11302 dw2_asm_output_data_uleb128 (lookup_filename (filename), "Filename we just started");
11306 /* Record the end of a source file. */
11309 dwarf2out_end_source_file ()
11311 if (flag_eliminate_dwarf2_dups)
11313 /* Record the end of the file for break_out_includes. */
11314 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11316 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11318 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11319 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11323 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11324 the tail part of the directive line, i.e. the part which is past the
11325 initial whitespace, #, whitespace, directive-name, whitespace part. */
11328 dwarf2out_define (lineno, buffer)
11329 register unsigned lineno ATTRIBUTE_UNUSED;
11330 register const char *buffer ATTRIBUTE_UNUSED;
11332 static int initialized = 0;
11335 dwarf2out_start_source_file (0, primary_filename);
11338 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11340 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11341 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11342 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11343 dw2_asm_output_nstring (buffer, -1, "The macro");
11347 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11348 the tail part of the directive line, i.e. the part which is past the
11349 initial whitespace, #, whitespace, directive-name, whitespace part. */
11352 dwarf2out_undef (lineno, buffer)
11353 register unsigned lineno ATTRIBUTE_UNUSED;
11354 register const char *buffer ATTRIBUTE_UNUSED;
11356 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11358 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11359 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
11360 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11361 dw2_asm_output_nstring (buffer, -1, "The macro");
11365 /* Set up for Dwarf output at the start of compilation. */
11368 dwarf2out_init (asm_out_file, main_input_filename)
11369 register FILE *asm_out_file;
11370 register const char *main_input_filename;
11372 init_file_table ();
11374 /* Remember the name of the primary input file. */
11375 primary_filename = main_input_filename;
11377 /* Add it to the file table first, under the assumption that we'll
11378 be emitting line number data for it first, which avoids having
11379 to add an initial DW_LNS_set_file. */
11380 lookup_filename (main_input_filename);
11382 /* Allocate the initial hunk of the decl_die_table. */
11384 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11385 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11386 decl_die_table_in_use = 0;
11388 /* Allocate the initial hunk of the decl_scope_table. */
11390 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11391 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11392 decl_scope_depth = 0;
11394 /* Allocate the initial hunk of the abbrev_die_table. */
11396 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11397 sizeof (dw_die_ref));
11398 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11399 /* Zero-th entry is allocated, but unused */
11400 abbrev_die_table_in_use = 1;
11402 /* Allocate the initial hunk of the line_info_table. */
11404 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11405 sizeof (dw_line_info_entry));
11406 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11407 /* Zero-th entry is allocated, but unused */
11408 line_info_table_in_use = 1;
11410 /* Generate the initial DIE for the .debug section. Note that the (string)
11411 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11412 will (typically) be a relative pathname and that this pathname should be
11413 taken as being relative to the directory from which the compiler was
11414 invoked when the given (base) source file was compiled. */
11415 comp_unit_die = gen_compile_unit_die (main_input_filename);
11417 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11418 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11420 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11421 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
11422 DEBUG_ABBREV_SECTION_LABEL, 0);
11423 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11424 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11426 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11427 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11428 DEBUG_INFO_SECTION_LABEL, 0);
11429 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11430 DEBUG_LINE_SECTION_LABEL, 0);
11431 ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, 0);
11432 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION);
11433 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
11434 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION);
11435 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11436 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11438 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11439 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11441 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11442 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11443 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11444 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11445 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11447 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11448 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
11449 DEBUG_MACINFO_SECTION_LABEL, 0);
11450 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
11454 /* Output stuff that dwarf requires at the end of every file,
11455 and generate the DWARF-2 debugging info. */
11458 dwarf2out_finish (asm_out_file, input_filename)
11459 register FILE *asm_out_file;
11460 register const char *input_filename ATTRIBUTE_UNUSED;
11462 limbo_die_node *node, *next_node;
11463 dw_die_ref die = 0;
11465 /* Traverse the limbo die list, and add parent/child links. The only
11466 dies without parents that should be here are concrete instances of
11467 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11468 For concrete instances, we can get the parent die from the abstract
11470 for (node = limbo_die_list; node; node = next_node)
11472 next_node = node->next;
11475 if (die->die_parent == NULL)
11477 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11479 add_child_die (origin->die_parent, die);
11480 else if (die == comp_unit_die)
11487 limbo_die_list = NULL;
11489 /* Walk through the list of incomplete types again, trying once more to
11490 emit full debugging info for them. */
11491 retry_incomplete_types ();
11493 /* We need to reverse all the dies before break_out_includes, or
11494 we'll see the end of an include file before the beginning. */
11495 reverse_all_dies (comp_unit_die);
11497 /* Generate separate CUs for each of the include files we've seen.
11498 They will go into limbo_die_list. */
11499 if (flag_eliminate_dwarf2_dups)
11500 break_out_includes (comp_unit_die);
11502 /* Traverse the DIE's and add add sibling attributes to those DIE's
11503 that have children. */
11504 add_sibling_attributes (comp_unit_die);
11505 for (node = limbo_die_list; node; node = node->next)
11506 add_sibling_attributes (node->die);
11508 /* Output a terminator label for the .text section. */
11509 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11510 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11513 /* Output a terminator label for the .data section. */
11514 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11515 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11517 /* Output a terminator label for the .bss section. */
11518 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11519 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11522 /* Output the source line correspondence table. We must do this
11523 even if there is no line information. Otherwise, on an empty
11524 translation unit, we will generate a present, but empty,
11525 .debug_info section. IRIX 6.5 `nm' will then complain when
11526 examining the file. */
11527 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11529 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11530 output_line_info ();
11533 /* We can only use the low/high_pc attributes if all of the code was
11535 if (separate_line_info_table_in_use == 0)
11537 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11538 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11541 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11542 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11543 debug_line_section_label);
11545 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11546 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
11548 /* Output all of the compilation units. We put the main one last so that
11549 the offsets are available to output_pubnames. */
11550 for (node = limbo_die_list; node; node = node->next)
11551 output_comp_unit (node->die);
11552 output_comp_unit (comp_unit_die);
11554 /* Output the abbreviation table. */
11555 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION);
11556 output_abbrev_section ();
11558 if (pubname_table_in_use)
11560 /* Output public names table. */
11561 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
11562 output_pubnames ();
11565 /* We only put functions in the arange table, so don't write it out if
11566 we don't have any. */
11567 if (fde_table_in_use)
11569 /* Output the address range information. */
11570 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
11573 /* Output location list section if necessary */
11574 if (have_location_lists)
11576 /* Output the location lists info. */
11577 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION);
11578 output_location_lists (die);
11579 have_location_lists = 0;
11582 /* Have to end the primary source file. */
11583 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11585 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11586 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11590 #else /* DWARF2_DEBUGGING_INFO
11592 /* Use dummy versions of init and finish routines. */
11595 dwarf2out_init (asm_out_file, main_input_filename)
11596 register FILE *asm_out_file ATTRIBUTE_UNUSED;
11597 register const char *main_input_filename ATTRIBUTE_UNUSED;
11602 dwarf2out_finish (asm_out_file, input_filename)
11603 register FILE *asm_out_file ATTRIBUTE_UNUSED;
11604 register const char *input_filename ATTRIBUTE_UNUSED;
11608 #endif /* DWARF2_DEBUGGING_INFO */