1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
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 GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
42 #include "hard-reg-set.h"
44 #include "insn-config.h"
52 #include "dwarf2out.h"
53 #include "dwarf2asm.h"
59 #include "diagnostic.h"
62 #include "langhooks.h"
63 #include "hashtable.h"
65 #ifdef DWARF2_DEBUGGING_INFO
66 static void dwarf2out_source_line PARAMS ((unsigned int, const char *));
69 /* DWARF2 Abbreviation Glossary:
70 CFA = Canonical Frame Address
71 a fixed address on the stack which identifies a call frame.
72 We define it to be the value of SP just before the call insn.
73 The CFA register and offset, which may change during the course
74 of the function, are used to calculate its value at runtime.
75 CFI = Call Frame Instruction
76 an instruction for the DWARF2 abstract machine
77 CIE = Common Information Entry
78 information describing information common to one or more FDEs
79 DIE = Debugging Information Entry
80 FDE = Frame Description Entry
81 information describing the stack call frame, in particular,
82 how to restore registers
84 DW_CFA_... = DWARF2 CFA call frame instruction
85 DW_TAG_... = DWARF2 DIE tag */
87 /* Decide whether we want to emit frame unwind information for the current
93 return (write_symbols == DWARF2_DEBUG
94 || write_symbols == VMS_AND_DWARF2_DEBUG
95 #ifdef DWARF2_FRAME_INFO
98 #ifdef DWARF2_UNWIND_INFO
100 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
105 /* The number of the current function definition for which debugging
106 information is being generated. These numbers range from 1 up to the
107 maximum number of function definitions contained within the current
108 compilation unit. These numbers are used to create unique label id's
109 unique to each function definition. */
110 unsigned current_funcdef_number = 0;
112 /* The size of the target's pointer type. */
114 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
117 /* Default version of targetm.eh_frame_section. Note this must appear
118 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
122 default_eh_frame_section ()
124 #ifdef EH_FRAME_SECTION_NAME
125 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
127 tree label = get_file_function_name ('F');
130 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
131 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
132 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
136 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
138 /* How to start an assembler comment. */
139 #ifndef ASM_COMMENT_START
140 #define ASM_COMMENT_START ";#"
143 typedef struct dw_cfi_struct *dw_cfi_ref;
144 typedef struct dw_fde_struct *dw_fde_ref;
145 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
147 /* Call frames are described using a sequence of Call Frame
148 Information instructions. The register number, offset
149 and address fields are provided as possible operands;
150 their use is selected by the opcode field. */
152 typedef union dw_cfi_oprnd_struct
154 unsigned long dw_cfi_reg_num;
155 long int dw_cfi_offset;
156 const char *dw_cfi_addr;
157 struct dw_loc_descr_struct *dw_cfi_loc;
161 typedef struct dw_cfi_struct
163 dw_cfi_ref dw_cfi_next;
164 enum dwarf_call_frame_info dw_cfi_opc;
165 dw_cfi_oprnd dw_cfi_oprnd1;
166 dw_cfi_oprnd dw_cfi_oprnd2;
170 /* This is how we define the location of the CFA. We use to handle it
171 as REG + OFFSET all the time, but now it can be more complex.
172 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
173 Instead of passing around REG and OFFSET, we pass a copy
174 of this structure. */
175 typedef struct cfa_loc
180 int indirect; /* 1 if CFA is accessed via a dereference. */
183 /* All call frame descriptions (FDE's) in the GCC generated DWARF
184 refer to a single Common Information Entry (CIE), defined at
185 the beginning of the .debug_frame section. This use of a single
186 CIE obviates the need to keep track of multiple CIE's
187 in the DWARF generation routines below. */
189 typedef struct dw_fde_struct
191 const char *dw_fde_begin;
192 const char *dw_fde_current_label;
193 const char *dw_fde_end;
194 dw_cfi_ref dw_fde_cfi;
195 unsigned funcdef_number;
196 unsigned nothrow : 1;
197 unsigned uses_eh_lsda : 1;
201 /* Maximum size (in bytes) of an artificially generated label. */
202 #define MAX_ARTIFICIAL_LABEL_BYTES 30
204 /* The size of addresses as they appear in the Dwarf 2 data.
205 Some architectures use word addresses to refer to code locations,
206 but Dwarf 2 info always uses byte addresses. On such machines,
207 Dwarf 2 addresses need to be larger than the architecture's
209 #ifndef DWARF2_ADDR_SIZE
210 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
213 /* The size in bytes of a DWARF field indicating an offset or length
214 relative to a debug info section, specified to be 4 bytes in the
215 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
218 #ifndef DWARF_OFFSET_SIZE
219 #define DWARF_OFFSET_SIZE 4
222 #define DWARF_VERSION 2
224 /* Round SIZE up to the nearest BOUNDARY. */
225 #define DWARF_ROUND(SIZE,BOUNDARY) \
226 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
228 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
229 #ifndef DWARF_CIE_DATA_ALIGNMENT
230 #ifdef STACK_GROWS_DOWNWARD
231 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
233 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
237 /* A pointer to the base of a table that contains frame description
238 information for each routine. */
239 static dw_fde_ref fde_table;
241 /* Number of elements currently allocated for fde_table. */
242 static unsigned fde_table_allocated;
244 /* Number of elements in fde_table currently in use. */
245 static unsigned fde_table_in_use;
247 /* Size (in elements) of increments by which we may expand the
249 #define FDE_TABLE_INCREMENT 256
251 /* A list of call frame insns for the CIE. */
252 static dw_cfi_ref cie_cfi_head;
254 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
255 attribute that accelerates the lookup of the FDE associated
256 with the subprogram. This variable holds the table index of the FDE
257 associated with the current function (body) definition. */
258 static unsigned current_funcdef_fde;
260 struct ht *debug_str_hash;
262 struct indirect_string_node
264 struct ht_identifier id;
265 unsigned int refcount;
270 /* Forward declarations for functions defined in this file. */
272 static char *stripattributes PARAMS ((const char *));
273 static const char *dwarf_cfi_name PARAMS ((unsigned));
274 static dw_cfi_ref new_cfi PARAMS ((void));
275 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
276 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
277 static void lookup_cfa_1 PARAMS ((dw_cfi_ref,
279 static void lookup_cfa PARAMS ((dw_cfa_location *));
280 static void reg_save PARAMS ((const char *, unsigned,
282 static void initial_return_save PARAMS ((rtx));
283 static long stack_adjust_offset PARAMS ((rtx));
284 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
285 static void output_call_frame_info PARAMS ((int));
286 static void dwarf2out_stack_adjust PARAMS ((rtx));
287 static void queue_reg_save PARAMS ((const char *, rtx, long));
288 static void flush_queued_reg_saves PARAMS ((void));
289 static bool clobbers_queued_reg_save PARAMS ((rtx));
290 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
292 /* Support for complex CFA locations. */
293 static void output_cfa_loc PARAMS ((dw_cfi_ref));
294 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
295 struct dw_loc_descr_struct *));
296 static struct dw_loc_descr_struct *build_cfa_loc
297 PARAMS ((dw_cfa_location *));
298 static void def_cfa_1 PARAMS ((const char *,
301 /* How to start an assembler comment. */
302 #ifndef ASM_COMMENT_START
303 #define ASM_COMMENT_START ";#"
306 /* Data and reference forms for relocatable data. */
307 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
308 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
310 /* Pseudo-op for defining a new section. */
311 #ifndef SECTION_ASM_OP
312 #define SECTION_ASM_OP "\t.section\t"
315 #ifndef DEBUG_FRAME_SECTION
316 #define DEBUG_FRAME_SECTION ".debug_frame"
319 #ifndef FUNC_BEGIN_LABEL
320 #define FUNC_BEGIN_LABEL "LFB"
323 #ifndef FUNC_END_LABEL
324 #define FUNC_END_LABEL "LFE"
327 #define FRAME_BEGIN_LABEL "Lframe"
328 #define CIE_AFTER_SIZE_LABEL "LSCIE"
329 #define CIE_END_LABEL "LECIE"
330 #define CIE_LENGTH_LABEL "LLCIE"
331 #define FDE_LABEL "LSFDE"
332 #define FDE_AFTER_SIZE_LABEL "LASFDE"
333 #define FDE_END_LABEL "LEFDE"
334 #define FDE_LENGTH_LABEL "LLFDE"
335 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
336 #define LINE_NUMBER_END_LABEL "LELT"
337 #define LN_PROLOG_AS_LABEL "LASLTP"
338 #define LN_PROLOG_END_LABEL "LELTP"
339 #define DIE_LABEL_PREFIX "DW"
341 /* Definitions of defaults for various types of primitive assembly language
342 output operations. These may be overridden from within the tm.h file,
343 but typically, that is unnecessary. */
346 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
347 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
349 fprintf (FILE, "%s", SET_ASM_OP); \
350 assemble_name (FILE, SY); \
352 assemble_name (FILE, HI); \
354 assemble_name (FILE, LO); \
359 /* The DWARF 2 CFA column which tracks the return address. Normally this
360 is the column for PC, or the first column after all of the hard
362 #ifndef DWARF_FRAME_RETURN_COLUMN
364 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
366 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
370 /* The mapping from gcc register number to DWARF 2 CFA column number. By
371 default, we just provide columns for all registers. */
372 #ifndef DWARF_FRAME_REGNUM
373 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
376 /* The offset from the incoming value of %sp to the top of the stack frame
377 for the current function. */
378 #ifndef INCOMING_FRAME_SP_OFFSET
379 #define INCOMING_FRAME_SP_OFFSET 0
382 /* Hook used by __throw. */
385 expand_builtin_dwarf_fp_regnum ()
387 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
390 /* Return a pointer to a copy of the section string name S with all
391 attributes stripped off, and an asterisk prepended (for assemble_name). */
397 char *stripped = xmalloc (strlen (s) + 2);
402 while (*s && *s != ',')
409 /* Generate code to initialize the register size table. */
412 expand_builtin_init_dwarf_reg_sizes (address)
416 enum machine_mode mode = TYPE_MODE (char_type_node);
417 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
418 rtx mem = gen_rtx_MEM (BLKmode, addr);
420 for (i = 0; i < DWARF_FRAME_REGISTERS; i++)
422 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
423 HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]);
428 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
432 /* Convert a DWARF call frame info. operation to its string name */
435 dwarf_cfi_name (cfi_opc)
440 case DW_CFA_advance_loc:
441 return "DW_CFA_advance_loc";
443 return "DW_CFA_offset";
445 return "DW_CFA_restore";
449 return "DW_CFA_set_loc";
450 case DW_CFA_advance_loc1:
451 return "DW_CFA_advance_loc1";
452 case DW_CFA_advance_loc2:
453 return "DW_CFA_advance_loc2";
454 case DW_CFA_advance_loc4:
455 return "DW_CFA_advance_loc4";
456 case DW_CFA_offset_extended:
457 return "DW_CFA_offset_extended";
458 case DW_CFA_restore_extended:
459 return "DW_CFA_restore_extended";
460 case DW_CFA_undefined:
461 return "DW_CFA_undefined";
462 case DW_CFA_same_value:
463 return "DW_CFA_same_value";
464 case DW_CFA_register:
465 return "DW_CFA_register";
466 case DW_CFA_remember_state:
467 return "DW_CFA_remember_state";
468 case DW_CFA_restore_state:
469 return "DW_CFA_restore_state";
471 return "DW_CFA_def_cfa";
472 case DW_CFA_def_cfa_register:
473 return "DW_CFA_def_cfa_register";
474 case DW_CFA_def_cfa_offset:
475 return "DW_CFA_def_cfa_offset";
478 case DW_CFA_def_cfa_expression:
479 return "DW_CFA_def_cfa_expression";
480 case DW_CFA_expression:
481 return "DW_CFA_expression";
482 case DW_CFA_offset_extended_sf:
483 return "DW_CFA_offset_extended_sf";
484 case DW_CFA_def_cfa_sf:
485 return "DW_CFA_def_cfa_sf";
486 case DW_CFA_def_cfa_offset_sf:
487 return "DW_CFA_def_cfa_offset_sf";
489 /* SGI/MIPS specific */
490 case DW_CFA_MIPS_advance_loc8:
491 return "DW_CFA_MIPS_advance_loc8";
494 case DW_CFA_GNU_window_save:
495 return "DW_CFA_GNU_window_save";
496 case DW_CFA_GNU_args_size:
497 return "DW_CFA_GNU_args_size";
498 case DW_CFA_GNU_negative_offset_extended:
499 return "DW_CFA_GNU_negative_offset_extended";
502 return "DW_CFA_<unknown>";
506 /* Return a pointer to a newly allocated Call Frame Instruction. */
508 static inline dw_cfi_ref
511 dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
513 cfi->dw_cfi_next = NULL;
514 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
515 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
520 /* Add a Call Frame Instruction to list of instructions. */
523 add_cfi (list_head, cfi)
524 dw_cfi_ref *list_head;
529 /* Find the end of the chain. */
530 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
536 /* Generate a new label for the CFI info to refer to. */
539 dwarf2out_cfi_label ()
541 static char label[20];
542 static unsigned long label_num = 0;
544 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
545 ASM_OUTPUT_LABEL (asm_out_file, label);
549 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
550 or to the CIE if LABEL is NULL. */
553 add_fde_cfi (label, cfi)
559 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
562 label = dwarf2out_cfi_label ();
564 if (fde->dw_fde_current_label == NULL
565 || strcmp (label, fde->dw_fde_current_label) != 0)
569 fde->dw_fde_current_label = label = xstrdup (label);
571 /* Set the location counter to the new label. */
573 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
574 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
575 add_cfi (&fde->dw_fde_cfi, xcfi);
578 add_cfi (&fde->dw_fde_cfi, cfi);
582 add_cfi (&cie_cfi_head, cfi);
585 /* Subroutine of lookup_cfa. */
588 lookup_cfa_1 (cfi, loc)
590 dw_cfa_location *loc;
592 switch (cfi->dw_cfi_opc)
594 case DW_CFA_def_cfa_offset:
595 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
597 case DW_CFA_def_cfa_register:
598 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
601 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
602 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
604 case DW_CFA_def_cfa_expression:
605 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
612 /* Find the previous value for the CFA. */
616 dw_cfa_location *loc;
620 loc->reg = (unsigned long) -1;
623 loc->base_offset = 0;
625 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
626 lookup_cfa_1 (cfi, loc);
628 if (fde_table_in_use)
630 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
631 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
632 lookup_cfa_1 (cfi, loc);
636 /* The current rule for calculating the DWARF2 canonical frame address. */
637 static dw_cfa_location cfa;
639 /* The register used for saving registers to the stack, and its offset
641 static dw_cfa_location cfa_store;
643 /* The running total of the size of arguments pushed onto the stack. */
644 static long args_size;
646 /* The last args_size we actually output. */
647 static long old_args_size;
649 /* Entry point to update the canonical frame address (CFA).
650 LABEL is passed to add_fde_cfi. The value of CFA is now to be
651 calculated from REG+OFFSET. */
654 dwarf2out_def_cfa (label, reg, offset)
664 def_cfa_1 (label, &loc);
667 /* This routine does the actual work. The CFA is now calculated from
668 the dw_cfa_location structure. */
671 def_cfa_1 (label, loc_p)
673 dw_cfa_location *loc_p;
676 dw_cfa_location old_cfa, loc;
681 if (cfa_store.reg == loc.reg && loc.indirect == 0)
682 cfa_store.offset = loc.offset;
684 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
685 lookup_cfa (&old_cfa);
687 /* If nothing changed, no need to issue any call frame instructions. */
688 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
689 && loc.indirect == old_cfa.indirect
690 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
695 if (loc.reg == old_cfa.reg && !loc.indirect)
697 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
698 indicating the CFA register did not change but the offset
700 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
701 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
704 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
705 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
708 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
709 indicating the CFA register has changed to <register> but the
710 offset has not changed. */
711 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
712 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
716 else if (loc.indirect == 0)
718 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
719 indicating the CFA register has changed to <register> with
720 the specified offset. */
721 cfi->dw_cfi_opc = DW_CFA_def_cfa;
722 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
723 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
727 /* Construct a DW_CFA_def_cfa_expression instruction to
728 calculate the CFA using a full location expression since no
729 register-offset pair is available. */
730 struct dw_loc_descr_struct *loc_list;
732 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
733 loc_list = build_cfa_loc (&loc);
734 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
737 add_fde_cfi (label, cfi);
740 /* Add the CFI for saving a register. REG is the CFA column number.
741 LABEL is passed to add_fde_cfi.
742 If SREG is -1, the register is saved at OFFSET from the CFA;
743 otherwise it is saved in SREG. */
746 reg_save (label, reg, sreg, offset)
752 dw_cfi_ref cfi = new_cfi ();
754 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
756 /* The following comparison is correct. -1 is used to indicate that
757 the value isn't a register number. */
758 if (sreg == (unsigned int) -1)
761 /* The register number won't fit in 6 bits, so we have to use
763 cfi->dw_cfi_opc = DW_CFA_offset_extended;
765 cfi->dw_cfi_opc = DW_CFA_offset;
767 #ifdef ENABLE_CHECKING
769 /* If we get an offset that is not a multiple of
770 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
771 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
773 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
775 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
779 offset /= DWARF_CIE_DATA_ALIGNMENT;
781 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
783 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
785 else if (sreg == reg)
786 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
790 cfi->dw_cfi_opc = DW_CFA_register;
791 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
794 add_fde_cfi (label, cfi);
797 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
798 This CFI tells the unwinder that it needs to restore the window registers
799 from the previous frame's window save area.
801 ??? Perhaps we should note in the CIE where windows are saved (instead of
802 assuming 0(cfa)) and what registers are in the window. */
805 dwarf2out_window_save (label)
808 dw_cfi_ref cfi = new_cfi ();
810 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
811 add_fde_cfi (label, cfi);
814 /* Add a CFI to update the running total of the size of arguments
815 pushed onto the stack. */
818 dwarf2out_args_size (label, size)
824 if (size == old_args_size)
827 old_args_size = size;
830 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
831 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
832 add_fde_cfi (label, cfi);
835 /* Entry point for saving a register to the stack. REG is the GCC register
836 number. LABEL and OFFSET are passed to reg_save. */
839 dwarf2out_reg_save (label, reg, offset)
844 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
847 /* Entry point for saving the return address in the stack.
848 LABEL and OFFSET are passed to reg_save. */
851 dwarf2out_return_save (label, offset)
855 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
858 /* Entry point for saving the return address in a register.
859 LABEL and SREG are passed to reg_save. */
862 dwarf2out_return_reg (label, sreg)
866 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
869 /* Record the initial position of the return address. RTL is
870 INCOMING_RETURN_ADDR_RTX. */
873 initial_return_save (rtl)
876 unsigned int reg = (unsigned int) -1;
877 HOST_WIDE_INT offset = 0;
879 switch (GET_CODE (rtl))
882 /* RA is in a register. */
883 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
887 /* RA is on the stack. */
889 switch (GET_CODE (rtl))
892 if (REGNO (rtl) != STACK_POINTER_REGNUM)
898 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
900 offset = INTVAL (XEXP (rtl, 1));
904 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
906 offset = -INTVAL (XEXP (rtl, 1));
916 /* The return address is at some offset from any value we can
917 actually load. For instance, on the SPARC it is in %i7+8. Just
918 ignore the offset for now; it doesn't matter for unwinding frames. */
919 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
921 initial_return_save (XEXP (rtl, 0));
928 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
931 /* Given a SET, calculate the amount of stack adjustment it
935 stack_adjust_offset (pattern)
938 rtx src = SET_SRC (pattern);
939 rtx dest = SET_DEST (pattern);
940 HOST_WIDE_INT offset = 0;
943 if (dest == stack_pointer_rtx)
945 /* (set (reg sp) (plus (reg sp) (const_int))) */
946 code = GET_CODE (src);
947 if (! (code == PLUS || code == MINUS)
948 || XEXP (src, 0) != stack_pointer_rtx
949 || GET_CODE (XEXP (src, 1)) != CONST_INT)
952 offset = INTVAL (XEXP (src, 1));
954 else if (GET_CODE (dest) == MEM)
956 /* (set (mem (pre_dec (reg sp))) (foo)) */
957 src = XEXP (dest, 0);
958 code = GET_CODE (src);
960 if ((code != PRE_DEC && code != PRE_INC && code != PRE_MODIFY)
961 || XEXP (src, 0) != stack_pointer_rtx)
964 if (code == PRE_MODIFY)
966 rtx val = XEXP (XEXP (src, 1), 1);
968 /* We handle only adjustments by constant amount. */
969 if (GET_CODE (XEXP (src, 1)) != PLUS ||
970 GET_CODE (val) != CONST_INT)
973 offset = -INTVAL (val);
976 offset = GET_MODE_SIZE (GET_MODE (dest));
981 if (code == PLUS || code == PRE_INC)
987 /* Check INSN to see if it looks like a push or a stack adjustment, and
988 make a note of it if it does. EH uses this information to find out how
989 much extra space it needs to pop off the stack. */
992 dwarf2out_stack_adjust (insn)
995 HOST_WIDE_INT offset;
999 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1001 /* Extract the size of the args from the CALL rtx itself. */
1002 insn = PATTERN (insn);
1003 if (GET_CODE (insn) == PARALLEL)
1004 insn = XVECEXP (insn, 0, 0);
1005 if (GET_CODE (insn) == SET)
1006 insn = SET_SRC (insn);
1007 if (GET_CODE (insn) != CALL)
1010 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1014 /* If only calls can throw, and we have a frame pointer,
1015 save up adjustments until we see the CALL_INSN. */
1016 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1019 if (GET_CODE (insn) == BARRIER)
1021 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1022 the compiler will have already emitted a stack adjustment, but
1023 doesn't bother for calls to noreturn functions. */
1024 #ifdef STACK_GROWS_DOWNWARD
1025 offset = -args_size;
1030 else if (GET_CODE (PATTERN (insn)) == SET)
1031 offset = stack_adjust_offset (PATTERN (insn));
1032 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1033 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1035 /* There may be stack adjustments inside compound insns. Search
1037 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1038 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1039 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1047 if (cfa.reg == STACK_POINTER_REGNUM)
1048 cfa.offset += offset;
1050 #ifndef STACK_GROWS_DOWNWARD
1054 args_size += offset;
1058 label = dwarf2out_cfi_label ();
1059 def_cfa_1 (label, &cfa);
1060 dwarf2out_args_size (label, args_size);
1063 /* We delay emitting a register save until either (a) we reach the end
1064 of the prologue or (b) the register is clobbered. This clusters
1065 register saves so that there are fewer pc advances. */
1067 struct queued_reg_save
1069 struct queued_reg_save *next;
1074 static struct queued_reg_save *queued_reg_saves;
1075 static const char *last_reg_save_label;
1078 queue_reg_save (label, reg, offset)
1083 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1085 q->next = queued_reg_saves;
1087 q->cfa_offset = offset;
1088 queued_reg_saves = q;
1090 last_reg_save_label = label;
1094 flush_queued_reg_saves ()
1096 struct queued_reg_save *q, *next;
1098 for (q = queued_reg_saves; q ; q = next)
1100 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1105 queued_reg_saves = NULL;
1106 last_reg_save_label = NULL;
1110 clobbers_queued_reg_save (insn)
1113 struct queued_reg_save *q;
1115 for (q = queued_reg_saves; q ; q = q->next)
1116 if (modified_in_p (q->reg, insn))
1123 /* A temporary register holding an integral value used in adjusting SP
1124 or setting up the store_reg. The "offset" field holds the integer
1125 value, not an offset. */
1126 static dw_cfa_location cfa_temp;
1128 /* Record call frame debugging information for an expression EXPR,
1129 which either sets SP or FP (adjusting how we calculate the frame
1130 address) or saves a register to the stack. LABEL indicates the
1133 This function encodes a state machine mapping rtxes to actions on
1134 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1135 users need not read the source code.
1137 The High-Level Picture
1139 Changes in the register we use to calculate the CFA: Currently we
1140 assume that if you copy the CFA register into another register, we
1141 should take the other one as the new CFA register; this seems to
1142 work pretty well. If it's wrong for some target, it's simple
1143 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1145 Changes in the register we use for saving registers to the stack:
1146 This is usually SP, but not always. Again, we deduce that if you
1147 copy SP into another register (and SP is not the CFA register),
1148 then the new register is the one we will be using for register
1149 saves. This also seems to work.
1151 Register saves: There's not much guesswork about this one; if
1152 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1153 register save, and the register used to calculate the destination
1154 had better be the one we think we're using for this purpose.
1156 Except: If the register being saved is the CFA register, and the
1157 offset is non-zero, we are saving the CFA, so we assume we have to
1158 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1159 the intent is to save the value of SP from the previous frame.
1161 Invariants / Summaries of Rules
1163 cfa current rule for calculating the CFA. It usually
1164 consists of a register and an offset.
1165 cfa_store register used by prologue code to save things to the stack
1166 cfa_store.offset is the offset from the value of
1167 cfa_store.reg to the actual CFA
1168 cfa_temp register holding an integral value. cfa_temp.offset
1169 stores the value, which will be used to adjust the
1170 stack pointer. cfa_temp is also used like cfa_store,
1171 to track stores to the stack via fp or a temp reg.
1173 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1174 with cfa.reg as the first operand changes the cfa.reg and its
1175 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1178 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1179 expression yielding a constant. This sets cfa_temp.reg
1180 and cfa_temp.offset.
1182 Rule 5: Create a new register cfa_store used to save items to the
1185 Rules 10-14: Save a register to the stack. Define offset as the
1186 difference of the original location and cfa_store's
1187 location (or cfa_temp's location if cfa_temp is used).
1191 "{a,b}" indicates a choice of a xor b.
1192 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1195 (set <reg1> <reg2>:cfa.reg)
1196 effects: cfa.reg = <reg1>
1197 cfa.offset unchanged
1198 cfa_temp.reg = <reg1>
1199 cfa_temp.offset = cfa.offset
1202 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1203 {<const_int>,<reg>:cfa_temp.reg}))
1204 effects: cfa.reg = sp if fp used
1205 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1206 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1207 if cfa_store.reg==sp
1210 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1211 effects: cfa.reg = fp
1212 cfa_offset += +/- <const_int>
1215 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1216 constraints: <reg1> != fp
1218 effects: cfa.reg = <reg1>
1219 cfa_temp.reg = <reg1>
1220 cfa_temp.offset = cfa.offset
1223 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1224 constraints: <reg1> != fp
1226 effects: cfa_store.reg = <reg1>
1227 cfa_store.offset = cfa.offset - cfa_temp.offset
1230 (set <reg> <const_int>)
1231 effects: cfa_temp.reg = <reg>
1232 cfa_temp.offset = <const_int>
1235 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1236 effects: cfa_temp.reg = <reg1>
1237 cfa_temp.offset |= <const_int>
1240 (set <reg> (high <exp>))
1244 (set <reg> (lo_sum <exp> <const_int>))
1245 effects: cfa_temp.reg = <reg>
1246 cfa_temp.offset = <const_int>
1249 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1250 effects: cfa_store.offset -= <const_int>
1251 cfa.offset = cfa_store.offset if cfa.reg == sp
1253 cfa.base_offset = -cfa_store.offset
1256 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1257 effects: cfa_store.offset += -/+ mode_size(mem)
1258 cfa.offset = cfa_store.offset if cfa.reg == sp
1260 cfa.base_offset = -cfa_store.offset
1263 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1266 effects: cfa.reg = <reg1>
1267 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1270 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1271 effects: cfa.reg = <reg1>
1272 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1275 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1276 effects: cfa.reg = <reg1>
1277 cfa.base_offset = -cfa_temp.offset
1278 cfa_temp.offset -= mode_size(mem) */
1281 dwarf2out_frame_debug_expr (expr, label)
1286 HOST_WIDE_INT offset;
1288 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1289 the PARALLEL independently. The first element is always processed if
1290 it is a SET. This is for backward compatibility. Other elements
1291 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1292 flag is set in them. */
1293 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1296 int limit = XVECLEN (expr, 0);
1298 for (par_index = 0; par_index < limit; par_index++)
1299 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1300 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1302 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1307 if (GET_CODE (expr) != SET)
1310 src = SET_SRC (expr);
1311 dest = SET_DEST (expr);
1313 switch (GET_CODE (dest))
1317 /* Update the CFA rule wrt SP or FP. Make sure src is
1318 relative to the current CFA register. */
1319 switch (GET_CODE (src))
1321 /* Setting FP from SP. */
1323 if (cfa.reg == (unsigned) REGNO (src))
1329 /* We used to require that dest be either SP or FP, but the
1330 ARM copies SP to a temporary register, and from there to
1331 FP. So we just rely on the backends to only set
1332 RTX_FRAME_RELATED_P on appropriate insns. */
1333 cfa.reg = REGNO (dest);
1334 cfa_temp.reg = cfa.reg;
1335 cfa_temp.offset = cfa.offset;
1341 if (dest == stack_pointer_rtx)
1345 switch (GET_CODE (XEXP (src, 1)))
1348 offset = INTVAL (XEXP (src, 1));
1351 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1353 offset = cfa_temp.offset;
1359 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1361 /* Restoring SP from FP in the epilogue. */
1362 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1364 cfa.reg = STACK_POINTER_REGNUM;
1366 else if (GET_CODE (src) == LO_SUM)
1367 /* Assume we've set the source reg of the LO_SUM from sp. */
1369 else if (XEXP (src, 0) != stack_pointer_rtx)
1372 if (GET_CODE (src) != MINUS)
1374 if (cfa.reg == STACK_POINTER_REGNUM)
1375 cfa.offset += offset;
1376 if (cfa_store.reg == STACK_POINTER_REGNUM)
1377 cfa_store.offset += offset;
1379 else if (dest == hard_frame_pointer_rtx)
1382 /* Either setting the FP from an offset of the SP,
1383 or adjusting the FP */
1384 if (! frame_pointer_needed)
1387 if (GET_CODE (XEXP (src, 0)) == REG
1388 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1389 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1391 offset = INTVAL (XEXP (src, 1));
1392 if (GET_CODE (src) != MINUS)
1394 cfa.offset += offset;
1395 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1402 if (GET_CODE (src) == MINUS)
1406 if (GET_CODE (XEXP (src, 0)) == REG
1407 && REGNO (XEXP (src, 0)) == cfa.reg
1408 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1410 /* Setting a temporary CFA register that will be copied
1411 into the FP later on. */
1412 offset = - INTVAL (XEXP (src, 1));
1413 cfa.offset += offset;
1414 cfa.reg = REGNO (dest);
1415 /* Or used to save regs to the stack. */
1416 cfa_temp.reg = cfa.reg;
1417 cfa_temp.offset = cfa.offset;
1421 else if (GET_CODE (XEXP (src, 0)) == REG
1422 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1423 && XEXP (src, 1) == stack_pointer_rtx)
1425 /* Setting a scratch register that we will use instead
1426 of SP for saving registers to the stack. */
1427 if (cfa.reg != STACK_POINTER_REGNUM)
1429 cfa_store.reg = REGNO (dest);
1430 cfa_store.offset = cfa.offset - cfa_temp.offset;
1434 else if (GET_CODE (src) == LO_SUM
1435 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1437 cfa_temp.reg = REGNO (dest);
1438 cfa_temp.offset = INTVAL (XEXP (src, 1));
1447 cfa_temp.reg = REGNO (dest);
1448 cfa_temp.offset = INTVAL (src);
1453 if (GET_CODE (XEXP (src, 0)) != REG
1454 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1455 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1458 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1459 cfa_temp.reg = REGNO (dest);
1460 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1463 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1464 which will fill in all of the bits. */
1473 def_cfa_1 (label, &cfa);
1477 if (GET_CODE (src) != REG)
1480 /* Saving a register to the stack. Make sure dest is relative to the
1482 switch (GET_CODE (XEXP (dest, 0)))
1487 /* We can't handle variable size modifications. */
1488 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1490 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1492 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1493 || cfa_store.reg != STACK_POINTER_REGNUM)
1496 cfa_store.offset += offset;
1497 if (cfa.reg == STACK_POINTER_REGNUM)
1498 cfa.offset = cfa_store.offset;
1500 offset = -cfa_store.offset;
1506 offset = GET_MODE_SIZE (GET_MODE (dest));
1507 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1510 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1511 || cfa_store.reg != STACK_POINTER_REGNUM)
1514 cfa_store.offset += offset;
1515 if (cfa.reg == STACK_POINTER_REGNUM)
1516 cfa.offset = cfa_store.offset;
1518 offset = -cfa_store.offset;
1522 /* With an offset. */
1526 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1528 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1529 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1532 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1533 offset -= cfa_store.offset;
1534 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1535 offset -= cfa_temp.offset;
1541 /* Without an offset. */
1543 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1544 offset = -cfa_store.offset;
1545 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1546 offset = -cfa_temp.offset;
1553 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1555 offset = -cfa_temp.offset;
1556 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1563 if (REGNO (src) != STACK_POINTER_REGNUM
1564 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1565 && (unsigned) REGNO (src) == cfa.reg)
1567 /* We're storing the current CFA reg into the stack. */
1569 if (cfa.offset == 0)
1571 /* If the source register is exactly the CFA, assume
1572 we're saving SP like any other register; this happens
1574 def_cfa_1 (label, &cfa);
1575 queue_reg_save (label, stack_pointer_rtx, offset);
1580 /* Otherwise, we'll need to look in the stack to
1581 calculate the CFA. */
1582 rtx x = XEXP (dest, 0);
1584 if (GET_CODE (x) != REG)
1586 if (GET_CODE (x) != REG)
1589 cfa.reg = REGNO (x);
1590 cfa.base_offset = offset;
1592 def_cfa_1 (label, &cfa);
1597 def_cfa_1 (label, &cfa);
1598 queue_reg_save (label, src, offset);
1606 /* Record call frame debugging information for INSN, which either
1607 sets SP or FP (adjusting how we calculate the frame address) or saves a
1608 register to the stack. If INSN is NULL_RTX, initialize our state. */
1611 dwarf2out_frame_debug (insn)
1617 if (insn == NULL_RTX)
1619 /* Flush any queued register saves. */
1620 flush_queued_reg_saves ();
1622 /* Set up state for generating call frame debug info. */
1624 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1627 cfa.reg = STACK_POINTER_REGNUM;
1630 cfa_temp.offset = 0;
1634 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1635 flush_queued_reg_saves ();
1637 if (! RTX_FRAME_RELATED_P (insn))
1639 if (!ACCUMULATE_OUTGOING_ARGS)
1640 dwarf2out_stack_adjust (insn);
1645 label = dwarf2out_cfi_label ();
1646 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1648 insn = XEXP (src, 0);
1650 insn = PATTERN (insn);
1652 dwarf2out_frame_debug_expr (insn, label);
1655 /* Output a Call Frame Information opcode and its operand(s). */
1658 output_cfi (cfi, fde, for_eh)
1663 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1664 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1665 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1666 "DW_CFA_advance_loc 0x%lx",
1667 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1668 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1670 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1671 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1672 "DW_CFA_offset, column 0x%lx",
1673 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1674 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1676 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1677 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1678 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1679 "DW_CFA_restore, column 0x%lx",
1680 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1683 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1684 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1686 switch (cfi->dw_cfi_opc)
1688 case DW_CFA_set_loc:
1690 dw2_asm_output_encoded_addr_rtx (
1691 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1692 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1695 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1696 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1699 case DW_CFA_advance_loc1:
1700 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1701 fde->dw_fde_current_label, NULL);
1702 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1705 case DW_CFA_advance_loc2:
1706 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1707 fde->dw_fde_current_label, NULL);
1708 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1711 case DW_CFA_advance_loc4:
1712 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1713 fde->dw_fde_current_label, NULL);
1714 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1717 case DW_CFA_MIPS_advance_loc8:
1718 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1719 fde->dw_fde_current_label, NULL);
1720 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1723 case DW_CFA_offset_extended:
1724 case DW_CFA_def_cfa:
1725 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1727 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1730 case DW_CFA_offset_extended_sf:
1731 case DW_CFA_def_cfa_sf:
1732 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1734 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1737 case DW_CFA_restore_extended:
1738 case DW_CFA_undefined:
1739 case DW_CFA_same_value:
1740 case DW_CFA_def_cfa_register:
1741 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1745 case DW_CFA_register:
1746 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1748 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1752 case DW_CFA_def_cfa_offset:
1753 case DW_CFA_GNU_args_size:
1754 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1757 case DW_CFA_def_cfa_offset_sf:
1758 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1761 case DW_CFA_GNU_window_save:
1764 case DW_CFA_def_cfa_expression:
1765 case DW_CFA_expression:
1766 output_cfa_loc (cfi);
1769 case DW_CFA_GNU_negative_offset_extended:
1770 /* Obsoleted by DW_CFA_offset_extended_sf. */
1779 /* Output the call frame information used to used to record information
1780 that relates to calculating the frame pointer, and records the
1781 location of saved registers. */
1784 output_call_frame_info (for_eh)
1790 char l1[20], l2[20], section_start_label[20];
1791 int any_lsda_needed = 0;
1792 char augmentation[6];
1793 int augmentation_size;
1794 int fde_encoding = DW_EH_PE_absptr;
1795 int per_encoding = DW_EH_PE_absptr;
1796 int lsda_encoding = DW_EH_PE_absptr;
1798 /* If we don't have any functions we'll want to unwind out of, don't emit any
1799 EH unwind information. */
1802 int any_eh_needed = flag_asynchronous_unwind_tables;
1804 for (i = 0; i < fde_table_in_use; i++)
1805 if (fde_table[i].uses_eh_lsda)
1806 any_eh_needed = any_lsda_needed = 1;
1807 else if (! fde_table[i].nothrow)
1810 if (! any_eh_needed)
1814 /* We're going to be generating comments, so turn on app. */
1819 (*targetm.asm_out.eh_frame_section) ();
1821 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1823 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1824 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1826 /* Output the CIE. */
1827 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1828 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1829 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1830 "Length of Common Information Entry");
1831 ASM_OUTPUT_LABEL (asm_out_file, l1);
1833 /* Now that the CIE pointer is PC-relative for EH,
1834 use 0 to identify the CIE. */
1835 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1836 (for_eh ? 0 : DW_CIE_ID),
1837 "CIE Identifier Tag");
1839 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1841 augmentation[0] = 0;
1842 augmentation_size = 0;
1848 z Indicates that a uleb128 is present to size the
1849 augmentation section.
1850 L Indicates the encoding (and thus presence) of
1851 an LSDA pointer in the FDE augmentation.
1852 R Indicates a non-default pointer encoding for
1854 P Indicates the presence of an encoding + language
1855 personality routine in the CIE augmentation. */
1857 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1858 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1859 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1861 p = augmentation + 1;
1862 if (eh_personality_libfunc)
1865 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1867 if (any_lsda_needed)
1870 augmentation_size += 1;
1872 if (fde_encoding != DW_EH_PE_absptr)
1875 augmentation_size += 1;
1877 if (p > augmentation + 1)
1879 augmentation[0] = 'z';
1883 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1884 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1886 int offset = ( 4 /* Length */
1888 + 1 /* CIE version */
1889 + strlen (augmentation) + 1 /* Augmentation */
1890 + size_of_uleb128 (1) /* Code alignment */
1891 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1893 + 1 /* Augmentation size */
1894 + 1 /* Personality encoding */ );
1895 int pad = -offset & (PTR_SIZE - 1);
1897 augmentation_size += pad;
1899 /* Augmentations should be small, so there's scarce need to
1900 iterate for a solution. Die if we exceed one uleb128 byte. */
1901 if (size_of_uleb128 (augmentation_size) != 1)
1906 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1907 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1908 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1909 "CIE Data Alignment Factor");
1910 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1912 if (augmentation[0])
1914 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1915 if (eh_personality_libfunc)
1917 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1918 eh_data_format_name (per_encoding));
1919 dw2_asm_output_encoded_addr_rtx (per_encoding,
1920 eh_personality_libfunc, NULL);
1923 if (any_lsda_needed)
1924 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1925 eh_data_format_name (lsda_encoding));
1927 if (fde_encoding != DW_EH_PE_absptr)
1928 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1929 eh_data_format_name (fde_encoding));
1932 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1933 output_cfi (cfi, NULL, for_eh);
1935 /* Pad the CIE out to an address sized boundary. */
1936 ASM_OUTPUT_ALIGN (asm_out_file,
1937 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1938 ASM_OUTPUT_LABEL (asm_out_file, l2);
1940 /* Loop through all of the FDE's. */
1941 for (i = 0; i < fde_table_in_use; i++)
1943 fde = &fde_table[i];
1945 /* Don't emit EH unwind info for leaf functions that don't need it. */
1946 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1949 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1950 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1951 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1952 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1954 ASM_OUTPUT_LABEL (asm_out_file, l1);
1957 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
1959 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
1964 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1965 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1966 "FDE initial location");
1967 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1968 fde->dw_fde_end, fde->dw_fde_begin,
1969 "FDE address range");
1973 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1974 "FDE initial location");
1975 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1976 fde->dw_fde_end, fde->dw_fde_begin,
1977 "FDE address range");
1980 if (augmentation[0])
1982 if (any_lsda_needed)
1984 int size = size_of_encoded_value (lsda_encoding);
1986 if (lsda_encoding == DW_EH_PE_aligned)
1988 int offset = ( 4 /* Length */
1989 + 4 /* CIE offset */
1990 + 2 * size_of_encoded_value (fde_encoding)
1991 + 1 /* Augmentation size */ );
1992 int pad = -offset & (PTR_SIZE - 1);
1995 if (size_of_uleb128 (size) != 1)
1999 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2001 if (fde->uses_eh_lsda)
2003 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2004 fde->funcdef_number);
2005 dw2_asm_output_encoded_addr_rtx (
2006 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2007 "Language Specific Data Area");
2011 if (lsda_encoding == DW_EH_PE_aligned)
2012 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2014 (size_of_encoded_value (lsda_encoding), 0,
2015 "Language Specific Data Area (none)");
2019 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2022 /* Loop through the Call Frame Instructions associated with
2024 fde->dw_fde_current_label = fde->dw_fde_begin;
2025 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2026 output_cfi (cfi, fde, for_eh);
2028 /* Pad the FDE out to an address sized boundary. */
2029 ASM_OUTPUT_ALIGN (asm_out_file,
2030 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2031 ASM_OUTPUT_LABEL (asm_out_file, l2);
2034 #ifndef EH_FRAME_SECTION_NAME
2036 dw2_asm_output_data (4, 0, "End of Table");
2038 #ifdef MIPS_DEBUGGING_INFO
2039 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2040 get a value of 0. Putting .align 0 after the label fixes it. */
2041 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2044 /* Turn off app to make assembly quicker. */
2049 /* Output a marker (i.e. a label) for the beginning of a function, before
2053 dwarf2out_begin_prologue (line, file)
2054 unsigned int line ATTRIBUTE_UNUSED;
2055 const char *file ATTRIBUTE_UNUSED;
2057 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2060 current_function_func_begin_label = 0;
2062 #ifdef IA64_UNWIND_INFO
2063 /* ??? current_function_func_begin_label is also used by except.c
2064 for call-site information. We must emit this label if it might
2066 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2067 && ! dwarf2out_do_frame ())
2070 if (! dwarf2out_do_frame ())
2074 current_funcdef_number++;
2075 function_section (current_function_decl);
2076 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2077 current_funcdef_number);
2078 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2079 current_funcdef_number);
2080 current_function_func_begin_label = get_identifier (label);
2082 #ifdef IA64_UNWIND_INFO
2083 /* We can elide the fde allocation if we're not emitting debug info. */
2084 if (! dwarf2out_do_frame ())
2088 /* Expand the fde table if necessary. */
2089 if (fde_table_in_use == fde_table_allocated)
2091 fde_table_allocated += FDE_TABLE_INCREMENT;
2093 = (dw_fde_ref) xrealloc (fde_table,
2094 fde_table_allocated * sizeof (dw_fde_node));
2097 /* Record the FDE associated with this function. */
2098 current_funcdef_fde = fde_table_in_use;
2100 /* Add the new FDE at the end of the fde_table. */
2101 fde = &fde_table[fde_table_in_use++];
2102 fde->dw_fde_begin = xstrdup (label);
2103 fde->dw_fde_current_label = NULL;
2104 fde->dw_fde_end = NULL;
2105 fde->dw_fde_cfi = NULL;
2106 fde->funcdef_number = current_funcdef_number;
2107 fde->nothrow = current_function_nothrow;
2108 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2110 args_size = old_args_size = 0;
2112 /* We only want to output line number information for the genuine dwarf2
2113 prologue case, not the eh frame case. */
2114 #ifdef DWARF2_DEBUGGING_INFO
2116 dwarf2out_source_line (line, file);
2120 /* Output a marker (i.e. a label) for the absolute end of the generated code
2121 for a function definition. This gets called *after* the epilogue code has
2125 dwarf2out_end_epilogue ()
2128 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2130 /* Output a label to mark the endpoint of the code generated for this
2132 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2133 ASM_OUTPUT_LABEL (asm_out_file, label);
2134 fde = &fde_table[fde_table_in_use - 1];
2135 fde->dw_fde_end = xstrdup (label);
2139 dwarf2out_frame_init ()
2141 /* Allocate the initial hunk of the fde_table. */
2142 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2143 fde_table_allocated = FDE_TABLE_INCREMENT;
2144 fde_table_in_use = 0;
2146 /* Generate the CFA instructions common to all FDE's. Do it now for the
2147 sake of lookup_cfa. */
2149 #ifdef DWARF2_UNWIND_INFO
2150 /* On entry, the Canonical Frame Address is at SP. */
2151 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2152 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2157 dwarf2out_frame_finish ()
2159 /* Output call frame information. */
2160 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2161 output_call_frame_info (0);
2163 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2164 output_call_frame_info (1);
2167 /* And now, the subset of the debugging information support code necessary
2168 for emitting location expressions. */
2170 typedef struct dw_val_struct *dw_val_ref;
2171 typedef struct die_struct *dw_die_ref;
2172 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2173 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2175 /* Each DIE may have a series of attribute/value pairs. Values
2176 can take on several forms. The forms that are used in this
2177 implementation are listed below. */
2182 dw_val_class_offset,
2184 dw_val_class_loc_list,
2185 dw_val_class_range_list,
2187 dw_val_class_unsigned_const,
2188 dw_val_class_long_long,
2191 dw_val_class_die_ref,
2192 dw_val_class_fde_ref,
2193 dw_val_class_lbl_id,
2194 dw_val_class_lbl_offset,
2199 /* Describe a double word constant value. */
2200 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2202 typedef struct dw_long_long_struct
2209 /* Describe a floating point constant value. */
2211 typedef struct dw_fp_struct
2218 /* The dw_val_node describes an attribute's value, as it is
2219 represented internally. */
2221 typedef struct dw_val_struct
2223 dw_val_class val_class;
2227 long unsigned val_offset;
2228 dw_loc_list_ref val_loc_list;
2229 dw_loc_descr_ref val_loc;
2231 long unsigned val_unsigned;
2232 dw_long_long_const val_long_long;
2233 dw_float_const val_float;
2239 unsigned val_fde_index;
2240 struct indirect_string_node *val_str;
2242 unsigned char val_flag;
2248 /* Locations in memory are described using a sequence of stack machine
2251 typedef struct dw_loc_descr_struct
2253 dw_loc_descr_ref dw_loc_next;
2254 enum dwarf_location_atom dw_loc_opc;
2255 dw_val_node dw_loc_oprnd1;
2256 dw_val_node dw_loc_oprnd2;
2261 /* Location lists are ranges + location descriptions for that range,
2262 so you can track variables that are in different places over
2263 their entire life. */
2264 typedef struct dw_loc_list_struct
2266 dw_loc_list_ref dw_loc_next;
2267 const char *begin; /* Label for begin address of range */
2268 const char *end; /* Label for end address of range */
2269 char *ll_symbol; /* Label for beginning of location list.
2270 Only on head of list */
2271 const char *section; /* Section this loclist is relative to */
2272 dw_loc_descr_ref expr;
2275 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2276 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2279 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2281 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2282 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2283 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2284 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2286 /* Convert a DWARF stack opcode into its string name. */
2289 dwarf_stack_op_name (op)
2295 return "DW_OP_addr";
2297 return "DW_OP_deref";
2299 return "DW_OP_const1u";
2301 return "DW_OP_const1s";
2303 return "DW_OP_const2u";
2305 return "DW_OP_const2s";
2307 return "DW_OP_const4u";
2309 return "DW_OP_const4s";
2311 return "DW_OP_const8u";
2313 return "DW_OP_const8s";
2315 return "DW_OP_constu";
2317 return "DW_OP_consts";
2321 return "DW_OP_drop";
2323 return "DW_OP_over";
2325 return "DW_OP_pick";
2327 return "DW_OP_swap";
2331 return "DW_OP_xderef";
2339 return "DW_OP_minus";
2351 return "DW_OP_plus";
2352 case DW_OP_plus_uconst:
2353 return "DW_OP_plus_uconst";
2359 return "DW_OP_shra";
2377 return "DW_OP_skip";
2379 return "DW_OP_lit0";
2381 return "DW_OP_lit1";
2383 return "DW_OP_lit2";
2385 return "DW_OP_lit3";
2387 return "DW_OP_lit4";
2389 return "DW_OP_lit5";
2391 return "DW_OP_lit6";
2393 return "DW_OP_lit7";
2395 return "DW_OP_lit8";
2397 return "DW_OP_lit9";
2399 return "DW_OP_lit10";
2401 return "DW_OP_lit11";
2403 return "DW_OP_lit12";
2405 return "DW_OP_lit13";
2407 return "DW_OP_lit14";
2409 return "DW_OP_lit15";
2411 return "DW_OP_lit16";
2413 return "DW_OP_lit17";
2415 return "DW_OP_lit18";
2417 return "DW_OP_lit19";
2419 return "DW_OP_lit20";
2421 return "DW_OP_lit21";
2423 return "DW_OP_lit22";
2425 return "DW_OP_lit23";
2427 return "DW_OP_lit24";
2429 return "DW_OP_lit25";
2431 return "DW_OP_lit26";
2433 return "DW_OP_lit27";
2435 return "DW_OP_lit28";
2437 return "DW_OP_lit29";
2439 return "DW_OP_lit30";
2441 return "DW_OP_lit31";
2443 return "DW_OP_reg0";
2445 return "DW_OP_reg1";
2447 return "DW_OP_reg2";
2449 return "DW_OP_reg3";
2451 return "DW_OP_reg4";
2453 return "DW_OP_reg5";
2455 return "DW_OP_reg6";
2457 return "DW_OP_reg7";
2459 return "DW_OP_reg8";
2461 return "DW_OP_reg9";
2463 return "DW_OP_reg10";
2465 return "DW_OP_reg11";
2467 return "DW_OP_reg12";
2469 return "DW_OP_reg13";
2471 return "DW_OP_reg14";
2473 return "DW_OP_reg15";
2475 return "DW_OP_reg16";
2477 return "DW_OP_reg17";
2479 return "DW_OP_reg18";
2481 return "DW_OP_reg19";
2483 return "DW_OP_reg20";
2485 return "DW_OP_reg21";
2487 return "DW_OP_reg22";
2489 return "DW_OP_reg23";
2491 return "DW_OP_reg24";
2493 return "DW_OP_reg25";
2495 return "DW_OP_reg26";
2497 return "DW_OP_reg27";
2499 return "DW_OP_reg28";
2501 return "DW_OP_reg29";
2503 return "DW_OP_reg30";
2505 return "DW_OP_reg31";
2507 return "DW_OP_breg0";
2509 return "DW_OP_breg1";
2511 return "DW_OP_breg2";
2513 return "DW_OP_breg3";
2515 return "DW_OP_breg4";
2517 return "DW_OP_breg5";
2519 return "DW_OP_breg6";
2521 return "DW_OP_breg7";
2523 return "DW_OP_breg8";
2525 return "DW_OP_breg9";
2527 return "DW_OP_breg10";
2529 return "DW_OP_breg11";
2531 return "DW_OP_breg12";
2533 return "DW_OP_breg13";
2535 return "DW_OP_breg14";
2537 return "DW_OP_breg15";
2539 return "DW_OP_breg16";
2541 return "DW_OP_breg17";
2543 return "DW_OP_breg18";
2545 return "DW_OP_breg19";
2547 return "DW_OP_breg20";
2549 return "DW_OP_breg21";
2551 return "DW_OP_breg22";
2553 return "DW_OP_breg23";
2555 return "DW_OP_breg24";
2557 return "DW_OP_breg25";
2559 return "DW_OP_breg26";
2561 return "DW_OP_breg27";
2563 return "DW_OP_breg28";
2565 return "DW_OP_breg29";
2567 return "DW_OP_breg30";
2569 return "DW_OP_breg31";
2571 return "DW_OP_regx";
2573 return "DW_OP_fbreg";
2575 return "DW_OP_bregx";
2577 return "DW_OP_piece";
2578 case DW_OP_deref_size:
2579 return "DW_OP_deref_size";
2580 case DW_OP_xderef_size:
2581 return "DW_OP_xderef_size";
2585 return "OP_<unknown>";
2589 /* Return a pointer to a newly allocated location description. Location
2590 descriptions are simple expression terms that can be strung
2591 together to form more complicated location (address) descriptions. */
2593 static inline dw_loc_descr_ref
2594 new_loc_descr (op, oprnd1, oprnd2)
2595 enum dwarf_location_atom op;
2596 unsigned long oprnd1;
2597 unsigned long oprnd2;
2599 /* Use xcalloc here so we clear out all of the long_long constant in
2601 dw_loc_descr_ref descr
2602 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2604 descr->dw_loc_opc = op;
2605 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2606 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2607 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2608 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2614 /* Add a location description term to a location description expression. */
2617 add_loc_descr (list_head, descr)
2618 dw_loc_descr_ref *list_head;
2619 dw_loc_descr_ref descr;
2621 dw_loc_descr_ref *d;
2623 /* Find the end of the chain. */
2624 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2630 /* Return the size of a location descriptor. */
2632 static unsigned long
2633 size_of_loc_descr (loc)
2634 dw_loc_descr_ref loc;
2636 unsigned long size = 1;
2638 switch (loc->dw_loc_opc)
2641 size += DWARF2_ADDR_SIZE;
2660 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2663 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2668 case DW_OP_plus_uconst:
2669 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2707 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2710 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2713 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2716 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2717 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2720 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2722 case DW_OP_deref_size:
2723 case DW_OP_xderef_size:
2733 /* Return the size of a series of location descriptors. */
2735 static unsigned long
2737 dw_loc_descr_ref loc;
2741 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2743 loc->dw_loc_addr = size;
2744 size += size_of_loc_descr (loc);
2750 /* Output location description stack opcode's operands (if any). */
2753 output_loc_operands (loc)
2754 dw_loc_descr_ref loc;
2756 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2757 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2759 switch (loc->dw_loc_opc)
2761 #ifdef DWARF2_DEBUGGING_INFO
2763 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2767 dw2_asm_output_data (2, val1->v.val_int, NULL);
2771 dw2_asm_output_data (4, val1->v.val_int, NULL);
2775 if (HOST_BITS_PER_LONG < 64)
2777 dw2_asm_output_data (8, val1->v.val_int, NULL);
2784 if (val1->val_class == dw_val_class_loc)
2785 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2789 dw2_asm_output_data (2, offset, NULL);
2802 /* We currently don't make any attempt to make sure these are
2803 aligned properly like we do for the main unwind info, so
2804 don't support emitting things larger than a byte if we're
2805 only doing unwinding. */
2810 dw2_asm_output_data (1, val1->v.val_int, NULL);
2813 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2816 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2819 dw2_asm_output_data (1, val1->v.val_int, NULL);
2821 case DW_OP_plus_uconst:
2822 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2856 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2859 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2862 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2865 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2866 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2869 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2871 case DW_OP_deref_size:
2872 case DW_OP_xderef_size:
2873 dw2_asm_output_data (1, val1->v.val_int, NULL);
2876 /* Other codes have no operands. */
2881 /* Output a sequence of location operations. */
2884 output_loc_sequence (loc)
2885 dw_loc_descr_ref loc;
2887 for (; loc != NULL; loc = loc->dw_loc_next)
2889 /* Output the opcode. */
2890 dw2_asm_output_data (1, loc->dw_loc_opc,
2891 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2893 /* Output the operand(s) (if any). */
2894 output_loc_operands (loc);
2898 /* This routine will generate the correct assembly data for a location
2899 description based on a cfi entry with a complex address. */
2902 output_cfa_loc (cfi)
2905 dw_loc_descr_ref loc;
2908 /* Output the size of the block. */
2909 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2910 size = size_of_locs (loc);
2911 dw2_asm_output_data_uleb128 (size, NULL);
2913 /* Now output the operations themselves. */
2914 output_loc_sequence (loc);
2917 /* This function builds a dwarf location descriptor sequence from
2918 a dw_cfa_location. */
2920 static struct dw_loc_descr_struct *
2922 dw_cfa_location *cfa;
2924 struct dw_loc_descr_struct *head, *tmp;
2926 if (cfa->indirect == 0)
2929 if (cfa->base_offset)
2932 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2934 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2936 else if (cfa->reg <= 31)
2937 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2939 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2941 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2942 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2943 add_loc_descr (&head, tmp);
2944 if (cfa->offset != 0)
2946 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2947 add_loc_descr (&head, tmp);
2953 /* This function fills in aa dw_cfa_location structure from a dwarf location
2954 descriptor sequence. */
2957 get_cfa_from_loc_descr (cfa, loc)
2958 dw_cfa_location *cfa;
2959 struct dw_loc_descr_struct *loc;
2961 struct dw_loc_descr_struct *ptr;
2963 cfa->base_offset = 0;
2967 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2969 enum dwarf_location_atom op = ptr->dw_loc_opc;
3005 cfa->reg = op - DW_OP_reg0;
3008 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3042 cfa->reg = op - DW_OP_breg0;
3043 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3046 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3047 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3052 case DW_OP_plus_uconst:
3053 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3056 internal_error ("DW_LOC_OP %s not implemented\n",
3057 dwarf_stack_op_name (ptr->dw_loc_opc));
3061 #endif /* .debug_frame support */
3063 /* And now, the support for symbolic debugging information. */
3064 #ifdef DWARF2_DEBUGGING_INFO
3066 /* .debug_str support. */
3067 static hashnode indirect_string_alloc PARAMS ((hash_table *));
3068 static int output_indirect_string PARAMS ((struct cpp_reader *,
3069 hashnode, const PTR));
3072 static void dwarf2out_init PARAMS ((const char *));
3073 static void dwarf2out_finish PARAMS ((const char *));
3074 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3075 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3076 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3077 static void dwarf2out_end_source_file PARAMS ((unsigned));
3078 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3079 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3080 static bool dwarf2out_ignore_block PARAMS ((tree));
3081 static void dwarf2out_global_decl PARAMS ((tree));
3082 static void dwarf2out_abstract_function PARAMS ((tree));
3084 /* The debug hooks structure. */
3086 struct gcc_debug_hooks dwarf2_debug_hooks =
3092 dwarf2out_start_source_file,
3093 dwarf2out_end_source_file,
3094 dwarf2out_begin_block,
3095 dwarf2out_end_block,
3096 dwarf2out_ignore_block,
3097 dwarf2out_source_line,
3098 dwarf2out_begin_prologue,
3099 debug_nothing_int, /* end_prologue */
3100 dwarf2out_end_epilogue,
3101 debug_nothing_tree, /* begin_function */
3102 debug_nothing_int, /* end_function */
3103 dwarf2out_decl, /* function_decl */
3104 dwarf2out_global_decl,
3105 debug_nothing_tree, /* deferred_inline_function */
3106 /* The DWARF 2 backend tries to reduce debugging bloat by not
3107 emitting the abstract description of inline functions until
3108 something tries to reference them. */
3109 dwarf2out_abstract_function, /* outlining_inline_function */
3110 debug_nothing_rtx /* label */
3113 /* NOTE: In the comments in this file, many references are made to
3114 "Debugging Information Entries". This term is abbreviated as `DIE'
3115 throughout the remainder of this file. */
3117 /* An internal representation of the DWARF output is built, and then
3118 walked to generate the DWARF debugging info. The walk of the internal
3119 representation is done after the entire program has been compiled.
3120 The types below are used to describe the internal representation. */
3122 /* Various DIE's use offsets relative to the beginning of the
3123 .debug_info section to refer to each other. */
3125 typedef long int dw_offset;
3127 /* Define typedefs here to avoid circular dependencies. */
3129 typedef struct dw_attr_struct *dw_attr_ref;
3130 typedef struct dw_line_info_struct *dw_line_info_ref;
3131 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3132 typedef struct pubname_struct *pubname_ref;
3133 typedef struct dw_ranges_struct *dw_ranges_ref;
3135 /* Each entry in the line_info_table maintains the file and
3136 line number associated with the label generated for that
3137 entry. The label gives the PC value associated with
3138 the line number entry. */
3140 typedef struct dw_line_info_struct
3142 unsigned long dw_file_num;
3143 unsigned long dw_line_num;
3147 /* Line information for functions in separate sections; each one gets its
3149 typedef struct dw_separate_line_info_struct
3151 unsigned long dw_file_num;
3152 unsigned long dw_line_num;
3153 unsigned long function;
3155 dw_separate_line_info_entry;
3157 /* Each DIE attribute has a field specifying the attribute kind,
3158 a link to the next attribute in the chain, and an attribute value.
3159 Attributes are typically linked below the DIE they modify. */
3161 typedef struct dw_attr_struct
3163 enum dwarf_attribute dw_attr;
3164 dw_attr_ref dw_attr_next;
3165 dw_val_node dw_attr_val;
3169 /* The Debugging Information Entry (DIE) structure */
3171 typedef struct die_struct
3173 enum dwarf_tag die_tag;
3175 dw_attr_ref die_attr;
3176 dw_die_ref die_parent;
3177 dw_die_ref die_child;
3179 dw_offset die_offset;
3180 unsigned long die_abbrev;
3185 /* The pubname structure */
3187 typedef struct pubname_struct
3194 struct dw_ranges_struct
3199 /* The limbo die list structure. */
3200 typedef struct limbo_die_struct
3204 struct limbo_die_struct *next;
3208 /* How to start an assembler comment. */
3209 #ifndef ASM_COMMENT_START
3210 #define ASM_COMMENT_START ";#"
3213 /* Define a macro which returns non-zero for a TYPE_DECL which was
3214 implicitly generated for a tagged type.
3216 Note that unlike the gcc front end (which generates a NULL named
3217 TYPE_DECL node for each complete tagged type, each array type, and
3218 each function type node created) the g++ front end generates a
3219 _named_ TYPE_DECL node for each tagged type node created.
3220 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3221 generate a DW_TAG_typedef DIE for them. */
3223 #define TYPE_DECL_IS_STUB(decl) \
3224 (DECL_NAME (decl) == NULL_TREE \
3225 || (DECL_ARTIFICIAL (decl) \
3226 && is_tagged_type (TREE_TYPE (decl)) \
3227 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3228 /* This is necessary for stub decls that \
3229 appear in nested inline functions. */ \
3230 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3231 && (decl_ultimate_origin (decl) \
3232 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3234 /* Information concerning the compilation unit's programming
3235 language, and compiler version. */
3237 extern int flag_traditional;
3239 /* Fixed size portion of the DWARF compilation unit header. */
3240 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3242 /* Fixed size portion of debugging line information prolog. */
3243 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3245 /* Fixed size portion of public names info. */
3246 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3248 /* Fixed size portion of the address range info. */
3249 #define DWARF_ARANGES_HEADER_SIZE \
3250 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3251 - DWARF_OFFSET_SIZE)
3253 /* Size of padding portion in the address range info. It must be
3254 aligned to twice the pointer size. */
3255 #define DWARF_ARANGES_PAD_SIZE \
3256 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3257 - (2 * DWARF_OFFSET_SIZE + 4))
3259 /* Use assembler line directives if available. */
3260 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3261 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3262 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3264 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3268 /* Minimum line offset in a special line info. opcode.
3269 This value was chosen to give a reasonable range of values. */
3270 #define DWARF_LINE_BASE -10
3272 /* First special line opcode - leave room for the standard opcodes. */
3273 #define DWARF_LINE_OPCODE_BASE 10
3275 /* Range of line offsets in a special line info. opcode. */
3276 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3278 /* Flag that indicates the initial value of the is_stmt_start flag.
3279 In the present implementation, we do not mark any lines as
3280 the beginning of a source statement, because that information
3281 is not made available by the GCC front-end. */
3282 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3284 /* This location is used by calc_die_sizes() to keep track
3285 the offset of each DIE within the .debug_info section. */
3286 static unsigned long next_die_offset;
3288 /* Record the root of the DIE's built for the current compilation unit. */
3289 static dw_die_ref comp_unit_die;
3291 /* A list of DIEs with a NULL parent waiting to be relocated. */
3292 static limbo_die_node *limbo_die_list = 0;
3294 /* Structure used by lookup_filename to manage sets of filenames. */
3300 unsigned last_lookup_index;
3303 /* Size (in elements) of increments by which we may expand the filename
3305 #define FILE_TABLE_INCREMENT 64
3307 /* Filenames referenced by this compilation unit. */
3308 static struct file_table file_table;
3310 /* Local pointer to the name of the main input file. Initialized in
3312 static const char *primary_filename;
3314 /* A pointer to the base of a table of references to DIE's that describe
3315 declarations. The table is indexed by DECL_UID() which is a unique
3316 number identifying each decl. */
3317 static dw_die_ref *decl_die_table;
3319 /* Number of elements currently allocated for the decl_die_table. */
3320 static unsigned decl_die_table_allocated;
3322 /* Number of elements in decl_die_table currently in use. */
3323 static unsigned decl_die_table_in_use;
3325 /* Size (in elements) of increments by which we may expand the
3327 #define DECL_DIE_TABLE_INCREMENT 256
3329 /* A pointer to the base of a table of references to declaration
3330 scopes. This table is a display which tracks the nesting
3331 of declaration scopes at the current scope and containing
3332 scopes. This table is used to find the proper place to
3333 define type declaration DIE's. */
3334 varray_type decl_scope_table;
3336 /* A pointer to the base of a list of references to DIE's that
3337 are uniquely identified by their tag, presence/absence of
3338 children DIE's, and list of attribute/value pairs. */
3339 static dw_die_ref *abbrev_die_table;
3341 /* Number of elements currently allocated for abbrev_die_table. */
3342 static unsigned abbrev_die_table_allocated;
3344 /* Number of elements in type_die_table currently in use. */
3345 static unsigned abbrev_die_table_in_use;
3347 /* Size (in elements) of increments by which we may expand the
3348 abbrev_die_table. */
3349 #define ABBREV_DIE_TABLE_INCREMENT 256
3351 /* A pointer to the base of a table that contains line information
3352 for each source code line in .text in the compilation unit. */
3353 static dw_line_info_ref line_info_table;
3355 /* Number of elements currently allocated for line_info_table. */
3356 static unsigned line_info_table_allocated;
3358 /* Number of elements in separate_line_info_table currently in use. */
3359 static unsigned separate_line_info_table_in_use;
3361 /* A pointer to the base of a table that contains line information
3362 for each source code line outside of .text in the compilation unit. */
3363 static dw_separate_line_info_ref separate_line_info_table;
3365 /* Number of elements currently allocated for separate_line_info_table. */
3366 static unsigned separate_line_info_table_allocated;
3368 /* Number of elements in line_info_table currently in use. */
3369 static unsigned line_info_table_in_use;
3371 /* Size (in elements) of increments by which we may expand the
3373 #define LINE_INFO_TABLE_INCREMENT 1024
3375 /* A pointer to the base of a table that contains a list of publicly
3376 accessible names. */
3377 static pubname_ref pubname_table;
3379 /* Number of elements currently allocated for pubname_table. */
3380 static unsigned pubname_table_allocated;
3382 /* Number of elements in pubname_table currently in use. */
3383 static unsigned pubname_table_in_use;
3385 /* Size (in elements) of increments by which we may expand the
3387 #define PUBNAME_TABLE_INCREMENT 64
3389 /* Array of dies for which we should generate .debug_arange info. */
3390 static dw_die_ref *arange_table;
3392 /* Number of elements currently allocated for arange_table. */
3393 static unsigned arange_table_allocated;
3395 /* Number of elements in arange_table currently in use. */
3396 static unsigned arange_table_in_use;
3398 /* Size (in elements) of increments by which we may expand the
3400 #define ARANGE_TABLE_INCREMENT 64
3402 /* Array of dies for which we should generate .debug_ranges info. */
3403 static dw_ranges_ref ranges_table;
3405 /* Number of elements currently allocated for ranges_table. */
3406 static unsigned ranges_table_allocated;
3408 /* Number of elements in ranges_table currently in use. */
3409 static unsigned ranges_table_in_use;
3411 /* Size (in elements) of increments by which we may expand the
3413 #define RANGES_TABLE_INCREMENT 64
3415 /* Whether we have location lists that need outputting */
3416 static unsigned have_location_lists;
3418 /* A pointer to the base of a list of incomplete types which might be
3419 completed at some later time. incomplete_types_list needs to be a VARRAY
3420 because we want to tell the garbage collector about it. */
3421 varray_type incomplete_types;
3423 /* Record whether the function being analyzed contains inlined functions. */
3424 static int current_function_has_inlines;
3425 #if 0 && defined (MIPS_DEBUGGING_INFO)
3426 static int comp_unit_has_inlines;
3429 /* Array of RTXes referenced by the debugging information, which therefore
3430 must be kept around forever. This is a GC root. */
3431 static varray_type used_rtx_varray;
3433 /* Forward declarations for functions defined in this file. */
3435 static int is_pseudo_reg PARAMS ((rtx));
3436 static tree type_main_variant PARAMS ((tree));
3437 static int is_tagged_type PARAMS ((tree));
3438 static const char *dwarf_tag_name PARAMS ((unsigned));
3439 static const char *dwarf_attr_name PARAMS ((unsigned));
3440 static const char *dwarf_form_name PARAMS ((unsigned));
3442 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3444 static tree decl_ultimate_origin PARAMS ((tree));
3445 static tree block_ultimate_origin PARAMS ((tree));
3446 static tree decl_class_context PARAMS ((tree));
3447 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3448 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
3449 static void add_AT_flag PARAMS ((dw_die_ref,
3450 enum dwarf_attribute,
3452 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3453 static void add_AT_int PARAMS ((dw_die_ref,
3454 enum dwarf_attribute, long));
3455 static inline long int AT_int PARAMS ((dw_attr_ref));
3456 static void add_AT_unsigned PARAMS ((dw_die_ref,
3457 enum dwarf_attribute,
3459 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
3460 static void add_AT_long_long PARAMS ((dw_die_ref,
3461 enum dwarf_attribute,
3464 static void add_AT_float PARAMS ((dw_die_ref,
3465 enum dwarf_attribute,
3467 static void add_AT_string PARAMS ((dw_die_ref,
3468 enum dwarf_attribute,
3470 static inline const char *AT_string PARAMS ((dw_attr_ref));
3471 static int AT_string_form PARAMS ((dw_attr_ref));
3472 static void add_AT_die_ref PARAMS ((dw_die_ref,
3473 enum dwarf_attribute,
3475 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
3476 static inline int AT_ref_external PARAMS ((dw_attr_ref));
3477 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
3478 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3479 enum dwarf_attribute,
3481 static void add_AT_loc PARAMS ((dw_die_ref,
3482 enum dwarf_attribute,
3484 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
3485 static void add_AT_loc_list PARAMS ((dw_die_ref,
3486 enum dwarf_attribute,
3488 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
3489 static void add_AT_addr PARAMS ((dw_die_ref,
3490 enum dwarf_attribute,
3492 static inline rtx AT_addr PARAMS ((dw_attr_ref));
3493 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3494 enum dwarf_attribute,
3496 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3497 enum dwarf_attribute,
3499 static void add_AT_offset PARAMS ((dw_die_ref,
3500 enum dwarf_attribute,
3502 static void add_AT_range_list PARAMS ((dw_die_ref,
3503 enum dwarf_attribute,
3505 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
3506 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3507 enum dwarf_attribute));
3508 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3509 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3510 static const char *get_AT_string PARAMS ((dw_die_ref,
3511 enum dwarf_attribute));
3512 static int get_AT_flag PARAMS ((dw_die_ref,
3513 enum dwarf_attribute));
3514 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3515 enum dwarf_attribute));
3516 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3517 enum dwarf_attribute));
3518 static int is_c_family PARAMS ((void));
3519 static int is_cxx PARAMS ((void));
3520 static int is_java PARAMS ((void));
3521 static int is_fortran PARAMS ((void));
3522 static void remove_AT PARAMS ((dw_die_ref,
3523 enum dwarf_attribute));
3524 static inline void free_die PARAMS ((dw_die_ref));
3525 static void remove_children PARAMS ((dw_die_ref));
3526 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3527 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref,
3529 static dw_die_ref lookup_type_die PARAMS ((tree));
3530 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3531 static dw_die_ref lookup_decl_die PARAMS ((tree));
3532 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3533 static void print_spaces PARAMS ((FILE *));
3534 static void print_die PARAMS ((dw_die_ref, FILE *));
3535 static void print_dwarf_line_table PARAMS ((FILE *));
3536 static void reverse_die_lists PARAMS ((dw_die_ref));
3537 static void reverse_all_dies PARAMS ((dw_die_ref));
3538 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3539 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3540 static void loc_checksum PARAMS ((dw_loc_descr_ref,
3542 static void attr_checksum PARAMS ((dw_attr_ref,
3544 static void die_checksum PARAMS ((dw_die_ref,
3546 static void compute_section_prefix PARAMS ((dw_die_ref));
3547 static int is_type_die PARAMS ((dw_die_ref));
3548 static int is_comdat_die PARAMS ((dw_die_ref));
3549 static int is_symbol_die PARAMS ((dw_die_ref));
3550 static void assign_symbol_names PARAMS ((dw_die_ref));
3551 static void break_out_includes PARAMS ((dw_die_ref));
3552 static void add_sibling_attributes PARAMS ((dw_die_ref));
3553 static void build_abbrev_table PARAMS ((dw_die_ref));
3554 static void output_location_lists PARAMS ((dw_die_ref));
3555 static int constant_size PARAMS ((long unsigned));
3556 static unsigned long size_of_die PARAMS ((dw_die_ref));
3557 static void calc_die_sizes PARAMS ((dw_die_ref));
3558 static void mark_dies PARAMS ((dw_die_ref));
3559 static void unmark_dies PARAMS ((dw_die_ref));
3560 static unsigned long size_of_pubnames PARAMS ((void));
3561 static unsigned long size_of_aranges PARAMS ((void));
3562 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3563 static void output_value_format PARAMS ((dw_attr_ref));
3564 static void output_abbrev_section PARAMS ((void));
3565 static void output_die_symbol PARAMS ((dw_die_ref));
3566 static void output_die PARAMS ((dw_die_ref));
3567 static void output_compilation_unit_header PARAMS ((void));
3568 static void output_comp_unit PARAMS ((dw_die_ref));
3569 static const char *dwarf2_name PARAMS ((tree, int));
3570 static void add_pubname PARAMS ((tree, dw_die_ref));
3571 static void output_pubnames PARAMS ((void));
3572 static void add_arange PARAMS ((tree, dw_die_ref));
3573 static void output_aranges PARAMS ((void));
3574 static unsigned int add_ranges PARAMS ((tree));
3575 static void output_ranges PARAMS ((void));
3576 static void output_line_info PARAMS ((void));
3577 static void output_file_names PARAMS ((void));
3578 static dw_die_ref base_type_die PARAMS ((tree));
3579 static tree root_type PARAMS ((tree));
3580 static int is_base_type PARAMS ((tree));
3581 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3582 static int type_is_enum PARAMS ((tree));
3583 static unsigned int reg_number PARAMS ((rtx));
3584 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3585 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3586 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3587 static int is_based_loc PARAMS ((rtx));
3588 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3589 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3590 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3591 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3592 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3593 static tree field_type PARAMS ((tree));
3594 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3595 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3596 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3597 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3598 static void add_AT_location_description PARAMS ((dw_die_ref,
3599 enum dwarf_attribute, rtx));
3600 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3601 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3602 static rtx rtl_for_decl_location PARAMS ((tree));
3603 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3604 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3605 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3606 static void add_bound_info PARAMS ((dw_die_ref,
3607 enum dwarf_attribute, tree));
3608 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3609 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3610 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3611 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3612 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3613 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3614 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3615 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3616 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3617 static void push_decl_scope PARAMS ((tree));
3618 static void pop_decl_scope PARAMS ((void));
3619 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3620 static inline int local_scope_p PARAMS ((dw_die_ref));
3621 static inline int class_scope_p PARAMS ((dw_die_ref));
3622 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3624 static const char *type_tag PARAMS ((tree));
3625 static tree member_declared_type PARAMS ((tree));
3627 static const char *decl_start_label PARAMS ((tree));
3629 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3630 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3632 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3634 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3635 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3636 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3637 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3638 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3639 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3640 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3641 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3642 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3643 static void gen_label_die PARAMS ((tree, dw_die_ref));
3644 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3645 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3646 static void gen_field_die PARAMS ((tree, dw_die_ref));
3647 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3648 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3649 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3650 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3651 static void gen_member_die PARAMS ((tree, dw_die_ref));
3652 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3653 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3654 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3655 static void gen_type_die PARAMS ((tree, dw_die_ref));
3656 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3657 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3658 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3659 static int is_redundant_typedef PARAMS ((tree));
3660 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3661 static unsigned lookup_filename PARAMS ((const char *));
3662 static void init_file_table PARAMS ((void));
3663 static void retry_incomplete_types PARAMS ((void));
3664 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3665 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3666 static int file_info_cmp PARAMS ((const void *, const void *));
3667 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3668 const char *, const char *,
3669 const char *, unsigned));
3670 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3672 const char *, const char *, const char *));
3673 static void output_loc_list PARAMS ((dw_loc_list_ref));
3674 static char *gen_internal_sym PARAMS ((const char *));
3675 static void mark_limbo_die_list PARAMS ((void *));
3677 /* Section names used to hold DWARF debugging information. */
3678 #ifndef DEBUG_INFO_SECTION
3679 #define DEBUG_INFO_SECTION ".debug_info"
3681 #ifndef DEBUG_ABBREV_SECTION
3682 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3684 #ifndef DEBUG_ARANGES_SECTION
3685 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3687 #ifndef DEBUG_MACINFO_SECTION
3688 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3690 #ifndef DEBUG_LINE_SECTION
3691 #define DEBUG_LINE_SECTION ".debug_line"
3693 #ifndef DEBUG_LOC_SECTION
3694 #define DEBUG_LOC_SECTION ".debug_loc"
3696 #ifndef DEBUG_PUBNAMES_SECTION
3697 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3699 #ifndef DEBUG_STR_SECTION
3700 #define DEBUG_STR_SECTION ".debug_str"
3702 #ifndef DEBUG_RANGES_SECTION
3703 #define DEBUG_RANGES_SECTION ".debug_ranges"
3706 /* Standard ELF section names for compiled code and data. */
3707 #ifndef TEXT_SECTION_NAME
3708 #define TEXT_SECTION_NAME ".text"
3711 /* Section flags for .debug_str section. */
3712 #ifdef HAVE_GAS_SHF_MERGE
3713 #define DEBUG_STR_SECTION_FLAGS \
3714 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3716 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3719 /* Labels we insert at beginning sections we can reference instead of
3720 the section names themselves. */
3722 #ifndef TEXT_SECTION_LABEL
3723 #define TEXT_SECTION_LABEL "Ltext"
3725 #ifndef DEBUG_LINE_SECTION_LABEL
3726 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3728 #ifndef DEBUG_INFO_SECTION_LABEL
3729 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3731 #ifndef DEBUG_ABBREV_SECTION_LABEL
3732 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3734 #ifndef DEBUG_LOC_SECTION_LABEL
3735 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3737 #ifndef DEBUG_RANGES_SECTION_LABEL
3738 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3740 #ifndef DEBUG_MACINFO_SECTION_LABEL
3741 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3744 /* Definitions of defaults for formats and names of various special
3745 (artificial) labels which may be generated within this file (when the -g
3746 options is used and DWARF_DEBUGGING_INFO is in effect.
3747 If necessary, these may be overridden from within the tm.h file, but
3748 typically, overriding these defaults is unnecessary. */
3750 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3751 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3752 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3753 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3754 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3755 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3756 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3757 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3759 #ifndef TEXT_END_LABEL
3760 #define TEXT_END_LABEL "Letext"
3762 #ifndef DATA_END_LABEL
3763 #define DATA_END_LABEL "Ledata"
3765 #ifndef BSS_END_LABEL
3766 #define BSS_END_LABEL "Lebss"
3768 #ifndef BLOCK_BEGIN_LABEL
3769 #define BLOCK_BEGIN_LABEL "LBB"
3771 #ifndef BLOCK_END_LABEL
3772 #define BLOCK_END_LABEL "LBE"
3774 #ifndef BODY_BEGIN_LABEL
3775 #define BODY_BEGIN_LABEL "Lbb"
3777 #ifndef BODY_END_LABEL
3778 #define BODY_END_LABEL "Lbe"
3780 #ifndef LINE_CODE_LABEL
3781 #define LINE_CODE_LABEL "LM"
3783 #ifndef SEPARATE_LINE_CODE_LABEL
3784 #define SEPARATE_LINE_CODE_LABEL "LSM"
3787 /* We allow a language front-end to designate a function that is to be
3788 called to "demangle" any name before it it put into a DIE. */
3790 static const char *(*demangle_name_func) PARAMS ((const char *));
3793 dwarf2out_set_demangle_name_func (func)
3794 const char *(*func) PARAMS ((const char *));
3796 demangle_name_func = func;
3799 /* Test if rtl node points to a pseudo register. */
3805 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3806 || (GET_CODE (rtl) == SUBREG
3807 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3810 /* Return a reference to a type, with its const and volatile qualifiers
3814 type_main_variant (type)
3817 type = TYPE_MAIN_VARIANT (type);
3819 /* ??? There really should be only one main variant among any group of
3820 variants of a given type (and all of the MAIN_VARIANT values for all
3821 members of the group should point to that one type) but sometimes the C
3822 front-end messes this up for array types, so we work around that bug
3824 if (TREE_CODE (type) == ARRAY_TYPE)
3825 while (type != TYPE_MAIN_VARIANT (type))
3826 type = TYPE_MAIN_VARIANT (type);
3831 /* Return non-zero if the given type node represents a tagged type. */
3834 is_tagged_type (type)
3837 enum tree_code code = TREE_CODE (type);
3839 return (code == RECORD_TYPE || code == UNION_TYPE
3840 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3843 /* Convert a DIE tag into its string name. */
3846 dwarf_tag_name (tag)
3851 case DW_TAG_padding:
3852 return "DW_TAG_padding";
3853 case DW_TAG_array_type:
3854 return "DW_TAG_array_type";
3855 case DW_TAG_class_type:
3856 return "DW_TAG_class_type";
3857 case DW_TAG_entry_point:
3858 return "DW_TAG_entry_point";
3859 case DW_TAG_enumeration_type:
3860 return "DW_TAG_enumeration_type";
3861 case DW_TAG_formal_parameter:
3862 return "DW_TAG_formal_parameter";
3863 case DW_TAG_imported_declaration:
3864 return "DW_TAG_imported_declaration";
3866 return "DW_TAG_label";
3867 case DW_TAG_lexical_block:
3868 return "DW_TAG_lexical_block";
3870 return "DW_TAG_member";
3871 case DW_TAG_pointer_type:
3872 return "DW_TAG_pointer_type";
3873 case DW_TAG_reference_type:
3874 return "DW_TAG_reference_type";
3875 case DW_TAG_compile_unit:
3876 return "DW_TAG_compile_unit";
3877 case DW_TAG_string_type:
3878 return "DW_TAG_string_type";
3879 case DW_TAG_structure_type:
3880 return "DW_TAG_structure_type";
3881 case DW_TAG_subroutine_type:
3882 return "DW_TAG_subroutine_type";
3883 case DW_TAG_typedef:
3884 return "DW_TAG_typedef";
3885 case DW_TAG_union_type:
3886 return "DW_TAG_union_type";
3887 case DW_TAG_unspecified_parameters:
3888 return "DW_TAG_unspecified_parameters";
3889 case DW_TAG_variant:
3890 return "DW_TAG_variant";
3891 case DW_TAG_common_block:
3892 return "DW_TAG_common_block";
3893 case DW_TAG_common_inclusion:
3894 return "DW_TAG_common_inclusion";
3895 case DW_TAG_inheritance:
3896 return "DW_TAG_inheritance";
3897 case DW_TAG_inlined_subroutine:
3898 return "DW_TAG_inlined_subroutine";
3900 return "DW_TAG_module";
3901 case DW_TAG_ptr_to_member_type:
3902 return "DW_TAG_ptr_to_member_type";
3903 case DW_TAG_set_type:
3904 return "DW_TAG_set_type";
3905 case DW_TAG_subrange_type:
3906 return "DW_TAG_subrange_type";
3907 case DW_TAG_with_stmt:
3908 return "DW_TAG_with_stmt";
3909 case DW_TAG_access_declaration:
3910 return "DW_TAG_access_declaration";
3911 case DW_TAG_base_type:
3912 return "DW_TAG_base_type";
3913 case DW_TAG_catch_block:
3914 return "DW_TAG_catch_block";
3915 case DW_TAG_const_type:
3916 return "DW_TAG_const_type";
3917 case DW_TAG_constant:
3918 return "DW_TAG_constant";
3919 case DW_TAG_enumerator:
3920 return "DW_TAG_enumerator";
3921 case DW_TAG_file_type:
3922 return "DW_TAG_file_type";
3924 return "DW_TAG_friend";
3925 case DW_TAG_namelist:
3926 return "DW_TAG_namelist";
3927 case DW_TAG_namelist_item:
3928 return "DW_TAG_namelist_item";
3929 case DW_TAG_packed_type:
3930 return "DW_TAG_packed_type";
3931 case DW_TAG_subprogram:
3932 return "DW_TAG_subprogram";
3933 case DW_TAG_template_type_param:
3934 return "DW_TAG_template_type_param";
3935 case DW_TAG_template_value_param:
3936 return "DW_TAG_template_value_param";
3937 case DW_TAG_thrown_type:
3938 return "DW_TAG_thrown_type";
3939 case DW_TAG_try_block:
3940 return "DW_TAG_try_block";
3941 case DW_TAG_variant_part:
3942 return "DW_TAG_variant_part";
3943 case DW_TAG_variable:
3944 return "DW_TAG_variable";
3945 case DW_TAG_volatile_type:
3946 return "DW_TAG_volatile_type";
3947 case DW_TAG_MIPS_loop:
3948 return "DW_TAG_MIPS_loop";
3949 case DW_TAG_format_label:
3950 return "DW_TAG_format_label";
3951 case DW_TAG_function_template:
3952 return "DW_TAG_function_template";
3953 case DW_TAG_class_template:
3954 return "DW_TAG_class_template";
3955 case DW_TAG_GNU_BINCL:
3956 return "DW_TAG_GNU_BINCL";
3957 case DW_TAG_GNU_EINCL:
3958 return "DW_TAG_GNU_EINCL";
3960 return "DW_TAG_<unknown>";
3964 /* Convert a DWARF attribute code into its string name. */
3967 dwarf_attr_name (attr)
3973 return "DW_AT_sibling";
3974 case DW_AT_location:
3975 return "DW_AT_location";
3977 return "DW_AT_name";
3978 case DW_AT_ordering:
3979 return "DW_AT_ordering";
3980 case DW_AT_subscr_data:
3981 return "DW_AT_subscr_data";
3982 case DW_AT_byte_size:
3983 return "DW_AT_byte_size";
3984 case DW_AT_bit_offset:
3985 return "DW_AT_bit_offset";
3986 case DW_AT_bit_size:
3987 return "DW_AT_bit_size";
3988 case DW_AT_element_list:
3989 return "DW_AT_element_list";
3990 case DW_AT_stmt_list:
3991 return "DW_AT_stmt_list";
3993 return "DW_AT_low_pc";
3995 return "DW_AT_high_pc";
3996 case DW_AT_language:
3997 return "DW_AT_language";
3999 return "DW_AT_member";
4001 return "DW_AT_discr";
4002 case DW_AT_discr_value:
4003 return "DW_AT_discr_value";
4004 case DW_AT_visibility:
4005 return "DW_AT_visibility";
4007 return "DW_AT_import";
4008 case DW_AT_string_length:
4009 return "DW_AT_string_length";
4010 case DW_AT_common_reference:
4011 return "DW_AT_common_reference";
4012 case DW_AT_comp_dir:
4013 return "DW_AT_comp_dir";
4014 case DW_AT_const_value:
4015 return "DW_AT_const_value";
4016 case DW_AT_containing_type:
4017 return "DW_AT_containing_type";
4018 case DW_AT_default_value:
4019 return "DW_AT_default_value";
4021 return "DW_AT_inline";
4022 case DW_AT_is_optional:
4023 return "DW_AT_is_optional";
4024 case DW_AT_lower_bound:
4025 return "DW_AT_lower_bound";
4026 case DW_AT_producer:
4027 return "DW_AT_producer";
4028 case DW_AT_prototyped:
4029 return "DW_AT_prototyped";
4030 case DW_AT_return_addr:
4031 return "DW_AT_return_addr";
4032 case DW_AT_start_scope:
4033 return "DW_AT_start_scope";
4034 case DW_AT_stride_size:
4035 return "DW_AT_stride_size";
4036 case DW_AT_upper_bound:
4037 return "DW_AT_upper_bound";
4038 case DW_AT_abstract_origin:
4039 return "DW_AT_abstract_origin";
4040 case DW_AT_accessibility:
4041 return "DW_AT_accessibility";
4042 case DW_AT_address_class:
4043 return "DW_AT_address_class";
4044 case DW_AT_artificial:
4045 return "DW_AT_artificial";
4046 case DW_AT_base_types:
4047 return "DW_AT_base_types";
4048 case DW_AT_calling_convention:
4049 return "DW_AT_calling_convention";
4051 return "DW_AT_count";
4052 case DW_AT_data_member_location:
4053 return "DW_AT_data_member_location";
4054 case DW_AT_decl_column:
4055 return "DW_AT_decl_column";
4056 case DW_AT_decl_file:
4057 return "DW_AT_decl_file";
4058 case DW_AT_decl_line:
4059 return "DW_AT_decl_line";
4060 case DW_AT_declaration:
4061 return "DW_AT_declaration";
4062 case DW_AT_discr_list:
4063 return "DW_AT_discr_list";
4064 case DW_AT_encoding:
4065 return "DW_AT_encoding";
4066 case DW_AT_external:
4067 return "DW_AT_external";
4068 case DW_AT_frame_base:
4069 return "DW_AT_frame_base";
4071 return "DW_AT_friend";
4072 case DW_AT_identifier_case:
4073 return "DW_AT_identifier_case";
4074 case DW_AT_macro_info:
4075 return "DW_AT_macro_info";
4076 case DW_AT_namelist_items:
4077 return "DW_AT_namelist_items";
4078 case DW_AT_priority:
4079 return "DW_AT_priority";
4081 return "DW_AT_segment";
4082 case DW_AT_specification:
4083 return "DW_AT_specification";
4084 case DW_AT_static_link:
4085 return "DW_AT_static_link";
4087 return "DW_AT_type";
4088 case DW_AT_use_location:
4089 return "DW_AT_use_location";
4090 case DW_AT_variable_parameter:
4091 return "DW_AT_variable_parameter";
4092 case DW_AT_virtuality:
4093 return "DW_AT_virtuality";
4094 case DW_AT_vtable_elem_location:
4095 return "DW_AT_vtable_elem_location";
4097 case DW_AT_allocated:
4098 return "DW_AT_allocated";
4099 case DW_AT_associated:
4100 return "DW_AT_associated";
4101 case DW_AT_data_location:
4102 return "DW_AT_data_location";
4104 return "DW_AT_stride";
4105 case DW_AT_entry_pc:
4106 return "DW_AT_entry_pc";
4107 case DW_AT_use_UTF8:
4108 return "DW_AT_use_UTF8";
4109 case DW_AT_extension:
4110 return "DW_AT_extension";
4112 return "DW_AT_ranges";
4113 case DW_AT_trampoline:
4114 return "DW_AT_trampoline";
4115 case DW_AT_call_column:
4116 return "DW_AT_call_column";
4117 case DW_AT_call_file:
4118 return "DW_AT_call_file";
4119 case DW_AT_call_line:
4120 return "DW_AT_call_line";
4122 case DW_AT_MIPS_fde:
4123 return "DW_AT_MIPS_fde";
4124 case DW_AT_MIPS_loop_begin:
4125 return "DW_AT_MIPS_loop_begin";
4126 case DW_AT_MIPS_tail_loop_begin:
4127 return "DW_AT_MIPS_tail_loop_begin";
4128 case DW_AT_MIPS_epilog_begin:
4129 return "DW_AT_MIPS_epilog_begin";
4130 case DW_AT_MIPS_loop_unroll_factor:
4131 return "DW_AT_MIPS_loop_unroll_factor";
4132 case DW_AT_MIPS_software_pipeline_depth:
4133 return "DW_AT_MIPS_software_pipeline_depth";
4134 case DW_AT_MIPS_linkage_name:
4135 return "DW_AT_MIPS_linkage_name";
4136 case DW_AT_MIPS_stride:
4137 return "DW_AT_MIPS_stride";
4138 case DW_AT_MIPS_abstract_name:
4139 return "DW_AT_MIPS_abstract_name";
4140 case DW_AT_MIPS_clone_origin:
4141 return "DW_AT_MIPS_clone_origin";
4142 case DW_AT_MIPS_has_inlines:
4143 return "DW_AT_MIPS_has_inlines";
4145 case DW_AT_sf_names:
4146 return "DW_AT_sf_names";
4147 case DW_AT_src_info:
4148 return "DW_AT_src_info";
4149 case DW_AT_mac_info:
4150 return "DW_AT_mac_info";
4151 case DW_AT_src_coords:
4152 return "DW_AT_src_coords";
4153 case DW_AT_body_begin:
4154 return "DW_AT_body_begin";
4155 case DW_AT_body_end:
4156 return "DW_AT_body_end";
4157 case DW_AT_VMS_rtnbeg_pd_address:
4158 return "DW_AT_VMS_rtnbeg_pd_address";
4161 return "DW_AT_<unknown>";
4165 /* Convert a DWARF value form code into its string name. */
4168 dwarf_form_name (form)
4174 return "DW_FORM_addr";
4175 case DW_FORM_block2:
4176 return "DW_FORM_block2";
4177 case DW_FORM_block4:
4178 return "DW_FORM_block4";
4180 return "DW_FORM_data2";
4182 return "DW_FORM_data4";
4184 return "DW_FORM_data8";
4185 case DW_FORM_string:
4186 return "DW_FORM_string";
4188 return "DW_FORM_block";
4189 case DW_FORM_block1:
4190 return "DW_FORM_block1";
4192 return "DW_FORM_data1";
4194 return "DW_FORM_flag";
4196 return "DW_FORM_sdata";
4198 return "DW_FORM_strp";
4200 return "DW_FORM_udata";
4201 case DW_FORM_ref_addr:
4202 return "DW_FORM_ref_addr";
4204 return "DW_FORM_ref1";
4206 return "DW_FORM_ref2";
4208 return "DW_FORM_ref4";
4210 return "DW_FORM_ref8";
4211 case DW_FORM_ref_udata:
4212 return "DW_FORM_ref_udata";
4213 case DW_FORM_indirect:
4214 return "DW_FORM_indirect";
4216 return "DW_FORM_<unknown>";
4220 /* Convert a DWARF type code into its string name. */
4224 dwarf_type_encoding_name (enc)
4229 case DW_ATE_address:
4230 return "DW_ATE_address";
4231 case DW_ATE_boolean:
4232 return "DW_ATE_boolean";
4233 case DW_ATE_complex_float:
4234 return "DW_ATE_complex_float";
4236 return "DW_ATE_float";
4238 return "DW_ATE_signed";
4239 case DW_ATE_signed_char:
4240 return "DW_ATE_signed_char";
4241 case DW_ATE_unsigned:
4242 return "DW_ATE_unsigned";
4243 case DW_ATE_unsigned_char:
4244 return "DW_ATE_unsigned_char";
4246 return "DW_ATE_<unknown>";
4251 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4252 instance of an inlined instance of a decl which is local to an inline
4253 function, so we have to trace all of the way back through the origin chain
4254 to find out what sort of node actually served as the original seed for the
4258 decl_ultimate_origin (decl)
4261 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4262 nodes in the function to point to themselves; ignore that if
4263 we're trying to output the abstract instance of this function. */
4264 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4267 #ifdef ENABLE_CHECKING
4268 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4269 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4270 most distant ancestor, this should never happen. */
4274 return DECL_ABSTRACT_ORIGIN (decl);
4277 /* Determine the "ultimate origin" of a block. The block may be an inlined
4278 instance of an inlined instance of a block which is local to an inline
4279 function, so we have to trace all of the way back through the origin chain
4280 to find out what sort of node actually served as the original seed for the
4284 block_ultimate_origin (block)
4287 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4289 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4290 nodes in the function to point to themselves; ignore that if
4291 we're trying to output the abstract instance of this function. */
4292 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4295 if (immediate_origin == NULL_TREE)
4300 tree lookahead = immediate_origin;
4304 ret_val = lookahead;
4305 lookahead = (TREE_CODE (ret_val) == BLOCK
4306 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4308 while (lookahead != NULL && lookahead != ret_val);
4314 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4315 of a virtual function may refer to a base class, so we check the 'this'
4319 decl_class_context (decl)
4322 tree context = NULL_TREE;
4324 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4325 context = DECL_CONTEXT (decl);
4327 context = TYPE_MAIN_VARIANT
4328 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4330 if (context && !TYPE_P (context))
4331 context = NULL_TREE;
4336 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4337 addition order, and correct that in reverse_all_dies. */
4340 add_dwarf_attr (die, attr)
4344 if (die != NULL && attr != NULL)
4346 attr->dw_attr_next = die->die_attr;
4347 die->die_attr = attr;
4351 static inline dw_val_class
4355 return a->dw_attr_val.val_class;
4358 /* Add a flag value attribute to a DIE. */
4361 add_AT_flag (die, attr_kind, flag)
4363 enum dwarf_attribute attr_kind;
4366 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4368 attr->dw_attr_next = NULL;
4369 attr->dw_attr = attr_kind;
4370 attr->dw_attr_val.val_class = dw_val_class_flag;
4371 attr->dw_attr_val.v.val_flag = flag;
4372 add_dwarf_attr (die, attr);
4375 static inline unsigned
4379 if (a && AT_class (a) == dw_val_class_flag)
4380 return a->dw_attr_val.v.val_flag;
4385 /* Add a signed integer attribute value to a DIE. */
4388 add_AT_int (die, attr_kind, int_val)
4390 enum dwarf_attribute attr_kind;
4393 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4395 attr->dw_attr_next = NULL;
4396 attr->dw_attr = attr_kind;
4397 attr->dw_attr_val.val_class = dw_val_class_const;
4398 attr->dw_attr_val.v.val_int = int_val;
4399 add_dwarf_attr (die, attr);
4402 static inline long int
4406 if (a && AT_class (a) == dw_val_class_const)
4407 return a->dw_attr_val.v.val_int;
4412 /* Add an unsigned integer attribute value to a DIE. */
4415 add_AT_unsigned (die, attr_kind, unsigned_val)
4417 enum dwarf_attribute attr_kind;
4418 unsigned long unsigned_val;
4420 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4422 attr->dw_attr_next = NULL;
4423 attr->dw_attr = attr_kind;
4424 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4425 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4426 add_dwarf_attr (die, attr);
4429 static inline unsigned long
4433 if (a && AT_class (a) == dw_val_class_unsigned_const)
4434 return a->dw_attr_val.v.val_unsigned;
4439 /* Add an unsigned double integer attribute value to a DIE. */
4442 add_AT_long_long (die, attr_kind, val_hi, val_low)
4444 enum dwarf_attribute attr_kind;
4445 unsigned long val_hi;
4446 unsigned long val_low;
4448 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4450 attr->dw_attr_next = NULL;
4451 attr->dw_attr = attr_kind;
4452 attr->dw_attr_val.val_class = dw_val_class_long_long;
4453 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4454 attr->dw_attr_val.v.val_long_long.low = val_low;
4455 add_dwarf_attr (die, attr);
4458 /* Add a floating point attribute value to a DIE and return it. */
4461 add_AT_float (die, attr_kind, length, array)
4463 enum dwarf_attribute attr_kind;
4467 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4469 attr->dw_attr_next = NULL;
4470 attr->dw_attr = attr_kind;
4471 attr->dw_attr_val.val_class = dw_val_class_float;
4472 attr->dw_attr_val.v.val_float.length = length;
4473 attr->dw_attr_val.v.val_float.array = array;
4474 add_dwarf_attr (die, attr);
4477 /* Add a string attribute value to a DIE. */
4480 add_AT_string (die, attr_kind, str)
4482 enum dwarf_attribute attr_kind;
4485 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4486 struct indirect_string_node *node;
4488 if (! debug_str_hash)
4490 debug_str_hash = ht_create (10);
4491 debug_str_hash->alloc_node = indirect_string_alloc;
4494 node = (struct indirect_string_node *)
4495 ht_lookup (debug_str_hash, (const unsigned char *) str,
4496 strlen (str), HT_ALLOC);
4499 attr->dw_attr_next = NULL;
4500 attr->dw_attr = attr_kind;
4501 attr->dw_attr_val.val_class = dw_val_class_str;
4502 attr->dw_attr_val.v.val_str = node;
4503 add_dwarf_attr (die, attr);
4506 static inline const char *
4510 if (a && AT_class (a) == dw_val_class_str)
4511 return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id);
4516 /* Find out whether a string should be output inline in DIE
4517 or out-of-line in .debug_str section. */
4523 if (a && AT_class (a) == dw_val_class_str)
4525 struct indirect_string_node *node;
4527 extern int const_labelno;
4530 node = a->dw_attr_val.v.val_str;
4534 len = HT_LEN (&node->id) + 1;
4536 /* If the string is shorter or equal to the size of the reference, it is
4537 always better to put it inline. */
4538 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4539 return node->form = DW_FORM_string;
4541 /* If we cannot expect the linker to merge strings in .debug_str
4542 section, only put it into .debug_str if it is worth even in this
4544 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4545 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4546 return node->form = DW_FORM_string;
4548 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4550 node->label = xstrdup (label);
4552 return node->form = DW_FORM_strp;
4558 /* Add a DIE reference attribute value to a DIE. */
4561 add_AT_die_ref (die, attr_kind, targ_die)
4563 enum dwarf_attribute attr_kind;
4564 dw_die_ref targ_die;
4566 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4568 attr->dw_attr_next = NULL;
4569 attr->dw_attr = attr_kind;
4570 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4571 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4572 attr->dw_attr_val.v.val_die_ref.external = 0;
4573 add_dwarf_attr (die, attr);
4576 static inline dw_die_ref
4580 if (a && AT_class (a) == dw_val_class_die_ref)
4581 return a->dw_attr_val.v.val_die_ref.die;
4590 if (a && AT_class (a) == dw_val_class_die_ref)
4591 return a->dw_attr_val.v.val_die_ref.external;
4597 set_AT_ref_external (a, i)
4601 if (a && AT_class (a) == dw_val_class_die_ref)
4602 a->dw_attr_val.v.val_die_ref.external = i;
4607 /* Add an FDE reference attribute value to a DIE. */
4610 add_AT_fde_ref (die, attr_kind, targ_fde)
4612 enum dwarf_attribute attr_kind;
4615 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4617 attr->dw_attr_next = NULL;
4618 attr->dw_attr = attr_kind;
4619 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4620 attr->dw_attr_val.v.val_fde_index = targ_fde;
4621 add_dwarf_attr (die, attr);
4624 /* Add a location description attribute value to a DIE. */
4627 add_AT_loc (die, attr_kind, loc)
4629 enum dwarf_attribute attr_kind;
4630 dw_loc_descr_ref loc;
4632 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4634 attr->dw_attr_next = NULL;
4635 attr->dw_attr = attr_kind;
4636 attr->dw_attr_val.val_class = dw_val_class_loc;
4637 attr->dw_attr_val.v.val_loc = loc;
4638 add_dwarf_attr (die, attr);
4641 static inline dw_loc_descr_ref
4645 if (a && AT_class (a) == dw_val_class_loc)
4646 return a->dw_attr_val.v.val_loc;
4652 add_AT_loc_list (die, attr_kind, loc_list)
4654 enum dwarf_attribute attr_kind;
4655 dw_loc_list_ref loc_list;
4657 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4659 attr->dw_attr_next = NULL;
4660 attr->dw_attr = attr_kind;
4661 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4662 attr->dw_attr_val.v.val_loc_list = loc_list;
4663 add_dwarf_attr (die, attr);
4664 have_location_lists = 1;
4667 static inline dw_loc_list_ref
4671 if (a && AT_class (a) == dw_val_class_loc_list)
4672 return a->dw_attr_val.v.val_loc_list;
4677 /* Add an address constant attribute value to a DIE. */
4680 add_AT_addr (die, attr_kind, addr)
4682 enum dwarf_attribute attr_kind;
4685 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4687 attr->dw_attr_next = NULL;
4688 attr->dw_attr = attr_kind;
4689 attr->dw_attr_val.val_class = dw_val_class_addr;
4690 attr->dw_attr_val.v.val_addr = addr;
4691 add_dwarf_attr (die, attr);
4698 if (a && AT_class (a) == dw_val_class_addr)
4699 return a->dw_attr_val.v.val_addr;
4704 /* Add a label identifier attribute value to a DIE. */
4707 add_AT_lbl_id (die, attr_kind, lbl_id)
4709 enum dwarf_attribute attr_kind;
4712 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4714 attr->dw_attr_next = NULL;
4715 attr->dw_attr = attr_kind;
4716 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4717 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4718 add_dwarf_attr (die, attr);
4721 /* Add a section offset attribute value to a DIE. */
4724 add_AT_lbl_offset (die, attr_kind, label)
4726 enum dwarf_attribute attr_kind;
4729 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4731 attr->dw_attr_next = NULL;
4732 attr->dw_attr = attr_kind;
4733 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4734 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4735 add_dwarf_attr (die, attr);
4738 /* Add an offset attribute value to a DIE. */
4741 add_AT_offset (die, attr_kind, offset)
4743 enum dwarf_attribute attr_kind;
4744 unsigned long offset;
4746 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4748 attr->dw_attr_next = NULL;
4749 attr->dw_attr = attr_kind;
4750 attr->dw_attr_val.val_class = dw_val_class_offset;
4751 attr->dw_attr_val.v.val_offset = offset;
4752 add_dwarf_attr (die, attr);
4755 /* Add an range_list attribute value to a DIE. */
4758 add_AT_range_list (die, attr_kind, offset)
4760 enum dwarf_attribute attr_kind;
4761 unsigned long offset;
4763 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4765 attr->dw_attr_next = NULL;
4766 attr->dw_attr = attr_kind;
4767 attr->dw_attr_val.val_class = dw_val_class_range_list;
4768 attr->dw_attr_val.v.val_offset = offset;
4769 add_dwarf_attr (die, attr);
4772 static inline const char *
4776 if (a && (AT_class (a) == dw_val_class_lbl_id
4777 || AT_class (a) == dw_val_class_lbl_offset))
4778 return a->dw_attr_val.v.val_lbl_id;
4783 /* Get the attribute of type attr_kind. */
4785 static inline dw_attr_ref
4786 get_AT (die, attr_kind)
4788 enum dwarf_attribute attr_kind;
4791 dw_die_ref spec = NULL;
4795 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4796 if (a->dw_attr == attr_kind)
4798 else if (a->dw_attr == DW_AT_specification
4799 || a->dw_attr == DW_AT_abstract_origin)
4803 return get_AT (spec, attr_kind);
4809 /* Return the "low pc" attribute value, typically associated with a subprogram
4810 DIE. Return null if the "low pc" attribute is either not present, or if it
4811 cannot be represented as an assembler label identifier. */
4813 static inline const char *
4817 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4819 return a ? AT_lbl (a) : NULL;
4822 /* Return the "high pc" attribute value, typically associated with a subprogram
4823 DIE. Return null if the "high pc" attribute is either not present, or if it
4824 cannot be represented as an assembler label identifier. */
4826 static inline const char *
4830 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4832 return a ? AT_lbl (a) : NULL;
4835 /* Return the value of the string attribute designated by ATTR_KIND, or
4836 NULL if it is not present. */
4838 static inline const char *
4839 get_AT_string (die, attr_kind)
4841 enum dwarf_attribute attr_kind;
4843 dw_attr_ref a = get_AT (die, attr_kind);
4845 return a ? AT_string (a) : NULL;
4848 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4849 if it is not present. */
4852 get_AT_flag (die, attr_kind)
4854 enum dwarf_attribute attr_kind;
4856 dw_attr_ref a = get_AT (die, attr_kind);
4858 return a ? AT_flag (a) : 0;
4861 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4862 if it is not present. */
4864 static inline unsigned
4865 get_AT_unsigned (die, attr_kind)
4867 enum dwarf_attribute attr_kind;
4869 dw_attr_ref a = get_AT (die, attr_kind);
4871 return a ? AT_unsigned (a) : 0;
4874 static inline dw_die_ref
4875 get_AT_ref (die, attr_kind)
4877 enum dwarf_attribute attr_kind;
4879 dw_attr_ref a = get_AT (die, attr_kind);
4881 return a ? AT_ref (a) : NULL;
4887 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4889 return (lang == DW_LANG_C || lang == DW_LANG_C89
4890 || lang == DW_LANG_C_plus_plus);
4896 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4897 == DW_LANG_C_plus_plus);
4903 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4905 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4911 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4913 return (lang == DW_LANG_Java);
4916 /* Free up the memory used by A. */
4918 static inline void free_AT PARAMS ((dw_attr_ref));
4923 switch (AT_class (a))
4925 case dw_val_class_str:
4926 if (a->dw_attr_val.v.val_str->refcount)
4927 a->dw_attr_val.v.val_str->refcount--;
4930 case dw_val_class_lbl_id:
4931 case dw_val_class_lbl_offset:
4932 free (a->dw_attr_val.v.val_lbl_id);
4935 case dw_val_class_float:
4936 free (a->dw_attr_val.v.val_float.array);
4946 /* Remove the specified attribute if present. */
4949 remove_AT (die, attr_kind)
4951 enum dwarf_attribute attr_kind;
4954 dw_attr_ref removed = NULL;
4958 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4959 if ((*p)->dw_attr == attr_kind)
4962 *p = (*p)->dw_attr_next;
4971 /* Free up the memory used by DIE. */
4977 remove_children (die);
4981 /* Discard the children of this DIE. */
4984 remove_children (die)
4987 dw_die_ref child_die = die->die_child;
4989 die->die_child = NULL;
4991 while (child_die != NULL)
4993 dw_die_ref tmp_die = child_die;
4996 child_die = child_die->die_sib;
4998 for (a = tmp_die->die_attr; a != NULL;)
5000 dw_attr_ref tmp_a = a;
5002 a = a->dw_attr_next;
5010 /* Add a child DIE below its parent. We build the lists up in reverse
5011 addition order, and correct that in reverse_all_dies. */
5014 add_child_die (die, child_die)
5016 dw_die_ref child_die;
5018 if (die != NULL && child_die != NULL)
5020 if (die == child_die)
5023 child_die->die_parent = die;
5024 child_die->die_sib = die->die_child;
5025 die->die_child = child_die;
5029 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5030 is the specification, to the front of PARENT's list of children. */
5033 splice_child_die (parent, child)
5034 dw_die_ref parent, child;
5038 /* We want the declaration DIE from inside the class, not the
5039 specification DIE at toplevel. */
5040 if (child->die_parent != parent)
5042 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5048 if (child->die_parent != parent
5049 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
5052 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5055 *p = child->die_sib;
5059 child->die_sib = parent->die_child;
5060 parent->die_child = child;
5063 /* Return a pointer to a newly created DIE node. */
5065 static inline dw_die_ref
5066 new_die (tag_value, parent_die, t)
5067 enum dwarf_tag tag_value;
5068 dw_die_ref parent_die;
5071 dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5073 die->die_tag = tag_value;
5075 if (parent_die != NULL)
5076 add_child_die (parent_die, die);
5079 limbo_die_node *limbo_node;
5081 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5082 limbo_node->die = die;
5083 limbo_node->created_for = t;
5084 limbo_node->next = limbo_die_list;
5085 limbo_die_list = limbo_node;
5091 /* Return the DIE associated with the given type specifier. */
5093 static inline dw_die_ref
5094 lookup_type_die (type)
5097 if (TREE_CODE (type) == VECTOR_TYPE)
5098 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
5100 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
5103 /* Equate a DIE to a given type specifier. */
5106 equate_type_number_to_die (type, type_die)
5108 dw_die_ref type_die;
5110 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
5113 /* Return the DIE associated with a given declaration. */
5115 static inline dw_die_ref
5116 lookup_decl_die (decl)
5119 unsigned decl_id = DECL_UID (decl);
5121 return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
5124 /* Equate a DIE to a particular declaration. */
5127 equate_decl_number_to_die (decl, decl_die)
5129 dw_die_ref decl_die;
5131 unsigned int decl_id = DECL_UID (decl);
5132 unsigned int num_allocated;
5134 if (decl_id >= decl_die_table_allocated)
5137 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5138 / DECL_DIE_TABLE_INCREMENT)
5139 * DECL_DIE_TABLE_INCREMENT;
5142 = (dw_die_ref *) xrealloc (decl_die_table,
5143 sizeof (dw_die_ref) * num_allocated);
5145 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5146 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5147 decl_die_table_allocated = num_allocated;
5150 if (decl_id >= decl_die_table_in_use)
5151 decl_die_table_in_use = (decl_id + 1);
5153 decl_die_table[decl_id] = decl_die;
5156 /* Keep track of the number of spaces used to indent the
5157 output of the debugging routines that print the structure of
5158 the DIE internal representation. */
5159 static int print_indent;
5161 /* Indent the line the number of spaces given by print_indent. */
5164 print_spaces (outfile)
5167 fprintf (outfile, "%*s", print_indent, "");
5170 /* Print the information associated with a given DIE, and its children.
5171 This routine is a debugging aid only. */
5174 print_die (die, outfile)
5181 print_spaces (outfile);
5182 fprintf (outfile, "DIE %4lu: %s\n",
5183 die->die_offset, dwarf_tag_name (die->die_tag));
5184 print_spaces (outfile);
5185 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5186 fprintf (outfile, " offset: %lu\n", die->die_offset);
5188 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5190 print_spaces (outfile);
5191 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5193 switch (AT_class (a))
5195 case dw_val_class_addr:
5196 fprintf (outfile, "address");
5198 case dw_val_class_offset:
5199 fprintf (outfile, "offset");
5201 case dw_val_class_loc:
5202 fprintf (outfile, "location descriptor");
5204 case dw_val_class_loc_list:
5205 fprintf (outfile, "location list -> label:%s",
5206 AT_loc_list (a)->ll_symbol);
5208 case dw_val_class_range_list:
5209 fprintf (outfile, "range list");
5211 case dw_val_class_const:
5212 fprintf (outfile, "%ld", AT_int (a));
5214 case dw_val_class_unsigned_const:
5215 fprintf (outfile, "%lu", AT_unsigned (a));
5217 case dw_val_class_long_long:
5218 fprintf (outfile, "constant (%lu,%lu)",
5219 a->dw_attr_val.v.val_long_long.hi,
5220 a->dw_attr_val.v.val_long_long.low);
5222 case dw_val_class_float:
5223 fprintf (outfile, "floating-point constant");
5225 case dw_val_class_flag:
5226 fprintf (outfile, "%u", AT_flag (a));
5228 case dw_val_class_die_ref:
5229 if (AT_ref (a) != NULL)
5231 if (AT_ref (a)->die_symbol)
5232 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5234 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5237 fprintf (outfile, "die -> <null>");
5239 case dw_val_class_lbl_id:
5240 case dw_val_class_lbl_offset:
5241 fprintf (outfile, "label: %s", AT_lbl (a));
5243 case dw_val_class_str:
5244 if (AT_string (a) != NULL)
5245 fprintf (outfile, "\"%s\"", AT_string (a));
5247 fprintf (outfile, "<null>");
5253 fprintf (outfile, "\n");
5256 if (die->die_child != NULL)
5259 for (c = die->die_child; c != NULL; c = c->die_sib)
5260 print_die (c, outfile);
5264 if (print_indent == 0)
5265 fprintf (outfile, "\n");
5268 /* Print the contents of the source code line number correspondence table.
5269 This routine is a debugging aid only. */
5272 print_dwarf_line_table (outfile)
5276 dw_line_info_ref line_info;
5278 fprintf (outfile, "\n\nDWARF source line information\n");
5279 for (i = 1; i < line_info_table_in_use; i++)
5281 line_info = &line_info_table[i];
5282 fprintf (outfile, "%5d: ", i);
5283 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5284 fprintf (outfile, "%6ld", line_info->dw_line_num);
5285 fprintf (outfile, "\n");
5288 fprintf (outfile, "\n\n");
5291 /* Print the information collected for a given DIE. */
5294 debug_dwarf_die (die)
5297 print_die (die, stderr);
5300 /* Print all DWARF information collected for the compilation unit.
5301 This routine is a debugging aid only. */
5307 print_die (comp_unit_die, stderr);
5308 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5309 print_dwarf_line_table (stderr);
5312 /* We build up the lists of children and attributes by pushing new ones
5313 onto the beginning of the list. Reverse the lists for DIE so that
5314 they are in order of addition. */
5317 reverse_die_lists (die)
5320 dw_die_ref c, cp, cn;
5321 dw_attr_ref a, ap, an;
5323 for (a = die->die_attr, ap = 0; a; a = an)
5325 an = a->dw_attr_next;
5326 a->dw_attr_next = ap;
5332 for (c = die->die_child, cp = 0; c; c = cn)
5339 die->die_child = cp;
5342 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5343 reverse all dies in add_sibling_attributes, which runs through all the dies,
5344 it would reverse all the dies. Now, however, since we don't call
5345 reverse_die_lists in add_sibling_attributes, we need a routine to
5346 recursively reverse all the dies. This is that routine. */
5349 reverse_all_dies (die)
5354 reverse_die_lists (die);
5356 for (c = die->die_child; c; c = c->die_sib)
5357 reverse_all_dies (c);
5360 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5361 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5362 DIE that marks the start of the DIEs for this include file. */
5365 push_new_compile_unit (old_unit, bincl_die)
5366 dw_die_ref old_unit, bincl_die;
5368 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5369 dw_die_ref new_unit = gen_compile_unit_die (filename);
5371 new_unit->die_sib = old_unit;
5375 /* Close an include-file CU and reopen the enclosing one. */
5378 pop_compile_unit (old_unit)
5379 dw_die_ref old_unit;
5381 dw_die_ref new_unit = old_unit->die_sib;
5383 old_unit->die_sib = NULL;
5387 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5388 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5390 /* Calculate the checksum of a location expression. */
5393 loc_checksum (loc, ctx)
5394 dw_loc_descr_ref loc;
5395 struct md5_ctx *ctx;
5397 CHECKSUM (loc->dw_loc_opc);
5398 CHECKSUM (loc->dw_loc_oprnd1);
5399 CHECKSUM (loc->dw_loc_oprnd2);
5402 /* Calculate the checksum of an attribute. */
5405 attr_checksum (at, ctx)
5407 struct md5_ctx *ctx;
5409 dw_loc_descr_ref loc;
5412 CHECKSUM (at->dw_attr);
5414 /* We don't care about differences in file numbering. */
5415 if (at->dw_attr == DW_AT_decl_file
5416 /* Or that this was compiled with a different compiler snapshot; if
5417 the output is the same, that's what matters. */
5418 || at->dw_attr == DW_AT_producer)
5421 switch (AT_class (at))
5423 case dw_val_class_const:
5424 CHECKSUM (at->dw_attr_val.v.val_int);
5426 case dw_val_class_unsigned_const:
5427 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5429 case dw_val_class_long_long:
5430 CHECKSUM (at->dw_attr_val.v.val_long_long);
5432 case dw_val_class_float:
5433 CHECKSUM (at->dw_attr_val.v.val_float);
5435 case dw_val_class_flag:
5436 CHECKSUM (at->dw_attr_val.v.val_flag);
5438 case dw_val_class_str:
5439 CHECKSUM_STRING (AT_string (at));
5442 case dw_val_class_addr:
5444 switch (GET_CODE (r))
5447 CHECKSUM_STRING (XSTR (r, 0));
5455 case dw_val_class_offset:
5456 CHECKSUM (at->dw_attr_val.v.val_offset);
5459 case dw_val_class_loc:
5460 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5461 loc_checksum (loc, ctx);
5464 case dw_val_class_die_ref:
5465 if (AT_ref (at)->die_offset)
5466 CHECKSUM (AT_ref (at)->die_offset);
5467 /* FIXME else use target die name or something. */
5469 case dw_val_class_fde_ref:
5470 case dw_val_class_lbl_id:
5471 case dw_val_class_lbl_offset:
5479 /* Calculate the checksum of a DIE. */
5482 die_checksum (die, ctx)
5484 struct md5_ctx *ctx;
5489 CHECKSUM (die->die_tag);
5491 for (a = die->die_attr; a; a = a->dw_attr_next)
5492 attr_checksum (a, ctx);
5494 for (c = die->die_child; c; c = c->die_sib)
5495 die_checksum (c, ctx);
5499 #undef CHECKSUM_STRING
5501 /* The prefix to attach to symbols on DIEs in the current comdat debug
5503 static char *comdat_symbol_id;
5505 /* The index of the current symbol within the current comdat CU. */
5506 static unsigned int comdat_symbol_number;
5508 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5509 children, and set comdat_symbol_id accordingly. */
5512 compute_section_prefix (unit_die)
5513 dw_die_ref unit_die;
5515 const char *base = lbasename (get_AT_string (unit_die, DW_AT_name));
5516 char *name = (char *) alloca (strlen (base) + 64);
5519 unsigned char checksum[16];
5522 /* Compute the checksum of the DIE, then append part of it as hex digits to
5523 the name filename of the unit. */
5525 md5_init_ctx (&ctx);
5526 die_checksum (unit_die, &ctx);
5527 md5_finish_ctx (&ctx, checksum);
5529 sprintf (name, "%s.", base);
5530 clean_symbol_name (name);
5532 p = name + strlen (name);
5533 for (i = 0; i < 4; i++)
5535 sprintf (p, "%.2x", checksum[i]);
5539 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5540 comdat_symbol_number = 0;
5543 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5549 switch (die->die_tag)
5551 case DW_TAG_array_type:
5552 case DW_TAG_class_type:
5553 case DW_TAG_enumeration_type:
5554 case DW_TAG_pointer_type:
5555 case DW_TAG_reference_type:
5556 case DW_TAG_string_type:
5557 case DW_TAG_structure_type:
5558 case DW_TAG_subroutine_type:
5559 case DW_TAG_union_type:
5560 case DW_TAG_ptr_to_member_type:
5561 case DW_TAG_set_type:
5562 case DW_TAG_subrange_type:
5563 case DW_TAG_base_type:
5564 case DW_TAG_const_type:
5565 case DW_TAG_file_type:
5566 case DW_TAG_packed_type:
5567 case DW_TAG_volatile_type:
5574 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5575 Basically, we want to choose the bits that are likely to be shared between
5576 compilations (types) and leave out the bits that are specific to individual
5577 compilations (functions). */
5583 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5584 we do for stabs. The advantage is a greater likelihood of sharing between
5585 objects that don't include headers in the same order (and therefore would
5586 put the base types in a different comdat). jason 8/28/00 */
5588 if (c->die_tag == DW_TAG_base_type)
5591 if (c->die_tag == DW_TAG_pointer_type
5592 || c->die_tag == DW_TAG_reference_type
5593 || c->die_tag == DW_TAG_const_type
5594 || c->die_tag == DW_TAG_volatile_type)
5596 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5598 return t ? is_comdat_die (t) : 0;
5601 return is_type_die (c);
5604 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5605 compilation unit. */
5611 return (is_type_die (c)
5612 || (get_AT (c, DW_AT_declaration)
5613 && !get_AT (c, DW_AT_specification)));
5617 gen_internal_sym (prefix)
5621 static int label_num;
5623 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5624 return xstrdup (buf);
5627 /* Assign symbols to all worthy DIEs under DIE. */
5630 assign_symbol_names (die)
5635 if (is_symbol_die (die))
5637 if (comdat_symbol_id)
5639 char *p = alloca (strlen (comdat_symbol_id) + 64);
5641 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5642 comdat_symbol_id, comdat_symbol_number++);
5643 die->die_symbol = xstrdup (p);
5646 die->die_symbol = gen_internal_sym ("LDIE");
5649 for (c = die->die_child; c != NULL; c = c->die_sib)
5650 assign_symbol_names (c);
5653 /* Traverse the DIE (which is always comp_unit_die), and set up
5654 additional compilation units for each of the include files we see
5655 bracketed by BINCL/EINCL. */
5658 break_out_includes (die)
5662 dw_die_ref unit = NULL;
5663 limbo_die_node *node;
5665 for (ptr = &(die->die_child); *ptr; )
5667 dw_die_ref c = *ptr;
5669 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
5670 || (unit && is_comdat_die (c)))
5672 /* This DIE is for a secondary CU; remove it from the main one. */
5675 if (c->die_tag == DW_TAG_GNU_BINCL)
5677 unit = push_new_compile_unit (unit, c);
5680 else if (c->die_tag == DW_TAG_GNU_EINCL)
5682 unit = pop_compile_unit (unit);
5686 add_child_die (unit, c);
5690 /* Leave this DIE in the main CU. */
5691 ptr = &(c->die_sib);
5697 /* We can only use this in debugging, since the frontend doesn't check
5698 to make sure that we leave every include file we enter. */
5703 assign_symbol_names (die);
5704 for (node = limbo_die_list; node; node = node->next)
5706 compute_section_prefix (node->die);
5707 assign_symbol_names (node->die);
5711 /* Traverse the DIE and add a sibling attribute if it may have the
5712 effect of speeding up access to siblings. To save some space,
5713 avoid generating sibling attributes for DIE's without children. */
5716 add_sibling_attributes (die)
5721 if (die->die_tag != DW_TAG_compile_unit
5722 && die->die_sib && die->die_child != NULL)
5723 /* Add the sibling link to the front of the attribute list. */
5724 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5726 for (c = die->die_child; c != NULL; c = c->die_sib)
5727 add_sibling_attributes (c);
5730 /* Output all location lists for the DIE and its children. */
5733 output_location_lists (die)
5739 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5740 if (AT_class (d_attr) == dw_val_class_loc_list)
5741 output_loc_list (AT_loc_list (d_attr));
5743 for (c = die->die_child; c != NULL; c = c->die_sib)
5744 output_location_lists (c);
5747 /* The format of each DIE (and its attribute value pairs) is encoded in an
5748 abbreviation table. This routine builds the abbreviation table and assigns
5749 a unique abbreviation id for each abbreviation entry. The children of each
5750 die are visited recursively. */
5753 build_abbrev_table (die)
5756 unsigned long abbrev_id;
5757 unsigned int n_alloc;
5759 dw_attr_ref d_attr, a_attr;
5761 /* Scan the DIE references, and mark as external any that refer to
5762 DIEs from other CUs (i.e. those which are not marked). */
5763 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5764 if (AT_class (d_attr) == dw_val_class_die_ref
5765 && AT_ref (d_attr)->die_mark == 0)
5767 if (AT_ref (d_attr)->die_symbol == 0)
5770 set_AT_ref_external (d_attr, 1);
5773 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5775 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5777 if (abbrev->die_tag == die->die_tag)
5779 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5781 a_attr = abbrev->die_attr;
5782 d_attr = die->die_attr;
5784 while (a_attr != NULL && d_attr != NULL)
5786 if ((a_attr->dw_attr != d_attr->dw_attr)
5787 || (value_format (a_attr) != value_format (d_attr)))
5790 a_attr = a_attr->dw_attr_next;
5791 d_attr = d_attr->dw_attr_next;
5794 if (a_attr == NULL && d_attr == NULL)
5800 if (abbrev_id >= abbrev_die_table_in_use)
5802 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5804 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5806 = (dw_die_ref *) xrealloc (abbrev_die_table,
5807 sizeof (dw_die_ref) * n_alloc);
5809 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5810 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5811 abbrev_die_table_allocated = n_alloc;
5814 ++abbrev_die_table_in_use;
5815 abbrev_die_table[abbrev_id] = die;
5818 die->die_abbrev = abbrev_id;
5819 for (c = die->die_child; c != NULL; c = c->die_sib)
5820 build_abbrev_table (c);
5823 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5826 constant_size (value)
5827 long unsigned value;
5834 log = floor_log2 (value);
5837 log = 1 << (floor_log2 (log) + 1);
5842 /* Return the size of a DIE as it is represented in the
5843 .debug_info section. */
5845 static unsigned long
5849 unsigned long size = 0;
5852 size += size_of_uleb128 (die->die_abbrev);
5853 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5855 switch (AT_class (a))
5857 case dw_val_class_addr:
5858 size += DWARF2_ADDR_SIZE;
5860 case dw_val_class_offset:
5861 size += DWARF_OFFSET_SIZE;
5863 case dw_val_class_loc:
5865 unsigned long lsize = size_of_locs (AT_loc (a));
5868 size += constant_size (lsize);
5872 case dw_val_class_loc_list:
5873 size += DWARF_OFFSET_SIZE;
5875 case dw_val_class_range_list:
5876 size += DWARF_OFFSET_SIZE;
5878 case dw_val_class_const:
5879 size += size_of_sleb128 (AT_int (a));
5881 case dw_val_class_unsigned_const:
5882 size += constant_size (AT_unsigned (a));
5884 case dw_val_class_long_long:
5885 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5887 case dw_val_class_float:
5888 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5890 case dw_val_class_flag:
5893 case dw_val_class_die_ref:
5894 size += DWARF_OFFSET_SIZE;
5896 case dw_val_class_fde_ref:
5897 size += DWARF_OFFSET_SIZE;
5899 case dw_val_class_lbl_id:
5900 size += DWARF2_ADDR_SIZE;
5902 case dw_val_class_lbl_offset:
5903 size += DWARF_OFFSET_SIZE;
5905 case dw_val_class_str:
5906 if (AT_string_form (a) == DW_FORM_strp)
5907 size += DWARF_OFFSET_SIZE;
5909 size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1;
5919 /* Size the debugging information associated with a given DIE. Visits the
5920 DIE's children recursively. Updates the global variable next_die_offset, on
5921 each time through. Uses the current value of next_die_offset to update the
5922 die_offset field in each DIE. */
5925 calc_die_sizes (die)
5930 die->die_offset = next_die_offset;
5931 next_die_offset += size_of_die (die);
5933 for (c = die->die_child; c != NULL; c = c->die_sib)
5936 if (die->die_child != NULL)
5937 /* Count the null byte used to terminate sibling lists. */
5938 next_die_offset += 1;
5941 /* Set the marks for a die and its children. We do this so
5942 that we know whether or not a reference needs to use FORM_ref_addr; only
5943 DIEs in the same CU will be marked. We used to clear out the offset
5944 and use that as the flag, but ran into ordering problems. */
5953 for (c = die->die_child; c; c = c->die_sib)
5957 /* Clear the marks for a die and its children. */
5966 for (c = die->die_child; c; c = c->die_sib)
5970 /* Return the size of the .debug_pubnames table generated for the
5971 compilation unit. */
5973 static unsigned long
5979 size = DWARF_PUBNAMES_HEADER_SIZE;
5980 for (i = 0; i < pubname_table_in_use; i++)
5982 pubname_ref p = &pubname_table[i];
5983 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
5986 size += DWARF_OFFSET_SIZE;
5990 /* Return the size of the information in the .debug_aranges section. */
5992 static unsigned long
5997 size = DWARF_ARANGES_HEADER_SIZE;
5999 /* Count the address/length pair for this compilation unit. */
6000 size += 2 * DWARF2_ADDR_SIZE;
6001 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6003 /* Count the two zero words used to terminated the address range table. */
6004 size += 2 * DWARF2_ADDR_SIZE;
6008 /* Select the encoding of an attribute value. */
6010 static enum dwarf_form
6014 switch (a->dw_attr_val.val_class)
6016 case dw_val_class_addr:
6017 return DW_FORM_addr;
6018 case dw_val_class_range_list:
6019 case dw_val_class_offset:
6020 if (DWARF_OFFSET_SIZE == 4)
6021 return DW_FORM_data4;
6022 if (DWARF_OFFSET_SIZE == 8)
6023 return DW_FORM_data8;
6025 case dw_val_class_loc_list:
6026 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6027 .debug_loc section */
6028 return DW_FORM_data4;
6029 case dw_val_class_loc:
6030 switch (constant_size (size_of_locs (AT_loc (a))))
6033 return DW_FORM_block1;
6035 return DW_FORM_block2;
6039 case dw_val_class_const:
6040 return DW_FORM_sdata;
6041 case dw_val_class_unsigned_const:
6042 switch (constant_size (AT_unsigned (a)))
6045 return DW_FORM_data1;
6047 return DW_FORM_data2;
6049 return DW_FORM_data4;
6051 return DW_FORM_data8;
6055 case dw_val_class_long_long:
6056 return DW_FORM_block1;
6057 case dw_val_class_float:
6058 return DW_FORM_block1;
6059 case dw_val_class_flag:
6060 return DW_FORM_flag;
6061 case dw_val_class_die_ref:
6062 if (AT_ref_external (a))
6063 return DW_FORM_ref_addr;
6066 case dw_val_class_fde_ref:
6067 return DW_FORM_data;
6068 case dw_val_class_lbl_id:
6069 return DW_FORM_addr;
6070 case dw_val_class_lbl_offset:
6071 return DW_FORM_data;
6072 case dw_val_class_str:
6073 return AT_string_form (a);
6080 /* Output the encoding of an attribute value. */
6083 output_value_format (a)
6086 enum dwarf_form form = value_format (a);
6088 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6091 /* Output the .debug_abbrev section which defines the DIE abbreviation
6095 output_abbrev_section ()
6097 unsigned long abbrev_id;
6101 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6103 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6105 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6106 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6107 dwarf_tag_name (abbrev->die_tag));
6109 if (abbrev->die_child != NULL)
6110 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6112 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6114 for (a_attr = abbrev->die_attr; a_attr != NULL;
6115 a_attr = a_attr->dw_attr_next)
6117 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6118 dwarf_attr_name (a_attr->dw_attr));
6119 output_value_format (a_attr);
6122 dw2_asm_output_data (1, 0, NULL);
6123 dw2_asm_output_data (1, 0, NULL);
6126 /* Terminate the table. */
6127 dw2_asm_output_data (1, 0, NULL);
6130 /* Output a symbol we can use to refer to this DIE from another CU. */
6133 output_die_symbol (die)
6136 char *sym = die->die_symbol;
6141 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6142 /* We make these global, not weak; if the target doesn't support
6143 .linkonce, it doesn't support combining the sections, so debugging
6145 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6147 ASM_OUTPUT_LABEL (asm_out_file, sym);
6150 /* Return a new location list, given the begin and end range, and the
6151 expression. gensym tells us whether to generate a new internal symbol for
6152 this location list node, which is done for the head of the list only. */
6154 static inline dw_loc_list_ref
6155 new_loc_list (expr, begin, end, section, gensym)
6156 dw_loc_descr_ref expr;
6159 const char *section;
6162 dw_loc_list_ref retlist
6163 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6165 retlist->begin = begin;
6167 retlist->expr = expr;
6168 retlist->section = section;
6170 retlist->ll_symbol = gen_internal_sym ("LLST");
6175 /* Add a location description expression to a location list */
6178 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6179 dw_loc_list_ref *list_head;
6180 dw_loc_descr_ref descr;
6183 const char *section;
6187 /* Find the end of the chain. */
6188 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6191 /* Add a new location list node to the list */
6192 *d = new_loc_list (descr, begin, end, section, 0);
6195 /* Output the location list given to us */
6198 output_loc_list (list_head)
6199 dw_loc_list_ref list_head;
6201 dw_loc_list_ref curr = list_head;
6203 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6205 /* ??? This shouldn't be needed now that we've forced the
6206 compilation unit base address to zero when there is code
6207 in more than one section. */
6208 if (strcmp (curr->section, ".text") == 0)
6210 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6211 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
6212 "Location list base address specifier fake entry");
6213 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6214 "Location list base address specifier base");
6217 for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
6221 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6222 "Location list begin address (%s)",
6223 list_head->ll_symbol);
6224 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6225 "Location list end address (%s)",
6226 list_head->ll_symbol);
6227 size = size_of_locs (curr->expr);
6229 /* Output the block length for this list of location operations. */
6232 dw2_asm_output_data (2, size, "%s", "Location expression size");
6234 output_loc_sequence (curr->expr);
6237 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6238 "Location list terminator begin (%s)",
6239 list_head->ll_symbol);
6240 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6241 "Location list terminator end (%s)",
6242 list_head->ll_symbol);
6245 /* Output the DIE and its attributes. Called recursively to generate
6246 the definitions of each child DIE. */
6256 /* If someone in another CU might refer to us, set up a symbol for
6257 them to point to. */
6258 if (die->die_symbol)
6259 output_die_symbol (die);
6261 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6262 die->die_offset, dwarf_tag_name (die->die_tag));
6264 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6266 const char *name = dwarf_attr_name (a->dw_attr);
6268 switch (AT_class (a))
6270 case dw_val_class_addr:
6271 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6274 case dw_val_class_offset:
6275 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6279 case dw_val_class_range_list:
6281 char *p = strchr (ranges_section_label, '\0');
6283 sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset);
6284 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6290 case dw_val_class_loc:
6291 size = size_of_locs (AT_loc (a));
6293 /* Output the block length for this list of location operations. */
6294 dw2_asm_output_data (constant_size (size), size, "%s", name);
6296 output_loc_sequence (AT_loc (a));
6299 case dw_val_class_const:
6300 /* ??? It would be slightly more efficient to use a scheme like is
6301 used for unsigned constants below, but gdb 4.x does not sign
6302 extend. Gdb 5.x does sign extend. */
6303 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6306 case dw_val_class_unsigned_const:
6307 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6308 AT_unsigned (a), "%s", name);
6311 case dw_val_class_long_long:
6313 unsigned HOST_WIDE_INT first, second;
6315 dw2_asm_output_data (1,
6316 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6319 if (WORDS_BIG_ENDIAN)
6321 first = a->dw_attr_val.v.val_long_long.hi;
6322 second = a->dw_attr_val.v.val_long_long.low;
6326 first = a->dw_attr_val.v.val_long_long.low;
6327 second = a->dw_attr_val.v.val_long_long.hi;
6330 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6331 first, "long long constant");
6332 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6337 case dw_val_class_float:
6341 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6344 for (i = 0; i < a->dw_attr_val.v.val_float.length; i++)
6345 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6346 "fp constant word %u", i);
6350 case dw_val_class_flag:
6351 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6354 case dw_val_class_loc_list:
6356 char *sym = AT_loc_list (a)->ll_symbol;
6360 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6361 loc_section_label, "%s", name);
6365 case dw_val_class_die_ref:
6366 if (AT_ref_external (a))
6368 char *sym = AT_ref (a)->die_symbol;
6372 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6374 else if (AT_ref (a)->die_offset == 0)
6377 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6381 case dw_val_class_fde_ref:
6385 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6386 a->dw_attr_val.v.val_fde_index * 2);
6387 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6391 case dw_val_class_lbl_id:
6392 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6395 case dw_val_class_lbl_offset:
6396 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6399 case dw_val_class_str:
6400 if (AT_string_form (a) == DW_FORM_strp)
6401 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6402 a->dw_attr_val.v.val_str->label,
6403 "%s: \"%s\"", name, AT_string (a));
6405 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6413 for (c = die->die_child; c != NULL; c = c->die_sib)
6416 /* Add null byte to terminate sibling list. */
6417 if (die->die_child != NULL)
6418 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6422 /* Output the compilation unit that appears at the beginning of the
6423 .debug_info section, and precedes the DIE descriptions. */
6426 output_compilation_unit_header ()
6428 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6429 "Length of Compilation Unit Info");
6430 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6431 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6432 "Offset Into Abbrev. Section");
6433 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6436 /* Output the compilation unit DIE and its children. */
6439 output_comp_unit (die)
6442 const char *secname;
6444 /* Even if there are no children of this DIE, we must output the information
6445 about the compilation unit. Otherwise, on an empty translation unit, we
6446 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6447 will then complain when examining the file. First mark all the DIEs in
6448 this CU so we know which get local refs. */
6451 build_abbrev_table (die);
6453 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6454 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6455 calc_die_sizes (die);
6457 if (die->die_symbol)
6459 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6461 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6463 die->die_symbol = NULL;
6466 secname = (const char *) DEBUG_INFO_SECTION;
6468 /* Output debugging information. */
6469 named_section_flags (secname, SECTION_DEBUG);
6470 output_compilation_unit_header ();
6473 /* Leave the marks on the main CU, so we can check them in
6475 if (die->die_symbol)
6479 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6480 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6481 argument list, and maybe the scope. */
6484 dwarf2_name (decl, scope)
6488 return (*decl_printable_name) (decl, scope ? 1 : 0);
6491 /* Add a new entry to .debug_pubnames if appropriate. */
6494 add_pubname (decl, die)
6500 if (! TREE_PUBLIC (decl))
6503 if (pubname_table_in_use == pubname_table_allocated)
6505 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6507 = (pubname_ref) xrealloc (pubname_table,
6508 (pubname_table_allocated
6509 * sizeof (pubname_entry)));
6512 p = &pubname_table[pubname_table_in_use++];
6514 p->name = xstrdup (dwarf2_name (decl, 1));
6517 /* Output the public names table used to speed up access to externally
6518 visible names. For now, only generate entries for externally
6519 visible procedures. */
6525 unsigned long pubnames_length = size_of_pubnames ();
6527 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6528 "Length of Public Names Info");
6529 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6530 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6531 "Offset of Compilation Unit Info");
6532 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6533 "Compilation Unit Length");
6535 for (i = 0; i < pubname_table_in_use; i++)
6537 pubname_ref pub = &pubname_table[i];
6539 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6540 if (pub->die->die_mark == 0)
6543 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6546 dw2_asm_output_nstring (pub->name, -1, "external name");
6549 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6552 /* Add a new entry to .debug_aranges if appropriate. */
6555 add_arange (decl, die)
6559 if (! DECL_SECTION_NAME (decl))
6562 if (arange_table_in_use == arange_table_allocated)
6564 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6565 arange_table = (dw_die_ref *)
6566 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6569 arange_table[arange_table_in_use++] = die;
6572 /* Output the information that goes into the .debug_aranges table.
6573 Namely, define the beginning and ending address range of the
6574 text section generated for this compilation unit. */
6580 unsigned long aranges_length = size_of_aranges ();
6582 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6583 "Length of Address Ranges Info");
6584 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6585 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6586 "Offset of Compilation Unit Info");
6587 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6588 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6590 /* We need to align to twice the pointer size here. */
6591 if (DWARF_ARANGES_PAD_SIZE)
6593 /* Pad using a 2 byte words so that padding is correct for any
6595 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6596 2 * DWARF2_ADDR_SIZE);
6597 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6598 dw2_asm_output_data (2, 0, NULL);
6601 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6602 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6603 text_section_label, "Length");
6605 for (i = 0; i < arange_table_in_use; i++)
6607 dw_die_ref die = arange_table[i];
6609 /* We shouldn't see aranges for DIEs outside of the main CU. */
6610 if (die->die_mark == 0)
6613 if (die->die_tag == DW_TAG_subprogram)
6615 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6617 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6618 get_AT_low_pc (die), "Length");
6622 /* A static variable; extract the symbol from DW_AT_location.
6623 Note that this code isn't currently hit, as we only emit
6624 aranges for functions (jason 9/23/99). */
6625 dw_attr_ref a = get_AT (die, DW_AT_location);
6626 dw_loc_descr_ref loc;
6628 if (! a || AT_class (a) != dw_val_class_loc)
6632 if (loc->dw_loc_opc != DW_OP_addr)
6635 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6636 loc->dw_loc_oprnd1.v.val_addr, "Address");
6637 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6638 get_AT_unsigned (die, DW_AT_byte_size),
6643 /* Output the terminator words. */
6644 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6645 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6648 /* Add a new entry to .debug_ranges. Return the offset at which it
6655 unsigned int in_use = ranges_table_in_use;
6657 if (in_use == ranges_table_allocated)
6659 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6660 ranges_table = (dw_ranges_ref)
6661 xrealloc (ranges_table, (ranges_table_allocated
6662 * sizeof (struct dw_ranges_struct)));
6665 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6666 ranges_table_in_use = in_use + 1;
6668 return in_use * 2 * DWARF2_ADDR_SIZE;
6675 static const char *const start_fmt = "Offset 0x%x";
6676 const char *fmt = start_fmt;
6678 for (i = 0; i < ranges_table_in_use; i++)
6680 int block_num = ranges_table[i].block_num;
6684 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6685 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6687 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6688 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6690 /* If all code is in the text section, then the compilation
6691 unit base address defaults to DW_AT_low_pc, which is the
6692 base of the text section. */
6693 if (separate_line_info_table_in_use == 0)
6695 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6697 fmt, i * 2 * DWARF2_ADDR_SIZE);
6698 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6699 text_section_label, NULL);
6702 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6703 compilation unit base address to zero, which allows us to
6704 use absolute addresses, and not worry about whether the
6705 target supports cross-section arithmetic. */
6708 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6709 fmt, i * 2 * DWARF2_ADDR_SIZE);
6710 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6717 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6718 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6724 /* Data structure containing information about input files. */
6727 char *path; /* Complete file name. */
6728 char *fname; /* File name part. */
6729 int length; /* Length of entire string. */
6730 int file_idx; /* Index in input file table. */
6731 int dir_idx; /* Index in directory table. */
6734 /* Data structure containing information about directories with source
6738 char *path; /* Path including directory name. */
6739 int length; /* Path length. */
6740 int prefix; /* Index of directory entry which is a prefix. */
6741 int count; /* Number of files in this directory. */
6742 int dir_idx; /* Index of directory used as base. */
6743 int used; /* Used in the end? */
6746 /* Callback function for file_info comparison. We sort by looking at
6747 the directories in the path. */
6750 file_info_cmp (p1, p2)
6754 const struct file_info *s1 = p1;
6755 const struct file_info *s2 = p2;
6759 /* Take care of file names without directories. We need to make sure that
6760 we return consistent values to qsort since some will get confused if
6761 we return the same value when identical operands are passed in opposite
6762 orders. So if neither has a directory, return 0 and otherwise return
6763 1 or -1 depending on which one has the directory. */
6764 if ((s1->path == s1->fname || s2->path == s2->fname))
6765 return (s2->path == s2->fname) - (s1->path == s1->fname);
6767 cp1 = (unsigned char *) s1->path;
6768 cp2 = (unsigned char *) s2->path;
6774 /* Reached the end of the first path? If so, handle like above. */
6775 if ((cp1 == (unsigned char *) s1->fname)
6776 || (cp2 == (unsigned char *) s2->fname))
6777 return ((cp2 == (unsigned char *) s2->fname)
6778 - (cp1 == (unsigned char *) s1->fname));
6780 /* Character of current path component the same? */
6781 else if (*cp1 != *cp2)
6786 /* Output the directory table and the file name table. We try to minimize
6787 the total amount of memory needed. A heuristic is used to avoid large
6788 slowdowns with many input files. */
6791 output_file_names ()
6793 struct file_info *files;
6794 struct dir_info *dirs;
6803 /* Allocate the various arrays we need. */
6804 files = (struct file_info *) alloca (file_table.in_use
6805 * sizeof (struct file_info));
6806 dirs = (struct dir_info *) alloca (file_table.in_use
6807 * sizeof (struct dir_info));
6809 /* Sort the file names. */
6810 for (i = 1; i < (int) file_table.in_use; i++)
6814 /* Skip all leading "./". */
6815 f = file_table.table[i];
6816 while (f[0] == '.' && f[1] == '/')
6819 /* Create a new array entry. */
6821 files[i].length = strlen (f);
6822 files[i].file_idx = i;
6824 /* Search for the file name part. */
6825 f = strrchr (f, '/');
6826 files[i].fname = f == NULL ? files[i].path : f + 1;
6829 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6831 /* Find all the different directories used. */
6832 dirs[0].path = files[1].path;
6833 dirs[0].length = files[1].fname - files[1].path;
6834 dirs[0].prefix = -1;
6836 dirs[0].dir_idx = 0;
6838 files[1].dir_idx = 0;
6841 for (i = 2; i < (int) file_table.in_use; i++)
6842 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6843 && memcmp (dirs[ndirs - 1].path, files[i].path,
6844 dirs[ndirs - 1].length) == 0)
6846 /* Same directory as last entry. */
6847 files[i].dir_idx = ndirs - 1;
6848 ++dirs[ndirs - 1].count;
6854 /* This is a new directory. */
6855 dirs[ndirs].path = files[i].path;
6856 dirs[ndirs].length = files[i].fname - files[i].path;
6857 dirs[ndirs].count = 1;
6858 dirs[ndirs].dir_idx = ndirs;
6859 dirs[ndirs].used = 0;
6860 files[i].dir_idx = ndirs;
6862 /* Search for a prefix. */
6863 dirs[ndirs].prefix = -1;
6864 for (j = 0; j < ndirs; j++)
6865 if (dirs[j].length < dirs[ndirs].length
6866 && dirs[j].length > 1
6867 && (dirs[ndirs].prefix == -1
6868 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6869 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6870 dirs[ndirs].prefix = j;
6875 /* Now to the actual work. We have to find a subset of the directories which
6876 allow expressing the file name using references to the directory table
6877 with the least amount of characters. We do not do an exhaustive search
6878 where we would have to check out every combination of every single
6879 possible prefix. Instead we use a heuristic which provides nearly optimal
6880 results in most cases and never is much off. */
6881 saved = (int *) alloca (ndirs * sizeof (int));
6882 savehere = (int *) alloca (ndirs * sizeof (int));
6884 memset (saved, '\0', ndirs * sizeof (saved[0]));
6885 for (i = 0; i < ndirs; i++)
6890 /* We can always save some space for the current directory. But this
6891 does not mean it will be enough to justify adding the directory. */
6892 savehere[i] = dirs[i].length;
6893 total = (savehere[i] - saved[i]) * dirs[i].count;
6895 for (j = i + 1; j < ndirs; j++)
6898 if (saved[j] < dirs[i].length)
6900 /* Determine whether the dirs[i] path is a prefix of the
6905 while (k != -1 && k != i)
6910 /* Yes it is. We can possibly safe some memory but
6911 writing the filenames in dirs[j] relative to
6913 savehere[j] = dirs[i].length;
6914 total += (savehere[j] - saved[j]) * dirs[j].count;
6919 /* Check whether we can safe enough to justify adding the dirs[i]
6921 if (total > dirs[i].length + 1)
6923 /* It's worthwhile adding. */
6924 for (j = i; j < ndirs; j++)
6925 if (savehere[j] > 0)
6927 /* Remember how much we saved for this directory so far. */
6928 saved[j] = savehere[j];
6930 /* Remember the prefix directory. */
6931 dirs[j].dir_idx = i;
6936 /* We have to emit them in the order they appear in the file_table array
6937 since the index is used in the debug info generation. To do this
6938 efficiently we generate a back-mapping of the indices first. */
6939 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6940 for (i = 1; i < (int) file_table.in_use; i++)
6942 backmap[files[i].file_idx] = i;
6944 /* Mark this directory as used. */
6945 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6948 /* That was it. We are ready to emit the information. First emit the
6949 directory name table. We have to make sure the first actually emitted
6950 directory name has index one; zero is reserved for the current working
6951 directory. Make sure we do not confuse these indices with the one for the
6952 constructed table (even though most of the time they are identical). */
6954 idx_offset = dirs[0].length > 0 ? 1 : 0;
6955 for (i = 1 - idx_offset; i < ndirs; i++)
6956 if (dirs[i].used != 0)
6958 dirs[i].used = idx++;
6959 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6960 "Directory Entry: 0x%x", dirs[i].used);
6963 dw2_asm_output_data (1, 0, "End directory table");
6965 /* Correct the index for the current working directory entry if it
6967 if (idx_offset == 0)
6970 /* Now write all the file names. */
6971 for (i = 1; i < (int) file_table.in_use; i++)
6973 int file_idx = backmap[i];
6974 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6976 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6977 "File Entry: 0x%x", i);
6979 /* Include directory index. */
6980 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6982 /* Modification time. */
6983 dw2_asm_output_data_uleb128 (0, NULL);
6985 /* File length in bytes. */
6986 dw2_asm_output_data_uleb128 (0, NULL);
6989 dw2_asm_output_data (1, 0, "End file name table");
6993 /* Output the source line number correspondence information. This
6994 information goes into the .debug_line section. */
6999 char l1[20], l2[20], p1[20], p2[20];
7000 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7001 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7004 unsigned long lt_index;
7005 unsigned long current_line;
7008 unsigned long current_file;
7009 unsigned long function;
7011 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7012 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7013 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7014 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7016 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7017 "Length of Source Line Info");
7018 ASM_OUTPUT_LABEL (asm_out_file, l1);
7020 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7021 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7022 ASM_OUTPUT_LABEL (asm_out_file, p1);
7024 /* Define the architecture-dependent minimum instruction length (in
7025 bytes). In this implementation of DWARF, this field is used for
7026 information purposes only. Since GCC generates assembly language,
7027 we have no a priori knowledge of how many instruction bytes are
7028 generated for each source line, and therefore can use only the
7029 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7030 commands. Accordingly, we fix this as `1', which is "correct
7031 enough" for all architectures, and don't let the target override. */
7032 dw2_asm_output_data (1, 1,
7033 "Minimum Instruction Length");
7035 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7036 "Default is_stmt_start flag");
7037 dw2_asm_output_data (1, DWARF_LINE_BASE,
7038 "Line Base Value (Special Opcodes)");
7039 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7040 "Line Range Value (Special Opcodes)");
7041 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7042 "Special Opcode Base");
7044 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7048 case DW_LNS_advance_pc:
7049 case DW_LNS_advance_line:
7050 case DW_LNS_set_file:
7051 case DW_LNS_set_column:
7052 case DW_LNS_fixed_advance_pc:
7060 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7064 /* Write out the information about the files we use. */
7065 output_file_names ();
7066 ASM_OUTPUT_LABEL (asm_out_file, p2);
7068 /* We used to set the address register to the first location in the text
7069 section here, but that didn't accomplish anything since we already
7070 have a line note for the opening brace of the first function. */
7072 /* Generate the line number to PC correspondence table, encoded as
7073 a series of state machine operations. */
7076 strcpy (prev_line_label, text_section_label);
7077 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7079 dw_line_info_ref line_info = &line_info_table[lt_index];
7082 /* Disable this optimization for now; GDB wants to see two line notes
7083 at the beginning of a function so it can find the end of the
7086 /* Don't emit anything for redundant notes. Just updating the
7087 address doesn't accomplish anything, because we already assume
7088 that anything after the last address is this line. */
7089 if (line_info->dw_line_num == current_line
7090 && line_info->dw_file_num == current_file)
7094 /* Emit debug info for the address of the current line.
7096 Unfortunately, we have little choice here currently, and must always
7097 use the most general form. GCC does not know the address delta
7098 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7099 attributes which will give an upper bound on the address range. We
7100 could perhaps use length attributes to determine when it is safe to
7101 use DW_LNS_fixed_advance_pc. */
7103 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7106 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7107 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7108 "DW_LNS_fixed_advance_pc");
7109 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7113 /* This can handle any delta. This takes
7114 4+DWARF2_ADDR_SIZE bytes. */
7115 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7116 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7117 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7118 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7121 strcpy (prev_line_label, line_label);
7123 /* Emit debug info for the source file of the current line, if
7124 different from the previous line. */
7125 if (line_info->dw_file_num != current_file)
7127 current_file = line_info->dw_file_num;
7128 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7129 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7130 file_table.table[current_file]);
7133 /* Emit debug info for the current line number, choosing the encoding
7134 that uses the least amount of space. */
7135 if (line_info->dw_line_num != current_line)
7137 line_offset = line_info->dw_line_num - current_line;
7138 line_delta = line_offset - DWARF_LINE_BASE;
7139 current_line = line_info->dw_line_num;
7140 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7141 /* This can handle deltas from -10 to 234, using the current
7142 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7144 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7145 "line %lu", current_line);
7148 /* This can handle any delta. This takes at least 4 bytes,
7149 depending on the value being encoded. */
7150 dw2_asm_output_data (1, DW_LNS_advance_line,
7151 "advance to line %lu", current_line);
7152 dw2_asm_output_data_sleb128 (line_offset, NULL);
7153 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7157 /* We still need to start a new row, so output a copy insn. */
7158 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7161 /* Emit debug info for the address of the end of the function. */
7164 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7165 "DW_LNS_fixed_advance_pc");
7166 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7170 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7171 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7172 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7173 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7176 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7177 dw2_asm_output_data_uleb128 (1, NULL);
7178 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7183 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7185 dw_separate_line_info_ref line_info
7186 = &separate_line_info_table[lt_index];
7189 /* Don't emit anything for redundant notes. */
7190 if (line_info->dw_line_num == current_line
7191 && line_info->dw_file_num == current_file
7192 && line_info->function == function)
7196 /* Emit debug info for the address of the current line. If this is
7197 a new function, or the first line of a function, then we need
7198 to handle it differently. */
7199 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7201 if (function != line_info->function)
7203 function = line_info->function;
7205 /* Set the address register to the first line in the function */
7206 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7207 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7208 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7209 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7213 /* ??? See the DW_LNS_advance_pc comment above. */
7216 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7217 "DW_LNS_fixed_advance_pc");
7218 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7222 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7223 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7224 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7225 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7229 strcpy (prev_line_label, line_label);
7231 /* Emit debug info for the source file of the current line, if
7232 different from the previous line. */
7233 if (line_info->dw_file_num != current_file)
7235 current_file = line_info->dw_file_num;
7236 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7237 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7238 file_table.table[current_file]);
7241 /* Emit debug info for the current line number, choosing the encoding
7242 that uses the least amount of space. */
7243 if (line_info->dw_line_num != current_line)
7245 line_offset = line_info->dw_line_num - current_line;
7246 line_delta = line_offset - DWARF_LINE_BASE;
7247 current_line = line_info->dw_line_num;
7248 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7249 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7250 "line %lu", current_line);
7253 dw2_asm_output_data (1, DW_LNS_advance_line,
7254 "advance to line %lu", current_line);
7255 dw2_asm_output_data_sleb128 (line_offset, NULL);
7256 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7260 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7268 /* If we're done with a function, end its sequence. */
7269 if (lt_index == separate_line_info_table_in_use
7270 || separate_line_info_table[lt_index].function != function)
7275 /* Emit debug info for the address of the end of the function. */
7276 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7279 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7280 "DW_LNS_fixed_advance_pc");
7281 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7285 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7286 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7287 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7288 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7291 /* Output the marker for the end of this sequence. */
7292 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7293 dw2_asm_output_data_uleb128 (1, NULL);
7294 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7298 /* Output the marker for the end of the line number info. */
7299 ASM_OUTPUT_LABEL (asm_out_file, l2);
7302 /* Given a pointer to a tree node for some base type, return a pointer to
7303 a DIE that describes the given type.
7305 This routine must only be called for GCC type nodes that correspond to
7306 Dwarf base (fundamental) types. */
7309 base_type_die (type)
7312 dw_die_ref base_type_result;
7313 const char *type_name;
7314 enum dwarf_type encoding;
7315 tree name = TYPE_NAME (type);
7317 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7322 if (TREE_CODE (name) == TYPE_DECL)
7323 name = DECL_NAME (name);
7325 type_name = IDENTIFIER_POINTER (name);
7328 type_name = "__unknown__";
7330 switch (TREE_CODE (type))
7333 /* Carefully distinguish the C character types, without messing
7334 up if the language is not C. Note that we check only for the names
7335 that contain spaces; other names might occur by coincidence in other
7337 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7338 && (type == char_type_node
7339 || ! strcmp (type_name, "signed char")
7340 || ! strcmp (type_name, "unsigned char"))))
7342 if (TREE_UNSIGNED (type))
7343 encoding = DW_ATE_unsigned;
7345 encoding = DW_ATE_signed;
7348 /* else fall through. */
7351 /* GNU Pascal/Ada CHAR type. Not used in C. */
7352 if (TREE_UNSIGNED (type))
7353 encoding = DW_ATE_unsigned_char;
7355 encoding = DW_ATE_signed_char;
7359 encoding = DW_ATE_float;
7362 /* Dwarf2 doesn't know anything about complex ints, so use
7363 a user defined type for it. */
7365 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7366 encoding = DW_ATE_complex_float;
7368 encoding = DW_ATE_lo_user;
7372 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7373 encoding = DW_ATE_boolean;
7377 /* No other TREE_CODEs are Dwarf fundamental types. */
7381 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
7382 if (demangle_name_func)
7383 type_name = (*demangle_name_func) (type_name);
7385 add_AT_string (base_type_result, DW_AT_name, type_name);
7386 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7387 int_size_in_bytes (type));
7388 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7390 return base_type_result;
7393 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7394 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7395 a given type is generally the same as the given type, except that if the
7396 given type is a pointer or reference type, then the root type of the given
7397 type is the root type of the "basis" type for the pointer or reference
7398 type. (This definition of the "root" type is recursive.) Also, the root
7399 type of a `const' qualified type or a `volatile' qualified type is the
7400 root type of the given type without the qualifiers. */
7406 if (TREE_CODE (type) == ERROR_MARK)
7407 return error_mark_node;
7409 switch (TREE_CODE (type))
7412 return error_mark_node;
7415 case REFERENCE_TYPE:
7416 return type_main_variant (root_type (TREE_TYPE (type)));
7419 return type_main_variant (type);
7423 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7424 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7430 switch (TREE_CODE (type))
7445 case QUAL_UNION_TYPE:
7450 case REFERENCE_TYPE:
7464 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7465 entry that chains various modifiers in front of the given type. */
7468 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7471 int is_volatile_type;
7472 dw_die_ref context_die;
7474 enum tree_code code = TREE_CODE (type);
7475 dw_die_ref mod_type_die = NULL;
7476 dw_die_ref sub_die = NULL;
7477 tree item_type = NULL;
7479 if (code != ERROR_MARK)
7481 tree qualified_type;
7483 /* See if we already have the appropriately qualified variant of
7486 = get_qualified_type (type,
7487 ((is_const_type ? TYPE_QUAL_CONST : 0)
7489 ? TYPE_QUAL_VOLATILE : 0)));
7491 /* If we do, then we can just use its DIE, if it exists. */
7494 mod_type_die = lookup_type_die (qualified_type);
7496 return mod_type_die;
7499 /* Handle C typedef types. */
7500 if (qualified_type && TYPE_NAME (qualified_type)
7501 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7502 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7504 tree type_name = TYPE_NAME (qualified_type);
7505 tree dtype = TREE_TYPE (type_name);
7507 if (qualified_type == dtype)
7509 /* For a named type, use the typedef. */
7510 gen_type_die (qualified_type, context_die);
7511 mod_type_die = lookup_type_die (qualified_type);
7513 else if (is_const_type < TYPE_READONLY (dtype)
7514 || is_volatile_type < TYPE_VOLATILE (dtype))
7515 /* cv-unqualified version of named type. Just use the unnamed
7516 type to which it refers. */
7518 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7519 is_const_type, is_volatile_type,
7522 /* Else cv-qualified version of named type; fall through. */
7528 else if (is_const_type)
7530 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
7531 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7533 else if (is_volatile_type)
7535 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
7536 sub_die = modified_type_die (type, 0, 0, context_die);
7538 else if (code == POINTER_TYPE)
7540 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
7541 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7543 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7545 item_type = TREE_TYPE (type);
7547 else if (code == REFERENCE_TYPE)
7549 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
7550 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7552 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7554 item_type = TREE_TYPE (type);
7556 else if (is_base_type (type))
7557 mod_type_die = base_type_die (type);
7560 gen_type_die (type, context_die);
7562 /* We have to get the type_main_variant here (and pass that to the
7563 `lookup_type_die' routine) because the ..._TYPE node we have
7564 might simply be a *copy* of some original type node (where the
7565 copy was created to help us keep track of typedef names) and
7566 that copy might have a different TYPE_UID from the original
7568 if (TREE_CODE (type) != VECTOR_TYPE)
7569 mod_type_die = lookup_type_die (type_main_variant (type));
7571 /* Vectors have the debugging information in the type,
7572 not the main variant. */
7573 mod_type_die = lookup_type_die (type);
7574 if (mod_type_die == NULL)
7578 /* We want to equate the qualified type to the die below. */
7580 type = qualified_type;
7583 equate_type_number_to_die (type, mod_type_die);
7585 /* We must do this after the equate_type_number_to_die call, in case
7586 this is a recursive type. This ensures that the modified_type_die
7587 recursion will terminate even if the type is recursive. Recursive
7588 types are possible in Ada. */
7589 sub_die = modified_type_die (item_type,
7590 TYPE_READONLY (item_type),
7591 TYPE_VOLATILE (item_type),
7594 if (sub_die != NULL)
7595 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7597 return mod_type_die;
7600 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7601 an enumerated type. */
7607 return TREE_CODE (type) == ENUMERAL_TYPE;
7610 /* Return the register number described by a given RTL node. */
7616 unsigned regno = REGNO (rtl);
7618 if (regno >= FIRST_PSEUDO_REGISTER)
7621 return DBX_REGISTER_NUMBER (regno);
7624 /* Return a location descriptor that designates a machine register or
7625 zero if there is no such. */
7627 static dw_loc_descr_ref
7628 reg_loc_descriptor (rtl)
7631 dw_loc_descr_ref loc_result = NULL;
7634 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7637 reg = reg_number (rtl);
7639 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7641 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7646 /* Return a location descriptor that designates a constant. */
7648 static dw_loc_descr_ref
7649 int_loc_descriptor (i)
7652 enum dwarf_location_atom op;
7654 /* Pick the smallest representation of a constant, rather than just
7655 defaulting to the LEB encoding. */
7659 op = DW_OP_lit0 + i;
7662 else if (i <= 0xffff)
7664 else if (HOST_BITS_PER_WIDE_INT == 32
7674 else if (i >= -0x8000)
7676 else if (HOST_BITS_PER_WIDE_INT == 32
7677 || i >= -0x80000000)
7683 return new_loc_descr (op, i, 0);
7686 /* Return a location descriptor that designates a base+offset location. */
7688 static dw_loc_descr_ref
7689 based_loc_descr (reg, offset)
7693 dw_loc_descr_ref loc_result;
7694 /* For the "frame base", we use the frame pointer or stack pointer
7695 registers, since the RTL for local variables is relative to one of
7697 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7698 ? HARD_FRAME_POINTER_REGNUM
7699 : STACK_POINTER_REGNUM);
7702 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7704 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7706 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7711 /* Return true if this RTL expression describes a base+offset calculation. */
7717 return (GET_CODE (rtl) == PLUS
7718 && ((GET_CODE (XEXP (rtl, 0)) == REG
7719 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
7720 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7723 /* The following routine converts the RTL for a variable or parameter
7724 (resident in memory) into an equivalent Dwarf representation of a
7725 mechanism for getting the address of that same variable onto the top of a
7726 hypothetical "address evaluation" stack.
7728 When creating memory location descriptors, we are effectively transforming
7729 the RTL for a memory-resident object into its Dwarf postfix expression
7730 equivalent. This routine recursively descends an RTL tree, turning
7731 it into Dwarf postfix code as it goes.
7733 MODE is the mode of the memory reference, needed to handle some
7734 autoincrement addressing modes.
7736 Return 0 if we can't represent the location. */
7738 static dw_loc_descr_ref
7739 mem_loc_descriptor (rtl, mode)
7741 enum machine_mode mode;
7743 dw_loc_descr_ref mem_loc_result = NULL;
7745 /* Note that for a dynamically sized array, the location we will generate a
7746 description of here will be the lowest numbered location which is
7747 actually within the array. That's *not* necessarily the same as the
7748 zeroth element of the array. */
7750 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7751 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7754 switch (GET_CODE (rtl))
7759 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7760 just fall into the SUBREG code. */
7762 /* ... fall through ... */
7765 /* The case of a subreg may arise when we have a local (register)
7766 variable or a formal (register) parameter which doesn't quite fill
7767 up an entire register. For now, just assume that it is
7768 legitimate to make the Dwarf info refer to the whole register which
7769 contains the given subreg. */
7770 rtl = SUBREG_REG (rtl);
7772 /* ... fall through ... */
7775 /* Whenever a register number forms a part of the description of the
7776 method for calculating the (dynamic) address of a memory resident
7777 object, DWARF rules require the register number be referred to as
7778 a "base register". This distinction is not based in any way upon
7779 what category of register the hardware believes the given register
7780 belongs to. This is strictly DWARF terminology we're dealing with
7781 here. Note that in cases where the location of a memory-resident
7782 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7783 OP_CONST (0)) the actual DWARF location descriptor that we generate
7784 may just be OP_BASEREG (basereg). This may look deceptively like
7785 the object in question was allocated to a register (rather than in
7786 memory) so DWARF consumers need to be aware of the subtle
7787 distinction between OP_REG and OP_BASEREG. */
7788 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
7789 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7793 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7794 if (mem_loc_result != 0)
7795 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7799 /* Some ports can transform a symbol ref into a label ref, because
7800 the symbol ref is too far away and has to be dumped into a constant
7804 /* Alternatively, the symbol in the constant pool might be referenced
7805 by a different symbol. */
7806 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
7809 rtx tmp = get_pool_constant_mark (rtl, &marked);
7811 if (GET_CODE (tmp) == SYMBOL_REF)
7814 if (CONSTANT_POOL_ADDRESS_P (tmp))
7815 get_pool_constant_mark (tmp, &marked);
7820 /* If all references to this pool constant were optimized away,
7821 it was not output and thus we can't represent it.
7822 FIXME: might try to use DW_OP_const_value here, though
7823 DW_OP_piece complicates it. */
7828 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7829 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7830 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
7831 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
7835 /* Extract the PLUS expression nested inside and fall into
7837 rtl = XEXP (rtl, 1);
7842 /* Turn these into a PLUS expression and fall into the PLUS code
7844 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7845 GEN_INT (GET_CODE (rtl) == PRE_INC
7846 ? GET_MODE_UNIT_SIZE (mode)
7847 : -GET_MODE_UNIT_SIZE (mode)));
7849 /* ... fall through ... */
7853 if (is_based_loc (rtl))
7854 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7855 INTVAL (XEXP (rtl, 1)));
7858 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7859 if (mem_loc_result == 0)
7862 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7863 && INTVAL (XEXP (rtl, 1)) >= 0)
7864 add_loc_descr (&mem_loc_result,
7865 new_loc_descr (DW_OP_plus_uconst,
7866 INTVAL (XEXP (rtl, 1)), 0));
7869 add_loc_descr (&mem_loc_result,
7870 mem_loc_descriptor (XEXP (rtl, 1), mode));
7871 add_loc_descr (&mem_loc_result,
7872 new_loc_descr (DW_OP_plus, 0, 0));
7879 /* If a pseudo-reg is optimized away, it is possible for it to
7880 be replaced with a MEM containing a multiply. */
7881 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
7882 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
7884 if (op0 == 0 || op1 == 0)
7887 mem_loc_result = op0;
7888 add_loc_descr (&mem_loc_result, op1);
7889 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7894 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7898 /* If this is a MEM, return its address. Otherwise, we can't
7900 if (GET_CODE (XEXP (rtl, 0)) == MEM)
7901 return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode);
7909 return mem_loc_result;
7912 /* Return a descriptor that describes the concatenation of two locations.
7913 This is typically a complex variable. */
7915 static dw_loc_descr_ref
7916 concat_loc_descriptor (x0, x1)
7919 dw_loc_descr_ref cc_loc_result = NULL;
7920 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
7921 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
7923 if (x0_ref == 0 || x1_ref == 0)
7926 cc_loc_result = x0_ref;
7927 add_loc_descr (&cc_loc_result,
7928 new_loc_descr (DW_OP_piece,
7929 GET_MODE_SIZE (GET_MODE (x0)), 0));
7931 add_loc_descr (&cc_loc_result, x1_ref);
7932 add_loc_descr (&cc_loc_result,
7933 new_loc_descr (DW_OP_piece,
7934 GET_MODE_SIZE (GET_MODE (x1)), 0));
7936 return cc_loc_result;
7939 /* Output a proper Dwarf location descriptor for a variable or parameter
7940 which is either allocated in a register or in a memory location. For a
7941 register, we just generate an OP_REG and the register number. For a
7942 memory location we provide a Dwarf postfix expression describing how to
7943 generate the (dynamic) address of the object onto the address stack.
7945 If we don't know how to describe it, return 0. */
7947 static dw_loc_descr_ref
7948 loc_descriptor (rtl)
7951 dw_loc_descr_ref loc_result = NULL;
7953 switch (GET_CODE (rtl))
7956 /* The case of a subreg may arise when we have a local (register)
7957 variable or a formal (register) parameter which doesn't quite fill
7958 up an entire register. For now, just assume that it is
7959 legitimate to make the Dwarf info refer to the whole register which
7960 contains the given subreg. */
7961 rtl = SUBREG_REG (rtl);
7963 /* ... fall through ... */
7966 loc_result = reg_loc_descriptor (rtl);
7970 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7974 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7984 /* Similar, but generate the descriptor from trees instead of rtl. This comes
7985 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
7986 looking for an address. Otherwise, we return a value. If we can't make a
7987 descriptor, return 0. */
7989 static dw_loc_descr_ref
7990 loc_descriptor_from_tree (loc, addressp)
7994 dw_loc_descr_ref ret, ret1;
7996 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7997 enum dwarf_location_atom op;
7999 /* ??? Most of the time we do not take proper care for sign/zero
8000 extending the values properly. Hopefully this won't be a real
8003 switch (TREE_CODE (loc))
8008 case WITH_RECORD_EXPR:
8009 case PLACEHOLDER_EXPR:
8010 /* This case involves extracting fields from an object to determine the
8011 position of other fields. We don't try to encode this here. The
8012 only user of this is Ada, which encodes the needed information using
8013 the names of types. */
8020 /* We can support this only if we can look through conversions and
8021 find an INDIRECT_EXPR. */
8022 for (loc = TREE_OPERAND (loc, 0);
8023 TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR
8024 || TREE_CODE (loc) == NON_LVALUE_EXPR
8025 || TREE_CODE (loc) == VIEW_CONVERT_EXPR
8026 || TREE_CODE (loc) == SAVE_EXPR;
8027 loc = TREE_OPERAND (loc, 0))
8030 return (TREE_CODE (loc) == INDIRECT_REF
8031 ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp)
8037 rtx rtl = rtl_for_decl_location (loc);
8039 if (rtl == NULL_RTX)
8041 else if (CONSTANT_P (rtl))
8043 ret = new_loc_descr (DW_OP_addr, 0, 0);
8044 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8045 ret->dw_loc_oprnd1.v.val_addr = rtl;
8050 enum machine_mode mode = GET_MODE (rtl);
8052 if (GET_CODE (rtl) == MEM)
8055 rtl = XEXP (rtl, 0);
8058 ret = mem_loc_descriptor (rtl, mode);
8064 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8069 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
8073 case NON_LVALUE_EXPR:
8074 case VIEW_CONVERT_EXPR:
8076 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8081 case ARRAY_RANGE_REF:
8084 HOST_WIDE_INT bitsize, bitpos, bytepos;
8085 enum machine_mode mode;
8088 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8089 &unsignedp, &volatilep);
8094 ret = loc_descriptor_from_tree (obj, 1);
8096 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
8099 if (offset != NULL_TREE)
8101 /* Variable offset. */
8102 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8103 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8109 bytepos = bitpos / BITS_PER_UNIT;
8111 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8112 else if (bytepos < 0)
8114 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8115 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8121 if (host_integerp (loc, 0))
8122 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8127 case TRUTH_AND_EXPR:
8128 case TRUTH_ANDIF_EXPR:
8133 case TRUTH_XOR_EXPR:
8139 case TRUTH_ORIF_EXPR:
8144 case TRUNC_DIV_EXPR:
8152 case TRUNC_MOD_EXPR:
8165 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8169 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8170 && host_integerp (TREE_OPERAND (loc, 1), 0))
8172 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8176 add_loc_descr (&ret,
8177 new_loc_descr (DW_OP_plus_uconst,
8178 tree_low_cst (TREE_OPERAND (loc, 1),
8188 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8195 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8202 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8209 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8224 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8225 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8226 if (ret == 0 || ret1 == 0)
8229 add_loc_descr (&ret, ret1);
8230 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8233 case TRUTH_NOT_EXPR:
8247 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8251 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8255 loc = build (COND_EXPR, TREE_TYPE (loc),
8256 build (LT_EXPR, integer_type_node,
8257 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8258 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8260 /* ... fall through ... */
8264 dw_loc_descr_ref lhs
8265 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8266 dw_loc_descr_ref rhs
8267 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8268 dw_loc_descr_ref bra_node, jump_node, tmp;
8270 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8271 if (ret == 0 || lhs == 0 || rhs == 0)
8274 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8275 add_loc_descr (&ret, bra_node);
8277 add_loc_descr (&ret, rhs);
8278 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8279 add_loc_descr (&ret, jump_node);
8281 add_loc_descr (&ret, lhs);
8282 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8283 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
8285 /* ??? Need a node to point the skip at. Use a nop. */
8286 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8287 add_loc_descr (&ret, tmp);
8288 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8289 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8297 /* Show if we can't fill the request for an address. */
8298 if (addressp && indirect_p == 0)
8301 /* If we've got an address and don't want one, dereference. */
8302 if (!addressp && indirect_p > 0)
8304 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8306 if (size > DWARF2_ADDR_SIZE || size == -1)
8308 else if (size == DWARF2_ADDR_SIZE)
8311 op = DW_OP_deref_size;
8313 add_loc_descr (&ret, new_loc_descr (op, size, 0));
8319 /* Given a value, round it up to the lowest multiple of `boundary'
8320 which is not less than the value itself. */
8322 static inline HOST_WIDE_INT
8323 ceiling (value, boundary)
8324 HOST_WIDE_INT value;
8325 unsigned int boundary;
8327 return (((value + boundary - 1) / boundary) * boundary);
8330 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8331 pointer to the declared type for the relevant field variable, or return
8332 `integer_type_node' if the given node turns out to be an
8341 if (TREE_CODE (decl) == ERROR_MARK)
8342 return integer_type_node;
8344 type = DECL_BIT_FIELD_TYPE (decl);
8345 if (type == NULL_TREE)
8346 type = TREE_TYPE (decl);
8351 /* Given a pointer to a tree node, return the alignment in bits for
8352 it, or else return BITS_PER_WORD if the node actually turns out to
8353 be an ERROR_MARK node. */
8355 static inline unsigned
8356 simple_type_align_in_bits (type)
8359 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8362 static inline unsigned
8363 simple_decl_align_in_bits (decl)
8366 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8369 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8370 node, return the size in bits for the type if it is a constant, or else
8371 return the alignment for the type if the type's size is not constant, or
8372 else return BITS_PER_WORD if the type actually turns out to be an
8375 static inline unsigned HOST_WIDE_INT
8376 simple_type_size_in_bits (type)
8380 if (TREE_CODE (type) == ERROR_MARK)
8381 return BITS_PER_WORD;
8382 else if (TYPE_SIZE (type) == NULL_TREE)
8384 else if (host_integerp (TYPE_SIZE (type), 1))
8385 return tree_low_cst (TYPE_SIZE (type), 1);
8387 return TYPE_ALIGN (type);
8390 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8391 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8392 or return 0 if we are unable to determine what that offset is, either
8393 because the argument turns out to be a pointer to an ERROR_MARK node, or
8394 because the offset is actually variable. (We can't handle the latter case
8397 static HOST_WIDE_INT
8398 field_byte_offset (decl)
8401 unsigned int type_align_in_bits;
8402 unsigned int decl_align_in_bits;
8403 unsigned HOST_WIDE_INT type_size_in_bits;
8404 HOST_WIDE_INT object_offset_in_bits;
8406 tree field_size_tree;
8407 HOST_WIDE_INT bitpos_int;
8408 HOST_WIDE_INT deepest_bitpos;
8409 unsigned HOST_WIDE_INT field_size_in_bits;
8411 if (TREE_CODE (decl) == ERROR_MARK)
8413 else if (TREE_CODE (decl) != FIELD_DECL)
8416 type = field_type (decl);
8417 field_size_tree = DECL_SIZE (decl);
8419 /* The size could be unspecified if there was an error, or for
8420 a flexible array member. */
8421 if (! field_size_tree)
8422 field_size_tree = bitsize_zero_node;
8424 /* We cannot yet cope with fields whose positions are variable, so
8425 for now, when we see such things, we simply return 0. Someday, we may
8426 be able to handle such cases, but it will be damn difficult. */
8427 if (! host_integerp (bit_position (decl), 0))
8430 bitpos_int = int_bit_position (decl);
8432 /* If we don't know the size of the field, pretend it's a full word. */
8433 if (host_integerp (field_size_tree, 1))
8434 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8436 field_size_in_bits = BITS_PER_WORD;
8438 type_size_in_bits = simple_type_size_in_bits (type);
8439 type_align_in_bits = simple_type_align_in_bits (type);
8440 decl_align_in_bits = simple_decl_align_in_bits (decl);
8442 /* The GCC front-end doesn't make any attempt to keep track of the starting
8443 bit offset (relative to the start of the containing structure type) of the
8444 hypothetical "containing object" for a bit-field. Thus, when computing
8445 the byte offset value for the start of the "containing object" of a
8446 bit-field, we must deduce this information on our own. This can be rather
8447 tricky to do in some cases. For example, handling the following structure
8448 type definition when compiling for an i386/i486 target (which only aligns
8449 long long's to 32-bit boundaries) can be very tricky:
8451 struct S { int field1; long long field2:31; };
8453 Fortunately, there is a simple rule-of-thumb which can be used in such
8454 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8455 structure shown above. It decides to do this based upon one simple rule
8456 for bit-field allocation. GCC allocates each "containing object" for each
8457 bit-field at the first (i.e. lowest addressed) legitimate alignment
8458 boundary (based upon the required minimum alignment for the declared type
8459 of the field) which it can possibly use, subject to the condition that
8460 there is still enough available space remaining in the containing object
8461 (when allocated at the selected point) to fully accommodate all of the
8462 bits of the bit-field itself.
8464 This simple rule makes it obvious why GCC allocates 8 bytes for each
8465 object of the structure type shown above. When looking for a place to
8466 allocate the "containing object" for `field2', the compiler simply tries
8467 to allocate a 64-bit "containing object" at each successive 32-bit
8468 boundary (starting at zero) until it finds a place to allocate that 64-
8469 bit field such that at least 31 contiguous (and previously unallocated)
8470 bits remain within that selected 64 bit field. (As it turns out, for the
8471 example above, the compiler finds it is OK to allocate the "containing
8472 object" 64-bit field at bit-offset zero within the structure type.)
8474 Here we attempt to work backwards from the limited set of facts we're
8475 given, and we try to deduce from those facts, where GCC must have believed
8476 that the containing object started (within the structure type). The value
8477 we deduce is then used (by the callers of this routine) to generate
8478 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8479 and, in the case of DW_AT_location, regular fields as well). */
8481 /* Figure out the bit-distance from the start of the structure to the
8482 "deepest" bit of the bit-field. */
8483 deepest_bitpos = bitpos_int + field_size_in_bits;
8485 /* This is the tricky part. Use some fancy footwork to deduce where the
8486 lowest addressed bit of the containing object must be. */
8487 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8489 /* Round up to type_align by default. This works best for bitfields. */
8490 object_offset_in_bits += type_align_in_bits - 1;
8491 object_offset_in_bits /= type_align_in_bits;
8492 object_offset_in_bits *= type_align_in_bits;
8494 if (object_offset_in_bits > bitpos_int)
8496 /* Sigh, the decl must be packed. */
8497 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8499 /* Round up to decl_align instead. */
8500 object_offset_in_bits += decl_align_in_bits - 1;
8501 object_offset_in_bits /= decl_align_in_bits;
8502 object_offset_in_bits *= decl_align_in_bits;
8505 return object_offset_in_bits / BITS_PER_UNIT;
8508 /* The following routines define various Dwarf attributes and any data
8509 associated with them. */
8511 /* Add a location description attribute value to a DIE.
8513 This emits location attributes suitable for whole variables and
8514 whole parameters. Note that the location attributes for struct fields are
8515 generated by the routine `data_member_location_attribute' below. */
8518 add_AT_location_description (die, attr_kind, rtl)
8520 enum dwarf_attribute attr_kind;
8523 dw_loc_descr_ref descr = loc_descriptor (rtl);
8526 add_AT_loc (die, attr_kind, descr);
8529 /* Attach the specialized form of location attribute used for data members of
8530 struct and union types. In the special case of a FIELD_DECL node which
8531 represents a bit-field, the "offset" part of this special location
8532 descriptor must indicate the distance in bytes from the lowest-addressed
8533 byte of the containing struct or union type to the lowest-addressed byte of
8534 the "containing object" for the bit-field. (See the `field_byte_offset'
8537 For any given bit-field, the "containing object" is a hypothetical object
8538 (of some integral or enum type) within which the given bit-field lives. The
8539 type of this hypothetical "containing object" is always the same as the
8540 declared type of the individual bit-field itself (for GCC anyway... the
8541 DWARF spec doesn't actually mandate this). Note that it is the size (in
8542 bytes) of the hypothetical "containing object" which will be given in the
8543 DW_AT_byte_size attribute for this bit-field. (See the
8544 `byte_size_attribute' function below.) It is also used when calculating the
8545 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8549 add_data_member_location_attribute (die, decl)
8554 dw_loc_descr_ref loc_descr = 0;
8556 if (TREE_CODE (decl) == TREE_VEC)
8558 /* We're working on the TAG_inheritance for a base class. */
8559 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
8561 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8562 aren't at a fixed offset from all (sub)objects of the same
8563 type. We need to extract the appropriate offset from our
8564 vtable. The following dwarf expression means
8566 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8568 This is specific to the V3 ABI, of course. */
8570 dw_loc_descr_ref tmp;
8572 /* Make a copy of the object address. */
8573 tmp = new_loc_descr (DW_OP_dup, 0, 0);
8574 add_loc_descr (&loc_descr, tmp);
8576 /* Extract the vtable address. */
8577 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8578 add_loc_descr (&loc_descr, tmp);
8580 /* Calculate the address of the offset. */
8581 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
8585 tmp = int_loc_descriptor (-offset);
8586 add_loc_descr (&loc_descr, tmp);
8587 tmp = new_loc_descr (DW_OP_minus, 0, 0);
8588 add_loc_descr (&loc_descr, tmp);
8590 /* Extract the offset. */
8591 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8592 add_loc_descr (&loc_descr, tmp);
8594 /* Add it to the object address. */
8595 tmp = new_loc_descr (DW_OP_plus, 0, 0);
8596 add_loc_descr (&loc_descr, tmp);
8599 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8602 offset = field_byte_offset (decl);
8606 enum dwarf_location_atom op;
8608 /* The DWARF2 standard says that we should assume that the structure
8609 address is already on the stack, so we can specify a structure field
8610 address by using DW_OP_plus_uconst. */
8612 #ifdef MIPS_DEBUGGING_INFO
8613 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8614 operator correctly. It works only if we leave the offset on the
8618 op = DW_OP_plus_uconst;
8621 loc_descr = new_loc_descr (op, offset, 0);
8624 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8627 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8628 does not have a "location" either in memory or in a register. These
8629 things can arise in GNU C when a constant is passed as an actual parameter
8630 to an inlined function. They can also arise in C++ where declared
8631 constants do not necessarily get memory "homes". */
8634 add_const_value_attribute (die, rtl)
8638 switch (GET_CODE (rtl))
8641 /* Note that a CONST_INT rtx could represent either an integer
8642 or a floating-point constant. A CONST_INT is used whenever
8643 the constant will fit into a single word. In all such
8644 cases, the original mode of the constant value is wiped
8645 out, and the CONST_INT rtx is assigned VOIDmode. */
8647 HOST_WIDE_INT val = INTVAL (rtl);
8649 /* ??? We really should be using HOST_WIDE_INT throughout. */
8650 if (val < 0 && (long) val == val)
8651 add_AT_int (die, DW_AT_const_value, (long) val);
8652 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
8653 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8656 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8657 add_AT_long_long (die, DW_AT_const_value,
8658 val >> HOST_BITS_PER_LONG, val);
8667 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8668 floating-point constant. A CONST_DOUBLE is used whenever the
8669 constant requires more than one word in order to be adequately
8670 represented. We output CONST_DOUBLEs as blocks. */
8672 enum machine_mode mode = GET_MODE (rtl);
8674 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8676 unsigned length = GET_MODE_SIZE (mode) / 4;
8677 long *array = (long *) xmalloc (sizeof (long) * length);
8680 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8684 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8688 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8693 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8700 add_AT_float (die, DW_AT_const_value, length, array);
8704 /* ??? We really should be using HOST_WIDE_INT throughout. */
8705 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8708 add_AT_long_long (die, DW_AT_const_value,
8709 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8715 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8721 add_AT_addr (die, DW_AT_const_value, rtl);
8722 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
8726 /* In cases where an inlined instance of an inline function is passed
8727 the address of an `auto' variable (which is local to the caller) we
8728 can get a situation where the DECL_RTL of the artificial local
8729 variable (for the inlining) which acts as a stand-in for the
8730 corresponding formal parameter (of the inline function) will look
8731 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8732 exactly a compile-time constant expression, but it isn't the address
8733 of the (artificial) local variable either. Rather, it represents the
8734 *value* which the artificial local variable always has during its
8735 lifetime. We currently have no way to represent such quasi-constant
8736 values in Dwarf, so for now we just punt and generate nothing. */
8740 /* No other kinds of rtx should be possible here. */
8747 rtl_for_decl_location (decl)
8752 /* Here we have to decide where we are going to say the parameter "lives"
8753 (as far as the debugger is concerned). We only have a couple of
8754 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8756 DECL_RTL normally indicates where the parameter lives during most of the
8757 activation of the function. If optimization is enabled however, this
8758 could be either NULL or else a pseudo-reg. Both of those cases indicate
8759 that the parameter doesn't really live anywhere (as far as the code
8760 generation parts of GCC are concerned) during most of the function's
8761 activation. That will happen (for example) if the parameter is never
8762 referenced within the function.
8764 We could just generate a location descriptor here for all non-NULL
8765 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8766 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8767 where DECL_RTL is NULL or is a pseudo-reg.
8769 Note however that we can only get away with using DECL_INCOMING_RTL as
8770 a backup substitute for DECL_RTL in certain limited cases. In cases
8771 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8772 we can be sure that the parameter was passed using the same type as it is
8773 declared to have within the function, and that its DECL_INCOMING_RTL
8774 points us to a place where a value of that type is passed.
8776 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8777 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8778 because in these cases DECL_INCOMING_RTL points us to a value of some
8779 type which is *different* from the type of the parameter itself. Thus,
8780 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8781 such cases, the debugger would end up (for example) trying to fetch a
8782 `float' from a place which actually contains the first part of a
8783 `double'. That would lead to really incorrect and confusing
8784 output at debug-time.
8786 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8787 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8788 are a couple of exceptions however. On little-endian machines we can
8789 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8790 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8791 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8792 when (on a little-endian machine) a non-prototyped function has a
8793 parameter declared to be of type `short' or `char'. In such cases,
8794 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8795 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8796 passed `int' value. If the debugger then uses that address to fetch
8797 a `short' or a `char' (on a little-endian machine) the result will be
8798 the correct data, so we allow for such exceptional cases below.
8800 Note that our goal here is to describe the place where the given formal
8801 parameter lives during most of the function's activation (i.e. between the
8802 end of the prologue and the start of the epilogue). We'll do that as best
8803 as we can. Note however that if the given formal parameter is modified
8804 sometime during the execution of the function, then a stack backtrace (at
8805 debug-time) will show the function as having been called with the *new*
8806 value rather than the value which was originally passed in. This happens
8807 rarely enough that it is not a major problem, but it *is* a problem, and
8810 A future version of dwarf2out.c may generate two additional attributes for
8811 any given DW_TAG_formal_parameter DIE which will describe the "passed
8812 type" and the "passed location" for the given formal parameter in addition
8813 to the attributes we now generate to indicate the "declared type" and the
8814 "active location" for each parameter. This additional set of attributes
8815 could be used by debuggers for stack backtraces. Separately, note that
8816 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8817 This happens (for example) for inlined-instances of inline function formal
8818 parameters which are never referenced. This really shouldn't be
8819 happening. All PARM_DECL nodes should get valid non-NULL
8820 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8821 values for inlined instances of inline function parameters, so when we see
8822 such cases, we are just out-of-luck for the time being (until integrate.c
8825 /* Use DECL_RTL as the "location" unless we find something better. */
8826 rtl = DECL_RTL_IF_SET (decl);
8828 /* When generating abstract instances, ignore everything except
8829 constants and symbols living in memory. */
8830 if (! reload_completed)
8833 && (CONSTANT_P (rtl)
8834 || (GET_CODE (rtl) == MEM
8835 && CONSTANT_P (XEXP (rtl, 0)))))
8839 else if (TREE_CODE (decl) == PARM_DECL)
8841 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8843 tree declared_type = type_main_variant (TREE_TYPE (decl));
8844 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8846 /* This decl represents a formal parameter which was optimized out.
8847 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8848 all cases where (rtl == NULL_RTX) just below. */
8849 if (declared_type == passed_type)
8850 rtl = DECL_INCOMING_RTL (decl);
8851 else if (! BYTES_BIG_ENDIAN
8852 && TREE_CODE (declared_type) == INTEGER_TYPE
8853 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8854 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8855 rtl = DECL_INCOMING_RTL (decl);
8858 /* If the parm was passed in registers, but lives on the stack, then
8859 make a big endian correction if the mode of the type of the
8860 parameter is not the same as the mode of the rtl. */
8861 /* ??? This is the same series of checks that are made in dbxout.c before
8862 we reach the big endian correction code there. It isn't clear if all
8863 of these checks are necessary here, but keeping them all is the safe
8865 else if (GET_CODE (rtl) == MEM
8866 && XEXP (rtl, 0) != const0_rtx
8867 && ! CONSTANT_P (XEXP (rtl, 0))
8868 /* Not passed in memory. */
8869 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8870 /* Not passed by invisible reference. */
8871 && (GET_CODE (XEXP (rtl, 0)) != REG
8872 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8873 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8874 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8875 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8878 /* Big endian correction check. */
8880 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8881 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8884 int offset = (UNITS_PER_WORD
8885 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8887 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8888 plus_constant (XEXP (rtl, 0), offset));
8892 if (rtl != NULL_RTX)
8894 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8895 #ifdef LEAF_REG_REMAP
8896 if (current_function_uses_only_leaf_regs)
8897 leaf_renumber_regs_insn (rtl);
8901 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8902 and will have been substituted directly into all expressions that use it.
8903 C does not have such a concept, but C++ and other languages do. */
8904 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
8905 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
8906 EXPAND_INITIALIZER);
8911 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8912 data attribute for a variable or a parameter. We generate the
8913 DW_AT_const_value attribute only in those cases where the given variable
8914 or parameter does not have a true "location" either in memory or in a
8915 register. This can happen (for example) when a constant is passed as an
8916 actual argument in a call to an inline function. (It's possible that
8917 these things can crop up in other ways also.) Note that one type of
8918 constant value which can be passed into an inlined function is a constant
8919 pointer. This can happen for example if an actual argument in an inlined
8920 function call evaluates to a compile-time constant address. */
8923 add_location_or_const_value_attribute (die, decl)
8929 if (TREE_CODE (decl) == ERROR_MARK)
8931 else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8934 rtl = rtl_for_decl_location (decl);
8935 if (rtl == NULL_RTX)
8938 /* If we don't look past the constant pool, we risk emitting a
8939 reference to a constant pool entry that isn't referenced from
8940 code, and thus is not emitted. */
8941 rtl = avoid_constant_pool_reference (rtl);
8943 switch (GET_CODE (rtl))
8946 /* The address of a variable that was optimized away; don't emit
8957 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8958 add_const_value_attribute (die, rtl);
8965 add_AT_location_description (die, DW_AT_location, rtl);
8973 /* If we don't have a copy of this variable in memory for some reason (such
8974 as a C++ member constant that doesn't have an out-of-line definition),
8975 we should tell the debugger about the constant value. */
8978 tree_add_const_value_attribute (var_die, decl)
8982 tree init = DECL_INITIAL (decl);
8983 tree type = TREE_TYPE (decl);
8985 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8986 && initializer_constant_valid_p (init, type) == null_pointer_node)
8991 switch (TREE_CODE (type))
8994 if (host_integerp (init, 0))
8995 add_AT_unsigned (var_die, DW_AT_const_value,
8996 tree_low_cst (init, 0));
8998 add_AT_long_long (var_die, DW_AT_const_value,
8999 TREE_INT_CST_HIGH (init),
9000 TREE_INT_CST_LOW (init));
9007 /* Generate an DW_AT_name attribute given some string value to be included as
9008 the value of the attribute. */
9011 add_name_attribute (die, name_string)
9013 const char *name_string;
9015 if (name_string != NULL && *name_string != 0)
9017 if (demangle_name_func)
9018 name_string = (*demangle_name_func) (name_string);
9020 add_AT_string (die, DW_AT_name, name_string);
9024 /* Given a tree node describing an array bound (either lower or upper) output
9025 a representation for that bound. */
9028 add_bound_info (subrange_die, bound_attr, bound)
9029 dw_die_ref subrange_die;
9030 enum dwarf_attribute bound_attr;
9033 switch (TREE_CODE (bound))
9038 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9040 if (! host_integerp (bound, 0)
9041 || (bound_attr == DW_AT_lower_bound
9042 && (((is_c_family () || is_java ()) && integer_zerop (bound))
9043 || (is_fortran () && integer_onep (bound)))))
9044 /* use the default */
9047 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
9052 case NON_LVALUE_EXPR:
9053 case VIEW_CONVERT_EXPR:
9054 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
9058 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9059 access the upper bound values may be bogus. If they refer to a
9060 register, they may only describe how to get at these values at the
9061 points in the generated code right after they have just been
9062 computed. Worse yet, in the typical case, the upper bound values
9063 will not even *be* computed in the optimized code (though the
9064 number of elements will), so these SAVE_EXPRs are entirely
9065 bogus. In order to compensate for this fact, we check here to see
9066 if optimization is enabled, and if so, we don't add an attribute
9067 for the (unknown and unknowable) upper bound. This should not
9068 cause too much trouble for existing (stupid?) debuggers because
9069 they have to deal with empty upper bounds location descriptions
9070 anyway in order to be able to deal with incomplete array types.
9071 Of course an intelligent debugger (GDB?) should be able to
9072 comprehend that a missing upper bound specification in an array
9073 type used for a storage class `auto' local array variable
9074 indicates that the upper bound is both unknown (at compile- time)
9075 and unknowable (at run-time) due to optimization.
9077 We assume that a MEM rtx is safe because gcc wouldn't put the
9078 value there unless it was going to be used repeatedly in the
9079 function, i.e. for cleanups. */
9080 if (SAVE_EXPR_RTL (bound)
9081 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9083 dw_die_ref ctx = lookup_decl_die (current_function_decl);
9084 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound);
9085 rtx loc = SAVE_EXPR_RTL (bound);
9087 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9088 it references an outer function's frame. */
9089 if (GET_CODE (loc) == MEM)
9091 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9093 if (XEXP (loc, 0) != new_addr)
9094 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9097 add_AT_flag (decl_die, DW_AT_artificial, 1);
9098 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9099 add_AT_location_description (decl_die, DW_AT_location, loc);
9100 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9103 /* Else leave out the attribute. */
9109 dw_die_ref decl_die = lookup_decl_die (bound);
9111 /* ??? Can this happen, or should the variable have been bound
9112 first? Probably it can, since I imagine that we try to create
9113 the types of parameters in the order in which they exist in
9114 the list, and won't have created a forward reference to a
9116 if (decl_die != NULL)
9117 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9123 /* Otherwise try to create a stack operation procedure to
9124 evaluate the value of the array bound. */
9126 dw_die_ref ctx, decl_die;
9127 dw_loc_descr_ref loc;
9129 loc = loc_descriptor_from_tree (bound, 0);
9133 if (current_function_decl == 0)
9134 ctx = comp_unit_die;
9136 ctx = lookup_decl_die (current_function_decl);
9138 /* If we weren't able to find a context, it's most likely the case
9139 that we are processing the return type of the function. So
9140 make a SAVE_EXPR to point to it and have the limbo DIE code
9141 find the proper die. The save_expr function doesn't always
9142 make a SAVE_EXPR, so do it ourselves. */
9144 bound = build (SAVE_EXPR, TREE_TYPE (bound), bound,
9145 current_function_decl, NULL_TREE);
9147 decl_die = new_die (DW_TAG_variable, ctx, bound);
9148 add_AT_flag (decl_die, DW_AT_artificial, 1);
9149 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9150 add_AT_loc (decl_die, DW_AT_location, loc);
9152 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9158 /* Note that the block of subscript information for an array type also
9159 includes information about the element type of type given array type. */
9162 add_subscript_info (type_die, type)
9163 dw_die_ref type_die;
9166 #ifndef MIPS_DEBUGGING_INFO
9167 unsigned dimension_number;
9170 dw_die_ref subrange_die;
9172 /* The GNU compilers represent multidimensional array types as sequences of
9173 one dimensional array types whose element types are themselves array
9174 types. Here we squish that down, so that each multidimensional array
9175 type gets only one array_type DIE in the Dwarf debugging info. The draft
9176 Dwarf specification say that we are allowed to do this kind of
9177 compression in C (because there is no difference between an array or
9178 arrays and a multidimensional array in C) but for other source languages
9179 (e.g. Ada) we probably shouldn't do this. */
9181 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9182 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9183 We work around this by disabling this feature. See also
9184 gen_array_type_die. */
9185 #ifndef MIPS_DEBUGGING_INFO
9186 for (dimension_number = 0;
9187 TREE_CODE (type) == ARRAY_TYPE;
9188 type = TREE_TYPE (type), dimension_number++)
9191 tree domain = TYPE_DOMAIN (type);
9193 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9194 and (in GNU C only) variable bounds. Handle all three forms
9196 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
9199 /* We have an array type with specified bounds. */
9200 lower = TYPE_MIN_VALUE (domain);
9201 upper = TYPE_MAX_VALUE (domain);
9203 /* define the index type. */
9204 if (TREE_TYPE (domain))
9206 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9207 TREE_TYPE field. We can't emit debug info for this
9208 because it is an unnamed integral type. */
9209 if (TREE_CODE (domain) == INTEGER_TYPE
9210 && TYPE_NAME (domain) == NULL_TREE
9211 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9212 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9215 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9219 /* ??? If upper is NULL, the array has unspecified length,
9220 but it does have a lower bound. This happens with Fortran
9222 Since the debugger is definitely going to need to know N
9223 to produce useful results, go ahead and output the lower
9224 bound solo, and hope the debugger can cope. */
9226 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9228 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9231 /* Otherwise we have an array type with an unspecified length. The
9232 DWARF-2 spec does not say how to handle this; let's just leave out the
9238 add_byte_size_attribute (die, tree_node)
9244 switch (TREE_CODE (tree_node))
9252 case QUAL_UNION_TYPE:
9253 size = int_size_in_bytes (tree_node);
9256 /* For a data member of a struct or union, the DW_AT_byte_size is
9257 generally given as the number of bytes normally allocated for an
9258 object of the *declared* type of the member itself. This is true
9259 even for bit-fields. */
9260 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9266 /* Note that `size' might be -1 when we get to this point. If it is, that
9267 indicates that the byte size of the entity in question is variable. We
9268 have no good way of expressing this fact in Dwarf at the present time,
9269 so just let the -1 pass on through. */
9270 add_AT_unsigned (die, DW_AT_byte_size, size);
9273 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9274 which specifies the distance in bits from the highest order bit of the
9275 "containing object" for the bit-field to the highest order bit of the
9278 For any given bit-field, the "containing object" is a hypothetical object
9279 (of some integral or enum type) within which the given bit-field lives. The
9280 type of this hypothetical "containing object" is always the same as the
9281 declared type of the individual bit-field itself. The determination of the
9282 exact location of the "containing object" for a bit-field is rather
9283 complicated. It's handled by the `field_byte_offset' function (above).
9285 Note that it is the size (in bytes) of the hypothetical "containing object"
9286 which will be given in the DW_AT_byte_size attribute for this bit-field.
9287 (See `byte_size_attribute' above). */
9290 add_bit_offset_attribute (die, decl)
9294 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9295 tree type = DECL_BIT_FIELD_TYPE (decl);
9296 HOST_WIDE_INT bitpos_int;
9297 HOST_WIDE_INT highest_order_object_bit_offset;
9298 HOST_WIDE_INT highest_order_field_bit_offset;
9299 HOST_WIDE_INT unsigned bit_offset;
9301 /* Must be a field and a bit field. */
9303 || TREE_CODE (decl) != FIELD_DECL)
9306 /* We can't yet handle bit-fields whose offsets are variable, so if we
9307 encounter such things, just return without generating any attribute
9308 whatsoever. Likewise for variable or too large size. */
9309 if (! host_integerp (bit_position (decl), 0)
9310 || ! host_integerp (DECL_SIZE (decl), 1))
9313 bitpos_int = int_bit_position (decl);
9315 /* Note that the bit offset is always the distance (in bits) from the
9316 highest-order bit of the "containing object" to the highest-order bit of
9317 the bit-field itself. Since the "high-order end" of any object or field
9318 is different on big-endian and little-endian machines, the computation
9319 below must take account of these differences. */
9320 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9321 highest_order_field_bit_offset = bitpos_int;
9323 if (! BYTES_BIG_ENDIAN)
9325 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9326 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9330 = (! BYTES_BIG_ENDIAN
9331 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9332 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9334 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9337 /* For a FIELD_DECL node which represents a bit field, output an attribute
9338 which specifies the length in bits of the given field. */
9341 add_bit_size_attribute (die, decl)
9345 /* Must be a field and a bit field. */
9346 if (TREE_CODE (decl) != FIELD_DECL
9347 || ! DECL_BIT_FIELD_TYPE (decl))
9350 if (host_integerp (DECL_SIZE (decl), 1))
9351 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9354 /* If the compiled language is ANSI C, then add a 'prototyped'
9355 attribute, if arg types are given for the parameters of a function. */
9358 add_prototyped_attribute (die, func_type)
9362 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9363 && TYPE_ARG_TYPES (func_type) != NULL)
9364 add_AT_flag (die, DW_AT_prototyped, 1);
9367 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9368 by looking in either the type declaration or object declaration
9372 add_abstract_origin_attribute (die, origin)
9376 dw_die_ref origin_die = NULL;
9378 if (TREE_CODE (origin) != FUNCTION_DECL)
9380 /* We may have gotten separated from the block for the inlined
9381 function, if we're in an exception handler or some such; make
9382 sure that the abstract function has been written out.
9384 Doing this for nested functions is wrong, however; functions are
9385 distinct units, and our context might not even be inline. */
9389 fn = TYPE_STUB_DECL (fn);
9391 fn = decl_function_context (fn);
9393 dwarf2out_abstract_function (fn);
9396 if (DECL_P (origin))
9397 origin_die = lookup_decl_die (origin);
9398 else if (TYPE_P (origin))
9399 origin_die = lookup_type_die (origin);
9401 if (origin_die == NULL)
9404 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9407 /* We do not currently support the pure_virtual attribute. */
9410 add_pure_or_virtual_attribute (die, func_decl)
9414 if (DECL_VINDEX (func_decl))
9416 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9418 if (host_integerp (DECL_VINDEX (func_decl), 0))
9419 add_AT_loc (die, DW_AT_vtable_elem_location,
9420 new_loc_descr (DW_OP_constu,
9421 tree_low_cst (DECL_VINDEX (func_decl), 0),
9424 /* GNU extension: Record what type this method came from originally. */
9425 if (debug_info_level > DINFO_LEVEL_TERSE)
9426 add_AT_die_ref (die, DW_AT_containing_type,
9427 lookup_type_die (DECL_CONTEXT (func_decl)));
9431 /* Add source coordinate attributes for the given decl. */
9434 add_src_coords_attributes (die, decl)
9438 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9440 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9441 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9444 /* Add an DW_AT_name attribute and source coordinate attribute for the
9445 given decl, but only if it actually has a name. */
9448 add_name_and_src_coords_attributes (die, decl)
9454 decl_name = DECL_NAME (decl);
9455 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9457 add_name_attribute (die, dwarf2_name (decl, 0));
9458 if (! DECL_ARTIFICIAL (decl))
9459 add_src_coords_attributes (die, decl);
9461 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9462 && TREE_PUBLIC (decl)
9463 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9464 && !DECL_ABSTRACT (decl))
9465 add_AT_string (die, DW_AT_MIPS_linkage_name,
9466 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9469 #ifdef VMS_DEBUGGING_INFO
9470 /* Get the function's name, as described by its RTL. This may be different
9471 from the DECL_NAME name used in the source file. */
9472 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
9474 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
9475 XEXP (DECL_RTL (decl), 0));
9476 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
9481 /* Push a new declaration scope. */
9484 push_decl_scope (scope)
9487 VARRAY_PUSH_TREE (decl_scope_table, scope);
9490 /* Pop a declaration scope. */
9495 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9498 VARRAY_POP (decl_scope_table);
9501 /* Return the DIE for the scope that immediately contains this type.
9502 Non-named types get global scope. Named types nested in other
9503 types get their containing scope if it's open, or global scope
9504 otherwise. All other types (i.e. function-local named types) get
9505 the current active scope. */
9508 scope_die_for (t, context_die)
9510 dw_die_ref context_die;
9512 dw_die_ref scope_die = NULL;
9513 tree containing_scope;
9516 /* Non-types always go in the current scope. */
9520 containing_scope = TYPE_CONTEXT (t);
9522 /* Ignore namespaces for the moment. */
9523 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9524 containing_scope = NULL_TREE;
9526 /* Ignore function type "scopes" from the C frontend. They mean that
9527 a tagged type is local to a parmlist of a function declarator, but
9528 that isn't useful to DWARF. */
9529 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9530 containing_scope = NULL_TREE;
9532 if (containing_scope == NULL_TREE)
9533 scope_die = comp_unit_die;
9534 else if (TYPE_P (containing_scope))
9536 /* For types, we can just look up the appropriate DIE. But
9537 first we check to see if we're in the middle of emitting it
9538 so we know where the new DIE should go. */
9539 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9540 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
9545 if (debug_info_level > DINFO_LEVEL_TERSE
9546 && !TREE_ASM_WRITTEN (containing_scope))
9549 /* If none of the current dies are suitable, we get file scope. */
9550 scope_die = comp_unit_die;
9553 scope_die = lookup_type_die (containing_scope);
9556 scope_die = context_die;
9561 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9564 local_scope_p (context_die)
9565 dw_die_ref context_die;
9567 for (; context_die; context_die = context_die->die_parent)
9568 if (context_die->die_tag == DW_TAG_inlined_subroutine
9569 || context_die->die_tag == DW_TAG_subprogram)
9575 /* Returns nonzero if CONTEXT_DIE is a class. */
9578 class_scope_p (context_die)
9579 dw_die_ref context_die;
9582 && (context_die->die_tag == DW_TAG_structure_type
9583 || context_die->die_tag == DW_TAG_union_type));
9586 /* Many forms of DIEs require a "type description" attribute. This
9587 routine locates the proper "type descriptor" die for the type given
9588 by 'type', and adds an DW_AT_type attribute below the given die. */
9591 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9592 dw_die_ref object_die;
9596 dw_die_ref context_die;
9598 enum tree_code code = TREE_CODE (type);
9599 dw_die_ref type_die = NULL;
9601 /* ??? If this type is an unnamed subrange type of an integral or
9602 floating-point type, use the inner type. This is because we have no
9603 support for unnamed types in base_type_die. This can happen if this is
9604 an Ada subrange type. Correct solution is emit a subrange type die. */
9605 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9606 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9607 type = TREE_TYPE (type), code = TREE_CODE (type);
9609 if (code == ERROR_MARK
9610 /* Handle a special case. For functions whose return type is void, we
9611 generate *no* type attribute. (Note that no object may have type
9612 `void', so this only applies to function return types). */
9613 || code == VOID_TYPE)
9616 type_die = modified_type_die (type,
9617 decl_const || TYPE_READONLY (type),
9618 decl_volatile || TYPE_VOLATILE (type),
9621 if (type_die != NULL)
9622 add_AT_die_ref (object_die, DW_AT_type, type_die);
9625 /* Given a tree pointer to a struct, class, union, or enum type node, return
9626 a pointer to the (string) tag name for the given type, or zero if the type
9627 was declared without a tag. */
9633 const char *name = 0;
9635 if (TYPE_NAME (type) != 0)
9639 /* Find the IDENTIFIER_NODE for the type name. */
9640 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9641 t = TYPE_NAME (type);
9643 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9644 a TYPE_DECL node, regardless of whether or not a `typedef' was
9646 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9647 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9648 t = DECL_NAME (TYPE_NAME (type));
9650 /* Now get the name as a string, or invent one. */
9652 name = IDENTIFIER_POINTER (t);
9655 return (name == 0 || *name == '\0') ? 0 : name;
9658 /* Return the type associated with a data member, make a special check
9659 for bit field types. */
9662 member_declared_type (member)
9665 return (DECL_BIT_FIELD_TYPE (member)
9666 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
9669 /* Get the decl's label, as described by its RTL. This may be different
9670 from the DECL_NAME name used in the source file. */
9674 decl_start_label (decl)
9680 x = DECL_RTL (decl);
9681 if (GET_CODE (x) != MEM)
9685 if (GET_CODE (x) != SYMBOL_REF)
9688 fnname = XSTR (x, 0);
9693 /* These routines generate the internal representation of the DIE's for
9694 the compilation unit. Debugging information is collected by walking
9695 the declaration trees passed in from dwarf2out_decl(). */
9698 gen_array_type_die (type, context_die)
9700 dw_die_ref context_die;
9702 dw_die_ref scope_die = scope_die_for (type, context_die);
9703 dw_die_ref array_die;
9706 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9707 the inner array type comes before the outer array type. Thus we must
9708 call gen_type_die before we call new_die. See below also. */
9709 #ifdef MIPS_DEBUGGING_INFO
9710 gen_type_die (TREE_TYPE (type), context_die);
9713 array_die = new_die (DW_TAG_array_type, scope_die, type);
9716 /* We default the array ordering. SDB will probably do
9717 the right things even if DW_AT_ordering is not present. It's not even
9718 an issue until we start to get into multidimensional arrays anyway. If
9719 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9720 then we'll have to put the DW_AT_ordering attribute back in. (But if
9721 and when we find out that we need to put these in, we will only do so
9722 for multidimensional arrays. */
9723 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9726 #ifdef MIPS_DEBUGGING_INFO
9727 /* The SGI compilers handle arrays of unknown bound by setting
9728 AT_declaration and not emitting any subrange DIEs. */
9729 if (! TYPE_DOMAIN (type))
9730 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9733 add_subscript_info (array_die, type);
9735 add_name_attribute (array_die, type_tag (type));
9736 equate_type_number_to_die (type, array_die);
9738 /* Add representation of the type of the elements of this array type. */
9739 element_type = TREE_TYPE (type);
9741 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9742 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9743 We work around this by disabling this feature. See also
9744 add_subscript_info. */
9745 #ifndef MIPS_DEBUGGING_INFO
9746 while (TREE_CODE (element_type) == ARRAY_TYPE)
9747 element_type = TREE_TYPE (element_type);
9749 gen_type_die (element_type, context_die);
9752 add_type_attribute (array_die, element_type, 0, 0, context_die);
9756 gen_set_type_die (type, context_die)
9758 dw_die_ref context_die;
9761 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
9763 equate_type_number_to_die (type, type_die);
9764 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9769 gen_entry_point_die (decl, context_die)
9771 dw_die_ref context_die;
9773 tree origin = decl_ultimate_origin (decl);
9774 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
9777 add_abstract_origin_attribute (decl_die, origin);
9780 add_name_and_src_coords_attributes (decl_die, decl);
9781 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9785 if (DECL_ABSTRACT (decl))
9786 equate_decl_number_to_die (decl, decl_die);
9788 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9792 /* Walk through the list of incomplete types again, trying once more to
9793 emit full debugging info for them. */
9796 retry_incomplete_types ()
9800 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
9801 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
9804 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9807 gen_inlined_enumeration_type_die (type, context_die)
9809 dw_die_ref context_die;
9811 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
9813 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9814 be incomplete and such types are not marked. */
9815 add_abstract_origin_attribute (type_die, type);
9818 /* Generate a DIE to represent an inlined instance of a structure type. */
9821 gen_inlined_structure_type_die (type, context_die)
9823 dw_die_ref context_die;
9825 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
9827 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9828 be incomplete and such types are not marked. */
9829 add_abstract_origin_attribute (type_die, type);
9832 /* Generate a DIE to represent an inlined instance of a union type. */
9835 gen_inlined_union_type_die (type, context_die)
9837 dw_die_ref context_die;
9839 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
9841 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9842 be incomplete and such types are not marked. */
9843 add_abstract_origin_attribute (type_die, type);
9846 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9847 include all of the information about the enumeration values also. Each
9848 enumerated type name/value is listed as a child of the enumerated type
9852 gen_enumeration_type_die (type, context_die)
9854 dw_die_ref context_die;
9856 dw_die_ref type_die = lookup_type_die (type);
9858 if (type_die == NULL)
9860 type_die = new_die (DW_TAG_enumeration_type,
9861 scope_die_for (type, context_die), type);
9862 equate_type_number_to_die (type, type_die);
9863 add_name_attribute (type_die, type_tag (type));
9865 else if (! TYPE_SIZE (type))
9868 remove_AT (type_die, DW_AT_declaration);
9870 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9871 given enum type is incomplete, do not generate the DW_AT_byte_size
9872 attribute or the DW_AT_element_list attribute. */
9873 if (TYPE_SIZE (type))
9877 TREE_ASM_WRITTEN (type) = 1;
9878 add_byte_size_attribute (type_die, type);
9879 if (TYPE_STUB_DECL (type) != NULL_TREE)
9880 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9882 /* If the first reference to this type was as the return type of an
9883 inline function, then it may not have a parent. Fix this now. */
9884 if (type_die->die_parent == NULL)
9885 add_child_die (scope_die_for (type, context_die), type_die);
9887 for (link = TYPE_FIELDS (type);
9888 link != NULL; link = TREE_CHAIN (link))
9890 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
9892 add_name_attribute (enum_die,
9893 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9895 if (host_integerp (TREE_VALUE (link), 0))
9897 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9898 add_AT_int (enum_die, DW_AT_const_value,
9899 tree_low_cst (TREE_VALUE (link), 0));
9901 add_AT_unsigned (enum_die, DW_AT_const_value,
9902 tree_low_cst (TREE_VALUE (link), 0));
9907 add_AT_flag (type_die, DW_AT_declaration, 1);
9910 /* Generate a DIE to represent either a real live formal parameter decl or to
9911 represent just the type of some formal parameter position in some function
9914 Note that this routine is a bit unusual because its argument may be a
9915 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9916 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9917 node. If it's the former then this function is being called to output a
9918 DIE to represent a formal parameter object (or some inlining thereof). If
9919 it's the latter, then this function is only being called to output a
9920 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9921 argument type of some subprogram type. */
9924 gen_formal_parameter_die (node, context_die)
9926 dw_die_ref context_die;
9929 = new_die (DW_TAG_formal_parameter, context_die, node);
9932 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9935 origin = decl_ultimate_origin (node);
9937 add_abstract_origin_attribute (parm_die, origin);
9940 add_name_and_src_coords_attributes (parm_die, node);
9941 add_type_attribute (parm_die, TREE_TYPE (node),
9942 TREE_READONLY (node),
9943 TREE_THIS_VOLATILE (node),
9945 if (DECL_ARTIFICIAL (node))
9946 add_AT_flag (parm_die, DW_AT_artificial, 1);
9949 equate_decl_number_to_die (node, parm_die);
9950 if (! DECL_ABSTRACT (node))
9951 add_location_or_const_value_attribute (parm_die, node);
9956 /* We were called with some kind of a ..._TYPE node. */
9957 add_type_attribute (parm_die, node, 0, 0, context_die);
9967 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9968 at the end of an (ANSI prototyped) formal parameters list. */
9971 gen_unspecified_parameters_die (decl_or_type, context_die)
9973 dw_die_ref context_die;
9975 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
9978 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9979 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9980 parameters as specified in some function type specification (except for
9981 those which appear as part of a function *definition*). */
9984 gen_formal_types_die (function_or_method_type, context_die)
9985 tree function_or_method_type;
9986 dw_die_ref context_die;
9989 tree formal_type = NULL;
9990 tree first_parm_type;
9993 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9995 arg = DECL_ARGUMENTS (function_or_method_type);
9996 function_or_method_type = TREE_TYPE (function_or_method_type);
10001 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
10003 /* Make our first pass over the list of formal parameter types and output a
10004 DW_TAG_formal_parameter DIE for each one. */
10005 for (link = first_parm_type; link; )
10007 dw_die_ref parm_die;
10009 formal_type = TREE_VALUE (link);
10010 if (formal_type == void_type_node)
10013 /* Output a (nameless) DIE to represent the formal parameter itself. */
10014 parm_die = gen_formal_parameter_die (formal_type, context_die);
10015 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
10016 && link == first_parm_type)
10017 || (arg && DECL_ARTIFICIAL (arg)))
10018 add_AT_flag (parm_die, DW_AT_artificial, 1);
10020 link = TREE_CHAIN (link);
10022 arg = TREE_CHAIN (arg);
10025 /* If this function type has an ellipsis, add a
10026 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10027 if (formal_type != void_type_node)
10028 gen_unspecified_parameters_die (function_or_method_type, context_die);
10030 /* Make our second (and final) pass over the list of formal parameter types
10031 and output DIEs to represent those types (as necessary). */
10032 for (link = TYPE_ARG_TYPES (function_or_method_type);
10033 link && TREE_VALUE (link);
10034 link = TREE_CHAIN (link))
10035 gen_type_die (TREE_VALUE (link), context_die);
10038 /* We want to generate the DIE for TYPE so that we can generate the
10039 die for MEMBER, which has been defined; we will need to refer back
10040 to the member declaration nested within TYPE. If we're trying to
10041 generate minimal debug info for TYPE, processing TYPE won't do the
10042 trick; we need to attach the member declaration by hand. */
10045 gen_type_die_for_member (type, member, context_die)
10047 dw_die_ref context_die;
10049 gen_type_die (type, context_die);
10051 /* If we're trying to avoid duplicate debug info, we may not have
10052 emitted the member decl for this function. Emit it now. */
10053 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10054 && ! lookup_decl_die (member))
10056 if (decl_ultimate_origin (member))
10059 push_decl_scope (type);
10060 if (TREE_CODE (member) == FUNCTION_DECL)
10061 gen_subprogram_die (member, lookup_type_die (type));
10063 gen_variable_die (member, lookup_type_die (type));
10069 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10070 may later generate inlined and/or out-of-line instances of. */
10073 dwarf2out_abstract_function (decl)
10076 dw_die_ref old_die;
10079 int was_abstract = DECL_ABSTRACT (decl);
10081 /* Make sure we have the actual abstract inline, not a clone. */
10082 decl = DECL_ORIGIN (decl);
10084 old_die = lookup_decl_die (decl);
10085 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10086 /* We've already generated the abstract instance. */
10089 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10090 we don't get confused by DECL_ABSTRACT. */
10091 if (debug_info_level > DINFO_LEVEL_TERSE)
10093 context = decl_class_context (decl);
10095 gen_type_die_for_member
10096 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
10099 /* Pretend we've just finished compiling this function. */
10100 save_fn = current_function_decl;
10101 current_function_decl = decl;
10103 set_decl_abstract_flags (decl, 1);
10104 dwarf2out_decl (decl);
10105 if (! was_abstract)
10106 set_decl_abstract_flags (decl, 0);
10108 current_function_decl = save_fn;
10111 /* Generate a DIE to represent a declared function (either file-scope or
10115 gen_subprogram_die (decl, context_die)
10117 dw_die_ref context_die;
10119 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10120 tree origin = decl_ultimate_origin (decl);
10121 dw_die_ref subr_die;
10125 dw_die_ref old_die = lookup_decl_die (decl);
10126 int declaration = (current_function_decl != decl
10127 || class_scope_p (context_die));
10129 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10130 started to generate the abstract instance of an inline, decided to output
10131 its containing class, and proceeded to emit the declaration of the inline
10132 from the member list for the class. If so, DECLARATION takes priority;
10133 we'll get back to the abstract instance when done with the class. */
10135 /* The class-scope declaration DIE must be the primary DIE. */
10136 if (origin && declaration && class_scope_p (context_die))
10143 if (origin != NULL)
10145 if (declaration && ! local_scope_p (context_die))
10148 /* Fixup die_parent for the abstract instance of a nested
10149 inline function. */
10150 if (old_die && old_die->die_parent == NULL)
10151 add_child_die (context_die, old_die);
10153 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10154 add_abstract_origin_attribute (subr_die, origin);
10158 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10160 if (!get_AT_flag (old_die, DW_AT_declaration)
10161 /* We can have a normal definition following an inline one in the
10162 case of redefinition of GNU C extern inlines.
10163 It seems reasonable to use AT_specification in this case. */
10164 && !get_AT_unsigned (old_die, DW_AT_inline))
10166 /* ??? This can happen if there is a bug in the program, for
10167 instance, if it has duplicate function definitions. Ideally,
10168 we should detect this case and ignore it. For now, if we have
10169 already reported an error, any error at all, then assume that
10170 we got here because of an input error, not a dwarf2 bug. */
10176 /* If the definition comes from the same place as the declaration,
10177 maybe use the old DIE. We always want the DIE for this function
10178 that has the *_pc attributes to be under comp_unit_die so the
10179 debugger can find it. We also need to do this for abstract
10180 instances of inlines, since the spec requires the out-of-line copy
10181 to have the same parent. For local class methods, this doesn't
10182 apply; we just use the old DIE. */
10183 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10184 && (DECL_ARTIFICIAL (decl)
10185 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10186 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10187 == (unsigned) DECL_SOURCE_LINE (decl)))))
10189 subr_die = old_die;
10191 /* Clear out the declaration attribute and the parm types. */
10192 remove_AT (subr_die, DW_AT_declaration);
10193 remove_children (subr_die);
10197 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10198 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10199 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10200 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10201 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10202 != (unsigned) DECL_SOURCE_LINE (decl))
10204 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10209 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10211 if (TREE_PUBLIC (decl))
10212 add_AT_flag (subr_die, DW_AT_external, 1);
10214 add_name_and_src_coords_attributes (subr_die, decl);
10215 if (debug_info_level > DINFO_LEVEL_TERSE)
10217 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
10218 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
10219 0, 0, context_die);
10222 add_pure_or_virtual_attribute (subr_die, decl);
10223 if (DECL_ARTIFICIAL (decl))
10224 add_AT_flag (subr_die, DW_AT_artificial, 1);
10226 if (TREE_PROTECTED (decl))
10227 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10228 else if (TREE_PRIVATE (decl))
10229 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10234 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10236 add_AT_flag (subr_die, DW_AT_declaration, 1);
10238 /* The first time we see a member function, it is in the context of
10239 the class to which it belongs. We make sure of this by emitting
10240 the class first. The next time is the definition, which is
10241 handled above. The two may come from the same source text. */
10242 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10243 equate_decl_number_to_die (decl, subr_die);
10246 else if (DECL_ABSTRACT (decl))
10248 if (DECL_INLINE (decl) && !flag_no_inline)
10250 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10251 inline functions, but not for extern inline functions.
10252 We can't get this completely correct because information
10253 about whether the function was declared inline is not
10255 if (DECL_DEFER_OUTPUT (decl))
10256 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10258 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10261 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10263 equate_decl_number_to_die (decl, subr_die);
10265 else if (!DECL_EXTERNAL (decl))
10267 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10268 equate_decl_number_to_die (decl, subr_die);
10270 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10271 current_funcdef_number);
10272 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10273 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10274 current_funcdef_number);
10275 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10277 add_pubname (decl, subr_die);
10278 add_arange (decl, subr_die);
10280 #ifdef MIPS_DEBUGGING_INFO
10281 /* Add a reference to the FDE for this routine. */
10282 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10285 /* Define the "frame base" location for this routine. We use the
10286 frame pointer or stack pointer registers, since the RTL for local
10287 variables is relative to one of them. */
10289 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10290 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10293 /* ??? This fails for nested inline functions, because context_display
10294 is not part of the state saved/restored for inline functions. */
10295 if (current_function_needs_context)
10296 add_AT_location_description (subr_die, DW_AT_static_link,
10297 lookup_static_chain (decl));
10301 /* Now output descriptions of the arguments for this function. This gets
10302 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10303 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10304 `...' at the end of the formal parameter list. In order to find out if
10305 there was a trailing ellipsis or not, we must instead look at the type
10306 associated with the FUNCTION_DECL. This will be a node of type
10307 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10308 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10309 an ellipsis at the end. */
10311 /* In the case where we are describing a mere function declaration, all we
10312 need to do here (and all we *can* do here) is to describe the *types* of
10313 its formal parameters. */
10314 if (debug_info_level <= DINFO_LEVEL_TERSE)
10316 else if (declaration)
10317 gen_formal_types_die (decl, subr_die);
10320 /* Generate DIEs to represent all known formal parameters */
10321 tree arg_decls = DECL_ARGUMENTS (decl);
10324 /* When generating DIEs, generate the unspecified_parameters DIE
10325 instead if we come across the arg "__builtin_va_alist" */
10326 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10327 if (TREE_CODE (parm) == PARM_DECL)
10329 if (DECL_NAME (parm)
10330 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10331 "__builtin_va_alist"))
10332 gen_unspecified_parameters_die (parm, subr_die);
10334 gen_decl_die (parm, subr_die);
10337 /* Decide whether we need an unspecified_parameters DIE at the end.
10338 There are 2 more cases to do this for: 1) the ansi ... declaration -
10339 this is detectable when the end of the arg list is not a
10340 void_type_node 2) an unprototyped function declaration (not a
10341 definition). This just means that we have no info about the
10342 parameters at all. */
10343 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10344 if (fn_arg_types != NULL)
10346 /* this is the prototyped case, check for ... */
10347 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10348 gen_unspecified_parameters_die (decl, subr_die);
10350 else if (DECL_INITIAL (decl) == NULL_TREE)
10351 gen_unspecified_parameters_die (decl, subr_die);
10354 /* Output Dwarf info for all of the stuff within the body of the function
10355 (if it has one - it may be just a declaration). */
10356 outer_scope = DECL_INITIAL (decl);
10358 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10359 a function. This BLOCK actually represents the outermost binding contour
10360 for the function, i.e. the contour in which the function's formal
10361 parameters and labels get declared. Curiously, it appears that the front
10362 end doesn't actually put the PARM_DECL nodes for the current function onto
10363 the BLOCK_VARS list for this outer scope, but are strung off of the
10364 DECL_ARGUMENTS list for the function instead.
10366 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10367 the LABEL_DECL nodes for the function however, and we output DWARF info
10368 for those in decls_for_scope. Just within the `outer_scope' there will be
10369 a BLOCK node representing the function's outermost pair of curly braces,
10370 and any blocks used for the base and member initializers of a C++
10371 constructor function. */
10372 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10374 current_function_has_inlines = 0;
10375 decls_for_scope (outer_scope, subr_die, 0);
10377 #if 0 && defined (MIPS_DEBUGGING_INFO)
10378 if (current_function_has_inlines)
10380 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10381 if (! comp_unit_has_inlines)
10383 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10384 comp_unit_has_inlines = 1;
10391 /* Generate a DIE to represent a declared data object. */
10394 gen_variable_die (decl, context_die)
10396 dw_die_ref context_die;
10398 tree origin = decl_ultimate_origin (decl);
10399 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
10401 dw_die_ref old_die = lookup_decl_die (decl);
10402 int declaration = (DECL_EXTERNAL (decl)
10403 || class_scope_p (context_die));
10405 if (origin != NULL)
10406 add_abstract_origin_attribute (var_die, origin);
10408 /* Loop unrolling can create multiple blocks that refer to the same
10409 static variable, so we must test for the DW_AT_declaration flag.
10411 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10412 copy decls and set the DECL_ABSTRACT flag on them instead of
10415 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10416 else if (old_die && TREE_STATIC (decl)
10417 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10419 /* This is a definition of a C++ class level static. */
10420 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10421 if (DECL_NAME (decl))
10423 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10425 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10426 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10428 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10429 != (unsigned) DECL_SOURCE_LINE (decl))
10431 add_AT_unsigned (var_die, DW_AT_decl_line,
10432 DECL_SOURCE_LINE (decl));
10437 add_name_and_src_coords_attributes (var_die, decl);
10438 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
10439 TREE_THIS_VOLATILE (decl), context_die);
10441 if (TREE_PUBLIC (decl))
10442 add_AT_flag (var_die, DW_AT_external, 1);
10444 if (DECL_ARTIFICIAL (decl))
10445 add_AT_flag (var_die, DW_AT_artificial, 1);
10447 if (TREE_PROTECTED (decl))
10448 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10449 else if (TREE_PRIVATE (decl))
10450 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10454 add_AT_flag (var_die, DW_AT_declaration, 1);
10456 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10457 equate_decl_number_to_die (decl, var_die);
10459 if (! declaration && ! DECL_ABSTRACT (decl))
10461 add_location_or_const_value_attribute (var_die, decl);
10462 add_pubname (decl, var_die);
10465 tree_add_const_value_attribute (var_die, decl);
10468 /* Generate a DIE to represent a label identifier. */
10471 gen_label_die (decl, context_die)
10473 dw_die_ref context_die;
10475 tree origin = decl_ultimate_origin (decl);
10476 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
10478 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10480 if (origin != NULL)
10481 add_abstract_origin_attribute (lbl_die, origin);
10483 add_name_and_src_coords_attributes (lbl_die, decl);
10485 if (DECL_ABSTRACT (decl))
10486 equate_decl_number_to_die (decl, lbl_die);
10489 insn = DECL_RTL (decl);
10491 /* Deleted labels are programmer specified labels which have been
10492 eliminated because of various optimisations. We still emit them
10493 here so that it is possible to put breakpoints on them. */
10494 if (GET_CODE (insn) == CODE_LABEL
10495 || ((GET_CODE (insn) == NOTE
10496 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10498 /* When optimization is enabled (via -O) some parts of the compiler
10499 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10500 represent source-level labels which were explicitly declared by
10501 the user. This really shouldn't be happening though, so catch
10502 it if it ever does happen. */
10503 if (INSN_DELETED_P (insn))
10506 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10507 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10512 /* Generate a DIE for a lexical block. */
10515 gen_lexical_block_die (stmt, context_die, depth)
10517 dw_die_ref context_die;
10520 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
10521 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10523 if (! BLOCK_ABSTRACT (stmt))
10525 if (BLOCK_FRAGMENT_CHAIN (stmt))
10529 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
10531 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10534 add_ranges (chain);
10535 chain = BLOCK_FRAGMENT_CHAIN (chain);
10542 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10543 BLOCK_NUMBER (stmt));
10544 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10545 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10546 BLOCK_NUMBER (stmt));
10547 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10551 decls_for_scope (stmt, stmt_die, depth);
10554 /* Generate a DIE for an inlined subprogram. */
10557 gen_inlined_subroutine_die (stmt, context_die, depth)
10559 dw_die_ref context_die;
10562 if (! BLOCK_ABSTRACT (stmt))
10564 dw_die_ref subr_die
10565 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
10566 tree decl = block_ultimate_origin (stmt);
10567 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10569 /* Emit info for the abstract instance first, if we haven't yet. */
10570 dwarf2out_abstract_function (decl);
10572 add_abstract_origin_attribute (subr_die, decl);
10573 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10574 BLOCK_NUMBER (stmt));
10575 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10576 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10577 BLOCK_NUMBER (stmt));
10578 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10579 decls_for_scope (stmt, subr_die, depth);
10580 current_function_has_inlines = 1;
10584 /* Generate a DIE for a field in a record, or structure. */
10587 gen_field_die (decl, context_die)
10589 dw_die_ref context_die;
10591 dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl);
10593 add_name_and_src_coords_attributes (decl_die, decl);
10594 add_type_attribute (decl_die, member_declared_type (decl),
10595 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10598 if (DECL_BIT_FIELD_TYPE (decl))
10600 add_byte_size_attribute (decl_die, decl);
10601 add_bit_size_attribute (decl_die, decl);
10602 add_bit_offset_attribute (decl_die, decl);
10605 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10606 add_data_member_location_attribute (decl_die, decl);
10608 if (DECL_ARTIFICIAL (decl))
10609 add_AT_flag (decl_die, DW_AT_artificial, 1);
10611 if (TREE_PROTECTED (decl))
10612 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10613 else if (TREE_PRIVATE (decl))
10614 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10618 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10619 Use modified_type_die instead.
10620 We keep this code here just in case these types of DIEs may be needed to
10621 represent certain things in other languages (e.g. Pascal) someday. */
10624 gen_pointer_type_die (type, context_die)
10626 dw_die_ref context_die;
10629 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
10631 equate_type_number_to_die (type, ptr_die);
10632 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10633 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10636 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10637 Use modified_type_die instead.
10638 We keep this code here just in case these types of DIEs may be needed to
10639 represent certain things in other languages (e.g. Pascal) someday. */
10642 gen_reference_type_die (type, context_die)
10644 dw_die_ref context_die;
10647 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
10649 equate_type_number_to_die (type, ref_die);
10650 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10651 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10655 /* Generate a DIE for a pointer to a member type. */
10658 gen_ptr_to_mbr_type_die (type, context_die)
10660 dw_die_ref context_die;
10663 = new_die (DW_TAG_ptr_to_member_type,
10664 scope_die_for (type, context_die), type);
10666 equate_type_number_to_die (type, ptr_die);
10667 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10668 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10669 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10672 /* Generate the DIE for the compilation unit. */
10675 gen_compile_unit_die (filename)
10676 const char *filename;
10679 char producer[250];
10680 const char *wd = getpwd ();
10681 const char *language_string = lang_hooks.name;
10684 die = new_die (DW_TAG_compile_unit, NULL, NULL);
10685 add_name_attribute (die, filename);
10687 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10688 add_AT_string (die, DW_AT_comp_dir, wd);
10690 sprintf (producer, "%s %s", language_string, version_string);
10692 #ifdef MIPS_DEBUGGING_INFO
10693 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10694 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10695 not appear in the producer string, the debugger reaches the conclusion
10696 that the object file is stripped and has no debugging information.
10697 To get the MIPS/SGI debugger to believe that there is debugging
10698 information in the object file, we add a -g to the producer string. */
10699 if (debug_info_level > DINFO_LEVEL_TERSE)
10700 strcat (producer, " -g");
10703 add_AT_string (die, DW_AT_producer, producer);
10705 if (strcmp (language_string, "GNU C++") == 0)
10706 language = DW_LANG_C_plus_plus;
10707 else if (strcmp (language_string, "GNU Ada") == 0)
10708 language = DW_LANG_Ada83;
10709 else if (strcmp (language_string, "GNU F77") == 0)
10710 language = DW_LANG_Fortran77;
10711 else if (strcmp (language_string, "GNU Pascal") == 0)
10712 language = DW_LANG_Pascal83;
10713 else if (strcmp (language_string, "GNU Java") == 0)
10714 language = DW_LANG_Java;
10715 else if (flag_traditional)
10716 language = DW_LANG_C;
10718 language = DW_LANG_C89;
10720 add_AT_unsigned (die, DW_AT_language, language);
10724 /* Generate a DIE for a string type. */
10727 gen_string_type_die (type, context_die)
10729 dw_die_ref context_die;
10731 dw_die_ref type_die
10732 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
10734 equate_type_number_to_die (type, type_die);
10736 /* ??? Fudge the string length attribute for now.
10737 TODO: add string length info. */
10739 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10740 bound_representation (upper_bound, 0, 'u');
10744 /* Generate the DIE for a base class. */
10747 gen_inheritance_die (binfo, context_die)
10749 dw_die_ref context_die;
10751 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
10753 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10754 add_data_member_location_attribute (die, binfo);
10756 if (TREE_VIA_VIRTUAL (binfo))
10757 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10759 if (TREE_VIA_PUBLIC (binfo))
10760 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10761 else if (TREE_VIA_PROTECTED (binfo))
10762 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10765 /* Generate a DIE for a class member. */
10768 gen_member_die (type, context_die)
10770 dw_die_ref context_die;
10775 /* If this is not an incomplete type, output descriptions of each of its
10776 members. Note that as we output the DIEs necessary to represent the
10777 members of this record or union type, we will also be trying to output
10778 DIEs to represent the *types* of those members. However the `type'
10779 function (above) will specifically avoid generating type DIEs for member
10780 types *within* the list of member DIEs for this (containing) type except
10781 for those types (of members) which are explicitly marked as also being
10782 members of this (containing) type themselves. The g++ front- end can
10783 force any given type to be treated as a member of some other (containing)
10784 type by setting the TYPE_CONTEXT of the given (member) type to point to
10785 the TREE node representing the appropriate (containing) type. */
10787 /* First output info about the base classes. */
10788 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10790 tree bases = TYPE_BINFO_BASETYPES (type);
10791 int n_bases = TREE_VEC_LENGTH (bases);
10794 for (i = 0; i < n_bases; i++)
10795 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10798 /* Now output info about the data members and type members. */
10799 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10801 /* If we thought we were generating minimal debug info for TYPE
10802 and then changed our minds, some of the member declarations
10803 may have already been defined. Don't define them again, but
10804 do put them in the right order. */
10806 child = lookup_decl_die (member);
10808 splice_child_die (context_die, child);
10810 gen_decl_die (member, context_die);
10813 /* Now output info about the function members (if any). */
10814 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10816 /* Don't include clones in the member list. */
10817 if (DECL_ABSTRACT_ORIGIN (member))
10820 child = lookup_decl_die (member);
10822 splice_child_die (context_die, child);
10824 gen_decl_die (member, context_die);
10828 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10829 is set, we pretend that the type was never defined, so we only get the
10830 member DIEs needed by later specification DIEs. */
10833 gen_struct_or_union_type_die (type, context_die)
10835 dw_die_ref context_die;
10837 dw_die_ref type_die = lookup_type_die (type);
10838 dw_die_ref scope_die = 0;
10840 int complete = (TYPE_SIZE (type)
10841 && (! TYPE_STUB_DECL (type)
10842 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10844 if (type_die && ! complete)
10847 if (TYPE_CONTEXT (type) != NULL_TREE
10848 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10851 scope_die = scope_die_for (type, context_die);
10853 if (! type_die || (nested && scope_die == comp_unit_die))
10854 /* First occurrence of type or toplevel definition of nested class. */
10856 dw_die_ref old_die = type_die;
10858 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10859 ? DW_TAG_structure_type : DW_TAG_union_type,
10861 equate_type_number_to_die (type, type_die);
10863 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10865 add_name_attribute (type_die, type_tag (type));
10868 remove_AT (type_die, DW_AT_declaration);
10870 /* If this type has been completed, then give it a byte_size attribute and
10871 then give a list of members. */
10874 /* Prevent infinite recursion in cases where the type of some member of
10875 this type is expressed in terms of this type itself. */
10876 TREE_ASM_WRITTEN (type) = 1;
10877 add_byte_size_attribute (type_die, type);
10878 if (TYPE_STUB_DECL (type) != NULL_TREE)
10879 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10881 /* If the first reference to this type was as the return type of an
10882 inline function, then it may not have a parent. Fix this now. */
10883 if (type_die->die_parent == NULL)
10884 add_child_die (scope_die, type_die);
10886 push_decl_scope (type);
10887 gen_member_die (type, type_die);
10890 /* GNU extension: Record what type our vtable lives in. */
10891 if (TYPE_VFIELD (type))
10893 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10895 gen_type_die (vtype, context_die);
10896 add_AT_die_ref (type_die, DW_AT_containing_type,
10897 lookup_type_die (vtype));
10902 add_AT_flag (type_die, DW_AT_declaration, 1);
10904 /* We don't need to do this for function-local types. */
10905 if (TYPE_STUB_DECL (type)
10906 && ! decl_function_context (TYPE_STUB_DECL (type)))
10907 VARRAY_PUSH_TREE (incomplete_types, type);
10911 /* Generate a DIE for a subroutine _type_. */
10914 gen_subroutine_type_die (type, context_die)
10916 dw_die_ref context_die;
10918 tree return_type = TREE_TYPE (type);
10919 dw_die_ref subr_die
10920 = new_die (DW_TAG_subroutine_type,
10921 scope_die_for (type, context_die), type);
10923 equate_type_number_to_die (type, subr_die);
10924 add_prototyped_attribute (subr_die, type);
10925 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10926 gen_formal_types_die (type, subr_die);
10929 /* Generate a DIE for a type definition */
10932 gen_typedef_die (decl, context_die)
10934 dw_die_ref context_die;
10936 dw_die_ref type_die;
10939 if (TREE_ASM_WRITTEN (decl))
10942 TREE_ASM_WRITTEN (decl) = 1;
10943 type_die = new_die (DW_TAG_typedef, context_die, decl);
10944 origin = decl_ultimate_origin (decl);
10945 if (origin != NULL)
10946 add_abstract_origin_attribute (type_die, origin);
10951 add_name_and_src_coords_attributes (type_die, decl);
10952 if (DECL_ORIGINAL_TYPE (decl))
10954 type = DECL_ORIGINAL_TYPE (decl);
10956 if (type == TREE_TYPE (decl))
10959 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10962 type = TREE_TYPE (decl);
10964 add_type_attribute (type_die, type, TREE_READONLY (decl),
10965 TREE_THIS_VOLATILE (decl), context_die);
10968 if (DECL_ABSTRACT (decl))
10969 equate_decl_number_to_die (decl, type_die);
10972 /* Generate a type description DIE. */
10975 gen_type_die (type, context_die)
10977 dw_die_ref context_die;
10981 if (type == NULL_TREE || type == error_mark_node)
10984 /* We are going to output a DIE to represent the unqualified version
10985 of this type (i.e. without any const or volatile qualifiers) so
10986 get the main variant (i.e. the unqualified version) of this type
10987 now. (Vectors are special because the debugging info is in the
10988 cloned type itself). */
10989 if (TREE_CODE (type) != VECTOR_TYPE)
10990 type = type_main_variant (type);
10992 if (TREE_ASM_WRITTEN (type))
10995 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10996 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10998 TREE_ASM_WRITTEN (type) = 1;
10999 gen_decl_die (TYPE_NAME (type), context_die);
11003 switch (TREE_CODE (type))
11009 case REFERENCE_TYPE:
11010 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11011 ensures that the gen_type_die recursion will terminate even if the
11012 type is recursive. Recursive types are possible in Ada. */
11013 /* ??? We could perhaps do this for all types before the switch
11015 TREE_ASM_WRITTEN (type) = 1;
11017 /* For these types, all that is required is that we output a DIE (or a
11018 set of DIEs) to represent the "basis" type. */
11019 gen_type_die (TREE_TYPE (type), context_die);
11023 /* This code is used for C++ pointer-to-data-member types.
11024 Output a description of the relevant class type. */
11025 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
11027 /* Output a description of the type of the object pointed to. */
11028 gen_type_die (TREE_TYPE (type), context_die);
11030 /* Now output a DIE to represent this pointer-to-data-member type
11032 gen_ptr_to_mbr_type_die (type, context_die);
11036 gen_type_die (TYPE_DOMAIN (type), context_die);
11037 gen_set_type_die (type, context_die);
11041 gen_type_die (TREE_TYPE (type), context_die);
11042 abort (); /* No way to represent these in Dwarf yet! */
11045 case FUNCTION_TYPE:
11046 /* Force out return type (in case it wasn't forced out already). */
11047 gen_type_die (TREE_TYPE (type), context_die);
11048 gen_subroutine_type_die (type, context_die);
11052 /* Force out return type (in case it wasn't forced out already). */
11053 gen_type_die (TREE_TYPE (type), context_die);
11054 gen_subroutine_type_die (type, context_die);
11058 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
11060 gen_type_die (TREE_TYPE (type), context_die);
11061 gen_string_type_die (type, context_die);
11064 gen_array_type_die (type, context_die);
11068 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
11071 case ENUMERAL_TYPE:
11074 case QUAL_UNION_TYPE:
11075 /* If this is a nested type whose containing class hasn't been written
11076 out yet, writing it out will cover this one, too. This does not apply
11077 to instantiations of member class templates; they need to be added to
11078 the containing class as they are generated. FIXME: This hurts the
11079 idea of combining type decls from multiple TUs, since we can't predict
11080 what set of template instantiations we'll get. */
11081 if (TYPE_CONTEXT (type)
11082 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
11083 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
11085 gen_type_die (TYPE_CONTEXT (type), context_die);
11087 if (TREE_ASM_WRITTEN (type))
11090 /* If that failed, attach ourselves to the stub. */
11091 push_decl_scope (TYPE_CONTEXT (type));
11092 context_die = lookup_type_die (TYPE_CONTEXT (type));
11098 if (TREE_CODE (type) == ENUMERAL_TYPE)
11099 gen_enumeration_type_die (type, context_die);
11101 gen_struct_or_union_type_die (type, context_die);
11106 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11107 it up if it is ever completed. gen_*_type_die will set it for us
11108 when appropriate. */
11117 /* No DIEs needed for fundamental types. */
11121 /* No Dwarf representation currently defined. */
11128 TREE_ASM_WRITTEN (type) = 1;
11131 /* Generate a DIE for a tagged type instantiation. */
11134 gen_tagged_type_instantiation_die (type, context_die)
11136 dw_die_ref context_die;
11138 if (type == NULL_TREE || type == error_mark_node)
11141 /* We are going to output a DIE to represent the unqualified version of
11142 this type (i.e. without any const or volatile qualifiers) so make sure
11143 that we have the main variant (i.e. the unqualified version) of this
11145 if (type != type_main_variant (type))
11148 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11149 an instance of an unresolved type. */
11151 switch (TREE_CODE (type))
11156 case ENUMERAL_TYPE:
11157 gen_inlined_enumeration_type_die (type, context_die);
11161 gen_inlined_structure_type_die (type, context_die);
11165 case QUAL_UNION_TYPE:
11166 gen_inlined_union_type_die (type, context_die);
11174 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11175 things which are local to the given block. */
11178 gen_block_die (stmt, context_die, depth)
11180 dw_die_ref context_die;
11183 int must_output_die = 0;
11186 enum tree_code origin_code;
11188 /* Ignore blocks never really used to make RTL. */
11189 if (stmt == NULL_TREE || !TREE_USED (stmt)
11190 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11193 /* If the block is one fragment of a non-contiguous block, do not
11194 process the variables, since they will have been done by the
11195 origin block. Do process subblocks. */
11196 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11200 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
11201 gen_block_die (sub, context_die, depth + 1);
11206 /* Determine the "ultimate origin" of this block. This block may be an
11207 inlined instance of an inlined instance of inline function, so we have
11208 to trace all of the way back through the origin chain to find out what
11209 sort of node actually served as the original seed for the creation of
11210 the current block. */
11211 origin = block_ultimate_origin (stmt);
11212 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11214 /* Determine if we need to output any Dwarf DIEs at all to represent this
11216 if (origin_code == FUNCTION_DECL)
11217 /* The outer scopes for inlinings *must* always be represented. We
11218 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11219 must_output_die = 1;
11222 /* In the case where the current block represents an inlining of the
11223 "body block" of an inline function, we must *NOT* output any DIE for
11224 this block because we have already output a DIE to represent the whole
11225 inlined function scope and the "body block" of any function doesn't
11226 really represent a different scope according to ANSI C rules. So we
11227 check here to make sure that this block does not represent a "body
11228 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11229 if (! is_body_block (origin ? origin : stmt))
11231 /* Determine if this block directly contains any "significant"
11232 local declarations which we will need to output DIEs for. */
11233 if (debug_info_level > DINFO_LEVEL_TERSE)
11234 /* We are not in terse mode so *any* local declaration counts
11235 as being a "significant" one. */
11236 must_output_die = (BLOCK_VARS (stmt) != NULL);
11238 /* We are in terse mode, so only local (nested) function
11239 definitions count as "significant" local declarations. */
11240 for (decl = BLOCK_VARS (stmt);
11241 decl != NULL; decl = TREE_CHAIN (decl))
11242 if (TREE_CODE (decl) == FUNCTION_DECL
11243 && DECL_INITIAL (decl))
11245 must_output_die = 1;
11251 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11252 DIE for any block which contains no significant local declarations at
11253 all. Rather, in such cases we just call `decls_for_scope' so that any
11254 needed Dwarf info for any sub-blocks will get properly generated. Note
11255 that in terse mode, our definition of what constitutes a "significant"
11256 local declaration gets restricted to include only inlined function
11257 instances and local (nested) function definitions. */
11258 if (must_output_die)
11260 if (origin_code == FUNCTION_DECL)
11261 gen_inlined_subroutine_die (stmt, context_die, depth);
11263 gen_lexical_block_die (stmt, context_die, depth);
11266 decls_for_scope (stmt, context_die, depth);
11269 /* Generate all of the decls declared within a given scope and (recursively)
11270 all of its sub-blocks. */
11273 decls_for_scope (stmt, context_die, depth)
11275 dw_die_ref context_die;
11281 /* Ignore blocks never really used to make RTL. */
11282 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11285 /* Output the DIEs to represent all of the data objects and typedefs
11286 declared directly within this block but not within any nested
11287 sub-blocks. Also, nested function and tag DIEs have been
11288 generated with a parent of NULL; fix that up now. */
11289 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
11293 if (TREE_CODE (decl) == FUNCTION_DECL)
11294 die = lookup_decl_die (decl);
11295 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11296 die = lookup_type_die (TREE_TYPE (decl));
11300 if (die != NULL && die->die_parent == NULL)
11301 add_child_die (context_die, die);
11303 gen_decl_die (decl, context_die);
11306 /* Output the DIEs to represent all sub-blocks (and the items declared
11307 therein) of this block. */
11308 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11310 subblocks = BLOCK_CHAIN (subblocks))
11311 gen_block_die (subblocks, context_die, depth + 1);
11314 /* Is this a typedef we can avoid emitting? */
11317 is_redundant_typedef (decl)
11320 if (TYPE_DECL_IS_STUB (decl))
11323 if (DECL_ARTIFICIAL (decl)
11324 && DECL_CONTEXT (decl)
11325 && is_tagged_type (DECL_CONTEXT (decl))
11326 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11327 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11328 /* Also ignore the artificial member typedef for the class name. */
11334 /* Generate Dwarf debug information for a decl described by DECL. */
11337 gen_decl_die (decl, context_die)
11339 dw_die_ref context_die;
11343 if (DECL_P (decl) && DECL_IGNORED_P (decl))
11346 switch (TREE_CODE (decl))
11352 /* The individual enumerators of an enum type get output when we output
11353 the Dwarf representation of the relevant enum type itself. */
11356 case FUNCTION_DECL:
11357 /* Don't output any DIEs to represent mere function declarations,
11358 unless they are class members or explicit block externs. */
11359 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11360 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11363 /* If we're emitting a clone, emit info for the abstract instance. */
11364 if (DECL_ORIGIN (decl) != decl)
11365 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11367 /* If we're emitting an out-of-line copy of an inline function,
11368 emit info for the abstract instance and set up to refer to it. */
11369 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11370 && ! class_scope_p (context_die)
11371 /* dwarf2out_abstract_function won't emit a die if this is just
11372 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11373 that case, because that works only if we have a die. */
11374 && DECL_INITIAL (decl) != NULL_TREE)
11376 dwarf2out_abstract_function (decl);
11377 set_decl_origin_self (decl);
11380 /* Otherwise we're emitting the primary DIE for this decl. */
11381 else if (debug_info_level > DINFO_LEVEL_TERSE)
11383 /* Before we describe the FUNCTION_DECL itself, make sure that we
11384 have described its return type. */
11385 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11387 /* And its virtual context. */
11388 if (DECL_VINDEX (decl) != NULL_TREE)
11389 gen_type_die (DECL_CONTEXT (decl), context_die);
11391 /* And its containing type. */
11392 origin = decl_class_context (decl);
11393 if (origin != NULL_TREE)
11394 gen_type_die_for_member (origin, decl, context_die);
11397 /* Now output a DIE to represent the function itself. */
11398 gen_subprogram_die (decl, context_die);
11402 /* If we are in terse mode, don't generate any DIEs to represent any
11403 actual typedefs. */
11404 if (debug_info_level <= DINFO_LEVEL_TERSE)
11407 /* In the special case of a TYPE_DECL node representing the declaration
11408 of some type tag, if the given TYPE_DECL is marked as having been
11409 instantiated from some other (original) TYPE_DECL node (e.g. one which
11410 was generated within the original definition of an inline function) we
11411 have to generate a special (abbreviated) DW_TAG_structure_type,
11412 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11413 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11415 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11419 if (is_redundant_typedef (decl))
11420 gen_type_die (TREE_TYPE (decl), context_die);
11422 /* Output a DIE to represent the typedef itself. */
11423 gen_typedef_die (decl, context_die);
11427 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11428 gen_label_die (decl, context_die);
11432 /* If we are in terse mode, don't generate any DIEs to represent any
11433 variable declarations or definitions. */
11434 if (debug_info_level <= DINFO_LEVEL_TERSE)
11437 /* Output any DIEs that are needed to specify the type of this data
11439 gen_type_die (TREE_TYPE (decl), context_die);
11441 /* And its containing type. */
11442 origin = decl_class_context (decl);
11443 if (origin != NULL_TREE)
11444 gen_type_die_for_member (origin, decl, context_die);
11446 /* Now output the DIE to represent the data object itself. This gets
11447 complicated because of the possibility that the VAR_DECL really
11448 represents an inlined instance of a formal parameter for an inline
11450 origin = decl_ultimate_origin (decl);
11451 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11452 gen_formal_parameter_die (decl, context_die);
11454 gen_variable_die (decl, context_die);
11458 /* Ignore the nameless fields that are used to skip bits but handle C++
11459 anonymous unions. */
11460 if (DECL_NAME (decl) != NULL_TREE
11461 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11463 gen_type_die (member_declared_type (decl), context_die);
11464 gen_field_die (decl, context_die);
11469 gen_type_die (TREE_TYPE (decl), context_die);
11470 gen_formal_parameter_die (decl, context_die);
11473 case NAMESPACE_DECL:
11474 /* Ignore for now. */
11483 mark_limbo_die_list (ptr)
11484 void *ptr ATTRIBUTE_UNUSED;
11486 limbo_die_node *node;
11487 for (node = limbo_die_list; node ; node = node->next)
11488 ggc_mark_tree (node->created_for);
11491 /* Add Ada "use" clause information for SGI Workshop debugger. */
11494 dwarf2out_add_library_unit_info (filename, context_list)
11495 const char *filename;
11496 const char *context_list;
11498 unsigned int file_index;
11500 if (filename != NULL)
11502 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
11503 tree context_list_decl
11504 = build_decl (LABEL_DECL, get_identifier (context_list),
11507 TREE_PUBLIC (context_list_decl) = TRUE;
11508 add_name_attribute (unit_die, context_list);
11509 file_index = lookup_filename (filename);
11510 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11511 add_pubname (context_list_decl, unit_die);
11515 /* Output debug information for global decl DECL. Called from toplev.c after
11516 compilation proper has finished. */
11519 dwarf2out_global_decl (decl)
11522 /* Output DWARF2 information for file-scope tentative data object
11523 declarations, file-scope (extern) function declarations (which had no
11524 corresponding body) and file-scope tagged type declarations and
11525 definitions which have not yet been forced out. */
11526 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11527 dwarf2out_decl (decl);
11530 /* Write the debugging output for DECL. */
11533 dwarf2out_decl (decl)
11536 dw_die_ref context_die = comp_unit_die;
11538 switch (TREE_CODE (decl))
11543 case FUNCTION_DECL:
11544 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11545 builtin function. Explicit programmer-supplied declarations of
11546 these same functions should NOT be ignored however. */
11547 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11550 /* What we would really like to do here is to filter out all mere
11551 file-scope declarations of file-scope functions which are never
11552 referenced later within this translation unit (and keep all of ones
11553 that *are* referenced later on) but we aren't clairvoyant, so we have
11554 no idea which functions will be referenced in the future (i.e. later
11555 on within the current translation unit). So here we just ignore all
11556 file-scope function declarations which are not also definitions. If
11557 and when the debugger needs to know something about these functions,
11558 it will have to hunt around and find the DWARF information associated
11559 with the definition of the function.
11561 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11562 nodes represent definitions and which ones represent mere
11563 declarations. We have to check DECL_INITIAL instead. That's because
11564 the C front-end supports some weird semantics for "extern inline"
11565 function definitions. These can get inlined within the current
11566 translation unit (an thus, we need to generate Dwarf info for their
11567 abstract instances so that the Dwarf info for the concrete inlined
11568 instances can have something to refer to) but the compiler never
11569 generates any out-of-lines instances of such things (despite the fact
11570 that they *are* definitions).
11572 The important point is that the C front-end marks these "extern
11573 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11574 them anyway. Note that the C++ front-end also plays some similar games
11575 for inline function definitions appearing within include files which
11576 also contain `#pragma interface' pragmas. */
11577 if (DECL_INITIAL (decl) == NULL_TREE)
11580 /* If we're a nested function, initially use a parent of NULL; if we're
11581 a plain function, this will be fixed up in decls_for_scope. If
11582 we're a method, it will be ignored, since we already have a DIE. */
11583 if (decl_function_context (decl))
11584 context_die = NULL;
11588 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11589 declaration and if the declaration was never even referenced from
11590 within this entire compilation unit. We suppress these DIEs in
11591 order to save space in the .debug section (by eliminating entries
11592 which are probably useless). Note that we must not suppress
11593 block-local extern declarations (whether used or not) because that
11594 would screw-up the debugger's name lookup mechanism and cause it to
11595 miss things which really ought to be in scope at a given point. */
11596 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11599 /* If we are in terse mode, don't generate any DIEs to represent any
11600 variable declarations or definitions. */
11601 if (debug_info_level <= DINFO_LEVEL_TERSE)
11606 /* Don't emit stubs for types unless they are needed by other DIEs. */
11607 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11610 /* Don't bother trying to generate any DIEs to represent any of the
11611 normal built-in types for the language we are compiling. */
11612 if (DECL_SOURCE_LINE (decl) == 0)
11614 /* OK, we need to generate one for `bool' so GDB knows what type
11615 comparisons have. */
11616 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11617 == DW_LANG_C_plus_plus)
11618 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
11619 && ! DECL_IGNORED_P (decl))
11620 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11625 /* If we are in terse mode, don't generate any DIEs for types. */
11626 if (debug_info_level <= DINFO_LEVEL_TERSE)
11629 /* If we're a function-scope tag, initially use a parent of NULL;
11630 this will be fixed up in decls_for_scope. */
11631 if (decl_function_context (decl))
11632 context_die = NULL;
11640 gen_decl_die (decl, context_die);
11643 /* Output a marker (i.e. a label) for the beginning of the generated code for
11644 a lexical block. */
11647 dwarf2out_begin_block (line, blocknum)
11648 unsigned int line ATTRIBUTE_UNUSED;
11649 unsigned int blocknum;
11651 function_section (current_function_decl);
11652 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11655 /* Output a marker (i.e. a label) for the end of the generated code for a
11659 dwarf2out_end_block (line, blocknum)
11660 unsigned int line ATTRIBUTE_UNUSED;
11661 unsigned int blocknum;
11663 function_section (current_function_decl);
11664 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11667 /* Returns nonzero if it is appropriate not to emit any debugging
11668 information for BLOCK, because it doesn't contain any instructions.
11670 Don't allow this for blocks with nested functions or local classes
11671 as we would end up with orphans, and in the presence of scheduling
11672 we may end up calling them anyway. */
11675 dwarf2out_ignore_block (block)
11680 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11681 if (TREE_CODE (decl) == FUNCTION_DECL
11682 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11688 /* Lookup FILE_NAME (in the list of filenames that we know about here in
11689 dwarf2out.c) and return its "index". The index of each (known) filename is
11690 just a unique number which is associated with only that one filename. We
11691 need such numbers for the sake of generating labels (in the .debug_sfnames
11692 section) and references to those files numbers (in the .debug_srcinfo
11693 and.debug_macinfo sections). If the filename given as an argument is not
11694 found in our current list, add it to the list and assign it the next
11695 available unique index number. In order to speed up searches, we remember
11696 the index of the filename was looked up last. This handles the majority of
11700 lookup_filename (file_name)
11701 const char *file_name;
11705 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11706 if (strcmp (file_name, "<internal>") == 0
11707 || strcmp (file_name, "<built-in>") == 0)
11710 /* Check to see if the file name that was searched on the previous
11711 call matches this file name. If so, return the index. */
11712 if (file_table.last_lookup_index != 0)
11713 if (0 == strcmp (file_name,
11714 file_table.table[file_table.last_lookup_index]))
11715 return file_table.last_lookup_index;
11717 /* Didn't match the previous lookup, search the table */
11718 for (i = 1; i < file_table.in_use; i++)
11719 if (strcmp (file_name, file_table.table[i]) == 0)
11721 file_table.last_lookup_index = i;
11725 /* Prepare to add a new table entry by making sure there is enough space in
11726 the table to do so. If not, expand the current table. */
11727 if (i == file_table.allocated)
11729 file_table.allocated = i + FILE_TABLE_INCREMENT;
11730 file_table.table = (char **)
11731 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11734 /* Add the new entry to the end of the filename table. */
11735 file_table.table[i] = xstrdup (file_name);
11736 file_table.in_use = i + 1;
11737 file_table.last_lookup_index = i;
11739 if (DWARF2_ASM_LINE_DEBUG_INFO)
11740 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11748 /* Allocate the initial hunk of the file_table. */
11749 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11750 file_table.allocated = FILE_TABLE_INCREMENT;
11752 /* Skip the first entry - file numbers begin at 1. */
11753 file_table.in_use = 1;
11754 file_table.last_lookup_index = 0;
11757 /* Output a label to mark the beginning of a source code line entry
11758 and record information relating to this source line, in
11759 'line_info_table' for later output of the .debug_line section. */
11762 dwarf2out_source_line (line, filename)
11764 const char *filename;
11766 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11768 function_section (current_function_decl);
11770 /* If requested, emit something human-readable. */
11771 if (flag_debug_asm)
11772 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11775 if (DWARF2_ASM_LINE_DEBUG_INFO)
11777 unsigned file_num = lookup_filename (filename);
11779 /* Emit the .loc directive understood by GNU as. */
11780 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11782 /* Indicate that line number info exists. */
11783 line_info_table_in_use++;
11785 /* Indicate that multiple line number tables exist. */
11786 if (DECL_SECTION_NAME (current_function_decl))
11787 separate_line_info_table_in_use++;
11789 else if (DECL_SECTION_NAME (current_function_decl))
11791 dw_separate_line_info_ref line_info;
11792 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11793 separate_line_info_table_in_use);
11795 /* expand the line info table if necessary */
11796 if (separate_line_info_table_in_use
11797 == separate_line_info_table_allocated)
11799 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11800 separate_line_info_table
11801 = (dw_separate_line_info_ref)
11802 xrealloc (separate_line_info_table,
11803 separate_line_info_table_allocated
11804 * sizeof (dw_separate_line_info_entry));
11807 /* Add the new entry at the end of the line_info_table. */
11809 = &separate_line_info_table[separate_line_info_table_in_use++];
11810 line_info->dw_file_num = lookup_filename (filename);
11811 line_info->dw_line_num = line;
11812 line_info->function = current_funcdef_number;
11816 dw_line_info_ref line_info;
11818 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11819 line_info_table_in_use);
11821 /* Expand the line info table if necessary. */
11822 if (line_info_table_in_use == line_info_table_allocated)
11824 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11826 = (dw_line_info_ref)
11827 xrealloc (line_info_table,
11828 (line_info_table_allocated
11829 * sizeof (dw_line_info_entry)));
11832 /* Add the new entry at the end of the line_info_table. */
11833 line_info = &line_info_table[line_info_table_in_use++];
11834 line_info->dw_file_num = lookup_filename (filename);
11835 line_info->dw_line_num = line;
11840 /* Record the beginning of a new source file. */
11843 dwarf2out_start_source_file (lineno, filename)
11844 unsigned int lineno;
11845 const char *filename;
11847 if (flag_eliminate_dwarf2_dups)
11849 /* Record the beginning of the file for break_out_includes. */
11850 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
11851 add_AT_string (bincl_die, DW_AT_name, filename);
11854 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11856 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11857 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11858 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11860 dw2_asm_output_data_uleb128 (lookup_filename (filename),
11861 "Filename we just started");
11865 /* Record the end of a source file. */
11868 dwarf2out_end_source_file (lineno)
11869 unsigned int lineno ATTRIBUTE_UNUSED;
11871 if (flag_eliminate_dwarf2_dups)
11872 /* Record the end of the file for break_out_includes. */
11873 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
11875 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11877 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11878 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11882 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11883 the tail part of the directive line, i.e. the part which is past the
11884 initial whitespace, #, whitespace, directive-name, whitespace part. */
11887 dwarf2out_define (lineno, buffer)
11888 unsigned lineno ATTRIBUTE_UNUSED;
11889 const char *buffer ATTRIBUTE_UNUSED;
11891 static int initialized = 0;
11894 dwarf2out_start_source_file (0, primary_filename);
11898 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11900 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11901 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11902 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11903 dw2_asm_output_nstring (buffer, -1, "The macro");
11907 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11908 the tail part of the directive line, i.e. the part which is past the
11909 initial whitespace, #, whitespace, directive-name, whitespace part. */
11912 dwarf2out_undef (lineno, buffer)
11913 unsigned lineno ATTRIBUTE_UNUSED;
11914 const char *buffer ATTRIBUTE_UNUSED;
11916 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11918 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11919 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
11920 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11921 dw2_asm_output_nstring (buffer, -1, "The macro");
11925 /* Set up for Dwarf output at the start of compilation. */
11928 dwarf2out_init (main_input_filename)
11929 const char *main_input_filename;
11931 init_file_table ();
11933 /* Remember the name of the primary input file. */
11934 primary_filename = main_input_filename;
11936 /* Add it to the file table first, under the assumption that we'll
11937 be emitting line number data for it first, which avoids having
11938 to add an initial DW_LNS_set_file. */
11939 lookup_filename (main_input_filename);
11941 /* Allocate the initial hunk of the decl_die_table. */
11943 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11944 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11945 decl_die_table_in_use = 0;
11947 /* Allocate the initial hunk of the decl_scope_table. */
11948 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
11949 ggc_add_tree_varray_root (&decl_scope_table, 1);
11951 /* Allocate the initial hunk of the abbrev_die_table. */
11953 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11954 sizeof (dw_die_ref));
11955 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11956 /* Zero-th entry is allocated, but unused */
11957 abbrev_die_table_in_use = 1;
11959 /* Allocate the initial hunk of the line_info_table. */
11961 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11962 sizeof (dw_line_info_entry));
11963 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11965 /* Zero-th entry is allocated, but unused */
11966 line_info_table_in_use = 1;
11968 /* Generate the initial DIE for the .debug section. Note that the (string)
11969 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11970 will (typically) be a relative pathname and that this pathname should be
11971 taken as being relative to the directory from which the compiler was
11972 invoked when the given (base) source file was compiled. */
11973 comp_unit_die = gen_compile_unit_die (main_input_filename);
11975 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
11976 ggc_add_tree_varray_root (&incomplete_types, 1);
11978 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11979 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11981 ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list);
11983 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11984 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
11985 DEBUG_ABBREV_SECTION_LABEL, 0);
11986 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11987 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11989 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
11991 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11992 DEBUG_INFO_SECTION_LABEL, 0);
11993 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11994 DEBUG_LINE_SECTION_LABEL, 0);
11995 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
11996 DEBUG_RANGES_SECTION_LABEL, 0);
11997 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
11998 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11999 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
12000 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
12001 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12002 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
12004 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12006 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12007 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
12008 DEBUG_MACINFO_SECTION_LABEL, 0);
12009 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
12012 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12015 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
12019 /* Allocate a string in .debug_str hash table. */
12022 indirect_string_alloc (tab)
12023 hash_table *tab ATTRIBUTE_UNUSED;
12025 struct indirect_string_node *node;
12027 node = xmalloc (sizeof (struct indirect_string_node));
12028 node->refcount = 0;
12030 node->label = NULL;
12032 return (hashnode) node;
12035 /* A helper function for dwarf2out_finish called through
12036 ht_forall. Emit one queued .debug_str string. */
12039 output_indirect_string (pfile, h, v)
12040 struct cpp_reader *pfile ATTRIBUTE_UNUSED;
12042 const PTR v ATTRIBUTE_UNUSED;
12044 struct indirect_string_node *node = (struct indirect_string_node *) h;
12046 if (node->form == DW_FORM_strp)
12048 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
12049 ASM_OUTPUT_LABEL (asm_out_file, node->label);
12050 assemble_string ((const char *) HT_STR (&node->id),
12051 HT_LEN (&node->id) + 1);
12057 /* Output stuff that dwarf requires at the end of every file,
12058 and generate the DWARF-2 debugging info. */
12061 dwarf2out_finish (input_filename)
12062 const char *input_filename ATTRIBUTE_UNUSED;
12064 limbo_die_node *node, *next_node;
12065 dw_die_ref die = 0;
12067 /* Traverse the limbo die list, and add parent/child links. The only
12068 dies without parents that should be here are concrete instances of
12069 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12070 For concrete instances, we can get the parent die from the abstract
12072 for (node = limbo_die_list; node; node = next_node)
12074 next_node = node->next;
12077 if (die->die_parent == NULL)
12079 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
12083 add_child_die (origin->die_parent, die);
12084 else if (die == comp_unit_die)
12086 /* If this was an expression for a bound involved in a function
12087 return type, it may be a SAVE_EXPR for which we weren't able
12088 to find a DIE previously. So try now. */
12089 else if (node->created_for
12090 && TREE_CODE (node->created_for) == SAVE_EXPR
12091 && 0 != (origin = (lookup_decl_die
12093 (node->created_for)))))
12094 add_child_die (origin, die);
12095 else if (errorcount > 0 || sorrycount > 0)
12096 /* It's OK to be confused by errors in the input. */
12097 add_child_die (comp_unit_die, die);
12098 else if (node->created_for
12099 && ((DECL_P (node->created_for)
12100 && (context = DECL_CONTEXT (node->created_for)))
12101 || (TYPE_P (node->created_for)
12102 && (context = TYPE_CONTEXT (node->created_for))))
12103 && TREE_CODE (context) == FUNCTION_DECL)
12105 /* In certain situations, the lexical block containing a
12106 nested function can be optimized away, which results
12107 in the nested function die being orphaned. Likewise
12108 with the return type of that nested function. Force
12109 this to be a child of the containing function. */
12110 origin = lookup_decl_die (context);
12113 add_child_die (origin, die);
12122 limbo_die_list = NULL;
12124 /* Walk through the list of incomplete types again, trying once more to
12125 emit full debugging info for them. */
12126 retry_incomplete_types ();
12128 /* We need to reverse all the dies before break_out_includes, or
12129 we'll see the end of an include file before the beginning. */
12130 reverse_all_dies (comp_unit_die);
12132 /* Generate separate CUs for each of the include files we've seen.
12133 They will go into limbo_die_list. */
12134 if (flag_eliminate_dwarf2_dups)
12135 break_out_includes (comp_unit_die);
12137 /* Traverse the DIE's and add add sibling attributes to those DIE's
12138 that have children. */
12139 add_sibling_attributes (comp_unit_die);
12140 for (node = limbo_die_list; node; node = node->next)
12141 add_sibling_attributes (node->die);
12143 /* Output a terminator label for the .text section. */
12145 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
12147 /* Output the source line correspondence table. We must do this
12148 even if there is no line information. Otherwise, on an empty
12149 translation unit, we will generate a present, but empty,
12150 .debug_info section. IRIX 6.5 `nm' will then complain when
12151 examining the file. */
12152 if (! DWARF2_ASM_LINE_DEBUG_INFO)
12154 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12155 output_line_info ();
12158 /* Output location list section if necessary. */
12159 if (have_location_lists)
12161 /* Output the location lists info. */
12162 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
12163 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
12164 DEBUG_LOC_SECTION_LABEL, 0);
12165 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
12166 output_location_lists (die);
12167 have_location_lists = 0;
12170 /* We can only use the low/high_pc attributes if all of the code was
12172 if (separate_line_info_table_in_use == 0)
12174 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
12175 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
12178 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12179 "base address". Use zero so that these addresses become absolute. */
12180 else if (have_location_lists || ranges_table_in_use)
12181 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
12183 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12184 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
12185 debug_line_section_label);
12187 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12188 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
12190 /* Output all of the compilation units. We put the main one last so that
12191 the offsets are available to output_pubnames. */
12192 for (node = limbo_die_list; node; node = node->next)
12193 output_comp_unit (node->die);
12195 output_comp_unit (comp_unit_die);
12197 /* Output the abbreviation table. */
12198 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12199 output_abbrev_section ();
12201 /* Output public names table if necessary. */
12202 if (pubname_table_in_use)
12204 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
12205 output_pubnames ();
12208 /* Output the address range information. We only put functions in the arange
12209 table, so don't write it out if we don't have any. */
12210 if (fde_table_in_use)
12212 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
12216 /* Output ranges section if necessary. */
12217 if (ranges_table_in_use)
12219 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
12220 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12224 /* Have to end the primary source file. */
12225 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12227 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12228 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12231 /* If we emitted any DW_FORM_strp form attribute, output the string
12233 if (debug_str_hash)
12234 ht_forall (debug_str_hash, output_indirect_string, NULL);
12236 #endif /* DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO */