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
43 #include "hard-reg-set.h"
45 #include "insn-config.h"
53 #include "dwarf2out.h"
54 #include "dwarf2asm.h"
60 #include "diagnostic.h"
63 #include "langhooks.h"
64 #include "hashtable.h"
66 #ifdef DWARF2_DEBUGGING_INFO
67 static void dwarf2out_source_line PARAMS ((unsigned int, const char *));
70 /* DWARF2 Abbreviation Glossary:
71 CFA = Canonical Frame Address
72 a fixed address on the stack which identifies a call frame.
73 We define it to be the value of SP just before the call insn.
74 The CFA register and offset, which may change during the course
75 of the function, are used to calculate its value at runtime.
76 CFI = Call Frame Instruction
77 an instruction for the DWARF2 abstract machine
78 CIE = Common Information Entry
79 information describing information common to one or more FDEs
80 DIE = Debugging Information Entry
81 FDE = Frame Description Entry
82 information describing the stack call frame, in particular,
83 how to restore registers
85 DW_CFA_... = DWARF2 CFA call frame instruction
86 DW_TAG_... = DWARF2 DIE tag */
88 /* Decide whether we want to emit frame unwind information for the current
94 return (write_symbols == DWARF2_DEBUG
95 || write_symbols == VMS_AND_DWARF2_DEBUG
96 #ifdef DWARF2_FRAME_INFO
99 #ifdef DWARF2_UNWIND_INFO
100 || flag_unwind_tables
101 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
106 /* The number of the current function definition for which debugging
107 information is being generated. These numbers range from 1 up to the
108 maximum number of function definitions contained within the current
109 compilation unit. These numbers are used to create unique label id's
110 unique to each function definition. */
111 unsigned current_funcdef_number = 0;
113 /* The size of the target's pointer type. */
115 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
118 /* Default version of targetm.eh_frame_section. Note this must appear
119 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
123 default_eh_frame_section ()
125 #ifdef EH_FRAME_SECTION_NAME
126 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
128 tree label = get_file_function_name ('F');
131 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
132 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
133 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
137 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
139 /* How to start an assembler comment. */
140 #ifndef ASM_COMMENT_START
141 #define ASM_COMMENT_START ";#"
144 typedef struct dw_cfi_struct *dw_cfi_ref;
145 typedef struct dw_fde_struct *dw_fde_ref;
146 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
148 /* Call frames are described using a sequence of Call Frame
149 Information instructions. The register number, offset
150 and address fields are provided as possible operands;
151 their use is selected by the opcode field. */
153 typedef union dw_cfi_oprnd_struct
155 unsigned long dw_cfi_reg_num;
156 long int dw_cfi_offset;
157 const char *dw_cfi_addr;
158 struct dw_loc_descr_struct *dw_cfi_loc;
162 typedef struct dw_cfi_struct
164 dw_cfi_ref dw_cfi_next;
165 enum dwarf_call_frame_info dw_cfi_opc;
166 dw_cfi_oprnd dw_cfi_oprnd1;
167 dw_cfi_oprnd dw_cfi_oprnd2;
171 /* This is how we define the location of the CFA. We use to handle it
172 as REG + OFFSET all the time, but now it can be more complex.
173 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
174 Instead of passing around REG and OFFSET, we pass a copy
175 of this structure. */
176 typedef struct cfa_loc
181 int indirect; /* 1 if CFA is accessed via a dereference. */
184 /* All call frame descriptions (FDE's) in the GCC generated DWARF
185 refer to a single Common Information Entry (CIE), defined at
186 the beginning of the .debug_frame section. This use of a single
187 CIE obviates the need to keep track of multiple CIE's
188 in the DWARF generation routines below. */
190 typedef struct dw_fde_struct
192 const char *dw_fde_begin;
193 const char *dw_fde_current_label;
194 const char *dw_fde_end;
195 dw_cfi_ref dw_fde_cfi;
196 unsigned funcdef_number;
197 unsigned nothrow : 1;
198 unsigned uses_eh_lsda : 1;
202 /* Maximum size (in bytes) of an artificially generated label. */
203 #define MAX_ARTIFICIAL_LABEL_BYTES 30
205 /* The size of addresses as they appear in the Dwarf 2 data.
206 Some architectures use word addresses to refer to code locations,
207 but Dwarf 2 info always uses byte addresses. On such machines,
208 Dwarf 2 addresses need to be larger than the architecture's
210 #ifndef DWARF2_ADDR_SIZE
211 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
214 /* The size in bytes of a DWARF field indicating an offset or length
215 relative to a debug info section, specified to be 4 bytes in the
216 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
219 #ifndef DWARF_OFFSET_SIZE
220 #define DWARF_OFFSET_SIZE 4
223 #define DWARF_VERSION 2
225 /* Round SIZE up to the nearest BOUNDARY. */
226 #define DWARF_ROUND(SIZE,BOUNDARY) \
227 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
229 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
230 #ifndef DWARF_CIE_DATA_ALIGNMENT
231 #ifdef STACK_GROWS_DOWNWARD
232 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
234 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
238 /* A pointer to the base of a table that contains frame description
239 information for each routine. */
240 static dw_fde_ref fde_table;
242 /* Number of elements currently allocated for fde_table. */
243 static unsigned fde_table_allocated;
245 /* Number of elements in fde_table currently in use. */
246 static unsigned fde_table_in_use;
248 /* Size (in elements) of increments by which we may expand the
250 #define FDE_TABLE_INCREMENT 256
252 /* A list of call frame insns for the CIE. */
253 static dw_cfi_ref cie_cfi_head;
255 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
256 attribute that accelerates the lookup of the FDE associated
257 with the subprogram. This variable holds the table index of the FDE
258 associated with the current function (body) definition. */
259 static unsigned current_funcdef_fde;
261 struct ht *debug_str_hash;
263 struct indirect_string_node
265 struct ht_identifier id;
266 unsigned int refcount;
271 /* Forward declarations for functions defined in this file. */
273 static char *stripattributes PARAMS ((const char *));
274 static const char *dwarf_cfi_name PARAMS ((unsigned));
275 static dw_cfi_ref new_cfi PARAMS ((void));
276 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
277 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
278 static void lookup_cfa_1 PARAMS ((dw_cfi_ref,
280 static void lookup_cfa PARAMS ((dw_cfa_location *));
281 static void reg_save PARAMS ((const char *, unsigned,
283 static void initial_return_save PARAMS ((rtx));
284 static long stack_adjust_offset PARAMS ((rtx));
285 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
286 static void output_call_frame_info PARAMS ((int));
287 static void dwarf2out_stack_adjust PARAMS ((rtx));
288 static void queue_reg_save PARAMS ((const char *, rtx, long));
289 static void flush_queued_reg_saves PARAMS ((void));
290 static bool clobbers_queued_reg_save PARAMS ((rtx));
291 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
293 /* Support for complex CFA locations. */
294 static void output_cfa_loc PARAMS ((dw_cfi_ref));
295 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
296 struct dw_loc_descr_struct *));
297 static struct dw_loc_descr_struct *build_cfa_loc
298 PARAMS ((dw_cfa_location *));
299 static void def_cfa_1 PARAMS ((const char *,
302 /* How to start an assembler comment. */
303 #ifndef ASM_COMMENT_START
304 #define ASM_COMMENT_START ";#"
307 /* Data and reference forms for relocatable data. */
308 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
309 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
311 /* Pseudo-op for defining a new section. */
312 #ifndef SECTION_ASM_OP
313 #define SECTION_ASM_OP "\t.section\t"
316 #ifndef DEBUG_FRAME_SECTION
317 #define DEBUG_FRAME_SECTION ".debug_frame"
320 #ifndef FUNC_BEGIN_LABEL
321 #define FUNC_BEGIN_LABEL "LFB"
324 #ifndef FUNC_END_LABEL
325 #define FUNC_END_LABEL "LFE"
328 #define FRAME_BEGIN_LABEL "Lframe"
329 #define CIE_AFTER_SIZE_LABEL "LSCIE"
330 #define CIE_END_LABEL "LECIE"
331 #define CIE_LENGTH_LABEL "LLCIE"
332 #define FDE_LABEL "LSFDE"
333 #define FDE_AFTER_SIZE_LABEL "LASFDE"
334 #define FDE_END_LABEL "LEFDE"
335 #define FDE_LENGTH_LABEL "LLFDE"
336 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
337 #define LINE_NUMBER_END_LABEL "LELT"
338 #define LN_PROLOG_AS_LABEL "LASLTP"
339 #define LN_PROLOG_END_LABEL "LELTP"
340 #define DIE_LABEL_PREFIX "DW"
342 /* Definitions of defaults for various types of primitive assembly language
343 output operations. These may be overridden from within the tm.h file,
344 but typically, that is unnecessary. */
347 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
348 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
351 fprintf (FILE, "%s", SET_ASM_OP); \
352 assemble_name (FILE, SY); \
354 assemble_name (FILE, HI); \
356 assemble_name (FILE, LO); \
362 /* The DWARF 2 CFA column which tracks the return address. Normally this
363 is the column for PC, or the first column after all of the hard
365 #ifndef DWARF_FRAME_RETURN_COLUMN
367 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
369 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
373 /* The mapping from gcc register number to DWARF 2 CFA column number. By
374 default, we just provide columns for all registers. */
375 #ifndef DWARF_FRAME_REGNUM
376 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
379 /* The offset from the incoming value of %sp to the top of the stack frame
380 for the current function. */
381 #ifndef INCOMING_FRAME_SP_OFFSET
382 #define INCOMING_FRAME_SP_OFFSET 0
385 /* Hook used by __throw. */
388 expand_builtin_dwarf_fp_regnum ()
390 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
393 /* Return a pointer to a copy of the section string name S with all
394 attributes stripped off, and an asterisk prepended (for assemble_name). */
400 char *stripped = xmalloc (strlen (s) + 2);
405 while (*s && *s != ',')
412 /* Generate code to initialize the register size table. */
415 expand_builtin_init_dwarf_reg_sizes (address)
419 enum machine_mode mode = TYPE_MODE (char_type_node);
420 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
421 rtx mem = gen_rtx_MEM (BLKmode, addr);
423 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
424 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
426 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
427 HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]);
432 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
436 /* Convert a DWARF call frame info. operation to its string name */
439 dwarf_cfi_name (cfi_opc)
444 case DW_CFA_advance_loc:
445 return "DW_CFA_advance_loc";
447 return "DW_CFA_offset";
449 return "DW_CFA_restore";
453 return "DW_CFA_set_loc";
454 case DW_CFA_advance_loc1:
455 return "DW_CFA_advance_loc1";
456 case DW_CFA_advance_loc2:
457 return "DW_CFA_advance_loc2";
458 case DW_CFA_advance_loc4:
459 return "DW_CFA_advance_loc4";
460 case DW_CFA_offset_extended:
461 return "DW_CFA_offset_extended";
462 case DW_CFA_restore_extended:
463 return "DW_CFA_restore_extended";
464 case DW_CFA_undefined:
465 return "DW_CFA_undefined";
466 case DW_CFA_same_value:
467 return "DW_CFA_same_value";
468 case DW_CFA_register:
469 return "DW_CFA_register";
470 case DW_CFA_remember_state:
471 return "DW_CFA_remember_state";
472 case DW_CFA_restore_state:
473 return "DW_CFA_restore_state";
475 return "DW_CFA_def_cfa";
476 case DW_CFA_def_cfa_register:
477 return "DW_CFA_def_cfa_register";
478 case DW_CFA_def_cfa_offset:
479 return "DW_CFA_def_cfa_offset";
482 case DW_CFA_def_cfa_expression:
483 return "DW_CFA_def_cfa_expression";
484 case DW_CFA_expression:
485 return "DW_CFA_expression";
486 case DW_CFA_offset_extended_sf:
487 return "DW_CFA_offset_extended_sf";
488 case DW_CFA_def_cfa_sf:
489 return "DW_CFA_def_cfa_sf";
490 case DW_CFA_def_cfa_offset_sf:
491 return "DW_CFA_def_cfa_offset_sf";
493 /* SGI/MIPS specific */
494 case DW_CFA_MIPS_advance_loc8:
495 return "DW_CFA_MIPS_advance_loc8";
498 case DW_CFA_GNU_window_save:
499 return "DW_CFA_GNU_window_save";
500 case DW_CFA_GNU_args_size:
501 return "DW_CFA_GNU_args_size";
502 case DW_CFA_GNU_negative_offset_extended:
503 return "DW_CFA_GNU_negative_offset_extended";
506 return "DW_CFA_<unknown>";
510 /* Return a pointer to a newly allocated Call Frame Instruction. */
512 static inline dw_cfi_ref
515 dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
517 cfi->dw_cfi_next = NULL;
518 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
519 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
524 /* Add a Call Frame Instruction to list of instructions. */
527 add_cfi (list_head, cfi)
528 dw_cfi_ref *list_head;
533 /* Find the end of the chain. */
534 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
540 /* Generate a new label for the CFI info to refer to. */
543 dwarf2out_cfi_label ()
545 static char label[20];
546 static unsigned long label_num = 0;
548 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
549 ASM_OUTPUT_LABEL (asm_out_file, label);
553 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
554 or to the CIE if LABEL is NULL. */
557 add_fde_cfi (label, cfi)
563 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
566 label = dwarf2out_cfi_label ();
568 if (fde->dw_fde_current_label == NULL
569 || strcmp (label, fde->dw_fde_current_label) != 0)
573 fde->dw_fde_current_label = label = xstrdup (label);
575 /* Set the location counter to the new label. */
577 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
578 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
579 add_cfi (&fde->dw_fde_cfi, xcfi);
582 add_cfi (&fde->dw_fde_cfi, cfi);
586 add_cfi (&cie_cfi_head, cfi);
589 /* Subroutine of lookup_cfa. */
592 lookup_cfa_1 (cfi, loc)
594 dw_cfa_location *loc;
596 switch (cfi->dw_cfi_opc)
598 case DW_CFA_def_cfa_offset:
599 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
601 case DW_CFA_def_cfa_register:
602 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
605 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
606 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
608 case DW_CFA_def_cfa_expression:
609 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
616 /* Find the previous value for the CFA. */
620 dw_cfa_location *loc;
624 loc->reg = (unsigned long) -1;
627 loc->base_offset = 0;
629 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
630 lookup_cfa_1 (cfi, loc);
632 if (fde_table_in_use)
634 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
635 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
636 lookup_cfa_1 (cfi, loc);
640 /* The current rule for calculating the DWARF2 canonical frame address. */
641 static dw_cfa_location cfa;
643 /* The register used for saving registers to the stack, and its offset
645 static dw_cfa_location cfa_store;
647 /* The running total of the size of arguments pushed onto the stack. */
648 static long args_size;
650 /* The last args_size we actually output. */
651 static long old_args_size;
653 /* Entry point to update the canonical frame address (CFA).
654 LABEL is passed to add_fde_cfi. The value of CFA is now to be
655 calculated from REG+OFFSET. */
658 dwarf2out_def_cfa (label, reg, offset)
668 def_cfa_1 (label, &loc);
671 /* This routine does the actual work. The CFA is now calculated from
672 the dw_cfa_location structure. */
675 def_cfa_1 (label, loc_p)
677 dw_cfa_location *loc_p;
680 dw_cfa_location old_cfa, loc;
685 if (cfa_store.reg == loc.reg && loc.indirect == 0)
686 cfa_store.offset = loc.offset;
688 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
689 lookup_cfa (&old_cfa);
691 /* If nothing changed, no need to issue any call frame instructions. */
692 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
693 && loc.indirect == old_cfa.indirect
694 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
699 if (loc.reg == old_cfa.reg && !loc.indirect)
701 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
702 indicating the CFA register did not change but the offset
704 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
705 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
708 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
709 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
712 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
713 indicating the CFA register has changed to <register> but the
714 offset has not changed. */
715 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
716 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
720 else if (loc.indirect == 0)
722 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
723 indicating the CFA register has changed to <register> with
724 the specified offset. */
725 cfi->dw_cfi_opc = DW_CFA_def_cfa;
726 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
727 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
731 /* Construct a DW_CFA_def_cfa_expression instruction to
732 calculate the CFA using a full location expression since no
733 register-offset pair is available. */
734 struct dw_loc_descr_struct *loc_list;
736 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
737 loc_list = build_cfa_loc (&loc);
738 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
741 add_fde_cfi (label, cfi);
744 /* Add the CFI for saving a register. REG is the CFA column number.
745 LABEL is passed to add_fde_cfi.
746 If SREG is -1, the register is saved at OFFSET from the CFA;
747 otherwise it is saved in SREG. */
750 reg_save (label, reg, sreg, offset)
756 dw_cfi_ref cfi = new_cfi ();
758 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
760 /* The following comparison is correct. -1 is used to indicate that
761 the value isn't a register number. */
762 if (sreg == (unsigned int) -1)
765 /* The register number won't fit in 6 bits, so we have to use
767 cfi->dw_cfi_opc = DW_CFA_offset_extended;
769 cfi->dw_cfi_opc = DW_CFA_offset;
771 #ifdef ENABLE_CHECKING
773 /* If we get an offset that is not a multiple of
774 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
775 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
777 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
779 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
783 offset /= DWARF_CIE_DATA_ALIGNMENT;
785 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
787 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
789 else if (sreg == reg)
790 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
794 cfi->dw_cfi_opc = DW_CFA_register;
795 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
798 add_fde_cfi (label, cfi);
801 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
802 This CFI tells the unwinder that it needs to restore the window registers
803 from the previous frame's window save area.
805 ??? Perhaps we should note in the CIE where windows are saved (instead of
806 assuming 0(cfa)) and what registers are in the window. */
809 dwarf2out_window_save (label)
812 dw_cfi_ref cfi = new_cfi ();
814 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
815 add_fde_cfi (label, cfi);
818 /* Add a CFI to update the running total of the size of arguments
819 pushed onto the stack. */
822 dwarf2out_args_size (label, size)
828 if (size == old_args_size)
831 old_args_size = size;
834 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
835 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
836 add_fde_cfi (label, cfi);
839 /* Entry point for saving a register to the stack. REG is the GCC register
840 number. LABEL and OFFSET are passed to reg_save. */
843 dwarf2out_reg_save (label, reg, offset)
848 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
851 /* Entry point for saving the return address in the stack.
852 LABEL and OFFSET are passed to reg_save. */
855 dwarf2out_return_save (label, offset)
859 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
862 /* Entry point for saving the return address in a register.
863 LABEL and SREG are passed to reg_save. */
866 dwarf2out_return_reg (label, sreg)
870 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
873 /* Record the initial position of the return address. RTL is
874 INCOMING_RETURN_ADDR_RTX. */
877 initial_return_save (rtl)
880 unsigned int reg = (unsigned int) -1;
881 HOST_WIDE_INT offset = 0;
883 switch (GET_CODE (rtl))
886 /* RA is in a register. */
887 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
891 /* RA is on the stack. */
893 switch (GET_CODE (rtl))
896 if (REGNO (rtl) != STACK_POINTER_REGNUM)
902 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
904 offset = INTVAL (XEXP (rtl, 1));
908 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
910 offset = -INTVAL (XEXP (rtl, 1));
920 /* The return address is at some offset from any value we can
921 actually load. For instance, on the SPARC it is in %i7+8. Just
922 ignore the offset for now; it doesn't matter for unwinding frames. */
923 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
925 initial_return_save (XEXP (rtl, 0));
932 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
935 /* Given a SET, calculate the amount of stack adjustment it
939 stack_adjust_offset (pattern)
942 rtx src = SET_SRC (pattern);
943 rtx dest = SET_DEST (pattern);
944 HOST_WIDE_INT offset = 0;
947 if (dest == stack_pointer_rtx)
949 /* (set (reg sp) (plus (reg sp) (const_int))) */
950 code = GET_CODE (src);
951 if (! (code == PLUS || code == MINUS)
952 || XEXP (src, 0) != stack_pointer_rtx
953 || GET_CODE (XEXP (src, 1)) != CONST_INT)
956 offset = INTVAL (XEXP (src, 1));
960 else if (GET_CODE (dest) == MEM)
962 /* (set (mem (pre_dec (reg sp))) (foo)) */
963 src = XEXP (dest, 0);
964 code = GET_CODE (src);
970 if (XEXP (src, 0) == stack_pointer_rtx)
972 rtx val = XEXP (XEXP (src, 1), 1);
973 /* We handle only adjustments by constant amount. */
974 if (GET_CODE (XEXP (src, 1)) != PLUS ||
975 GET_CODE (val) != CONST_INT)
977 offset = -INTVAL (val);
984 if (XEXP (src, 0) == stack_pointer_rtx)
986 offset = GET_MODE_SIZE (GET_MODE (dest));
993 if (XEXP (src, 0) == stack_pointer_rtx)
995 offset = -GET_MODE_SIZE (GET_MODE (dest));
1010 /* Check INSN to see if it looks like a push or a stack adjustment, and
1011 make a note of it if it does. EH uses this information to find out how
1012 much extra space it needs to pop off the stack. */
1015 dwarf2out_stack_adjust (insn)
1018 HOST_WIDE_INT offset;
1022 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1024 /* Extract the size of the args from the CALL rtx itself. */
1025 insn = PATTERN (insn);
1026 if (GET_CODE (insn) == PARALLEL)
1027 insn = XVECEXP (insn, 0, 0);
1028 if (GET_CODE (insn) == SET)
1029 insn = SET_SRC (insn);
1030 if (GET_CODE (insn) != CALL)
1033 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1037 /* If only calls can throw, and we have a frame pointer,
1038 save up adjustments until we see the CALL_INSN. */
1039 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1042 if (GET_CODE (insn) == BARRIER)
1044 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1045 the compiler will have already emitted a stack adjustment, but
1046 doesn't bother for calls to noreturn functions. */
1047 #ifdef STACK_GROWS_DOWNWARD
1048 offset = -args_size;
1053 else if (GET_CODE (PATTERN (insn)) == SET)
1054 offset = stack_adjust_offset (PATTERN (insn));
1055 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1056 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1058 /* There may be stack adjustments inside compound insns. Search
1060 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1061 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1062 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1070 if (cfa.reg == STACK_POINTER_REGNUM)
1071 cfa.offset += offset;
1073 #ifndef STACK_GROWS_DOWNWARD
1077 args_size += offset;
1081 label = dwarf2out_cfi_label ();
1082 def_cfa_1 (label, &cfa);
1083 dwarf2out_args_size (label, args_size);
1086 /* We delay emitting a register save until either (a) we reach the end
1087 of the prologue or (b) the register is clobbered. This clusters
1088 register saves so that there are fewer pc advances. */
1090 struct queued_reg_save
1092 struct queued_reg_save *next;
1097 static struct queued_reg_save *queued_reg_saves;
1098 static const char *last_reg_save_label;
1101 queue_reg_save (label, reg, offset)
1106 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1108 q->next = queued_reg_saves;
1110 q->cfa_offset = offset;
1111 queued_reg_saves = q;
1113 last_reg_save_label = label;
1117 flush_queued_reg_saves ()
1119 struct queued_reg_save *q, *next;
1121 for (q = queued_reg_saves; q; q = next)
1123 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1128 queued_reg_saves = NULL;
1129 last_reg_save_label = NULL;
1133 clobbers_queued_reg_save (insn)
1136 struct queued_reg_save *q;
1138 for (q = queued_reg_saves; q; q = q->next)
1139 if (modified_in_p (q->reg, insn))
1146 /* A temporary register holding an integral value used in adjusting SP
1147 or setting up the store_reg. The "offset" field holds the integer
1148 value, not an offset. */
1149 static dw_cfa_location cfa_temp;
1151 /* Record call frame debugging information for an expression EXPR,
1152 which either sets SP or FP (adjusting how we calculate the frame
1153 address) or saves a register to the stack. LABEL indicates the
1156 This function encodes a state machine mapping rtxes to actions on
1157 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1158 users need not read the source code.
1160 The High-Level Picture
1162 Changes in the register we use to calculate the CFA: Currently we
1163 assume that if you copy the CFA register into another register, we
1164 should take the other one as the new CFA register; this seems to
1165 work pretty well. If it's wrong for some target, it's simple
1166 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1168 Changes in the register we use for saving registers to the stack:
1169 This is usually SP, but not always. Again, we deduce that if you
1170 copy SP into another register (and SP is not the CFA register),
1171 then the new register is the one we will be using for register
1172 saves. This also seems to work.
1174 Register saves: There's not much guesswork about this one; if
1175 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1176 register save, and the register used to calculate the destination
1177 had better be the one we think we're using for this purpose.
1179 Except: If the register being saved is the CFA register, and the
1180 offset is non-zero, we are saving the CFA, so we assume we have to
1181 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1182 the intent is to save the value of SP from the previous frame.
1184 Invariants / Summaries of Rules
1186 cfa current rule for calculating the CFA. It usually
1187 consists of a register and an offset.
1188 cfa_store register used by prologue code to save things to the stack
1189 cfa_store.offset is the offset from the value of
1190 cfa_store.reg to the actual CFA
1191 cfa_temp register holding an integral value. cfa_temp.offset
1192 stores the value, which will be used to adjust the
1193 stack pointer. cfa_temp is also used like cfa_store,
1194 to track stores to the stack via fp or a temp reg.
1196 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1197 with cfa.reg as the first operand changes the cfa.reg and its
1198 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1201 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1202 expression yielding a constant. This sets cfa_temp.reg
1203 and cfa_temp.offset.
1205 Rule 5: Create a new register cfa_store used to save items to the
1208 Rules 10-14: Save a register to the stack. Define offset as the
1209 difference of the original location and cfa_store's
1210 location (or cfa_temp's location if cfa_temp is used).
1214 "{a,b}" indicates a choice of a xor b.
1215 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1218 (set <reg1> <reg2>:cfa.reg)
1219 effects: cfa.reg = <reg1>
1220 cfa.offset unchanged
1221 cfa_temp.reg = <reg1>
1222 cfa_temp.offset = cfa.offset
1225 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1226 {<const_int>,<reg>:cfa_temp.reg}))
1227 effects: cfa.reg = sp if fp used
1228 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1229 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1230 if cfa_store.reg==sp
1233 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1234 effects: cfa.reg = fp
1235 cfa_offset += +/- <const_int>
1238 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1239 constraints: <reg1> != fp
1241 effects: cfa.reg = <reg1>
1242 cfa_temp.reg = <reg1>
1243 cfa_temp.offset = cfa.offset
1246 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1247 constraints: <reg1> != fp
1249 effects: cfa_store.reg = <reg1>
1250 cfa_store.offset = cfa.offset - cfa_temp.offset
1253 (set <reg> <const_int>)
1254 effects: cfa_temp.reg = <reg>
1255 cfa_temp.offset = <const_int>
1258 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1259 effects: cfa_temp.reg = <reg1>
1260 cfa_temp.offset |= <const_int>
1263 (set <reg> (high <exp>))
1267 (set <reg> (lo_sum <exp> <const_int>))
1268 effects: cfa_temp.reg = <reg>
1269 cfa_temp.offset = <const_int>
1272 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1273 effects: cfa_store.offset -= <const_int>
1274 cfa.offset = cfa_store.offset if cfa.reg == sp
1276 cfa.base_offset = -cfa_store.offset
1279 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1280 effects: cfa_store.offset += -/+ mode_size(mem)
1281 cfa.offset = cfa_store.offset if cfa.reg == sp
1283 cfa.base_offset = -cfa_store.offset
1286 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1289 effects: cfa.reg = <reg1>
1290 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1293 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1294 effects: cfa.reg = <reg1>
1295 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1298 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1299 effects: cfa.reg = <reg1>
1300 cfa.base_offset = -cfa_temp.offset
1301 cfa_temp.offset -= mode_size(mem) */
1304 dwarf2out_frame_debug_expr (expr, label)
1309 HOST_WIDE_INT offset;
1311 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1312 the PARALLEL independently. The first element is always processed if
1313 it is a SET. This is for backward compatibility. Other elements
1314 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1315 flag is set in them. */
1316 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1319 int limit = XVECLEN (expr, 0);
1321 for (par_index = 0; par_index < limit; par_index++)
1322 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1323 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1325 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1330 if (GET_CODE (expr) != SET)
1333 src = SET_SRC (expr);
1334 dest = SET_DEST (expr);
1336 switch (GET_CODE (dest))
1340 /* Update the CFA rule wrt SP or FP. Make sure src is
1341 relative to the current CFA register. */
1342 switch (GET_CODE (src))
1344 /* Setting FP from SP. */
1346 if (cfa.reg == (unsigned) REGNO (src))
1352 /* We used to require that dest be either SP or FP, but the
1353 ARM copies SP to a temporary register, and from there to
1354 FP. So we just rely on the backends to only set
1355 RTX_FRAME_RELATED_P on appropriate insns. */
1356 cfa.reg = REGNO (dest);
1357 cfa_temp.reg = cfa.reg;
1358 cfa_temp.offset = cfa.offset;
1364 if (dest == stack_pointer_rtx)
1368 switch (GET_CODE (XEXP (src, 1)))
1371 offset = INTVAL (XEXP (src, 1));
1374 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1376 offset = cfa_temp.offset;
1382 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1384 /* Restoring SP from FP in the epilogue. */
1385 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1387 cfa.reg = STACK_POINTER_REGNUM;
1389 else if (GET_CODE (src) == LO_SUM)
1390 /* Assume we've set the source reg of the LO_SUM from sp. */
1392 else if (XEXP (src, 0) != stack_pointer_rtx)
1395 if (GET_CODE (src) != MINUS)
1397 if (cfa.reg == STACK_POINTER_REGNUM)
1398 cfa.offset += offset;
1399 if (cfa_store.reg == STACK_POINTER_REGNUM)
1400 cfa_store.offset += offset;
1402 else if (dest == hard_frame_pointer_rtx)
1405 /* Either setting the FP from an offset of the SP,
1406 or adjusting the FP */
1407 if (! frame_pointer_needed)
1410 if (GET_CODE (XEXP (src, 0)) == REG
1411 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1412 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1414 offset = INTVAL (XEXP (src, 1));
1415 if (GET_CODE (src) != MINUS)
1417 cfa.offset += offset;
1418 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1425 if (GET_CODE (src) == MINUS)
1429 if (GET_CODE (XEXP (src, 0)) == REG
1430 && REGNO (XEXP (src, 0)) == cfa.reg
1431 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1433 /* Setting a temporary CFA register that will be copied
1434 into the FP later on. */
1435 offset = - INTVAL (XEXP (src, 1));
1436 cfa.offset += offset;
1437 cfa.reg = REGNO (dest);
1438 /* Or used to save regs to the stack. */
1439 cfa_temp.reg = cfa.reg;
1440 cfa_temp.offset = cfa.offset;
1444 else if (GET_CODE (XEXP (src, 0)) == REG
1445 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1446 && XEXP (src, 1) == stack_pointer_rtx)
1448 /* Setting a scratch register that we will use instead
1449 of SP for saving registers to the stack. */
1450 if (cfa.reg != STACK_POINTER_REGNUM)
1452 cfa_store.reg = REGNO (dest);
1453 cfa_store.offset = cfa.offset - cfa_temp.offset;
1457 else if (GET_CODE (src) == LO_SUM
1458 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1460 cfa_temp.reg = REGNO (dest);
1461 cfa_temp.offset = INTVAL (XEXP (src, 1));
1470 cfa_temp.reg = REGNO (dest);
1471 cfa_temp.offset = INTVAL (src);
1476 if (GET_CODE (XEXP (src, 0)) != REG
1477 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1478 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1481 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1482 cfa_temp.reg = REGNO (dest);
1483 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1486 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1487 which will fill in all of the bits. */
1496 def_cfa_1 (label, &cfa);
1500 if (GET_CODE (src) != REG)
1503 /* Saving a register to the stack. Make sure dest is relative to the
1505 switch (GET_CODE (XEXP (dest, 0)))
1510 /* We can't handle variable size modifications. */
1511 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1513 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1515 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1516 || cfa_store.reg != STACK_POINTER_REGNUM)
1519 cfa_store.offset += offset;
1520 if (cfa.reg == STACK_POINTER_REGNUM)
1521 cfa.offset = cfa_store.offset;
1523 offset = -cfa_store.offset;
1529 offset = GET_MODE_SIZE (GET_MODE (dest));
1530 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1533 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1534 || cfa_store.reg != STACK_POINTER_REGNUM)
1537 cfa_store.offset += offset;
1538 if (cfa.reg == STACK_POINTER_REGNUM)
1539 cfa.offset = cfa_store.offset;
1541 offset = -cfa_store.offset;
1545 /* With an offset. */
1549 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1551 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1552 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1555 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1556 offset -= cfa_store.offset;
1557 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1558 offset -= cfa_temp.offset;
1564 /* Without an offset. */
1566 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1567 offset = -cfa_store.offset;
1568 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1569 offset = -cfa_temp.offset;
1576 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1578 offset = -cfa_temp.offset;
1579 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1586 if (REGNO (src) != STACK_POINTER_REGNUM
1587 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1588 && (unsigned) REGNO (src) == cfa.reg)
1590 /* We're storing the current CFA reg into the stack. */
1592 if (cfa.offset == 0)
1594 /* If the source register is exactly the CFA, assume
1595 we're saving SP like any other register; this happens
1597 def_cfa_1 (label, &cfa);
1598 queue_reg_save (label, stack_pointer_rtx, offset);
1603 /* Otherwise, we'll need to look in the stack to
1604 calculate the CFA. */
1605 rtx x = XEXP (dest, 0);
1607 if (GET_CODE (x) != REG)
1609 if (GET_CODE (x) != REG)
1612 cfa.reg = REGNO (x);
1613 cfa.base_offset = offset;
1615 def_cfa_1 (label, &cfa);
1620 def_cfa_1 (label, &cfa);
1621 queue_reg_save (label, src, offset);
1629 /* Record call frame debugging information for INSN, which either
1630 sets SP or FP (adjusting how we calculate the frame address) or saves a
1631 register to the stack. If INSN is NULL_RTX, initialize our state. */
1634 dwarf2out_frame_debug (insn)
1640 if (insn == NULL_RTX)
1642 /* Flush any queued register saves. */
1643 flush_queued_reg_saves ();
1645 /* Set up state for generating call frame debug info. */
1647 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1650 cfa.reg = STACK_POINTER_REGNUM;
1653 cfa_temp.offset = 0;
1657 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1658 flush_queued_reg_saves ();
1660 if (! RTX_FRAME_RELATED_P (insn))
1662 if (!ACCUMULATE_OUTGOING_ARGS)
1663 dwarf2out_stack_adjust (insn);
1668 label = dwarf2out_cfi_label ();
1669 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1671 insn = XEXP (src, 0);
1673 insn = PATTERN (insn);
1675 dwarf2out_frame_debug_expr (insn, label);
1678 /* Output a Call Frame Information opcode and its operand(s). */
1681 output_cfi (cfi, fde, for_eh)
1686 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1687 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1688 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1689 "DW_CFA_advance_loc 0x%lx",
1690 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1691 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1693 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1694 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1695 "DW_CFA_offset, column 0x%lx",
1696 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1697 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1699 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1700 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1701 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1702 "DW_CFA_restore, column 0x%lx",
1703 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1706 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1707 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1709 switch (cfi->dw_cfi_opc)
1711 case DW_CFA_set_loc:
1713 dw2_asm_output_encoded_addr_rtx (
1714 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1715 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1718 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1719 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1722 case DW_CFA_advance_loc1:
1723 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1724 fde->dw_fde_current_label, NULL);
1725 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1728 case DW_CFA_advance_loc2:
1729 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1730 fde->dw_fde_current_label, NULL);
1731 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1734 case DW_CFA_advance_loc4:
1735 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1736 fde->dw_fde_current_label, NULL);
1737 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1740 case DW_CFA_MIPS_advance_loc8:
1741 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1742 fde->dw_fde_current_label, NULL);
1743 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1746 case DW_CFA_offset_extended:
1747 case DW_CFA_def_cfa:
1748 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1750 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1753 case DW_CFA_offset_extended_sf:
1754 case DW_CFA_def_cfa_sf:
1755 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1757 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1760 case DW_CFA_restore_extended:
1761 case DW_CFA_undefined:
1762 case DW_CFA_same_value:
1763 case DW_CFA_def_cfa_register:
1764 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1768 case DW_CFA_register:
1769 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1771 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1775 case DW_CFA_def_cfa_offset:
1776 case DW_CFA_GNU_args_size:
1777 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1780 case DW_CFA_def_cfa_offset_sf:
1781 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1784 case DW_CFA_GNU_window_save:
1787 case DW_CFA_def_cfa_expression:
1788 case DW_CFA_expression:
1789 output_cfa_loc (cfi);
1792 case DW_CFA_GNU_negative_offset_extended:
1793 /* Obsoleted by DW_CFA_offset_extended_sf. */
1802 /* Output the call frame information used to used to record information
1803 that relates to calculating the frame pointer, and records the
1804 location of saved registers. */
1807 output_call_frame_info (for_eh)
1813 char l1[20], l2[20], section_start_label[20];
1814 int any_lsda_needed = 0;
1815 char augmentation[6];
1816 int augmentation_size;
1817 int fde_encoding = DW_EH_PE_absptr;
1818 int per_encoding = DW_EH_PE_absptr;
1819 int lsda_encoding = DW_EH_PE_absptr;
1821 /* Don't emit a CIE if there won't be any FDEs. */
1822 if (fde_table_in_use == 0)
1825 /* If we don't have any functions we'll want to unwind out of, don't emit any
1826 EH unwind information. */
1829 int any_eh_needed = flag_asynchronous_unwind_tables;
1831 for (i = 0; i < fde_table_in_use; i++)
1832 if (fde_table[i].uses_eh_lsda)
1833 any_eh_needed = any_lsda_needed = 1;
1834 else if (! fde_table[i].nothrow)
1837 if (! any_eh_needed)
1841 /* We're going to be generating comments, so turn on app. */
1846 (*targetm.asm_out.eh_frame_section) ();
1848 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1850 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1851 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1853 /* Output the CIE. */
1854 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1855 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1856 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1857 "Length of Common Information Entry");
1858 ASM_OUTPUT_LABEL (asm_out_file, l1);
1860 /* Now that the CIE pointer is PC-relative for EH,
1861 use 0 to identify the CIE. */
1862 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1863 (for_eh ? 0 : DW_CIE_ID),
1864 "CIE Identifier Tag");
1866 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1868 augmentation[0] = 0;
1869 augmentation_size = 0;
1875 z Indicates that a uleb128 is present to size the
1876 augmentation section.
1877 L Indicates the encoding (and thus presence) of
1878 an LSDA pointer in the FDE augmentation.
1879 R Indicates a non-default pointer encoding for
1881 P Indicates the presence of an encoding + language
1882 personality routine in the CIE augmentation. */
1884 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1885 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1886 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1888 p = augmentation + 1;
1889 if (eh_personality_libfunc)
1892 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1894 if (any_lsda_needed)
1897 augmentation_size += 1;
1899 if (fde_encoding != DW_EH_PE_absptr)
1902 augmentation_size += 1;
1904 if (p > augmentation + 1)
1906 augmentation[0] = 'z';
1910 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1911 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1913 int offset = ( 4 /* Length */
1915 + 1 /* CIE version */
1916 + strlen (augmentation) + 1 /* Augmentation */
1917 + size_of_uleb128 (1) /* Code alignment */
1918 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1920 + 1 /* Augmentation size */
1921 + 1 /* Personality encoding */ );
1922 int pad = -offset & (PTR_SIZE - 1);
1924 augmentation_size += pad;
1926 /* Augmentations should be small, so there's scarce need to
1927 iterate for a solution. Die if we exceed one uleb128 byte. */
1928 if (size_of_uleb128 (augmentation_size) != 1)
1933 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1934 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1935 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1936 "CIE Data Alignment Factor");
1937 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1939 if (augmentation[0])
1941 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1942 if (eh_personality_libfunc)
1944 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1945 eh_data_format_name (per_encoding));
1946 dw2_asm_output_encoded_addr_rtx (per_encoding,
1947 eh_personality_libfunc, NULL);
1950 if (any_lsda_needed)
1951 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1952 eh_data_format_name (lsda_encoding));
1954 if (fde_encoding != DW_EH_PE_absptr)
1955 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1956 eh_data_format_name (fde_encoding));
1959 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1960 output_cfi (cfi, NULL, for_eh);
1962 /* Pad the CIE out to an address sized boundary. */
1963 ASM_OUTPUT_ALIGN (asm_out_file,
1964 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1965 ASM_OUTPUT_LABEL (asm_out_file, l2);
1967 /* Loop through all of the FDE's. */
1968 for (i = 0; i < fde_table_in_use; i++)
1970 fde = &fde_table[i];
1972 /* Don't emit EH unwind info for leaf functions that don't need it. */
1973 if (!flag_asynchronous_unwind_tables && for_eh && fde->nothrow
1974 && ! fde->uses_eh_lsda)
1977 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1978 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1979 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1980 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1982 ASM_OUTPUT_LABEL (asm_out_file, l1);
1985 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
1987 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
1992 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1993 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1994 "FDE initial location");
1995 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1996 fde->dw_fde_end, fde->dw_fde_begin,
1997 "FDE address range");
2001 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2002 "FDE initial location");
2003 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2004 fde->dw_fde_end, fde->dw_fde_begin,
2005 "FDE address range");
2008 if (augmentation[0])
2010 if (any_lsda_needed)
2012 int size = size_of_encoded_value (lsda_encoding);
2014 if (lsda_encoding == DW_EH_PE_aligned)
2016 int offset = ( 4 /* Length */
2017 + 4 /* CIE offset */
2018 + 2 * size_of_encoded_value (fde_encoding)
2019 + 1 /* Augmentation size */ );
2020 int pad = -offset & (PTR_SIZE - 1);
2023 if (size_of_uleb128 (size) != 1)
2027 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2029 if (fde->uses_eh_lsda)
2031 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2032 fde->funcdef_number);
2033 dw2_asm_output_encoded_addr_rtx (
2034 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2035 "Language Specific Data Area");
2039 if (lsda_encoding == DW_EH_PE_aligned)
2040 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2042 (size_of_encoded_value (lsda_encoding), 0,
2043 "Language Specific Data Area (none)");
2047 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2050 /* Loop through the Call Frame Instructions associated with
2052 fde->dw_fde_current_label = fde->dw_fde_begin;
2053 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2054 output_cfi (cfi, fde, for_eh);
2056 /* Pad the FDE out to an address sized boundary. */
2057 ASM_OUTPUT_ALIGN (asm_out_file,
2058 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2059 ASM_OUTPUT_LABEL (asm_out_file, l2);
2062 #ifndef EH_FRAME_SECTION_NAME
2064 dw2_asm_output_data (4, 0, "End of Table");
2066 #ifdef MIPS_DEBUGGING_INFO
2067 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2068 get a value of 0. Putting .align 0 after the label fixes it. */
2069 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2072 /* Turn off app to make assembly quicker. */
2077 /* Output a marker (i.e. a label) for the beginning of a function, before
2081 dwarf2out_begin_prologue (line, file)
2082 unsigned int line ATTRIBUTE_UNUSED;
2083 const char *file ATTRIBUTE_UNUSED;
2085 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2088 current_function_func_begin_label = 0;
2090 #ifdef IA64_UNWIND_INFO
2091 /* ??? current_function_func_begin_label is also used by except.c
2092 for call-site information. We must emit this label if it might
2094 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2095 && ! dwarf2out_do_frame ())
2098 if (! dwarf2out_do_frame ())
2102 current_funcdef_number++;
2103 function_section (current_function_decl);
2104 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2105 current_funcdef_number);
2106 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2107 current_funcdef_number);
2108 current_function_func_begin_label = get_identifier (label);
2110 #ifdef IA64_UNWIND_INFO
2111 /* We can elide the fde allocation if we're not emitting debug info. */
2112 if (! dwarf2out_do_frame ())
2116 /* Expand the fde table if necessary. */
2117 if (fde_table_in_use == fde_table_allocated)
2119 fde_table_allocated += FDE_TABLE_INCREMENT;
2121 = (dw_fde_ref) xrealloc (fde_table,
2122 fde_table_allocated * sizeof (dw_fde_node));
2125 /* Record the FDE associated with this function. */
2126 current_funcdef_fde = fde_table_in_use;
2128 /* Add the new FDE at the end of the fde_table. */
2129 fde = &fde_table[fde_table_in_use++];
2130 fde->dw_fde_begin = xstrdup (label);
2131 fde->dw_fde_current_label = NULL;
2132 fde->dw_fde_end = NULL;
2133 fde->dw_fde_cfi = NULL;
2134 fde->funcdef_number = current_funcdef_number;
2135 fde->nothrow = current_function_nothrow;
2136 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2138 args_size = old_args_size = 0;
2140 /* We only want to output line number information for the genuine dwarf2
2141 prologue case, not the eh frame case. */
2142 #ifdef DWARF2_DEBUGGING_INFO
2144 dwarf2out_source_line (line, file);
2148 /* Output a marker (i.e. a label) for the absolute end of the generated code
2149 for a function definition. This gets called *after* the epilogue code has
2153 dwarf2out_end_epilogue ()
2156 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2158 /* Output a label to mark the endpoint of the code generated for this
2160 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2161 ASM_OUTPUT_LABEL (asm_out_file, label);
2162 fde = &fde_table[fde_table_in_use - 1];
2163 fde->dw_fde_end = xstrdup (label);
2167 dwarf2out_frame_init ()
2169 /* Allocate the initial hunk of the fde_table. */
2170 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2171 fde_table_allocated = FDE_TABLE_INCREMENT;
2172 fde_table_in_use = 0;
2174 /* Generate the CFA instructions common to all FDE's. Do it now for the
2175 sake of lookup_cfa. */
2177 #ifdef DWARF2_UNWIND_INFO
2178 /* On entry, the Canonical Frame Address is at SP. */
2179 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2180 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2185 dwarf2out_frame_finish ()
2187 /* Output call frame information. */
2188 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2189 output_call_frame_info (0);
2191 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2192 output_call_frame_info (1);
2195 /* And now, the subset of the debugging information support code necessary
2196 for emitting location expressions. */
2198 typedef struct dw_val_struct *dw_val_ref;
2199 typedef struct die_struct *dw_die_ref;
2200 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2201 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2203 /* Each DIE may have a series of attribute/value pairs. Values
2204 can take on several forms. The forms that are used in this
2205 implementation are listed below. */
2210 dw_val_class_offset,
2212 dw_val_class_loc_list,
2213 dw_val_class_range_list,
2215 dw_val_class_unsigned_const,
2216 dw_val_class_long_long,
2219 dw_val_class_die_ref,
2220 dw_val_class_fde_ref,
2221 dw_val_class_lbl_id,
2222 dw_val_class_lbl_offset,
2227 /* Describe a double word constant value. */
2228 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2230 typedef struct dw_long_long_struct
2237 /* Describe a floating point constant value. */
2239 typedef struct dw_fp_struct
2246 /* The dw_val_node describes an attribute's value, as it is
2247 represented internally. */
2249 typedef struct dw_val_struct
2251 dw_val_class val_class;
2255 long unsigned val_offset;
2256 dw_loc_list_ref val_loc_list;
2257 dw_loc_descr_ref val_loc;
2259 long unsigned val_unsigned;
2260 dw_long_long_const val_long_long;
2261 dw_float_const val_float;
2267 unsigned val_fde_index;
2268 struct indirect_string_node *val_str;
2270 unsigned char val_flag;
2276 /* Locations in memory are described using a sequence of stack machine
2279 typedef struct dw_loc_descr_struct
2281 dw_loc_descr_ref dw_loc_next;
2282 enum dwarf_location_atom dw_loc_opc;
2283 dw_val_node dw_loc_oprnd1;
2284 dw_val_node dw_loc_oprnd2;
2289 /* Location lists are ranges + location descriptions for that range,
2290 so you can track variables that are in different places over
2291 their entire life. */
2292 typedef struct dw_loc_list_struct
2294 dw_loc_list_ref dw_loc_next;
2295 const char *begin; /* Label for begin address of range */
2296 const char *end; /* Label for end address of range */
2297 char *ll_symbol; /* Label for beginning of location list.
2298 Only on head of list */
2299 const char *section; /* Section this loclist is relative to */
2300 dw_loc_descr_ref expr;
2303 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2304 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2307 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2309 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2310 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2311 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2312 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2314 /* Convert a DWARF stack opcode into its string name. */
2317 dwarf_stack_op_name (op)
2323 return "DW_OP_addr";
2325 return "DW_OP_deref";
2327 return "DW_OP_const1u";
2329 return "DW_OP_const1s";
2331 return "DW_OP_const2u";
2333 return "DW_OP_const2s";
2335 return "DW_OP_const4u";
2337 return "DW_OP_const4s";
2339 return "DW_OP_const8u";
2341 return "DW_OP_const8s";
2343 return "DW_OP_constu";
2345 return "DW_OP_consts";
2349 return "DW_OP_drop";
2351 return "DW_OP_over";
2353 return "DW_OP_pick";
2355 return "DW_OP_swap";
2359 return "DW_OP_xderef";
2367 return "DW_OP_minus";
2379 return "DW_OP_plus";
2380 case DW_OP_plus_uconst:
2381 return "DW_OP_plus_uconst";
2387 return "DW_OP_shra";
2405 return "DW_OP_skip";
2407 return "DW_OP_lit0";
2409 return "DW_OP_lit1";
2411 return "DW_OP_lit2";
2413 return "DW_OP_lit3";
2415 return "DW_OP_lit4";
2417 return "DW_OP_lit5";
2419 return "DW_OP_lit6";
2421 return "DW_OP_lit7";
2423 return "DW_OP_lit8";
2425 return "DW_OP_lit9";
2427 return "DW_OP_lit10";
2429 return "DW_OP_lit11";
2431 return "DW_OP_lit12";
2433 return "DW_OP_lit13";
2435 return "DW_OP_lit14";
2437 return "DW_OP_lit15";
2439 return "DW_OP_lit16";
2441 return "DW_OP_lit17";
2443 return "DW_OP_lit18";
2445 return "DW_OP_lit19";
2447 return "DW_OP_lit20";
2449 return "DW_OP_lit21";
2451 return "DW_OP_lit22";
2453 return "DW_OP_lit23";
2455 return "DW_OP_lit24";
2457 return "DW_OP_lit25";
2459 return "DW_OP_lit26";
2461 return "DW_OP_lit27";
2463 return "DW_OP_lit28";
2465 return "DW_OP_lit29";
2467 return "DW_OP_lit30";
2469 return "DW_OP_lit31";
2471 return "DW_OP_reg0";
2473 return "DW_OP_reg1";
2475 return "DW_OP_reg2";
2477 return "DW_OP_reg3";
2479 return "DW_OP_reg4";
2481 return "DW_OP_reg5";
2483 return "DW_OP_reg6";
2485 return "DW_OP_reg7";
2487 return "DW_OP_reg8";
2489 return "DW_OP_reg9";
2491 return "DW_OP_reg10";
2493 return "DW_OP_reg11";
2495 return "DW_OP_reg12";
2497 return "DW_OP_reg13";
2499 return "DW_OP_reg14";
2501 return "DW_OP_reg15";
2503 return "DW_OP_reg16";
2505 return "DW_OP_reg17";
2507 return "DW_OP_reg18";
2509 return "DW_OP_reg19";
2511 return "DW_OP_reg20";
2513 return "DW_OP_reg21";
2515 return "DW_OP_reg22";
2517 return "DW_OP_reg23";
2519 return "DW_OP_reg24";
2521 return "DW_OP_reg25";
2523 return "DW_OP_reg26";
2525 return "DW_OP_reg27";
2527 return "DW_OP_reg28";
2529 return "DW_OP_reg29";
2531 return "DW_OP_reg30";
2533 return "DW_OP_reg31";
2535 return "DW_OP_breg0";
2537 return "DW_OP_breg1";
2539 return "DW_OP_breg2";
2541 return "DW_OP_breg3";
2543 return "DW_OP_breg4";
2545 return "DW_OP_breg5";
2547 return "DW_OP_breg6";
2549 return "DW_OP_breg7";
2551 return "DW_OP_breg8";
2553 return "DW_OP_breg9";
2555 return "DW_OP_breg10";
2557 return "DW_OP_breg11";
2559 return "DW_OP_breg12";
2561 return "DW_OP_breg13";
2563 return "DW_OP_breg14";
2565 return "DW_OP_breg15";
2567 return "DW_OP_breg16";
2569 return "DW_OP_breg17";
2571 return "DW_OP_breg18";
2573 return "DW_OP_breg19";
2575 return "DW_OP_breg20";
2577 return "DW_OP_breg21";
2579 return "DW_OP_breg22";
2581 return "DW_OP_breg23";
2583 return "DW_OP_breg24";
2585 return "DW_OP_breg25";
2587 return "DW_OP_breg26";
2589 return "DW_OP_breg27";
2591 return "DW_OP_breg28";
2593 return "DW_OP_breg29";
2595 return "DW_OP_breg30";
2597 return "DW_OP_breg31";
2599 return "DW_OP_regx";
2601 return "DW_OP_fbreg";
2603 return "DW_OP_bregx";
2605 return "DW_OP_piece";
2606 case DW_OP_deref_size:
2607 return "DW_OP_deref_size";
2608 case DW_OP_xderef_size:
2609 return "DW_OP_xderef_size";
2613 return "OP_<unknown>";
2617 /* Return a pointer to a newly allocated location description. Location
2618 descriptions are simple expression terms that can be strung
2619 together to form more complicated location (address) descriptions. */
2621 static inline dw_loc_descr_ref
2622 new_loc_descr (op, oprnd1, oprnd2)
2623 enum dwarf_location_atom op;
2624 unsigned long oprnd1;
2625 unsigned long oprnd2;
2627 /* Use xcalloc here so we clear out all of the long_long constant in
2629 dw_loc_descr_ref descr
2630 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2632 descr->dw_loc_opc = op;
2633 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2634 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2635 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2636 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2642 /* Add a location description term to a location description expression. */
2645 add_loc_descr (list_head, descr)
2646 dw_loc_descr_ref *list_head;
2647 dw_loc_descr_ref descr;
2649 dw_loc_descr_ref *d;
2651 /* Find the end of the chain. */
2652 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2658 /* Return the size of a location descriptor. */
2660 static unsigned long
2661 size_of_loc_descr (loc)
2662 dw_loc_descr_ref loc;
2664 unsigned long size = 1;
2666 switch (loc->dw_loc_opc)
2669 size += DWARF2_ADDR_SIZE;
2688 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2691 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2696 case DW_OP_plus_uconst:
2697 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2735 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2738 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2741 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2744 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2745 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2748 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2750 case DW_OP_deref_size:
2751 case DW_OP_xderef_size:
2761 /* Return the size of a series of location descriptors. */
2763 static unsigned long
2765 dw_loc_descr_ref loc;
2769 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2771 loc->dw_loc_addr = size;
2772 size += size_of_loc_descr (loc);
2778 /* Output location description stack opcode's operands (if any). */
2781 output_loc_operands (loc)
2782 dw_loc_descr_ref loc;
2784 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2785 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2787 switch (loc->dw_loc_opc)
2789 #ifdef DWARF2_DEBUGGING_INFO
2791 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2795 dw2_asm_output_data (2, val1->v.val_int, NULL);
2799 dw2_asm_output_data (4, val1->v.val_int, NULL);
2803 if (HOST_BITS_PER_LONG < 64)
2805 dw2_asm_output_data (8, val1->v.val_int, NULL);
2812 if (val1->val_class == dw_val_class_loc)
2813 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2817 dw2_asm_output_data (2, offset, NULL);
2830 /* We currently don't make any attempt to make sure these are
2831 aligned properly like we do for the main unwind info, so
2832 don't support emitting things larger than a byte if we're
2833 only doing unwinding. */
2838 dw2_asm_output_data (1, val1->v.val_int, NULL);
2841 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2844 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2847 dw2_asm_output_data (1, val1->v.val_int, NULL);
2849 case DW_OP_plus_uconst:
2850 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2884 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2887 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2890 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2893 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2894 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2897 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2899 case DW_OP_deref_size:
2900 case DW_OP_xderef_size:
2901 dw2_asm_output_data (1, val1->v.val_int, NULL);
2904 /* Other codes have no operands. */
2909 /* Output a sequence of location operations. */
2912 output_loc_sequence (loc)
2913 dw_loc_descr_ref loc;
2915 for (; loc != NULL; loc = loc->dw_loc_next)
2917 /* Output the opcode. */
2918 dw2_asm_output_data (1, loc->dw_loc_opc,
2919 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2921 /* Output the operand(s) (if any). */
2922 output_loc_operands (loc);
2926 /* This routine will generate the correct assembly data for a location
2927 description based on a cfi entry with a complex address. */
2930 output_cfa_loc (cfi)
2933 dw_loc_descr_ref loc;
2936 /* Output the size of the block. */
2937 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2938 size = size_of_locs (loc);
2939 dw2_asm_output_data_uleb128 (size, NULL);
2941 /* Now output the operations themselves. */
2942 output_loc_sequence (loc);
2945 /* This function builds a dwarf location descriptor sequence from
2946 a dw_cfa_location. */
2948 static struct dw_loc_descr_struct *
2950 dw_cfa_location *cfa;
2952 struct dw_loc_descr_struct *head, *tmp;
2954 if (cfa->indirect == 0)
2957 if (cfa->base_offset)
2960 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2962 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2964 else if (cfa->reg <= 31)
2965 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2967 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2969 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2970 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2971 add_loc_descr (&head, tmp);
2972 if (cfa->offset != 0)
2974 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2975 add_loc_descr (&head, tmp);
2981 /* This function fills in aa dw_cfa_location structure from a dwarf location
2982 descriptor sequence. */
2985 get_cfa_from_loc_descr (cfa, loc)
2986 dw_cfa_location *cfa;
2987 struct dw_loc_descr_struct *loc;
2989 struct dw_loc_descr_struct *ptr;
2991 cfa->base_offset = 0;
2995 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2997 enum dwarf_location_atom op = ptr->dw_loc_opc;
3033 cfa->reg = op - DW_OP_reg0;
3036 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3070 cfa->reg = op - DW_OP_breg0;
3071 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3074 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3075 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3080 case DW_OP_plus_uconst:
3081 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3084 internal_error ("DW_LOC_OP %s not implemented\n",
3085 dwarf_stack_op_name (ptr->dw_loc_opc));
3089 #endif /* .debug_frame support */
3091 /* And now, the support for symbolic debugging information. */
3092 #ifdef DWARF2_DEBUGGING_INFO
3094 /* .debug_str support. */
3095 static hashnode indirect_string_alloc PARAMS ((hash_table *));
3096 static int output_indirect_string PARAMS ((struct cpp_reader *,
3097 hashnode, const PTR));
3100 static void dwarf2out_init PARAMS ((const char *));
3101 static void dwarf2out_finish PARAMS ((const char *));
3102 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3103 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3104 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3105 static void dwarf2out_end_source_file PARAMS ((unsigned));
3106 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3107 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3108 static bool dwarf2out_ignore_block PARAMS ((tree));
3109 static void dwarf2out_global_decl PARAMS ((tree));
3110 static void dwarf2out_abstract_function PARAMS ((tree));
3112 /* The debug hooks structure. */
3114 const struct gcc_debug_hooks dwarf2_debug_hooks =
3120 dwarf2out_start_source_file,
3121 dwarf2out_end_source_file,
3122 dwarf2out_begin_block,
3123 dwarf2out_end_block,
3124 dwarf2out_ignore_block,
3125 dwarf2out_source_line,
3126 dwarf2out_begin_prologue,
3127 debug_nothing_int, /* end_prologue */
3128 dwarf2out_end_epilogue,
3129 debug_nothing_tree, /* begin_function */
3130 debug_nothing_int, /* end_function */
3131 dwarf2out_decl, /* function_decl */
3132 dwarf2out_global_decl,
3133 debug_nothing_tree, /* deferred_inline_function */
3134 /* The DWARF 2 backend tries to reduce debugging bloat by not
3135 emitting the abstract description of inline functions until
3136 something tries to reference them. */
3137 dwarf2out_abstract_function, /* outlining_inline_function */
3138 debug_nothing_rtx /* label */
3141 /* NOTE: In the comments in this file, many references are made to
3142 "Debugging Information Entries". This term is abbreviated as `DIE'
3143 throughout the remainder of this file. */
3145 /* An internal representation of the DWARF output is built, and then
3146 walked to generate the DWARF debugging info. The walk of the internal
3147 representation is done after the entire program has been compiled.
3148 The types below are used to describe the internal representation. */
3150 /* Various DIE's use offsets relative to the beginning of the
3151 .debug_info section to refer to each other. */
3153 typedef long int dw_offset;
3155 /* Define typedefs here to avoid circular dependencies. */
3157 typedef struct dw_attr_struct *dw_attr_ref;
3158 typedef struct dw_line_info_struct *dw_line_info_ref;
3159 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3160 typedef struct pubname_struct *pubname_ref;
3161 typedef struct dw_ranges_struct *dw_ranges_ref;
3163 /* Each entry in the line_info_table maintains the file and
3164 line number associated with the label generated for that
3165 entry. The label gives the PC value associated with
3166 the line number entry. */
3168 typedef struct dw_line_info_struct
3170 unsigned long dw_file_num;
3171 unsigned long dw_line_num;
3175 /* Line information for functions in separate sections; each one gets its
3177 typedef struct dw_separate_line_info_struct
3179 unsigned long dw_file_num;
3180 unsigned long dw_line_num;
3181 unsigned long function;
3183 dw_separate_line_info_entry;
3185 /* Each DIE attribute has a field specifying the attribute kind,
3186 a link to the next attribute in the chain, and an attribute value.
3187 Attributes are typically linked below the DIE they modify. */
3189 typedef struct dw_attr_struct
3191 enum dwarf_attribute dw_attr;
3192 dw_attr_ref dw_attr_next;
3193 dw_val_node dw_attr_val;
3197 /* The Debugging Information Entry (DIE) structure */
3199 typedef struct die_struct
3201 enum dwarf_tag die_tag;
3203 dw_attr_ref die_attr;
3204 dw_die_ref die_parent;
3205 dw_die_ref die_child;
3207 dw_offset die_offset;
3208 unsigned long die_abbrev;
3213 /* The pubname structure */
3215 typedef struct pubname_struct
3222 struct dw_ranges_struct
3227 /* The limbo die list structure. */
3228 typedef struct limbo_die_struct
3232 struct limbo_die_struct *next;
3236 /* How to start an assembler comment. */
3237 #ifndef ASM_COMMENT_START
3238 #define ASM_COMMENT_START ";#"
3241 /* Define a macro which returns non-zero for a TYPE_DECL which was
3242 implicitly generated for a tagged type.
3244 Note that unlike the gcc front end (which generates a NULL named
3245 TYPE_DECL node for each complete tagged type, each array type, and
3246 each function type node created) the g++ front end generates a
3247 _named_ TYPE_DECL node for each tagged type node created.
3248 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3249 generate a DW_TAG_typedef DIE for them. */
3251 #define TYPE_DECL_IS_STUB(decl) \
3252 (DECL_NAME (decl) == NULL_TREE \
3253 || (DECL_ARTIFICIAL (decl) \
3254 && is_tagged_type (TREE_TYPE (decl)) \
3255 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3256 /* This is necessary for stub decls that \
3257 appear in nested inline functions. */ \
3258 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3259 && (decl_ultimate_origin (decl) \
3260 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3262 /* Information concerning the compilation unit's programming
3263 language, and compiler version. */
3265 /* Fixed size portion of the DWARF compilation unit header. */
3266 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3268 /* Fixed size portion of debugging line information prolog. */
3269 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3271 /* Fixed size portion of public names info. */
3272 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3274 /* Fixed size portion of the address range info. */
3275 #define DWARF_ARANGES_HEADER_SIZE \
3276 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3277 - DWARF_OFFSET_SIZE)
3279 /* Size of padding portion in the address range info. It must be
3280 aligned to twice the pointer size. */
3281 #define DWARF_ARANGES_PAD_SIZE \
3282 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3283 - (2 * DWARF_OFFSET_SIZE + 4))
3285 /* Use assembler line directives if available. */
3286 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3287 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3288 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3290 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3294 /* Minimum line offset in a special line info. opcode.
3295 This value was chosen to give a reasonable range of values. */
3296 #define DWARF_LINE_BASE -10
3298 /* First special line opcode - leave room for the standard opcodes. */
3299 #define DWARF_LINE_OPCODE_BASE 10
3301 /* Range of line offsets in a special line info. opcode. */
3302 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3304 /* Flag that indicates the initial value of the is_stmt_start flag.
3305 In the present implementation, we do not mark any lines as
3306 the beginning of a source statement, because that information
3307 is not made available by the GCC front-end. */
3308 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3310 /* This location is used by calc_die_sizes() to keep track
3311 the offset of each DIE within the .debug_info section. */
3312 static unsigned long next_die_offset;
3314 /* Record the root of the DIE's built for the current compilation unit. */
3315 static dw_die_ref comp_unit_die;
3317 /* A list of DIEs with a NULL parent waiting to be relocated. */
3318 static limbo_die_node *limbo_die_list = 0;
3320 /* Structure used by lookup_filename to manage sets of filenames. */
3326 unsigned last_lookup_index;
3329 /* Size (in elements) of increments by which we may expand the filename
3331 #define FILE_TABLE_INCREMENT 64
3333 /* Filenames referenced by this compilation unit. */
3334 static struct file_table file_table;
3336 /* Local pointer to the name of the main input file. Initialized in
3338 static const char *primary_filename;
3340 /* A pointer to the base of a table of references to DIE's that describe
3341 declarations. The table is indexed by DECL_UID() which is a unique
3342 number identifying each decl. */
3343 static dw_die_ref *decl_die_table;
3345 /* Number of elements currently allocated for the decl_die_table. */
3346 static unsigned decl_die_table_allocated;
3348 /* Number of elements in decl_die_table currently in use. */
3349 static unsigned decl_die_table_in_use;
3351 /* Size (in elements) of increments by which we may expand the
3353 #define DECL_DIE_TABLE_INCREMENT 256
3355 /* A pointer to the base of a table of references to declaration
3356 scopes. This table is a display which tracks the nesting
3357 of declaration scopes at the current scope and containing
3358 scopes. This table is used to find the proper place to
3359 define type declaration DIE's. */
3360 varray_type decl_scope_table;
3362 /* A pointer to the base of a list of references to DIE's that
3363 are uniquely identified by their tag, presence/absence of
3364 children DIE's, and list of attribute/value pairs. */
3365 static dw_die_ref *abbrev_die_table;
3367 /* Number of elements currently allocated for abbrev_die_table. */
3368 static unsigned abbrev_die_table_allocated;
3370 /* Number of elements in type_die_table currently in use. */
3371 static unsigned abbrev_die_table_in_use;
3373 /* Size (in elements) of increments by which we may expand the
3374 abbrev_die_table. */
3375 #define ABBREV_DIE_TABLE_INCREMENT 256
3377 /* A pointer to the base of a table that contains line information
3378 for each source code line in .text in the compilation unit. */
3379 static dw_line_info_ref line_info_table;
3381 /* Number of elements currently allocated for line_info_table. */
3382 static unsigned line_info_table_allocated;
3384 /* Number of elements in separate_line_info_table currently in use. */
3385 static unsigned separate_line_info_table_in_use;
3387 /* A pointer to the base of a table that contains line information
3388 for each source code line outside of .text in the compilation unit. */
3389 static dw_separate_line_info_ref separate_line_info_table;
3391 /* Number of elements currently allocated for separate_line_info_table. */
3392 static unsigned separate_line_info_table_allocated;
3394 /* Number of elements in line_info_table currently in use. */
3395 static unsigned line_info_table_in_use;
3397 /* Size (in elements) of increments by which we may expand the
3399 #define LINE_INFO_TABLE_INCREMENT 1024
3401 /* A pointer to the base of a table that contains a list of publicly
3402 accessible names. */
3403 static pubname_ref pubname_table;
3405 /* Number of elements currently allocated for pubname_table. */
3406 static unsigned pubname_table_allocated;
3408 /* Number of elements in pubname_table currently in use. */
3409 static unsigned pubname_table_in_use;
3411 /* Size (in elements) of increments by which we may expand the
3413 #define PUBNAME_TABLE_INCREMENT 64
3415 /* Array of dies for which we should generate .debug_arange info. */
3416 static dw_die_ref *arange_table;
3418 /* Number of elements currently allocated for arange_table. */
3419 static unsigned arange_table_allocated;
3421 /* Number of elements in arange_table currently in use. */
3422 static unsigned arange_table_in_use;
3424 /* Size (in elements) of increments by which we may expand the
3426 #define ARANGE_TABLE_INCREMENT 64
3428 /* Array of dies for which we should generate .debug_ranges info. */
3429 static dw_ranges_ref ranges_table;
3431 /* Number of elements currently allocated for ranges_table. */
3432 static unsigned ranges_table_allocated;
3434 /* Number of elements in ranges_table currently in use. */
3435 static unsigned ranges_table_in_use;
3437 /* Size (in elements) of increments by which we may expand the
3439 #define RANGES_TABLE_INCREMENT 64
3441 /* Whether we have location lists that need outputting */
3442 static unsigned have_location_lists;
3444 /* A pointer to the base of a list of incomplete types which might be
3445 completed at some later time. incomplete_types_list needs to be a VARRAY
3446 because we want to tell the garbage collector about it. */
3447 varray_type incomplete_types;
3449 /* Record whether the function being analyzed contains inlined functions. */
3450 static int current_function_has_inlines;
3451 #if 0 && defined (MIPS_DEBUGGING_INFO)
3452 static int comp_unit_has_inlines;
3455 /* Array of RTXes referenced by the debugging information, which therefore
3456 must be kept around forever. This is a GC root. */
3457 static varray_type used_rtx_varray;
3459 /* Forward declarations for functions defined in this file. */
3461 static int is_pseudo_reg PARAMS ((rtx));
3462 static tree type_main_variant PARAMS ((tree));
3463 static int is_tagged_type PARAMS ((tree));
3464 static const char *dwarf_tag_name PARAMS ((unsigned));
3465 static const char *dwarf_attr_name PARAMS ((unsigned));
3466 static const char *dwarf_form_name PARAMS ((unsigned));
3468 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3470 static tree decl_ultimate_origin PARAMS ((tree));
3471 static tree block_ultimate_origin PARAMS ((tree));
3472 static tree decl_class_context PARAMS ((tree));
3473 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3474 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
3475 static void add_AT_flag PARAMS ((dw_die_ref,
3476 enum dwarf_attribute,
3478 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3479 static void add_AT_int PARAMS ((dw_die_ref,
3480 enum dwarf_attribute, long));
3481 static inline long int AT_int PARAMS ((dw_attr_ref));
3482 static void add_AT_unsigned PARAMS ((dw_die_ref,
3483 enum dwarf_attribute,
3485 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
3486 static void add_AT_long_long PARAMS ((dw_die_ref,
3487 enum dwarf_attribute,
3490 static void add_AT_float PARAMS ((dw_die_ref,
3491 enum dwarf_attribute,
3493 static void add_AT_string PARAMS ((dw_die_ref,
3494 enum dwarf_attribute,
3496 static inline const char *AT_string PARAMS ((dw_attr_ref));
3497 static int AT_string_form PARAMS ((dw_attr_ref));
3498 static void add_AT_die_ref PARAMS ((dw_die_ref,
3499 enum dwarf_attribute,
3501 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
3502 static inline int AT_ref_external PARAMS ((dw_attr_ref));
3503 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
3504 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3505 enum dwarf_attribute,
3507 static void add_AT_loc PARAMS ((dw_die_ref,
3508 enum dwarf_attribute,
3510 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
3511 static void add_AT_loc_list PARAMS ((dw_die_ref,
3512 enum dwarf_attribute,
3514 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
3515 static void add_AT_addr PARAMS ((dw_die_ref,
3516 enum dwarf_attribute,
3518 static inline rtx AT_addr PARAMS ((dw_attr_ref));
3519 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3520 enum dwarf_attribute,
3522 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3523 enum dwarf_attribute,
3525 static void add_AT_offset PARAMS ((dw_die_ref,
3526 enum dwarf_attribute,
3528 static void add_AT_range_list PARAMS ((dw_die_ref,
3529 enum dwarf_attribute,
3531 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
3532 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3533 enum dwarf_attribute));
3534 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3535 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3536 static const char *get_AT_string PARAMS ((dw_die_ref,
3537 enum dwarf_attribute));
3538 static int get_AT_flag PARAMS ((dw_die_ref,
3539 enum dwarf_attribute));
3540 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3541 enum dwarf_attribute));
3542 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3543 enum dwarf_attribute));
3544 static int is_c_family PARAMS ((void));
3545 static int is_cxx PARAMS ((void));
3546 static int is_java PARAMS ((void));
3547 static int is_fortran PARAMS ((void));
3548 static void remove_AT PARAMS ((dw_die_ref,
3549 enum dwarf_attribute));
3550 static inline void free_die PARAMS ((dw_die_ref));
3551 static void remove_children PARAMS ((dw_die_ref));
3552 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3553 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref,
3555 static dw_die_ref lookup_type_die PARAMS ((tree));
3556 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3557 static dw_die_ref lookup_decl_die PARAMS ((tree));
3558 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3559 static void print_spaces PARAMS ((FILE *));
3560 static void print_die PARAMS ((dw_die_ref, FILE *));
3561 static void print_dwarf_line_table PARAMS ((FILE *));
3562 static void reverse_die_lists PARAMS ((dw_die_ref));
3563 static void reverse_all_dies PARAMS ((dw_die_ref));
3564 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3565 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3566 static void loc_checksum PARAMS ((dw_loc_descr_ref,
3568 static void attr_checksum PARAMS ((dw_attr_ref,
3570 static void die_checksum PARAMS ((dw_die_ref,
3572 static void compute_section_prefix PARAMS ((dw_die_ref));
3573 static int is_type_die PARAMS ((dw_die_ref));
3574 static int is_comdat_die PARAMS ((dw_die_ref));
3575 static int is_symbol_die PARAMS ((dw_die_ref));
3576 static void assign_symbol_names PARAMS ((dw_die_ref));
3577 static void break_out_includes PARAMS ((dw_die_ref));
3578 static void add_sibling_attributes PARAMS ((dw_die_ref));
3579 static void build_abbrev_table PARAMS ((dw_die_ref));
3580 static void output_location_lists PARAMS ((dw_die_ref));
3581 static int constant_size PARAMS ((long unsigned));
3582 static unsigned long size_of_die PARAMS ((dw_die_ref));
3583 static void calc_die_sizes PARAMS ((dw_die_ref));
3584 static void mark_dies PARAMS ((dw_die_ref));
3585 static void unmark_dies PARAMS ((dw_die_ref));
3586 static unsigned long size_of_pubnames PARAMS ((void));
3587 static unsigned long size_of_aranges PARAMS ((void));
3588 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3589 static void output_value_format PARAMS ((dw_attr_ref));
3590 static void output_abbrev_section PARAMS ((void));
3591 static void output_die_symbol PARAMS ((dw_die_ref));
3592 static void output_die PARAMS ((dw_die_ref));
3593 static void output_compilation_unit_header PARAMS ((void));
3594 static void output_comp_unit PARAMS ((dw_die_ref));
3595 static const char *dwarf2_name PARAMS ((tree, int));
3596 static void add_pubname PARAMS ((tree, dw_die_ref));
3597 static void output_pubnames PARAMS ((void));
3598 static void add_arange PARAMS ((tree, dw_die_ref));
3599 static void output_aranges PARAMS ((void));
3600 static unsigned int add_ranges PARAMS ((tree));
3601 static void output_ranges PARAMS ((void));
3602 static void output_line_info PARAMS ((void));
3603 static void output_file_names PARAMS ((void));
3604 static dw_die_ref base_type_die PARAMS ((tree));
3605 static tree root_type PARAMS ((tree));
3606 static int is_base_type PARAMS ((tree));
3607 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3608 static int type_is_enum PARAMS ((tree));
3609 static unsigned int reg_number PARAMS ((rtx));
3610 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3611 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3612 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3613 static int is_based_loc PARAMS ((rtx));
3614 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3615 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3616 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3617 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3618 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3619 static tree field_type PARAMS ((tree));
3620 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3621 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3622 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3623 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3624 static void add_AT_location_description PARAMS ((dw_die_ref,
3625 enum dwarf_attribute, rtx));
3626 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3627 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3628 static rtx rtl_for_decl_location PARAMS ((tree));
3629 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3630 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3631 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3632 static void add_bound_info PARAMS ((dw_die_ref,
3633 enum dwarf_attribute, tree));
3634 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3635 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3636 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3637 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3638 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3639 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3640 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3641 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3642 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3643 static void push_decl_scope PARAMS ((tree));
3644 static void pop_decl_scope PARAMS ((void));
3645 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3646 static inline int local_scope_p PARAMS ((dw_die_ref));
3647 static inline int class_scope_p PARAMS ((dw_die_ref));
3648 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3650 static const char *type_tag PARAMS ((tree));
3651 static tree member_declared_type PARAMS ((tree));
3653 static const char *decl_start_label PARAMS ((tree));
3655 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3656 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3658 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3660 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3661 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3662 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3663 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3664 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3665 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3666 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3667 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3668 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3669 static void gen_label_die PARAMS ((tree, dw_die_ref));
3670 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3671 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3672 static void gen_field_die PARAMS ((tree, dw_die_ref));
3673 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3674 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3675 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3676 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3677 static void gen_member_die PARAMS ((tree, dw_die_ref));
3678 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3679 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3680 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3681 static void gen_type_die PARAMS ((tree, dw_die_ref));
3682 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3683 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3684 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3685 static int is_redundant_typedef PARAMS ((tree));
3686 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3687 static unsigned lookup_filename PARAMS ((const char *));
3688 static void init_file_table PARAMS ((void));
3689 static void retry_incomplete_types PARAMS ((void));
3690 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3691 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3692 static int file_info_cmp PARAMS ((const void *, const void *));
3693 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3694 const char *, const char *,
3695 const char *, unsigned));
3696 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3698 const char *, const char *, const char *));
3699 static void output_loc_list PARAMS ((dw_loc_list_ref));
3700 static char *gen_internal_sym PARAMS ((const char *));
3701 static void mark_limbo_die_list PARAMS ((void *));
3703 /* Section names used to hold DWARF debugging information. */
3704 #ifndef DEBUG_INFO_SECTION
3705 #define DEBUG_INFO_SECTION ".debug_info"
3707 #ifndef DEBUG_ABBREV_SECTION
3708 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3710 #ifndef DEBUG_ARANGES_SECTION
3711 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3713 #ifndef DEBUG_MACINFO_SECTION
3714 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3716 #ifndef DEBUG_LINE_SECTION
3717 #define DEBUG_LINE_SECTION ".debug_line"
3719 #ifndef DEBUG_LOC_SECTION
3720 #define DEBUG_LOC_SECTION ".debug_loc"
3722 #ifndef DEBUG_PUBNAMES_SECTION
3723 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3725 #ifndef DEBUG_STR_SECTION
3726 #define DEBUG_STR_SECTION ".debug_str"
3728 #ifndef DEBUG_RANGES_SECTION
3729 #define DEBUG_RANGES_SECTION ".debug_ranges"
3732 /* Standard ELF section names for compiled code and data. */
3733 #ifndef TEXT_SECTION_NAME
3734 #define TEXT_SECTION_NAME ".text"
3737 /* Section flags for .debug_str section. */
3738 #ifdef HAVE_GAS_SHF_MERGE
3739 #define DEBUG_STR_SECTION_FLAGS \
3740 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3742 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3745 /* Labels we insert at beginning sections we can reference instead of
3746 the section names themselves. */
3748 #ifndef TEXT_SECTION_LABEL
3749 #define TEXT_SECTION_LABEL "Ltext"
3751 #ifndef DEBUG_LINE_SECTION_LABEL
3752 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3754 #ifndef DEBUG_INFO_SECTION_LABEL
3755 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3757 #ifndef DEBUG_ABBREV_SECTION_LABEL
3758 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3760 #ifndef DEBUG_LOC_SECTION_LABEL
3761 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3763 #ifndef DEBUG_RANGES_SECTION_LABEL
3764 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3766 #ifndef DEBUG_MACINFO_SECTION_LABEL
3767 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3770 /* Definitions of defaults for formats and names of various special
3771 (artificial) labels which may be generated within this file (when the -g
3772 options is used and DWARF_DEBUGGING_INFO is in effect.
3773 If necessary, these may be overridden from within the tm.h file, but
3774 typically, overriding these defaults is unnecessary. */
3776 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3777 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3778 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3779 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3780 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3781 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3782 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3783 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3785 #ifndef TEXT_END_LABEL
3786 #define TEXT_END_LABEL "Letext"
3788 #ifndef DATA_END_LABEL
3789 #define DATA_END_LABEL "Ledata"
3791 #ifndef BSS_END_LABEL
3792 #define BSS_END_LABEL "Lebss"
3794 #ifndef BLOCK_BEGIN_LABEL
3795 #define BLOCK_BEGIN_LABEL "LBB"
3797 #ifndef BLOCK_END_LABEL
3798 #define BLOCK_END_LABEL "LBE"
3800 #ifndef BODY_BEGIN_LABEL
3801 #define BODY_BEGIN_LABEL "Lbb"
3803 #ifndef BODY_END_LABEL
3804 #define BODY_END_LABEL "Lbe"
3806 #ifndef LINE_CODE_LABEL
3807 #define LINE_CODE_LABEL "LM"
3809 #ifndef SEPARATE_LINE_CODE_LABEL
3810 #define SEPARATE_LINE_CODE_LABEL "LSM"
3813 /* We allow a language front-end to designate a function that is to be
3814 called to "demangle" any name before it it put into a DIE. */
3816 static const char *(*demangle_name_func) PARAMS ((const char *));
3819 dwarf2out_set_demangle_name_func (func)
3820 const char *(*func) PARAMS ((const char *));
3822 demangle_name_func = func;
3825 /* Test if rtl node points to a pseudo register. */
3831 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3832 || (GET_CODE (rtl) == SUBREG
3833 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3836 /* Return a reference to a type, with its const and volatile qualifiers
3840 type_main_variant (type)
3843 type = TYPE_MAIN_VARIANT (type);
3845 /* ??? There really should be only one main variant among any group of
3846 variants of a given type (and all of the MAIN_VARIANT values for all
3847 members of the group should point to that one type) but sometimes the C
3848 front-end messes this up for array types, so we work around that bug
3850 if (TREE_CODE (type) == ARRAY_TYPE)
3851 while (type != TYPE_MAIN_VARIANT (type))
3852 type = TYPE_MAIN_VARIANT (type);
3857 /* Return non-zero if the given type node represents a tagged type. */
3860 is_tagged_type (type)
3863 enum tree_code code = TREE_CODE (type);
3865 return (code == RECORD_TYPE || code == UNION_TYPE
3866 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3869 /* Convert a DIE tag into its string name. */
3872 dwarf_tag_name (tag)
3877 case DW_TAG_padding:
3878 return "DW_TAG_padding";
3879 case DW_TAG_array_type:
3880 return "DW_TAG_array_type";
3881 case DW_TAG_class_type:
3882 return "DW_TAG_class_type";
3883 case DW_TAG_entry_point:
3884 return "DW_TAG_entry_point";
3885 case DW_TAG_enumeration_type:
3886 return "DW_TAG_enumeration_type";
3887 case DW_TAG_formal_parameter:
3888 return "DW_TAG_formal_parameter";
3889 case DW_TAG_imported_declaration:
3890 return "DW_TAG_imported_declaration";
3892 return "DW_TAG_label";
3893 case DW_TAG_lexical_block:
3894 return "DW_TAG_lexical_block";
3896 return "DW_TAG_member";
3897 case DW_TAG_pointer_type:
3898 return "DW_TAG_pointer_type";
3899 case DW_TAG_reference_type:
3900 return "DW_TAG_reference_type";
3901 case DW_TAG_compile_unit:
3902 return "DW_TAG_compile_unit";
3903 case DW_TAG_string_type:
3904 return "DW_TAG_string_type";
3905 case DW_TAG_structure_type:
3906 return "DW_TAG_structure_type";
3907 case DW_TAG_subroutine_type:
3908 return "DW_TAG_subroutine_type";
3909 case DW_TAG_typedef:
3910 return "DW_TAG_typedef";
3911 case DW_TAG_union_type:
3912 return "DW_TAG_union_type";
3913 case DW_TAG_unspecified_parameters:
3914 return "DW_TAG_unspecified_parameters";
3915 case DW_TAG_variant:
3916 return "DW_TAG_variant";
3917 case DW_TAG_common_block:
3918 return "DW_TAG_common_block";
3919 case DW_TAG_common_inclusion:
3920 return "DW_TAG_common_inclusion";
3921 case DW_TAG_inheritance:
3922 return "DW_TAG_inheritance";
3923 case DW_TAG_inlined_subroutine:
3924 return "DW_TAG_inlined_subroutine";
3926 return "DW_TAG_module";
3927 case DW_TAG_ptr_to_member_type:
3928 return "DW_TAG_ptr_to_member_type";
3929 case DW_TAG_set_type:
3930 return "DW_TAG_set_type";
3931 case DW_TAG_subrange_type:
3932 return "DW_TAG_subrange_type";
3933 case DW_TAG_with_stmt:
3934 return "DW_TAG_with_stmt";
3935 case DW_TAG_access_declaration:
3936 return "DW_TAG_access_declaration";
3937 case DW_TAG_base_type:
3938 return "DW_TAG_base_type";
3939 case DW_TAG_catch_block:
3940 return "DW_TAG_catch_block";
3941 case DW_TAG_const_type:
3942 return "DW_TAG_const_type";
3943 case DW_TAG_constant:
3944 return "DW_TAG_constant";
3945 case DW_TAG_enumerator:
3946 return "DW_TAG_enumerator";
3947 case DW_TAG_file_type:
3948 return "DW_TAG_file_type";
3950 return "DW_TAG_friend";
3951 case DW_TAG_namelist:
3952 return "DW_TAG_namelist";
3953 case DW_TAG_namelist_item:
3954 return "DW_TAG_namelist_item";
3955 case DW_TAG_packed_type:
3956 return "DW_TAG_packed_type";
3957 case DW_TAG_subprogram:
3958 return "DW_TAG_subprogram";
3959 case DW_TAG_template_type_param:
3960 return "DW_TAG_template_type_param";
3961 case DW_TAG_template_value_param:
3962 return "DW_TAG_template_value_param";
3963 case DW_TAG_thrown_type:
3964 return "DW_TAG_thrown_type";
3965 case DW_TAG_try_block:
3966 return "DW_TAG_try_block";
3967 case DW_TAG_variant_part:
3968 return "DW_TAG_variant_part";
3969 case DW_TAG_variable:
3970 return "DW_TAG_variable";
3971 case DW_TAG_volatile_type:
3972 return "DW_TAG_volatile_type";
3973 case DW_TAG_MIPS_loop:
3974 return "DW_TAG_MIPS_loop";
3975 case DW_TAG_format_label:
3976 return "DW_TAG_format_label";
3977 case DW_TAG_function_template:
3978 return "DW_TAG_function_template";
3979 case DW_TAG_class_template:
3980 return "DW_TAG_class_template";
3981 case DW_TAG_GNU_BINCL:
3982 return "DW_TAG_GNU_BINCL";
3983 case DW_TAG_GNU_EINCL:
3984 return "DW_TAG_GNU_EINCL";
3986 return "DW_TAG_<unknown>";
3990 /* Convert a DWARF attribute code into its string name. */
3993 dwarf_attr_name (attr)
3999 return "DW_AT_sibling";
4000 case DW_AT_location:
4001 return "DW_AT_location";
4003 return "DW_AT_name";
4004 case DW_AT_ordering:
4005 return "DW_AT_ordering";
4006 case DW_AT_subscr_data:
4007 return "DW_AT_subscr_data";
4008 case DW_AT_byte_size:
4009 return "DW_AT_byte_size";
4010 case DW_AT_bit_offset:
4011 return "DW_AT_bit_offset";
4012 case DW_AT_bit_size:
4013 return "DW_AT_bit_size";
4014 case DW_AT_element_list:
4015 return "DW_AT_element_list";
4016 case DW_AT_stmt_list:
4017 return "DW_AT_stmt_list";
4019 return "DW_AT_low_pc";
4021 return "DW_AT_high_pc";
4022 case DW_AT_language:
4023 return "DW_AT_language";
4025 return "DW_AT_member";
4027 return "DW_AT_discr";
4028 case DW_AT_discr_value:
4029 return "DW_AT_discr_value";
4030 case DW_AT_visibility:
4031 return "DW_AT_visibility";
4033 return "DW_AT_import";
4034 case DW_AT_string_length:
4035 return "DW_AT_string_length";
4036 case DW_AT_common_reference:
4037 return "DW_AT_common_reference";
4038 case DW_AT_comp_dir:
4039 return "DW_AT_comp_dir";
4040 case DW_AT_const_value:
4041 return "DW_AT_const_value";
4042 case DW_AT_containing_type:
4043 return "DW_AT_containing_type";
4044 case DW_AT_default_value:
4045 return "DW_AT_default_value";
4047 return "DW_AT_inline";
4048 case DW_AT_is_optional:
4049 return "DW_AT_is_optional";
4050 case DW_AT_lower_bound:
4051 return "DW_AT_lower_bound";
4052 case DW_AT_producer:
4053 return "DW_AT_producer";
4054 case DW_AT_prototyped:
4055 return "DW_AT_prototyped";
4056 case DW_AT_return_addr:
4057 return "DW_AT_return_addr";
4058 case DW_AT_start_scope:
4059 return "DW_AT_start_scope";
4060 case DW_AT_stride_size:
4061 return "DW_AT_stride_size";
4062 case DW_AT_upper_bound:
4063 return "DW_AT_upper_bound";
4064 case DW_AT_abstract_origin:
4065 return "DW_AT_abstract_origin";
4066 case DW_AT_accessibility:
4067 return "DW_AT_accessibility";
4068 case DW_AT_address_class:
4069 return "DW_AT_address_class";
4070 case DW_AT_artificial:
4071 return "DW_AT_artificial";
4072 case DW_AT_base_types:
4073 return "DW_AT_base_types";
4074 case DW_AT_calling_convention:
4075 return "DW_AT_calling_convention";
4077 return "DW_AT_count";
4078 case DW_AT_data_member_location:
4079 return "DW_AT_data_member_location";
4080 case DW_AT_decl_column:
4081 return "DW_AT_decl_column";
4082 case DW_AT_decl_file:
4083 return "DW_AT_decl_file";
4084 case DW_AT_decl_line:
4085 return "DW_AT_decl_line";
4086 case DW_AT_declaration:
4087 return "DW_AT_declaration";
4088 case DW_AT_discr_list:
4089 return "DW_AT_discr_list";
4090 case DW_AT_encoding:
4091 return "DW_AT_encoding";
4092 case DW_AT_external:
4093 return "DW_AT_external";
4094 case DW_AT_frame_base:
4095 return "DW_AT_frame_base";
4097 return "DW_AT_friend";
4098 case DW_AT_identifier_case:
4099 return "DW_AT_identifier_case";
4100 case DW_AT_macro_info:
4101 return "DW_AT_macro_info";
4102 case DW_AT_namelist_items:
4103 return "DW_AT_namelist_items";
4104 case DW_AT_priority:
4105 return "DW_AT_priority";
4107 return "DW_AT_segment";
4108 case DW_AT_specification:
4109 return "DW_AT_specification";
4110 case DW_AT_static_link:
4111 return "DW_AT_static_link";
4113 return "DW_AT_type";
4114 case DW_AT_use_location:
4115 return "DW_AT_use_location";
4116 case DW_AT_variable_parameter:
4117 return "DW_AT_variable_parameter";
4118 case DW_AT_virtuality:
4119 return "DW_AT_virtuality";
4120 case DW_AT_vtable_elem_location:
4121 return "DW_AT_vtable_elem_location";
4123 case DW_AT_allocated:
4124 return "DW_AT_allocated";
4125 case DW_AT_associated:
4126 return "DW_AT_associated";
4127 case DW_AT_data_location:
4128 return "DW_AT_data_location";
4130 return "DW_AT_stride";
4131 case DW_AT_entry_pc:
4132 return "DW_AT_entry_pc";
4133 case DW_AT_use_UTF8:
4134 return "DW_AT_use_UTF8";
4135 case DW_AT_extension:
4136 return "DW_AT_extension";
4138 return "DW_AT_ranges";
4139 case DW_AT_trampoline:
4140 return "DW_AT_trampoline";
4141 case DW_AT_call_column:
4142 return "DW_AT_call_column";
4143 case DW_AT_call_file:
4144 return "DW_AT_call_file";
4145 case DW_AT_call_line:
4146 return "DW_AT_call_line";
4148 case DW_AT_MIPS_fde:
4149 return "DW_AT_MIPS_fde";
4150 case DW_AT_MIPS_loop_begin:
4151 return "DW_AT_MIPS_loop_begin";
4152 case DW_AT_MIPS_tail_loop_begin:
4153 return "DW_AT_MIPS_tail_loop_begin";
4154 case DW_AT_MIPS_epilog_begin:
4155 return "DW_AT_MIPS_epilog_begin";
4156 case DW_AT_MIPS_loop_unroll_factor:
4157 return "DW_AT_MIPS_loop_unroll_factor";
4158 case DW_AT_MIPS_software_pipeline_depth:
4159 return "DW_AT_MIPS_software_pipeline_depth";
4160 case DW_AT_MIPS_linkage_name:
4161 return "DW_AT_MIPS_linkage_name";
4162 case DW_AT_MIPS_stride:
4163 return "DW_AT_MIPS_stride";
4164 case DW_AT_MIPS_abstract_name:
4165 return "DW_AT_MIPS_abstract_name";
4166 case DW_AT_MIPS_clone_origin:
4167 return "DW_AT_MIPS_clone_origin";
4168 case DW_AT_MIPS_has_inlines:
4169 return "DW_AT_MIPS_has_inlines";
4171 case DW_AT_sf_names:
4172 return "DW_AT_sf_names";
4173 case DW_AT_src_info:
4174 return "DW_AT_src_info";
4175 case DW_AT_mac_info:
4176 return "DW_AT_mac_info";
4177 case DW_AT_src_coords:
4178 return "DW_AT_src_coords";
4179 case DW_AT_body_begin:
4180 return "DW_AT_body_begin";
4181 case DW_AT_body_end:
4182 return "DW_AT_body_end";
4183 case DW_AT_GNU_vector:
4184 return "DW_AT_GNU_vector";
4186 case DW_AT_VMS_rtnbeg_pd_address:
4187 return "DW_AT_VMS_rtnbeg_pd_address";
4190 return "DW_AT_<unknown>";
4194 /* Convert a DWARF value form code into its string name. */
4197 dwarf_form_name (form)
4203 return "DW_FORM_addr";
4204 case DW_FORM_block2:
4205 return "DW_FORM_block2";
4206 case DW_FORM_block4:
4207 return "DW_FORM_block4";
4209 return "DW_FORM_data2";
4211 return "DW_FORM_data4";
4213 return "DW_FORM_data8";
4214 case DW_FORM_string:
4215 return "DW_FORM_string";
4217 return "DW_FORM_block";
4218 case DW_FORM_block1:
4219 return "DW_FORM_block1";
4221 return "DW_FORM_data1";
4223 return "DW_FORM_flag";
4225 return "DW_FORM_sdata";
4227 return "DW_FORM_strp";
4229 return "DW_FORM_udata";
4230 case DW_FORM_ref_addr:
4231 return "DW_FORM_ref_addr";
4233 return "DW_FORM_ref1";
4235 return "DW_FORM_ref2";
4237 return "DW_FORM_ref4";
4239 return "DW_FORM_ref8";
4240 case DW_FORM_ref_udata:
4241 return "DW_FORM_ref_udata";
4242 case DW_FORM_indirect:
4243 return "DW_FORM_indirect";
4245 return "DW_FORM_<unknown>";
4249 /* Convert a DWARF type code into its string name. */
4253 dwarf_type_encoding_name (enc)
4258 case DW_ATE_address:
4259 return "DW_ATE_address";
4260 case DW_ATE_boolean:
4261 return "DW_ATE_boolean";
4262 case DW_ATE_complex_float:
4263 return "DW_ATE_complex_float";
4265 return "DW_ATE_float";
4267 return "DW_ATE_signed";
4268 case DW_ATE_signed_char:
4269 return "DW_ATE_signed_char";
4270 case DW_ATE_unsigned:
4271 return "DW_ATE_unsigned";
4272 case DW_ATE_unsigned_char:
4273 return "DW_ATE_unsigned_char";
4275 return "DW_ATE_<unknown>";
4280 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4281 instance of an inlined instance of a decl which is local to an inline
4282 function, so we have to trace all of the way back through the origin chain
4283 to find out what sort of node actually served as the original seed for the
4287 decl_ultimate_origin (decl)
4290 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4291 nodes in the function to point to themselves; ignore that if
4292 we're trying to output the abstract instance of this function. */
4293 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4296 #ifdef ENABLE_CHECKING
4297 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4298 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4299 most distant ancestor, this should never happen. */
4303 return DECL_ABSTRACT_ORIGIN (decl);
4306 /* Determine the "ultimate origin" of a block. The block may be an inlined
4307 instance of an inlined instance of a block which is local to an inline
4308 function, so we have to trace all of the way back through the origin chain
4309 to find out what sort of node actually served as the original seed for the
4313 block_ultimate_origin (block)
4316 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4318 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4319 nodes in the function to point to themselves; ignore that if
4320 we're trying to output the abstract instance of this function. */
4321 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4324 if (immediate_origin == NULL_TREE)
4329 tree lookahead = immediate_origin;
4333 ret_val = lookahead;
4334 lookahead = (TREE_CODE (ret_val) == BLOCK
4335 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4337 while (lookahead != NULL && lookahead != ret_val);
4343 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4344 of a virtual function may refer to a base class, so we check the 'this'
4348 decl_class_context (decl)
4351 tree context = NULL_TREE;
4353 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4354 context = DECL_CONTEXT (decl);
4356 context = TYPE_MAIN_VARIANT
4357 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4359 if (context && !TYPE_P (context))
4360 context = NULL_TREE;
4365 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4366 addition order, and correct that in reverse_all_dies. */
4369 add_dwarf_attr (die, attr)
4373 if (die != NULL && attr != NULL)
4375 attr->dw_attr_next = die->die_attr;
4376 die->die_attr = attr;
4380 static inline dw_val_class
4384 return a->dw_attr_val.val_class;
4387 /* Add a flag value attribute to a DIE. */
4390 add_AT_flag (die, attr_kind, flag)
4392 enum dwarf_attribute attr_kind;
4395 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4397 attr->dw_attr_next = NULL;
4398 attr->dw_attr = attr_kind;
4399 attr->dw_attr_val.val_class = dw_val_class_flag;
4400 attr->dw_attr_val.v.val_flag = flag;
4401 add_dwarf_attr (die, attr);
4404 static inline unsigned
4408 if (a && AT_class (a) == dw_val_class_flag)
4409 return a->dw_attr_val.v.val_flag;
4414 /* Add a signed integer attribute value to a DIE. */
4417 add_AT_int (die, attr_kind, int_val)
4419 enum dwarf_attribute attr_kind;
4422 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4424 attr->dw_attr_next = NULL;
4425 attr->dw_attr = attr_kind;
4426 attr->dw_attr_val.val_class = dw_val_class_const;
4427 attr->dw_attr_val.v.val_int = int_val;
4428 add_dwarf_attr (die, attr);
4431 static inline long int
4435 if (a && AT_class (a) == dw_val_class_const)
4436 return a->dw_attr_val.v.val_int;
4441 /* Add an unsigned integer attribute value to a DIE. */
4444 add_AT_unsigned (die, attr_kind, unsigned_val)
4446 enum dwarf_attribute attr_kind;
4447 unsigned long unsigned_val;
4449 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4451 attr->dw_attr_next = NULL;
4452 attr->dw_attr = attr_kind;
4453 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4454 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4455 add_dwarf_attr (die, attr);
4458 static inline unsigned long
4462 if (a && AT_class (a) == dw_val_class_unsigned_const)
4463 return a->dw_attr_val.v.val_unsigned;
4468 /* Add an unsigned double integer attribute value to a DIE. */
4471 add_AT_long_long (die, attr_kind, val_hi, val_low)
4473 enum dwarf_attribute attr_kind;
4474 unsigned long val_hi;
4475 unsigned long val_low;
4477 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4479 attr->dw_attr_next = NULL;
4480 attr->dw_attr = attr_kind;
4481 attr->dw_attr_val.val_class = dw_val_class_long_long;
4482 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4483 attr->dw_attr_val.v.val_long_long.low = val_low;
4484 add_dwarf_attr (die, attr);
4487 /* Add a floating point attribute value to a DIE and return it. */
4490 add_AT_float (die, attr_kind, length, array)
4492 enum dwarf_attribute attr_kind;
4496 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4498 attr->dw_attr_next = NULL;
4499 attr->dw_attr = attr_kind;
4500 attr->dw_attr_val.val_class = dw_val_class_float;
4501 attr->dw_attr_val.v.val_float.length = length;
4502 attr->dw_attr_val.v.val_float.array = array;
4503 add_dwarf_attr (die, attr);
4506 /* Add a string attribute value to a DIE. */
4509 add_AT_string (die, attr_kind, str)
4511 enum dwarf_attribute attr_kind;
4514 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4515 struct indirect_string_node *node;
4517 if (! debug_str_hash)
4519 debug_str_hash = ht_create (10);
4520 debug_str_hash->alloc_node = indirect_string_alloc;
4523 node = (struct indirect_string_node *)
4524 ht_lookup (debug_str_hash, (const unsigned char *) str,
4525 strlen (str), HT_ALLOC);
4528 attr->dw_attr_next = NULL;
4529 attr->dw_attr = attr_kind;
4530 attr->dw_attr_val.val_class = dw_val_class_str;
4531 attr->dw_attr_val.v.val_str = node;
4532 add_dwarf_attr (die, attr);
4535 static inline const char *
4539 if (a && AT_class (a) == dw_val_class_str)
4540 return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id);
4545 /* Find out whether a string should be output inline in DIE
4546 or out-of-line in .debug_str section. */
4552 if (a && AT_class (a) == dw_val_class_str)
4554 struct indirect_string_node *node;
4556 extern int const_labelno;
4559 node = a->dw_attr_val.v.val_str;
4563 len = HT_LEN (&node->id) + 1;
4565 /* If the string is shorter or equal to the size of the reference, it is
4566 always better to put it inline. */
4567 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4568 return node->form = DW_FORM_string;
4570 /* If we cannot expect the linker to merge strings in .debug_str
4571 section, only put it into .debug_str if it is worth even in this
4573 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4574 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4575 return node->form = DW_FORM_string;
4577 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4579 node->label = xstrdup (label);
4581 return node->form = DW_FORM_strp;
4587 /* Add a DIE reference attribute value to a DIE. */
4590 add_AT_die_ref (die, attr_kind, targ_die)
4592 enum dwarf_attribute attr_kind;
4593 dw_die_ref targ_die;
4595 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4597 attr->dw_attr_next = NULL;
4598 attr->dw_attr = attr_kind;
4599 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4600 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4601 attr->dw_attr_val.v.val_die_ref.external = 0;
4602 add_dwarf_attr (die, attr);
4605 static inline dw_die_ref
4609 if (a && AT_class (a) == dw_val_class_die_ref)
4610 return a->dw_attr_val.v.val_die_ref.die;
4619 if (a && AT_class (a) == dw_val_class_die_ref)
4620 return a->dw_attr_val.v.val_die_ref.external;
4626 set_AT_ref_external (a, i)
4630 if (a && AT_class (a) == dw_val_class_die_ref)
4631 a->dw_attr_val.v.val_die_ref.external = i;
4636 /* Add an FDE reference attribute value to a DIE. */
4639 add_AT_fde_ref (die, attr_kind, targ_fde)
4641 enum dwarf_attribute attr_kind;
4644 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4646 attr->dw_attr_next = NULL;
4647 attr->dw_attr = attr_kind;
4648 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4649 attr->dw_attr_val.v.val_fde_index = targ_fde;
4650 add_dwarf_attr (die, attr);
4653 /* Add a location description attribute value to a DIE. */
4656 add_AT_loc (die, attr_kind, loc)
4658 enum dwarf_attribute attr_kind;
4659 dw_loc_descr_ref loc;
4661 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4663 attr->dw_attr_next = NULL;
4664 attr->dw_attr = attr_kind;
4665 attr->dw_attr_val.val_class = dw_val_class_loc;
4666 attr->dw_attr_val.v.val_loc = loc;
4667 add_dwarf_attr (die, attr);
4670 static inline dw_loc_descr_ref
4674 if (a && AT_class (a) == dw_val_class_loc)
4675 return a->dw_attr_val.v.val_loc;
4681 add_AT_loc_list (die, attr_kind, loc_list)
4683 enum dwarf_attribute attr_kind;
4684 dw_loc_list_ref loc_list;
4686 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4688 attr->dw_attr_next = NULL;
4689 attr->dw_attr = attr_kind;
4690 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4691 attr->dw_attr_val.v.val_loc_list = loc_list;
4692 add_dwarf_attr (die, attr);
4693 have_location_lists = 1;
4696 static inline dw_loc_list_ref
4700 if (a && AT_class (a) == dw_val_class_loc_list)
4701 return a->dw_attr_val.v.val_loc_list;
4706 /* Add an address constant attribute value to a DIE. */
4709 add_AT_addr (die, attr_kind, addr)
4711 enum dwarf_attribute attr_kind;
4714 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4716 attr->dw_attr_next = NULL;
4717 attr->dw_attr = attr_kind;
4718 attr->dw_attr_val.val_class = dw_val_class_addr;
4719 attr->dw_attr_val.v.val_addr = addr;
4720 add_dwarf_attr (die, attr);
4727 if (a && AT_class (a) == dw_val_class_addr)
4728 return a->dw_attr_val.v.val_addr;
4733 /* Add a label identifier attribute value to a DIE. */
4736 add_AT_lbl_id (die, attr_kind, lbl_id)
4738 enum dwarf_attribute attr_kind;
4741 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4743 attr->dw_attr_next = NULL;
4744 attr->dw_attr = attr_kind;
4745 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4746 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4747 add_dwarf_attr (die, attr);
4750 /* Add a section offset attribute value to a DIE. */
4753 add_AT_lbl_offset (die, attr_kind, label)
4755 enum dwarf_attribute attr_kind;
4758 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4760 attr->dw_attr_next = NULL;
4761 attr->dw_attr = attr_kind;
4762 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4763 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4764 add_dwarf_attr (die, attr);
4767 /* Add an offset attribute value to a DIE. */
4770 add_AT_offset (die, attr_kind, offset)
4772 enum dwarf_attribute attr_kind;
4773 unsigned long offset;
4775 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4777 attr->dw_attr_next = NULL;
4778 attr->dw_attr = attr_kind;
4779 attr->dw_attr_val.val_class = dw_val_class_offset;
4780 attr->dw_attr_val.v.val_offset = offset;
4781 add_dwarf_attr (die, attr);
4784 /* Add an range_list attribute value to a DIE. */
4787 add_AT_range_list (die, attr_kind, offset)
4789 enum dwarf_attribute attr_kind;
4790 unsigned long offset;
4792 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4794 attr->dw_attr_next = NULL;
4795 attr->dw_attr = attr_kind;
4796 attr->dw_attr_val.val_class = dw_val_class_range_list;
4797 attr->dw_attr_val.v.val_offset = offset;
4798 add_dwarf_attr (die, attr);
4801 static inline const char *
4805 if (a && (AT_class (a) == dw_val_class_lbl_id
4806 || AT_class (a) == dw_val_class_lbl_offset))
4807 return a->dw_attr_val.v.val_lbl_id;
4812 /* Get the attribute of type attr_kind. */
4814 static inline dw_attr_ref
4815 get_AT (die, attr_kind)
4817 enum dwarf_attribute attr_kind;
4820 dw_die_ref spec = NULL;
4824 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4825 if (a->dw_attr == attr_kind)
4827 else if (a->dw_attr == DW_AT_specification
4828 || a->dw_attr == DW_AT_abstract_origin)
4832 return get_AT (spec, attr_kind);
4838 /* Return the "low pc" attribute value, typically associated with a subprogram
4839 DIE. Return null if the "low pc" attribute is either not present, or if it
4840 cannot be represented as an assembler label identifier. */
4842 static inline const char *
4846 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4848 return a ? AT_lbl (a) : NULL;
4851 /* Return the "high pc" attribute value, typically associated with a subprogram
4852 DIE. Return null if the "high pc" attribute is either not present, or if it
4853 cannot be represented as an assembler label identifier. */
4855 static inline const char *
4859 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4861 return a ? AT_lbl (a) : NULL;
4864 /* Return the value of the string attribute designated by ATTR_KIND, or
4865 NULL if it is not present. */
4867 static inline const char *
4868 get_AT_string (die, attr_kind)
4870 enum dwarf_attribute attr_kind;
4872 dw_attr_ref a = get_AT (die, attr_kind);
4874 return a ? AT_string (a) : NULL;
4877 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4878 if it is not present. */
4881 get_AT_flag (die, attr_kind)
4883 enum dwarf_attribute attr_kind;
4885 dw_attr_ref a = get_AT (die, attr_kind);
4887 return a ? AT_flag (a) : 0;
4890 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4891 if it is not present. */
4893 static inline unsigned
4894 get_AT_unsigned (die, attr_kind)
4896 enum dwarf_attribute attr_kind;
4898 dw_attr_ref a = get_AT (die, attr_kind);
4900 return a ? AT_unsigned (a) : 0;
4903 static inline dw_die_ref
4904 get_AT_ref (die, attr_kind)
4906 enum dwarf_attribute attr_kind;
4908 dw_attr_ref a = get_AT (die, attr_kind);
4910 return a ? AT_ref (a) : NULL;
4916 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4918 return (lang == DW_LANG_C || lang == DW_LANG_C89
4919 || lang == DW_LANG_C_plus_plus);
4925 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4926 == DW_LANG_C_plus_plus);
4932 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4934 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4940 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4942 return (lang == DW_LANG_Java);
4945 /* Free up the memory used by A. */
4947 static inline void free_AT PARAMS ((dw_attr_ref));
4952 switch (AT_class (a))
4954 case dw_val_class_str:
4955 if (a->dw_attr_val.v.val_str->refcount)
4956 a->dw_attr_val.v.val_str->refcount--;
4959 case dw_val_class_lbl_id:
4960 case dw_val_class_lbl_offset:
4961 free (a->dw_attr_val.v.val_lbl_id);
4964 case dw_val_class_float:
4965 free (a->dw_attr_val.v.val_float.array);
4975 /* Remove the specified attribute if present. */
4978 remove_AT (die, attr_kind)
4980 enum dwarf_attribute attr_kind;
4983 dw_attr_ref removed = NULL;
4987 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4988 if ((*p)->dw_attr == attr_kind)
4991 *p = (*p)->dw_attr_next;
5000 /* Free up the memory used by DIE. */
5006 remove_children (die);
5010 /* Discard the children of this DIE. */
5013 remove_children (die)
5016 dw_die_ref child_die = die->die_child;
5018 die->die_child = NULL;
5020 while (child_die != NULL)
5022 dw_die_ref tmp_die = child_die;
5025 child_die = child_die->die_sib;
5027 for (a = tmp_die->die_attr; a != NULL;)
5029 dw_attr_ref tmp_a = a;
5031 a = a->dw_attr_next;
5039 /* Add a child DIE below its parent. We build the lists up in reverse
5040 addition order, and correct that in reverse_all_dies. */
5043 add_child_die (die, child_die)
5045 dw_die_ref child_die;
5047 if (die != NULL && child_die != NULL)
5049 if (die == child_die)
5052 child_die->die_parent = die;
5053 child_die->die_sib = die->die_child;
5054 die->die_child = child_die;
5058 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5059 is the specification, to the front of PARENT's list of children. */
5062 splice_child_die (parent, child)
5063 dw_die_ref parent, child;
5067 /* We want the declaration DIE from inside the class, not the
5068 specification DIE at toplevel. */
5069 if (child->die_parent != parent)
5071 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5077 if (child->die_parent != parent
5078 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
5081 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5084 *p = child->die_sib;
5088 child->die_sib = parent->die_child;
5089 parent->die_child = child;
5092 /* Return a pointer to a newly created DIE node. */
5094 static inline dw_die_ref
5095 new_die (tag_value, parent_die, t)
5096 enum dwarf_tag tag_value;
5097 dw_die_ref parent_die;
5100 dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5102 die->die_tag = tag_value;
5104 if (parent_die != NULL)
5105 add_child_die (parent_die, die);
5108 limbo_die_node *limbo_node;
5110 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5111 limbo_node->die = die;
5112 limbo_node->created_for = t;
5113 limbo_node->next = limbo_die_list;
5114 limbo_die_list = limbo_node;
5120 /* Return the DIE associated with the given type specifier. */
5122 static inline dw_die_ref
5123 lookup_type_die (type)
5126 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
5129 /* Equate a DIE to a given type specifier. */
5132 equate_type_number_to_die (type, type_die)
5134 dw_die_ref type_die;
5136 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
5139 /* Return the DIE associated with a given declaration. */
5141 static inline dw_die_ref
5142 lookup_decl_die (decl)
5145 unsigned decl_id = DECL_UID (decl);
5147 return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
5150 /* Equate a DIE to a particular declaration. */
5153 equate_decl_number_to_die (decl, decl_die)
5155 dw_die_ref decl_die;
5157 unsigned int decl_id = DECL_UID (decl);
5158 unsigned int num_allocated;
5160 if (decl_id >= decl_die_table_allocated)
5163 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5164 / DECL_DIE_TABLE_INCREMENT)
5165 * DECL_DIE_TABLE_INCREMENT;
5168 = (dw_die_ref *) xrealloc (decl_die_table,
5169 sizeof (dw_die_ref) * num_allocated);
5171 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5172 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5173 decl_die_table_allocated = num_allocated;
5176 if (decl_id >= decl_die_table_in_use)
5177 decl_die_table_in_use = (decl_id + 1);
5179 decl_die_table[decl_id] = decl_die;
5182 /* Keep track of the number of spaces used to indent the
5183 output of the debugging routines that print the structure of
5184 the DIE internal representation. */
5185 static int print_indent;
5187 /* Indent the line the number of spaces given by print_indent. */
5190 print_spaces (outfile)
5193 fprintf (outfile, "%*s", print_indent, "");
5196 /* Print the information associated with a given DIE, and its children.
5197 This routine is a debugging aid only. */
5200 print_die (die, outfile)
5207 print_spaces (outfile);
5208 fprintf (outfile, "DIE %4lu: %s\n",
5209 die->die_offset, dwarf_tag_name (die->die_tag));
5210 print_spaces (outfile);
5211 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5212 fprintf (outfile, " offset: %lu\n", die->die_offset);
5214 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5216 print_spaces (outfile);
5217 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5219 switch (AT_class (a))
5221 case dw_val_class_addr:
5222 fprintf (outfile, "address");
5224 case dw_val_class_offset:
5225 fprintf (outfile, "offset");
5227 case dw_val_class_loc:
5228 fprintf (outfile, "location descriptor");
5230 case dw_val_class_loc_list:
5231 fprintf (outfile, "location list -> label:%s",
5232 AT_loc_list (a)->ll_symbol);
5234 case dw_val_class_range_list:
5235 fprintf (outfile, "range list");
5237 case dw_val_class_const:
5238 fprintf (outfile, "%ld", AT_int (a));
5240 case dw_val_class_unsigned_const:
5241 fprintf (outfile, "%lu", AT_unsigned (a));
5243 case dw_val_class_long_long:
5244 fprintf (outfile, "constant (%lu,%lu)",
5245 a->dw_attr_val.v.val_long_long.hi,
5246 a->dw_attr_val.v.val_long_long.low);
5248 case dw_val_class_float:
5249 fprintf (outfile, "floating-point constant");
5251 case dw_val_class_flag:
5252 fprintf (outfile, "%u", AT_flag (a));
5254 case dw_val_class_die_ref:
5255 if (AT_ref (a) != NULL)
5257 if (AT_ref (a)->die_symbol)
5258 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5260 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5263 fprintf (outfile, "die -> <null>");
5265 case dw_val_class_lbl_id:
5266 case dw_val_class_lbl_offset:
5267 fprintf (outfile, "label: %s", AT_lbl (a));
5269 case dw_val_class_str:
5270 if (AT_string (a) != NULL)
5271 fprintf (outfile, "\"%s\"", AT_string (a));
5273 fprintf (outfile, "<null>");
5279 fprintf (outfile, "\n");
5282 if (die->die_child != NULL)
5285 for (c = die->die_child; c != NULL; c = c->die_sib)
5286 print_die (c, outfile);
5290 if (print_indent == 0)
5291 fprintf (outfile, "\n");
5294 /* Print the contents of the source code line number correspondence table.
5295 This routine is a debugging aid only. */
5298 print_dwarf_line_table (outfile)
5302 dw_line_info_ref line_info;
5304 fprintf (outfile, "\n\nDWARF source line information\n");
5305 for (i = 1; i < line_info_table_in_use; i++)
5307 line_info = &line_info_table[i];
5308 fprintf (outfile, "%5d: ", i);
5309 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5310 fprintf (outfile, "%6ld", line_info->dw_line_num);
5311 fprintf (outfile, "\n");
5314 fprintf (outfile, "\n\n");
5317 /* Print the information collected for a given DIE. */
5320 debug_dwarf_die (die)
5323 print_die (die, stderr);
5326 /* Print all DWARF information collected for the compilation unit.
5327 This routine is a debugging aid only. */
5333 print_die (comp_unit_die, stderr);
5334 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5335 print_dwarf_line_table (stderr);
5338 /* We build up the lists of children and attributes by pushing new ones
5339 onto the beginning of the list. Reverse the lists for DIE so that
5340 they are in order of addition. */
5343 reverse_die_lists (die)
5346 dw_die_ref c, cp, cn;
5347 dw_attr_ref a, ap, an;
5349 for (a = die->die_attr, ap = 0; a; a = an)
5351 an = a->dw_attr_next;
5352 a->dw_attr_next = ap;
5358 for (c = die->die_child, cp = 0; c; c = cn)
5365 die->die_child = cp;
5368 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5369 reverse all dies in add_sibling_attributes, which runs through all the dies,
5370 it would reverse all the dies. Now, however, since we don't call
5371 reverse_die_lists in add_sibling_attributes, we need a routine to
5372 recursively reverse all the dies. This is that routine. */
5375 reverse_all_dies (die)
5380 reverse_die_lists (die);
5382 for (c = die->die_child; c; c = c->die_sib)
5383 reverse_all_dies (c);
5386 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5387 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5388 DIE that marks the start of the DIEs for this include file. */
5391 push_new_compile_unit (old_unit, bincl_die)
5392 dw_die_ref old_unit, bincl_die;
5394 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5395 dw_die_ref new_unit = gen_compile_unit_die (filename);
5397 new_unit->die_sib = old_unit;
5401 /* Close an include-file CU and reopen the enclosing one. */
5404 pop_compile_unit (old_unit)
5405 dw_die_ref old_unit;
5407 dw_die_ref new_unit = old_unit->die_sib;
5409 old_unit->die_sib = NULL;
5413 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5414 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5416 /* Calculate the checksum of a location expression. */
5419 loc_checksum (loc, ctx)
5420 dw_loc_descr_ref loc;
5421 struct md5_ctx *ctx;
5423 CHECKSUM (loc->dw_loc_opc);
5424 CHECKSUM (loc->dw_loc_oprnd1);
5425 CHECKSUM (loc->dw_loc_oprnd2);
5428 /* Calculate the checksum of an attribute. */
5431 attr_checksum (at, ctx)
5433 struct md5_ctx *ctx;
5435 dw_loc_descr_ref loc;
5438 CHECKSUM (at->dw_attr);
5440 /* We don't care about differences in file numbering. */
5441 if (at->dw_attr == DW_AT_decl_file
5442 /* Or that this was compiled with a different compiler snapshot; if
5443 the output is the same, that's what matters. */
5444 || at->dw_attr == DW_AT_producer)
5447 switch (AT_class (at))
5449 case dw_val_class_const:
5450 CHECKSUM (at->dw_attr_val.v.val_int);
5452 case dw_val_class_unsigned_const:
5453 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5455 case dw_val_class_long_long:
5456 CHECKSUM (at->dw_attr_val.v.val_long_long);
5458 case dw_val_class_float:
5459 CHECKSUM (at->dw_attr_val.v.val_float);
5461 case dw_val_class_flag:
5462 CHECKSUM (at->dw_attr_val.v.val_flag);
5464 case dw_val_class_str:
5465 CHECKSUM_STRING (AT_string (at));
5468 case dw_val_class_addr:
5470 switch (GET_CODE (r))
5473 CHECKSUM_STRING (XSTR (r, 0));
5481 case dw_val_class_offset:
5482 CHECKSUM (at->dw_attr_val.v.val_offset);
5485 case dw_val_class_loc:
5486 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5487 loc_checksum (loc, ctx);
5490 case dw_val_class_die_ref:
5491 if (AT_ref (at)->die_offset)
5492 CHECKSUM (AT_ref (at)->die_offset);
5493 /* FIXME else use target die name or something. */
5495 case dw_val_class_fde_ref:
5496 case dw_val_class_lbl_id:
5497 case dw_val_class_lbl_offset:
5505 /* Calculate the checksum of a DIE. */
5508 die_checksum (die, ctx)
5510 struct md5_ctx *ctx;
5515 CHECKSUM (die->die_tag);
5517 for (a = die->die_attr; a; a = a->dw_attr_next)
5518 attr_checksum (a, ctx);
5520 for (c = die->die_child; c; c = c->die_sib)
5521 die_checksum (c, ctx);
5525 #undef CHECKSUM_STRING
5527 /* The prefix to attach to symbols on DIEs in the current comdat debug
5529 static char *comdat_symbol_id;
5531 /* The index of the current symbol within the current comdat CU. */
5532 static unsigned int comdat_symbol_number;
5534 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5535 children, and set comdat_symbol_id accordingly. */
5538 compute_section_prefix (unit_die)
5539 dw_die_ref unit_die;
5541 const char *base = lbasename (get_AT_string (unit_die, DW_AT_name));
5542 char *name = (char *) alloca (strlen (base) + 64);
5545 unsigned char checksum[16];
5548 /* Compute the checksum of the DIE, then append part of it as hex digits to
5549 the name filename of the unit. */
5551 md5_init_ctx (&ctx);
5552 die_checksum (unit_die, &ctx);
5553 md5_finish_ctx (&ctx, checksum);
5555 sprintf (name, "%s.", base);
5556 clean_symbol_name (name);
5558 p = name + strlen (name);
5559 for (i = 0; i < 4; i++)
5561 sprintf (p, "%.2x", checksum[i]);
5565 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5566 comdat_symbol_number = 0;
5569 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5575 switch (die->die_tag)
5577 case DW_TAG_array_type:
5578 case DW_TAG_class_type:
5579 case DW_TAG_enumeration_type:
5580 case DW_TAG_pointer_type:
5581 case DW_TAG_reference_type:
5582 case DW_TAG_string_type:
5583 case DW_TAG_structure_type:
5584 case DW_TAG_subroutine_type:
5585 case DW_TAG_union_type:
5586 case DW_TAG_ptr_to_member_type:
5587 case DW_TAG_set_type:
5588 case DW_TAG_subrange_type:
5589 case DW_TAG_base_type:
5590 case DW_TAG_const_type:
5591 case DW_TAG_file_type:
5592 case DW_TAG_packed_type:
5593 case DW_TAG_volatile_type:
5600 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5601 Basically, we want to choose the bits that are likely to be shared between
5602 compilations (types) and leave out the bits that are specific to individual
5603 compilations (functions). */
5609 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5610 we do for stabs. The advantage is a greater likelihood of sharing between
5611 objects that don't include headers in the same order (and therefore would
5612 put the base types in a different comdat). jason 8/28/00 */
5614 if (c->die_tag == DW_TAG_base_type)
5617 if (c->die_tag == DW_TAG_pointer_type
5618 || c->die_tag == DW_TAG_reference_type
5619 || c->die_tag == DW_TAG_const_type
5620 || c->die_tag == DW_TAG_volatile_type)
5622 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5624 return t ? is_comdat_die (t) : 0;
5627 return is_type_die (c);
5630 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5631 compilation unit. */
5637 return (is_type_die (c)
5638 || (get_AT (c, DW_AT_declaration)
5639 && !get_AT (c, DW_AT_specification)));
5643 gen_internal_sym (prefix)
5647 static int label_num;
5649 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5650 return xstrdup (buf);
5653 /* Assign symbols to all worthy DIEs under DIE. */
5656 assign_symbol_names (die)
5661 if (is_symbol_die (die))
5663 if (comdat_symbol_id)
5665 char *p = alloca (strlen (comdat_symbol_id) + 64);
5667 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5668 comdat_symbol_id, comdat_symbol_number++);
5669 die->die_symbol = xstrdup (p);
5672 die->die_symbol = gen_internal_sym ("LDIE");
5675 for (c = die->die_child; c != NULL; c = c->die_sib)
5676 assign_symbol_names (c);
5679 /* Traverse the DIE (which is always comp_unit_die), and set up
5680 additional compilation units for each of the include files we see
5681 bracketed by BINCL/EINCL. */
5684 break_out_includes (die)
5688 dw_die_ref unit = NULL;
5689 limbo_die_node *node;
5691 for (ptr = &(die->die_child); *ptr;)
5693 dw_die_ref c = *ptr;
5695 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
5696 || (unit && is_comdat_die (c)))
5698 /* This DIE is for a secondary CU; remove it from the main one. */
5701 if (c->die_tag == DW_TAG_GNU_BINCL)
5703 unit = push_new_compile_unit (unit, c);
5706 else if (c->die_tag == DW_TAG_GNU_EINCL)
5708 unit = pop_compile_unit (unit);
5712 add_child_die (unit, c);
5716 /* Leave this DIE in the main CU. */
5717 ptr = &(c->die_sib);
5723 /* We can only use this in debugging, since the frontend doesn't check
5724 to make sure that we leave every include file we enter. */
5729 assign_symbol_names (die);
5730 for (node = limbo_die_list; node; node = node->next)
5732 compute_section_prefix (node->die);
5733 assign_symbol_names (node->die);
5737 /* Traverse the DIE and add a sibling attribute if it may have the
5738 effect of speeding up access to siblings. To save some space,
5739 avoid generating sibling attributes for DIE's without children. */
5742 add_sibling_attributes (die)
5747 if (die->die_tag != DW_TAG_compile_unit
5748 && die->die_sib && die->die_child != NULL)
5749 /* Add the sibling link to the front of the attribute list. */
5750 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5752 for (c = die->die_child; c != NULL; c = c->die_sib)
5753 add_sibling_attributes (c);
5756 /* Output all location lists for the DIE and its children. */
5759 output_location_lists (die)
5765 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5766 if (AT_class (d_attr) == dw_val_class_loc_list)
5767 output_loc_list (AT_loc_list (d_attr));
5769 for (c = die->die_child; c != NULL; c = c->die_sib)
5770 output_location_lists (c);
5774 /* The format of each DIE (and its attribute value pairs) is encoded in an
5775 abbreviation table. This routine builds the abbreviation table and assigns
5776 a unique abbreviation id for each abbreviation entry. The children of each
5777 die are visited recursively. */
5780 build_abbrev_table (die)
5783 unsigned long abbrev_id;
5784 unsigned int n_alloc;
5786 dw_attr_ref d_attr, a_attr;
5788 /* Scan the DIE references, and mark as external any that refer to
5789 DIEs from other CUs (i.e. those which are not marked). */
5790 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5791 if (AT_class (d_attr) == dw_val_class_die_ref
5792 && AT_ref (d_attr)->die_mark == 0)
5794 if (AT_ref (d_attr)->die_symbol == 0)
5797 set_AT_ref_external (d_attr, 1);
5800 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5802 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5804 if (abbrev->die_tag == die->die_tag)
5806 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5808 a_attr = abbrev->die_attr;
5809 d_attr = die->die_attr;
5811 while (a_attr != NULL && d_attr != NULL)
5813 if ((a_attr->dw_attr != d_attr->dw_attr)
5814 || (value_format (a_attr) != value_format (d_attr)))
5817 a_attr = a_attr->dw_attr_next;
5818 d_attr = d_attr->dw_attr_next;
5821 if (a_attr == NULL && d_attr == NULL)
5827 if (abbrev_id >= abbrev_die_table_in_use)
5829 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5831 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5833 = (dw_die_ref *) xrealloc (abbrev_die_table,
5834 sizeof (dw_die_ref) * n_alloc);
5836 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5837 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5838 abbrev_die_table_allocated = n_alloc;
5841 ++abbrev_die_table_in_use;
5842 abbrev_die_table[abbrev_id] = die;
5845 die->die_abbrev = abbrev_id;
5846 for (c = die->die_child; c != NULL; c = c->die_sib)
5847 build_abbrev_table (c);
5850 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5853 constant_size (value)
5854 long unsigned value;
5861 log = floor_log2 (value);
5864 log = 1 << (floor_log2 (log) + 1);
5869 /* Return the size of a DIE as it is represented in the
5870 .debug_info section. */
5872 static unsigned long
5876 unsigned long size = 0;
5879 size += size_of_uleb128 (die->die_abbrev);
5880 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5882 switch (AT_class (a))
5884 case dw_val_class_addr:
5885 size += DWARF2_ADDR_SIZE;
5887 case dw_val_class_offset:
5888 size += DWARF_OFFSET_SIZE;
5890 case dw_val_class_loc:
5892 unsigned long lsize = size_of_locs (AT_loc (a));
5895 size += constant_size (lsize);
5899 case dw_val_class_loc_list:
5900 size += DWARF_OFFSET_SIZE;
5902 case dw_val_class_range_list:
5903 size += DWARF_OFFSET_SIZE;
5905 case dw_val_class_const:
5906 size += size_of_sleb128 (AT_int (a));
5908 case dw_val_class_unsigned_const:
5909 size += constant_size (AT_unsigned (a));
5911 case dw_val_class_long_long:
5912 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5914 case dw_val_class_float:
5915 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5917 case dw_val_class_flag:
5920 case dw_val_class_die_ref:
5921 size += DWARF_OFFSET_SIZE;
5923 case dw_val_class_fde_ref:
5924 size += DWARF_OFFSET_SIZE;
5926 case dw_val_class_lbl_id:
5927 size += DWARF2_ADDR_SIZE;
5929 case dw_val_class_lbl_offset:
5930 size += DWARF_OFFSET_SIZE;
5932 case dw_val_class_str:
5933 if (AT_string_form (a) == DW_FORM_strp)
5934 size += DWARF_OFFSET_SIZE;
5936 size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1;
5946 /* Size the debugging information associated with a given DIE. Visits the
5947 DIE's children recursively. Updates the global variable next_die_offset, on
5948 each time through. Uses the current value of next_die_offset to update the
5949 die_offset field in each DIE. */
5952 calc_die_sizes (die)
5957 die->die_offset = next_die_offset;
5958 next_die_offset += size_of_die (die);
5960 for (c = die->die_child; c != NULL; c = c->die_sib)
5963 if (die->die_child != NULL)
5964 /* Count the null byte used to terminate sibling lists. */
5965 next_die_offset += 1;
5968 /* Set the marks for a die and its children. We do this so
5969 that we know whether or not a reference needs to use FORM_ref_addr; only
5970 DIEs in the same CU will be marked. We used to clear out the offset
5971 and use that as the flag, but ran into ordering problems. */
5980 for (c = die->die_child; c; c = c->die_sib)
5984 /* Clear the marks for a die and its children. */
5993 for (c = die->die_child; c; c = c->die_sib)
5997 /* Return the size of the .debug_pubnames table generated for the
5998 compilation unit. */
6000 static unsigned long
6006 size = DWARF_PUBNAMES_HEADER_SIZE;
6007 for (i = 0; i < pubname_table_in_use; i++)
6009 pubname_ref p = &pubname_table[i];
6010 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
6013 size += DWARF_OFFSET_SIZE;
6017 /* Return the size of the information in the .debug_aranges section. */
6019 static unsigned long
6024 size = DWARF_ARANGES_HEADER_SIZE;
6026 /* Count the address/length pair for this compilation unit. */
6027 size += 2 * DWARF2_ADDR_SIZE;
6028 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6030 /* Count the two zero words used to terminated the address range table. */
6031 size += 2 * DWARF2_ADDR_SIZE;
6035 /* Select the encoding of an attribute value. */
6037 static enum dwarf_form
6041 switch (a->dw_attr_val.val_class)
6043 case dw_val_class_addr:
6044 return DW_FORM_addr;
6045 case dw_val_class_range_list:
6046 case dw_val_class_offset:
6047 if (DWARF_OFFSET_SIZE == 4)
6048 return DW_FORM_data4;
6049 if (DWARF_OFFSET_SIZE == 8)
6050 return DW_FORM_data8;
6052 case dw_val_class_loc_list:
6053 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6054 .debug_loc section */
6055 return DW_FORM_data4;
6056 case dw_val_class_loc:
6057 switch (constant_size (size_of_locs (AT_loc (a))))
6060 return DW_FORM_block1;
6062 return DW_FORM_block2;
6066 case dw_val_class_const:
6067 return DW_FORM_sdata;
6068 case dw_val_class_unsigned_const:
6069 switch (constant_size (AT_unsigned (a)))
6072 return DW_FORM_data1;
6074 return DW_FORM_data2;
6076 return DW_FORM_data4;
6078 return DW_FORM_data8;
6082 case dw_val_class_long_long:
6083 return DW_FORM_block1;
6084 case dw_val_class_float:
6085 return DW_FORM_block1;
6086 case dw_val_class_flag:
6087 return DW_FORM_flag;
6088 case dw_val_class_die_ref:
6089 if (AT_ref_external (a))
6090 return DW_FORM_ref_addr;
6093 case dw_val_class_fde_ref:
6094 return DW_FORM_data;
6095 case dw_val_class_lbl_id:
6096 return DW_FORM_addr;
6097 case dw_val_class_lbl_offset:
6098 return DW_FORM_data;
6099 case dw_val_class_str:
6100 return AT_string_form (a);
6107 /* Output the encoding of an attribute value. */
6110 output_value_format (a)
6113 enum dwarf_form form = value_format (a);
6115 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6118 /* Output the .debug_abbrev section which defines the DIE abbreviation
6122 output_abbrev_section ()
6124 unsigned long abbrev_id;
6128 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6130 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6132 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6133 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6134 dwarf_tag_name (abbrev->die_tag));
6136 if (abbrev->die_child != NULL)
6137 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6139 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6141 for (a_attr = abbrev->die_attr; a_attr != NULL;
6142 a_attr = a_attr->dw_attr_next)
6144 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6145 dwarf_attr_name (a_attr->dw_attr));
6146 output_value_format (a_attr);
6149 dw2_asm_output_data (1, 0, NULL);
6150 dw2_asm_output_data (1, 0, NULL);
6153 /* Terminate the table. */
6154 dw2_asm_output_data (1, 0, NULL);
6157 /* Output a symbol we can use to refer to this DIE from another CU. */
6160 output_die_symbol (die)
6163 char *sym = die->die_symbol;
6168 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6169 /* We make these global, not weak; if the target doesn't support
6170 .linkonce, it doesn't support combining the sections, so debugging
6172 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6174 ASM_OUTPUT_LABEL (asm_out_file, sym);
6177 /* Return a new location list, given the begin and end range, and the
6178 expression. gensym tells us whether to generate a new internal symbol for
6179 this location list node, which is done for the head of the list only. */
6181 static inline dw_loc_list_ref
6182 new_loc_list (expr, begin, end, section, gensym)
6183 dw_loc_descr_ref expr;
6186 const char *section;
6189 dw_loc_list_ref retlist
6190 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6192 retlist->begin = begin;
6194 retlist->expr = expr;
6195 retlist->section = section;
6197 retlist->ll_symbol = gen_internal_sym ("LLST");
6202 /* Add a location description expression to a location list */
6205 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6206 dw_loc_list_ref *list_head;
6207 dw_loc_descr_ref descr;
6210 const char *section;
6214 /* Find the end of the chain. */
6215 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6218 /* Add a new location list node to the list */
6219 *d = new_loc_list (descr, begin, end, section, 0);
6222 /* Output the location list given to us */
6225 output_loc_list (list_head)
6226 dw_loc_list_ref list_head;
6228 dw_loc_list_ref curr = list_head;
6230 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6232 /* ??? This shouldn't be needed now that we've forced the
6233 compilation unit base address to zero when there is code
6234 in more than one section. */
6235 if (strcmp (curr->section, ".text") == 0)
6237 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6238 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
6239 "Location list base address specifier fake entry");
6240 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6241 "Location list base address specifier base");
6244 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
6248 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6249 "Location list begin address (%s)",
6250 list_head->ll_symbol);
6251 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6252 "Location list end address (%s)",
6253 list_head->ll_symbol);
6254 size = size_of_locs (curr->expr);
6256 /* Output the block length for this list of location operations. */
6259 dw2_asm_output_data (2, size, "%s", "Location expression size");
6261 output_loc_sequence (curr->expr);
6264 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6265 "Location list terminator begin (%s)",
6266 list_head->ll_symbol);
6267 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6268 "Location list terminator end (%s)",
6269 list_head->ll_symbol);
6272 /* Output the DIE and its attributes. Called recursively to generate
6273 the definitions of each child DIE. */
6283 /* If someone in another CU might refer to us, set up a symbol for
6284 them to point to. */
6285 if (die->die_symbol)
6286 output_die_symbol (die);
6288 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6289 die->die_offset, dwarf_tag_name (die->die_tag));
6291 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6293 const char *name = dwarf_attr_name (a->dw_attr);
6295 switch (AT_class (a))
6297 case dw_val_class_addr:
6298 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6301 case dw_val_class_offset:
6302 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6306 case dw_val_class_range_list:
6308 char *p = strchr (ranges_section_label, '\0');
6310 sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset);
6311 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6317 case dw_val_class_loc:
6318 size = size_of_locs (AT_loc (a));
6320 /* Output the block length for this list of location operations. */
6321 dw2_asm_output_data (constant_size (size), size, "%s", name);
6323 output_loc_sequence (AT_loc (a));
6326 case dw_val_class_const:
6327 /* ??? It would be slightly more efficient to use a scheme like is
6328 used for unsigned constants below, but gdb 4.x does not sign
6329 extend. Gdb 5.x does sign extend. */
6330 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6333 case dw_val_class_unsigned_const:
6334 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6335 AT_unsigned (a), "%s", name);
6338 case dw_val_class_long_long:
6340 unsigned HOST_WIDE_INT first, second;
6342 dw2_asm_output_data (1,
6343 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6346 if (WORDS_BIG_ENDIAN)
6348 first = a->dw_attr_val.v.val_long_long.hi;
6349 second = a->dw_attr_val.v.val_long_long.low;
6353 first = a->dw_attr_val.v.val_long_long.low;
6354 second = a->dw_attr_val.v.val_long_long.hi;
6357 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6358 first, "long long constant");
6359 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6364 case dw_val_class_float:
6368 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6371 for (i = 0; i < a->dw_attr_val.v.val_float.length; i++)
6372 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6373 "fp constant word %u", i);
6377 case dw_val_class_flag:
6378 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6381 case dw_val_class_loc_list:
6383 char *sym = AT_loc_list (a)->ll_symbol;
6387 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6388 loc_section_label, "%s", name);
6392 case dw_val_class_die_ref:
6393 if (AT_ref_external (a))
6395 char *sym = AT_ref (a)->die_symbol;
6399 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6401 else if (AT_ref (a)->die_offset == 0)
6404 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6408 case dw_val_class_fde_ref:
6412 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6413 a->dw_attr_val.v.val_fde_index * 2);
6414 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6418 case dw_val_class_lbl_id:
6419 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6422 case dw_val_class_lbl_offset:
6423 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6426 case dw_val_class_str:
6427 if (AT_string_form (a) == DW_FORM_strp)
6428 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6429 a->dw_attr_val.v.val_str->label,
6430 "%s: \"%s\"", name, AT_string (a));
6432 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6440 for (c = die->die_child; c != NULL; c = c->die_sib)
6443 /* Add null byte to terminate sibling list. */
6444 if (die->die_child != NULL)
6445 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6449 /* Output the compilation unit that appears at the beginning of the
6450 .debug_info section, and precedes the DIE descriptions. */
6453 output_compilation_unit_header ()
6455 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6456 "Length of Compilation Unit Info");
6457 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6458 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6459 "Offset Into Abbrev. Section");
6460 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6463 /* Output the compilation unit DIE and its children. */
6466 output_comp_unit (die)
6469 const char *secname;
6471 /* Even if there are no children of this DIE, we must output the information
6472 about the compilation unit. Otherwise, on an empty translation unit, we
6473 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6474 will then complain when examining the file. First mark all the DIEs in
6475 this CU so we know which get local refs. */
6478 build_abbrev_table (die);
6480 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6481 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6482 calc_die_sizes (die);
6484 if (die->die_symbol)
6486 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6488 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6490 die->die_symbol = NULL;
6493 secname = (const char *) DEBUG_INFO_SECTION;
6495 /* Output debugging information. */
6496 named_section_flags (secname, SECTION_DEBUG);
6497 output_compilation_unit_header ();
6500 /* Leave the marks on the main CU, so we can check them in
6502 if (die->die_symbol)
6506 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6507 output of lang_hooks.decl_printable_name for C++ looks like
6508 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6511 dwarf2_name (decl, scope)
6515 return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0);
6518 /* Add a new entry to .debug_pubnames if appropriate. */
6521 add_pubname (decl, die)
6527 if (! TREE_PUBLIC (decl))
6530 if (pubname_table_in_use == pubname_table_allocated)
6532 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6534 = (pubname_ref) xrealloc (pubname_table,
6535 (pubname_table_allocated
6536 * sizeof (pubname_entry)));
6539 p = &pubname_table[pubname_table_in_use++];
6541 p->name = xstrdup (dwarf2_name (decl, 1));
6544 /* Output the public names table used to speed up access to externally
6545 visible names. For now, only generate entries for externally
6546 visible procedures. */
6552 unsigned long pubnames_length = size_of_pubnames ();
6554 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6555 "Length of Public Names Info");
6556 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6557 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6558 "Offset of Compilation Unit Info");
6559 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6560 "Compilation Unit Length");
6562 for (i = 0; i < pubname_table_in_use; i++)
6564 pubname_ref pub = &pubname_table[i];
6566 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6567 if (pub->die->die_mark == 0)
6570 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6573 dw2_asm_output_nstring (pub->name, -1, "external name");
6576 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6579 /* Add a new entry to .debug_aranges if appropriate. */
6582 add_arange (decl, die)
6586 if (! DECL_SECTION_NAME (decl))
6589 if (arange_table_in_use == arange_table_allocated)
6591 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6592 arange_table = (dw_die_ref *)
6593 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6596 arange_table[arange_table_in_use++] = die;
6599 /* Output the information that goes into the .debug_aranges table.
6600 Namely, define the beginning and ending address range of the
6601 text section generated for this compilation unit. */
6607 unsigned long aranges_length = size_of_aranges ();
6609 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6610 "Length of Address Ranges Info");
6611 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6612 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6613 "Offset of Compilation Unit Info");
6614 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6615 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6617 /* We need to align to twice the pointer size here. */
6618 if (DWARF_ARANGES_PAD_SIZE)
6620 /* Pad using a 2 byte words so that padding is correct for any
6622 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6623 2 * DWARF2_ADDR_SIZE);
6624 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6625 dw2_asm_output_data (2, 0, NULL);
6628 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6629 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6630 text_section_label, "Length");
6632 for (i = 0; i < arange_table_in_use; i++)
6634 dw_die_ref die = arange_table[i];
6636 /* We shouldn't see aranges for DIEs outside of the main CU. */
6637 if (die->die_mark == 0)
6640 if (die->die_tag == DW_TAG_subprogram)
6642 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6644 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6645 get_AT_low_pc (die), "Length");
6649 /* A static variable; extract the symbol from DW_AT_location.
6650 Note that this code isn't currently hit, as we only emit
6651 aranges for functions (jason 9/23/99). */
6652 dw_attr_ref a = get_AT (die, DW_AT_location);
6653 dw_loc_descr_ref loc;
6655 if (! a || AT_class (a) != dw_val_class_loc)
6659 if (loc->dw_loc_opc != DW_OP_addr)
6662 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6663 loc->dw_loc_oprnd1.v.val_addr, "Address");
6664 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6665 get_AT_unsigned (die, DW_AT_byte_size),
6670 /* Output the terminator words. */
6671 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6672 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6675 /* Add a new entry to .debug_ranges. Return the offset at which it
6682 unsigned int in_use = ranges_table_in_use;
6684 if (in_use == ranges_table_allocated)
6686 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6687 ranges_table = (dw_ranges_ref)
6688 xrealloc (ranges_table, (ranges_table_allocated
6689 * sizeof (struct dw_ranges_struct)));
6692 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6693 ranges_table_in_use = in_use + 1;
6695 return in_use * 2 * DWARF2_ADDR_SIZE;
6702 static const char *const start_fmt = "Offset 0x%x";
6703 const char *fmt = start_fmt;
6705 for (i = 0; i < ranges_table_in_use; i++)
6707 int block_num = ranges_table[i].block_num;
6711 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6712 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6714 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6715 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6717 /* If all code is in the text section, then the compilation
6718 unit base address defaults to DW_AT_low_pc, which is the
6719 base of the text section. */
6720 if (separate_line_info_table_in_use == 0)
6722 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6724 fmt, i * 2 * DWARF2_ADDR_SIZE);
6725 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6726 text_section_label, NULL);
6729 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6730 compilation unit base address to zero, which allows us to
6731 use absolute addresses, and not worry about whether the
6732 target supports cross-section arithmetic. */
6735 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6736 fmt, i * 2 * DWARF2_ADDR_SIZE);
6737 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6744 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6745 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6751 /* Data structure containing information about input files. */
6754 char *path; /* Complete file name. */
6755 char *fname; /* File name part. */
6756 int length; /* Length of entire string. */
6757 int file_idx; /* Index in input file table. */
6758 int dir_idx; /* Index in directory table. */
6761 /* Data structure containing information about directories with source
6765 char *path; /* Path including directory name. */
6766 int length; /* Path length. */
6767 int prefix; /* Index of directory entry which is a prefix. */
6768 int count; /* Number of files in this directory. */
6769 int dir_idx; /* Index of directory used as base. */
6770 int used; /* Used in the end? */
6773 /* Callback function for file_info comparison. We sort by looking at
6774 the directories in the path. */
6777 file_info_cmp (p1, p2)
6781 const struct file_info *s1 = p1;
6782 const struct file_info *s2 = p2;
6786 /* Take care of file names without directories. We need to make sure that
6787 we return consistent values to qsort since some will get confused if
6788 we return the same value when identical operands are passed in opposite
6789 orders. So if neither has a directory, return 0 and otherwise return
6790 1 or -1 depending on which one has the directory. */
6791 if ((s1->path == s1->fname || s2->path == s2->fname))
6792 return (s2->path == s2->fname) - (s1->path == s1->fname);
6794 cp1 = (unsigned char *) s1->path;
6795 cp2 = (unsigned char *) s2->path;
6801 /* Reached the end of the first path? If so, handle like above. */
6802 if ((cp1 == (unsigned char *) s1->fname)
6803 || (cp2 == (unsigned char *) s2->fname))
6804 return ((cp2 == (unsigned char *) s2->fname)
6805 - (cp1 == (unsigned char *) s1->fname));
6807 /* Character of current path component the same? */
6808 else if (*cp1 != *cp2)
6813 /* Output the directory table and the file name table. We try to minimize
6814 the total amount of memory needed. A heuristic is used to avoid large
6815 slowdowns with many input files. */
6818 output_file_names ()
6820 struct file_info *files;
6821 struct dir_info *dirs;
6830 /* Allocate the various arrays we need. */
6831 files = (struct file_info *) alloca (file_table.in_use
6832 * sizeof (struct file_info));
6833 dirs = (struct dir_info *) alloca (file_table.in_use
6834 * sizeof (struct dir_info));
6836 /* Sort the file names. */
6837 for (i = 1; i < (int) file_table.in_use; i++)
6841 /* Skip all leading "./". */
6842 f = file_table.table[i];
6843 while (f[0] == '.' && f[1] == '/')
6846 /* Create a new array entry. */
6848 files[i].length = strlen (f);
6849 files[i].file_idx = i;
6851 /* Search for the file name part. */
6852 f = strrchr (f, '/');
6853 files[i].fname = f == NULL ? files[i].path : f + 1;
6856 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6858 /* Find all the different directories used. */
6859 dirs[0].path = files[1].path;
6860 dirs[0].length = files[1].fname - files[1].path;
6861 dirs[0].prefix = -1;
6863 dirs[0].dir_idx = 0;
6865 files[1].dir_idx = 0;
6868 for (i = 2; i < (int) file_table.in_use; i++)
6869 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6870 && memcmp (dirs[ndirs - 1].path, files[i].path,
6871 dirs[ndirs - 1].length) == 0)
6873 /* Same directory as last entry. */
6874 files[i].dir_idx = ndirs - 1;
6875 ++dirs[ndirs - 1].count;
6881 /* This is a new directory. */
6882 dirs[ndirs].path = files[i].path;
6883 dirs[ndirs].length = files[i].fname - files[i].path;
6884 dirs[ndirs].count = 1;
6885 dirs[ndirs].dir_idx = ndirs;
6886 dirs[ndirs].used = 0;
6887 files[i].dir_idx = ndirs;
6889 /* Search for a prefix. */
6890 dirs[ndirs].prefix = -1;
6891 for (j = 0; j < ndirs; j++)
6892 if (dirs[j].length < dirs[ndirs].length
6893 && dirs[j].length > 1
6894 && (dirs[ndirs].prefix == -1
6895 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6896 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6897 dirs[ndirs].prefix = j;
6902 /* Now to the actual work. We have to find a subset of the directories which
6903 allow expressing the file name using references to the directory table
6904 with the least amount of characters. We do not do an exhaustive search
6905 where we would have to check out every combination of every single
6906 possible prefix. Instead we use a heuristic which provides nearly optimal
6907 results in most cases and never is much off. */
6908 saved = (int *) alloca (ndirs * sizeof (int));
6909 savehere = (int *) alloca (ndirs * sizeof (int));
6911 memset (saved, '\0', ndirs * sizeof (saved[0]));
6912 for (i = 0; i < ndirs; i++)
6917 /* We can always save some space for the current directory. But this
6918 does not mean it will be enough to justify adding the directory. */
6919 savehere[i] = dirs[i].length;
6920 total = (savehere[i] - saved[i]) * dirs[i].count;
6922 for (j = i + 1; j < ndirs; j++)
6925 if (saved[j] < dirs[i].length)
6927 /* Determine whether the dirs[i] path is a prefix of the
6932 while (k != -1 && k != i)
6937 /* Yes it is. We can possibly safe some memory but
6938 writing the filenames in dirs[j] relative to
6940 savehere[j] = dirs[i].length;
6941 total += (savehere[j] - saved[j]) * dirs[j].count;
6946 /* Check whether we can safe enough to justify adding the dirs[i]
6948 if (total > dirs[i].length + 1)
6950 /* It's worthwhile adding. */
6951 for (j = i; j < ndirs; j++)
6952 if (savehere[j] > 0)
6954 /* Remember how much we saved for this directory so far. */
6955 saved[j] = savehere[j];
6957 /* Remember the prefix directory. */
6958 dirs[j].dir_idx = i;
6963 /* We have to emit them in the order they appear in the file_table array
6964 since the index is used in the debug info generation. To do this
6965 efficiently we generate a back-mapping of the indices first. */
6966 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6967 for (i = 1; i < (int) file_table.in_use; i++)
6969 backmap[files[i].file_idx] = i;
6971 /* Mark this directory as used. */
6972 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6975 /* That was it. We are ready to emit the information. First emit the
6976 directory name table. We have to make sure the first actually emitted
6977 directory name has index one; zero is reserved for the current working
6978 directory. Make sure we do not confuse these indices with the one for the
6979 constructed table (even though most of the time they are identical). */
6981 idx_offset = dirs[0].length > 0 ? 1 : 0;
6982 for (i = 1 - idx_offset; i < ndirs; i++)
6983 if (dirs[i].used != 0)
6985 dirs[i].used = idx++;
6986 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6987 "Directory Entry: 0x%x", dirs[i].used);
6990 dw2_asm_output_data (1, 0, "End directory table");
6992 /* Correct the index for the current working directory entry if it
6994 if (idx_offset == 0)
6997 /* Now write all the file names. */
6998 for (i = 1; i < (int) file_table.in_use; i++)
7000 int file_idx = backmap[i];
7001 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
7003 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
7004 "File Entry: 0x%x", i);
7006 /* Include directory index. */
7007 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
7009 /* Modification time. */
7010 dw2_asm_output_data_uleb128 (0, NULL);
7012 /* File length in bytes. */
7013 dw2_asm_output_data_uleb128 (0, NULL);
7016 dw2_asm_output_data (1, 0, "End file name table");
7020 /* Output the source line number correspondence information. This
7021 information goes into the .debug_line section. */
7026 char l1[20], l2[20], p1[20], p2[20];
7027 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7028 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7031 unsigned long lt_index;
7032 unsigned long current_line;
7035 unsigned long current_file;
7036 unsigned long function;
7038 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7039 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7040 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7041 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7043 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7044 "Length of Source Line Info");
7045 ASM_OUTPUT_LABEL (asm_out_file, l1);
7047 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7048 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7049 ASM_OUTPUT_LABEL (asm_out_file, p1);
7051 /* Define the architecture-dependent minimum instruction length (in
7052 bytes). In this implementation of DWARF, this field is used for
7053 information purposes only. Since GCC generates assembly language,
7054 we have no a priori knowledge of how many instruction bytes are
7055 generated for each source line, and therefore can use only the
7056 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7057 commands. Accordingly, we fix this as `1', which is "correct
7058 enough" for all architectures, and don't let the target override. */
7059 dw2_asm_output_data (1, 1,
7060 "Minimum Instruction Length");
7062 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7063 "Default is_stmt_start flag");
7064 dw2_asm_output_data (1, DWARF_LINE_BASE,
7065 "Line Base Value (Special Opcodes)");
7066 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7067 "Line Range Value (Special Opcodes)");
7068 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7069 "Special Opcode Base");
7071 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7075 case DW_LNS_advance_pc:
7076 case DW_LNS_advance_line:
7077 case DW_LNS_set_file:
7078 case DW_LNS_set_column:
7079 case DW_LNS_fixed_advance_pc:
7087 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7091 /* Write out the information about the files we use. */
7092 output_file_names ();
7093 ASM_OUTPUT_LABEL (asm_out_file, p2);
7095 /* We used to set the address register to the first location in the text
7096 section here, but that didn't accomplish anything since we already
7097 have a line note for the opening brace of the first function. */
7099 /* Generate the line number to PC correspondence table, encoded as
7100 a series of state machine operations. */
7103 strcpy (prev_line_label, text_section_label);
7104 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7106 dw_line_info_ref line_info = &line_info_table[lt_index];
7109 /* Disable this optimization for now; GDB wants to see two line notes
7110 at the beginning of a function so it can find the end of the
7113 /* Don't emit anything for redundant notes. Just updating the
7114 address doesn't accomplish anything, because we already assume
7115 that anything after the last address is this line. */
7116 if (line_info->dw_line_num == current_line
7117 && line_info->dw_file_num == current_file)
7121 /* Emit debug info for the address of the current line.
7123 Unfortunately, we have little choice here currently, and must always
7124 use the most general form. GCC does not know the address delta
7125 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7126 attributes which will give an upper bound on the address range. We
7127 could perhaps use length attributes to determine when it is safe to
7128 use DW_LNS_fixed_advance_pc. */
7130 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7133 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7134 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7135 "DW_LNS_fixed_advance_pc");
7136 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7140 /* This can handle any delta. This takes
7141 4+DWARF2_ADDR_SIZE bytes. */
7142 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7143 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7144 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7145 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7148 strcpy (prev_line_label, line_label);
7150 /* Emit debug info for the source file of the current line, if
7151 different from the previous line. */
7152 if (line_info->dw_file_num != current_file)
7154 current_file = line_info->dw_file_num;
7155 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7156 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7157 file_table.table[current_file]);
7160 /* Emit debug info for the current line number, choosing the encoding
7161 that uses the least amount of space. */
7162 if (line_info->dw_line_num != current_line)
7164 line_offset = line_info->dw_line_num - current_line;
7165 line_delta = line_offset - DWARF_LINE_BASE;
7166 current_line = line_info->dw_line_num;
7167 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7168 /* This can handle deltas from -10 to 234, using the current
7169 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7171 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7172 "line %lu", current_line);
7175 /* This can handle any delta. This takes at least 4 bytes,
7176 depending on the value being encoded. */
7177 dw2_asm_output_data (1, DW_LNS_advance_line,
7178 "advance to line %lu", current_line);
7179 dw2_asm_output_data_sleb128 (line_offset, NULL);
7180 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7184 /* We still need to start a new row, so output a copy insn. */
7185 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7188 /* Emit debug info for the address of the end of the function. */
7191 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7192 "DW_LNS_fixed_advance_pc");
7193 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7197 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7198 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7199 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7200 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7203 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7204 dw2_asm_output_data_uleb128 (1, NULL);
7205 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7210 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7212 dw_separate_line_info_ref line_info
7213 = &separate_line_info_table[lt_index];
7216 /* Don't emit anything for redundant notes. */
7217 if (line_info->dw_line_num == current_line
7218 && line_info->dw_file_num == current_file
7219 && line_info->function == function)
7223 /* Emit debug info for the address of the current line. If this is
7224 a new function, or the first line of a function, then we need
7225 to handle it differently. */
7226 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7228 if (function != line_info->function)
7230 function = line_info->function;
7232 /* Set the address register to the first line in the function */
7233 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7234 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7235 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7236 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7240 /* ??? See the DW_LNS_advance_pc comment above. */
7243 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7244 "DW_LNS_fixed_advance_pc");
7245 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7249 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7250 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7251 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7252 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7256 strcpy (prev_line_label, line_label);
7258 /* Emit debug info for the source file of the current line, if
7259 different from the previous line. */
7260 if (line_info->dw_file_num != current_file)
7262 current_file = line_info->dw_file_num;
7263 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7264 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7265 file_table.table[current_file]);
7268 /* Emit debug info for the current line number, choosing the encoding
7269 that uses the least amount of space. */
7270 if (line_info->dw_line_num != current_line)
7272 line_offset = line_info->dw_line_num - current_line;
7273 line_delta = line_offset - DWARF_LINE_BASE;
7274 current_line = line_info->dw_line_num;
7275 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7276 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7277 "line %lu", current_line);
7280 dw2_asm_output_data (1, DW_LNS_advance_line,
7281 "advance to line %lu", current_line);
7282 dw2_asm_output_data_sleb128 (line_offset, NULL);
7283 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7287 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7295 /* If we're done with a function, end its sequence. */
7296 if (lt_index == separate_line_info_table_in_use
7297 || separate_line_info_table[lt_index].function != function)
7302 /* Emit debug info for the address of the end of the function. */
7303 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7306 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7307 "DW_LNS_fixed_advance_pc");
7308 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7312 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7313 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7314 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7315 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7318 /* Output the marker for the end of this sequence. */
7319 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7320 dw2_asm_output_data_uleb128 (1, NULL);
7321 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7325 /* Output the marker for the end of the line number info. */
7326 ASM_OUTPUT_LABEL (asm_out_file, l2);
7329 /* Given a pointer to a tree node for some base type, return a pointer to
7330 a DIE that describes the given type.
7332 This routine must only be called for GCC type nodes that correspond to
7333 Dwarf base (fundamental) types. */
7336 base_type_die (type)
7339 dw_die_ref base_type_result;
7340 const char *type_name;
7341 enum dwarf_type encoding;
7342 tree name = TYPE_NAME (type);
7344 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7349 if (TREE_CODE (name) == TYPE_DECL)
7350 name = DECL_NAME (name);
7352 type_name = IDENTIFIER_POINTER (name);
7355 type_name = "__unknown__";
7357 switch (TREE_CODE (type))
7360 /* Carefully distinguish the C character types, without messing
7361 up if the language is not C. Note that we check only for the names
7362 that contain spaces; other names might occur by coincidence in other
7364 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7365 && (type == char_type_node
7366 || ! strcmp (type_name, "signed char")
7367 || ! strcmp (type_name, "unsigned char"))))
7369 if (TREE_UNSIGNED (type))
7370 encoding = DW_ATE_unsigned;
7372 encoding = DW_ATE_signed;
7375 /* else fall through. */
7378 /* GNU Pascal/Ada CHAR type. Not used in C. */
7379 if (TREE_UNSIGNED (type))
7380 encoding = DW_ATE_unsigned_char;
7382 encoding = DW_ATE_signed_char;
7386 encoding = DW_ATE_float;
7389 /* Dwarf2 doesn't know anything about complex ints, so use
7390 a user defined type for it. */
7392 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7393 encoding = DW_ATE_complex_float;
7395 encoding = DW_ATE_lo_user;
7399 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7400 encoding = DW_ATE_boolean;
7404 /* No other TREE_CODEs are Dwarf fundamental types. */
7408 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
7409 if (demangle_name_func)
7410 type_name = (*demangle_name_func) (type_name);
7412 add_AT_string (base_type_result, DW_AT_name, type_name);
7413 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7414 int_size_in_bytes (type));
7415 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7417 return base_type_result;
7420 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7421 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7422 a given type is generally the same as the given type, except that if the
7423 given type is a pointer or reference type, then the root type of the given
7424 type is the root type of the "basis" type for the pointer or reference
7425 type. (This definition of the "root" type is recursive.) Also, the root
7426 type of a `const' qualified type or a `volatile' qualified type is the
7427 root type of the given type without the qualifiers. */
7433 if (TREE_CODE (type) == ERROR_MARK)
7434 return error_mark_node;
7436 switch (TREE_CODE (type))
7439 return error_mark_node;
7442 case REFERENCE_TYPE:
7443 return type_main_variant (root_type (TREE_TYPE (type)));
7446 return type_main_variant (type);
7450 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7451 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7457 switch (TREE_CODE (type))
7472 case QUAL_UNION_TYPE:
7477 case REFERENCE_TYPE:
7491 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7492 entry that chains various modifiers in front of the given type. */
7495 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7498 int is_volatile_type;
7499 dw_die_ref context_die;
7501 enum tree_code code = TREE_CODE (type);
7502 dw_die_ref mod_type_die = NULL;
7503 dw_die_ref sub_die = NULL;
7504 tree item_type = NULL;
7506 if (code != ERROR_MARK)
7508 tree qualified_type;
7510 /* See if we already have the appropriately qualified variant of
7513 = get_qualified_type (type,
7514 ((is_const_type ? TYPE_QUAL_CONST : 0)
7516 ? TYPE_QUAL_VOLATILE : 0)));
7518 /* If we do, then we can just use its DIE, if it exists. */
7521 mod_type_die = lookup_type_die (qualified_type);
7523 return mod_type_die;
7526 /* Handle C typedef types. */
7527 if (qualified_type && TYPE_NAME (qualified_type)
7528 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7529 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7531 tree type_name = TYPE_NAME (qualified_type);
7532 tree dtype = TREE_TYPE (type_name);
7534 if (qualified_type == dtype)
7536 /* For a named type, use the typedef. */
7537 gen_type_die (qualified_type, context_die);
7538 mod_type_die = lookup_type_die (qualified_type);
7540 else if (is_const_type < TYPE_READONLY (dtype)
7541 || is_volatile_type < TYPE_VOLATILE (dtype))
7542 /* cv-unqualified version of named type. Just use the unnamed
7543 type to which it refers. */
7545 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7546 is_const_type, is_volatile_type,
7549 /* Else cv-qualified version of named type; fall through. */
7555 else if (is_const_type)
7557 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
7558 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7560 else if (is_volatile_type)
7562 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
7563 sub_die = modified_type_die (type, 0, 0, context_die);
7565 else if (code == POINTER_TYPE)
7567 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
7568 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7570 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7572 item_type = TREE_TYPE (type);
7574 else if (code == REFERENCE_TYPE)
7576 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
7577 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7579 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7581 item_type = TREE_TYPE (type);
7583 else if (is_base_type (type))
7584 mod_type_die = base_type_die (type);
7587 gen_type_die (type, context_die);
7589 /* We have to get the type_main_variant here (and pass that to the
7590 `lookup_type_die' routine) because the ..._TYPE node we have
7591 might simply be a *copy* of some original type node (where the
7592 copy was created to help us keep track of typedef names) and
7593 that copy might have a different TYPE_UID from the original
7595 if (TREE_CODE (type) != VECTOR_TYPE)
7596 mod_type_die = lookup_type_die (type_main_variant (type));
7598 /* Vectors have the debugging information in the type,
7599 not the main variant. */
7600 mod_type_die = lookup_type_die (type);
7601 if (mod_type_die == NULL)
7605 /* We want to equate the qualified type to the die below. */
7607 type = qualified_type;
7610 equate_type_number_to_die (type, mod_type_die);
7612 /* We must do this after the equate_type_number_to_die call, in case
7613 this is a recursive type. This ensures that the modified_type_die
7614 recursion will terminate even if the type is recursive. Recursive
7615 types are possible in Ada. */
7616 sub_die = modified_type_die (item_type,
7617 TYPE_READONLY (item_type),
7618 TYPE_VOLATILE (item_type),
7621 if (sub_die != NULL)
7622 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7624 return mod_type_die;
7627 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7628 an enumerated type. */
7634 return TREE_CODE (type) == ENUMERAL_TYPE;
7637 /* Return the register number described by a given RTL node. */
7643 unsigned regno = REGNO (rtl);
7645 if (regno >= FIRST_PSEUDO_REGISTER)
7648 return DBX_REGISTER_NUMBER (regno);
7651 /* Return a location descriptor that designates a machine register or
7652 zero if there is no such. */
7654 static dw_loc_descr_ref
7655 reg_loc_descriptor (rtl)
7658 dw_loc_descr_ref loc_result = NULL;
7659 unsigned reg, i, max;
7661 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7664 reg = reg_number (rtl);
7665 max = HARD_REGNO_NREGS (reg, GET_MODE (rtl));
7666 for (i = 0; i < max; ++i)
7668 add_loc_descr (&loc_result,
7669 new_loc_descr (reg <= 31 ? DW_OP_reg0 + reg : DW_OP_regx,
7670 reg <= 31 ? 0 : reg,
7674 add_loc_descr (&loc_result,
7675 new_loc_descr (DW_OP_piece,
7676 GET_MODE_SIZE (reg_raw_mode[reg]), 0));
7684 /* Return a location descriptor that designates a constant. */
7686 static dw_loc_descr_ref
7687 int_loc_descriptor (i)
7690 enum dwarf_location_atom op;
7692 /* Pick the smallest representation of a constant, rather than just
7693 defaulting to the LEB encoding. */
7697 op = DW_OP_lit0 + i;
7700 else if (i <= 0xffff)
7702 else if (HOST_BITS_PER_WIDE_INT == 32
7712 else if (i >= -0x8000)
7714 else if (HOST_BITS_PER_WIDE_INT == 32
7715 || i >= -0x80000000)
7721 return new_loc_descr (op, i, 0);
7724 /* Return a location descriptor that designates a base+offset location. */
7726 static dw_loc_descr_ref
7727 based_loc_descr (reg, offset)
7731 dw_loc_descr_ref loc_result;
7732 /* For the "frame base", we use the frame pointer or stack pointer
7733 registers, since the RTL for local variables is relative to one of
7735 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7736 ? HARD_FRAME_POINTER_REGNUM
7737 : STACK_POINTER_REGNUM);
7740 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7742 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7744 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7749 /* Return true if this RTL expression describes a base+offset calculation. */
7755 return (GET_CODE (rtl) == PLUS
7756 && ((GET_CODE (XEXP (rtl, 0)) == REG
7757 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
7758 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7761 /* The following routine converts the RTL for a variable or parameter
7762 (resident in memory) into an equivalent Dwarf representation of a
7763 mechanism for getting the address of that same variable onto the top of a
7764 hypothetical "address evaluation" stack.
7766 When creating memory location descriptors, we are effectively transforming
7767 the RTL for a memory-resident object into its Dwarf postfix expression
7768 equivalent. This routine recursively descends an RTL tree, turning
7769 it into Dwarf postfix code as it goes.
7771 MODE is the mode of the memory reference, needed to handle some
7772 autoincrement addressing modes.
7774 Return 0 if we can't represent the location. */
7776 static dw_loc_descr_ref
7777 mem_loc_descriptor (rtl, mode)
7779 enum machine_mode mode;
7781 dw_loc_descr_ref mem_loc_result = NULL;
7783 /* Note that for a dynamically sized array, the location we will generate a
7784 description of here will be the lowest numbered location which is
7785 actually within the array. That's *not* necessarily the same as the
7786 zeroth element of the array. */
7788 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7789 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7792 switch (GET_CODE (rtl))
7797 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7798 just fall into the SUBREG code. */
7800 /* ... fall through ... */
7803 /* The case of a subreg may arise when we have a local (register)
7804 variable or a formal (register) parameter which doesn't quite fill
7805 up an entire register. For now, just assume that it is
7806 legitimate to make the Dwarf info refer to the whole register which
7807 contains the given subreg. */
7808 rtl = SUBREG_REG (rtl);
7810 /* ... fall through ... */
7813 /* Whenever a register number forms a part of the description of the
7814 method for calculating the (dynamic) address of a memory resident
7815 object, DWARF rules require the register number be referred to as
7816 a "base register". This distinction is not based in any way upon
7817 what category of register the hardware believes the given register
7818 belongs to. This is strictly DWARF terminology we're dealing with
7819 here. Note that in cases where the location of a memory-resident
7820 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7821 OP_CONST (0)) the actual DWARF location descriptor that we generate
7822 may just be OP_BASEREG (basereg). This may look deceptively like
7823 the object in question was allocated to a register (rather than in
7824 memory) so DWARF consumers need to be aware of the subtle
7825 distinction between OP_REG and OP_BASEREG. */
7826 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
7827 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7831 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7832 if (mem_loc_result != 0)
7833 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7837 /* Some ports can transform a symbol ref into a label ref, because
7838 the symbol ref is too far away and has to be dumped into a constant
7842 /* Alternatively, the symbol in the constant pool might be referenced
7843 by a different symbol. */
7844 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
7847 rtx tmp = get_pool_constant_mark (rtl, &marked);
7849 if (GET_CODE (tmp) == SYMBOL_REF)
7852 if (CONSTANT_POOL_ADDRESS_P (tmp))
7853 get_pool_constant_mark (tmp, &marked);
7858 /* If all references to this pool constant were optimized away,
7859 it was not output and thus we can't represent it.
7860 FIXME: might try to use DW_OP_const_value here, though
7861 DW_OP_piece complicates it. */
7866 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7867 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7868 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
7869 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
7873 /* Extract the PLUS expression nested inside and fall into
7875 rtl = XEXP (rtl, 1);
7880 /* Turn these into a PLUS expression and fall into the PLUS code
7882 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7883 GEN_INT (GET_CODE (rtl) == PRE_INC
7884 ? GET_MODE_UNIT_SIZE (mode)
7885 : -GET_MODE_UNIT_SIZE (mode)));
7887 /* ... fall through ... */
7891 if (is_based_loc (rtl))
7892 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7893 INTVAL (XEXP (rtl, 1)));
7896 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7897 if (mem_loc_result == 0)
7900 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7901 && INTVAL (XEXP (rtl, 1)) >= 0)
7902 add_loc_descr (&mem_loc_result,
7903 new_loc_descr (DW_OP_plus_uconst,
7904 INTVAL (XEXP (rtl, 1)), 0));
7907 add_loc_descr (&mem_loc_result,
7908 mem_loc_descriptor (XEXP (rtl, 1), mode));
7909 add_loc_descr (&mem_loc_result,
7910 new_loc_descr (DW_OP_plus, 0, 0));
7917 /* If a pseudo-reg is optimized away, it is possible for it to
7918 be replaced with a MEM containing a multiply. */
7919 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
7920 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
7922 if (op0 == 0 || op1 == 0)
7925 mem_loc_result = op0;
7926 add_loc_descr (&mem_loc_result, op1);
7927 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7932 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7936 /* If this is a MEM, return its address. Otherwise, we can't
7938 if (GET_CODE (XEXP (rtl, 0)) == MEM)
7939 return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode);
7947 return mem_loc_result;
7950 /* Return a descriptor that describes the concatenation of two locations.
7951 This is typically a complex variable. */
7953 static dw_loc_descr_ref
7954 concat_loc_descriptor (x0, x1)
7957 dw_loc_descr_ref cc_loc_result = NULL;
7958 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
7959 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
7961 if (x0_ref == 0 || x1_ref == 0)
7964 cc_loc_result = x0_ref;
7965 add_loc_descr (&cc_loc_result,
7966 new_loc_descr (DW_OP_piece,
7967 GET_MODE_SIZE (GET_MODE (x0)), 0));
7969 add_loc_descr (&cc_loc_result, x1_ref);
7970 add_loc_descr (&cc_loc_result,
7971 new_loc_descr (DW_OP_piece,
7972 GET_MODE_SIZE (GET_MODE (x1)), 0));
7974 return cc_loc_result;
7977 /* Output a proper Dwarf location descriptor for a variable or parameter
7978 which is either allocated in a register or in a memory location. For a
7979 register, we just generate an OP_REG and the register number. For a
7980 memory location we provide a Dwarf postfix expression describing how to
7981 generate the (dynamic) address of the object onto the address stack.
7983 If we don't know how to describe it, return 0. */
7985 static dw_loc_descr_ref
7986 loc_descriptor (rtl)
7989 dw_loc_descr_ref loc_result = NULL;
7991 switch (GET_CODE (rtl))
7994 /* The case of a subreg may arise when we have a local (register)
7995 variable or a formal (register) parameter which doesn't quite fill
7996 up an entire register. For now, just assume that it is
7997 legitimate to make the Dwarf info refer to the whole register which
7998 contains the given subreg. */
7999 rtl = SUBREG_REG (rtl);
8001 /* ... fall through ... */
8004 loc_result = reg_loc_descriptor (rtl);
8008 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8012 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8022 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8023 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8024 looking for an address. Otherwise, we return a value. If we can't make a
8025 descriptor, return 0. */
8027 static dw_loc_descr_ref
8028 loc_descriptor_from_tree (loc, addressp)
8032 dw_loc_descr_ref ret, ret1;
8034 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
8035 enum dwarf_location_atom op;
8037 /* ??? Most of the time we do not take proper care for sign/zero
8038 extending the values properly. Hopefully this won't be a real
8041 switch (TREE_CODE (loc))
8046 case WITH_RECORD_EXPR:
8047 case PLACEHOLDER_EXPR:
8048 /* This case involves extracting fields from an object to determine the
8049 position of other fields. We don't try to encode this here. The
8050 only user of this is Ada, which encodes the needed information using
8051 the names of types. */
8058 /* We can support this only if we can look through conversions and
8059 find an INDIRECT_EXPR. */
8060 for (loc = TREE_OPERAND (loc, 0);
8061 TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR
8062 || TREE_CODE (loc) == NON_LVALUE_EXPR
8063 || TREE_CODE (loc) == VIEW_CONVERT_EXPR
8064 || TREE_CODE (loc) == SAVE_EXPR;
8065 loc = TREE_OPERAND (loc, 0))
8068 return (TREE_CODE (loc) == INDIRECT_REF
8069 ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp)
8075 rtx rtl = rtl_for_decl_location (loc);
8077 if (rtl == NULL_RTX)
8079 else if (CONSTANT_P (rtl))
8081 ret = new_loc_descr (DW_OP_addr, 0, 0);
8082 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8083 ret->dw_loc_oprnd1.v.val_addr = rtl;
8088 enum machine_mode mode = GET_MODE (rtl);
8090 if (GET_CODE (rtl) == MEM)
8093 rtl = XEXP (rtl, 0);
8096 ret = mem_loc_descriptor (rtl, mode);
8102 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8107 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
8111 case NON_LVALUE_EXPR:
8112 case VIEW_CONVERT_EXPR:
8114 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8119 case ARRAY_RANGE_REF:
8122 HOST_WIDE_INT bitsize, bitpos, bytepos;
8123 enum machine_mode mode;
8126 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8127 &unsignedp, &volatilep);
8132 ret = loc_descriptor_from_tree (obj, 1);
8134 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
8137 if (offset != NULL_TREE)
8139 /* Variable offset. */
8140 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8141 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8147 bytepos = bitpos / BITS_PER_UNIT;
8149 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8150 else if (bytepos < 0)
8152 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8153 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8159 if (host_integerp (loc, 0))
8160 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8165 case TRUTH_AND_EXPR:
8166 case TRUTH_ANDIF_EXPR:
8171 case TRUTH_XOR_EXPR:
8177 case TRUTH_ORIF_EXPR:
8182 case TRUNC_DIV_EXPR:
8190 case TRUNC_MOD_EXPR:
8203 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8207 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8208 && host_integerp (TREE_OPERAND (loc, 1), 0))
8210 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8214 add_loc_descr (&ret,
8215 new_loc_descr (DW_OP_plus_uconst,
8216 tree_low_cst (TREE_OPERAND (loc, 1),
8226 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8233 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8240 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8247 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8262 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8263 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8264 if (ret == 0 || ret1 == 0)
8267 add_loc_descr (&ret, ret1);
8268 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8271 case TRUTH_NOT_EXPR:
8285 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8289 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8293 loc = build (COND_EXPR, TREE_TYPE (loc),
8294 build (LT_EXPR, integer_type_node,
8295 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8296 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8298 /* ... fall through ... */
8302 dw_loc_descr_ref lhs
8303 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8304 dw_loc_descr_ref rhs
8305 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8306 dw_loc_descr_ref bra_node, jump_node, tmp;
8308 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8309 if (ret == 0 || lhs == 0 || rhs == 0)
8312 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8313 add_loc_descr (&ret, bra_node);
8315 add_loc_descr (&ret, rhs);
8316 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8317 add_loc_descr (&ret, jump_node);
8319 add_loc_descr (&ret, lhs);
8320 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8321 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
8323 /* ??? Need a node to point the skip at. Use a nop. */
8324 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8325 add_loc_descr (&ret, tmp);
8326 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8327 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8335 /* Show if we can't fill the request for an address. */
8336 if (addressp && indirect_p == 0)
8339 /* If we've got an address and don't want one, dereference. */
8340 if (!addressp && indirect_p > 0)
8342 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8344 if (size > DWARF2_ADDR_SIZE || size == -1)
8346 else if (size == DWARF2_ADDR_SIZE)
8349 op = DW_OP_deref_size;
8351 add_loc_descr (&ret, new_loc_descr (op, size, 0));
8357 /* Given a value, round it up to the lowest multiple of `boundary'
8358 which is not less than the value itself. */
8360 static inline HOST_WIDE_INT
8361 ceiling (value, boundary)
8362 HOST_WIDE_INT value;
8363 unsigned int boundary;
8365 return (((value + boundary - 1) / boundary) * boundary);
8368 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8369 pointer to the declared type for the relevant field variable, or return
8370 `integer_type_node' if the given node turns out to be an
8379 if (TREE_CODE (decl) == ERROR_MARK)
8380 return integer_type_node;
8382 type = DECL_BIT_FIELD_TYPE (decl);
8383 if (type == NULL_TREE)
8384 type = TREE_TYPE (decl);
8389 /* Given a pointer to a tree node, return the alignment in bits for
8390 it, or else return BITS_PER_WORD if the node actually turns out to
8391 be an ERROR_MARK node. */
8393 static inline unsigned
8394 simple_type_align_in_bits (type)
8397 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8400 static inline unsigned
8401 simple_decl_align_in_bits (decl)
8404 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8407 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8408 node, return the size in bits for the type if it is a constant, or else
8409 return the alignment for the type if the type's size is not constant, or
8410 else return BITS_PER_WORD if the type actually turns out to be an
8413 static inline unsigned HOST_WIDE_INT
8414 simple_type_size_in_bits (type)
8418 if (TREE_CODE (type) == ERROR_MARK)
8419 return BITS_PER_WORD;
8420 else if (TYPE_SIZE (type) == NULL_TREE)
8422 else if (host_integerp (TYPE_SIZE (type), 1))
8423 return tree_low_cst (TYPE_SIZE (type), 1);
8425 return TYPE_ALIGN (type);
8428 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8429 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8430 or return 0 if we are unable to determine what that offset is, either
8431 because the argument turns out to be a pointer to an ERROR_MARK node, or
8432 because the offset is actually variable. (We can't handle the latter case
8435 static HOST_WIDE_INT
8436 field_byte_offset (decl)
8439 unsigned int type_align_in_bits;
8440 unsigned int decl_align_in_bits;
8441 unsigned HOST_WIDE_INT type_size_in_bits;
8442 HOST_WIDE_INT object_offset_in_bits;
8444 tree field_size_tree;
8445 HOST_WIDE_INT bitpos_int;
8446 HOST_WIDE_INT deepest_bitpos;
8447 unsigned HOST_WIDE_INT field_size_in_bits;
8449 if (TREE_CODE (decl) == ERROR_MARK)
8451 else if (TREE_CODE (decl) != FIELD_DECL)
8454 type = field_type (decl);
8455 field_size_tree = DECL_SIZE (decl);
8457 /* The size could be unspecified if there was an error, or for
8458 a flexible array member. */
8459 if (! field_size_tree)
8460 field_size_tree = bitsize_zero_node;
8462 /* We cannot yet cope with fields whose positions are variable, so
8463 for now, when we see such things, we simply return 0. Someday, we may
8464 be able to handle such cases, but it will be damn difficult. */
8465 if (! host_integerp (bit_position (decl), 0))
8468 bitpos_int = int_bit_position (decl);
8470 /* If we don't know the size of the field, pretend it's a full word. */
8471 if (host_integerp (field_size_tree, 1))
8472 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8474 field_size_in_bits = BITS_PER_WORD;
8476 type_size_in_bits = simple_type_size_in_bits (type);
8477 type_align_in_bits = simple_type_align_in_bits (type);
8478 decl_align_in_bits = simple_decl_align_in_bits (decl);
8480 /* The GCC front-end doesn't make any attempt to keep track of the starting
8481 bit offset (relative to the start of the containing structure type) of the
8482 hypothetical "containing object" for a bit-field. Thus, when computing
8483 the byte offset value for the start of the "containing object" of a
8484 bit-field, we must deduce this information on our own. This can be rather
8485 tricky to do in some cases. For example, handling the following structure
8486 type definition when compiling for an i386/i486 target (which only aligns
8487 long long's to 32-bit boundaries) can be very tricky:
8489 struct S { int field1; long long field2:31; };
8491 Fortunately, there is a simple rule-of-thumb which can be used in such
8492 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8493 structure shown above. It decides to do this based upon one simple rule
8494 for bit-field allocation. GCC allocates each "containing object" for each
8495 bit-field at the first (i.e. lowest addressed) legitimate alignment
8496 boundary (based upon the required minimum alignment for the declared type
8497 of the field) which it can possibly use, subject to the condition that
8498 there is still enough available space remaining in the containing object
8499 (when allocated at the selected point) to fully accommodate all of the
8500 bits of the bit-field itself.
8502 This simple rule makes it obvious why GCC allocates 8 bytes for each
8503 object of the structure type shown above. When looking for a place to
8504 allocate the "containing object" for `field2', the compiler simply tries
8505 to allocate a 64-bit "containing object" at each successive 32-bit
8506 boundary (starting at zero) until it finds a place to allocate that 64-
8507 bit field such that at least 31 contiguous (and previously unallocated)
8508 bits remain within that selected 64 bit field. (As it turns out, for the
8509 example above, the compiler finds it is OK to allocate the "containing
8510 object" 64-bit field at bit-offset zero within the structure type.)
8512 Here we attempt to work backwards from the limited set of facts we're
8513 given, and we try to deduce from those facts, where GCC must have believed
8514 that the containing object started (within the structure type). The value
8515 we deduce is then used (by the callers of this routine) to generate
8516 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8517 and, in the case of DW_AT_location, regular fields as well). */
8519 /* Figure out the bit-distance from the start of the structure to the
8520 "deepest" bit of the bit-field. */
8521 deepest_bitpos = bitpos_int + field_size_in_bits;
8523 /* This is the tricky part. Use some fancy footwork to deduce where the
8524 lowest addressed bit of the containing object must be. */
8525 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8527 /* Round up to type_align by default. This works best for bitfields. */
8528 object_offset_in_bits += type_align_in_bits - 1;
8529 object_offset_in_bits /= type_align_in_bits;
8530 object_offset_in_bits *= type_align_in_bits;
8532 if (object_offset_in_bits > bitpos_int)
8534 /* Sigh, the decl must be packed. */
8535 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8537 /* Round up to decl_align instead. */
8538 object_offset_in_bits += decl_align_in_bits - 1;
8539 object_offset_in_bits /= decl_align_in_bits;
8540 object_offset_in_bits *= decl_align_in_bits;
8543 return object_offset_in_bits / BITS_PER_UNIT;
8546 /* The following routines define various Dwarf attributes and any data
8547 associated with them. */
8549 /* Add a location description attribute value to a DIE.
8551 This emits location attributes suitable for whole variables and
8552 whole parameters. Note that the location attributes for struct fields are
8553 generated by the routine `data_member_location_attribute' below. */
8556 add_AT_location_description (die, attr_kind, rtl)
8558 enum dwarf_attribute attr_kind;
8561 dw_loc_descr_ref descr = loc_descriptor (rtl);
8564 add_AT_loc (die, attr_kind, descr);
8567 /* Attach the specialized form of location attribute used for data members of
8568 struct and union types. In the special case of a FIELD_DECL node which
8569 represents a bit-field, the "offset" part of this special location
8570 descriptor must indicate the distance in bytes from the lowest-addressed
8571 byte of the containing struct or union type to the lowest-addressed byte of
8572 the "containing object" for the bit-field. (See the `field_byte_offset'
8575 For any given bit-field, the "containing object" is a hypothetical object
8576 (of some integral or enum type) within which the given bit-field lives. The
8577 type of this hypothetical "containing object" is always the same as the
8578 declared type of the individual bit-field itself (for GCC anyway... the
8579 DWARF spec doesn't actually mandate this). Note that it is the size (in
8580 bytes) of the hypothetical "containing object" which will be given in the
8581 DW_AT_byte_size attribute for this bit-field. (See the
8582 `byte_size_attribute' function below.) It is also used when calculating the
8583 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8587 add_data_member_location_attribute (die, decl)
8592 dw_loc_descr_ref loc_descr = 0;
8594 if (TREE_CODE (decl) == TREE_VEC)
8596 /* We're working on the TAG_inheritance for a base class. */
8597 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
8599 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8600 aren't at a fixed offset from all (sub)objects of the same
8601 type. We need to extract the appropriate offset from our
8602 vtable. The following dwarf expression means
8604 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8606 This is specific to the V3 ABI, of course. */
8608 dw_loc_descr_ref tmp;
8610 /* Make a copy of the object address. */
8611 tmp = new_loc_descr (DW_OP_dup, 0, 0);
8612 add_loc_descr (&loc_descr, tmp);
8614 /* Extract the vtable address. */
8615 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8616 add_loc_descr (&loc_descr, tmp);
8618 /* Calculate the address of the offset. */
8619 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
8623 tmp = int_loc_descriptor (-offset);
8624 add_loc_descr (&loc_descr, tmp);
8625 tmp = new_loc_descr (DW_OP_minus, 0, 0);
8626 add_loc_descr (&loc_descr, tmp);
8628 /* Extract the offset. */
8629 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8630 add_loc_descr (&loc_descr, tmp);
8632 /* Add it to the object address. */
8633 tmp = new_loc_descr (DW_OP_plus, 0, 0);
8634 add_loc_descr (&loc_descr, tmp);
8637 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8640 offset = field_byte_offset (decl);
8644 enum dwarf_location_atom op;
8646 /* The DWARF2 standard says that we should assume that the structure
8647 address is already on the stack, so we can specify a structure field
8648 address by using DW_OP_plus_uconst. */
8650 #ifdef MIPS_DEBUGGING_INFO
8651 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8652 operator correctly. It works only if we leave the offset on the
8656 op = DW_OP_plus_uconst;
8659 loc_descr = new_loc_descr (op, offset, 0);
8662 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8665 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8666 does not have a "location" either in memory or in a register. These
8667 things can arise in GNU C when a constant is passed as an actual parameter
8668 to an inlined function. They can also arise in C++ where declared
8669 constants do not necessarily get memory "homes". */
8672 add_const_value_attribute (die, rtl)
8676 switch (GET_CODE (rtl))
8679 /* Note that a CONST_INT rtx could represent either an integer
8680 or a floating-point constant. A CONST_INT is used whenever
8681 the constant will fit into a single word. In all such
8682 cases, the original mode of the constant value is wiped
8683 out, and the CONST_INT rtx is assigned VOIDmode. */
8685 HOST_WIDE_INT val = INTVAL (rtl);
8687 /* ??? We really should be using HOST_WIDE_INT throughout. */
8688 if (val < 0 && (long) val == val)
8689 add_AT_int (die, DW_AT_const_value, (long) val);
8690 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
8691 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8694 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8695 add_AT_long_long (die, DW_AT_const_value,
8696 val >> HOST_BITS_PER_LONG, val);
8705 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8706 floating-point constant. A CONST_DOUBLE is used whenever the
8707 constant requires more than one word in order to be adequately
8708 represented. We output CONST_DOUBLEs as blocks. */
8710 enum machine_mode mode = GET_MODE (rtl);
8712 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8714 unsigned length = GET_MODE_SIZE (mode) / 4;
8715 long *array = (long *) xmalloc (sizeof (long) * length);
8718 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8722 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8726 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8731 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8738 add_AT_float (die, DW_AT_const_value, length, array);
8742 /* ??? We really should be using HOST_WIDE_INT throughout. */
8743 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8746 add_AT_long_long (die, DW_AT_const_value,
8747 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8753 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8759 add_AT_addr (die, DW_AT_const_value, rtl);
8760 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
8764 /* In cases where an inlined instance of an inline function is passed
8765 the address of an `auto' variable (which is local to the caller) we
8766 can get a situation where the DECL_RTL of the artificial local
8767 variable (for the inlining) which acts as a stand-in for the
8768 corresponding formal parameter (of the inline function) will look
8769 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8770 exactly a compile-time constant expression, but it isn't the address
8771 of the (artificial) local variable either. Rather, it represents the
8772 *value* which the artificial local variable always has during its
8773 lifetime. We currently have no way to represent such quasi-constant
8774 values in Dwarf, so for now we just punt and generate nothing. */
8778 /* No other kinds of rtx should be possible here. */
8785 rtl_for_decl_location (decl)
8790 /* Here we have to decide where we are going to say the parameter "lives"
8791 (as far as the debugger is concerned). We only have a couple of
8792 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8794 DECL_RTL normally indicates where the parameter lives during most of the
8795 activation of the function. If optimization is enabled however, this
8796 could be either NULL or else a pseudo-reg. Both of those cases indicate
8797 that the parameter doesn't really live anywhere (as far as the code
8798 generation parts of GCC are concerned) during most of the function's
8799 activation. That will happen (for example) if the parameter is never
8800 referenced within the function.
8802 We could just generate a location descriptor here for all non-NULL
8803 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8804 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8805 where DECL_RTL is NULL or is a pseudo-reg.
8807 Note however that we can only get away with using DECL_INCOMING_RTL as
8808 a backup substitute for DECL_RTL in certain limited cases. In cases
8809 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8810 we can be sure that the parameter was passed using the same type as it is
8811 declared to have within the function, and that its DECL_INCOMING_RTL
8812 points us to a place where a value of that type is passed.
8814 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8815 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8816 because in these cases DECL_INCOMING_RTL points us to a value of some
8817 type which is *different* from the type of the parameter itself. Thus,
8818 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8819 such cases, the debugger would end up (for example) trying to fetch a
8820 `float' from a place which actually contains the first part of a
8821 `double'. That would lead to really incorrect and confusing
8822 output at debug-time.
8824 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8825 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8826 are a couple of exceptions however. On little-endian machines we can
8827 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8828 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8829 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8830 when (on a little-endian machine) a non-prototyped function has a
8831 parameter declared to be of type `short' or `char'. In such cases,
8832 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8833 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8834 passed `int' value. If the debugger then uses that address to fetch
8835 a `short' or a `char' (on a little-endian machine) the result will be
8836 the correct data, so we allow for such exceptional cases below.
8838 Note that our goal here is to describe the place where the given formal
8839 parameter lives during most of the function's activation (i.e. between the
8840 end of the prologue and the start of the epilogue). We'll do that as best
8841 as we can. Note however that if the given formal parameter is modified
8842 sometime during the execution of the function, then a stack backtrace (at
8843 debug-time) will show the function as having been called with the *new*
8844 value rather than the value which was originally passed in. This happens
8845 rarely enough that it is not a major problem, but it *is* a problem, and
8848 A future version of dwarf2out.c may generate two additional attributes for
8849 any given DW_TAG_formal_parameter DIE which will describe the "passed
8850 type" and the "passed location" for the given formal parameter in addition
8851 to the attributes we now generate to indicate the "declared type" and the
8852 "active location" for each parameter. This additional set of attributes
8853 could be used by debuggers for stack backtraces. Separately, note that
8854 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8855 This happens (for example) for inlined-instances of inline function formal
8856 parameters which are never referenced. This really shouldn't be
8857 happening. All PARM_DECL nodes should get valid non-NULL
8858 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8859 values for inlined instances of inline function parameters, so when we see
8860 such cases, we are just out-of-luck for the time being (until integrate.c
8863 /* Use DECL_RTL as the "location" unless we find something better. */
8864 rtl = DECL_RTL_IF_SET (decl);
8866 /* When generating abstract instances, ignore everything except
8867 constants and symbols living in memory. */
8868 if (! reload_completed)
8871 && (CONSTANT_P (rtl)
8872 || (GET_CODE (rtl) == MEM
8873 && CONSTANT_P (XEXP (rtl, 0)))))
8875 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8876 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
8882 else if (TREE_CODE (decl) == PARM_DECL)
8884 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8886 tree declared_type = type_main_variant (TREE_TYPE (decl));
8887 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8889 /* This decl represents a formal parameter which was optimized out.
8890 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8891 all cases where (rtl == NULL_RTX) just below. */
8892 if (declared_type == passed_type)
8893 rtl = DECL_INCOMING_RTL (decl);
8894 else if (! BYTES_BIG_ENDIAN
8895 && TREE_CODE (declared_type) == INTEGER_TYPE
8896 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8897 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8898 rtl = DECL_INCOMING_RTL (decl);
8901 /* If the parm was passed in registers, but lives on the stack, then
8902 make a big endian correction if the mode of the type of the
8903 parameter is not the same as the mode of the rtl. */
8904 /* ??? This is the same series of checks that are made in dbxout.c before
8905 we reach the big endian correction code there. It isn't clear if all
8906 of these checks are necessary here, but keeping them all is the safe
8908 else if (GET_CODE (rtl) == MEM
8909 && XEXP (rtl, 0) != const0_rtx
8910 && ! CONSTANT_P (XEXP (rtl, 0))
8911 /* Not passed in memory. */
8912 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8913 /* Not passed by invisible reference. */
8914 && (GET_CODE (XEXP (rtl, 0)) != REG
8915 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8916 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8917 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8918 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8921 /* Big endian correction check. */
8923 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8924 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8927 int offset = (UNITS_PER_WORD
8928 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8930 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8931 plus_constant (XEXP (rtl, 0), offset));
8935 if (rtl != NULL_RTX)
8937 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8938 #ifdef LEAF_REG_REMAP
8939 if (current_function_uses_only_leaf_regs)
8940 leaf_renumber_regs_insn (rtl);
8944 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8945 and will have been substituted directly into all expressions that use it.
8946 C does not have such a concept, but C++ and other languages do. */
8947 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
8949 /* If a variable is initialized with a string constant without embedded
8950 zeros, build CONST_STRING. */
8951 if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8952 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
8954 tree arrtype = TREE_TYPE (decl);
8955 tree enttype = TREE_TYPE (arrtype);
8956 tree domain = TYPE_DOMAIN (arrtype);
8957 tree init = DECL_INITIAL (decl);
8958 enum machine_mode mode = TYPE_MODE (enttype);
8960 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
8962 && integer_zerop (TYPE_MIN_VALUE (domain))
8963 && compare_tree_int (TYPE_MAX_VALUE (domain),
8964 TREE_STRING_LENGTH (init) - 1) == 0
8965 && ((size_t) TREE_STRING_LENGTH (init)
8966 == strlen (TREE_STRING_POINTER (init)) + 1))
8967 rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init));
8969 /* If the initializer is something that we know will expand into an
8970 immediate RTL constant, expand it now. Expanding anything else
8971 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
8972 else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST
8973 || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST)
8975 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
8976 EXPAND_INITIALIZER);
8977 /* If expand_expr returns a MEM, it wasn't immediate. */
8978 if (rtl && GET_CODE (rtl) == MEM)
8983 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8985 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
8990 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8991 data attribute for a variable or a parameter. We generate the
8992 DW_AT_const_value attribute only in those cases where the given variable
8993 or parameter does not have a true "location" either in memory or in a
8994 register. This can happen (for example) when a constant is passed as an
8995 actual argument in a call to an inline function. (It's possible that
8996 these things can crop up in other ways also.) Note that one type of
8997 constant value which can be passed into an inlined function is a constant
8998 pointer. This can happen for example if an actual argument in an inlined
8999 function call evaluates to a compile-time constant address. */
9002 add_location_or_const_value_attribute (die, decl)
9008 if (TREE_CODE (decl) == ERROR_MARK)
9010 else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
9013 rtl = rtl_for_decl_location (decl);
9014 if (rtl == NULL_RTX)
9017 /* If we don't look past the constant pool, we risk emitting a
9018 reference to a constant pool entry that isn't referenced from
9019 code, and thus is not emitted. */
9020 rtl = avoid_constant_pool_reference (rtl);
9022 switch (GET_CODE (rtl))
9025 /* The address of a variable that was optimized away; don't emit
9036 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9037 add_const_value_attribute (die, rtl);
9044 add_AT_location_description (die, DW_AT_location, rtl);
9052 /* If we don't have a copy of this variable in memory for some reason (such
9053 as a C++ member constant that doesn't have an out-of-line definition),
9054 we should tell the debugger about the constant value. */
9057 tree_add_const_value_attribute (var_die, decl)
9061 tree init = DECL_INITIAL (decl);
9062 tree type = TREE_TYPE (decl);
9064 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
9065 && initializer_constant_valid_p (init, type) == null_pointer_node)
9070 switch (TREE_CODE (type))
9073 if (host_integerp (init, 0))
9074 add_AT_unsigned (var_die, DW_AT_const_value,
9075 tree_low_cst (init, 0));
9077 add_AT_long_long (var_die, DW_AT_const_value,
9078 TREE_INT_CST_HIGH (init),
9079 TREE_INT_CST_LOW (init));
9086 /* Generate an DW_AT_name attribute given some string value to be included as
9087 the value of the attribute. */
9090 add_name_attribute (die, name_string)
9092 const char *name_string;
9094 if (name_string != NULL && *name_string != 0)
9096 if (demangle_name_func)
9097 name_string = (*demangle_name_func) (name_string);
9099 add_AT_string (die, DW_AT_name, name_string);
9103 /* Given a tree node describing an array bound (either lower or upper) output
9104 a representation for that bound. */
9107 add_bound_info (subrange_die, bound_attr, bound)
9108 dw_die_ref subrange_die;
9109 enum dwarf_attribute bound_attr;
9112 switch (TREE_CODE (bound))
9117 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9119 if (! host_integerp (bound, 0)
9120 || (bound_attr == DW_AT_lower_bound
9121 && (((is_c_family () || is_java ()) && integer_zerop (bound))
9122 || (is_fortran () && integer_onep (bound)))))
9123 /* use the default */
9126 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
9131 case NON_LVALUE_EXPR:
9132 case VIEW_CONVERT_EXPR:
9133 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
9137 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9138 access the upper bound values may be bogus. If they refer to a
9139 register, they may only describe how to get at these values at the
9140 points in the generated code right after they have just been
9141 computed. Worse yet, in the typical case, the upper bound values
9142 will not even *be* computed in the optimized code (though the
9143 number of elements will), so these SAVE_EXPRs are entirely
9144 bogus. In order to compensate for this fact, we check here to see
9145 if optimization is enabled, and if so, we don't add an attribute
9146 for the (unknown and unknowable) upper bound. This should not
9147 cause too much trouble for existing (stupid?) debuggers because
9148 they have to deal with empty upper bounds location descriptions
9149 anyway in order to be able to deal with incomplete array types.
9150 Of course an intelligent debugger (GDB?) should be able to
9151 comprehend that a missing upper bound specification in an array
9152 type used for a storage class `auto' local array variable
9153 indicates that the upper bound is both unknown (at compile- time)
9154 and unknowable (at run-time) due to optimization.
9156 We assume that a MEM rtx is safe because gcc wouldn't put the
9157 value there unless it was going to be used repeatedly in the
9158 function, i.e. for cleanups. */
9159 if (SAVE_EXPR_RTL (bound)
9160 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9162 dw_die_ref ctx = lookup_decl_die (current_function_decl);
9163 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound);
9164 rtx loc = SAVE_EXPR_RTL (bound);
9166 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9167 it references an outer function's frame. */
9168 if (GET_CODE (loc) == MEM)
9170 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9172 if (XEXP (loc, 0) != new_addr)
9173 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9176 add_AT_flag (decl_die, DW_AT_artificial, 1);
9177 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9178 add_AT_location_description (decl_die, DW_AT_location, loc);
9179 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9182 /* Else leave out the attribute. */
9188 dw_die_ref decl_die = lookup_decl_die (bound);
9190 /* ??? Can this happen, or should the variable have been bound
9191 first? Probably it can, since I imagine that we try to create
9192 the types of parameters in the order in which they exist in
9193 the list, and won't have created a forward reference to a
9195 if (decl_die != NULL)
9196 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9202 /* Otherwise try to create a stack operation procedure to
9203 evaluate the value of the array bound. */
9205 dw_die_ref ctx, decl_die;
9206 dw_loc_descr_ref loc;
9208 loc = loc_descriptor_from_tree (bound, 0);
9212 if (current_function_decl == 0)
9213 ctx = comp_unit_die;
9215 ctx = lookup_decl_die (current_function_decl);
9217 /* If we weren't able to find a context, it's most likely the case
9218 that we are processing the return type of the function. So
9219 make a SAVE_EXPR to point to it and have the limbo DIE code
9220 find the proper die. The save_expr function doesn't always
9221 make a SAVE_EXPR, so do it ourselves. */
9223 bound = build (SAVE_EXPR, TREE_TYPE (bound), bound,
9224 current_function_decl, NULL_TREE);
9226 decl_die = new_die (DW_TAG_variable, ctx, bound);
9227 add_AT_flag (decl_die, DW_AT_artificial, 1);
9228 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9229 add_AT_loc (decl_die, DW_AT_location, loc);
9231 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9237 /* Note that the block of subscript information for an array type also
9238 includes information about the element type of type given array type. */
9241 add_subscript_info (type_die, type)
9242 dw_die_ref type_die;
9245 #ifndef MIPS_DEBUGGING_INFO
9246 unsigned dimension_number;
9249 dw_die_ref subrange_die;
9251 /* The GNU compilers represent multidimensional array types as sequences of
9252 one dimensional array types whose element types are themselves array
9253 types. Here we squish that down, so that each multidimensional array
9254 type gets only one array_type DIE in the Dwarf debugging info. The draft
9255 Dwarf specification say that we are allowed to do this kind of
9256 compression in C (because there is no difference between an array or
9257 arrays and a multidimensional array in C) but for other source languages
9258 (e.g. Ada) we probably shouldn't do this. */
9260 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9261 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9262 We work around this by disabling this feature. See also
9263 gen_array_type_die. */
9264 #ifndef MIPS_DEBUGGING_INFO
9265 for (dimension_number = 0;
9266 TREE_CODE (type) == ARRAY_TYPE;
9267 type = TREE_TYPE (type), dimension_number++)
9270 tree domain = TYPE_DOMAIN (type);
9272 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9273 and (in GNU C only) variable bounds. Handle all three forms
9275 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
9278 /* We have an array type with specified bounds. */
9279 lower = TYPE_MIN_VALUE (domain);
9280 upper = TYPE_MAX_VALUE (domain);
9282 /* define the index type. */
9283 if (TREE_TYPE (domain))
9285 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9286 TREE_TYPE field. We can't emit debug info for this
9287 because it is an unnamed integral type. */
9288 if (TREE_CODE (domain) == INTEGER_TYPE
9289 && TYPE_NAME (domain) == NULL_TREE
9290 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9291 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9294 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9298 /* ??? If upper is NULL, the array has unspecified length,
9299 but it does have a lower bound. This happens with Fortran
9301 Since the debugger is definitely going to need to know N
9302 to produce useful results, go ahead and output the lower
9303 bound solo, and hope the debugger can cope. */
9305 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9307 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9310 /* Otherwise we have an array type with an unspecified length. The
9311 DWARF-2 spec does not say how to handle this; let's just leave out the
9317 add_byte_size_attribute (die, tree_node)
9323 switch (TREE_CODE (tree_node))
9331 case QUAL_UNION_TYPE:
9332 size = int_size_in_bytes (tree_node);
9335 /* For a data member of a struct or union, the DW_AT_byte_size is
9336 generally given as the number of bytes normally allocated for an
9337 object of the *declared* type of the member itself. This is true
9338 even for bit-fields. */
9339 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9345 /* Note that `size' might be -1 when we get to this point. If it is, that
9346 indicates that the byte size of the entity in question is variable. We
9347 have no good way of expressing this fact in Dwarf at the present time,
9348 so just let the -1 pass on through. */
9349 add_AT_unsigned (die, DW_AT_byte_size, size);
9352 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9353 which specifies the distance in bits from the highest order bit of the
9354 "containing object" for the bit-field to the highest order bit of the
9357 For any given bit-field, the "containing object" is a hypothetical object
9358 (of some integral or enum type) within which the given bit-field lives. The
9359 type of this hypothetical "containing object" is always the same as the
9360 declared type of the individual bit-field itself. The determination of the
9361 exact location of the "containing object" for a bit-field is rather
9362 complicated. It's handled by the `field_byte_offset' function (above).
9364 Note that it is the size (in bytes) of the hypothetical "containing object"
9365 which will be given in the DW_AT_byte_size attribute for this bit-field.
9366 (See `byte_size_attribute' above). */
9369 add_bit_offset_attribute (die, decl)
9373 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9374 tree type = DECL_BIT_FIELD_TYPE (decl);
9375 HOST_WIDE_INT bitpos_int;
9376 HOST_WIDE_INT highest_order_object_bit_offset;
9377 HOST_WIDE_INT highest_order_field_bit_offset;
9378 HOST_WIDE_INT unsigned bit_offset;
9380 /* Must be a field and a bit field. */
9382 || TREE_CODE (decl) != FIELD_DECL)
9385 /* We can't yet handle bit-fields whose offsets are variable, so if we
9386 encounter such things, just return without generating any attribute
9387 whatsoever. Likewise for variable or too large size. */
9388 if (! host_integerp (bit_position (decl), 0)
9389 || ! host_integerp (DECL_SIZE (decl), 1))
9392 bitpos_int = int_bit_position (decl);
9394 /* Note that the bit offset is always the distance (in bits) from the
9395 highest-order bit of the "containing object" to the highest-order bit of
9396 the bit-field itself. Since the "high-order end" of any object or field
9397 is different on big-endian and little-endian machines, the computation
9398 below must take account of these differences. */
9399 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9400 highest_order_field_bit_offset = bitpos_int;
9402 if (! BYTES_BIG_ENDIAN)
9404 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9405 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9409 = (! BYTES_BIG_ENDIAN
9410 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9411 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9413 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9416 /* For a FIELD_DECL node which represents a bit field, output an attribute
9417 which specifies the length in bits of the given field. */
9420 add_bit_size_attribute (die, decl)
9424 /* Must be a field and a bit field. */
9425 if (TREE_CODE (decl) != FIELD_DECL
9426 || ! DECL_BIT_FIELD_TYPE (decl))
9429 if (host_integerp (DECL_SIZE (decl), 1))
9430 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9433 /* If the compiled language is ANSI C, then add a 'prototyped'
9434 attribute, if arg types are given for the parameters of a function. */
9437 add_prototyped_attribute (die, func_type)
9441 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9442 && TYPE_ARG_TYPES (func_type) != NULL)
9443 add_AT_flag (die, DW_AT_prototyped, 1);
9446 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9447 by looking in either the type declaration or object declaration
9451 add_abstract_origin_attribute (die, origin)
9455 dw_die_ref origin_die = NULL;
9457 if (TREE_CODE (origin) != FUNCTION_DECL)
9459 /* We may have gotten separated from the block for the inlined
9460 function, if we're in an exception handler or some such; make
9461 sure that the abstract function has been written out.
9463 Doing this for nested functions is wrong, however; functions are
9464 distinct units, and our context might not even be inline. */
9468 fn = TYPE_STUB_DECL (fn);
9470 fn = decl_function_context (fn);
9472 dwarf2out_abstract_function (fn);
9475 if (DECL_P (origin))
9476 origin_die = lookup_decl_die (origin);
9477 else if (TYPE_P (origin))
9478 origin_die = lookup_type_die (origin);
9480 if (origin_die == NULL)
9483 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9486 /* We do not currently support the pure_virtual attribute. */
9489 add_pure_or_virtual_attribute (die, func_decl)
9493 if (DECL_VINDEX (func_decl))
9495 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9497 if (host_integerp (DECL_VINDEX (func_decl), 0))
9498 add_AT_loc (die, DW_AT_vtable_elem_location,
9499 new_loc_descr (DW_OP_constu,
9500 tree_low_cst (DECL_VINDEX (func_decl), 0),
9503 /* GNU extension: Record what type this method came from originally. */
9504 if (debug_info_level > DINFO_LEVEL_TERSE)
9505 add_AT_die_ref (die, DW_AT_containing_type,
9506 lookup_type_die (DECL_CONTEXT (func_decl)));
9510 /* Add source coordinate attributes for the given decl. */
9513 add_src_coords_attributes (die, decl)
9517 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9519 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9520 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9523 /* Add an DW_AT_name attribute and source coordinate attribute for the
9524 given decl, but only if it actually has a name. */
9527 add_name_and_src_coords_attributes (die, decl)
9533 decl_name = DECL_NAME (decl);
9534 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9536 add_name_attribute (die, dwarf2_name (decl, 0));
9537 if (! DECL_ARTIFICIAL (decl))
9538 add_src_coords_attributes (die, decl);
9540 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9541 && TREE_PUBLIC (decl)
9542 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9543 && !DECL_ABSTRACT (decl))
9544 add_AT_string (die, DW_AT_MIPS_linkage_name,
9545 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9548 #ifdef VMS_DEBUGGING_INFO
9549 /* Get the function's name, as described by its RTL. This may be different
9550 from the DECL_NAME name used in the source file. */
9551 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
9553 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
9554 XEXP (DECL_RTL (decl), 0));
9555 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
9560 /* Push a new declaration scope. */
9563 push_decl_scope (scope)
9566 VARRAY_PUSH_TREE (decl_scope_table, scope);
9569 /* Pop a declaration scope. */
9574 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9577 VARRAY_POP (decl_scope_table);
9580 /* Return the DIE for the scope that immediately contains this type.
9581 Non-named types get global scope. Named types nested in other
9582 types get their containing scope if it's open, or global scope
9583 otherwise. All other types (i.e. function-local named types) get
9584 the current active scope. */
9587 scope_die_for (t, context_die)
9589 dw_die_ref context_die;
9591 dw_die_ref scope_die = NULL;
9592 tree containing_scope;
9595 /* Non-types always go in the current scope. */
9599 containing_scope = TYPE_CONTEXT (t);
9601 /* Ignore namespaces for the moment. */
9602 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9603 containing_scope = NULL_TREE;
9605 /* Ignore function type "scopes" from the C frontend. They mean that
9606 a tagged type is local to a parmlist of a function declarator, but
9607 that isn't useful to DWARF. */
9608 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9609 containing_scope = NULL_TREE;
9611 if (containing_scope == NULL_TREE)
9612 scope_die = comp_unit_die;
9613 else if (TYPE_P (containing_scope))
9615 /* For types, we can just look up the appropriate DIE. But
9616 first we check to see if we're in the middle of emitting it
9617 so we know where the new DIE should go. */
9618 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9619 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
9624 if (debug_info_level > DINFO_LEVEL_TERSE
9625 && !TREE_ASM_WRITTEN (containing_scope))
9628 /* If none of the current dies are suitable, we get file scope. */
9629 scope_die = comp_unit_die;
9632 scope_die = lookup_type_die (containing_scope);
9635 scope_die = context_die;
9640 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9643 local_scope_p (context_die)
9644 dw_die_ref context_die;
9646 for (; context_die; context_die = context_die->die_parent)
9647 if (context_die->die_tag == DW_TAG_inlined_subroutine
9648 || context_die->die_tag == DW_TAG_subprogram)
9654 /* Returns nonzero if CONTEXT_DIE is a class. */
9657 class_scope_p (context_die)
9658 dw_die_ref context_die;
9661 && (context_die->die_tag == DW_TAG_structure_type
9662 || context_die->die_tag == DW_TAG_union_type));
9665 /* Many forms of DIEs require a "type description" attribute. This
9666 routine locates the proper "type descriptor" die for the type given
9667 by 'type', and adds an DW_AT_type attribute below the given die. */
9670 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9671 dw_die_ref object_die;
9675 dw_die_ref context_die;
9677 enum tree_code code = TREE_CODE (type);
9678 dw_die_ref type_die = NULL;
9680 /* ??? If this type is an unnamed subrange type of an integral or
9681 floating-point type, use the inner type. This is because we have no
9682 support for unnamed types in base_type_die. This can happen if this is
9683 an Ada subrange type. Correct solution is emit a subrange type die. */
9684 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9685 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9686 type = TREE_TYPE (type), code = TREE_CODE (type);
9688 if (code == ERROR_MARK
9689 /* Handle a special case. For functions whose return type is void, we
9690 generate *no* type attribute. (Note that no object may have type
9691 `void', so this only applies to function return types). */
9692 || code == VOID_TYPE)
9695 type_die = modified_type_die (type,
9696 decl_const || TYPE_READONLY (type),
9697 decl_volatile || TYPE_VOLATILE (type),
9700 if (type_die != NULL)
9701 add_AT_die_ref (object_die, DW_AT_type, type_die);
9704 /* Given a tree pointer to a struct, class, union, or enum type node, return
9705 a pointer to the (string) tag name for the given type, or zero if the type
9706 was declared without a tag. */
9712 const char *name = 0;
9714 if (TYPE_NAME (type) != 0)
9718 /* Find the IDENTIFIER_NODE for the type name. */
9719 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9720 t = TYPE_NAME (type);
9722 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9723 a TYPE_DECL node, regardless of whether or not a `typedef' was
9725 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9726 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9727 t = DECL_NAME (TYPE_NAME (type));
9729 /* Now get the name as a string, or invent one. */
9731 name = IDENTIFIER_POINTER (t);
9734 return (name == 0 || *name == '\0') ? 0 : name;
9737 /* Return the type associated with a data member, make a special check
9738 for bit field types. */
9741 member_declared_type (member)
9744 return (DECL_BIT_FIELD_TYPE (member)
9745 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
9748 /* Get the decl's label, as described by its RTL. This may be different
9749 from the DECL_NAME name used in the source file. */
9753 decl_start_label (decl)
9759 x = DECL_RTL (decl);
9760 if (GET_CODE (x) != MEM)
9764 if (GET_CODE (x) != SYMBOL_REF)
9767 fnname = XSTR (x, 0);
9772 /* These routines generate the internal representation of the DIE's for
9773 the compilation unit. Debugging information is collected by walking
9774 the declaration trees passed in from dwarf2out_decl(). */
9777 gen_array_type_die (type, context_die)
9779 dw_die_ref context_die;
9781 dw_die_ref scope_die = scope_die_for (type, context_die);
9782 dw_die_ref array_die;
9785 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9786 the inner array type comes before the outer array type. Thus we must
9787 call gen_type_die before we call new_die. See below also. */
9788 #ifdef MIPS_DEBUGGING_INFO
9789 gen_type_die (TREE_TYPE (type), context_die);
9792 array_die = new_die (DW_TAG_array_type, scope_die, type);
9793 add_name_attribute (array_die, type_tag (type));
9794 equate_type_number_to_die (type, array_die);
9796 if (TREE_CODE (type) == VECTOR_TYPE)
9798 /* The frontend feeds us a representation for the vector as a struct
9799 containing an array. Pull out the array type. */
9800 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
9801 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
9805 /* We default the array ordering. SDB will probably do
9806 the right things even if DW_AT_ordering is not present. It's not even
9807 an issue until we start to get into multidimensional arrays anyway. If
9808 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9809 then we'll have to put the DW_AT_ordering attribute back in. (But if
9810 and when we find out that we need to put these in, we will only do so
9811 for multidimensional arrays. */
9812 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9815 #ifdef MIPS_DEBUGGING_INFO
9816 /* The SGI compilers handle arrays of unknown bound by setting
9817 AT_declaration and not emitting any subrange DIEs. */
9818 if (! TYPE_DOMAIN (type))
9819 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9822 add_subscript_info (array_die, type);
9824 /* Add representation of the type of the elements of this array type. */
9825 element_type = TREE_TYPE (type);
9827 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9828 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9829 We work around this by disabling this feature. See also
9830 add_subscript_info. */
9831 #ifndef MIPS_DEBUGGING_INFO
9832 while (TREE_CODE (element_type) == ARRAY_TYPE)
9833 element_type = TREE_TYPE (element_type);
9835 gen_type_die (element_type, context_die);
9838 add_type_attribute (array_die, element_type, 0, 0, context_die);
9842 gen_set_type_die (type, context_die)
9844 dw_die_ref context_die;
9847 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
9849 equate_type_number_to_die (type, type_die);
9850 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9855 gen_entry_point_die (decl, context_die)
9857 dw_die_ref context_die;
9859 tree origin = decl_ultimate_origin (decl);
9860 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
9863 add_abstract_origin_attribute (decl_die, origin);
9866 add_name_and_src_coords_attributes (decl_die, decl);
9867 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9871 if (DECL_ABSTRACT (decl))
9872 equate_decl_number_to_die (decl, decl_die);
9874 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9878 /* Walk through the list of incomplete types again, trying once more to
9879 emit full debugging info for them. */
9882 retry_incomplete_types ()
9886 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
9887 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
9890 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9893 gen_inlined_enumeration_type_die (type, context_die)
9895 dw_die_ref context_die;
9897 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
9899 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9900 be incomplete and such types are not marked. */
9901 add_abstract_origin_attribute (type_die, type);
9904 /* Generate a DIE to represent an inlined instance of a structure type. */
9907 gen_inlined_structure_type_die (type, context_die)
9909 dw_die_ref context_die;
9911 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
9913 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9914 be incomplete and such types are not marked. */
9915 add_abstract_origin_attribute (type_die, type);
9918 /* Generate a DIE to represent an inlined instance of a union type. */
9921 gen_inlined_union_type_die (type, context_die)
9923 dw_die_ref context_die;
9925 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
9927 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9928 be incomplete and such types are not marked. */
9929 add_abstract_origin_attribute (type_die, type);
9932 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9933 include all of the information about the enumeration values also. Each
9934 enumerated type name/value is listed as a child of the enumerated type
9938 gen_enumeration_type_die (type, context_die)
9940 dw_die_ref context_die;
9942 dw_die_ref type_die = lookup_type_die (type);
9944 if (type_die == NULL)
9946 type_die = new_die (DW_TAG_enumeration_type,
9947 scope_die_for (type, context_die), type);
9948 equate_type_number_to_die (type, type_die);
9949 add_name_attribute (type_die, type_tag (type));
9951 else if (! TYPE_SIZE (type))
9954 remove_AT (type_die, DW_AT_declaration);
9956 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9957 given enum type is incomplete, do not generate the DW_AT_byte_size
9958 attribute or the DW_AT_element_list attribute. */
9959 if (TYPE_SIZE (type))
9963 TREE_ASM_WRITTEN (type) = 1;
9964 add_byte_size_attribute (type_die, type);
9965 if (TYPE_STUB_DECL (type) != NULL_TREE)
9966 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9968 /* If the first reference to this type was as the return type of an
9969 inline function, then it may not have a parent. Fix this now. */
9970 if (type_die->die_parent == NULL)
9971 add_child_die (scope_die_for (type, context_die), type_die);
9973 for (link = TYPE_FIELDS (type);
9974 link != NULL; link = TREE_CHAIN (link))
9976 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
9978 add_name_attribute (enum_die,
9979 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9981 if (host_integerp (TREE_VALUE (link), 0))
9983 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9984 add_AT_int (enum_die, DW_AT_const_value,
9985 tree_low_cst (TREE_VALUE (link), 0));
9987 add_AT_unsigned (enum_die, DW_AT_const_value,
9988 tree_low_cst (TREE_VALUE (link), 0));
9993 add_AT_flag (type_die, DW_AT_declaration, 1);
9996 /* Generate a DIE to represent either a real live formal parameter decl or to
9997 represent just the type of some formal parameter position in some function
10000 Note that this routine is a bit unusual because its argument may be a
10001 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
10002 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
10003 node. If it's the former then this function is being called to output a
10004 DIE to represent a formal parameter object (or some inlining thereof). If
10005 it's the latter, then this function is only being called to output a
10006 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
10007 argument type of some subprogram type. */
10010 gen_formal_parameter_die (node, context_die)
10012 dw_die_ref context_die;
10014 dw_die_ref parm_die
10015 = new_die (DW_TAG_formal_parameter, context_die, node);
10018 switch (TREE_CODE_CLASS (TREE_CODE (node)))
10021 origin = decl_ultimate_origin (node);
10022 if (origin != NULL)
10023 add_abstract_origin_attribute (parm_die, origin);
10026 add_name_and_src_coords_attributes (parm_die, node);
10027 add_type_attribute (parm_die, TREE_TYPE (node),
10028 TREE_READONLY (node),
10029 TREE_THIS_VOLATILE (node),
10031 if (DECL_ARTIFICIAL (node))
10032 add_AT_flag (parm_die, DW_AT_artificial, 1);
10035 equate_decl_number_to_die (node, parm_die);
10036 if (! DECL_ABSTRACT (node))
10037 add_location_or_const_value_attribute (parm_die, node);
10042 /* We were called with some kind of a ..._TYPE node. */
10043 add_type_attribute (parm_die, node, 0, 0, context_die);
10053 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10054 at the end of an (ANSI prototyped) formal parameters list. */
10057 gen_unspecified_parameters_die (decl_or_type, context_die)
10059 dw_die_ref context_die;
10061 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
10064 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10065 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10066 parameters as specified in some function type specification (except for
10067 those which appear as part of a function *definition*). */
10070 gen_formal_types_die (function_or_method_type, context_die)
10071 tree function_or_method_type;
10072 dw_die_ref context_die;
10075 tree formal_type = NULL;
10076 tree first_parm_type;
10079 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
10081 arg = DECL_ARGUMENTS (function_or_method_type);
10082 function_or_method_type = TREE_TYPE (function_or_method_type);
10087 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
10089 /* Make our first pass over the list of formal parameter types and output a
10090 DW_TAG_formal_parameter DIE for each one. */
10091 for (link = first_parm_type; link; )
10093 dw_die_ref parm_die;
10095 formal_type = TREE_VALUE (link);
10096 if (formal_type == void_type_node)
10099 /* Output a (nameless) DIE to represent the formal parameter itself. */
10100 parm_die = gen_formal_parameter_die (formal_type, context_die);
10101 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
10102 && link == first_parm_type)
10103 || (arg && DECL_ARTIFICIAL (arg)))
10104 add_AT_flag (parm_die, DW_AT_artificial, 1);
10106 link = TREE_CHAIN (link);
10108 arg = TREE_CHAIN (arg);
10111 /* If this function type has an ellipsis, add a
10112 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10113 if (formal_type != void_type_node)
10114 gen_unspecified_parameters_die (function_or_method_type, context_die);
10116 /* Make our second (and final) pass over the list of formal parameter types
10117 and output DIEs to represent those types (as necessary). */
10118 for (link = TYPE_ARG_TYPES (function_or_method_type);
10119 link && TREE_VALUE (link);
10120 link = TREE_CHAIN (link))
10121 gen_type_die (TREE_VALUE (link), context_die);
10124 /* We want to generate the DIE for TYPE so that we can generate the
10125 die for MEMBER, which has been defined; we will need to refer back
10126 to the member declaration nested within TYPE. If we're trying to
10127 generate minimal debug info for TYPE, processing TYPE won't do the
10128 trick; we need to attach the member declaration by hand. */
10131 gen_type_die_for_member (type, member, context_die)
10133 dw_die_ref context_die;
10135 gen_type_die (type, context_die);
10137 /* If we're trying to avoid duplicate debug info, we may not have
10138 emitted the member decl for this function. Emit it now. */
10139 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10140 && ! lookup_decl_die (member))
10142 if (decl_ultimate_origin (member))
10145 push_decl_scope (type);
10146 if (TREE_CODE (member) == FUNCTION_DECL)
10147 gen_subprogram_die (member, lookup_type_die (type));
10149 gen_variable_die (member, lookup_type_die (type));
10155 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10156 may later generate inlined and/or out-of-line instances of. */
10159 dwarf2out_abstract_function (decl)
10162 dw_die_ref old_die;
10165 int was_abstract = DECL_ABSTRACT (decl);
10167 /* Make sure we have the actual abstract inline, not a clone. */
10168 decl = DECL_ORIGIN (decl);
10170 old_die = lookup_decl_die (decl);
10171 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10172 /* We've already generated the abstract instance. */
10175 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10176 we don't get confused by DECL_ABSTRACT. */
10177 if (debug_info_level > DINFO_LEVEL_TERSE)
10179 context = decl_class_context (decl);
10181 gen_type_die_for_member
10182 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
10185 /* Pretend we've just finished compiling this function. */
10186 save_fn = current_function_decl;
10187 current_function_decl = decl;
10189 set_decl_abstract_flags (decl, 1);
10190 dwarf2out_decl (decl);
10191 if (! was_abstract)
10192 set_decl_abstract_flags (decl, 0);
10194 current_function_decl = save_fn;
10197 /* Generate a DIE to represent a declared function (either file-scope or
10201 gen_subprogram_die (decl, context_die)
10203 dw_die_ref context_die;
10205 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10206 tree origin = decl_ultimate_origin (decl);
10207 dw_die_ref subr_die;
10211 dw_die_ref old_die = lookup_decl_die (decl);
10212 int declaration = (current_function_decl != decl
10213 || class_scope_p (context_die));
10215 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10216 started to generate the abstract instance of an inline, decided to output
10217 its containing class, and proceeded to emit the declaration of the inline
10218 from the member list for the class. If so, DECLARATION takes priority;
10219 we'll get back to the abstract instance when done with the class. */
10221 /* The class-scope declaration DIE must be the primary DIE. */
10222 if (origin && declaration && class_scope_p (context_die))
10229 if (origin != NULL)
10231 if (declaration && ! local_scope_p (context_die))
10234 /* Fixup die_parent for the abstract instance of a nested
10235 inline function. */
10236 if (old_die && old_die->die_parent == NULL)
10237 add_child_die (context_die, old_die);
10239 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10240 add_abstract_origin_attribute (subr_die, origin);
10244 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10246 if (!get_AT_flag (old_die, DW_AT_declaration)
10247 /* We can have a normal definition following an inline one in the
10248 case of redefinition of GNU C extern inlines.
10249 It seems reasonable to use AT_specification in this case. */
10250 && !get_AT_unsigned (old_die, DW_AT_inline))
10252 /* ??? This can happen if there is a bug in the program, for
10253 instance, if it has duplicate function definitions. Ideally,
10254 we should detect this case and ignore it. For now, if we have
10255 already reported an error, any error at all, then assume that
10256 we got here because of an input error, not a dwarf2 bug. */
10262 /* If the definition comes from the same place as the declaration,
10263 maybe use the old DIE. We always want the DIE for this function
10264 that has the *_pc attributes to be under comp_unit_die so the
10265 debugger can find it. We also need to do this for abstract
10266 instances of inlines, since the spec requires the out-of-line copy
10267 to have the same parent. For local class methods, this doesn't
10268 apply; we just use the old DIE. */
10269 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10270 && (DECL_ARTIFICIAL (decl)
10271 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10272 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10273 == (unsigned) DECL_SOURCE_LINE (decl)))))
10275 subr_die = old_die;
10277 /* Clear out the declaration attribute and the parm types. */
10278 remove_AT (subr_die, DW_AT_declaration);
10279 remove_children (subr_die);
10283 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10284 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10285 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10286 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10287 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10288 != (unsigned) DECL_SOURCE_LINE (decl))
10290 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10295 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10297 if (TREE_PUBLIC (decl))
10298 add_AT_flag (subr_die, DW_AT_external, 1);
10300 add_name_and_src_coords_attributes (subr_die, decl);
10301 if (debug_info_level > DINFO_LEVEL_TERSE)
10303 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
10304 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
10305 0, 0, context_die);
10308 add_pure_or_virtual_attribute (subr_die, decl);
10309 if (DECL_ARTIFICIAL (decl))
10310 add_AT_flag (subr_die, DW_AT_artificial, 1);
10312 if (TREE_PROTECTED (decl))
10313 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10314 else if (TREE_PRIVATE (decl))
10315 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10320 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10322 add_AT_flag (subr_die, DW_AT_declaration, 1);
10324 /* The first time we see a member function, it is in the context of
10325 the class to which it belongs. We make sure of this by emitting
10326 the class first. The next time is the definition, which is
10327 handled above. The two may come from the same source text. */
10328 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10329 equate_decl_number_to_die (decl, subr_die);
10332 else if (DECL_ABSTRACT (decl))
10334 if (DECL_INLINE (decl) && !flag_no_inline)
10336 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10337 inline functions, but not for extern inline functions.
10338 We can't get this completely correct because information
10339 about whether the function was declared inline is not
10341 if (DECL_DEFER_OUTPUT (decl))
10342 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10344 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10347 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10349 equate_decl_number_to_die (decl, subr_die);
10351 else if (!DECL_EXTERNAL (decl))
10353 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10354 equate_decl_number_to_die (decl, subr_die);
10356 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10357 current_funcdef_number);
10358 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10359 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10360 current_funcdef_number);
10361 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10363 add_pubname (decl, subr_die);
10364 add_arange (decl, subr_die);
10366 #ifdef MIPS_DEBUGGING_INFO
10367 /* Add a reference to the FDE for this routine. */
10368 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10371 /* Define the "frame base" location for this routine. We use the
10372 frame pointer or stack pointer registers, since the RTL for local
10373 variables is relative to one of them. */
10375 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10376 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10379 /* ??? This fails for nested inline functions, because context_display
10380 is not part of the state saved/restored for inline functions. */
10381 if (current_function_needs_context)
10382 add_AT_location_description (subr_die, DW_AT_static_link,
10383 lookup_static_chain (decl));
10387 /* Now output descriptions of the arguments for this function. This gets
10388 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10389 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10390 `...' at the end of the formal parameter list. In order to find out if
10391 there was a trailing ellipsis or not, we must instead look at the type
10392 associated with the FUNCTION_DECL. This will be a node of type
10393 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10394 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10395 an ellipsis at the end. */
10397 /* In the case where we are describing a mere function declaration, all we
10398 need to do here (and all we *can* do here) is to describe the *types* of
10399 its formal parameters. */
10400 if (debug_info_level <= DINFO_LEVEL_TERSE)
10402 else if (declaration)
10403 gen_formal_types_die (decl, subr_die);
10406 /* Generate DIEs to represent all known formal parameters */
10407 tree arg_decls = DECL_ARGUMENTS (decl);
10410 /* When generating DIEs, generate the unspecified_parameters DIE
10411 instead if we come across the arg "__builtin_va_alist" */
10412 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10413 if (TREE_CODE (parm) == PARM_DECL)
10415 if (DECL_NAME (parm)
10416 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10417 "__builtin_va_alist"))
10418 gen_unspecified_parameters_die (parm, subr_die);
10420 gen_decl_die (parm, subr_die);
10423 /* Decide whether we need an unspecified_parameters DIE at the end.
10424 There are 2 more cases to do this for: 1) the ansi ... declaration -
10425 this is detectable when the end of the arg list is not a
10426 void_type_node 2) an unprototyped function declaration (not a
10427 definition). This just means that we have no info about the
10428 parameters at all. */
10429 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10430 if (fn_arg_types != NULL)
10432 /* this is the prototyped case, check for ... */
10433 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10434 gen_unspecified_parameters_die (decl, subr_die);
10436 else if (DECL_INITIAL (decl) == NULL_TREE)
10437 gen_unspecified_parameters_die (decl, subr_die);
10440 /* Output Dwarf info for all of the stuff within the body of the function
10441 (if it has one - it may be just a declaration). */
10442 outer_scope = DECL_INITIAL (decl);
10444 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10445 a function. This BLOCK actually represents the outermost binding contour
10446 for the function, i.e. the contour in which the function's formal
10447 parameters and labels get declared. Curiously, it appears that the front
10448 end doesn't actually put the PARM_DECL nodes for the current function onto
10449 the BLOCK_VARS list for this outer scope, but are strung off of the
10450 DECL_ARGUMENTS list for the function instead.
10452 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10453 the LABEL_DECL nodes for the function however, and we output DWARF info
10454 for those in decls_for_scope. Just within the `outer_scope' there will be
10455 a BLOCK node representing the function's outermost pair of curly braces,
10456 and any blocks used for the base and member initializers of a C++
10457 constructor function. */
10458 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10460 current_function_has_inlines = 0;
10461 decls_for_scope (outer_scope, subr_die, 0);
10463 #if 0 && defined (MIPS_DEBUGGING_INFO)
10464 if (current_function_has_inlines)
10466 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10467 if (! comp_unit_has_inlines)
10469 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10470 comp_unit_has_inlines = 1;
10477 /* Generate a DIE to represent a declared data object. */
10480 gen_variable_die (decl, context_die)
10482 dw_die_ref context_die;
10484 tree origin = decl_ultimate_origin (decl);
10485 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
10487 dw_die_ref old_die = lookup_decl_die (decl);
10488 int declaration = (DECL_EXTERNAL (decl)
10489 || class_scope_p (context_die));
10491 if (origin != NULL)
10492 add_abstract_origin_attribute (var_die, origin);
10494 /* Loop unrolling can create multiple blocks that refer to the same
10495 static variable, so we must test for the DW_AT_declaration flag.
10497 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10498 copy decls and set the DECL_ABSTRACT flag on them instead of
10501 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10502 else if (old_die && TREE_STATIC (decl)
10503 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10505 /* This is a definition of a C++ class level static. */
10506 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10507 if (DECL_NAME (decl))
10509 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10511 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10512 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10514 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10515 != (unsigned) DECL_SOURCE_LINE (decl))
10517 add_AT_unsigned (var_die, DW_AT_decl_line,
10518 DECL_SOURCE_LINE (decl));
10523 add_name_and_src_coords_attributes (var_die, decl);
10524 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
10525 TREE_THIS_VOLATILE (decl), context_die);
10527 if (TREE_PUBLIC (decl))
10528 add_AT_flag (var_die, DW_AT_external, 1);
10530 if (DECL_ARTIFICIAL (decl))
10531 add_AT_flag (var_die, DW_AT_artificial, 1);
10533 if (TREE_PROTECTED (decl))
10534 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10535 else if (TREE_PRIVATE (decl))
10536 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10540 add_AT_flag (var_die, DW_AT_declaration, 1);
10542 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10543 equate_decl_number_to_die (decl, var_die);
10545 if (! declaration && ! DECL_ABSTRACT (decl))
10547 add_location_or_const_value_attribute (var_die, decl);
10548 add_pubname (decl, var_die);
10551 tree_add_const_value_attribute (var_die, decl);
10554 /* Generate a DIE to represent a label identifier. */
10557 gen_label_die (decl, context_die)
10559 dw_die_ref context_die;
10561 tree origin = decl_ultimate_origin (decl);
10562 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
10564 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10566 if (origin != NULL)
10567 add_abstract_origin_attribute (lbl_die, origin);
10569 add_name_and_src_coords_attributes (lbl_die, decl);
10571 if (DECL_ABSTRACT (decl))
10572 equate_decl_number_to_die (decl, lbl_die);
10575 insn = DECL_RTL (decl);
10577 /* Deleted labels are programmer specified labels which have been
10578 eliminated because of various optimisations. We still emit them
10579 here so that it is possible to put breakpoints on them. */
10580 if (GET_CODE (insn) == CODE_LABEL
10581 || ((GET_CODE (insn) == NOTE
10582 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10584 /* When optimization is enabled (via -O) some parts of the compiler
10585 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10586 represent source-level labels which were explicitly declared by
10587 the user. This really shouldn't be happening though, so catch
10588 it if it ever does happen. */
10589 if (INSN_DELETED_P (insn))
10592 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10593 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10598 /* Generate a DIE for a lexical block. */
10601 gen_lexical_block_die (stmt, context_die, depth)
10603 dw_die_ref context_die;
10606 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
10607 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10609 if (! BLOCK_ABSTRACT (stmt))
10611 if (BLOCK_FRAGMENT_CHAIN (stmt))
10615 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
10617 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10620 add_ranges (chain);
10621 chain = BLOCK_FRAGMENT_CHAIN (chain);
10628 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10629 BLOCK_NUMBER (stmt));
10630 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10631 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10632 BLOCK_NUMBER (stmt));
10633 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10637 decls_for_scope (stmt, stmt_die, depth);
10640 /* Generate a DIE for an inlined subprogram. */
10643 gen_inlined_subroutine_die (stmt, context_die, depth)
10645 dw_die_ref context_die;
10648 if (! BLOCK_ABSTRACT (stmt))
10650 dw_die_ref subr_die
10651 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
10652 tree decl = block_ultimate_origin (stmt);
10653 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10655 /* Emit info for the abstract instance first, if we haven't yet. */
10656 dwarf2out_abstract_function (decl);
10658 add_abstract_origin_attribute (subr_die, decl);
10659 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10660 BLOCK_NUMBER (stmt));
10661 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10662 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10663 BLOCK_NUMBER (stmt));
10664 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10665 decls_for_scope (stmt, subr_die, depth);
10666 current_function_has_inlines = 1;
10669 /* We may get here if we're the outer block of function A that was
10670 inlined into function B that was inlined into function C. When
10671 generating debugging info for C, dwarf2out_abstract_function(B)
10672 would mark all inlined blocks as abstract, including this one.
10673 So, we wouldn't (and shouldn't) expect labels to be generated
10674 for this one. Instead, just emit debugging info for
10675 declarations within the block. This is particularly important
10676 in the case of initializers of arguments passed from B to us:
10677 if they're statement expressions containing declarations, we
10678 wouldn't generate dies for their abstract variables, and then,
10679 when generating dies for the real variables, we'd die (pun
10681 gen_lexical_block_die (stmt, context_die, depth);
10684 /* Generate a DIE for a field in a record, or structure. */
10687 gen_field_die (decl, context_die)
10689 dw_die_ref context_die;
10691 dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl);
10693 add_name_and_src_coords_attributes (decl_die, decl);
10694 add_type_attribute (decl_die, member_declared_type (decl),
10695 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10698 if (DECL_BIT_FIELD_TYPE (decl))
10700 add_byte_size_attribute (decl_die, decl);
10701 add_bit_size_attribute (decl_die, decl);
10702 add_bit_offset_attribute (decl_die, decl);
10705 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10706 add_data_member_location_attribute (decl_die, decl);
10708 if (DECL_ARTIFICIAL (decl))
10709 add_AT_flag (decl_die, DW_AT_artificial, 1);
10711 if (TREE_PROTECTED (decl))
10712 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10713 else if (TREE_PRIVATE (decl))
10714 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10718 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10719 Use modified_type_die instead.
10720 We keep this code here just in case these types of DIEs may be needed to
10721 represent certain things in other languages (e.g. Pascal) someday. */
10724 gen_pointer_type_die (type, context_die)
10726 dw_die_ref context_die;
10729 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
10731 equate_type_number_to_die (type, ptr_die);
10732 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10733 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10736 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10737 Use modified_type_die instead.
10738 We keep this code here just in case these types of DIEs may be needed to
10739 represent certain things in other languages (e.g. Pascal) someday. */
10742 gen_reference_type_die (type, context_die)
10744 dw_die_ref context_die;
10747 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
10749 equate_type_number_to_die (type, ref_die);
10750 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10751 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10755 /* Generate a DIE for a pointer to a member type. */
10758 gen_ptr_to_mbr_type_die (type, context_die)
10760 dw_die_ref context_die;
10763 = new_die (DW_TAG_ptr_to_member_type,
10764 scope_die_for (type, context_die), type);
10766 equate_type_number_to_die (type, ptr_die);
10767 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10768 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10769 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10772 /* Generate the DIE for the compilation unit. */
10775 gen_compile_unit_die (filename)
10776 const char *filename;
10779 char producer[250];
10780 const char *wd = getpwd ();
10781 const char *language_string = lang_hooks.name;
10784 die = new_die (DW_TAG_compile_unit, NULL, NULL);
10785 add_name_attribute (die, filename);
10787 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10788 add_AT_string (die, DW_AT_comp_dir, wd);
10790 sprintf (producer, "%s %s", language_string, version_string);
10792 #ifdef MIPS_DEBUGGING_INFO
10793 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10794 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10795 not appear in the producer string, the debugger reaches the conclusion
10796 that the object file is stripped and has no debugging information.
10797 To get the MIPS/SGI debugger to believe that there is debugging
10798 information in the object file, we add a -g to the producer string. */
10799 if (debug_info_level > DINFO_LEVEL_TERSE)
10800 strcat (producer, " -g");
10803 add_AT_string (die, DW_AT_producer, producer);
10805 if (strcmp (language_string, "GNU C++") == 0)
10806 language = DW_LANG_C_plus_plus;
10807 else if (strcmp (language_string, "GNU Ada") == 0)
10808 language = DW_LANG_Ada83;
10809 else if (strcmp (language_string, "GNU F77") == 0)
10810 language = DW_LANG_Fortran77;
10811 else if (strcmp (language_string, "GNU Pascal") == 0)
10812 language = DW_LANG_Pascal83;
10813 else if (strcmp (language_string, "GNU Java") == 0)
10814 language = DW_LANG_Java;
10816 language = DW_LANG_C89;
10818 add_AT_unsigned (die, DW_AT_language, language);
10822 /* Generate a DIE for a string type. */
10825 gen_string_type_die (type, context_die)
10827 dw_die_ref context_die;
10829 dw_die_ref type_die
10830 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
10832 equate_type_number_to_die (type, type_die);
10834 /* ??? Fudge the string length attribute for now.
10835 TODO: add string length info. */
10837 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10838 bound_representation (upper_bound, 0, 'u');
10842 /* Generate the DIE for a base class. */
10845 gen_inheritance_die (binfo, context_die)
10847 dw_die_ref context_die;
10849 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
10851 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10852 add_data_member_location_attribute (die, binfo);
10854 if (TREE_VIA_VIRTUAL (binfo))
10855 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10857 if (TREE_VIA_PUBLIC (binfo))
10858 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10859 else if (TREE_VIA_PROTECTED (binfo))
10860 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10863 /* Generate a DIE for a class member. */
10866 gen_member_die (type, context_die)
10868 dw_die_ref context_die;
10873 /* If this is not an incomplete type, output descriptions of each of its
10874 members. Note that as we output the DIEs necessary to represent the
10875 members of this record or union type, we will also be trying to output
10876 DIEs to represent the *types* of those members. However the `type'
10877 function (above) will specifically avoid generating type DIEs for member
10878 types *within* the list of member DIEs for this (containing) type except
10879 for those types (of members) which are explicitly marked as also being
10880 members of this (containing) type themselves. The g++ front- end can
10881 force any given type to be treated as a member of some other (containing)
10882 type by setting the TYPE_CONTEXT of the given (member) type to point to
10883 the TREE node representing the appropriate (containing) type. */
10885 /* First output info about the base classes. */
10886 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10888 tree bases = TYPE_BINFO_BASETYPES (type);
10889 int n_bases = TREE_VEC_LENGTH (bases);
10892 for (i = 0; i < n_bases; i++)
10893 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10896 /* Now output info about the data members and type members. */
10897 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10899 /* If we thought we were generating minimal debug info for TYPE
10900 and then changed our minds, some of the member declarations
10901 may have already been defined. Don't define them again, but
10902 do put them in the right order. */
10904 child = lookup_decl_die (member);
10906 splice_child_die (context_die, child);
10908 gen_decl_die (member, context_die);
10911 /* Now output info about the function members (if any). */
10912 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10914 /* Don't include clones in the member list. */
10915 if (DECL_ABSTRACT_ORIGIN (member))
10918 child = lookup_decl_die (member);
10920 splice_child_die (context_die, child);
10922 gen_decl_die (member, context_die);
10926 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10927 is set, we pretend that the type was never defined, so we only get the
10928 member DIEs needed by later specification DIEs. */
10931 gen_struct_or_union_type_die (type, context_die)
10933 dw_die_ref context_die;
10935 dw_die_ref type_die = lookup_type_die (type);
10936 dw_die_ref scope_die = 0;
10938 int complete = (TYPE_SIZE (type)
10939 && (! TYPE_STUB_DECL (type)
10940 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10942 if (type_die && ! complete)
10945 if (TYPE_CONTEXT (type) != NULL_TREE
10946 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10949 scope_die = scope_die_for (type, context_die);
10951 if (! type_die || (nested && scope_die == comp_unit_die))
10952 /* First occurrence of type or toplevel definition of nested class. */
10954 dw_die_ref old_die = type_die;
10956 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10957 ? DW_TAG_structure_type : DW_TAG_union_type,
10959 equate_type_number_to_die (type, type_die);
10961 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10963 add_name_attribute (type_die, type_tag (type));
10966 remove_AT (type_die, DW_AT_declaration);
10968 /* If this type has been completed, then give it a byte_size attribute and
10969 then give a list of members. */
10972 /* Prevent infinite recursion in cases where the type of some member of
10973 this type is expressed in terms of this type itself. */
10974 TREE_ASM_WRITTEN (type) = 1;
10975 add_byte_size_attribute (type_die, type);
10976 if (TYPE_STUB_DECL (type) != NULL_TREE)
10977 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10979 /* If the first reference to this type was as the return type of an
10980 inline function, then it may not have a parent. Fix this now. */
10981 if (type_die->die_parent == NULL)
10982 add_child_die (scope_die, type_die);
10984 push_decl_scope (type);
10985 gen_member_die (type, type_die);
10988 /* GNU extension: Record what type our vtable lives in. */
10989 if (TYPE_VFIELD (type))
10991 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10993 gen_type_die (vtype, context_die);
10994 add_AT_die_ref (type_die, DW_AT_containing_type,
10995 lookup_type_die (vtype));
11000 add_AT_flag (type_die, DW_AT_declaration, 1);
11002 /* We don't need to do this for function-local types. */
11003 if (TYPE_STUB_DECL (type)
11004 && ! decl_function_context (TYPE_STUB_DECL (type)))
11005 VARRAY_PUSH_TREE (incomplete_types, type);
11009 /* Generate a DIE for a subroutine _type_. */
11012 gen_subroutine_type_die (type, context_die)
11014 dw_die_ref context_die;
11016 tree return_type = TREE_TYPE (type);
11017 dw_die_ref subr_die
11018 = new_die (DW_TAG_subroutine_type,
11019 scope_die_for (type, context_die), type);
11021 equate_type_number_to_die (type, subr_die);
11022 add_prototyped_attribute (subr_die, type);
11023 add_type_attribute (subr_die, return_type, 0, 0, context_die);
11024 gen_formal_types_die (type, subr_die);
11027 /* Generate a DIE for a type definition */
11030 gen_typedef_die (decl, context_die)
11032 dw_die_ref context_die;
11034 dw_die_ref type_die;
11037 if (TREE_ASM_WRITTEN (decl))
11040 TREE_ASM_WRITTEN (decl) = 1;
11041 type_die = new_die (DW_TAG_typedef, context_die, decl);
11042 origin = decl_ultimate_origin (decl);
11043 if (origin != NULL)
11044 add_abstract_origin_attribute (type_die, origin);
11049 add_name_and_src_coords_attributes (type_die, decl);
11050 if (DECL_ORIGINAL_TYPE (decl))
11052 type = DECL_ORIGINAL_TYPE (decl);
11054 if (type == TREE_TYPE (decl))
11057 equate_type_number_to_die (TREE_TYPE (decl), type_die);
11060 type = TREE_TYPE (decl);
11062 add_type_attribute (type_die, type, TREE_READONLY (decl),
11063 TREE_THIS_VOLATILE (decl), context_die);
11066 if (DECL_ABSTRACT (decl))
11067 equate_decl_number_to_die (decl, type_die);
11070 /* Generate a type description DIE. */
11073 gen_type_die (type, context_die)
11075 dw_die_ref context_die;
11079 if (type == NULL_TREE || type == error_mark_node)
11082 /* We are going to output a DIE to represent the unqualified version
11083 of this type (i.e. without any const or volatile qualifiers) so
11084 get the main variant (i.e. the unqualified version) of this type
11085 now. (Vectors are special because the debugging info is in the
11086 cloned type itself). */
11087 if (TREE_CODE (type) != VECTOR_TYPE)
11088 type = type_main_variant (type);
11090 if (TREE_ASM_WRITTEN (type))
11093 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11094 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
11096 /* Prevent broken recursion; we can't hand off to the same type. */
11097 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type)
11100 TREE_ASM_WRITTEN (type) = 1;
11101 gen_decl_die (TYPE_NAME (type), context_die);
11105 switch (TREE_CODE (type))
11111 case REFERENCE_TYPE:
11112 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11113 ensures that the gen_type_die recursion will terminate even if the
11114 type is recursive. Recursive types are possible in Ada. */
11115 /* ??? We could perhaps do this for all types before the switch
11117 TREE_ASM_WRITTEN (type) = 1;
11119 /* For these types, all that is required is that we output a DIE (or a
11120 set of DIEs) to represent the "basis" type. */
11121 gen_type_die (TREE_TYPE (type), context_die);
11125 /* This code is used for C++ pointer-to-data-member types.
11126 Output a description of the relevant class type. */
11127 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
11129 /* Output a description of the type of the object pointed to. */
11130 gen_type_die (TREE_TYPE (type), context_die);
11132 /* Now output a DIE to represent this pointer-to-data-member type
11134 gen_ptr_to_mbr_type_die (type, context_die);
11138 gen_type_die (TYPE_DOMAIN (type), context_die);
11139 gen_set_type_die (type, context_die);
11143 gen_type_die (TREE_TYPE (type), context_die);
11144 abort (); /* No way to represent these in Dwarf yet! */
11147 case FUNCTION_TYPE:
11148 /* Force out return type (in case it wasn't forced out already). */
11149 gen_type_die (TREE_TYPE (type), context_die);
11150 gen_subroutine_type_die (type, context_die);
11154 /* Force out return type (in case it wasn't forced out already). */
11155 gen_type_die (TREE_TYPE (type), context_die);
11156 gen_subroutine_type_die (type, context_die);
11160 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
11162 gen_type_die (TREE_TYPE (type), context_die);
11163 gen_string_type_die (type, context_die);
11166 gen_array_type_die (type, context_die);
11170 gen_array_type_die (type, context_die);
11173 case ENUMERAL_TYPE:
11176 case QUAL_UNION_TYPE:
11177 /* If this is a nested type whose containing class hasn't been written
11178 out yet, writing it out will cover this one, too. This does not apply
11179 to instantiations of member class templates; they need to be added to
11180 the containing class as they are generated. FIXME: This hurts the
11181 idea of combining type decls from multiple TUs, since we can't predict
11182 what set of template instantiations we'll get. */
11183 if (TYPE_CONTEXT (type)
11184 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
11185 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
11187 gen_type_die (TYPE_CONTEXT (type), context_die);
11189 if (TREE_ASM_WRITTEN (type))
11192 /* If that failed, attach ourselves to the stub. */
11193 push_decl_scope (TYPE_CONTEXT (type));
11194 context_die = lookup_type_die (TYPE_CONTEXT (type));
11200 if (TREE_CODE (type) == ENUMERAL_TYPE)
11201 gen_enumeration_type_die (type, context_die);
11203 gen_struct_or_union_type_die (type, context_die);
11208 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11209 it up if it is ever completed. gen_*_type_die will set it for us
11210 when appropriate. */
11219 /* No DIEs needed for fundamental types. */
11223 /* No Dwarf representation currently defined. */
11230 TREE_ASM_WRITTEN (type) = 1;
11233 /* Generate a DIE for a tagged type instantiation. */
11236 gen_tagged_type_instantiation_die (type, context_die)
11238 dw_die_ref context_die;
11240 if (type == NULL_TREE || type == error_mark_node)
11243 /* We are going to output a DIE to represent the unqualified version of
11244 this type (i.e. without any const or volatile qualifiers) so make sure
11245 that we have the main variant (i.e. the unqualified version) of this
11247 if (type != type_main_variant (type))
11250 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11251 an instance of an unresolved type. */
11253 switch (TREE_CODE (type))
11258 case ENUMERAL_TYPE:
11259 gen_inlined_enumeration_type_die (type, context_die);
11263 gen_inlined_structure_type_die (type, context_die);
11267 case QUAL_UNION_TYPE:
11268 gen_inlined_union_type_die (type, context_die);
11276 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11277 things which are local to the given block. */
11280 gen_block_die (stmt, context_die, depth)
11282 dw_die_ref context_die;
11285 int must_output_die = 0;
11288 enum tree_code origin_code;
11290 /* Ignore blocks never really used to make RTL. */
11291 if (stmt == NULL_TREE || !TREE_USED (stmt)
11292 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11295 /* If the block is one fragment of a non-contiguous block, do not
11296 process the variables, since they will have been done by the
11297 origin block. Do process subblocks. */
11298 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11302 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
11303 gen_block_die (sub, context_die, depth + 1);
11308 /* Determine the "ultimate origin" of this block. This block may be an
11309 inlined instance of an inlined instance of inline function, so we have
11310 to trace all of the way back through the origin chain to find out what
11311 sort of node actually served as the original seed for the creation of
11312 the current block. */
11313 origin = block_ultimate_origin (stmt);
11314 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11316 /* Determine if we need to output any Dwarf DIEs at all to represent this
11318 if (origin_code == FUNCTION_DECL)
11319 /* The outer scopes for inlinings *must* always be represented. We
11320 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11321 must_output_die = 1;
11324 /* In the case where the current block represents an inlining of the
11325 "body block" of an inline function, we must *NOT* output any DIE for
11326 this block because we have already output a DIE to represent the whole
11327 inlined function scope and the "body block" of any function doesn't
11328 really represent a different scope according to ANSI C rules. So we
11329 check here to make sure that this block does not represent a "body
11330 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11331 if (! is_body_block (origin ? origin : stmt))
11333 /* Determine if this block directly contains any "significant"
11334 local declarations which we will need to output DIEs for. */
11335 if (debug_info_level > DINFO_LEVEL_TERSE)
11336 /* We are not in terse mode so *any* local declaration counts
11337 as being a "significant" one. */
11338 must_output_die = (BLOCK_VARS (stmt) != NULL);
11340 /* We are in terse mode, so only local (nested) function
11341 definitions count as "significant" local declarations. */
11342 for (decl = BLOCK_VARS (stmt);
11343 decl != NULL; decl = TREE_CHAIN (decl))
11344 if (TREE_CODE (decl) == FUNCTION_DECL
11345 && DECL_INITIAL (decl))
11347 must_output_die = 1;
11353 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11354 DIE for any block which contains no significant local declarations at
11355 all. Rather, in such cases we just call `decls_for_scope' so that any
11356 needed Dwarf info for any sub-blocks will get properly generated. Note
11357 that in terse mode, our definition of what constitutes a "significant"
11358 local declaration gets restricted to include only inlined function
11359 instances and local (nested) function definitions. */
11360 if (must_output_die)
11362 if (origin_code == FUNCTION_DECL)
11363 gen_inlined_subroutine_die (stmt, context_die, depth);
11365 gen_lexical_block_die (stmt, context_die, depth);
11368 decls_for_scope (stmt, context_die, depth);
11371 /* Generate all of the decls declared within a given scope and (recursively)
11372 all of its sub-blocks. */
11375 decls_for_scope (stmt, context_die, depth)
11377 dw_die_ref context_die;
11383 /* Ignore blocks never really used to make RTL. */
11384 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11387 /* Output the DIEs to represent all of the data objects and typedefs
11388 declared directly within this block but not within any nested
11389 sub-blocks. Also, nested function and tag DIEs have been
11390 generated with a parent of NULL; fix that up now. */
11391 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
11395 if (TREE_CODE (decl) == FUNCTION_DECL)
11396 die = lookup_decl_die (decl);
11397 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11398 die = lookup_type_die (TREE_TYPE (decl));
11402 if (die != NULL && die->die_parent == NULL)
11403 add_child_die (context_die, die);
11405 gen_decl_die (decl, context_die);
11408 /* Output the DIEs to represent all sub-blocks (and the items declared
11409 therein) of this block. */
11410 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11412 subblocks = BLOCK_CHAIN (subblocks))
11413 gen_block_die (subblocks, context_die, depth + 1);
11416 /* Is this a typedef we can avoid emitting? */
11419 is_redundant_typedef (decl)
11422 if (TYPE_DECL_IS_STUB (decl))
11425 if (DECL_ARTIFICIAL (decl)
11426 && DECL_CONTEXT (decl)
11427 && is_tagged_type (DECL_CONTEXT (decl))
11428 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11429 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11430 /* Also ignore the artificial member typedef for the class name. */
11436 /* Generate Dwarf debug information for a decl described by DECL. */
11439 gen_decl_die (decl, context_die)
11441 dw_die_ref context_die;
11445 if (DECL_P (decl) && DECL_IGNORED_P (decl))
11448 switch (TREE_CODE (decl))
11454 /* The individual enumerators of an enum type get output when we output
11455 the Dwarf representation of the relevant enum type itself. */
11458 case FUNCTION_DECL:
11459 /* Don't output any DIEs to represent mere function declarations,
11460 unless they are class members or explicit block externs. */
11461 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11462 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11465 /* If we're emitting a clone, emit info for the abstract instance. */
11466 if (DECL_ORIGIN (decl) != decl)
11467 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11469 /* If we're emitting an out-of-line copy of an inline function,
11470 emit info for the abstract instance and set up to refer to it. */
11471 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11472 && ! class_scope_p (context_die)
11473 /* dwarf2out_abstract_function won't emit a die if this is just
11474 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11475 that case, because that works only if we have a die. */
11476 && DECL_INITIAL (decl) != NULL_TREE)
11478 dwarf2out_abstract_function (decl);
11479 set_decl_origin_self (decl);
11482 /* Otherwise we're emitting the primary DIE for this decl. */
11483 else if (debug_info_level > DINFO_LEVEL_TERSE)
11485 /* Before we describe the FUNCTION_DECL itself, make sure that we
11486 have described its return type. */
11487 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11489 /* And its virtual context. */
11490 if (DECL_VINDEX (decl) != NULL_TREE)
11491 gen_type_die (DECL_CONTEXT (decl), context_die);
11493 /* And its containing type. */
11494 origin = decl_class_context (decl);
11495 if (origin != NULL_TREE)
11496 gen_type_die_for_member (origin, decl, context_die);
11499 /* Now output a DIE to represent the function itself. */
11500 gen_subprogram_die (decl, context_die);
11504 /* If we are in terse mode, don't generate any DIEs to represent any
11505 actual typedefs. */
11506 if (debug_info_level <= DINFO_LEVEL_TERSE)
11509 /* In the special case of a TYPE_DECL node representing the declaration
11510 of some type tag, if the given TYPE_DECL is marked as having been
11511 instantiated from some other (original) TYPE_DECL node (e.g. one which
11512 was generated within the original definition of an inline function) we
11513 have to generate a special (abbreviated) DW_TAG_structure_type,
11514 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11515 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11517 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11521 if (is_redundant_typedef (decl))
11522 gen_type_die (TREE_TYPE (decl), context_die);
11524 /* Output a DIE to represent the typedef itself. */
11525 gen_typedef_die (decl, context_die);
11529 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11530 gen_label_die (decl, context_die);
11534 /* If we are in terse mode, don't generate any DIEs to represent any
11535 variable declarations or definitions. */
11536 if (debug_info_level <= DINFO_LEVEL_TERSE)
11539 /* Output any DIEs that are needed to specify the type of this data
11541 gen_type_die (TREE_TYPE (decl), context_die);
11543 /* And its containing type. */
11544 origin = decl_class_context (decl);
11545 if (origin != NULL_TREE)
11546 gen_type_die_for_member (origin, decl, context_die);
11548 /* Now output the DIE to represent the data object itself. This gets
11549 complicated because of the possibility that the VAR_DECL really
11550 represents an inlined instance of a formal parameter for an inline
11552 origin = decl_ultimate_origin (decl);
11553 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11554 gen_formal_parameter_die (decl, context_die);
11556 gen_variable_die (decl, context_die);
11560 /* Ignore the nameless fields that are used to skip bits but handle C++
11561 anonymous unions. */
11562 if (DECL_NAME (decl) != NULL_TREE
11563 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11565 gen_type_die (member_declared_type (decl), context_die);
11566 gen_field_die (decl, context_die);
11571 gen_type_die (TREE_TYPE (decl), context_die);
11572 gen_formal_parameter_die (decl, context_die);
11575 case NAMESPACE_DECL:
11576 /* Ignore for now. */
11585 mark_limbo_die_list (ptr)
11586 void *ptr ATTRIBUTE_UNUSED;
11588 limbo_die_node *node;
11589 for (node = limbo_die_list; node; node = node->next)
11590 ggc_mark_tree (node->created_for);
11593 /* Add Ada "use" clause information for SGI Workshop debugger. */
11596 dwarf2out_add_library_unit_info (filename, context_list)
11597 const char *filename;
11598 const char *context_list;
11600 unsigned int file_index;
11602 if (filename != NULL)
11604 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
11605 tree context_list_decl
11606 = build_decl (LABEL_DECL, get_identifier (context_list),
11609 TREE_PUBLIC (context_list_decl) = TRUE;
11610 add_name_attribute (unit_die, context_list);
11611 file_index = lookup_filename (filename);
11612 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11613 add_pubname (context_list_decl, unit_die);
11617 /* Output debug information for global decl DECL. Called from toplev.c after
11618 compilation proper has finished. */
11621 dwarf2out_global_decl (decl)
11624 /* Output DWARF2 information for file-scope tentative data object
11625 declarations, file-scope (extern) function declarations (which had no
11626 corresponding body) and file-scope tagged type declarations and
11627 definitions which have not yet been forced out. */
11628 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11629 dwarf2out_decl (decl);
11632 /* Write the debugging output for DECL. */
11635 dwarf2out_decl (decl)
11638 dw_die_ref context_die = comp_unit_die;
11640 switch (TREE_CODE (decl))
11645 case FUNCTION_DECL:
11646 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11647 builtin function. Explicit programmer-supplied declarations of
11648 these same functions should NOT be ignored however. */
11649 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11652 /* What we would really like to do here is to filter out all mere
11653 file-scope declarations of file-scope functions which are never
11654 referenced later within this translation unit (and keep all of ones
11655 that *are* referenced later on) but we aren't clairvoyant, so we have
11656 no idea which functions will be referenced in the future (i.e. later
11657 on within the current translation unit). So here we just ignore all
11658 file-scope function declarations which are not also definitions. If
11659 and when the debugger needs to know something about these functions,
11660 it will have to hunt around and find the DWARF information associated
11661 with the definition of the function.
11663 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11664 nodes represent definitions and which ones represent mere
11665 declarations. We have to check DECL_INITIAL instead. That's because
11666 the C front-end supports some weird semantics for "extern inline"
11667 function definitions. These can get inlined within the current
11668 translation unit (an thus, we need to generate Dwarf info for their
11669 abstract instances so that the Dwarf info for the concrete inlined
11670 instances can have something to refer to) but the compiler never
11671 generates any out-of-lines instances of such things (despite the fact
11672 that they *are* definitions).
11674 The important point is that the C front-end marks these "extern
11675 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11676 them anyway. Note that the C++ front-end also plays some similar games
11677 for inline function definitions appearing within include files which
11678 also contain `#pragma interface' pragmas. */
11679 if (DECL_INITIAL (decl) == NULL_TREE)
11682 /* If we're a nested function, initially use a parent of NULL; if we're
11683 a plain function, this will be fixed up in decls_for_scope. If
11684 we're a method, it will be ignored, since we already have a DIE. */
11685 if (decl_function_context (decl))
11686 context_die = NULL;
11690 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11691 declaration and if the declaration was never even referenced from
11692 within this entire compilation unit. We suppress these DIEs in
11693 order to save space in the .debug section (by eliminating entries
11694 which are probably useless). Note that we must not suppress
11695 block-local extern declarations (whether used or not) because that
11696 would screw-up the debugger's name lookup mechanism and cause it to
11697 miss things which really ought to be in scope at a given point. */
11698 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11701 /* If we are in terse mode, don't generate any DIEs to represent any
11702 variable declarations or definitions. */
11703 if (debug_info_level <= DINFO_LEVEL_TERSE)
11708 /* Don't emit stubs for types unless they are needed by other DIEs. */
11709 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11712 /* Don't bother trying to generate any DIEs to represent any of the
11713 normal built-in types for the language we are compiling. */
11714 if (DECL_SOURCE_LINE (decl) == 0)
11716 /* OK, we need to generate one for `bool' so GDB knows what type
11717 comparisons have. */
11718 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11719 == DW_LANG_C_plus_plus)
11720 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
11721 && ! DECL_IGNORED_P (decl))
11722 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11727 /* If we are in terse mode, don't generate any DIEs for types. */
11728 if (debug_info_level <= DINFO_LEVEL_TERSE)
11731 /* If we're a function-scope tag, initially use a parent of NULL;
11732 this will be fixed up in decls_for_scope. */
11733 if (decl_function_context (decl))
11734 context_die = NULL;
11742 gen_decl_die (decl, context_die);
11745 /* Output a marker (i.e. a label) for the beginning of the generated code for
11746 a lexical block. */
11749 dwarf2out_begin_block (line, blocknum)
11750 unsigned int line ATTRIBUTE_UNUSED;
11751 unsigned int blocknum;
11753 function_section (current_function_decl);
11754 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11757 /* Output a marker (i.e. a label) for the end of the generated code for a
11761 dwarf2out_end_block (line, blocknum)
11762 unsigned int line ATTRIBUTE_UNUSED;
11763 unsigned int blocknum;
11765 function_section (current_function_decl);
11766 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11769 /* Returns nonzero if it is appropriate not to emit any debugging
11770 information for BLOCK, because it doesn't contain any instructions.
11772 Don't allow this for blocks with nested functions or local classes
11773 as we would end up with orphans, and in the presence of scheduling
11774 we may end up calling them anyway. */
11777 dwarf2out_ignore_block (block)
11782 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11783 if (TREE_CODE (decl) == FUNCTION_DECL
11784 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11790 /* Lookup FILE_NAME (in the list of filenames that we know about here in
11791 dwarf2out.c) and return its "index". The index of each (known) filename is
11792 just a unique number which is associated with only that one filename. We
11793 need such numbers for the sake of generating labels (in the .debug_sfnames
11794 section) and references to those files numbers (in the .debug_srcinfo
11795 and.debug_macinfo sections). If the filename given as an argument is not
11796 found in our current list, add it to the list and assign it the next
11797 available unique index number. In order to speed up searches, we remember
11798 the index of the filename was looked up last. This handles the majority of
11802 lookup_filename (file_name)
11803 const char *file_name;
11807 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11808 if (strcmp (file_name, "<internal>") == 0
11809 || strcmp (file_name, "<built-in>") == 0)
11812 /* Check to see if the file name that was searched on the previous
11813 call matches this file name. If so, return the index. */
11814 if (file_table.last_lookup_index != 0)
11815 if (0 == strcmp (file_name,
11816 file_table.table[file_table.last_lookup_index]))
11817 return file_table.last_lookup_index;
11819 /* Didn't match the previous lookup, search the table */
11820 for (i = 1; i < file_table.in_use; i++)
11821 if (strcmp (file_name, file_table.table[i]) == 0)
11823 file_table.last_lookup_index = i;
11827 /* Prepare to add a new table entry by making sure there is enough space in
11828 the table to do so. If not, expand the current table. */
11829 if (i == file_table.allocated)
11831 file_table.allocated = i + FILE_TABLE_INCREMENT;
11832 file_table.table = (char **)
11833 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11836 /* Add the new entry to the end of the filename table. */
11837 file_table.table[i] = xstrdup (file_name);
11838 file_table.in_use = i + 1;
11839 file_table.last_lookup_index = i;
11841 if (DWARF2_ASM_LINE_DEBUG_INFO)
11843 fprintf (asm_out_file, "\t.file %u ", i);
11844 output_quoted_string (asm_out_file, file_name);
11845 fputc ('\n', asm_out_file);
11854 /* Allocate the initial hunk of the file_table. */
11855 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11856 file_table.allocated = FILE_TABLE_INCREMENT;
11858 /* Skip the first entry - file numbers begin at 1. */
11859 file_table.in_use = 1;
11860 file_table.last_lookup_index = 0;
11863 /* Output a label to mark the beginning of a source code line entry
11864 and record information relating to this source line, in
11865 'line_info_table' for later output of the .debug_line section. */
11868 dwarf2out_source_line (line, filename)
11870 const char *filename;
11872 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11874 function_section (current_function_decl);
11876 /* If requested, emit something human-readable. */
11877 if (flag_debug_asm)
11878 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11881 if (DWARF2_ASM_LINE_DEBUG_INFO)
11883 unsigned file_num = lookup_filename (filename);
11885 /* Emit the .loc directive understood by GNU as. */
11886 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11888 /* Indicate that line number info exists. */
11889 line_info_table_in_use++;
11891 /* Indicate that multiple line number tables exist. */
11892 if (DECL_SECTION_NAME (current_function_decl))
11893 separate_line_info_table_in_use++;
11895 else if (DECL_SECTION_NAME (current_function_decl))
11897 dw_separate_line_info_ref line_info;
11898 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11899 separate_line_info_table_in_use);
11901 /* expand the line info table if necessary */
11902 if (separate_line_info_table_in_use
11903 == separate_line_info_table_allocated)
11905 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11906 separate_line_info_table
11907 = (dw_separate_line_info_ref)
11908 xrealloc (separate_line_info_table,
11909 separate_line_info_table_allocated
11910 * sizeof (dw_separate_line_info_entry));
11913 /* Add the new entry at the end of the line_info_table. */
11915 = &separate_line_info_table[separate_line_info_table_in_use++];
11916 line_info->dw_file_num = lookup_filename (filename);
11917 line_info->dw_line_num = line;
11918 line_info->function = current_funcdef_number;
11922 dw_line_info_ref line_info;
11924 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11925 line_info_table_in_use);
11927 /* Expand the line info table if necessary. */
11928 if (line_info_table_in_use == line_info_table_allocated)
11930 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11932 = (dw_line_info_ref)
11933 xrealloc (line_info_table,
11934 (line_info_table_allocated
11935 * sizeof (dw_line_info_entry)));
11938 /* Add the new entry at the end of the line_info_table. */
11939 line_info = &line_info_table[line_info_table_in_use++];
11940 line_info->dw_file_num = lookup_filename (filename);
11941 line_info->dw_line_num = line;
11946 /* Record the beginning of a new source file. */
11949 dwarf2out_start_source_file (lineno, filename)
11950 unsigned int lineno;
11951 const char *filename;
11953 if (flag_eliminate_dwarf2_dups)
11955 /* Record the beginning of the file for break_out_includes. */
11956 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
11957 add_AT_string (bincl_die, DW_AT_name, filename);
11960 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11962 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11963 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11964 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11966 dw2_asm_output_data_uleb128 (lookup_filename (filename),
11967 "Filename we just started");
11971 /* Record the end of a source file. */
11974 dwarf2out_end_source_file (lineno)
11975 unsigned int lineno ATTRIBUTE_UNUSED;
11977 if (flag_eliminate_dwarf2_dups)
11978 /* Record the end of the file for break_out_includes. */
11979 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
11981 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11983 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11984 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11988 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11989 the tail part of the directive line, i.e. the part which is past the
11990 initial whitespace, #, whitespace, directive-name, whitespace part. */
11993 dwarf2out_define (lineno, buffer)
11994 unsigned lineno ATTRIBUTE_UNUSED;
11995 const char *buffer ATTRIBUTE_UNUSED;
11997 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11999 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12000 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
12001 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12002 dw2_asm_output_nstring (buffer, -1, "The macro");
12006 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
12007 the tail part of the directive line, i.e. the part which is past the
12008 initial whitespace, #, whitespace, directive-name, whitespace part. */
12011 dwarf2out_undef (lineno, buffer)
12012 unsigned lineno ATTRIBUTE_UNUSED;
12013 const char *buffer ATTRIBUTE_UNUSED;
12015 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12017 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12018 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
12019 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12020 dw2_asm_output_nstring (buffer, -1, "The macro");
12024 /* Set up for Dwarf output at the start of compilation. */
12027 dwarf2out_init (main_input_filename)
12028 const char *main_input_filename;
12030 init_file_table ();
12032 /* Remember the name of the primary input file. */
12033 primary_filename = main_input_filename;
12035 /* Add it to the file table first, under the assumption that we'll
12036 be emitting line number data for it first, which avoids having
12037 to add an initial DW_LNS_set_file. */
12038 lookup_filename (main_input_filename);
12040 /* Allocate the initial hunk of the decl_die_table. */
12042 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
12043 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
12044 decl_die_table_in_use = 0;
12046 /* Allocate the initial hunk of the decl_scope_table. */
12047 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
12048 ggc_add_tree_varray_root (&decl_scope_table, 1);
12050 /* Allocate the initial hunk of the abbrev_die_table. */
12052 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
12053 sizeof (dw_die_ref));
12054 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
12055 /* Zero-th entry is allocated, but unused */
12056 abbrev_die_table_in_use = 1;
12058 /* Allocate the initial hunk of the line_info_table. */
12060 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
12061 sizeof (dw_line_info_entry));
12062 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
12064 /* Zero-th entry is allocated, but unused */
12065 line_info_table_in_use = 1;
12067 /* Generate the initial DIE for the .debug section. Note that the (string)
12068 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12069 will (typically) be a relative pathname and that this pathname should be
12070 taken as being relative to the directory from which the compiler was
12071 invoked when the given (base) source file was compiled. */
12072 comp_unit_die = gen_compile_unit_die (main_input_filename);
12074 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
12075 ggc_add_tree_varray_root (&incomplete_types, 1);
12077 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
12078 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
12080 ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list);
12082 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
12083 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
12084 DEBUG_ABBREV_SECTION_LABEL, 0);
12085 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12086 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
12088 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
12090 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
12091 DEBUG_INFO_SECTION_LABEL, 0);
12092 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
12093 DEBUG_LINE_SECTION_LABEL, 0);
12094 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
12095 DEBUG_RANGES_SECTION_LABEL, 0);
12096 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12097 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
12098 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
12099 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
12100 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12101 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
12103 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12105 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12106 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
12107 DEBUG_MACINFO_SECTION_LABEL, 0);
12108 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
12111 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12114 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
12118 /* Allocate a string in .debug_str hash table. */
12121 indirect_string_alloc (tab)
12122 hash_table *tab ATTRIBUTE_UNUSED;
12124 struct indirect_string_node *node;
12126 node = xmalloc (sizeof (struct indirect_string_node));
12127 node->refcount = 0;
12129 node->label = NULL;
12131 return (hashnode) node;
12134 /* A helper function for dwarf2out_finish called through
12135 ht_forall. Emit one queued .debug_str string. */
12138 output_indirect_string (pfile, h, v)
12139 struct cpp_reader *pfile ATTRIBUTE_UNUSED;
12141 const PTR v ATTRIBUTE_UNUSED;
12143 struct indirect_string_node *node = (struct indirect_string_node *) h;
12145 if (node->form == DW_FORM_strp)
12147 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
12148 ASM_OUTPUT_LABEL (asm_out_file, node->label);
12149 assemble_string ((const char *) HT_STR (&node->id),
12150 HT_LEN (&node->id) + 1);
12156 /* Output stuff that dwarf requires at the end of every file,
12157 and generate the DWARF-2 debugging info. */
12160 dwarf2out_finish (input_filename)
12161 const char *input_filename ATTRIBUTE_UNUSED;
12163 limbo_die_node *node, *next_node;
12164 dw_die_ref die = 0;
12166 /* Traverse the limbo die list, and add parent/child links. The only
12167 dies without parents that should be here are concrete instances of
12168 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12169 For concrete instances, we can get the parent die from the abstract
12171 for (node = limbo_die_list; node; node = next_node)
12173 next_node = node->next;
12176 if (die->die_parent == NULL)
12178 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
12182 add_child_die (origin->die_parent, die);
12183 else if (die == comp_unit_die)
12185 /* If this was an expression for a bound involved in a function
12186 return type, it may be a SAVE_EXPR for which we weren't able
12187 to find a DIE previously. So try now. */
12188 else if (node->created_for
12189 && TREE_CODE (node->created_for) == SAVE_EXPR
12190 && 0 != (origin = (lookup_decl_die
12192 (node->created_for)))))
12193 add_child_die (origin, die);
12194 else if (errorcount > 0 || sorrycount > 0)
12195 /* It's OK to be confused by errors in the input. */
12196 add_child_die (comp_unit_die, die);
12197 else if (node->created_for
12198 && ((DECL_P (node->created_for)
12199 && (context = DECL_CONTEXT (node->created_for)))
12200 || (TYPE_P (node->created_for)
12201 && (context = TYPE_CONTEXT (node->created_for))))
12202 && TREE_CODE (context) == FUNCTION_DECL)
12204 /* In certain situations, the lexical block containing a
12205 nested function can be optimized away, which results
12206 in the nested function die being orphaned. Likewise
12207 with the return type of that nested function. Force
12208 this to be a child of the containing function. */
12209 origin = lookup_decl_die (context);
12212 add_child_die (origin, die);
12221 limbo_die_list = NULL;
12223 /* Walk through the list of incomplete types again, trying once more to
12224 emit full debugging info for them. */
12225 retry_incomplete_types ();
12227 /* We need to reverse all the dies before break_out_includes, or
12228 we'll see the end of an include file before the beginning. */
12229 reverse_all_dies (comp_unit_die);
12231 /* Generate separate CUs for each of the include files we've seen.
12232 They will go into limbo_die_list. */
12233 if (flag_eliminate_dwarf2_dups)
12234 break_out_includes (comp_unit_die);
12236 /* Traverse the DIE's and add add sibling attributes to those DIE's
12237 that have children. */
12238 add_sibling_attributes (comp_unit_die);
12239 for (node = limbo_die_list; node; node = node->next)
12240 add_sibling_attributes (node->die);
12242 /* Output a terminator label for the .text section. */
12244 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
12246 /* Output the source line correspondence table. We must do this
12247 even if there is no line information. Otherwise, on an empty
12248 translation unit, we will generate a present, but empty,
12249 .debug_info section. IRIX 6.5 `nm' will then complain when
12250 examining the file. */
12251 if (! DWARF2_ASM_LINE_DEBUG_INFO)
12253 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12254 output_line_info ();
12257 /* Output location list section if necessary. */
12258 if (have_location_lists)
12260 /* Output the location lists info. */
12261 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
12262 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
12263 DEBUG_LOC_SECTION_LABEL, 0);
12264 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
12265 output_location_lists (die);
12266 have_location_lists = 0;
12269 /* We can only use the low/high_pc attributes if all of the code was
12271 if (separate_line_info_table_in_use == 0)
12273 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
12274 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
12277 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12278 "base address". Use zero so that these addresses become absolute. */
12279 else if (have_location_lists || ranges_table_in_use)
12280 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
12282 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12283 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
12284 debug_line_section_label);
12286 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12287 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
12289 /* Output all of the compilation units. We put the main one last so that
12290 the offsets are available to output_pubnames. */
12291 for (node = limbo_die_list; node; node = node->next)
12292 output_comp_unit (node->die);
12294 output_comp_unit (comp_unit_die);
12296 /* Output the abbreviation table. */
12297 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12298 output_abbrev_section ();
12300 /* Output public names table if necessary. */
12301 if (pubname_table_in_use)
12303 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
12304 output_pubnames ();
12307 /* Output the address range information. We only put functions in the arange
12308 table, so don't write it out if we don't have any. */
12309 if (fde_table_in_use)
12311 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
12315 /* Output ranges section if necessary. */
12316 if (ranges_table_in_use)
12318 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
12319 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12323 /* Have to end the primary source file. */
12324 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12326 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12327 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12328 dw2_asm_output_data (1, 0, "End compilation unit");
12331 /* If we emitted any DW_FORM_strp form attribute, output the string
12333 if (debug_str_hash)
12334 ht_forall (debug_str_hash, output_indirect_string, NULL);
12336 #endif /* DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO */