1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
42 #include "hard-reg-set.h"
44 #include "insn-config.h"
52 #include "dwarf2out.h"
53 #include "dwarf2asm.h"
59 #include "diagnostic.h"
62 #include "langhooks.h"
63 #include "hashtable.h"
65 #ifdef DWARF2_DEBUGGING_INFO
66 static void dwarf2out_source_line PARAMS ((unsigned int, const char *));
69 /* DWARF2 Abbreviation Glossary:
70 CFA = Canonical Frame Address
71 a fixed address on the stack which identifies a call frame.
72 We define it to be the value of SP just before the call insn.
73 The CFA register and offset, which may change during the course
74 of the function, are used to calculate its value at runtime.
75 CFI = Call Frame Instruction
76 an instruction for the DWARF2 abstract machine
77 CIE = Common Information Entry
78 information describing information common to one or more FDEs
79 DIE = Debugging Information Entry
80 FDE = Frame Description Entry
81 information describing the stack call frame, in particular,
82 how to restore registers
84 DW_CFA_... = DWARF2 CFA call frame instruction
85 DW_TAG_... = DWARF2 DIE tag */
87 /* Decide whether we want to emit frame unwind information for the current
93 return (write_symbols == DWARF2_DEBUG
94 || write_symbols == VMS_AND_DWARF2_DEBUG
95 #ifdef DWARF2_FRAME_INFO
98 #ifdef DWARF2_UNWIND_INFO
100 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
105 /* The number of the current function definition for which debugging
106 information is being generated. These numbers range from 1 up to the
107 maximum number of function definitions contained within the current
108 compilation unit. These numbers are used to create unique label id's
109 unique to each function definition. */
110 unsigned current_funcdef_number = 0;
112 /* The size of the target's pointer type. */
114 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
117 /* Default version of targetm.eh_frame_section. Note this must appear
118 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
122 default_eh_frame_section ()
124 #ifdef EH_FRAME_SECTION_NAME
125 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
127 tree label = get_file_function_name ('F');
130 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
131 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
132 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
136 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
138 /* How to start an assembler comment. */
139 #ifndef ASM_COMMENT_START
140 #define ASM_COMMENT_START ";#"
143 typedef struct dw_cfi_struct *dw_cfi_ref;
144 typedef struct dw_fde_struct *dw_fde_ref;
145 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
147 /* Call frames are described using a sequence of Call Frame
148 Information instructions. The register number, offset
149 and address fields are provided as possible operands;
150 their use is selected by the opcode field. */
152 typedef union dw_cfi_oprnd_struct
154 unsigned long dw_cfi_reg_num;
155 long int dw_cfi_offset;
156 const char *dw_cfi_addr;
157 struct dw_loc_descr_struct *dw_cfi_loc;
161 typedef struct dw_cfi_struct
163 dw_cfi_ref dw_cfi_next;
164 enum dwarf_call_frame_info dw_cfi_opc;
165 dw_cfi_oprnd dw_cfi_oprnd1;
166 dw_cfi_oprnd dw_cfi_oprnd2;
170 /* This is how we define the location of the CFA. We use to handle it
171 as REG + OFFSET all the time, but now it can be more complex.
172 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
173 Instead of passing around REG and OFFSET, we pass a copy
174 of this structure. */
175 typedef struct cfa_loc
180 int indirect; /* 1 if CFA is accessed via a dereference. */
183 /* All call frame descriptions (FDE's) in the GCC generated DWARF
184 refer to a single Common Information Entry (CIE), defined at
185 the beginning of the .debug_frame section. This use of a single
186 CIE obviates the need to keep track of multiple CIE's
187 in the DWARF generation routines below. */
189 typedef struct dw_fde_struct
191 const char *dw_fde_begin;
192 const char *dw_fde_current_label;
193 const char *dw_fde_end;
194 dw_cfi_ref dw_fde_cfi;
195 unsigned funcdef_number;
196 unsigned nothrow : 1;
197 unsigned uses_eh_lsda : 1;
201 /* Maximum size (in bytes) of an artificially generated label. */
202 #define MAX_ARTIFICIAL_LABEL_BYTES 30
204 /* The size of addresses as they appear in the Dwarf 2 data.
205 Some architectures use word addresses to refer to code locations,
206 but Dwarf 2 info always uses byte addresses. On such machines,
207 Dwarf 2 addresses need to be larger than the architecture's
209 #ifndef DWARF2_ADDR_SIZE
210 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
213 /* The size in bytes of a DWARF field indicating an offset or length
214 relative to a debug info section, specified to be 4 bytes in the
215 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
218 #ifndef DWARF_OFFSET_SIZE
219 #define DWARF_OFFSET_SIZE 4
222 #define DWARF_VERSION 2
224 /* Round SIZE up to the nearest BOUNDARY. */
225 #define DWARF_ROUND(SIZE,BOUNDARY) \
226 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
228 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
229 #ifndef DWARF_CIE_DATA_ALIGNMENT
230 #ifdef STACK_GROWS_DOWNWARD
231 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
233 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
237 /* A pointer to the base of a table that contains frame description
238 information for each routine. */
239 static dw_fde_ref fde_table;
241 /* Number of elements currently allocated for fde_table. */
242 static unsigned fde_table_allocated;
244 /* Number of elements in fde_table currently in use. */
245 static unsigned fde_table_in_use;
247 /* Size (in elements) of increments by which we may expand the
249 #define FDE_TABLE_INCREMENT 256
251 /* A list of call frame insns for the CIE. */
252 static dw_cfi_ref cie_cfi_head;
254 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
255 attribute that accelerates the lookup of the FDE associated
256 with the subprogram. This variable holds the table index of the FDE
257 associated with the current function (body) definition. */
258 static unsigned current_funcdef_fde;
260 struct ht *debug_str_hash;
262 struct indirect_string_node
264 struct ht_identifier id;
265 unsigned int refcount;
270 /* Forward declarations for functions defined in this file. */
272 static char *stripattributes PARAMS ((const char *));
273 static const char *dwarf_cfi_name PARAMS ((unsigned));
274 static dw_cfi_ref new_cfi PARAMS ((void));
275 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
276 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
277 static void lookup_cfa_1 PARAMS ((dw_cfi_ref,
279 static void lookup_cfa PARAMS ((dw_cfa_location *));
280 static void reg_save PARAMS ((const char *, unsigned,
282 static void initial_return_save PARAMS ((rtx));
283 static long stack_adjust_offset PARAMS ((rtx));
284 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
285 static void output_call_frame_info PARAMS ((int));
286 static void dwarf2out_stack_adjust PARAMS ((rtx));
287 static void queue_reg_save PARAMS ((const char *, rtx, long));
288 static void flush_queued_reg_saves PARAMS ((void));
289 static bool clobbers_queued_reg_save PARAMS ((rtx));
290 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
292 /* Support for complex CFA locations. */
293 static void output_cfa_loc PARAMS ((dw_cfi_ref));
294 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
295 struct dw_loc_descr_struct *));
296 static struct dw_loc_descr_struct *build_cfa_loc
297 PARAMS ((dw_cfa_location *));
298 static void def_cfa_1 PARAMS ((const char *,
301 /* .debug_str support. */
302 static hashnode indirect_string_alloc PARAMS ((hash_table *));
303 static int output_indirect_string PARAMS ((struct cpp_reader *,
304 hashnode, const PTR));
306 /* How to start an assembler comment. */
307 #ifndef ASM_COMMENT_START
308 #define ASM_COMMENT_START ";#"
311 /* Data and reference forms for relocatable data. */
312 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
313 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
315 /* Pseudo-op for defining a new section. */
316 #ifndef SECTION_ASM_OP
317 #define SECTION_ASM_OP "\t.section\t"
320 #ifndef DEBUG_FRAME_SECTION
321 #define DEBUG_FRAME_SECTION ".debug_frame"
324 #ifndef FUNC_BEGIN_LABEL
325 #define FUNC_BEGIN_LABEL "LFB"
328 #ifndef FUNC_END_LABEL
329 #define FUNC_END_LABEL "LFE"
332 #define FRAME_BEGIN_LABEL "Lframe"
333 #define CIE_AFTER_SIZE_LABEL "LSCIE"
334 #define CIE_END_LABEL "LECIE"
335 #define CIE_LENGTH_LABEL "LLCIE"
336 #define FDE_LABEL "LSFDE"
337 #define FDE_AFTER_SIZE_LABEL "LASFDE"
338 #define FDE_END_LABEL "LEFDE"
339 #define FDE_LENGTH_LABEL "LLFDE"
340 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
341 #define LINE_NUMBER_END_LABEL "LELT"
342 #define LN_PROLOG_AS_LABEL "LASLTP"
343 #define LN_PROLOG_END_LABEL "LELTP"
344 #define DIE_LABEL_PREFIX "DW"
346 /* Definitions of defaults for various types of primitive assembly language
347 output operations. These may be overridden from within the tm.h file,
348 but typically, that is unnecessary. */
351 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
352 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
354 fprintf (FILE, "%s", SET_ASM_OP); \
355 assemble_name (FILE, SY); \
357 assemble_name (FILE, HI); \
359 assemble_name (FILE, LO); \
364 /* The DWARF 2 CFA column which tracks the return address. Normally this
365 is the column for PC, or the first column after all of the hard
367 #ifndef DWARF_FRAME_RETURN_COLUMN
369 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
371 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
375 /* The mapping from gcc register number to DWARF 2 CFA column number. By
376 default, we just provide columns for all registers. */
377 #ifndef DWARF_FRAME_REGNUM
378 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
381 /* The offset from the incoming value of %sp to the top of the stack frame
382 for the current function. */
383 #ifndef INCOMING_FRAME_SP_OFFSET
384 #define INCOMING_FRAME_SP_OFFSET 0
387 /* Hook used by __throw. */
390 expand_builtin_dwarf_fp_regnum ()
392 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
395 /* Return a pointer to a copy of the section string name S with all
396 attributes stripped off, and an asterisk prepended (for assemble_name). */
402 char *stripped = xmalloc (strlen (s) + 2);
407 while (*s && *s != ',')
414 /* Generate code to initialize the register size table. */
417 expand_builtin_init_dwarf_reg_sizes (address)
421 enum machine_mode mode = TYPE_MODE (char_type_node);
422 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
423 rtx mem = gen_rtx_MEM (BLKmode, addr);
425 for (i = 0; i < DWARF_FRAME_REGISTERS; i++)
427 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
428 HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]);
433 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
437 /* Convert a DWARF call frame info. operation to its string name */
440 dwarf_cfi_name (cfi_opc)
445 case DW_CFA_advance_loc:
446 return "DW_CFA_advance_loc";
448 return "DW_CFA_offset";
450 return "DW_CFA_restore";
454 return "DW_CFA_set_loc";
455 case DW_CFA_advance_loc1:
456 return "DW_CFA_advance_loc1";
457 case DW_CFA_advance_loc2:
458 return "DW_CFA_advance_loc2";
459 case DW_CFA_advance_loc4:
460 return "DW_CFA_advance_loc4";
461 case DW_CFA_offset_extended:
462 return "DW_CFA_offset_extended";
463 case DW_CFA_restore_extended:
464 return "DW_CFA_restore_extended";
465 case DW_CFA_undefined:
466 return "DW_CFA_undefined";
467 case DW_CFA_same_value:
468 return "DW_CFA_same_value";
469 case DW_CFA_register:
470 return "DW_CFA_register";
471 case DW_CFA_remember_state:
472 return "DW_CFA_remember_state";
473 case DW_CFA_restore_state:
474 return "DW_CFA_restore_state";
476 return "DW_CFA_def_cfa";
477 case DW_CFA_def_cfa_register:
478 return "DW_CFA_def_cfa_register";
479 case DW_CFA_def_cfa_offset:
480 return "DW_CFA_def_cfa_offset";
481 case DW_CFA_def_cfa_expression:
482 return "DW_CFA_def_cfa_expression";
484 /* SGI/MIPS specific */
485 case DW_CFA_MIPS_advance_loc8:
486 return "DW_CFA_MIPS_advance_loc8";
489 case DW_CFA_GNU_window_save:
490 return "DW_CFA_GNU_window_save";
491 case DW_CFA_GNU_args_size:
492 return "DW_CFA_GNU_args_size";
493 case DW_CFA_GNU_negative_offset_extended:
494 return "DW_CFA_GNU_negative_offset_extended";
497 return "DW_CFA_<unknown>";
501 /* Return a pointer to a newly allocated Call Frame Instruction. */
503 static inline dw_cfi_ref
506 dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
508 cfi->dw_cfi_next = NULL;
509 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
510 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
515 /* Add a Call Frame Instruction to list of instructions. */
518 add_cfi (list_head, cfi)
519 dw_cfi_ref *list_head;
524 /* Find the end of the chain. */
525 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
531 /* Generate a new label for the CFI info to refer to. */
534 dwarf2out_cfi_label ()
536 static char label[20];
537 static unsigned long label_num = 0;
539 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
540 ASM_OUTPUT_LABEL (asm_out_file, label);
544 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
545 or to the CIE if LABEL is NULL. */
548 add_fde_cfi (label, cfi)
554 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
557 label = dwarf2out_cfi_label ();
559 if (fde->dw_fde_current_label == NULL
560 || strcmp (label, fde->dw_fde_current_label) != 0)
564 fde->dw_fde_current_label = label = xstrdup (label);
566 /* Set the location counter to the new label. */
568 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
569 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
570 add_cfi (&fde->dw_fde_cfi, xcfi);
573 add_cfi (&fde->dw_fde_cfi, cfi);
577 add_cfi (&cie_cfi_head, cfi);
580 /* Subroutine of lookup_cfa. */
583 lookup_cfa_1 (cfi, loc)
585 dw_cfa_location *loc;
587 switch (cfi->dw_cfi_opc)
589 case DW_CFA_def_cfa_offset:
590 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
592 case DW_CFA_def_cfa_register:
593 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
596 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
597 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
599 case DW_CFA_def_cfa_expression:
600 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
607 /* Find the previous value for the CFA. */
611 dw_cfa_location *loc;
615 loc->reg = (unsigned long) -1;
618 loc->base_offset = 0;
620 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
621 lookup_cfa_1 (cfi, loc);
623 if (fde_table_in_use)
625 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
626 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
627 lookup_cfa_1 (cfi, loc);
631 /* The current rule for calculating the DWARF2 canonical frame address. */
632 static dw_cfa_location cfa;
634 /* The register used for saving registers to the stack, and its offset
636 static dw_cfa_location cfa_store;
638 /* The running total of the size of arguments pushed onto the stack. */
639 static long args_size;
641 /* The last args_size we actually output. */
642 static long old_args_size;
644 /* Entry point to update the canonical frame address (CFA).
645 LABEL is passed to add_fde_cfi. The value of CFA is now to be
646 calculated from REG+OFFSET. */
649 dwarf2out_def_cfa (label, reg, offset)
659 def_cfa_1 (label, &loc);
662 /* This routine does the actual work. The CFA is now calculated from
663 the dw_cfa_location structure. */
666 def_cfa_1 (label, loc_p)
668 dw_cfa_location *loc_p;
671 dw_cfa_location old_cfa, loc;
676 if (cfa_store.reg == loc.reg && loc.indirect == 0)
677 cfa_store.offset = loc.offset;
679 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
680 lookup_cfa (&old_cfa);
682 /* If nothing changed, no need to issue any call frame instructions. */
683 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
684 && loc.indirect == old_cfa.indirect
685 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
690 if (loc.reg == old_cfa.reg && !loc.indirect)
692 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
693 indicating the CFA register did not change but the offset
695 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
696 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
699 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
700 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
703 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
704 indicating the CFA register has changed to <register> but the
705 offset has not changed. */
706 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
707 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
711 else if (loc.indirect == 0)
713 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
714 indicating the CFA register has changed to <register> with
715 the specified offset. */
716 cfi->dw_cfi_opc = DW_CFA_def_cfa;
717 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
718 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
722 /* Construct a DW_CFA_def_cfa_expression instruction to
723 calculate the CFA using a full location expression since no
724 register-offset pair is available. */
725 struct dw_loc_descr_struct *loc_list;
727 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
728 loc_list = build_cfa_loc (&loc);
729 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
732 add_fde_cfi (label, cfi);
735 /* Add the CFI for saving a register. REG is the CFA column number.
736 LABEL is passed to add_fde_cfi.
737 If SREG is -1, the register is saved at OFFSET from the CFA;
738 otherwise it is saved in SREG. */
741 reg_save (label, reg, sreg, offset)
747 dw_cfi_ref cfi = new_cfi ();
749 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
751 /* The following comparison is correct. -1 is used to indicate that
752 the value isn't a register number. */
753 if (sreg == (unsigned int) -1)
756 /* The register number won't fit in 6 bits, so we have to use
758 cfi->dw_cfi_opc = DW_CFA_offset_extended;
760 cfi->dw_cfi_opc = DW_CFA_offset;
762 #ifdef ENABLE_CHECKING
764 /* If we get an offset that is not a multiple of
765 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
766 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
768 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
770 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
774 offset /= DWARF_CIE_DATA_ALIGNMENT;
777 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
781 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
783 else if (sreg == reg)
784 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
788 cfi->dw_cfi_opc = DW_CFA_register;
789 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
792 add_fde_cfi (label, cfi);
795 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
796 This CFI tells the unwinder that it needs to restore the window registers
797 from the previous frame's window save area.
799 ??? Perhaps we should note in the CIE where windows are saved (instead of
800 assuming 0(cfa)) and what registers are in the window. */
803 dwarf2out_window_save (label)
806 dw_cfi_ref cfi = new_cfi ();
808 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
809 add_fde_cfi (label, cfi);
812 /* Add a CFI to update the running total of the size of arguments
813 pushed onto the stack. */
816 dwarf2out_args_size (label, size)
822 if (size == old_args_size)
825 old_args_size = size;
828 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
829 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
830 add_fde_cfi (label, cfi);
833 /* Entry point for saving a register to the stack. REG is the GCC register
834 number. LABEL and OFFSET are passed to reg_save. */
837 dwarf2out_reg_save (label, reg, offset)
842 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
845 /* Entry point for saving the return address in the stack.
846 LABEL and OFFSET are passed to reg_save. */
849 dwarf2out_return_save (label, offset)
853 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
856 /* Entry point for saving the return address in a register.
857 LABEL and SREG are passed to reg_save. */
860 dwarf2out_return_reg (label, sreg)
864 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
867 /* Record the initial position of the return address. RTL is
868 INCOMING_RETURN_ADDR_RTX. */
871 initial_return_save (rtl)
874 unsigned int reg = (unsigned int) -1;
875 HOST_WIDE_INT offset = 0;
877 switch (GET_CODE (rtl))
880 /* RA is in a register. */
881 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
885 /* RA is on the stack. */
887 switch (GET_CODE (rtl))
890 if (REGNO (rtl) != STACK_POINTER_REGNUM)
896 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
898 offset = INTVAL (XEXP (rtl, 1));
902 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
904 offset = -INTVAL (XEXP (rtl, 1));
914 /* The return address is at some offset from any value we can
915 actually load. For instance, on the SPARC it is in %i7+8. Just
916 ignore the offset for now; it doesn't matter for unwinding frames. */
917 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
919 initial_return_save (XEXP (rtl, 0));
926 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
929 /* Given a SET, calculate the amount of stack adjustment it
933 stack_adjust_offset (pattern)
936 rtx src = SET_SRC (pattern);
937 rtx dest = SET_DEST (pattern);
938 HOST_WIDE_INT offset = 0;
941 if (dest == stack_pointer_rtx)
943 /* (set (reg sp) (plus (reg sp) (const_int))) */
944 code = GET_CODE (src);
945 if (! (code == PLUS || code == MINUS)
946 || XEXP (src, 0) != stack_pointer_rtx
947 || GET_CODE (XEXP (src, 1)) != CONST_INT)
950 offset = INTVAL (XEXP (src, 1));
952 else if (GET_CODE (dest) == MEM)
954 /* (set (mem (pre_dec (reg sp))) (foo)) */
955 src = XEXP (dest, 0);
956 code = GET_CODE (src);
958 if ((code != PRE_DEC && code != PRE_INC && code != PRE_MODIFY)
959 || XEXP (src, 0) != stack_pointer_rtx)
962 if (code == PRE_MODIFY)
964 rtx val = XEXP (XEXP (src, 1), 1);
966 /* We handle only adjustments by constant amount. */
967 if (GET_CODE (XEXP (src, 1)) != PLUS ||
968 GET_CODE (val) != CONST_INT)
971 offset = -INTVAL (val);
974 offset = GET_MODE_SIZE (GET_MODE (dest));
979 if (code == PLUS || code == PRE_INC)
985 /* Check INSN to see if it looks like a push or a stack adjustment, and
986 make a note of it if it does. EH uses this information to find out how
987 much extra space it needs to pop off the stack. */
990 dwarf2out_stack_adjust (insn)
993 HOST_WIDE_INT offset;
997 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
999 /* Extract the size of the args from the CALL rtx itself. */
1000 insn = PATTERN (insn);
1001 if (GET_CODE (insn) == PARALLEL)
1002 insn = XVECEXP (insn, 0, 0);
1003 if (GET_CODE (insn) == SET)
1004 insn = SET_SRC (insn);
1005 if (GET_CODE (insn) != CALL)
1008 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1012 /* If only calls can throw, and we have a frame pointer,
1013 save up adjustments until we see the CALL_INSN. */
1014 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1017 if (GET_CODE (insn) == BARRIER)
1019 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1020 the compiler will have already emitted a stack adjustment, but
1021 doesn't bother for calls to noreturn functions. */
1022 #ifdef STACK_GROWS_DOWNWARD
1023 offset = -args_size;
1028 else if (GET_CODE (PATTERN (insn)) == SET)
1029 offset = stack_adjust_offset (PATTERN (insn));
1030 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1031 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1033 /* There may be stack adjustments inside compound insns. Search
1035 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1036 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1037 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1045 if (cfa.reg == STACK_POINTER_REGNUM)
1046 cfa.offset += offset;
1048 #ifndef STACK_GROWS_DOWNWARD
1052 args_size += offset;
1056 label = dwarf2out_cfi_label ();
1057 def_cfa_1 (label, &cfa);
1058 dwarf2out_args_size (label, args_size);
1061 /* We delay emitting a register save until either (a) we reach the end
1062 of the prologue or (b) the register is clobbered. This clusters
1063 register saves so that there are fewer pc advances. */
1065 struct queued_reg_save
1067 struct queued_reg_save *next;
1072 static struct queued_reg_save *queued_reg_saves;
1073 static const char *last_reg_save_label;
1076 queue_reg_save (label, reg, offset)
1081 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1083 q->next = queued_reg_saves;
1085 q->cfa_offset = offset;
1086 queued_reg_saves = q;
1088 last_reg_save_label = label;
1092 flush_queued_reg_saves ()
1094 struct queued_reg_save *q, *next;
1096 for (q = queued_reg_saves; q ; q = next)
1098 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1103 queued_reg_saves = NULL;
1104 last_reg_save_label = NULL;
1108 clobbers_queued_reg_save (insn)
1111 struct queued_reg_save *q;
1113 for (q = queued_reg_saves; q ; q = q->next)
1114 if (modified_in_p (q->reg, insn))
1121 /* A temporary register holding an integral value used in adjusting SP
1122 or setting up the store_reg. The "offset" field holds the integer
1123 value, not an offset. */
1124 static dw_cfa_location cfa_temp;
1126 /* Record call frame debugging information for an expression EXPR,
1127 which either sets SP or FP (adjusting how we calculate the frame
1128 address) or saves a register to the stack. LABEL indicates the
1131 This function encodes a state machine mapping rtxes to actions on
1132 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1133 users need not read the source code.
1135 The High-Level Picture
1137 Changes in the register we use to calculate the CFA: Currently we
1138 assume that if you copy the CFA register into another register, we
1139 should take the other one as the new CFA register; this seems to
1140 work pretty well. If it's wrong for some target, it's simple
1141 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1143 Changes in the register we use for saving registers to the stack:
1144 This is usually SP, but not always. Again, we deduce that if you
1145 copy SP into another register (and SP is not the CFA register),
1146 then the new register is the one we will be using for register
1147 saves. This also seems to work.
1149 Register saves: There's not much guesswork about this one; if
1150 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1151 register save, and the register used to calculate the destination
1152 had better be the one we think we're using for this purpose.
1154 Except: If the register being saved is the CFA register, and the
1155 offset is non-zero, we are saving the CFA, so we assume we have to
1156 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1157 the intent is to save the value of SP from the previous frame.
1159 Invariants / Summaries of Rules
1161 cfa current rule for calculating the CFA. It usually
1162 consists of a register and an offset.
1163 cfa_store register used by prologue code to save things to the stack
1164 cfa_store.offset is the offset from the value of
1165 cfa_store.reg to the actual CFA
1166 cfa_temp register holding an integral value. cfa_temp.offset
1167 stores the value, which will be used to adjust the
1168 stack pointer. cfa_temp is also used like cfa_store,
1169 to track stores to the stack via fp or a temp reg.
1171 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1172 with cfa.reg as the first operand changes the cfa.reg and its
1173 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1176 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1177 expression yielding a constant. This sets cfa_temp.reg
1178 and cfa_temp.offset.
1180 Rule 5: Create a new register cfa_store used to save items to the
1183 Rules 10-14: Save a register to the stack. Define offset as the
1184 difference of the original location and cfa_store's
1185 location (or cfa_temp's location if cfa_temp is used).
1189 "{a,b}" indicates a choice of a xor b.
1190 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1193 (set <reg1> <reg2>:cfa.reg)
1194 effects: cfa.reg = <reg1>
1195 cfa.offset unchanged
1196 cfa_temp.reg = <reg1>
1197 cfa_temp.offset = cfa.offset
1200 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1201 {<const_int>,<reg>:cfa_temp.reg}))
1202 effects: cfa.reg = sp if fp used
1203 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1204 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1205 if cfa_store.reg==sp
1208 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1209 effects: cfa.reg = fp
1210 cfa_offset += +/- <const_int>
1213 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1214 constraints: <reg1> != fp
1216 effects: cfa.reg = <reg1>
1217 cfa_temp.reg = <reg1>
1218 cfa_temp.offset = cfa.offset
1221 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1222 constraints: <reg1> != fp
1224 effects: cfa_store.reg = <reg1>
1225 cfa_store.offset = cfa.offset - cfa_temp.offset
1228 (set <reg> <const_int>)
1229 effects: cfa_temp.reg = <reg>
1230 cfa_temp.offset = <const_int>
1233 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1234 effects: cfa_temp.reg = <reg1>
1235 cfa_temp.offset |= <const_int>
1238 (set <reg> (high <exp>))
1242 (set <reg> (lo_sum <exp> <const_int>))
1243 effects: cfa_temp.reg = <reg>
1244 cfa_temp.offset = <const_int>
1247 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1248 effects: cfa_store.offset -= <const_int>
1249 cfa.offset = cfa_store.offset if cfa.reg == sp
1251 cfa.base_offset = -cfa_store.offset
1254 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1255 effects: cfa_store.offset += -/+ mode_size(mem)
1256 cfa.offset = cfa_store.offset if cfa.reg == sp
1258 cfa.base_offset = -cfa_store.offset
1261 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1264 effects: cfa.reg = <reg1>
1265 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1268 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1269 effects: cfa.reg = <reg1>
1270 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1273 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1274 effects: cfa.reg = <reg1>
1275 cfa.base_offset = -cfa_temp.offset
1276 cfa_temp.offset -= mode_size(mem) */
1279 dwarf2out_frame_debug_expr (expr, label)
1284 HOST_WIDE_INT offset;
1286 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1287 the PARALLEL independently. The first element is always processed if
1288 it is a SET. This is for backward compatibility. Other elements
1289 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1290 flag is set in them. */
1291 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1294 int limit = XVECLEN (expr, 0);
1296 for (par_index = 0; par_index < limit; par_index++)
1297 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1298 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1300 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1305 if (GET_CODE (expr) != SET)
1308 src = SET_SRC (expr);
1309 dest = SET_DEST (expr);
1311 switch (GET_CODE (dest))
1315 /* Update the CFA rule wrt SP or FP. Make sure src is
1316 relative to the current CFA register. */
1317 switch (GET_CODE (src))
1319 /* Setting FP from SP. */
1321 if (cfa.reg == (unsigned) REGNO (src))
1327 /* We used to require that dest be either SP or FP, but the
1328 ARM copies SP to a temporary register, and from there to
1329 FP. So we just rely on the backends to only set
1330 RTX_FRAME_RELATED_P on appropriate insns. */
1331 cfa.reg = REGNO (dest);
1332 cfa_temp.reg = cfa.reg;
1333 cfa_temp.offset = cfa.offset;
1339 if (dest == stack_pointer_rtx)
1343 switch (GET_CODE (XEXP (src, 1)))
1346 offset = INTVAL (XEXP (src, 1));
1349 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1351 offset = cfa_temp.offset;
1357 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1359 /* Restoring SP from FP in the epilogue. */
1360 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1362 cfa.reg = STACK_POINTER_REGNUM;
1364 else if (GET_CODE (src) == LO_SUM)
1365 /* Assume we've set the source reg of the LO_SUM from sp. */
1367 else if (XEXP (src, 0) != stack_pointer_rtx)
1370 if (GET_CODE (src) != MINUS)
1372 if (cfa.reg == STACK_POINTER_REGNUM)
1373 cfa.offset += offset;
1374 if (cfa_store.reg == STACK_POINTER_REGNUM)
1375 cfa_store.offset += offset;
1377 else if (dest == hard_frame_pointer_rtx)
1380 /* Either setting the FP from an offset of the SP,
1381 or adjusting the FP */
1382 if (! frame_pointer_needed)
1385 if (GET_CODE (XEXP (src, 0)) == REG
1386 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1387 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1389 offset = INTVAL (XEXP (src, 1));
1390 if (GET_CODE (src) != MINUS)
1392 cfa.offset += offset;
1393 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1400 if (GET_CODE (src) == MINUS)
1404 if (GET_CODE (XEXP (src, 0)) == REG
1405 && REGNO (XEXP (src, 0)) == cfa.reg
1406 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1408 /* Setting a temporary CFA register that will be copied
1409 into the FP later on. */
1410 offset = - INTVAL (XEXP (src, 1));
1411 cfa.offset += offset;
1412 cfa.reg = REGNO (dest);
1413 /* Or used to save regs to the stack. */
1414 cfa_temp.reg = cfa.reg;
1415 cfa_temp.offset = cfa.offset;
1419 else if (GET_CODE (XEXP (src, 0)) == REG
1420 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1421 && XEXP (src, 1) == stack_pointer_rtx)
1423 /* Setting a scratch register that we will use instead
1424 of SP for saving registers to the stack. */
1425 if (cfa.reg != STACK_POINTER_REGNUM)
1427 cfa_store.reg = REGNO (dest);
1428 cfa_store.offset = cfa.offset - cfa_temp.offset;
1432 else if (GET_CODE (src) == LO_SUM
1433 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1435 cfa_temp.reg = REGNO (dest);
1436 cfa_temp.offset = INTVAL (XEXP (src, 1));
1445 cfa_temp.reg = REGNO (dest);
1446 cfa_temp.offset = INTVAL (src);
1451 if (GET_CODE (XEXP (src, 0)) != REG
1452 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1453 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1456 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1457 cfa_temp.reg = REGNO (dest);
1458 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1461 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1462 which will fill in all of the bits. */
1471 def_cfa_1 (label, &cfa);
1475 if (GET_CODE (src) != REG)
1478 /* Saving a register to the stack. Make sure dest is relative to the
1480 switch (GET_CODE (XEXP (dest, 0)))
1485 /* We can't handle variable size modifications. */
1486 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1488 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1490 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1491 || cfa_store.reg != STACK_POINTER_REGNUM)
1494 cfa_store.offset += offset;
1495 if (cfa.reg == STACK_POINTER_REGNUM)
1496 cfa.offset = cfa_store.offset;
1498 offset = -cfa_store.offset;
1504 offset = GET_MODE_SIZE (GET_MODE (dest));
1505 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1508 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1509 || cfa_store.reg != STACK_POINTER_REGNUM)
1512 cfa_store.offset += offset;
1513 if (cfa.reg == STACK_POINTER_REGNUM)
1514 cfa.offset = cfa_store.offset;
1516 offset = -cfa_store.offset;
1520 /* With an offset. */
1524 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1526 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1527 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1530 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1531 offset -= cfa_store.offset;
1532 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1533 offset -= cfa_temp.offset;
1539 /* Without an offset. */
1541 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1542 offset = -cfa_store.offset;
1543 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1544 offset = -cfa_temp.offset;
1551 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1553 offset = -cfa_temp.offset;
1554 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1561 if (REGNO (src) != STACK_POINTER_REGNUM
1562 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1563 && (unsigned) REGNO (src) == cfa.reg)
1565 /* We're storing the current CFA reg into the stack. */
1567 if (cfa.offset == 0)
1569 /* If the source register is exactly the CFA, assume
1570 we're saving SP like any other register; this happens
1572 def_cfa_1 (label, &cfa);
1573 queue_reg_save (label, stack_pointer_rtx, offset);
1578 /* Otherwise, we'll need to look in the stack to
1579 calculate the CFA. */
1580 rtx x = XEXP (dest, 0);
1582 if (GET_CODE (x) != REG)
1584 if (GET_CODE (x) != REG)
1587 cfa.reg = REGNO (x);
1588 cfa.base_offset = offset;
1590 def_cfa_1 (label, &cfa);
1595 def_cfa_1 (label, &cfa);
1596 queue_reg_save (label, src, offset);
1604 /* Record call frame debugging information for INSN, which either
1605 sets SP or FP (adjusting how we calculate the frame address) or saves a
1606 register to the stack. If INSN is NULL_RTX, initialize our state. */
1609 dwarf2out_frame_debug (insn)
1615 if (insn == NULL_RTX)
1617 /* Flush any queued register saves. */
1618 flush_queued_reg_saves ();
1620 /* Set up state for generating call frame debug info. */
1622 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1625 cfa.reg = STACK_POINTER_REGNUM;
1628 cfa_temp.offset = 0;
1632 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1633 flush_queued_reg_saves ();
1635 if (! RTX_FRAME_RELATED_P (insn))
1637 if (!ACCUMULATE_OUTGOING_ARGS)
1638 dwarf2out_stack_adjust (insn);
1643 label = dwarf2out_cfi_label ();
1644 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1646 insn = XEXP (src, 0);
1648 insn = PATTERN (insn);
1650 dwarf2out_frame_debug_expr (insn, label);
1653 /* Output a Call Frame Information opcode and its operand(s). */
1656 output_cfi (cfi, fde, for_eh)
1661 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1662 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1663 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1664 "DW_CFA_advance_loc 0x%lx",
1665 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1666 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1668 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1669 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1670 "DW_CFA_offset, column 0x%lx",
1671 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1672 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1674 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1675 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1676 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1677 "DW_CFA_restore, column 0x%lx",
1678 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1681 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1682 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1684 switch (cfi->dw_cfi_opc)
1686 case DW_CFA_set_loc:
1688 dw2_asm_output_encoded_addr_rtx (
1689 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1690 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1693 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1694 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1697 case DW_CFA_advance_loc1:
1698 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1699 fde->dw_fde_current_label, NULL);
1700 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1703 case DW_CFA_advance_loc2:
1704 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1705 fde->dw_fde_current_label, NULL);
1706 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1709 case DW_CFA_advance_loc4:
1710 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1711 fde->dw_fde_current_label, NULL);
1712 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1715 case DW_CFA_MIPS_advance_loc8:
1716 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1717 fde->dw_fde_current_label, NULL);
1718 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1721 case DW_CFA_offset_extended:
1722 case DW_CFA_GNU_negative_offset_extended:
1723 case DW_CFA_def_cfa:
1724 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1726 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1729 case DW_CFA_restore_extended:
1730 case DW_CFA_undefined:
1731 case DW_CFA_same_value:
1732 case DW_CFA_def_cfa_register:
1733 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1737 case DW_CFA_register:
1738 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1740 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1744 case DW_CFA_def_cfa_offset:
1745 case DW_CFA_GNU_args_size:
1746 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1749 case DW_CFA_GNU_window_save:
1752 case DW_CFA_def_cfa_expression:
1753 output_cfa_loc (cfi);
1762 /* Output the call frame information used to used to record information
1763 that relates to calculating the frame pointer, and records the
1764 location of saved registers. */
1767 output_call_frame_info (for_eh)
1773 char l1[20], l2[20], section_start_label[20];
1774 int any_lsda_needed = 0;
1775 char augmentation[6];
1776 int augmentation_size;
1777 int fde_encoding = DW_EH_PE_absptr;
1778 int per_encoding = DW_EH_PE_absptr;
1779 int lsda_encoding = DW_EH_PE_absptr;
1781 /* If we don't have any functions we'll want to unwind out of, don't emit any
1782 EH unwind information. */
1785 int any_eh_needed = flag_asynchronous_unwind_tables;
1787 for (i = 0; i < fde_table_in_use; i++)
1788 if (fde_table[i].uses_eh_lsda)
1789 any_eh_needed = any_lsda_needed = 1;
1790 else if (! fde_table[i].nothrow)
1793 if (! any_eh_needed)
1797 /* We're going to be generating comments, so turn on app. */
1802 (*targetm.asm_out.eh_frame_section) ();
1804 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1806 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1807 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1809 /* Output the CIE. */
1810 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1811 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1812 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1813 "Length of Common Information Entry");
1814 ASM_OUTPUT_LABEL (asm_out_file, l1);
1816 /* Now that the CIE pointer is PC-relative for EH,
1817 use 0 to identify the CIE. */
1818 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1819 (for_eh ? 0 : DW_CIE_ID),
1820 "CIE Identifier Tag");
1822 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1824 augmentation[0] = 0;
1825 augmentation_size = 0;
1831 z Indicates that a uleb128 is present to size the
1832 augmentation section.
1833 L Indicates the encoding (and thus presence) of
1834 an LSDA pointer in the FDE augmentation.
1835 R Indicates a non-default pointer encoding for
1837 P Indicates the presence of an encoding + language
1838 personality routine in the CIE augmentation. */
1840 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1841 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1842 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1844 p = augmentation + 1;
1845 if (eh_personality_libfunc)
1848 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1850 if (any_lsda_needed)
1853 augmentation_size += 1;
1855 if (fde_encoding != DW_EH_PE_absptr)
1858 augmentation_size += 1;
1860 if (p > augmentation + 1)
1862 augmentation[0] = 'z';
1866 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1867 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1869 int offset = ( 4 /* Length */
1871 + 1 /* CIE version */
1872 + strlen (augmentation) + 1 /* Augmentation */
1873 + size_of_uleb128 (1) /* Code alignment */
1874 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1876 + 1 /* Augmentation size */
1877 + 1 /* Personality encoding */ );
1878 int pad = -offset & (PTR_SIZE - 1);
1880 augmentation_size += pad;
1882 /* Augmentations should be small, so there's scarce need to
1883 iterate for a solution. Die if we exceed one uleb128 byte. */
1884 if (size_of_uleb128 (augmentation_size) != 1)
1889 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1890 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1891 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1892 "CIE Data Alignment Factor");
1893 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1895 if (augmentation[0])
1897 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1898 if (eh_personality_libfunc)
1900 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1901 eh_data_format_name (per_encoding));
1902 dw2_asm_output_encoded_addr_rtx (per_encoding,
1903 eh_personality_libfunc, NULL);
1906 if (any_lsda_needed)
1907 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1908 eh_data_format_name (lsda_encoding));
1910 if (fde_encoding != DW_EH_PE_absptr)
1911 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1912 eh_data_format_name (fde_encoding));
1915 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1916 output_cfi (cfi, NULL, for_eh);
1918 /* Pad the CIE out to an address sized boundary. */
1919 ASM_OUTPUT_ALIGN (asm_out_file,
1920 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1921 ASM_OUTPUT_LABEL (asm_out_file, l2);
1923 /* Loop through all of the FDE's. */
1924 for (i = 0; i < fde_table_in_use; i++)
1926 fde = &fde_table[i];
1928 /* Don't emit EH unwind info for leaf functions that don't need it. */
1929 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1932 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1933 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1934 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1935 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1937 ASM_OUTPUT_LABEL (asm_out_file, l1);
1940 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
1942 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
1947 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1948 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1949 "FDE initial location");
1950 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1951 fde->dw_fde_end, fde->dw_fde_begin,
1952 "FDE address range");
1956 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1957 "FDE initial location");
1958 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1959 fde->dw_fde_end, fde->dw_fde_begin,
1960 "FDE address range");
1963 if (augmentation[0])
1965 if (any_lsda_needed)
1967 int size = size_of_encoded_value (lsda_encoding);
1969 if (lsda_encoding == DW_EH_PE_aligned)
1971 int offset = ( 4 /* Length */
1972 + 4 /* CIE offset */
1973 + 2 * size_of_encoded_value (fde_encoding)
1974 + 1 /* Augmentation size */ );
1975 int pad = -offset & (PTR_SIZE - 1);
1978 if (size_of_uleb128 (size) != 1)
1982 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1984 if (fde->uses_eh_lsda)
1986 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
1987 fde->funcdef_number);
1988 dw2_asm_output_encoded_addr_rtx (
1989 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
1990 "Language Specific Data Area");
1994 if (lsda_encoding == DW_EH_PE_aligned)
1995 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1997 (size_of_encoded_value (lsda_encoding), 0,
1998 "Language Specific Data Area (none)");
2002 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2005 /* Loop through the Call Frame Instructions associated with
2007 fde->dw_fde_current_label = fde->dw_fde_begin;
2008 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2009 output_cfi (cfi, fde, for_eh);
2011 /* Pad the FDE out to an address sized boundary. */
2012 ASM_OUTPUT_ALIGN (asm_out_file,
2013 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2014 ASM_OUTPUT_LABEL (asm_out_file, l2);
2017 #ifndef EH_FRAME_SECTION_NAME
2019 dw2_asm_output_data (4, 0, "End of Table");
2021 #ifdef MIPS_DEBUGGING_INFO
2022 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2023 get a value of 0. Putting .align 0 after the label fixes it. */
2024 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2027 /* Turn off app to make assembly quicker. */
2032 /* Output a marker (i.e. a label) for the beginning of a function, before
2036 dwarf2out_begin_prologue (line, file)
2037 unsigned int line ATTRIBUTE_UNUSED;
2038 const char *file ATTRIBUTE_UNUSED;
2040 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2043 current_function_func_begin_label = 0;
2045 #ifdef IA64_UNWIND_INFO
2046 /* ??? current_function_func_begin_label is also used by except.c
2047 for call-site information. We must emit this label if it might
2049 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2050 && ! dwarf2out_do_frame ())
2053 if (! dwarf2out_do_frame ())
2057 current_funcdef_number++;
2058 function_section (current_function_decl);
2059 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2060 current_funcdef_number);
2061 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2062 current_funcdef_number);
2063 current_function_func_begin_label = get_identifier (label);
2065 #ifdef IA64_UNWIND_INFO
2066 /* We can elide the fde allocation if we're not emitting debug info. */
2067 if (! dwarf2out_do_frame ())
2071 /* Expand the fde table if necessary. */
2072 if (fde_table_in_use == fde_table_allocated)
2074 fde_table_allocated += FDE_TABLE_INCREMENT;
2076 = (dw_fde_ref) xrealloc (fde_table,
2077 fde_table_allocated * sizeof (dw_fde_node));
2080 /* Record the FDE associated with this function. */
2081 current_funcdef_fde = fde_table_in_use;
2083 /* Add the new FDE at the end of the fde_table. */
2084 fde = &fde_table[fde_table_in_use++];
2085 fde->dw_fde_begin = xstrdup (label);
2086 fde->dw_fde_current_label = NULL;
2087 fde->dw_fde_end = NULL;
2088 fde->dw_fde_cfi = NULL;
2089 fde->funcdef_number = current_funcdef_number;
2090 fde->nothrow = current_function_nothrow;
2091 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2093 args_size = old_args_size = 0;
2095 /* We only want to output line number information for the genuine dwarf2
2096 prologue case, not the eh frame case. */
2097 #ifdef DWARF2_DEBUGGING_INFO
2099 dwarf2out_source_line (line, file);
2103 /* Output a marker (i.e. a label) for the absolute end of the generated code
2104 for a function definition. This gets called *after* the epilogue code has
2108 dwarf2out_end_epilogue ()
2111 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2113 /* Output a label to mark the endpoint of the code generated for this
2115 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2116 ASM_OUTPUT_LABEL (asm_out_file, label);
2117 fde = &fde_table[fde_table_in_use - 1];
2118 fde->dw_fde_end = xstrdup (label);
2122 dwarf2out_frame_init ()
2124 /* Allocate the initial hunk of the fde_table. */
2125 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2126 fde_table_allocated = FDE_TABLE_INCREMENT;
2127 fde_table_in_use = 0;
2129 /* Generate the CFA instructions common to all FDE's. Do it now for the
2130 sake of lookup_cfa. */
2132 #ifdef DWARF2_UNWIND_INFO
2133 /* On entry, the Canonical Frame Address is at SP. */
2134 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2135 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2140 dwarf2out_frame_finish ()
2142 /* Output call frame information. */
2143 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2144 output_call_frame_info (0);
2146 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2147 output_call_frame_info (1);
2150 /* And now, the subset of the debugging information support code necessary
2151 for emitting location expressions. */
2153 typedef struct dw_val_struct *dw_val_ref;
2154 typedef struct die_struct *dw_die_ref;
2155 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2156 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2158 /* Each DIE may have a series of attribute/value pairs. Values
2159 can take on several forms. The forms that are used in this
2160 implementation are listed below. */
2165 dw_val_class_offset,
2167 dw_val_class_loc_list,
2168 dw_val_class_range_list,
2170 dw_val_class_unsigned_const,
2171 dw_val_class_long_long,
2174 dw_val_class_die_ref,
2175 dw_val_class_fde_ref,
2176 dw_val_class_lbl_id,
2177 dw_val_class_lbl_offset,
2182 /* Describe a double word constant value. */
2183 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2185 typedef struct dw_long_long_struct
2192 /* Describe a floating point constant value. */
2194 typedef struct dw_fp_struct
2201 /* The dw_val_node describes an attribute's value, as it is
2202 represented internally. */
2204 typedef struct dw_val_struct
2206 dw_val_class val_class;
2210 long unsigned val_offset;
2211 dw_loc_list_ref val_loc_list;
2212 dw_loc_descr_ref val_loc;
2214 long unsigned val_unsigned;
2215 dw_long_long_const val_long_long;
2216 dw_float_const val_float;
2222 unsigned val_fde_index;
2223 struct indirect_string_node *val_str;
2225 unsigned char val_flag;
2231 /* Locations in memory are described using a sequence of stack machine
2234 typedef struct dw_loc_descr_struct
2236 dw_loc_descr_ref dw_loc_next;
2237 enum dwarf_location_atom dw_loc_opc;
2238 dw_val_node dw_loc_oprnd1;
2239 dw_val_node dw_loc_oprnd2;
2244 /* Location lists are ranges + location descriptions for that range,
2245 so you can track variables that are in different places over
2246 their entire life. */
2247 typedef struct dw_loc_list_struct
2249 dw_loc_list_ref dw_loc_next;
2250 const char *begin; /* Label for begin address of range */
2251 const char *end; /* Label for end address of range */
2252 char *ll_symbol; /* Label for beginning of location list.
2253 Only on head of list */
2254 const char *section; /* Section this loclist is relative to */
2255 dw_loc_descr_ref expr;
2258 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2259 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2262 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2264 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2265 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2266 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2267 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2269 /* Convert a DWARF stack opcode into its string name. */
2272 dwarf_stack_op_name (op)
2278 return "DW_OP_addr";
2280 return "DW_OP_deref";
2282 return "DW_OP_const1u";
2284 return "DW_OP_const1s";
2286 return "DW_OP_const2u";
2288 return "DW_OP_const2s";
2290 return "DW_OP_const4u";
2292 return "DW_OP_const4s";
2294 return "DW_OP_const8u";
2296 return "DW_OP_const8s";
2298 return "DW_OP_constu";
2300 return "DW_OP_consts";
2304 return "DW_OP_drop";
2306 return "DW_OP_over";
2308 return "DW_OP_pick";
2310 return "DW_OP_swap";
2314 return "DW_OP_xderef";
2322 return "DW_OP_minus";
2334 return "DW_OP_plus";
2335 case DW_OP_plus_uconst:
2336 return "DW_OP_plus_uconst";
2342 return "DW_OP_shra";
2360 return "DW_OP_skip";
2362 return "DW_OP_lit0";
2364 return "DW_OP_lit1";
2366 return "DW_OP_lit2";
2368 return "DW_OP_lit3";
2370 return "DW_OP_lit4";
2372 return "DW_OP_lit5";
2374 return "DW_OP_lit6";
2376 return "DW_OP_lit7";
2378 return "DW_OP_lit8";
2380 return "DW_OP_lit9";
2382 return "DW_OP_lit10";
2384 return "DW_OP_lit11";
2386 return "DW_OP_lit12";
2388 return "DW_OP_lit13";
2390 return "DW_OP_lit14";
2392 return "DW_OP_lit15";
2394 return "DW_OP_lit16";
2396 return "DW_OP_lit17";
2398 return "DW_OP_lit18";
2400 return "DW_OP_lit19";
2402 return "DW_OP_lit20";
2404 return "DW_OP_lit21";
2406 return "DW_OP_lit22";
2408 return "DW_OP_lit23";
2410 return "DW_OP_lit24";
2412 return "DW_OP_lit25";
2414 return "DW_OP_lit26";
2416 return "DW_OP_lit27";
2418 return "DW_OP_lit28";
2420 return "DW_OP_lit29";
2422 return "DW_OP_lit30";
2424 return "DW_OP_lit31";
2426 return "DW_OP_reg0";
2428 return "DW_OP_reg1";
2430 return "DW_OP_reg2";
2432 return "DW_OP_reg3";
2434 return "DW_OP_reg4";
2436 return "DW_OP_reg5";
2438 return "DW_OP_reg6";
2440 return "DW_OP_reg7";
2442 return "DW_OP_reg8";
2444 return "DW_OP_reg9";
2446 return "DW_OP_reg10";
2448 return "DW_OP_reg11";
2450 return "DW_OP_reg12";
2452 return "DW_OP_reg13";
2454 return "DW_OP_reg14";
2456 return "DW_OP_reg15";
2458 return "DW_OP_reg16";
2460 return "DW_OP_reg17";
2462 return "DW_OP_reg18";
2464 return "DW_OP_reg19";
2466 return "DW_OP_reg20";
2468 return "DW_OP_reg21";
2470 return "DW_OP_reg22";
2472 return "DW_OP_reg23";
2474 return "DW_OP_reg24";
2476 return "DW_OP_reg25";
2478 return "DW_OP_reg26";
2480 return "DW_OP_reg27";
2482 return "DW_OP_reg28";
2484 return "DW_OP_reg29";
2486 return "DW_OP_reg30";
2488 return "DW_OP_reg31";
2490 return "DW_OP_breg0";
2492 return "DW_OP_breg1";
2494 return "DW_OP_breg2";
2496 return "DW_OP_breg3";
2498 return "DW_OP_breg4";
2500 return "DW_OP_breg5";
2502 return "DW_OP_breg6";
2504 return "DW_OP_breg7";
2506 return "DW_OP_breg8";
2508 return "DW_OP_breg9";
2510 return "DW_OP_breg10";
2512 return "DW_OP_breg11";
2514 return "DW_OP_breg12";
2516 return "DW_OP_breg13";
2518 return "DW_OP_breg14";
2520 return "DW_OP_breg15";
2522 return "DW_OP_breg16";
2524 return "DW_OP_breg17";
2526 return "DW_OP_breg18";
2528 return "DW_OP_breg19";
2530 return "DW_OP_breg20";
2532 return "DW_OP_breg21";
2534 return "DW_OP_breg22";
2536 return "DW_OP_breg23";
2538 return "DW_OP_breg24";
2540 return "DW_OP_breg25";
2542 return "DW_OP_breg26";
2544 return "DW_OP_breg27";
2546 return "DW_OP_breg28";
2548 return "DW_OP_breg29";
2550 return "DW_OP_breg30";
2552 return "DW_OP_breg31";
2554 return "DW_OP_regx";
2556 return "DW_OP_fbreg";
2558 return "DW_OP_bregx";
2560 return "DW_OP_piece";
2561 case DW_OP_deref_size:
2562 return "DW_OP_deref_size";
2563 case DW_OP_xderef_size:
2564 return "DW_OP_xderef_size";
2568 return "OP_<unknown>";
2572 /* Return a pointer to a newly allocated location description. Location
2573 descriptions are simple expression terms that can be strung
2574 together to form more complicated location (address) descriptions. */
2576 static inline dw_loc_descr_ref
2577 new_loc_descr (op, oprnd1, oprnd2)
2578 enum dwarf_location_atom op;
2579 unsigned long oprnd1;
2580 unsigned long oprnd2;
2582 /* Use xcalloc here so we clear out all of the long_long constant in
2584 dw_loc_descr_ref descr
2585 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2587 descr->dw_loc_opc = op;
2588 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2589 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2590 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2591 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2597 /* Add a location description term to a location description expression. */
2600 add_loc_descr (list_head, descr)
2601 dw_loc_descr_ref *list_head;
2602 dw_loc_descr_ref descr;
2604 dw_loc_descr_ref *d;
2606 /* Find the end of the chain. */
2607 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2613 /* Return the size of a location descriptor. */
2615 static unsigned long
2616 size_of_loc_descr (loc)
2617 dw_loc_descr_ref loc;
2619 unsigned long size = 1;
2621 switch (loc->dw_loc_opc)
2624 size += DWARF2_ADDR_SIZE;
2643 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2646 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2651 case DW_OP_plus_uconst:
2652 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2690 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2693 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2696 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2699 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2700 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2703 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2705 case DW_OP_deref_size:
2706 case DW_OP_xderef_size:
2716 /* Return the size of a series of location descriptors. */
2718 static unsigned long
2720 dw_loc_descr_ref loc;
2724 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2726 loc->dw_loc_addr = size;
2727 size += size_of_loc_descr (loc);
2733 /* Output location description stack opcode's operands (if any). */
2736 output_loc_operands (loc)
2737 dw_loc_descr_ref loc;
2739 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2740 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2742 switch (loc->dw_loc_opc)
2744 #ifdef DWARF2_DEBUGGING_INFO
2746 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2750 dw2_asm_output_data (2, val1->v.val_int, NULL);
2754 dw2_asm_output_data (4, val1->v.val_int, NULL);
2758 if (HOST_BITS_PER_LONG < 64)
2760 dw2_asm_output_data (8, val1->v.val_int, NULL);
2767 if (val1->val_class == dw_val_class_loc)
2768 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2772 dw2_asm_output_data (2, offset, NULL);
2785 /* We currently don't make any attempt to make sure these are
2786 aligned properly like we do for the main unwind info, so
2787 don't support emitting things larger than a byte if we're
2788 only doing unwinding. */
2793 dw2_asm_output_data (1, val1->v.val_int, NULL);
2796 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2799 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2802 dw2_asm_output_data (1, val1->v.val_int, NULL);
2804 case DW_OP_plus_uconst:
2805 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2839 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2842 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2845 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2848 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2849 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2852 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2854 case DW_OP_deref_size:
2855 case DW_OP_xderef_size:
2856 dw2_asm_output_data (1, val1->v.val_int, NULL);
2859 /* Other codes have no operands. */
2864 /* Output a sequence of location operations. */
2867 output_loc_sequence (loc)
2868 dw_loc_descr_ref loc;
2870 for (; loc != NULL; loc = loc->dw_loc_next)
2872 /* Output the opcode. */
2873 dw2_asm_output_data (1, loc->dw_loc_opc,
2874 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2876 /* Output the operand(s) (if any). */
2877 output_loc_operands (loc);
2881 /* This routine will generate the correct assembly data for a location
2882 description based on a cfi entry with a complex address. */
2885 output_cfa_loc (cfi)
2888 dw_loc_descr_ref loc;
2891 /* Output the size of the block. */
2892 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2893 size = size_of_locs (loc);
2894 dw2_asm_output_data_uleb128 (size, NULL);
2896 /* Now output the operations themselves. */
2897 output_loc_sequence (loc);
2900 /* This function builds a dwarf location descriptor sequence from
2901 a dw_cfa_location. */
2903 static struct dw_loc_descr_struct *
2905 dw_cfa_location *cfa;
2907 struct dw_loc_descr_struct *head, *tmp;
2909 if (cfa->indirect == 0)
2912 if (cfa->base_offset)
2915 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2917 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2919 else if (cfa->reg <= 31)
2920 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2922 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2924 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2925 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2926 add_loc_descr (&head, tmp);
2927 if (cfa->offset != 0)
2929 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2930 add_loc_descr (&head, tmp);
2936 /* This function fills in aa dw_cfa_location structure from a dwarf location
2937 descriptor sequence. */
2940 get_cfa_from_loc_descr (cfa, loc)
2941 dw_cfa_location *cfa;
2942 struct dw_loc_descr_struct *loc;
2944 struct dw_loc_descr_struct *ptr;
2946 cfa->base_offset = 0;
2950 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2952 enum dwarf_location_atom op = ptr->dw_loc_opc;
2988 cfa->reg = op - DW_OP_reg0;
2991 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3025 cfa->reg = op - DW_OP_breg0;
3026 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3029 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3030 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3035 case DW_OP_plus_uconst:
3036 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3039 internal_error ("DW_LOC_OP %s not implemented\n",
3040 dwarf_stack_op_name (ptr->dw_loc_opc));
3044 #endif /* .debug_frame support */
3046 /* And now, the support for symbolic debugging information. */
3047 #ifdef DWARF2_DEBUGGING_INFO
3049 static void dwarf2out_init PARAMS ((const char *));
3050 static void dwarf2out_finish PARAMS ((const char *));
3051 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3052 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3053 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3054 static void dwarf2out_end_source_file PARAMS ((unsigned));
3055 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3056 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3057 static bool dwarf2out_ignore_block PARAMS ((tree));
3058 static void dwarf2out_global_decl PARAMS ((tree));
3059 static void dwarf2out_abstract_function PARAMS ((tree));
3061 /* The debug hooks structure. */
3063 struct gcc_debug_hooks dwarf2_debug_hooks =
3069 dwarf2out_start_source_file,
3070 dwarf2out_end_source_file,
3071 dwarf2out_begin_block,
3072 dwarf2out_end_block,
3073 dwarf2out_ignore_block,
3074 dwarf2out_source_line,
3075 dwarf2out_begin_prologue,
3076 debug_nothing_int, /* end_prologue */
3077 dwarf2out_end_epilogue,
3078 debug_nothing_tree, /* begin_function */
3079 debug_nothing_int, /* end_function */
3080 dwarf2out_decl, /* function_decl */
3081 dwarf2out_global_decl,
3082 debug_nothing_tree, /* deferred_inline_function */
3083 /* The DWARF 2 backend tries to reduce debugging bloat by not
3084 emitting the abstract description of inline functions until
3085 something tries to reference them. */
3086 dwarf2out_abstract_function, /* outlining_inline_function */
3087 debug_nothing_rtx /* label */
3090 /* NOTE: In the comments in this file, many references are made to
3091 "Debugging Information Entries". This term is abbreviated as `DIE'
3092 throughout the remainder of this file. */
3094 /* An internal representation of the DWARF output is built, and then
3095 walked to generate the DWARF debugging info. The walk of the internal
3096 representation is done after the entire program has been compiled.
3097 The types below are used to describe the internal representation. */
3099 /* Various DIE's use offsets relative to the beginning of the
3100 .debug_info section to refer to each other. */
3102 typedef long int dw_offset;
3104 /* Define typedefs here to avoid circular dependencies. */
3106 typedef struct dw_attr_struct *dw_attr_ref;
3107 typedef struct dw_line_info_struct *dw_line_info_ref;
3108 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3109 typedef struct pubname_struct *pubname_ref;
3110 typedef struct dw_ranges_struct *dw_ranges_ref;
3112 /* Each entry in the line_info_table maintains the file and
3113 line number associated with the label generated for that
3114 entry. The label gives the PC value associated with
3115 the line number entry. */
3117 typedef struct dw_line_info_struct
3119 unsigned long dw_file_num;
3120 unsigned long dw_line_num;
3124 /* Line information for functions in separate sections; each one gets its
3126 typedef struct dw_separate_line_info_struct
3128 unsigned long dw_file_num;
3129 unsigned long dw_line_num;
3130 unsigned long function;
3132 dw_separate_line_info_entry;
3134 /* Each DIE attribute has a field specifying the attribute kind,
3135 a link to the next attribute in the chain, and an attribute value.
3136 Attributes are typically linked below the DIE they modify. */
3138 typedef struct dw_attr_struct
3140 enum dwarf_attribute dw_attr;
3141 dw_attr_ref dw_attr_next;
3142 dw_val_node dw_attr_val;
3146 /* The Debugging Information Entry (DIE) structure */
3148 typedef struct die_struct
3150 enum dwarf_tag die_tag;
3152 dw_attr_ref die_attr;
3153 dw_die_ref die_parent;
3154 dw_die_ref die_child;
3156 dw_offset die_offset;
3157 unsigned long die_abbrev;
3162 /* The pubname structure */
3164 typedef struct pubname_struct
3171 struct dw_ranges_struct
3176 /* The limbo die list structure. */
3177 typedef struct limbo_die_struct
3181 struct limbo_die_struct *next;
3185 /* How to start an assembler comment. */
3186 #ifndef ASM_COMMENT_START
3187 #define ASM_COMMENT_START ";#"
3190 /* Define a macro which returns non-zero for a TYPE_DECL which was
3191 implicitly generated for a tagged type.
3193 Note that unlike the gcc front end (which generates a NULL named
3194 TYPE_DECL node for each complete tagged type, each array type, and
3195 each function type node created) the g++ front end generates a
3196 _named_ TYPE_DECL node for each tagged type node created.
3197 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3198 generate a DW_TAG_typedef DIE for them. */
3200 #define TYPE_DECL_IS_STUB(decl) \
3201 (DECL_NAME (decl) == NULL_TREE \
3202 || (DECL_ARTIFICIAL (decl) \
3203 && is_tagged_type (TREE_TYPE (decl)) \
3204 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3205 /* This is necessary for stub decls that \
3206 appear in nested inline functions. */ \
3207 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3208 && (decl_ultimate_origin (decl) \
3209 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3211 /* Information concerning the compilation unit's programming
3212 language, and compiler version. */
3214 extern int flag_traditional;
3216 /* Fixed size portion of the DWARF compilation unit header. */
3217 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3219 /* Fixed size portion of debugging line information prolog. */
3220 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3222 /* Fixed size portion of public names info. */
3223 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3225 /* Fixed size portion of the address range info. */
3226 #define DWARF_ARANGES_HEADER_SIZE \
3227 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3228 - DWARF_OFFSET_SIZE)
3230 /* Size of padding portion in the address range info. It must be
3231 aligned to twice the pointer size. */
3232 #define DWARF_ARANGES_PAD_SIZE \
3233 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3234 - (2 * DWARF_OFFSET_SIZE + 4))
3236 /* Use assembler line directives if available. */
3237 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3238 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3239 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3241 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3245 /* Define the architecture-dependent minimum instruction length (in bytes).
3246 In this implementation of DWARF, this field is used for information
3247 purposes only. Since GCC generates assembly language, we have
3248 no a priori knowledge of how many instruction bytes are generated
3249 for each source line, and therefore can use only the DW_LNE_set_address
3250 and DW_LNS_fixed_advance_pc line information commands. */
3251 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3252 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3255 /* Minimum line offset in a special line info. opcode.
3256 This value was chosen to give a reasonable range of values. */
3257 #define DWARF_LINE_BASE -10
3259 /* First special line opcode - leave room for the standard opcodes. */
3260 #define DWARF_LINE_OPCODE_BASE 10
3262 /* Range of line offsets in a special line info. opcode. */
3263 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3265 /* Flag that indicates the initial value of the is_stmt_start flag.
3266 In the present implementation, we do not mark any lines as
3267 the beginning of a source statement, because that information
3268 is not made available by the GCC front-end. */
3269 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3271 /* This location is used by calc_die_sizes() to keep track
3272 the offset of each DIE within the .debug_info section. */
3273 static unsigned long next_die_offset;
3275 /* Record the root of the DIE's built for the current compilation unit. */
3276 static dw_die_ref comp_unit_die;
3278 /* A list of DIEs with a NULL parent waiting to be relocated. */
3279 static limbo_die_node *limbo_die_list = 0;
3281 /* Structure used by lookup_filename to manage sets of filenames. */
3287 unsigned last_lookup_index;
3290 /* Size (in elements) of increments by which we may expand the filename
3292 #define FILE_TABLE_INCREMENT 64
3294 /* Filenames referenced by this compilation unit. */
3295 static struct file_table file_table;
3297 /* Local pointer to the name of the main input file. Initialized in
3299 static const char *primary_filename;
3301 /* A pointer to the base of a table of references to DIE's that describe
3302 declarations. The table is indexed by DECL_UID() which is a unique
3303 number identifying each decl. */
3304 static dw_die_ref *decl_die_table;
3306 /* Number of elements currently allocated for the decl_die_table. */
3307 static unsigned decl_die_table_allocated;
3309 /* Number of elements in decl_die_table currently in use. */
3310 static unsigned decl_die_table_in_use;
3312 /* Size (in elements) of increments by which we may expand the
3314 #define DECL_DIE_TABLE_INCREMENT 256
3316 /* A pointer to the base of a table of references to declaration
3317 scopes. This table is a display which tracks the nesting
3318 of declaration scopes at the current scope and containing
3319 scopes. This table is used to find the proper place to
3320 define type declaration DIE's. */
3321 varray_type decl_scope_table;
3323 /* A pointer to the base of a list of references to DIE's that
3324 are uniquely identified by their tag, presence/absence of
3325 children DIE's, and list of attribute/value pairs. */
3326 static dw_die_ref *abbrev_die_table;
3328 /* Number of elements currently allocated for abbrev_die_table. */
3329 static unsigned abbrev_die_table_allocated;
3331 /* Number of elements in type_die_table currently in use. */
3332 static unsigned abbrev_die_table_in_use;
3334 /* Size (in elements) of increments by which we may expand the
3335 abbrev_die_table. */
3336 #define ABBREV_DIE_TABLE_INCREMENT 256
3338 /* A pointer to the base of a table that contains line information
3339 for each source code line in .text in the compilation unit. */
3340 static dw_line_info_ref line_info_table;
3342 /* Number of elements currently allocated for line_info_table. */
3343 static unsigned line_info_table_allocated;
3345 /* Number of elements in separate_line_info_table currently in use. */
3346 static unsigned separate_line_info_table_in_use;
3348 /* A pointer to the base of a table that contains line information
3349 for each source code line outside of .text in the compilation unit. */
3350 static dw_separate_line_info_ref separate_line_info_table;
3352 /* Number of elements currently allocated for separate_line_info_table. */
3353 static unsigned separate_line_info_table_allocated;
3355 /* Number of elements in line_info_table currently in use. */
3356 static unsigned line_info_table_in_use;
3358 /* Size (in elements) of increments by which we may expand the
3360 #define LINE_INFO_TABLE_INCREMENT 1024
3362 /* A pointer to the base of a table that contains a list of publicly
3363 accessible names. */
3364 static pubname_ref pubname_table;
3366 /* Number of elements currently allocated for pubname_table. */
3367 static unsigned pubname_table_allocated;
3369 /* Number of elements in pubname_table currently in use. */
3370 static unsigned pubname_table_in_use;
3372 /* Size (in elements) of increments by which we may expand the
3374 #define PUBNAME_TABLE_INCREMENT 64
3376 /* Array of dies for which we should generate .debug_arange info. */
3377 static dw_die_ref *arange_table;
3379 /* Number of elements currently allocated for arange_table. */
3380 static unsigned arange_table_allocated;
3382 /* Number of elements in arange_table currently in use. */
3383 static unsigned arange_table_in_use;
3385 /* Size (in elements) of increments by which we may expand the
3387 #define ARANGE_TABLE_INCREMENT 64
3389 /* Array of dies for which we should generate .debug_ranges info. */
3390 static dw_ranges_ref ranges_table;
3392 /* Number of elements currently allocated for ranges_table. */
3393 static unsigned ranges_table_allocated;
3395 /* Number of elements in ranges_table currently in use. */
3396 static unsigned ranges_table_in_use;
3398 /* Size (in elements) of increments by which we may expand the
3400 #define RANGES_TABLE_INCREMENT 64
3402 /* Whether we have location lists that need outputting */
3403 static unsigned have_location_lists;
3405 /* A pointer to the base of a list of incomplete types which might be
3406 completed at some later time. incomplete_types_list needs to be a VARRAY
3407 because we want to tell the garbage collector about it. */
3408 varray_type incomplete_types;
3410 /* Record whether the function being analyzed contains inlined functions. */
3411 static int current_function_has_inlines;
3412 #if 0 && defined (MIPS_DEBUGGING_INFO)
3413 static int comp_unit_has_inlines;
3416 /* Array of RTXes referenced by the debugging information, which therefore
3417 must be kept around forever. This is a GC root. */
3418 static varray_type used_rtx_varray;
3420 /* Forward declarations for functions defined in this file. */
3422 static int is_pseudo_reg PARAMS ((rtx));
3423 static tree type_main_variant PARAMS ((tree));
3424 static int is_tagged_type PARAMS ((tree));
3425 static const char *dwarf_tag_name PARAMS ((unsigned));
3426 static const char *dwarf_attr_name PARAMS ((unsigned));
3427 static const char *dwarf_form_name PARAMS ((unsigned));
3429 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3431 static tree decl_ultimate_origin PARAMS ((tree));
3432 static tree block_ultimate_origin PARAMS ((tree));
3433 static tree decl_class_context PARAMS ((tree));
3434 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3435 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
3436 static void add_AT_flag PARAMS ((dw_die_ref,
3437 enum dwarf_attribute,
3439 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3440 static void add_AT_int PARAMS ((dw_die_ref,
3441 enum dwarf_attribute, long));
3442 static inline long int AT_int PARAMS ((dw_attr_ref));
3443 static void add_AT_unsigned PARAMS ((dw_die_ref,
3444 enum dwarf_attribute,
3446 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
3447 static void add_AT_long_long PARAMS ((dw_die_ref,
3448 enum dwarf_attribute,
3451 static void add_AT_float PARAMS ((dw_die_ref,
3452 enum dwarf_attribute,
3454 static void add_AT_string PARAMS ((dw_die_ref,
3455 enum dwarf_attribute,
3457 static inline const char *AT_string PARAMS ((dw_attr_ref));
3458 static int AT_string_form PARAMS ((dw_attr_ref));
3459 static void add_AT_die_ref PARAMS ((dw_die_ref,
3460 enum dwarf_attribute,
3462 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
3463 static inline int AT_ref_external PARAMS ((dw_attr_ref));
3464 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
3465 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3466 enum dwarf_attribute,
3468 static void add_AT_loc PARAMS ((dw_die_ref,
3469 enum dwarf_attribute,
3471 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
3472 static void add_AT_loc_list PARAMS ((dw_die_ref,
3473 enum dwarf_attribute,
3475 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
3476 static void add_AT_addr PARAMS ((dw_die_ref,
3477 enum dwarf_attribute,
3479 static inline rtx AT_addr PARAMS ((dw_attr_ref));
3480 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3481 enum dwarf_attribute,
3483 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3484 enum dwarf_attribute,
3486 static void add_AT_offset PARAMS ((dw_die_ref,
3487 enum dwarf_attribute,
3489 static void add_AT_range_list PARAMS ((dw_die_ref,
3490 enum dwarf_attribute,
3492 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
3493 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3494 enum dwarf_attribute));
3495 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3496 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3497 static const char *get_AT_string PARAMS ((dw_die_ref,
3498 enum dwarf_attribute));
3499 static int get_AT_flag PARAMS ((dw_die_ref,
3500 enum dwarf_attribute));
3501 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3502 enum dwarf_attribute));
3503 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3504 enum dwarf_attribute));
3505 static int is_c_family PARAMS ((void));
3506 static int is_cxx PARAMS ((void));
3507 static int is_java PARAMS ((void));
3508 static int is_fortran PARAMS ((void));
3509 static void remove_AT PARAMS ((dw_die_ref,
3510 enum dwarf_attribute));
3511 static inline void free_die PARAMS ((dw_die_ref));
3512 static void remove_children PARAMS ((dw_die_ref));
3513 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3514 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref,
3516 static dw_die_ref lookup_type_die PARAMS ((tree));
3517 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3518 static dw_die_ref lookup_decl_die PARAMS ((tree));
3519 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3520 static void print_spaces PARAMS ((FILE *));
3521 static void print_die PARAMS ((dw_die_ref, FILE *));
3522 static void print_dwarf_line_table PARAMS ((FILE *));
3523 static void reverse_die_lists PARAMS ((dw_die_ref));
3524 static void reverse_all_dies PARAMS ((dw_die_ref));
3525 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3526 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3527 static void loc_checksum PARAMS ((dw_loc_descr_ref,
3529 static void attr_checksum PARAMS ((dw_attr_ref,
3531 static void die_checksum PARAMS ((dw_die_ref,
3533 static void compute_section_prefix PARAMS ((dw_die_ref));
3534 static int is_type_die PARAMS ((dw_die_ref));
3535 static int is_comdat_die PARAMS ((dw_die_ref));
3536 static int is_symbol_die PARAMS ((dw_die_ref));
3537 static void assign_symbol_names PARAMS ((dw_die_ref));
3538 static void break_out_includes PARAMS ((dw_die_ref));
3539 static void add_sibling_attributes PARAMS ((dw_die_ref));
3540 static void build_abbrev_table PARAMS ((dw_die_ref));
3541 static void output_location_lists PARAMS ((dw_die_ref));
3542 static int constant_size PARAMS ((long unsigned));
3543 static unsigned long size_of_die PARAMS ((dw_die_ref));
3544 static void calc_die_sizes PARAMS ((dw_die_ref));
3545 static void mark_dies PARAMS ((dw_die_ref));
3546 static void unmark_dies PARAMS ((dw_die_ref));
3547 static unsigned long size_of_pubnames PARAMS ((void));
3548 static unsigned long size_of_aranges PARAMS ((void));
3549 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3550 static void output_value_format PARAMS ((dw_attr_ref));
3551 static void output_abbrev_section PARAMS ((void));
3552 static void output_die_symbol PARAMS ((dw_die_ref));
3553 static void output_die PARAMS ((dw_die_ref));
3554 static void output_compilation_unit_header PARAMS ((void));
3555 static void output_comp_unit PARAMS ((dw_die_ref));
3556 static const char *dwarf2_name PARAMS ((tree, int));
3557 static void add_pubname PARAMS ((tree, dw_die_ref));
3558 static void output_pubnames PARAMS ((void));
3559 static void add_arange PARAMS ((tree, dw_die_ref));
3560 static void output_aranges PARAMS ((void));
3561 static unsigned int add_ranges PARAMS ((tree));
3562 static void output_ranges PARAMS ((void));
3563 static void output_line_info PARAMS ((void));
3564 static void output_file_names PARAMS ((void));
3565 static dw_die_ref base_type_die PARAMS ((tree));
3566 static tree root_type PARAMS ((tree));
3567 static int is_base_type PARAMS ((tree));
3568 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3569 static int type_is_enum PARAMS ((tree));
3570 static unsigned int reg_number PARAMS ((rtx));
3571 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3572 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3573 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3574 static int is_based_loc PARAMS ((rtx));
3575 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3576 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3577 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3578 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3579 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3580 static tree field_type PARAMS ((tree));
3581 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3582 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3583 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3584 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3585 static void add_AT_location_description PARAMS ((dw_die_ref,
3586 enum dwarf_attribute, rtx));
3587 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3588 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3589 static rtx rtl_for_decl_location PARAMS ((tree));
3590 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3591 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3592 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3593 static void add_bound_info PARAMS ((dw_die_ref,
3594 enum dwarf_attribute, tree));
3595 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3596 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3597 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3598 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3599 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3600 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3601 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3602 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3603 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3604 static void push_decl_scope PARAMS ((tree));
3605 static void pop_decl_scope PARAMS ((void));
3606 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3607 static inline int local_scope_p PARAMS ((dw_die_ref));
3608 static inline int class_scope_p PARAMS ((dw_die_ref));
3609 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3611 static const char *type_tag PARAMS ((tree));
3612 static tree member_declared_type PARAMS ((tree));
3614 static const char *decl_start_label PARAMS ((tree));
3616 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3617 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3619 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3621 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3622 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3623 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3624 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3625 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3626 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3627 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3628 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3629 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3630 static void gen_label_die PARAMS ((tree, dw_die_ref));
3631 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3632 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3633 static void gen_field_die PARAMS ((tree, dw_die_ref));
3634 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3635 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3636 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3637 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3638 static void gen_member_die PARAMS ((tree, dw_die_ref));
3639 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3640 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3641 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3642 static void gen_type_die PARAMS ((tree, dw_die_ref));
3643 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3644 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3645 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3646 static int is_redundant_typedef PARAMS ((tree));
3647 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3648 static unsigned lookup_filename PARAMS ((const char *));
3649 static void init_file_table PARAMS ((void));
3650 static void retry_incomplete_types PARAMS ((void));
3651 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3652 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3653 static int file_info_cmp PARAMS ((const void *, const void *));
3654 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3655 const char *, const char *,
3656 const char *, unsigned));
3657 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3659 const char *, const char *, const char *));
3660 static void output_loc_list PARAMS ((dw_loc_list_ref));
3661 static char *gen_internal_sym PARAMS ((const char *));
3662 static void mark_limbo_die_list PARAMS ((void *));
3664 /* Section names used to hold DWARF debugging information. */
3665 #ifndef DEBUG_INFO_SECTION
3666 #define DEBUG_INFO_SECTION ".debug_info"
3668 #ifndef DEBUG_ABBREV_SECTION
3669 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3671 #ifndef DEBUG_ARANGES_SECTION
3672 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3674 #ifndef DEBUG_MACINFO_SECTION
3675 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3677 #ifndef DEBUG_LINE_SECTION
3678 #define DEBUG_LINE_SECTION ".debug_line"
3680 #ifndef DEBUG_LOC_SECTION
3681 #define DEBUG_LOC_SECTION ".debug_loc"
3683 #ifndef DEBUG_PUBNAMES_SECTION
3684 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3686 #ifndef DEBUG_STR_SECTION
3687 #define DEBUG_STR_SECTION ".debug_str"
3689 #ifndef DEBUG_RANGES_SECTION
3690 #define DEBUG_RANGES_SECTION ".debug_ranges"
3693 /* Standard ELF section names for compiled code and data. */
3694 #ifndef TEXT_SECTION_NAME
3695 #define TEXT_SECTION_NAME ".text"
3698 /* Section flags for .debug_str section. */
3699 #ifdef HAVE_GAS_SHF_MERGE
3700 #define DEBUG_STR_SECTION_FLAGS \
3701 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3703 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3706 /* Labels we insert at beginning sections we can reference instead of
3707 the section names themselves. */
3709 #ifndef TEXT_SECTION_LABEL
3710 #define TEXT_SECTION_LABEL "Ltext"
3712 #ifndef DEBUG_LINE_SECTION_LABEL
3713 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3715 #ifndef DEBUG_INFO_SECTION_LABEL
3716 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3718 #ifndef DEBUG_ABBREV_SECTION_LABEL
3719 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3721 #ifndef DEBUG_LOC_SECTION_LABEL
3722 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3724 #ifndef DEBUG_RANGES_SECTION_LABEL
3725 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3727 #ifndef DEBUG_MACINFO_SECTION_LABEL
3728 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3731 /* Definitions of defaults for formats and names of various special
3732 (artificial) labels which may be generated within this file (when the -g
3733 options is used and DWARF_DEBUGGING_INFO is in effect.
3734 If necessary, these may be overridden from within the tm.h file, but
3735 typically, overriding these defaults is unnecessary. */
3737 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3738 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3739 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3740 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3741 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3742 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3743 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3744 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3746 #ifndef TEXT_END_LABEL
3747 #define TEXT_END_LABEL "Letext"
3749 #ifndef DATA_END_LABEL
3750 #define DATA_END_LABEL "Ledata"
3752 #ifndef BSS_END_LABEL
3753 #define BSS_END_LABEL "Lebss"
3755 #ifndef BLOCK_BEGIN_LABEL
3756 #define BLOCK_BEGIN_LABEL "LBB"
3758 #ifndef BLOCK_END_LABEL
3759 #define BLOCK_END_LABEL "LBE"
3761 #ifndef BODY_BEGIN_LABEL
3762 #define BODY_BEGIN_LABEL "Lbb"
3764 #ifndef BODY_END_LABEL
3765 #define BODY_END_LABEL "Lbe"
3767 #ifndef LINE_CODE_LABEL
3768 #define LINE_CODE_LABEL "LM"
3770 #ifndef SEPARATE_LINE_CODE_LABEL
3771 #define SEPARATE_LINE_CODE_LABEL "LSM"
3774 /* We allow a language front-end to designate a function that is to be
3775 called to "demangle" any name before it it put into a DIE. */
3777 static const char *(*demangle_name_func) PARAMS ((const char *));
3780 dwarf2out_set_demangle_name_func (func)
3781 const char *(*func) PARAMS ((const char *));
3783 demangle_name_func = func;
3786 /* Test if rtl node points to a pseudo register. */
3792 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3793 || (GET_CODE (rtl) == SUBREG
3794 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3797 /* Return a reference to a type, with its const and volatile qualifiers
3801 type_main_variant (type)
3804 type = TYPE_MAIN_VARIANT (type);
3806 /* ??? There really should be only one main variant among any group of
3807 variants of a given type (and all of the MAIN_VARIANT values for all
3808 members of the group should point to that one type) but sometimes the C
3809 front-end messes this up for array types, so we work around that bug
3811 if (TREE_CODE (type) == ARRAY_TYPE)
3812 while (type != TYPE_MAIN_VARIANT (type))
3813 type = TYPE_MAIN_VARIANT (type);
3818 /* Return non-zero if the given type node represents a tagged type. */
3821 is_tagged_type (type)
3824 enum tree_code code = TREE_CODE (type);
3826 return (code == RECORD_TYPE || code == UNION_TYPE
3827 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3830 /* Convert a DIE tag into its string name. */
3833 dwarf_tag_name (tag)
3838 case DW_TAG_padding:
3839 return "DW_TAG_padding";
3840 case DW_TAG_array_type:
3841 return "DW_TAG_array_type";
3842 case DW_TAG_class_type:
3843 return "DW_TAG_class_type";
3844 case DW_TAG_entry_point:
3845 return "DW_TAG_entry_point";
3846 case DW_TAG_enumeration_type:
3847 return "DW_TAG_enumeration_type";
3848 case DW_TAG_formal_parameter:
3849 return "DW_TAG_formal_parameter";
3850 case DW_TAG_imported_declaration:
3851 return "DW_TAG_imported_declaration";
3853 return "DW_TAG_label";
3854 case DW_TAG_lexical_block:
3855 return "DW_TAG_lexical_block";
3857 return "DW_TAG_member";
3858 case DW_TAG_pointer_type:
3859 return "DW_TAG_pointer_type";
3860 case DW_TAG_reference_type:
3861 return "DW_TAG_reference_type";
3862 case DW_TAG_compile_unit:
3863 return "DW_TAG_compile_unit";
3864 case DW_TAG_string_type:
3865 return "DW_TAG_string_type";
3866 case DW_TAG_structure_type:
3867 return "DW_TAG_structure_type";
3868 case DW_TAG_subroutine_type:
3869 return "DW_TAG_subroutine_type";
3870 case DW_TAG_typedef:
3871 return "DW_TAG_typedef";
3872 case DW_TAG_union_type:
3873 return "DW_TAG_union_type";
3874 case DW_TAG_unspecified_parameters:
3875 return "DW_TAG_unspecified_parameters";
3876 case DW_TAG_variant:
3877 return "DW_TAG_variant";
3878 case DW_TAG_common_block:
3879 return "DW_TAG_common_block";
3880 case DW_TAG_common_inclusion:
3881 return "DW_TAG_common_inclusion";
3882 case DW_TAG_inheritance:
3883 return "DW_TAG_inheritance";
3884 case DW_TAG_inlined_subroutine:
3885 return "DW_TAG_inlined_subroutine";
3887 return "DW_TAG_module";
3888 case DW_TAG_ptr_to_member_type:
3889 return "DW_TAG_ptr_to_member_type";
3890 case DW_TAG_set_type:
3891 return "DW_TAG_set_type";
3892 case DW_TAG_subrange_type:
3893 return "DW_TAG_subrange_type";
3894 case DW_TAG_with_stmt:
3895 return "DW_TAG_with_stmt";
3896 case DW_TAG_access_declaration:
3897 return "DW_TAG_access_declaration";
3898 case DW_TAG_base_type:
3899 return "DW_TAG_base_type";
3900 case DW_TAG_catch_block:
3901 return "DW_TAG_catch_block";
3902 case DW_TAG_const_type:
3903 return "DW_TAG_const_type";
3904 case DW_TAG_constant:
3905 return "DW_TAG_constant";
3906 case DW_TAG_enumerator:
3907 return "DW_TAG_enumerator";
3908 case DW_TAG_file_type:
3909 return "DW_TAG_file_type";
3911 return "DW_TAG_friend";
3912 case DW_TAG_namelist:
3913 return "DW_TAG_namelist";
3914 case DW_TAG_namelist_item:
3915 return "DW_TAG_namelist_item";
3916 case DW_TAG_packed_type:
3917 return "DW_TAG_packed_type";
3918 case DW_TAG_subprogram:
3919 return "DW_TAG_subprogram";
3920 case DW_TAG_template_type_param:
3921 return "DW_TAG_template_type_param";
3922 case DW_TAG_template_value_param:
3923 return "DW_TAG_template_value_param";
3924 case DW_TAG_thrown_type:
3925 return "DW_TAG_thrown_type";
3926 case DW_TAG_try_block:
3927 return "DW_TAG_try_block";
3928 case DW_TAG_variant_part:
3929 return "DW_TAG_variant_part";
3930 case DW_TAG_variable:
3931 return "DW_TAG_variable";
3932 case DW_TAG_volatile_type:
3933 return "DW_TAG_volatile_type";
3934 case DW_TAG_MIPS_loop:
3935 return "DW_TAG_MIPS_loop";
3936 case DW_TAG_format_label:
3937 return "DW_TAG_format_label";
3938 case DW_TAG_function_template:
3939 return "DW_TAG_function_template";
3940 case DW_TAG_class_template:
3941 return "DW_TAG_class_template";
3942 case DW_TAG_GNU_BINCL:
3943 return "DW_TAG_GNU_BINCL";
3944 case DW_TAG_GNU_EINCL:
3945 return "DW_TAG_GNU_EINCL";
3947 return "DW_TAG_<unknown>";
3951 /* Convert a DWARF attribute code into its string name. */
3954 dwarf_attr_name (attr)
3960 return "DW_AT_sibling";
3961 case DW_AT_location:
3962 return "DW_AT_location";
3964 return "DW_AT_name";
3965 case DW_AT_ordering:
3966 return "DW_AT_ordering";
3967 case DW_AT_subscr_data:
3968 return "DW_AT_subscr_data";
3969 case DW_AT_byte_size:
3970 return "DW_AT_byte_size";
3971 case DW_AT_bit_offset:
3972 return "DW_AT_bit_offset";
3973 case DW_AT_bit_size:
3974 return "DW_AT_bit_size";
3975 case DW_AT_element_list:
3976 return "DW_AT_element_list";
3977 case DW_AT_stmt_list:
3978 return "DW_AT_stmt_list";
3980 return "DW_AT_low_pc";
3982 return "DW_AT_high_pc";
3983 case DW_AT_language:
3984 return "DW_AT_language";
3986 return "DW_AT_member";
3988 return "DW_AT_discr";
3989 case DW_AT_discr_value:
3990 return "DW_AT_discr_value";
3991 case DW_AT_visibility:
3992 return "DW_AT_visibility";
3994 return "DW_AT_import";
3995 case DW_AT_string_length:
3996 return "DW_AT_string_length";
3997 case DW_AT_common_reference:
3998 return "DW_AT_common_reference";
3999 case DW_AT_comp_dir:
4000 return "DW_AT_comp_dir";
4001 case DW_AT_const_value:
4002 return "DW_AT_const_value";
4003 case DW_AT_containing_type:
4004 return "DW_AT_containing_type";
4005 case DW_AT_default_value:
4006 return "DW_AT_default_value";
4008 return "DW_AT_inline";
4009 case DW_AT_is_optional:
4010 return "DW_AT_is_optional";
4011 case DW_AT_lower_bound:
4012 return "DW_AT_lower_bound";
4013 case DW_AT_producer:
4014 return "DW_AT_producer";
4015 case DW_AT_prototyped:
4016 return "DW_AT_prototyped";
4017 case DW_AT_return_addr:
4018 return "DW_AT_return_addr";
4019 case DW_AT_start_scope:
4020 return "DW_AT_start_scope";
4021 case DW_AT_stride_size:
4022 return "DW_AT_stride_size";
4023 case DW_AT_upper_bound:
4024 return "DW_AT_upper_bound";
4025 case DW_AT_abstract_origin:
4026 return "DW_AT_abstract_origin";
4027 case DW_AT_accessibility:
4028 return "DW_AT_accessibility";
4029 case DW_AT_address_class:
4030 return "DW_AT_address_class";
4031 case DW_AT_artificial:
4032 return "DW_AT_artificial";
4033 case DW_AT_base_types:
4034 return "DW_AT_base_types";
4035 case DW_AT_calling_convention:
4036 return "DW_AT_calling_convention";
4038 return "DW_AT_count";
4039 case DW_AT_data_member_location:
4040 return "DW_AT_data_member_location";
4041 case DW_AT_decl_column:
4042 return "DW_AT_decl_column";
4043 case DW_AT_decl_file:
4044 return "DW_AT_decl_file";
4045 case DW_AT_decl_line:
4046 return "DW_AT_decl_line";
4047 case DW_AT_declaration:
4048 return "DW_AT_declaration";
4049 case DW_AT_discr_list:
4050 return "DW_AT_discr_list";
4051 case DW_AT_encoding:
4052 return "DW_AT_encoding";
4053 case DW_AT_external:
4054 return "DW_AT_external";
4055 case DW_AT_frame_base:
4056 return "DW_AT_frame_base";
4058 return "DW_AT_friend";
4059 case DW_AT_identifier_case:
4060 return "DW_AT_identifier_case";
4061 case DW_AT_macro_info:
4062 return "DW_AT_macro_info";
4063 case DW_AT_namelist_items:
4064 return "DW_AT_namelist_items";
4065 case DW_AT_priority:
4066 return "DW_AT_priority";
4068 return "DW_AT_segment";
4069 case DW_AT_specification:
4070 return "DW_AT_specification";
4071 case DW_AT_static_link:
4072 return "DW_AT_static_link";
4074 return "DW_AT_type";
4075 case DW_AT_use_location:
4076 return "DW_AT_use_location";
4077 case DW_AT_variable_parameter:
4078 return "DW_AT_variable_parameter";
4079 case DW_AT_virtuality:
4080 return "DW_AT_virtuality";
4081 case DW_AT_vtable_elem_location:
4082 return "DW_AT_vtable_elem_location";
4084 case DW_AT_allocated:
4085 return "DW_AT_allocated";
4086 case DW_AT_associated:
4087 return "DW_AT_associated";
4088 case DW_AT_data_location:
4089 return "DW_AT_data_location";
4091 return "DW_AT_stride";
4092 case DW_AT_entry_pc:
4093 return "DW_AT_entry_pc";
4094 case DW_AT_use_UTF8:
4095 return "DW_AT_use_UTF8";
4096 case DW_AT_extension:
4097 return "DW_AT_extension";
4099 return "DW_AT_ranges";
4100 case DW_AT_trampoline:
4101 return "DW_AT_trampoline";
4102 case DW_AT_call_column:
4103 return "DW_AT_call_column";
4104 case DW_AT_call_file:
4105 return "DW_AT_call_file";
4106 case DW_AT_call_line:
4107 return "DW_AT_call_line";
4109 case DW_AT_MIPS_fde:
4110 return "DW_AT_MIPS_fde";
4111 case DW_AT_MIPS_loop_begin:
4112 return "DW_AT_MIPS_loop_begin";
4113 case DW_AT_MIPS_tail_loop_begin:
4114 return "DW_AT_MIPS_tail_loop_begin";
4115 case DW_AT_MIPS_epilog_begin:
4116 return "DW_AT_MIPS_epilog_begin";
4117 case DW_AT_MIPS_loop_unroll_factor:
4118 return "DW_AT_MIPS_loop_unroll_factor";
4119 case DW_AT_MIPS_software_pipeline_depth:
4120 return "DW_AT_MIPS_software_pipeline_depth";
4121 case DW_AT_MIPS_linkage_name:
4122 return "DW_AT_MIPS_linkage_name";
4123 case DW_AT_MIPS_stride:
4124 return "DW_AT_MIPS_stride";
4125 case DW_AT_MIPS_abstract_name:
4126 return "DW_AT_MIPS_abstract_name";
4127 case DW_AT_MIPS_clone_origin:
4128 return "DW_AT_MIPS_clone_origin";
4129 case DW_AT_MIPS_has_inlines:
4130 return "DW_AT_MIPS_has_inlines";
4132 case DW_AT_sf_names:
4133 return "DW_AT_sf_names";
4134 case DW_AT_src_info:
4135 return "DW_AT_src_info";
4136 case DW_AT_mac_info:
4137 return "DW_AT_mac_info";
4138 case DW_AT_src_coords:
4139 return "DW_AT_src_coords";
4140 case DW_AT_body_begin:
4141 return "DW_AT_body_begin";
4142 case DW_AT_body_end:
4143 return "DW_AT_body_end";
4144 case DW_AT_VMS_rtnbeg_pd_address:
4145 return "DW_AT_VMS_rtnbeg_pd_address";
4148 return "DW_AT_<unknown>";
4152 /* Convert a DWARF value form code into its string name. */
4155 dwarf_form_name (form)
4161 return "DW_FORM_addr";
4162 case DW_FORM_block2:
4163 return "DW_FORM_block2";
4164 case DW_FORM_block4:
4165 return "DW_FORM_block4";
4167 return "DW_FORM_data2";
4169 return "DW_FORM_data4";
4171 return "DW_FORM_data8";
4172 case DW_FORM_string:
4173 return "DW_FORM_string";
4175 return "DW_FORM_block";
4176 case DW_FORM_block1:
4177 return "DW_FORM_block1";
4179 return "DW_FORM_data1";
4181 return "DW_FORM_flag";
4183 return "DW_FORM_sdata";
4185 return "DW_FORM_strp";
4187 return "DW_FORM_udata";
4188 case DW_FORM_ref_addr:
4189 return "DW_FORM_ref_addr";
4191 return "DW_FORM_ref1";
4193 return "DW_FORM_ref2";
4195 return "DW_FORM_ref4";
4197 return "DW_FORM_ref8";
4198 case DW_FORM_ref_udata:
4199 return "DW_FORM_ref_udata";
4200 case DW_FORM_indirect:
4201 return "DW_FORM_indirect";
4203 return "DW_FORM_<unknown>";
4207 /* Convert a DWARF type code into its string name. */
4211 dwarf_type_encoding_name (enc)
4216 case DW_ATE_address:
4217 return "DW_ATE_address";
4218 case DW_ATE_boolean:
4219 return "DW_ATE_boolean";
4220 case DW_ATE_complex_float:
4221 return "DW_ATE_complex_float";
4223 return "DW_ATE_float";
4225 return "DW_ATE_signed";
4226 case DW_ATE_signed_char:
4227 return "DW_ATE_signed_char";
4228 case DW_ATE_unsigned:
4229 return "DW_ATE_unsigned";
4230 case DW_ATE_unsigned_char:
4231 return "DW_ATE_unsigned_char";
4233 return "DW_ATE_<unknown>";
4238 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4239 instance of an inlined instance of a decl which is local to an inline
4240 function, so we have to trace all of the way back through the origin chain
4241 to find out what sort of node actually served as the original seed for the
4245 decl_ultimate_origin (decl)
4248 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4249 nodes in the function to point to themselves; ignore that if
4250 we're trying to output the abstract instance of this function. */
4251 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4254 #ifdef ENABLE_CHECKING
4255 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4256 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4257 most distant ancestor, this should never happen. */
4261 return DECL_ABSTRACT_ORIGIN (decl);
4264 /* Determine the "ultimate origin" of a block. The block may be an inlined
4265 instance of an inlined instance of a block which is local to an inline
4266 function, so we have to trace all of the way back through the origin chain
4267 to find out what sort of node actually served as the original seed for the
4271 block_ultimate_origin (block)
4274 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4276 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4277 nodes in the function to point to themselves; ignore that if
4278 we're trying to output the abstract instance of this function. */
4279 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4282 if (immediate_origin == NULL_TREE)
4287 tree lookahead = immediate_origin;
4291 ret_val = lookahead;
4292 lookahead = (TREE_CODE (ret_val) == BLOCK
4293 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4295 while (lookahead != NULL && lookahead != ret_val);
4301 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4302 of a virtual function may refer to a base class, so we check the 'this'
4306 decl_class_context (decl)
4309 tree context = NULL_TREE;
4311 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4312 context = DECL_CONTEXT (decl);
4314 context = TYPE_MAIN_VARIANT
4315 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4317 if (context && !TYPE_P (context))
4318 context = NULL_TREE;
4323 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4324 addition order, and correct that in reverse_all_dies. */
4327 add_dwarf_attr (die, attr)
4331 if (die != NULL && attr != NULL)
4333 attr->dw_attr_next = die->die_attr;
4334 die->die_attr = attr;
4338 static inline dw_val_class
4342 return a->dw_attr_val.val_class;
4345 /* Add a flag value attribute to a DIE. */
4348 add_AT_flag (die, attr_kind, flag)
4350 enum dwarf_attribute attr_kind;
4353 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4355 attr->dw_attr_next = NULL;
4356 attr->dw_attr = attr_kind;
4357 attr->dw_attr_val.val_class = dw_val_class_flag;
4358 attr->dw_attr_val.v.val_flag = flag;
4359 add_dwarf_attr (die, attr);
4362 static inline unsigned
4366 if (a && AT_class (a) == dw_val_class_flag)
4367 return a->dw_attr_val.v.val_flag;
4372 /* Add a signed integer attribute value to a DIE. */
4375 add_AT_int (die, attr_kind, int_val)
4377 enum dwarf_attribute attr_kind;
4380 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4382 attr->dw_attr_next = NULL;
4383 attr->dw_attr = attr_kind;
4384 attr->dw_attr_val.val_class = dw_val_class_const;
4385 attr->dw_attr_val.v.val_int = int_val;
4386 add_dwarf_attr (die, attr);
4389 static inline long int
4393 if (a && AT_class (a) == dw_val_class_const)
4394 return a->dw_attr_val.v.val_int;
4399 /* Add an unsigned integer attribute value to a DIE. */
4402 add_AT_unsigned (die, attr_kind, unsigned_val)
4404 enum dwarf_attribute attr_kind;
4405 unsigned long unsigned_val;
4407 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4409 attr->dw_attr_next = NULL;
4410 attr->dw_attr = attr_kind;
4411 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4412 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4413 add_dwarf_attr (die, attr);
4416 static inline unsigned long
4420 if (a && AT_class (a) == dw_val_class_unsigned_const)
4421 return a->dw_attr_val.v.val_unsigned;
4426 /* Add an unsigned double integer attribute value to a DIE. */
4429 add_AT_long_long (die, attr_kind, val_hi, val_low)
4431 enum dwarf_attribute attr_kind;
4432 unsigned long val_hi;
4433 unsigned long val_low;
4435 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4437 attr->dw_attr_next = NULL;
4438 attr->dw_attr = attr_kind;
4439 attr->dw_attr_val.val_class = dw_val_class_long_long;
4440 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4441 attr->dw_attr_val.v.val_long_long.low = val_low;
4442 add_dwarf_attr (die, attr);
4445 /* Add a floating point attribute value to a DIE and return it. */
4448 add_AT_float (die, attr_kind, length, array)
4450 enum dwarf_attribute attr_kind;
4454 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4456 attr->dw_attr_next = NULL;
4457 attr->dw_attr = attr_kind;
4458 attr->dw_attr_val.val_class = dw_val_class_float;
4459 attr->dw_attr_val.v.val_float.length = length;
4460 attr->dw_attr_val.v.val_float.array = array;
4461 add_dwarf_attr (die, attr);
4464 /* Add a string attribute value to a DIE. */
4467 add_AT_string (die, attr_kind, str)
4469 enum dwarf_attribute attr_kind;
4472 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4473 struct indirect_string_node *node;
4475 if (! debug_str_hash)
4477 debug_str_hash = ht_create (10);
4478 debug_str_hash->alloc_node = indirect_string_alloc;
4481 node = (struct indirect_string_node *)
4482 ht_lookup (debug_str_hash, (const unsigned char *) str,
4483 strlen (str), HT_ALLOC);
4486 attr->dw_attr_next = NULL;
4487 attr->dw_attr = attr_kind;
4488 attr->dw_attr_val.val_class = dw_val_class_str;
4489 attr->dw_attr_val.v.val_str = node;
4490 add_dwarf_attr (die, attr);
4493 static inline const char *
4497 if (a && AT_class (a) == dw_val_class_str)
4498 return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id);
4503 /* Find out whether a string should be output inline in DIE
4504 or out-of-line in .debug_str section. */
4510 if (a && AT_class (a) == dw_val_class_str)
4512 struct indirect_string_node *node;
4514 extern int const_labelno;
4517 node = a->dw_attr_val.v.val_str;
4521 len = HT_LEN (&node->id) + 1;
4523 /* If the string is shorter or equal to the size of the reference, it is
4524 always better to put it inline. */
4525 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4526 return node->form = DW_FORM_string;
4528 /* If we cannot expect the linker to merge strings in .debug_str
4529 section, only put it into .debug_str if it is worth even in this
4531 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4532 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4533 return node->form = DW_FORM_string;
4535 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4537 node->label = xstrdup (label);
4539 return node->form = DW_FORM_strp;
4545 /* Add a DIE reference attribute value to a DIE. */
4548 add_AT_die_ref (die, attr_kind, targ_die)
4550 enum dwarf_attribute attr_kind;
4551 dw_die_ref targ_die;
4553 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4555 attr->dw_attr_next = NULL;
4556 attr->dw_attr = attr_kind;
4557 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4558 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4559 attr->dw_attr_val.v.val_die_ref.external = 0;
4560 add_dwarf_attr (die, attr);
4563 static inline dw_die_ref
4567 if (a && AT_class (a) == dw_val_class_die_ref)
4568 return a->dw_attr_val.v.val_die_ref.die;
4577 if (a && AT_class (a) == dw_val_class_die_ref)
4578 return a->dw_attr_val.v.val_die_ref.external;
4584 set_AT_ref_external (a, i)
4588 if (a && AT_class (a) == dw_val_class_die_ref)
4589 a->dw_attr_val.v.val_die_ref.external = i;
4594 /* Add an FDE reference attribute value to a DIE. */
4597 add_AT_fde_ref (die, attr_kind, targ_fde)
4599 enum dwarf_attribute attr_kind;
4602 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4604 attr->dw_attr_next = NULL;
4605 attr->dw_attr = attr_kind;
4606 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4607 attr->dw_attr_val.v.val_fde_index = targ_fde;
4608 add_dwarf_attr (die, attr);
4611 /* Add a location description attribute value to a DIE. */
4614 add_AT_loc (die, attr_kind, loc)
4616 enum dwarf_attribute attr_kind;
4617 dw_loc_descr_ref loc;
4619 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4621 attr->dw_attr_next = NULL;
4622 attr->dw_attr = attr_kind;
4623 attr->dw_attr_val.val_class = dw_val_class_loc;
4624 attr->dw_attr_val.v.val_loc = loc;
4625 add_dwarf_attr (die, attr);
4628 static inline dw_loc_descr_ref
4632 if (a && AT_class (a) == dw_val_class_loc)
4633 return a->dw_attr_val.v.val_loc;
4639 add_AT_loc_list (die, attr_kind, loc_list)
4641 enum dwarf_attribute attr_kind;
4642 dw_loc_list_ref loc_list;
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_loc_list;
4649 attr->dw_attr_val.v.val_loc_list = loc_list;
4650 add_dwarf_attr (die, attr);
4651 have_location_lists = 1;
4654 static inline dw_loc_list_ref
4658 if (a && AT_class (a) == dw_val_class_loc_list)
4659 return a->dw_attr_val.v.val_loc_list;
4664 /* Add an address constant attribute value to a DIE. */
4667 add_AT_addr (die, attr_kind, addr)
4669 enum dwarf_attribute attr_kind;
4672 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4674 attr->dw_attr_next = NULL;
4675 attr->dw_attr = attr_kind;
4676 attr->dw_attr_val.val_class = dw_val_class_addr;
4677 attr->dw_attr_val.v.val_addr = addr;
4678 add_dwarf_attr (die, attr);
4685 if (a && AT_class (a) == dw_val_class_addr)
4686 return a->dw_attr_val.v.val_addr;
4691 /* Add a label identifier attribute value to a DIE. */
4694 add_AT_lbl_id (die, attr_kind, lbl_id)
4696 enum dwarf_attribute attr_kind;
4699 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4701 attr->dw_attr_next = NULL;
4702 attr->dw_attr = attr_kind;
4703 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4704 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4705 add_dwarf_attr (die, attr);
4708 /* Add a section offset attribute value to a DIE. */
4711 add_AT_lbl_offset (die, attr_kind, label)
4713 enum dwarf_attribute attr_kind;
4716 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4718 attr->dw_attr_next = NULL;
4719 attr->dw_attr = attr_kind;
4720 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4721 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4722 add_dwarf_attr (die, attr);
4725 /* Add an offset attribute value to a DIE. */
4728 add_AT_offset (die, attr_kind, offset)
4730 enum dwarf_attribute attr_kind;
4731 unsigned long offset;
4733 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4735 attr->dw_attr_next = NULL;
4736 attr->dw_attr = attr_kind;
4737 attr->dw_attr_val.val_class = dw_val_class_offset;
4738 attr->dw_attr_val.v.val_offset = offset;
4739 add_dwarf_attr (die, attr);
4742 /* Add an range_list attribute value to a DIE. */
4745 add_AT_range_list (die, attr_kind, offset)
4747 enum dwarf_attribute attr_kind;
4748 unsigned long offset;
4750 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4752 attr->dw_attr_next = NULL;
4753 attr->dw_attr = attr_kind;
4754 attr->dw_attr_val.val_class = dw_val_class_range_list;
4755 attr->dw_attr_val.v.val_offset = offset;
4756 add_dwarf_attr (die, attr);
4759 static inline const char *
4763 if (a && (AT_class (a) == dw_val_class_lbl_id
4764 || AT_class (a) == dw_val_class_lbl_offset))
4765 return a->dw_attr_val.v.val_lbl_id;
4770 /* Get the attribute of type attr_kind. */
4772 static inline dw_attr_ref
4773 get_AT (die, attr_kind)
4775 enum dwarf_attribute attr_kind;
4778 dw_die_ref spec = NULL;
4782 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4783 if (a->dw_attr == attr_kind)
4785 else if (a->dw_attr == DW_AT_specification
4786 || a->dw_attr == DW_AT_abstract_origin)
4790 return get_AT (spec, attr_kind);
4796 /* Return the "low pc" attribute value, typically associated with a subprogram
4797 DIE. Return null if the "low pc" attribute is either not present, or if it
4798 cannot be represented as an assembler label identifier. */
4800 static inline const char *
4804 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4806 return a ? AT_lbl (a) : NULL;
4809 /* Return the "high pc" attribute value, typically associated with a subprogram
4810 DIE. Return null if the "high pc" attribute is either not present, or if it
4811 cannot be represented as an assembler label identifier. */
4813 static inline const char *
4817 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4819 return a ? AT_lbl (a) : NULL;
4822 /* Return the value of the string attribute designated by ATTR_KIND, or
4823 NULL if it is not present. */
4825 static inline const char *
4826 get_AT_string (die, attr_kind)
4828 enum dwarf_attribute attr_kind;
4830 dw_attr_ref a = get_AT (die, attr_kind);
4832 return a ? AT_string (a) : NULL;
4835 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4836 if it is not present. */
4839 get_AT_flag (die, attr_kind)
4841 enum dwarf_attribute attr_kind;
4843 dw_attr_ref a = get_AT (die, attr_kind);
4845 return a ? AT_flag (a) : 0;
4848 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4849 if it is not present. */
4851 static inline unsigned
4852 get_AT_unsigned (die, attr_kind)
4854 enum dwarf_attribute attr_kind;
4856 dw_attr_ref a = get_AT (die, attr_kind);
4858 return a ? AT_unsigned (a) : 0;
4861 static inline dw_die_ref
4862 get_AT_ref (die, attr_kind)
4864 enum dwarf_attribute attr_kind;
4866 dw_attr_ref a = get_AT (die, attr_kind);
4868 return a ? AT_ref (a) : NULL;
4874 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4876 return (lang == DW_LANG_C || lang == DW_LANG_C89
4877 || lang == DW_LANG_C_plus_plus);
4883 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4884 == DW_LANG_C_plus_plus);
4890 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4892 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4898 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4900 return (lang == DW_LANG_Java);
4903 /* Free up the memory used by A. */
4905 static inline void free_AT PARAMS ((dw_attr_ref));
4910 switch (AT_class (a))
4912 case dw_val_class_str:
4913 if (a->dw_attr_val.v.val_str->refcount)
4914 a->dw_attr_val.v.val_str->refcount--;
4917 case dw_val_class_lbl_id:
4918 case dw_val_class_lbl_offset:
4919 free (a->dw_attr_val.v.val_lbl_id);
4922 case dw_val_class_float:
4923 free (a->dw_attr_val.v.val_float.array);
4933 /* Remove the specified attribute if present. */
4936 remove_AT (die, attr_kind)
4938 enum dwarf_attribute attr_kind;
4941 dw_attr_ref removed = NULL;
4945 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4946 if ((*p)->dw_attr == attr_kind)
4949 *p = (*p)->dw_attr_next;
4958 /* Free up the memory used by DIE. */
4964 remove_children (die);
4968 /* Discard the children of this DIE. */
4971 remove_children (die)
4974 dw_die_ref child_die = die->die_child;
4976 die->die_child = NULL;
4978 while (child_die != NULL)
4980 dw_die_ref tmp_die = child_die;
4983 child_die = child_die->die_sib;
4985 for (a = tmp_die->die_attr; a != NULL;)
4987 dw_attr_ref tmp_a = a;
4989 a = a->dw_attr_next;
4997 /* Add a child DIE below its parent. We build the lists up in reverse
4998 addition order, and correct that in reverse_all_dies. */
5001 add_child_die (die, child_die)
5003 dw_die_ref child_die;
5005 if (die != NULL && child_die != NULL)
5007 if (die == child_die)
5010 child_die->die_parent = die;
5011 child_die->die_sib = die->die_child;
5012 die->die_child = child_die;
5016 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5017 is the specification, to the front of PARENT's list of children. */
5020 splice_child_die (parent, child)
5021 dw_die_ref parent, child;
5025 /* We want the declaration DIE from inside the class, not the
5026 specification DIE at toplevel. */
5027 if (child->die_parent != parent)
5029 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5035 if (child->die_parent != parent
5036 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
5039 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5042 *p = child->die_sib;
5046 child->die_sib = parent->die_child;
5047 parent->die_child = child;
5050 /* Return a pointer to a newly created DIE node. */
5052 static inline dw_die_ref
5053 new_die (tag_value, parent_die, t)
5054 enum dwarf_tag tag_value;
5055 dw_die_ref parent_die;
5058 dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5060 die->die_tag = tag_value;
5062 if (parent_die != NULL)
5063 add_child_die (parent_die, die);
5066 limbo_die_node *limbo_node;
5068 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5069 limbo_node->die = die;
5070 limbo_node->created_for = t;
5071 limbo_node->next = limbo_die_list;
5072 limbo_die_list = limbo_node;
5078 /* Return the DIE associated with the given type specifier. */
5080 static inline dw_die_ref
5081 lookup_type_die (type)
5084 if (TREE_CODE (type) == VECTOR_TYPE)
5085 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
5087 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
5090 /* Equate a DIE to a given type specifier. */
5093 equate_type_number_to_die (type, type_die)
5095 dw_die_ref type_die;
5097 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
5100 /* Return the DIE associated with a given declaration. */
5102 static inline dw_die_ref
5103 lookup_decl_die (decl)
5106 unsigned decl_id = DECL_UID (decl);
5108 return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
5111 /* Equate a DIE to a particular declaration. */
5114 equate_decl_number_to_die (decl, decl_die)
5116 dw_die_ref decl_die;
5118 unsigned decl_id = DECL_UID (decl);
5119 unsigned num_allocated;
5121 if (decl_id >= decl_die_table_allocated)
5124 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5125 / DECL_DIE_TABLE_INCREMENT)
5126 * DECL_DIE_TABLE_INCREMENT;
5129 = (dw_die_ref *) xrealloc (decl_die_table,
5130 sizeof (dw_die_ref) * num_allocated);
5132 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5133 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5134 decl_die_table_allocated = num_allocated;
5137 if (decl_id >= decl_die_table_in_use)
5138 decl_die_table_in_use = (decl_id + 1);
5140 decl_die_table[decl_id] = decl_die;
5143 /* Keep track of the number of spaces used to indent the
5144 output of the debugging routines that print the structure of
5145 the DIE internal representation. */
5146 static int print_indent;
5148 /* Indent the line the number of spaces given by print_indent. */
5151 print_spaces (outfile)
5154 fprintf (outfile, "%*s", print_indent, "");
5157 /* Print the information associated with a given DIE, and its children.
5158 This routine is a debugging aid only. */
5161 print_die (die, outfile)
5168 print_spaces (outfile);
5169 fprintf (outfile, "DIE %4lu: %s\n",
5170 die->die_offset, dwarf_tag_name (die->die_tag));
5171 print_spaces (outfile);
5172 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5173 fprintf (outfile, " offset: %lu\n", die->die_offset);
5175 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5177 print_spaces (outfile);
5178 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5180 switch (AT_class (a))
5182 case dw_val_class_addr:
5183 fprintf (outfile, "address");
5185 case dw_val_class_offset:
5186 fprintf (outfile, "offset");
5188 case dw_val_class_loc:
5189 fprintf (outfile, "location descriptor");
5191 case dw_val_class_loc_list:
5192 fprintf (outfile, "location list -> label:%s",
5193 AT_loc_list (a)->ll_symbol);
5195 case dw_val_class_range_list:
5196 fprintf (outfile, "range list");
5198 case dw_val_class_const:
5199 fprintf (outfile, "%ld", AT_int (a));
5201 case dw_val_class_unsigned_const:
5202 fprintf (outfile, "%lu", AT_unsigned (a));
5204 case dw_val_class_long_long:
5205 fprintf (outfile, "constant (%lu,%lu)",
5206 a->dw_attr_val.v.val_long_long.hi,
5207 a->dw_attr_val.v.val_long_long.low);
5209 case dw_val_class_float:
5210 fprintf (outfile, "floating-point constant");
5212 case dw_val_class_flag:
5213 fprintf (outfile, "%u", AT_flag (a));
5215 case dw_val_class_die_ref:
5216 if (AT_ref (a) != NULL)
5218 if (AT_ref (a)->die_symbol)
5219 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5221 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5224 fprintf (outfile, "die -> <null>");
5226 case dw_val_class_lbl_id:
5227 case dw_val_class_lbl_offset:
5228 fprintf (outfile, "label: %s", AT_lbl (a));
5230 case dw_val_class_str:
5231 if (AT_string (a) != NULL)
5232 fprintf (outfile, "\"%s\"", AT_string (a));
5234 fprintf (outfile, "<null>");
5240 fprintf (outfile, "\n");
5243 if (die->die_child != NULL)
5246 for (c = die->die_child; c != NULL; c = c->die_sib)
5247 print_die (c, outfile);
5251 if (print_indent == 0)
5252 fprintf (outfile, "\n");
5255 /* Print the contents of the source code line number correspondence table.
5256 This routine is a debugging aid only. */
5259 print_dwarf_line_table (outfile)
5263 dw_line_info_ref line_info;
5265 fprintf (outfile, "\n\nDWARF source line information\n");
5266 for (i = 1; i < line_info_table_in_use; i++)
5268 line_info = &line_info_table[i];
5269 fprintf (outfile, "%5d: ", i);
5270 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5271 fprintf (outfile, "%6ld", line_info->dw_line_num);
5272 fprintf (outfile, "\n");
5275 fprintf (outfile, "\n\n");
5278 /* Print the information collected for a given DIE. */
5281 debug_dwarf_die (die)
5284 print_die (die, stderr);
5287 /* Print all DWARF information collected for the compilation unit.
5288 This routine is a debugging aid only. */
5294 print_die (comp_unit_die, stderr);
5295 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5296 print_dwarf_line_table (stderr);
5299 /* We build up the lists of children and attributes by pushing new ones
5300 onto the beginning of the list. Reverse the lists for DIE so that
5301 they are in order of addition. */
5304 reverse_die_lists (die)
5307 dw_die_ref c, cp, cn;
5308 dw_attr_ref a, ap, an;
5310 for (a = die->die_attr, ap = 0; a; a = an)
5312 an = a->dw_attr_next;
5313 a->dw_attr_next = ap;
5319 for (c = die->die_child, cp = 0; c; c = cn)
5326 die->die_child = cp;
5329 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5330 reverse all dies in add_sibling_attributes, which runs through all the dies,
5331 it would reverse all the dies. Now, however, since we don't call
5332 reverse_die_lists in add_sibling_attributes, we need a routine to
5333 recursively reverse all the dies. This is that routine. */
5336 reverse_all_dies (die)
5341 reverse_die_lists (die);
5343 for (c = die->die_child; c; c = c->die_sib)
5344 reverse_all_dies (c);
5347 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5348 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5349 DIE that marks the start of the DIEs for this include file. */
5352 push_new_compile_unit (old_unit, bincl_die)
5353 dw_die_ref old_unit, bincl_die;
5355 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5356 dw_die_ref new_unit = gen_compile_unit_die (filename);
5358 new_unit->die_sib = old_unit;
5362 /* Close an include-file CU and reopen the enclosing one. */
5365 pop_compile_unit (old_unit)
5366 dw_die_ref old_unit;
5368 dw_die_ref new_unit = old_unit->die_sib;
5370 old_unit->die_sib = NULL;
5374 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5375 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5377 /* Calculate the checksum of a location expression. */
5380 loc_checksum (loc, ctx)
5381 dw_loc_descr_ref loc;
5382 struct md5_ctx *ctx;
5384 CHECKSUM (loc->dw_loc_opc);
5385 CHECKSUM (loc->dw_loc_oprnd1);
5386 CHECKSUM (loc->dw_loc_oprnd2);
5389 /* Calculate the checksum of an attribute. */
5392 attr_checksum (at, ctx)
5394 struct md5_ctx *ctx;
5396 dw_loc_descr_ref loc;
5399 CHECKSUM (at->dw_attr);
5401 /* We don't care about differences in file numbering. */
5402 if (at->dw_attr == DW_AT_decl_file
5403 /* Or that this was compiled with a different compiler snapshot; if
5404 the output is the same, that's what matters. */
5405 || at->dw_attr == DW_AT_producer)
5408 switch (AT_class (at))
5410 case dw_val_class_const:
5411 CHECKSUM (at->dw_attr_val.v.val_int);
5413 case dw_val_class_unsigned_const:
5414 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5416 case dw_val_class_long_long:
5417 CHECKSUM (at->dw_attr_val.v.val_long_long);
5419 case dw_val_class_float:
5420 CHECKSUM (at->dw_attr_val.v.val_float);
5422 case dw_val_class_flag:
5423 CHECKSUM (at->dw_attr_val.v.val_flag);
5425 case dw_val_class_str:
5426 CHECKSUM_STRING (AT_string (at));
5429 case dw_val_class_addr:
5431 switch (GET_CODE (r))
5434 CHECKSUM_STRING (XSTR (r, 0));
5442 case dw_val_class_offset:
5443 CHECKSUM (at->dw_attr_val.v.val_offset);
5446 case dw_val_class_loc:
5447 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5448 loc_checksum (loc, ctx);
5451 case dw_val_class_die_ref:
5452 if (AT_ref (at)->die_offset)
5453 CHECKSUM (AT_ref (at)->die_offset);
5454 /* FIXME else use target die name or something. */
5456 case dw_val_class_fde_ref:
5457 case dw_val_class_lbl_id:
5458 case dw_val_class_lbl_offset:
5466 /* Calculate the checksum of a DIE. */
5469 die_checksum (die, ctx)
5471 struct md5_ctx *ctx;
5476 CHECKSUM (die->die_tag);
5478 for (a = die->die_attr; a; a = a->dw_attr_next)
5479 attr_checksum (a, ctx);
5481 for (c = die->die_child; c; c = c->die_sib)
5482 die_checksum (c, ctx);
5486 #undef CHECKSUM_STRING
5488 /* The prefix to attach to symbols on DIEs in the current comdat debug
5490 static char *comdat_symbol_id;
5492 /* The index of the current symbol within the current comdat CU. */
5493 static unsigned int comdat_symbol_number;
5495 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5496 children, and set comdat_symbol_id accordingly. */
5499 compute_section_prefix (unit_die)
5500 dw_die_ref unit_die;
5502 const char *base = lbasename (get_AT_string (unit_die, DW_AT_name));
5503 char *name = (char *) alloca (strlen (base) + 64);
5506 unsigned char checksum[16];
5509 /* Compute the checksum of the DIE, then append part of it as hex digits to
5510 the name filename of the unit. */
5512 md5_init_ctx (&ctx);
5513 die_checksum (unit_die, &ctx);
5514 md5_finish_ctx (&ctx, checksum);
5516 sprintf (name, "%s.", base);
5517 clean_symbol_name (name);
5519 p = name + strlen (name);
5520 for (i = 0; i < 4; i++)
5522 sprintf (p, "%.2x", checksum[i]);
5526 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5527 comdat_symbol_number = 0;
5530 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5536 switch (die->die_tag)
5538 case DW_TAG_array_type:
5539 case DW_TAG_class_type:
5540 case DW_TAG_enumeration_type:
5541 case DW_TAG_pointer_type:
5542 case DW_TAG_reference_type:
5543 case DW_TAG_string_type:
5544 case DW_TAG_structure_type:
5545 case DW_TAG_subroutine_type:
5546 case DW_TAG_union_type:
5547 case DW_TAG_ptr_to_member_type:
5548 case DW_TAG_set_type:
5549 case DW_TAG_subrange_type:
5550 case DW_TAG_base_type:
5551 case DW_TAG_const_type:
5552 case DW_TAG_file_type:
5553 case DW_TAG_packed_type:
5554 case DW_TAG_volatile_type:
5561 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5562 Basically, we want to choose the bits that are likely to be shared between
5563 compilations (types) and leave out the bits that are specific to individual
5564 compilations (functions). */
5570 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5571 we do for stabs. The advantage is a greater likelihood of sharing between
5572 objects that don't include headers in the same order (and therefore would
5573 put the base types in a different comdat). jason 8/28/00 */
5575 if (c->die_tag == DW_TAG_base_type)
5578 if (c->die_tag == DW_TAG_pointer_type
5579 || c->die_tag == DW_TAG_reference_type
5580 || c->die_tag == DW_TAG_const_type
5581 || c->die_tag == DW_TAG_volatile_type)
5583 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5585 return t ? is_comdat_die (t) : 0;
5588 return is_type_die (c);
5591 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5592 compilation unit. */
5598 return (is_type_die (c)
5599 || (get_AT (c, DW_AT_declaration)
5600 && !get_AT (c, DW_AT_specification)));
5604 gen_internal_sym (prefix)
5608 static int label_num;
5610 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5611 return xstrdup (buf);
5614 /* Assign symbols to all worthy DIEs under DIE. */
5617 assign_symbol_names (die)
5622 if (is_symbol_die (die))
5624 if (comdat_symbol_id)
5626 char *p = alloca (strlen (comdat_symbol_id) + 64);
5628 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5629 comdat_symbol_id, comdat_symbol_number++);
5630 die->die_symbol = xstrdup (p);
5633 die->die_symbol = gen_internal_sym ("LDIE");
5636 for (c = die->die_child; c != NULL; c = c->die_sib)
5637 assign_symbol_names (c);
5640 /* Traverse the DIE (which is always comp_unit_die), and set up
5641 additional compilation units for each of the include files we see
5642 bracketed by BINCL/EINCL. */
5645 break_out_includes (die)
5649 dw_die_ref unit = NULL;
5650 limbo_die_node *node;
5652 for (ptr = &(die->die_child); *ptr; )
5654 dw_die_ref c = *ptr;
5656 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
5657 || (unit && is_comdat_die (c)))
5659 /* This DIE is for a secondary CU; remove it from the main one. */
5662 if (c->die_tag == DW_TAG_GNU_BINCL)
5664 unit = push_new_compile_unit (unit, c);
5667 else if (c->die_tag == DW_TAG_GNU_EINCL)
5669 unit = pop_compile_unit (unit);
5673 add_child_die (unit, c);
5677 /* Leave this DIE in the main CU. */
5678 ptr = &(c->die_sib);
5684 /* We can only use this in debugging, since the frontend doesn't check
5685 to make sure that we leave every include file we enter. */
5690 assign_symbol_names (die);
5691 for (node = limbo_die_list; node; node = node->next)
5693 compute_section_prefix (node->die);
5694 assign_symbol_names (node->die);
5698 /* Traverse the DIE and add a sibling attribute if it may have the
5699 effect of speeding up access to siblings. To save some space,
5700 avoid generating sibling attributes for DIE's without children. */
5703 add_sibling_attributes (die)
5708 if (die->die_tag != DW_TAG_compile_unit
5709 && die->die_sib && die->die_child != NULL)
5710 /* Add the sibling link to the front of the attribute list. */
5711 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5713 for (c = die->die_child; c != NULL; c = c->die_sib)
5714 add_sibling_attributes (c);
5717 /* Output all location lists for the DIE and its children. */
5720 output_location_lists (die)
5726 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5727 if (AT_class (d_attr) == dw_val_class_loc_list)
5728 output_loc_list (AT_loc_list (d_attr));
5730 for (c = die->die_child; c != NULL; c = c->die_sib)
5731 output_location_lists (c);
5734 /* The format of each DIE (and its attribute value pairs) is encoded in an
5735 abbreviation table. This routine builds the abbreviation table and assigns
5736 a unique abbreviation id for each abbreviation entry. The children of each
5737 die are visited recursively. */
5740 build_abbrev_table (die)
5743 unsigned long abbrev_id;
5744 unsigned int n_alloc;
5746 dw_attr_ref d_attr, a_attr;
5748 /* Scan the DIE references, and mark as external any that refer to
5749 DIEs from other CUs (i.e. those which are not marked). */
5750 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5751 if (AT_class (d_attr) == dw_val_class_die_ref
5752 && AT_ref (d_attr)->die_mark == 0)
5754 if (AT_ref (d_attr)->die_symbol == 0)
5757 set_AT_ref_external (d_attr, 1);
5760 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5762 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5764 if (abbrev->die_tag == die->die_tag)
5766 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5768 a_attr = abbrev->die_attr;
5769 d_attr = die->die_attr;
5771 while (a_attr != NULL && d_attr != NULL)
5773 if ((a_attr->dw_attr != d_attr->dw_attr)
5774 || (value_format (a_attr) != value_format (d_attr)))
5777 a_attr = a_attr->dw_attr_next;
5778 d_attr = d_attr->dw_attr_next;
5781 if (a_attr == NULL && d_attr == NULL)
5787 if (abbrev_id >= abbrev_die_table_in_use)
5789 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5791 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5793 = (dw_die_ref *) xrealloc (abbrev_die_table,
5794 sizeof (dw_die_ref) * n_alloc);
5796 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5797 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5798 abbrev_die_table_allocated = n_alloc;
5801 ++abbrev_die_table_in_use;
5802 abbrev_die_table[abbrev_id] = die;
5805 die->die_abbrev = abbrev_id;
5806 for (c = die->die_child; c != NULL; c = c->die_sib)
5807 build_abbrev_table (c);
5810 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5813 constant_size (value)
5814 long unsigned value;
5821 log = floor_log2 (value);
5824 log = 1 << (floor_log2 (log) + 1);
5829 /* Return the size of a DIE as it is represented in the
5830 .debug_info section. */
5832 static unsigned long
5836 unsigned long size = 0;
5839 size += size_of_uleb128 (die->die_abbrev);
5840 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5842 switch (AT_class (a))
5844 case dw_val_class_addr:
5845 size += DWARF2_ADDR_SIZE;
5847 case dw_val_class_offset:
5848 size += DWARF_OFFSET_SIZE;
5850 case dw_val_class_loc:
5852 unsigned long lsize = size_of_locs (AT_loc (a));
5855 size += constant_size (lsize);
5859 case dw_val_class_loc_list:
5860 size += DWARF_OFFSET_SIZE;
5862 case dw_val_class_range_list:
5863 size += DWARF_OFFSET_SIZE;
5865 case dw_val_class_const:
5866 size += size_of_sleb128 (AT_int (a));
5868 case dw_val_class_unsigned_const:
5869 size += constant_size (AT_unsigned (a));
5871 case dw_val_class_long_long:
5872 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5874 case dw_val_class_float:
5875 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5877 case dw_val_class_flag:
5880 case dw_val_class_die_ref:
5881 size += DWARF_OFFSET_SIZE;
5883 case dw_val_class_fde_ref:
5884 size += DWARF_OFFSET_SIZE;
5886 case dw_val_class_lbl_id:
5887 size += DWARF2_ADDR_SIZE;
5889 case dw_val_class_lbl_offset:
5890 size += DWARF_OFFSET_SIZE;
5892 case dw_val_class_str:
5893 if (AT_string_form (a) == DW_FORM_strp)
5894 size += DWARF_OFFSET_SIZE;
5896 size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1;
5906 /* Size the debugging information associated with a given DIE. Visits the
5907 DIE's children recursively. Updates the global variable next_die_offset, on
5908 each time through. Uses the current value of next_die_offset to update the
5909 die_offset field in each DIE. */
5912 calc_die_sizes (die)
5917 die->die_offset = next_die_offset;
5918 next_die_offset += size_of_die (die);
5920 for (c = die->die_child; c != NULL; c = c->die_sib)
5923 if (die->die_child != NULL)
5924 /* Count the null byte used to terminate sibling lists. */
5925 next_die_offset += 1;
5928 /* Set the marks for a die and its children. We do this so
5929 that we know whether or not a reference needs to use FORM_ref_addr; only
5930 DIEs in the same CU will be marked. We used to clear out the offset
5931 and use that as the flag, but ran into ordering problems. */
5940 for (c = die->die_child; c; c = c->die_sib)
5944 /* Clear the marks for a die and its children. */
5953 for (c = die->die_child; c; c = c->die_sib)
5957 /* Return the size of the .debug_pubnames table generated for the
5958 compilation unit. */
5960 static unsigned long
5966 size = DWARF_PUBNAMES_HEADER_SIZE;
5967 for (i = 0; i < pubname_table_in_use; i++)
5969 pubname_ref p = &pubname_table[i];
5970 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
5973 size += DWARF_OFFSET_SIZE;
5977 /* Return the size of the information in the .debug_aranges section. */
5979 static unsigned long
5984 size = DWARF_ARANGES_HEADER_SIZE;
5986 /* Count the address/length pair for this compilation unit. */
5987 size += 2 * DWARF2_ADDR_SIZE;
5988 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5990 /* Count the two zero words used to terminated the address range table. */
5991 size += 2 * DWARF2_ADDR_SIZE;
5995 /* Select the encoding of an attribute value. */
5997 static enum dwarf_form
6001 switch (a->dw_attr_val.val_class)
6003 case dw_val_class_addr:
6004 return DW_FORM_addr;
6005 case dw_val_class_range_list:
6006 case dw_val_class_offset:
6007 if (DWARF_OFFSET_SIZE == 4)
6008 return DW_FORM_data4;
6009 if (DWARF_OFFSET_SIZE == 8)
6010 return DW_FORM_data8;
6012 case dw_val_class_loc_list:
6013 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6014 .debug_loc section */
6015 return DW_FORM_data4;
6016 case dw_val_class_loc:
6017 switch (constant_size (size_of_locs (AT_loc (a))))
6020 return DW_FORM_block1;
6022 return DW_FORM_block2;
6026 case dw_val_class_const:
6027 return DW_FORM_sdata;
6028 case dw_val_class_unsigned_const:
6029 switch (constant_size (AT_unsigned (a)))
6032 return DW_FORM_data1;
6034 return DW_FORM_data2;
6036 return DW_FORM_data4;
6038 return DW_FORM_data8;
6042 case dw_val_class_long_long:
6043 return DW_FORM_block1;
6044 case dw_val_class_float:
6045 return DW_FORM_block1;
6046 case dw_val_class_flag:
6047 return DW_FORM_flag;
6048 case dw_val_class_die_ref:
6049 if (AT_ref_external (a))
6050 return DW_FORM_ref_addr;
6053 case dw_val_class_fde_ref:
6054 return DW_FORM_data;
6055 case dw_val_class_lbl_id:
6056 return DW_FORM_addr;
6057 case dw_val_class_lbl_offset:
6058 return DW_FORM_data;
6059 case dw_val_class_str:
6060 return AT_string_form (a);
6067 /* Output the encoding of an attribute value. */
6070 output_value_format (a)
6073 enum dwarf_form form = value_format (a);
6075 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6078 /* Output the .debug_abbrev section which defines the DIE abbreviation
6082 output_abbrev_section ()
6084 unsigned long abbrev_id;
6088 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6090 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6092 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6093 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6094 dwarf_tag_name (abbrev->die_tag));
6096 if (abbrev->die_child != NULL)
6097 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6099 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6101 for (a_attr = abbrev->die_attr; a_attr != NULL;
6102 a_attr = a_attr->dw_attr_next)
6104 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6105 dwarf_attr_name (a_attr->dw_attr));
6106 output_value_format (a_attr);
6109 dw2_asm_output_data (1, 0, NULL);
6110 dw2_asm_output_data (1, 0, NULL);
6113 /* Terminate the table. */
6114 dw2_asm_output_data (1, 0, NULL);
6117 /* Output a symbol we can use to refer to this DIE from another CU. */
6120 output_die_symbol (die)
6123 char *sym = die->die_symbol;
6128 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6129 /* We make these global, not weak; if the target doesn't support
6130 .linkonce, it doesn't support combining the sections, so debugging
6132 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6134 ASM_OUTPUT_LABEL (asm_out_file, sym);
6137 /* Return a new location list, given the begin and end range, and the
6138 expression. gensym tells us whether to generate a new internal symbol for
6139 this location list node, which is done for the head of the list only. */
6141 static inline dw_loc_list_ref
6142 new_loc_list (expr, begin, end, section, gensym)
6143 dw_loc_descr_ref expr;
6146 const char *section;
6149 dw_loc_list_ref retlist
6150 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6152 retlist->begin = begin;
6154 retlist->expr = expr;
6155 retlist->section = section;
6157 retlist->ll_symbol = gen_internal_sym ("LLST");
6162 /* Add a location description expression to a location list */
6165 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6166 dw_loc_list_ref *list_head;
6167 dw_loc_descr_ref descr;
6170 const char *section;
6174 /* Find the end of the chain. */
6175 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6178 /* Add a new location list node to the list */
6179 *d = new_loc_list (descr, begin, end, section, 0);
6182 /* Output the location list given to us */
6185 output_loc_list (list_head)
6186 dw_loc_list_ref list_head;
6188 dw_loc_list_ref curr = list_head;
6190 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6192 /* ??? This shouldn't be needed now that we've forced the
6193 compilation unit base address to zero when there is code
6194 in more than one section. */
6195 if (strcmp (curr->section, ".text") == 0)
6197 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6198 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
6199 "Location list base address specifier fake entry");
6200 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6201 "Location list base address specifier base");
6204 for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
6208 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6209 "Location list begin address (%s)",
6210 list_head->ll_symbol);
6211 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6212 "Location list end address (%s)",
6213 list_head->ll_symbol);
6214 size = size_of_locs (curr->expr);
6216 /* Output the block length for this list of location operations. */
6219 dw2_asm_output_data (2, size, "%s", "Location expression size");
6221 output_loc_sequence (curr->expr);
6224 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6225 "Location list terminator begin (%s)",
6226 list_head->ll_symbol);
6227 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6228 "Location list terminator end (%s)",
6229 list_head->ll_symbol);
6232 /* Output the DIE and its attributes. Called recursively to generate
6233 the definitions of each child DIE. */
6243 /* If someone in another CU might refer to us, set up a symbol for
6244 them to point to. */
6245 if (die->die_symbol)
6246 output_die_symbol (die);
6248 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6249 die->die_offset, dwarf_tag_name (die->die_tag));
6251 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6253 const char *name = dwarf_attr_name (a->dw_attr);
6255 switch (AT_class (a))
6257 case dw_val_class_addr:
6258 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6261 case dw_val_class_offset:
6262 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6266 case dw_val_class_range_list:
6268 char *p = strchr (ranges_section_label, '\0');
6270 sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset);
6271 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6277 case dw_val_class_loc:
6278 size = size_of_locs (AT_loc (a));
6280 /* Output the block length for this list of location operations. */
6281 dw2_asm_output_data (constant_size (size), size, "%s", name);
6283 output_loc_sequence (AT_loc (a));
6286 case dw_val_class_const:
6287 /* ??? It would be slightly more efficient to use a scheme like is
6288 used for unsigned constants below, but gdb 4.x does not sign
6289 extend. Gdb 5.x does sign extend. */
6290 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6293 case dw_val_class_unsigned_const:
6294 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6295 AT_unsigned (a), "%s", name);
6298 case dw_val_class_long_long:
6300 unsigned HOST_WIDE_INT first, second;
6302 dw2_asm_output_data (1,
6303 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6306 if (WORDS_BIG_ENDIAN)
6308 first = a->dw_attr_val.v.val_long_long.hi;
6309 second = a->dw_attr_val.v.val_long_long.low;
6313 first = a->dw_attr_val.v.val_long_long.low;
6314 second = a->dw_attr_val.v.val_long_long.hi;
6317 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6318 first, "long long constant");
6319 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6324 case dw_val_class_float:
6328 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6331 for (i = 0; i < a->dw_attr_val.v.val_float.length; i++)
6332 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6333 "fp constant word %u", i);
6337 case dw_val_class_flag:
6338 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6341 case dw_val_class_loc_list:
6343 char *sym = AT_loc_list (a)->ll_symbol;
6347 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6348 loc_section_label, "%s", name);
6352 case dw_val_class_die_ref:
6353 if (AT_ref_external (a))
6355 char *sym = AT_ref (a)->die_symbol;
6359 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6361 else if (AT_ref (a)->die_offset == 0)
6364 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6368 case dw_val_class_fde_ref:
6372 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6373 a->dw_attr_val.v.val_fde_index * 2);
6374 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6378 case dw_val_class_lbl_id:
6379 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6382 case dw_val_class_lbl_offset:
6383 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6386 case dw_val_class_str:
6387 if (AT_string_form (a) == DW_FORM_strp)
6388 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6389 a->dw_attr_val.v.val_str->label,
6390 "%s: \"%s\"", name, AT_string (a));
6392 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6400 for (c = die->die_child; c != NULL; c = c->die_sib)
6403 /* Add null byte to terminate sibling list. */
6404 if (die->die_child != NULL)
6405 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6409 /* Output the compilation unit that appears at the beginning of the
6410 .debug_info section, and precedes the DIE descriptions. */
6413 output_compilation_unit_header ()
6415 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6416 "Length of Compilation Unit Info");
6417 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6418 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6419 "Offset Into Abbrev. Section");
6420 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6423 /* Output the compilation unit DIE and its children. */
6426 output_comp_unit (die)
6429 const char *secname;
6431 /* Even if there are no children of this DIE, we must output the information
6432 about the compilation unit. Otherwise, on an empty translation unit, we
6433 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6434 will then complain when examining the file. First mark all the DIEs in
6435 this CU so we know which get local refs. */
6438 build_abbrev_table (die);
6440 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6441 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6442 calc_die_sizes (die);
6444 if (die->die_symbol)
6446 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6448 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6450 die->die_symbol = NULL;
6453 secname = (const char *) DEBUG_INFO_SECTION;
6455 /* Output debugging information. */
6456 named_section_flags (secname, SECTION_DEBUG);
6457 output_compilation_unit_header ();
6460 /* Leave the marks on the main CU, so we can check them in
6462 if (die->die_symbol)
6466 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6467 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6468 argument list, and maybe the scope. */
6471 dwarf2_name (decl, scope)
6475 return (*decl_printable_name) (decl, scope ? 1 : 0);
6478 /* Add a new entry to .debug_pubnames if appropriate. */
6481 add_pubname (decl, die)
6487 if (! TREE_PUBLIC (decl))
6490 if (pubname_table_in_use == pubname_table_allocated)
6492 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6494 = (pubname_ref) xrealloc (pubname_table,
6495 (pubname_table_allocated
6496 * sizeof (pubname_entry)));
6499 p = &pubname_table[pubname_table_in_use++];
6501 p->name = xstrdup (dwarf2_name (decl, 1));
6504 /* Output the public names table used to speed up access to externally
6505 visible names. For now, only generate entries for externally
6506 visible procedures. */
6512 unsigned long pubnames_length = size_of_pubnames ();
6514 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6515 "Length of Public Names Info");
6516 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6517 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6518 "Offset of Compilation Unit Info");
6519 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6520 "Compilation Unit Length");
6522 for (i = 0; i < pubname_table_in_use; i++)
6524 pubname_ref pub = &pubname_table[i];
6526 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6527 if (pub->die->die_mark == 0)
6530 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6533 dw2_asm_output_nstring (pub->name, -1, "external name");
6536 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6539 /* Add a new entry to .debug_aranges if appropriate. */
6542 add_arange (decl, die)
6546 if (! DECL_SECTION_NAME (decl))
6549 if (arange_table_in_use == arange_table_allocated)
6551 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6552 arange_table = (dw_die_ref *)
6553 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6556 arange_table[arange_table_in_use++] = die;
6559 /* Output the information that goes into the .debug_aranges table.
6560 Namely, define the beginning and ending address range of the
6561 text section generated for this compilation unit. */
6567 unsigned long aranges_length = size_of_aranges ();
6569 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6570 "Length of Address Ranges Info");
6571 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6572 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6573 "Offset of Compilation Unit Info");
6574 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6575 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6577 /* We need to align to twice the pointer size here. */
6578 if (DWARF_ARANGES_PAD_SIZE)
6580 /* Pad using a 2 byte words so that padding is correct for any
6582 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6583 2 * DWARF2_ADDR_SIZE);
6584 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6585 dw2_asm_output_data (2, 0, NULL);
6588 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6589 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6590 text_section_label, "Length");
6592 for (i = 0; i < arange_table_in_use; i++)
6594 dw_die_ref die = arange_table[i];
6596 /* We shouldn't see aranges for DIEs outside of the main CU. */
6597 if (die->die_mark == 0)
6600 if (die->die_tag == DW_TAG_subprogram)
6602 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6604 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6605 get_AT_low_pc (die), "Length");
6609 /* A static variable; extract the symbol from DW_AT_location.
6610 Note that this code isn't currently hit, as we only emit
6611 aranges for functions (jason 9/23/99). */
6612 dw_attr_ref a = get_AT (die, DW_AT_location);
6613 dw_loc_descr_ref loc;
6615 if (! a || AT_class (a) != dw_val_class_loc)
6619 if (loc->dw_loc_opc != DW_OP_addr)
6622 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6623 loc->dw_loc_oprnd1.v.val_addr, "Address");
6624 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6625 get_AT_unsigned (die, DW_AT_byte_size),
6630 /* Output the terminator words. */
6631 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6632 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6635 /* Add a new entry to .debug_ranges. Return the offset at which it
6642 unsigned int in_use = ranges_table_in_use;
6644 if (in_use == ranges_table_allocated)
6646 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6647 ranges_table = (dw_ranges_ref)
6648 xrealloc (ranges_table, (ranges_table_allocated
6649 * sizeof (struct dw_ranges_struct)));
6652 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6653 ranges_table_in_use = in_use + 1;
6655 return in_use * 2 * DWARF2_ADDR_SIZE;
6662 static const char *const start_fmt = "Offset 0x%x";
6663 const char *fmt = start_fmt;
6665 for (i = 0; i < ranges_table_in_use; i++)
6667 int block_num = ranges_table[i].block_num;
6671 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6672 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6674 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6675 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6677 /* If all code is in the text section, then the compilation
6678 unit base address defaults to DW_AT_low_pc, which is the
6679 base of the text section. */
6680 if (separate_line_info_table_in_use == 0)
6682 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6684 fmt, i * 2 * DWARF2_ADDR_SIZE);
6685 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6686 text_section_label, NULL);
6689 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6690 compilation unit base address to zero, which allows us to
6691 use absolute addresses, and not worry about whether the
6692 target supports cross-section arithmetic. */
6695 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6696 fmt, i * 2 * DWARF2_ADDR_SIZE);
6697 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6704 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6705 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6711 /* Data structure containing information about input files. */
6714 char *path; /* Complete file name. */
6715 char *fname; /* File name part. */
6716 int length; /* Length of entire string. */
6717 int file_idx; /* Index in input file table. */
6718 int dir_idx; /* Index in directory table. */
6721 /* Data structure containing information about directories with source
6725 char *path; /* Path including directory name. */
6726 int length; /* Path length. */
6727 int prefix; /* Index of directory entry which is a prefix. */
6728 int count; /* Number of files in this directory. */
6729 int dir_idx; /* Index of directory used as base. */
6730 int used; /* Used in the end? */
6733 /* Callback function for file_info comparison. We sort by looking at
6734 the directories in the path. */
6737 file_info_cmp (p1, p2)
6741 const struct file_info *s1 = p1;
6742 const struct file_info *s2 = p2;
6746 /* Take care of file names without directories. We need to make sure that
6747 we return consistent values to qsort since some will get confused if
6748 we return the same value when identical operands are passed in opposite
6749 orders. So if neither has a directory, return 0 and otherwise return
6750 1 or -1 depending on which one has the directory. */
6751 if ((s1->path == s1->fname || s2->path == s2->fname))
6752 return (s2->path == s2->fname) - (s1->path == s1->fname);
6754 cp1 = (unsigned char *) s1->path;
6755 cp2 = (unsigned char *) s2->path;
6761 /* Reached the end of the first path? If so, handle like above. */
6762 if ((cp1 == (unsigned char *) s1->fname)
6763 || (cp2 == (unsigned char *) s2->fname))
6764 return ((cp2 == (unsigned char *) s2->fname)
6765 - (cp1 == (unsigned char *) s1->fname));
6767 /* Character of current path component the same? */
6768 else if (*cp1 != *cp2)
6773 /* Output the directory table and the file name table. We try to minimize
6774 the total amount of memory needed. A heuristic is used to avoid large
6775 slowdowns with many input files. */
6778 output_file_names ()
6780 struct file_info *files;
6781 struct dir_info *dirs;
6790 /* Allocate the various arrays we need. */
6791 files = (struct file_info *) alloca (file_table.in_use
6792 * sizeof (struct file_info));
6793 dirs = (struct dir_info *) alloca (file_table.in_use
6794 * sizeof (struct dir_info));
6796 /* Sort the file names. */
6797 for (i = 1; i < (int) file_table.in_use; i++)
6801 /* Skip all leading "./". */
6802 f = file_table.table[i];
6803 while (f[0] == '.' && f[1] == '/')
6806 /* Create a new array entry. */
6808 files[i].length = strlen (f);
6809 files[i].file_idx = i;
6811 /* Search for the file name part. */
6812 f = strrchr (f, '/');
6813 files[i].fname = f == NULL ? files[i].path : f + 1;
6816 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6818 /* Find all the different directories used. */
6819 dirs[0].path = files[1].path;
6820 dirs[0].length = files[1].fname - files[1].path;
6821 dirs[0].prefix = -1;
6823 dirs[0].dir_idx = 0;
6825 files[1].dir_idx = 0;
6828 for (i = 2; i < (int) file_table.in_use; i++)
6829 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6830 && memcmp (dirs[ndirs - 1].path, files[i].path,
6831 dirs[ndirs - 1].length) == 0)
6833 /* Same directory as last entry. */
6834 files[i].dir_idx = ndirs - 1;
6835 ++dirs[ndirs - 1].count;
6841 /* This is a new directory. */
6842 dirs[ndirs].path = files[i].path;
6843 dirs[ndirs].length = files[i].fname - files[i].path;
6844 dirs[ndirs].count = 1;
6845 dirs[ndirs].dir_idx = ndirs;
6846 dirs[ndirs].used = 0;
6847 files[i].dir_idx = ndirs;
6849 /* Search for a prefix. */
6850 dirs[ndirs].prefix = -1;
6851 for (j = 0; j < ndirs; j++)
6852 if (dirs[j].length < dirs[ndirs].length
6853 && dirs[j].length > 1
6854 && (dirs[ndirs].prefix == -1
6855 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6856 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6857 dirs[ndirs].prefix = j;
6862 /* Now to the actual work. We have to find a subset of the directories which
6863 allow expressing the file name using references to the directory table
6864 with the least amount of characters. We do not do an exhaustive search
6865 where we would have to check out every combination of every single
6866 possible prefix. Instead we use a heuristic which provides nearly optimal
6867 results in most cases and never is much off. */
6868 saved = (int *) alloca (ndirs * sizeof (int));
6869 savehere = (int *) alloca (ndirs * sizeof (int));
6871 memset (saved, '\0', ndirs * sizeof (saved[0]));
6872 for (i = 0; i < ndirs; i++)
6877 /* We can always save some space for the current directory. But this
6878 does not mean it will be enough to justify adding the directory. */
6879 savehere[i] = dirs[i].length;
6880 total = (savehere[i] - saved[i]) * dirs[i].count;
6882 for (j = i + 1; j < ndirs; j++)
6885 if (saved[j] < dirs[i].length)
6887 /* Determine whether the dirs[i] path is a prefix of the
6892 while (k != -1 && k != i)
6897 /* Yes it is. We can possibly safe some memory but
6898 writing the filenames in dirs[j] relative to
6900 savehere[j] = dirs[i].length;
6901 total += (savehere[j] - saved[j]) * dirs[j].count;
6906 /* Check whether we can safe enough to justify adding the dirs[i]
6908 if (total > dirs[i].length + 1)
6910 /* It's worthwhile adding. */
6911 for (j = i; j < ndirs; j++)
6912 if (savehere[j] > 0)
6914 /* Remember how much we saved for this directory so far. */
6915 saved[j] = savehere[j];
6917 /* Remember the prefix directory. */
6918 dirs[j].dir_idx = i;
6923 /* We have to emit them in the order they appear in the file_table array
6924 since the index is used in the debug info generation. To do this
6925 efficiently we generate a back-mapping of the indices first. */
6926 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6927 for (i = 1; i < (int) file_table.in_use; i++)
6929 backmap[files[i].file_idx] = i;
6931 /* Mark this directory as used. */
6932 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6935 /* That was it. We are ready to emit the information. First emit the
6936 directory name table. We have to make sure the first actually emitted
6937 directory name has index one; zero is reserved for the current working
6938 directory. Make sure we do not confuse these indices with the one for the
6939 constructed table (even though most of the time they are identical). */
6941 idx_offset = dirs[0].length > 0 ? 1 : 0;
6942 for (i = 1 - idx_offset; i < ndirs; i++)
6943 if (dirs[i].used != 0)
6945 dirs[i].used = idx++;
6946 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6947 "Directory Entry: 0x%x", dirs[i].used);
6950 dw2_asm_output_data (1, 0, "End directory table");
6952 /* Correct the index for the current working directory entry if it
6954 if (idx_offset == 0)
6957 /* Now write all the file names. */
6958 for (i = 1; i < (int) file_table.in_use; i++)
6960 int file_idx = backmap[i];
6961 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6963 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6964 "File Entry: 0x%x", i);
6966 /* Include directory index. */
6967 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6969 /* Modification time. */
6970 dw2_asm_output_data_uleb128 (0, NULL);
6972 /* File length in bytes. */
6973 dw2_asm_output_data_uleb128 (0, NULL);
6976 dw2_asm_output_data (1, 0, "End file name table");
6980 /* Output the source line number correspondence information. This
6981 information goes into the .debug_line section. */
6986 char l1[20], l2[20], p1[20], p2[20];
6987 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6988 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6991 unsigned long lt_index;
6992 unsigned long current_line;
6995 unsigned long current_file;
6996 unsigned long function;
6998 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6999 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7000 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7001 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7003 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7004 "Length of Source Line Info");
7005 ASM_OUTPUT_LABEL (asm_out_file, l1);
7007 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7008 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7009 ASM_OUTPUT_LABEL (asm_out_file, p1);
7011 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
7012 "Minimum Instruction Length");
7013 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7014 "Default is_stmt_start flag");
7015 dw2_asm_output_data (1, DWARF_LINE_BASE,
7016 "Line Base Value (Special Opcodes)");
7017 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7018 "Line Range Value (Special Opcodes)");
7019 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7020 "Special Opcode Base");
7022 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7026 case DW_LNS_advance_pc:
7027 case DW_LNS_advance_line:
7028 case DW_LNS_set_file:
7029 case DW_LNS_set_column:
7030 case DW_LNS_fixed_advance_pc:
7038 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7042 /* Write out the information about the files we use. */
7043 output_file_names ();
7044 ASM_OUTPUT_LABEL (asm_out_file, p2);
7046 /* We used to set the address register to the first location in the text
7047 section here, but that didn't accomplish anything since we already
7048 have a line note for the opening brace of the first function. */
7050 /* Generate the line number to PC correspondence table, encoded as
7051 a series of state machine operations. */
7054 strcpy (prev_line_label, text_section_label);
7055 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7057 dw_line_info_ref line_info = &line_info_table[lt_index];
7060 /* Disable this optimization for now; GDB wants to see two line notes
7061 at the beginning of a function so it can find the end of the
7064 /* Don't emit anything for redundant notes. Just updating the
7065 address doesn't accomplish anything, because we already assume
7066 that anything after the last address is this line. */
7067 if (line_info->dw_line_num == current_line
7068 && line_info->dw_file_num == current_file)
7072 /* Emit debug info for the address of the current line.
7074 Unfortunately, we have little choice here currently, and must always
7075 use the most general form. GCC does not know the address delta
7076 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7077 attributes which will give an upper bound on the address range. We
7078 could perhaps use length attributes to determine when it is safe to
7079 use DW_LNS_fixed_advance_pc. */
7081 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7084 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7085 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7086 "DW_LNS_fixed_advance_pc");
7087 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7091 /* This can handle any delta. This takes
7092 4+DWARF2_ADDR_SIZE bytes. */
7093 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7094 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7095 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7096 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7099 strcpy (prev_line_label, line_label);
7101 /* Emit debug info for the source file of the current line, if
7102 different from the previous line. */
7103 if (line_info->dw_file_num != current_file)
7105 current_file = line_info->dw_file_num;
7106 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7107 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7108 file_table.table[current_file]);
7111 /* Emit debug info for the current line number, choosing the encoding
7112 that uses the least amount of space. */
7113 if (line_info->dw_line_num != current_line)
7115 line_offset = line_info->dw_line_num - current_line;
7116 line_delta = line_offset - DWARF_LINE_BASE;
7117 current_line = line_info->dw_line_num;
7118 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7119 /* This can handle deltas from -10 to 234, using the current
7120 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7122 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7123 "line %lu", current_line);
7126 /* This can handle any delta. This takes at least 4 bytes,
7127 depending on the value being encoded. */
7128 dw2_asm_output_data (1, DW_LNS_advance_line,
7129 "advance to line %lu", current_line);
7130 dw2_asm_output_data_sleb128 (line_offset, NULL);
7131 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7135 /* We still need to start a new row, so output a copy insn. */
7136 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7139 /* Emit debug info for the address of the end of the function. */
7142 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7143 "DW_LNS_fixed_advance_pc");
7144 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7148 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7149 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7150 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7151 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7154 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7155 dw2_asm_output_data_uleb128 (1, NULL);
7156 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7161 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7163 dw_separate_line_info_ref line_info
7164 = &separate_line_info_table[lt_index];
7167 /* Don't emit anything for redundant notes. */
7168 if (line_info->dw_line_num == current_line
7169 && line_info->dw_file_num == current_file
7170 && line_info->function == function)
7174 /* Emit debug info for the address of the current line. If this is
7175 a new function, or the first line of a function, then we need
7176 to handle it differently. */
7177 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7179 if (function != line_info->function)
7181 function = line_info->function;
7183 /* Set the address register to the first line in the function */
7184 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7185 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7186 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7187 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7191 /* ??? See the DW_LNS_advance_pc comment above. */
7194 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7195 "DW_LNS_fixed_advance_pc");
7196 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7200 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7201 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7202 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7203 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7207 strcpy (prev_line_label, line_label);
7209 /* Emit debug info for the source file of the current line, if
7210 different from the previous line. */
7211 if (line_info->dw_file_num != current_file)
7213 current_file = line_info->dw_file_num;
7214 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7215 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7216 file_table.table[current_file]);
7219 /* Emit debug info for the current line number, choosing the encoding
7220 that uses the least amount of space. */
7221 if (line_info->dw_line_num != current_line)
7223 line_offset = line_info->dw_line_num - current_line;
7224 line_delta = line_offset - DWARF_LINE_BASE;
7225 current_line = line_info->dw_line_num;
7226 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7227 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7228 "line %lu", current_line);
7231 dw2_asm_output_data (1, DW_LNS_advance_line,
7232 "advance to line %lu", current_line);
7233 dw2_asm_output_data_sleb128 (line_offset, NULL);
7234 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7238 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7246 /* If we're done with a function, end its sequence. */
7247 if (lt_index == separate_line_info_table_in_use
7248 || separate_line_info_table[lt_index].function != function)
7253 /* Emit debug info for the address of the end of the function. */
7254 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7257 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7258 "DW_LNS_fixed_advance_pc");
7259 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7263 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7264 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7265 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7266 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7269 /* Output the marker for the end of this sequence. */
7270 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7271 dw2_asm_output_data_uleb128 (1, NULL);
7272 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7276 /* Output the marker for the end of the line number info. */
7277 ASM_OUTPUT_LABEL (asm_out_file, l2);
7280 /* Given a pointer to a tree node for some base type, return a pointer to
7281 a DIE that describes the given type.
7283 This routine must only be called for GCC type nodes that correspond to
7284 Dwarf base (fundamental) types. */
7287 base_type_die (type)
7290 dw_die_ref base_type_result;
7291 const char *type_name;
7292 enum dwarf_type encoding;
7293 tree name = TYPE_NAME (type);
7295 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7300 if (TREE_CODE (name) == TYPE_DECL)
7301 name = DECL_NAME (name);
7303 type_name = IDENTIFIER_POINTER (name);
7306 type_name = "__unknown__";
7308 switch (TREE_CODE (type))
7311 /* Carefully distinguish the C character types, without messing
7312 up if the language is not C. Note that we check only for the names
7313 that contain spaces; other names might occur by coincidence in other
7315 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7316 && (type == char_type_node
7317 || ! strcmp (type_name, "signed char")
7318 || ! strcmp (type_name, "unsigned char"))))
7320 if (TREE_UNSIGNED (type))
7321 encoding = DW_ATE_unsigned;
7323 encoding = DW_ATE_signed;
7326 /* else fall through. */
7329 /* GNU Pascal/Ada CHAR type. Not used in C. */
7330 if (TREE_UNSIGNED (type))
7331 encoding = DW_ATE_unsigned_char;
7333 encoding = DW_ATE_signed_char;
7337 encoding = DW_ATE_float;
7340 /* Dwarf2 doesn't know anything about complex ints, so use
7341 a user defined type for it. */
7343 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7344 encoding = DW_ATE_complex_float;
7346 encoding = DW_ATE_lo_user;
7350 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7351 encoding = DW_ATE_boolean;
7355 /* No other TREE_CODEs are Dwarf fundamental types. */
7359 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
7360 if (demangle_name_func)
7361 type_name = (*demangle_name_func) (type_name);
7363 add_AT_string (base_type_result, DW_AT_name, type_name);
7364 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7365 int_size_in_bytes (type));
7366 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7368 return base_type_result;
7371 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7372 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7373 a given type is generally the same as the given type, except that if the
7374 given type is a pointer or reference type, then the root type of the given
7375 type is the root type of the "basis" type for the pointer or reference
7376 type. (This definition of the "root" type is recursive.) Also, the root
7377 type of a `const' qualified type or a `volatile' qualified type is the
7378 root type of the given type without the qualifiers. */
7384 if (TREE_CODE (type) == ERROR_MARK)
7385 return error_mark_node;
7387 switch (TREE_CODE (type))
7390 return error_mark_node;
7393 case REFERENCE_TYPE:
7394 return type_main_variant (root_type (TREE_TYPE (type)));
7397 return type_main_variant (type);
7401 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7402 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7408 switch (TREE_CODE (type))
7423 case QUAL_UNION_TYPE:
7428 case REFERENCE_TYPE:
7442 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7443 entry that chains various modifiers in front of the given type. */
7446 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7449 int is_volatile_type;
7450 dw_die_ref context_die;
7452 enum tree_code code = TREE_CODE (type);
7453 dw_die_ref mod_type_die = NULL;
7454 dw_die_ref sub_die = NULL;
7455 tree item_type = NULL;
7457 if (code != ERROR_MARK)
7459 tree qualified_type;
7461 /* See if we already have the appropriately qualified variant of
7464 = get_qualified_type (type,
7465 ((is_const_type ? TYPE_QUAL_CONST : 0)
7467 ? TYPE_QUAL_VOLATILE : 0)));
7469 /* If we do, then we can just use its DIE, if it exists. */
7472 mod_type_die = lookup_type_die (qualified_type);
7474 return mod_type_die;
7477 /* Handle C typedef types. */
7478 if (qualified_type && TYPE_NAME (qualified_type)
7479 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7480 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7482 tree type_name = TYPE_NAME (qualified_type);
7483 tree dtype = TREE_TYPE (type_name);
7485 if (qualified_type == dtype)
7487 /* For a named type, use the typedef. */
7488 gen_type_die (qualified_type, context_die);
7489 mod_type_die = lookup_type_die (qualified_type);
7491 else if (is_const_type < TYPE_READONLY (dtype)
7492 || is_volatile_type < TYPE_VOLATILE (dtype))
7493 /* cv-unqualified version of named type. Just use the unnamed
7494 type to which it refers. */
7496 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7497 is_const_type, is_volatile_type,
7500 /* Else cv-qualified version of named type; fall through. */
7506 else if (is_const_type)
7508 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
7509 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7511 else if (is_volatile_type)
7513 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
7514 sub_die = modified_type_die (type, 0, 0, context_die);
7516 else if (code == POINTER_TYPE)
7518 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
7519 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7521 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7523 item_type = TREE_TYPE (type);
7525 else if (code == REFERENCE_TYPE)
7527 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
7528 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7530 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7532 item_type = TREE_TYPE (type);
7534 else if (is_base_type (type))
7535 mod_type_die = base_type_die (type);
7538 gen_type_die (type, context_die);
7540 /* We have to get the type_main_variant here (and pass that to the
7541 `lookup_type_die' routine) because the ..._TYPE node we have
7542 might simply be a *copy* of some original type node (where the
7543 copy was created to help us keep track of typedef names) and
7544 that copy might have a different TYPE_UID from the original
7546 mod_type_die = lookup_type_die (type_main_variant (type));
7547 if (mod_type_die == NULL)
7551 /* We want to equate the qualified type to the die below. */
7553 type = qualified_type;
7556 equate_type_number_to_die (type, mod_type_die);
7558 /* We must do this after the equate_type_number_to_die call, in case
7559 this is a recursive type. This ensures that the modified_type_die
7560 recursion will terminate even if the type is recursive. Recursive
7561 types are possible in Ada. */
7562 sub_die = modified_type_die (item_type,
7563 TYPE_READONLY (item_type),
7564 TYPE_VOLATILE (item_type),
7567 if (sub_die != NULL)
7568 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7570 return mod_type_die;
7573 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7574 an enumerated type. */
7580 return TREE_CODE (type) == ENUMERAL_TYPE;
7583 /* Return the register number described by a given RTL node. */
7589 unsigned regno = REGNO (rtl);
7591 if (regno >= FIRST_PSEUDO_REGISTER)
7594 return DBX_REGISTER_NUMBER (regno);
7597 /* Return a location descriptor that designates a machine register or
7598 zero if there is no such. */
7600 static dw_loc_descr_ref
7601 reg_loc_descriptor (rtl)
7604 dw_loc_descr_ref loc_result = NULL;
7607 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7610 reg = reg_number (rtl);
7612 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7614 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7619 /* Return a location descriptor that designates a constant. */
7621 static dw_loc_descr_ref
7622 int_loc_descriptor (i)
7625 enum dwarf_location_atom op;
7627 /* Pick the smallest representation of a constant, rather than just
7628 defaulting to the LEB encoding. */
7632 op = DW_OP_lit0 + i;
7635 else if (i <= 0xffff)
7637 else if (HOST_BITS_PER_WIDE_INT == 32
7647 else if (i >= -0x8000)
7649 else if (HOST_BITS_PER_WIDE_INT == 32
7650 || i >= -0x80000000)
7656 return new_loc_descr (op, i, 0);
7659 /* Return a location descriptor that designates a base+offset location. */
7661 static dw_loc_descr_ref
7662 based_loc_descr (reg, offset)
7666 dw_loc_descr_ref loc_result;
7667 /* For the "frame base", we use the frame pointer or stack pointer
7668 registers, since the RTL for local variables is relative to one of
7670 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7671 ? HARD_FRAME_POINTER_REGNUM
7672 : STACK_POINTER_REGNUM);
7675 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7677 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7679 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7684 /* Return true if this RTL expression describes a base+offset calculation. */
7690 return (GET_CODE (rtl) == PLUS
7691 && ((GET_CODE (XEXP (rtl, 0)) == REG
7692 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
7693 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7696 /* The following routine converts the RTL for a variable or parameter
7697 (resident in memory) into an equivalent Dwarf representation of a
7698 mechanism for getting the address of that same variable onto the top of a
7699 hypothetical "address evaluation" stack.
7701 When creating memory location descriptors, we are effectively transforming
7702 the RTL for a memory-resident object into its Dwarf postfix expression
7703 equivalent. This routine recursively descends an RTL tree, turning
7704 it into Dwarf postfix code as it goes.
7706 MODE is the mode of the memory reference, needed to handle some
7707 autoincrement addressing modes.
7709 Return 0 if we can't represent the location. */
7711 static dw_loc_descr_ref
7712 mem_loc_descriptor (rtl, mode)
7714 enum machine_mode mode;
7716 dw_loc_descr_ref mem_loc_result = NULL;
7718 /* Note that for a dynamically sized array, the location we will generate a
7719 description of here will be the lowest numbered location which is
7720 actually within the array. That's *not* necessarily the same as the
7721 zeroth element of the array. */
7723 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7724 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7727 switch (GET_CODE (rtl))
7732 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7733 just fall into the SUBREG code. */
7735 /* ... fall through ... */
7738 /* The case of a subreg may arise when we have a local (register)
7739 variable or a formal (register) parameter which doesn't quite fill
7740 up an entire register. For now, just assume that it is
7741 legitimate to make the Dwarf info refer to the whole register which
7742 contains the given subreg. */
7743 rtl = SUBREG_REG (rtl);
7745 /* ... fall through ... */
7748 /* Whenever a register number forms a part of the description of the
7749 method for calculating the (dynamic) address of a memory resident
7750 object, DWARF rules require the register number be referred to as
7751 a "base register". This distinction is not based in any way upon
7752 what category of register the hardware believes the given register
7753 belongs to. This is strictly DWARF terminology we're dealing with
7754 here. Note that in cases where the location of a memory-resident
7755 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7756 OP_CONST (0)) the actual DWARF location descriptor that we generate
7757 may just be OP_BASEREG (basereg). This may look deceptively like
7758 the object in question was allocated to a register (rather than in
7759 memory) so DWARF consumers need to be aware of the subtle
7760 distinction between OP_REG and OP_BASEREG. */
7761 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
7762 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7766 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7767 if (mem_loc_result != 0)
7768 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7772 /* Some ports can transform a symbol ref into a label ref, because
7773 the symbol ref is too far away and has to be dumped into a constant
7777 /* Alternatively, the symbol in the constant pool might be referenced
7778 by a different symbol. */
7779 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
7781 rtx tmp = get_pool_constant (rtl);
7783 if (GET_CODE (tmp) == SYMBOL_REF)
7787 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7788 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7789 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
7790 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
7794 /* Extract the PLUS expression nested inside and fall into
7796 rtl = XEXP (rtl, 1);
7801 /* Turn these into a PLUS expression and fall into the PLUS code
7803 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7804 GEN_INT (GET_CODE (rtl) == PRE_INC
7805 ? GET_MODE_UNIT_SIZE (mode)
7806 : -GET_MODE_UNIT_SIZE (mode)));
7808 /* ... fall through ... */
7812 if (is_based_loc (rtl))
7813 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7814 INTVAL (XEXP (rtl, 1)));
7817 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7818 if (mem_loc_result == 0)
7821 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7822 && INTVAL (XEXP (rtl, 1)) >= 0)
7823 add_loc_descr (&mem_loc_result,
7824 new_loc_descr (DW_OP_plus_uconst,
7825 INTVAL (XEXP (rtl, 1)), 0));
7828 add_loc_descr (&mem_loc_result,
7829 mem_loc_descriptor (XEXP (rtl, 1), mode));
7830 add_loc_descr (&mem_loc_result,
7831 new_loc_descr (DW_OP_plus, 0, 0));
7838 /* If a pseudo-reg is optimized away, it is possible for it to
7839 be replaced with a MEM containing a multiply. */
7840 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
7841 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
7843 if (op0 == 0 || op1 == 0)
7846 mem_loc_result = op0;
7847 add_loc_descr (&mem_loc_result, op1);
7848 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7853 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7860 return mem_loc_result;
7863 /* Return a descriptor that describes the concatenation of two locations.
7864 This is typically a complex variable. */
7866 static dw_loc_descr_ref
7867 concat_loc_descriptor (x0, x1)
7870 dw_loc_descr_ref cc_loc_result = NULL;
7871 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
7872 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
7874 if (x0_ref == 0 || x1_ref == 0)
7877 cc_loc_result = x0_ref;
7878 add_loc_descr (&cc_loc_result,
7879 new_loc_descr (DW_OP_piece,
7880 GET_MODE_SIZE (GET_MODE (x0)), 0));
7882 add_loc_descr (&cc_loc_result, x1_ref);
7883 add_loc_descr (&cc_loc_result,
7884 new_loc_descr (DW_OP_piece,
7885 GET_MODE_SIZE (GET_MODE (x1)), 0));
7887 return cc_loc_result;
7890 /* Output a proper Dwarf location descriptor for a variable or parameter
7891 which is either allocated in a register or in a memory location. For a
7892 register, we just generate an OP_REG and the register number. For a
7893 memory location we provide a Dwarf postfix expression describing how to
7894 generate the (dynamic) address of the object onto the address stack.
7896 If we don't know how to describe it, return 0. */
7898 static dw_loc_descr_ref
7899 loc_descriptor (rtl)
7902 dw_loc_descr_ref loc_result = NULL;
7904 switch (GET_CODE (rtl))
7907 /* The case of a subreg may arise when we have a local (register)
7908 variable or a formal (register) parameter which doesn't quite fill
7909 up an entire register. For now, just assume that it is
7910 legitimate to make the Dwarf info refer to the whole register which
7911 contains the given subreg. */
7912 rtl = SUBREG_REG (rtl);
7914 /* ... fall through ... */
7917 loc_result = reg_loc_descriptor (rtl);
7921 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7925 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7935 /* Similar, but generate the descriptor from trees instead of rtl. This comes
7936 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
7937 looking for an address. Otherwise, we return a value. If we can't make a
7938 descriptor, return 0. */
7940 static dw_loc_descr_ref
7941 loc_descriptor_from_tree (loc, addressp)
7945 dw_loc_descr_ref ret, ret1;
7947 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7948 enum dwarf_location_atom op;
7950 /* ??? Most of the time we do not take proper care for sign/zero
7951 extending the values properly. Hopefully this won't be a real
7954 switch (TREE_CODE (loc))
7959 case WITH_RECORD_EXPR:
7960 case PLACEHOLDER_EXPR:
7961 /* This case involves extracting fields from an object to determine the
7962 position of other fields. We don't try to encode this here. The
7963 only user of this is Ada, which encodes the needed information using
7964 the names of types. */
7970 rtx rtl = rtl_for_decl_location (loc);
7972 if (rtl == NULL_RTX)
7974 else if (CONSTANT_P (rtl))
7976 ret = new_loc_descr (DW_OP_addr, 0, 0);
7977 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7978 ret->dw_loc_oprnd1.v.val_addr = rtl;
7983 enum machine_mode mode = GET_MODE (rtl);
7985 if (GET_CODE (rtl) == MEM)
7988 rtl = XEXP (rtl, 0);
7991 ret = mem_loc_descriptor (rtl, mode);
7997 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8002 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
8006 case NON_LVALUE_EXPR:
8007 case VIEW_CONVERT_EXPR:
8009 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8014 case ARRAY_RANGE_REF:
8017 HOST_WIDE_INT bitsize, bitpos, bytepos;
8018 enum machine_mode mode;
8021 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8022 &unsignedp, &volatilep);
8027 ret = loc_descriptor_from_tree (obj, 1);
8029 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
8032 if (offset != NULL_TREE)
8034 /* Variable offset. */
8035 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8036 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8042 bytepos = bitpos / BITS_PER_UNIT;
8044 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8045 else if (bytepos < 0)
8047 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8048 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8054 if (host_integerp (loc, 0))
8055 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8072 case TRUNC_DIV_EXPR:
8080 case TRUNC_MOD_EXPR:
8093 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8097 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8098 && host_integerp (TREE_OPERAND (loc, 1), 0))
8100 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8104 add_loc_descr (&ret,
8105 new_loc_descr (DW_OP_plus_uconst,
8106 tree_low_cst (TREE_OPERAND (loc, 1),
8116 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8123 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8130 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8137 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8152 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8153 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8154 if (ret == 0 || ret1 == 0)
8157 add_loc_descr (&ret, ret1);
8158 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8174 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8178 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8182 loc = build (COND_EXPR, TREE_TYPE (loc),
8183 build (LT_EXPR, integer_type_node,
8184 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8185 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8187 /* ... fall through ... */
8191 dw_loc_descr_ref lhs
8192 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8193 dw_loc_descr_ref rhs
8194 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8195 dw_loc_descr_ref bra_node, jump_node, tmp;
8197 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8198 if (ret == 0 || lhs == 0 || rhs == 0)
8201 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8202 add_loc_descr (&ret, bra_node);
8204 add_loc_descr (&ret, rhs);
8205 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8206 add_loc_descr (&ret, jump_node);
8208 add_loc_descr (&ret, lhs);
8209 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8210 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
8212 /* ??? Need a node to point the skip at. Use a nop. */
8213 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8214 add_loc_descr (&ret, tmp);
8215 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8216 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8224 /* Show if we can't fill the request for an address. */
8225 if (addressp && indirect_p == 0)
8228 /* If we've got an address and don't want one, dereference. */
8229 if (!addressp && indirect_p > 0)
8231 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8233 if (size > DWARF2_ADDR_SIZE || size == -1)
8235 else if (size == DWARF2_ADDR_SIZE)
8238 op = DW_OP_deref_size;
8240 add_loc_descr (&ret, new_loc_descr (op, size, 0));
8246 /* Given a value, round it up to the lowest multiple of `boundary'
8247 which is not less than the value itself. */
8249 static inline HOST_WIDE_INT
8250 ceiling (value, boundary)
8251 HOST_WIDE_INT value;
8252 unsigned int boundary;
8254 return (((value + boundary - 1) / boundary) * boundary);
8257 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8258 pointer to the declared type for the relevant field variable, or return
8259 `integer_type_node' if the given node turns out to be an
8268 if (TREE_CODE (decl) == ERROR_MARK)
8269 return integer_type_node;
8271 type = DECL_BIT_FIELD_TYPE (decl);
8272 if (type == NULL_TREE)
8273 type = TREE_TYPE (decl);
8278 /* Given a pointer to a tree node, return the alignment in bits for
8279 it, or else return BITS_PER_WORD if the node actually turns out to
8280 be an ERROR_MARK node. */
8282 static inline unsigned
8283 simple_type_align_in_bits (type)
8286 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8289 static inline unsigned
8290 simple_decl_align_in_bits (decl)
8293 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8296 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8297 node, return the size in bits for the type if it is a constant, or else
8298 return the alignment for the type if the type's size is not constant, or
8299 else return BITS_PER_WORD if the type actually turns out to be an
8302 static inline unsigned HOST_WIDE_INT
8303 simple_type_size_in_bits (type)
8307 if (TREE_CODE (type) == ERROR_MARK)
8308 return BITS_PER_WORD;
8309 else if (TYPE_SIZE (type) == NULL_TREE)
8311 else if (host_integerp (TYPE_SIZE (type), 1))
8312 return tree_low_cst (TYPE_SIZE (type), 1);
8314 return TYPE_ALIGN (type);
8317 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8318 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8319 or return 0 if we are unable to determine what that offset is, either
8320 because the argument turns out to be a pointer to an ERROR_MARK node, or
8321 because the offset is actually variable. (We can't handle the latter case
8324 static HOST_WIDE_INT
8325 field_byte_offset (decl)
8328 unsigned int type_align_in_bits;
8329 unsigned int decl_align_in_bits;
8330 unsigned HOST_WIDE_INT type_size_in_bits;
8331 HOST_WIDE_INT object_offset_in_bits;
8333 tree field_size_tree;
8334 HOST_WIDE_INT bitpos_int;
8335 HOST_WIDE_INT deepest_bitpos;
8336 unsigned HOST_WIDE_INT field_size_in_bits;
8338 if (TREE_CODE (decl) == ERROR_MARK)
8340 else if (TREE_CODE (decl) != FIELD_DECL)
8343 type = field_type (decl);
8344 field_size_tree = DECL_SIZE (decl);
8346 /* The size could be unspecified if there was an error, or for
8347 a flexible array member. */
8348 if (! field_size_tree)
8349 field_size_tree = bitsize_zero_node;
8351 /* We cannot yet cope with fields whose positions are variable, so
8352 for now, when we see such things, we simply return 0. Someday, we may
8353 be able to handle such cases, but it will be damn difficult. */
8354 if (! host_integerp (bit_position (decl), 0))
8357 bitpos_int = int_bit_position (decl);
8359 /* If we don't know the size of the field, pretend it's a full word. */
8360 if (host_integerp (field_size_tree, 1))
8361 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8363 field_size_in_bits = BITS_PER_WORD;
8365 type_size_in_bits = simple_type_size_in_bits (type);
8366 type_align_in_bits = simple_type_align_in_bits (type);
8367 decl_align_in_bits = simple_decl_align_in_bits (decl);
8369 /* The GCC front-end doesn't make any attempt to keep track of the starting
8370 bit offset (relative to the start of the containing structure type) of the
8371 hypothetical "containing object" for a bit-field. Thus, when computing
8372 the byte offset value for the start of the "containing object" of a
8373 bit-field, we must deduce this information on our own. This can be rather
8374 tricky to do in some cases. For example, handling the following structure
8375 type definition when compiling for an i386/i486 target (which only aligns
8376 long long's to 32-bit boundaries) can be very tricky:
8378 struct S { int field1; long long field2:31; };
8380 Fortunately, there is a simple rule-of-thumb which can be used in such
8381 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8382 structure shown above. It decides to do this based upon one simple rule
8383 for bit-field allocation. GCC allocates each "containing object" for each
8384 bit-field at the first (i.e. lowest addressed) legitimate alignment
8385 boundary (based upon the required minimum alignment for the declared type
8386 of the field) which it can possibly use, subject to the condition that
8387 there is still enough available space remaining in the containing object
8388 (when allocated at the selected point) to fully accommodate all of the
8389 bits of the bit-field itself.
8391 This simple rule makes it obvious why GCC allocates 8 bytes for each
8392 object of the structure type shown above. When looking for a place to
8393 allocate the "containing object" for `field2', the compiler simply tries
8394 to allocate a 64-bit "containing object" at each successive 32-bit
8395 boundary (starting at zero) until it finds a place to allocate that 64-
8396 bit field such that at least 31 contiguous (and previously unallocated)
8397 bits remain within that selected 64 bit field. (As it turns out, for the
8398 example above, the compiler finds it is OK to allocate the "containing
8399 object" 64-bit field at bit-offset zero within the structure type.)
8401 Here we attempt to work backwards from the limited set of facts we're
8402 given, and we try to deduce from those facts, where GCC must have believed
8403 that the containing object started (within the structure type). The value
8404 we deduce is then used (by the callers of this routine) to generate
8405 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8406 and, in the case of DW_AT_location, regular fields as well). */
8408 /* Figure out the bit-distance from the start of the structure to the
8409 "deepest" bit of the bit-field. */
8410 deepest_bitpos = bitpos_int + field_size_in_bits;
8412 /* This is the tricky part. Use some fancy footwork to deduce where the
8413 lowest addressed bit of the containing object must be. */
8414 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8416 /* Round up to type_align by default. This works best for bitfields. */
8417 object_offset_in_bits += type_align_in_bits - 1;
8418 object_offset_in_bits /= type_align_in_bits;
8419 object_offset_in_bits *= type_align_in_bits;
8421 if (object_offset_in_bits > bitpos_int)
8423 /* Sigh, the decl must be packed. */
8424 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8426 /* Round up to decl_align instead. */
8427 object_offset_in_bits += decl_align_in_bits - 1;
8428 object_offset_in_bits /= decl_align_in_bits;
8429 object_offset_in_bits *= decl_align_in_bits;
8432 return object_offset_in_bits / BITS_PER_UNIT;
8435 /* The following routines define various Dwarf attributes and any data
8436 associated with them. */
8438 /* Add a location description attribute value to a DIE.
8440 This emits location attributes suitable for whole variables and
8441 whole parameters. Note that the location attributes for struct fields are
8442 generated by the routine `data_member_location_attribute' below. */
8445 add_AT_location_description (die, attr_kind, rtl)
8447 enum dwarf_attribute attr_kind;
8450 dw_loc_descr_ref descr = loc_descriptor (rtl);
8453 add_AT_loc (die, attr_kind, descr);
8456 /* Attach the specialized form of location attribute used for data members of
8457 struct and union types. In the special case of a FIELD_DECL node which
8458 represents a bit-field, the "offset" part of this special location
8459 descriptor must indicate the distance in bytes from the lowest-addressed
8460 byte of the containing struct or union type to the lowest-addressed byte of
8461 the "containing object" for the bit-field. (See the `field_byte_offset'
8464 For any given bit-field, the "containing object" is a hypothetical object
8465 (of some integral or enum type) within which the given bit-field lives. The
8466 type of this hypothetical "containing object" is always the same as the
8467 declared type of the individual bit-field itself (for GCC anyway... the
8468 DWARF spec doesn't actually mandate this). Note that it is the size (in
8469 bytes) of the hypothetical "containing object" which will be given in the
8470 DW_AT_byte_size attribute for this bit-field. (See the
8471 `byte_size_attribute' function below.) It is also used when calculating the
8472 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8476 add_data_member_location_attribute (die, decl)
8481 dw_loc_descr_ref loc_descr = 0;
8483 if (TREE_CODE (decl) == TREE_VEC)
8485 /* We're working on the TAG_inheritance for a base class. */
8486 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
8488 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8489 aren't at a fixed offset from all (sub)objects of the same
8490 type. We need to extract the appropriate offset from our
8491 vtable. The following dwarf expression means
8493 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8495 This is specific to the V3 ABI, of course. */
8497 dw_loc_descr_ref tmp;
8499 /* Make a copy of the object address. */
8500 tmp = new_loc_descr (DW_OP_dup, 0, 0);
8501 add_loc_descr (&loc_descr, tmp);
8503 /* Extract the vtable address. */
8504 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8505 add_loc_descr (&loc_descr, tmp);
8507 /* Calculate the address of the offset. */
8508 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
8512 tmp = int_loc_descriptor (-offset);
8513 add_loc_descr (&loc_descr, tmp);
8514 tmp = new_loc_descr (DW_OP_minus, 0, 0);
8515 add_loc_descr (&loc_descr, tmp);
8517 /* Extract the offset. */
8518 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8519 add_loc_descr (&loc_descr, tmp);
8521 /* Add it to the object address. */
8522 tmp = new_loc_descr (DW_OP_plus, 0, 0);
8523 add_loc_descr (&loc_descr, tmp);
8526 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8529 offset = field_byte_offset (decl);
8533 enum dwarf_location_atom op;
8535 /* The DWARF2 standard says that we should assume that the structure
8536 address is already on the stack, so we can specify a structure field
8537 address by using DW_OP_plus_uconst. */
8539 #ifdef MIPS_DEBUGGING_INFO
8540 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8541 operator correctly. It works only if we leave the offset on the
8545 op = DW_OP_plus_uconst;
8548 loc_descr = new_loc_descr (op, offset, 0);
8551 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8554 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8555 does not have a "location" either in memory or in a register. These
8556 things can arise in GNU C when a constant is passed as an actual parameter
8557 to an inlined function. They can also arise in C++ where declared
8558 constants do not necessarily get memory "homes". */
8561 add_const_value_attribute (die, rtl)
8565 switch (GET_CODE (rtl))
8568 /* Note that a CONST_INT rtx could represent either an integer
8569 or a floating-point constant. A CONST_INT is used whenever
8570 the constant will fit into a single word. In all such
8571 cases, the original mode of the constant value is wiped
8572 out, and the CONST_INT rtx is assigned VOIDmode. */
8574 HOST_WIDE_INT val = INTVAL (rtl);
8576 /* ??? We really should be using HOST_WIDE_INT throughout. */
8577 if (val < 0 && (long) val == val)
8578 add_AT_int (die, DW_AT_const_value, (long) val);
8579 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
8580 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8583 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8584 add_AT_long_long (die, DW_AT_const_value,
8585 val >> HOST_BITS_PER_LONG, val);
8594 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8595 floating-point constant. A CONST_DOUBLE is used whenever the
8596 constant requires more than one word in order to be adequately
8597 represented. We output CONST_DOUBLEs as blocks. */
8599 enum machine_mode mode = GET_MODE (rtl);
8601 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8603 unsigned length = GET_MODE_SIZE (mode) / 4;
8604 long *array = (long *) xmalloc (sizeof (long) * length);
8607 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8611 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8615 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8620 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8627 add_AT_float (die, DW_AT_const_value, length, array);
8631 /* ??? We really should be using HOST_WIDE_INT throughout. */
8632 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8635 add_AT_long_long (die, DW_AT_const_value,
8636 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8642 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8648 add_AT_addr (die, DW_AT_const_value, rtl);
8649 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
8653 /* In cases where an inlined instance of an inline function is passed
8654 the address of an `auto' variable (which is local to the caller) we
8655 can get a situation where the DECL_RTL of the artificial local
8656 variable (for the inlining) which acts as a stand-in for the
8657 corresponding formal parameter (of the inline function) will look
8658 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8659 exactly a compile-time constant expression, but it isn't the address
8660 of the (artificial) local variable either. Rather, it represents the
8661 *value* which the artificial local variable always has during its
8662 lifetime. We currently have no way to represent such quasi-constant
8663 values in Dwarf, so for now we just punt and generate nothing. */
8667 /* No other kinds of rtx should be possible here. */
8674 rtl_for_decl_location (decl)
8679 /* Here we have to decide where we are going to say the parameter "lives"
8680 (as far as the debugger is concerned). We only have a couple of
8681 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8683 DECL_RTL normally indicates where the parameter lives during most of the
8684 activation of the function. If optimization is enabled however, this
8685 could be either NULL or else a pseudo-reg. Both of those cases indicate
8686 that the parameter doesn't really live anywhere (as far as the code
8687 generation parts of GCC are concerned) during most of the function's
8688 activation. That will happen (for example) if the parameter is never
8689 referenced within the function.
8691 We could just generate a location descriptor here for all non-NULL
8692 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8693 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8694 where DECL_RTL is NULL or is a pseudo-reg.
8696 Note however that we can only get away with using DECL_INCOMING_RTL as
8697 a backup substitute for DECL_RTL in certain limited cases. In cases
8698 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8699 we can be sure that the parameter was passed using the same type as it is
8700 declared to have within the function, and that its DECL_INCOMING_RTL
8701 points us to a place where a value of that type is passed.
8703 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8704 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8705 because in these cases DECL_INCOMING_RTL points us to a value of some
8706 type which is *different* from the type of the parameter itself. Thus,
8707 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8708 such cases, the debugger would end up (for example) trying to fetch a
8709 `float' from a place which actually contains the first part of a
8710 `double'. That would lead to really incorrect and confusing
8711 output at debug-time.
8713 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8714 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8715 are a couple of exceptions however. On little-endian machines we can
8716 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8717 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8718 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8719 when (on a little-endian machine) a non-prototyped function has a
8720 parameter declared to be of type `short' or `char'. In such cases,
8721 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8722 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8723 passed `int' value. If the debugger then uses that address to fetch
8724 a `short' or a `char' (on a little-endian machine) the result will be
8725 the correct data, so we allow for such exceptional cases below.
8727 Note that our goal here is to describe the place where the given formal
8728 parameter lives during most of the function's activation (i.e. between the
8729 end of the prologue and the start of the epilogue). We'll do that as best
8730 as we can. Note however that if the given formal parameter is modified
8731 sometime during the execution of the function, then a stack backtrace (at
8732 debug-time) will show the function as having been called with the *new*
8733 value rather than the value which was originally passed in. This happens
8734 rarely enough that it is not a major problem, but it *is* a problem, and
8737 A future version of dwarf2out.c may generate two additional attributes for
8738 any given DW_TAG_formal_parameter DIE which will describe the "passed
8739 type" and the "passed location" for the given formal parameter in addition
8740 to the attributes we now generate to indicate the "declared type" and the
8741 "active location" for each parameter. This additional set of attributes
8742 could be used by debuggers for stack backtraces. Separately, note that
8743 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8744 This happens (for example) for inlined-instances of inline function formal
8745 parameters which are never referenced. This really shouldn't be
8746 happening. All PARM_DECL nodes should get valid non-NULL
8747 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8748 values for inlined instances of inline function parameters, so when we see
8749 such cases, we are just out-of-luck for the time being (until integrate.c
8752 /* Use DECL_RTL as the "location" unless we find something better. */
8753 rtl = DECL_RTL_IF_SET (decl);
8755 /* When generating abstract instances, ignore everything except
8756 constants and symbols living in memory. */
8757 if (! reload_completed)
8760 && (CONSTANT_P (rtl)
8761 || (GET_CODE (rtl) == MEM
8762 && CONSTANT_P (XEXP (rtl, 0)))))
8766 else if (TREE_CODE (decl) == PARM_DECL)
8768 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8770 tree declared_type = type_main_variant (TREE_TYPE (decl));
8771 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8773 /* This decl represents a formal parameter which was optimized out.
8774 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8775 all cases where (rtl == NULL_RTX) just below. */
8776 if (declared_type == passed_type)
8777 rtl = DECL_INCOMING_RTL (decl);
8778 else if (! BYTES_BIG_ENDIAN
8779 && TREE_CODE (declared_type) == INTEGER_TYPE
8780 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8781 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8782 rtl = DECL_INCOMING_RTL (decl);
8785 /* If the parm was passed in registers, but lives on the stack, then
8786 make a big endian correction if the mode of the type of the
8787 parameter is not the same as the mode of the rtl. */
8788 /* ??? This is the same series of checks that are made in dbxout.c before
8789 we reach the big endian correction code there. It isn't clear if all
8790 of these checks are necessary here, but keeping them all is the safe
8792 else if (GET_CODE (rtl) == MEM
8793 && XEXP (rtl, 0) != const0_rtx
8794 && ! CONSTANT_P (XEXP (rtl, 0))
8795 /* Not passed in memory. */
8796 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8797 /* Not passed by invisible reference. */
8798 && (GET_CODE (XEXP (rtl, 0)) != REG
8799 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8800 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8801 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8802 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8805 /* Big endian correction check. */
8807 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8808 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8811 int offset = (UNITS_PER_WORD
8812 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8814 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8815 plus_constant (XEXP (rtl, 0), offset));
8819 if (rtl != NULL_RTX)
8821 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8822 #ifdef LEAF_REG_REMAP
8823 if (current_function_uses_only_leaf_regs)
8824 leaf_renumber_regs_insn (rtl);
8828 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8829 and will have been substituted directly into all expressions that use it.
8830 C does not have such a concept, but C++ and other languages do. */
8831 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
8832 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
8833 EXPAND_INITIALIZER);
8838 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8839 data attribute for a variable or a parameter. We generate the
8840 DW_AT_const_value attribute only in those cases where the given variable
8841 or parameter does not have a true "location" either in memory or in a
8842 register. This can happen (for example) when a constant is passed as an
8843 actual argument in a call to an inline function. (It's possible that
8844 these things can crop up in other ways also.) Note that one type of
8845 constant value which can be passed into an inlined function is a constant
8846 pointer. This can happen for example if an actual argument in an inlined
8847 function call evaluates to a compile-time constant address. */
8850 add_location_or_const_value_attribute (die, decl)
8856 if (TREE_CODE (decl) == ERROR_MARK)
8858 else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8861 rtl = rtl_for_decl_location (decl);
8862 if (rtl == NULL_RTX)
8865 /* If we don't look past the constant pool, we risk emitting a
8866 reference to a constant pool entry that isn't referenced from
8867 code, and thus is not emitted. */
8868 rtl = avoid_constant_pool_reference (rtl);
8870 switch (GET_CODE (rtl))
8873 /* The address of a variable that was optimized away; don't emit
8884 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8885 add_const_value_attribute (die, rtl);
8892 add_AT_location_description (die, DW_AT_location, rtl);
8900 /* If we don't have a copy of this variable in memory for some reason (such
8901 as a C++ member constant that doesn't have an out-of-line definition),
8902 we should tell the debugger about the constant value. */
8905 tree_add_const_value_attribute (var_die, decl)
8909 tree init = DECL_INITIAL (decl);
8910 tree type = TREE_TYPE (decl);
8912 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8913 && initializer_constant_valid_p (init, type) == null_pointer_node)
8918 switch (TREE_CODE (type))
8921 if (host_integerp (init, 0))
8922 add_AT_unsigned (var_die, DW_AT_const_value,
8923 tree_low_cst (init, 0));
8925 add_AT_long_long (var_die, DW_AT_const_value,
8926 TREE_INT_CST_HIGH (init),
8927 TREE_INT_CST_LOW (init));
8934 /* Generate an DW_AT_name attribute given some string value to be included as
8935 the value of the attribute. */
8938 add_name_attribute (die, name_string)
8940 const char *name_string;
8942 if (name_string != NULL && *name_string != 0)
8944 if (demangle_name_func)
8945 name_string = (*demangle_name_func) (name_string);
8947 add_AT_string (die, DW_AT_name, name_string);
8951 /* Given a tree node describing an array bound (either lower or upper) output
8952 a representation for that bound. */
8955 add_bound_info (subrange_die, bound_attr, bound)
8956 dw_die_ref subrange_die;
8957 enum dwarf_attribute bound_attr;
8960 switch (TREE_CODE (bound))
8965 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8967 if (! host_integerp (bound, 0)
8968 || (bound_attr == DW_AT_lower_bound
8969 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8970 || (is_fortran () && integer_onep (bound)))))
8971 /* use the default */
8974 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8979 case NON_LVALUE_EXPR:
8980 case VIEW_CONVERT_EXPR:
8981 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8985 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8986 access the upper bound values may be bogus. If they refer to a
8987 register, they may only describe how to get at these values at the
8988 points in the generated code right after they have just been
8989 computed. Worse yet, in the typical case, the upper bound values
8990 will not even *be* computed in the optimized code (though the
8991 number of elements will), so these SAVE_EXPRs are entirely
8992 bogus. In order to compensate for this fact, we check here to see
8993 if optimization is enabled, and if so, we don't add an attribute
8994 for the (unknown and unknowable) upper bound. This should not
8995 cause too much trouble for existing (stupid?) debuggers because
8996 they have to deal with empty upper bounds location descriptions
8997 anyway in order to be able to deal with incomplete array types.
8998 Of course an intelligent debugger (GDB?) should be able to
8999 comprehend that a missing upper bound specification in an array
9000 type used for a storage class `auto' local array variable
9001 indicates that the upper bound is both unknown (at compile- time)
9002 and unknowable (at run-time) due to optimization.
9004 We assume that a MEM rtx is safe because gcc wouldn't put the
9005 value there unless it was going to be used repeatedly in the
9006 function, i.e. for cleanups. */
9007 if (SAVE_EXPR_RTL (bound)
9008 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9010 dw_die_ref ctx = lookup_decl_die (current_function_decl);
9011 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound);
9012 rtx loc = SAVE_EXPR_RTL (bound);
9014 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9015 it references an outer function's frame. */
9016 if (GET_CODE (loc) == MEM)
9018 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9020 if (XEXP (loc, 0) != new_addr)
9021 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9024 add_AT_flag (decl_die, DW_AT_artificial, 1);
9025 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9026 add_AT_location_description (decl_die, DW_AT_location, loc);
9027 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9030 /* Else leave out the attribute. */
9036 dw_die_ref decl_die = lookup_decl_die (bound);
9038 /* ??? Can this happen, or should the variable have been bound
9039 first? Probably it can, since I imagine that we try to create
9040 the types of parameters in the order in which they exist in
9041 the list, and won't have created a forward reference to a
9043 if (decl_die != NULL)
9044 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9050 /* Otherwise try to create a stack operation procedure to
9051 evaluate the value of the array bound. */
9053 dw_die_ref ctx, decl_die;
9054 dw_loc_descr_ref loc;
9056 loc = loc_descriptor_from_tree (bound, 0);
9060 if (current_function_decl == 0)
9061 ctx = comp_unit_die;
9063 ctx = lookup_decl_die (current_function_decl);
9065 decl_die = new_die (DW_TAG_variable, ctx, bound);
9066 add_AT_flag (decl_die, DW_AT_artificial, 1);
9067 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9068 add_AT_loc (decl_die, DW_AT_location, loc);
9070 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9076 /* Note that the block of subscript information for an array type also
9077 includes information about the element type of type given array type. */
9080 add_subscript_info (type_die, type)
9081 dw_die_ref type_die;
9084 #ifndef MIPS_DEBUGGING_INFO
9085 unsigned dimension_number;
9088 dw_die_ref subrange_die;
9090 /* The GNU compilers represent multidimensional array types as sequences of
9091 one dimensional array types whose element types are themselves array
9092 types. Here we squish that down, so that each multidimensional array
9093 type gets only one array_type DIE in the Dwarf debugging info. The draft
9094 Dwarf specification say that we are allowed to do this kind of
9095 compression in C (because there is no difference between an array or
9096 arrays and a multidimensional array in C) but for other source languages
9097 (e.g. Ada) we probably shouldn't do this. */
9099 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9100 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9101 We work around this by disabling this feature. See also
9102 gen_array_type_die. */
9103 #ifndef MIPS_DEBUGGING_INFO
9104 for (dimension_number = 0;
9105 TREE_CODE (type) == ARRAY_TYPE;
9106 type = TREE_TYPE (type), dimension_number++)
9109 tree domain = TYPE_DOMAIN (type);
9111 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9112 and (in GNU C only) variable bounds. Handle all three forms
9114 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
9117 /* We have an array type with specified bounds. */
9118 lower = TYPE_MIN_VALUE (domain);
9119 upper = TYPE_MAX_VALUE (domain);
9121 /* define the index type. */
9122 if (TREE_TYPE (domain))
9124 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9125 TREE_TYPE field. We can't emit debug info for this
9126 because it is an unnamed integral type. */
9127 if (TREE_CODE (domain) == INTEGER_TYPE
9128 && TYPE_NAME (domain) == NULL_TREE
9129 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9130 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9133 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9137 /* ??? If upper is NULL, the array has unspecified length,
9138 but it does have a lower bound. This happens with Fortran
9140 Since the debugger is definitely going to need to know N
9141 to produce useful results, go ahead and output the lower
9142 bound solo, and hope the debugger can cope. */
9144 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9146 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9149 /* Otherwise we have an array type with an unspecified length. The
9150 DWARF-2 spec does not say how to handle this; let's just leave out the
9156 add_byte_size_attribute (die, tree_node)
9162 switch (TREE_CODE (tree_node))
9170 case QUAL_UNION_TYPE:
9171 size = int_size_in_bytes (tree_node);
9174 /* For a data member of a struct or union, the DW_AT_byte_size is
9175 generally given as the number of bytes normally allocated for an
9176 object of the *declared* type of the member itself. This is true
9177 even for bit-fields. */
9178 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9184 /* Note that `size' might be -1 when we get to this point. If it is, that
9185 indicates that the byte size of the entity in question is variable. We
9186 have no good way of expressing this fact in Dwarf at the present time,
9187 so just let the -1 pass on through. */
9188 add_AT_unsigned (die, DW_AT_byte_size, size);
9191 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9192 which specifies the distance in bits from the highest order bit of the
9193 "containing object" for the bit-field to the highest order bit of the
9196 For any given bit-field, the "containing object" is a hypothetical object
9197 (of some integral or enum type) within which the given bit-field lives. The
9198 type of this hypothetical "containing object" is always the same as the
9199 declared type of the individual bit-field itself. The determination of the
9200 exact location of the "containing object" for a bit-field is rather
9201 complicated. It's handled by the `field_byte_offset' function (above).
9203 Note that it is the size (in bytes) of the hypothetical "containing object"
9204 which will be given in the DW_AT_byte_size attribute for this bit-field.
9205 (See `byte_size_attribute' above). */
9208 add_bit_offset_attribute (die, decl)
9212 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9213 tree type = DECL_BIT_FIELD_TYPE (decl);
9214 HOST_WIDE_INT bitpos_int;
9215 HOST_WIDE_INT highest_order_object_bit_offset;
9216 HOST_WIDE_INT highest_order_field_bit_offset;
9217 HOST_WIDE_INT unsigned bit_offset;
9219 /* Must be a field and a bit field. */
9221 || TREE_CODE (decl) != FIELD_DECL)
9224 /* We can't yet handle bit-fields whose offsets are variable, so if we
9225 encounter such things, just return without generating any attribute
9226 whatsoever. Likewise for variable or too large size. */
9227 if (! host_integerp (bit_position (decl), 0)
9228 || ! host_integerp (DECL_SIZE (decl), 1))
9231 bitpos_int = int_bit_position (decl);
9233 /* Note that the bit offset is always the distance (in bits) from the
9234 highest-order bit of the "containing object" to the highest-order bit of
9235 the bit-field itself. Since the "high-order end" of any object or field
9236 is different on big-endian and little-endian machines, the computation
9237 below must take account of these differences. */
9238 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9239 highest_order_field_bit_offset = bitpos_int;
9241 if (! BYTES_BIG_ENDIAN)
9243 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9244 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9248 = (! BYTES_BIG_ENDIAN
9249 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9250 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9252 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9255 /* For a FIELD_DECL node which represents a bit field, output an attribute
9256 which specifies the length in bits of the given field. */
9259 add_bit_size_attribute (die, decl)
9263 /* Must be a field and a bit field. */
9264 if (TREE_CODE (decl) != FIELD_DECL
9265 || ! DECL_BIT_FIELD_TYPE (decl))
9268 if (host_integerp (DECL_SIZE (decl), 1))
9269 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9272 /* If the compiled language is ANSI C, then add a 'prototyped'
9273 attribute, if arg types are given for the parameters of a function. */
9276 add_prototyped_attribute (die, func_type)
9280 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9281 && TYPE_ARG_TYPES (func_type) != NULL)
9282 add_AT_flag (die, DW_AT_prototyped, 1);
9285 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9286 by looking in either the type declaration or object declaration
9290 add_abstract_origin_attribute (die, origin)
9294 dw_die_ref origin_die = NULL;
9296 if (TREE_CODE (origin) != FUNCTION_DECL)
9298 /* We may have gotten separated from the block for the inlined
9299 function, if we're in an exception handler or some such; make
9300 sure that the abstract function has been written out.
9302 Doing this for nested functions is wrong, however; functions are
9303 distinct units, and our context might not even be inline. */
9307 fn = TYPE_STUB_DECL (fn);
9309 fn = decl_function_context (fn);
9311 dwarf2out_abstract_function (fn);
9314 if (DECL_P (origin))
9315 origin_die = lookup_decl_die (origin);
9316 else if (TYPE_P (origin))
9317 origin_die = lookup_type_die (origin);
9319 if (origin_die == NULL)
9322 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9325 /* We do not currently support the pure_virtual attribute. */
9328 add_pure_or_virtual_attribute (die, func_decl)
9332 if (DECL_VINDEX (func_decl))
9334 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9336 if (host_integerp (DECL_VINDEX (func_decl), 0))
9337 add_AT_loc (die, DW_AT_vtable_elem_location,
9338 new_loc_descr (DW_OP_constu,
9339 tree_low_cst (DECL_VINDEX (func_decl), 0),
9342 /* GNU extension: Record what type this method came from originally. */
9343 if (debug_info_level > DINFO_LEVEL_TERSE)
9344 add_AT_die_ref (die, DW_AT_containing_type,
9345 lookup_type_die (DECL_CONTEXT (func_decl)));
9349 /* Add source coordinate attributes for the given decl. */
9352 add_src_coords_attributes (die, decl)
9356 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9358 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9359 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9362 /* Add an DW_AT_name attribute and source coordinate attribute for the
9363 given decl, but only if it actually has a name. */
9366 add_name_and_src_coords_attributes (die, decl)
9372 decl_name = DECL_NAME (decl);
9373 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9375 add_name_attribute (die, dwarf2_name (decl, 0));
9376 if (! DECL_ARTIFICIAL (decl))
9377 add_src_coords_attributes (die, decl);
9379 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9380 && TREE_PUBLIC (decl)
9381 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9382 && !DECL_ABSTRACT (decl))
9383 add_AT_string (die, DW_AT_MIPS_linkage_name,
9384 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9387 #ifdef VMS_DEBUGGING_INFO
9388 /* Get the function's name, as described by its RTL. This may be different
9389 from the DECL_NAME name used in the source file. */
9390 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
9392 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
9393 XEXP (DECL_RTL (decl), 0));
9394 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
9399 /* Push a new declaration scope. */
9402 push_decl_scope (scope)
9405 VARRAY_PUSH_TREE (decl_scope_table, scope);
9408 /* Pop a declaration scope. */
9413 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9416 VARRAY_POP (decl_scope_table);
9419 /* Return the DIE for the scope that immediately contains this type.
9420 Non-named types get global scope. Named types nested in other
9421 types get their containing scope if it's open, or global scope
9422 otherwise. All other types (i.e. function-local named types) get
9423 the current active scope. */
9426 scope_die_for (t, context_die)
9428 dw_die_ref context_die;
9430 dw_die_ref scope_die = NULL;
9431 tree containing_scope;
9434 /* Non-types always go in the current scope. */
9438 containing_scope = TYPE_CONTEXT (t);
9440 /* Ignore namespaces for the moment. */
9441 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9442 containing_scope = NULL_TREE;
9444 /* Ignore function type "scopes" from the C frontend. They mean that
9445 a tagged type is local to a parmlist of a function declarator, but
9446 that isn't useful to DWARF. */
9447 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9448 containing_scope = NULL_TREE;
9450 if (containing_scope == NULL_TREE)
9451 scope_die = comp_unit_die;
9452 else if (TYPE_P (containing_scope))
9454 /* For types, we can just look up the appropriate DIE. But
9455 first we check to see if we're in the middle of emitting it
9456 so we know where the new DIE should go. */
9457 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9458 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
9463 if (debug_info_level > DINFO_LEVEL_TERSE
9464 && !TREE_ASM_WRITTEN (containing_scope))
9467 /* If none of the current dies are suitable, we get file scope. */
9468 scope_die = comp_unit_die;
9471 scope_die = lookup_type_die (containing_scope);
9474 scope_die = context_die;
9479 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9482 local_scope_p (context_die)
9483 dw_die_ref context_die;
9485 for (; context_die; context_die = context_die->die_parent)
9486 if (context_die->die_tag == DW_TAG_inlined_subroutine
9487 || context_die->die_tag == DW_TAG_subprogram)
9493 /* Returns nonzero if CONTEXT_DIE is a class. */
9496 class_scope_p (context_die)
9497 dw_die_ref context_die;
9500 && (context_die->die_tag == DW_TAG_structure_type
9501 || context_die->die_tag == DW_TAG_union_type));
9504 /* Many forms of DIEs require a "type description" attribute. This
9505 routine locates the proper "type descriptor" die for the type given
9506 by 'type', and adds an DW_AT_type attribute below the given die. */
9509 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9510 dw_die_ref object_die;
9514 dw_die_ref context_die;
9516 enum tree_code code = TREE_CODE (type);
9517 dw_die_ref type_die = NULL;
9519 /* ??? If this type is an unnamed subrange type of an integral or
9520 floating-point type, use the inner type. This is because we have no
9521 support for unnamed types in base_type_die. This can happen if this is
9522 an Ada subrange type. Correct solution is emit a subrange type die. */
9523 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9524 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9525 type = TREE_TYPE (type), code = TREE_CODE (type);
9527 if (code == ERROR_MARK
9528 /* Handle a special case. For functions whose return type is void, we
9529 generate *no* type attribute. (Note that no object may have type
9530 `void', so this only applies to function return types). */
9531 || code == VOID_TYPE)
9534 type_die = modified_type_die (type,
9535 decl_const || TYPE_READONLY (type),
9536 decl_volatile || TYPE_VOLATILE (type),
9539 if (type_die != NULL)
9540 add_AT_die_ref (object_die, DW_AT_type, type_die);
9543 /* Given a tree pointer to a struct, class, union, or enum type node, return
9544 a pointer to the (string) tag name for the given type, or zero if the type
9545 was declared without a tag. */
9551 const char *name = 0;
9553 if (TYPE_NAME (type) != 0)
9557 /* Find the IDENTIFIER_NODE for the type name. */
9558 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9559 t = TYPE_NAME (type);
9561 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9562 a TYPE_DECL node, regardless of whether or not a `typedef' was
9564 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9565 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9566 t = DECL_NAME (TYPE_NAME (type));
9568 /* Now get the name as a string, or invent one. */
9570 name = IDENTIFIER_POINTER (t);
9573 return (name == 0 || *name == '\0') ? 0 : name;
9576 /* Return the type associated with a data member, make a special check
9577 for bit field types. */
9580 member_declared_type (member)
9583 return (DECL_BIT_FIELD_TYPE (member)
9584 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
9587 /* Get the decl's label, as described by its RTL. This may be different
9588 from the DECL_NAME name used in the source file. */
9592 decl_start_label (decl)
9598 x = DECL_RTL (decl);
9599 if (GET_CODE (x) != MEM)
9603 if (GET_CODE (x) != SYMBOL_REF)
9606 fnname = XSTR (x, 0);
9611 /* These routines generate the internal representation of the DIE's for
9612 the compilation unit. Debugging information is collected by walking
9613 the declaration trees passed in from dwarf2out_decl(). */
9616 gen_array_type_die (type, context_die)
9618 dw_die_ref context_die;
9620 dw_die_ref scope_die = scope_die_for (type, context_die);
9621 dw_die_ref array_die;
9624 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9625 the inner array type comes before the outer array type. Thus we must
9626 call gen_type_die before we call new_die. See below also. */
9627 #ifdef MIPS_DEBUGGING_INFO
9628 gen_type_die (TREE_TYPE (type), context_die);
9631 array_die = new_die (DW_TAG_array_type, scope_die, type);
9634 /* We default the array ordering. SDB will probably do
9635 the right things even if DW_AT_ordering is not present. It's not even
9636 an issue until we start to get into multidimensional arrays anyway. If
9637 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9638 then we'll have to put the DW_AT_ordering attribute back in. (But if
9639 and when we find out that we need to put these in, we will only do so
9640 for multidimensional arrays. */
9641 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9644 #ifdef MIPS_DEBUGGING_INFO
9645 /* The SGI compilers handle arrays of unknown bound by setting
9646 AT_declaration and not emitting any subrange DIEs. */
9647 if (! TYPE_DOMAIN (type))
9648 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9651 add_subscript_info (array_die, type);
9653 add_name_attribute (array_die, type_tag (type));
9654 equate_type_number_to_die (type, array_die);
9656 /* Add representation of the type of the elements of this array type. */
9657 element_type = TREE_TYPE (type);
9659 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9660 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9661 We work around this by disabling this feature. See also
9662 add_subscript_info. */
9663 #ifndef MIPS_DEBUGGING_INFO
9664 while (TREE_CODE (element_type) == ARRAY_TYPE)
9665 element_type = TREE_TYPE (element_type);
9667 gen_type_die (element_type, context_die);
9670 add_type_attribute (array_die, element_type, 0, 0, context_die);
9674 gen_set_type_die (type, context_die)
9676 dw_die_ref context_die;
9679 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
9681 equate_type_number_to_die (type, type_die);
9682 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9687 gen_entry_point_die (decl, context_die)
9689 dw_die_ref context_die;
9691 tree origin = decl_ultimate_origin (decl);
9692 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
9695 add_abstract_origin_attribute (decl_die, origin);
9698 add_name_and_src_coords_attributes (decl_die, decl);
9699 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9703 if (DECL_ABSTRACT (decl))
9704 equate_decl_number_to_die (decl, decl_die);
9706 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9710 /* Walk through the list of incomplete types again, trying once more to
9711 emit full debugging info for them. */
9714 retry_incomplete_types ()
9718 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
9719 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
9722 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9725 gen_inlined_enumeration_type_die (type, context_die)
9727 dw_die_ref context_die;
9729 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
9731 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9732 be incomplete and such types are not marked. */
9733 add_abstract_origin_attribute (type_die, type);
9736 /* Generate a DIE to represent an inlined instance of a structure type. */
9739 gen_inlined_structure_type_die (type, context_die)
9741 dw_die_ref context_die;
9743 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
9745 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9746 be incomplete and such types are not marked. */
9747 add_abstract_origin_attribute (type_die, type);
9750 /* Generate a DIE to represent an inlined instance of a union type. */
9753 gen_inlined_union_type_die (type, context_die)
9755 dw_die_ref context_die;
9757 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
9759 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9760 be incomplete and such types are not marked. */
9761 add_abstract_origin_attribute (type_die, type);
9764 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9765 include all of the information about the enumeration values also. Each
9766 enumerated type name/value is listed as a child of the enumerated type
9770 gen_enumeration_type_die (type, context_die)
9772 dw_die_ref context_die;
9774 dw_die_ref type_die = lookup_type_die (type);
9776 if (type_die == NULL)
9778 type_die = new_die (DW_TAG_enumeration_type,
9779 scope_die_for (type, context_die), type);
9780 equate_type_number_to_die (type, type_die);
9781 add_name_attribute (type_die, type_tag (type));
9783 else if (! TYPE_SIZE (type))
9786 remove_AT (type_die, DW_AT_declaration);
9788 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9789 given enum type is incomplete, do not generate the DW_AT_byte_size
9790 attribute or the DW_AT_element_list attribute. */
9791 if (TYPE_SIZE (type))
9795 TREE_ASM_WRITTEN (type) = 1;
9796 add_byte_size_attribute (type_die, type);
9797 if (TYPE_STUB_DECL (type) != NULL_TREE)
9798 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9800 /* If the first reference to this type was as the return type of an
9801 inline function, then it may not have a parent. Fix this now. */
9802 if (type_die->die_parent == NULL)
9803 add_child_die (scope_die_for (type, context_die), type_die);
9805 for (link = TYPE_FIELDS (type);
9806 link != NULL; link = TREE_CHAIN (link))
9808 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
9810 add_name_attribute (enum_die,
9811 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9813 if (host_integerp (TREE_VALUE (link), 0))
9815 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9816 add_AT_int (enum_die, DW_AT_const_value,
9817 tree_low_cst (TREE_VALUE (link), 0));
9819 add_AT_unsigned (enum_die, DW_AT_const_value,
9820 tree_low_cst (TREE_VALUE (link), 0));
9825 add_AT_flag (type_die, DW_AT_declaration, 1);
9828 /* Generate a DIE to represent either a real live formal parameter decl or to
9829 represent just the type of some formal parameter position in some function
9832 Note that this routine is a bit unusual because its argument may be a
9833 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9834 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9835 node. If it's the former then this function is being called to output a
9836 DIE to represent a formal parameter object (or some inlining thereof). If
9837 it's the latter, then this function is only being called to output a
9838 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9839 argument type of some subprogram type. */
9842 gen_formal_parameter_die (node, context_die)
9844 dw_die_ref context_die;
9847 = new_die (DW_TAG_formal_parameter, context_die, node);
9850 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9853 origin = decl_ultimate_origin (node);
9855 add_abstract_origin_attribute (parm_die, origin);
9858 add_name_and_src_coords_attributes (parm_die, node);
9859 add_type_attribute (parm_die, TREE_TYPE (node),
9860 TREE_READONLY (node),
9861 TREE_THIS_VOLATILE (node),
9863 if (DECL_ARTIFICIAL (node))
9864 add_AT_flag (parm_die, DW_AT_artificial, 1);
9867 equate_decl_number_to_die (node, parm_die);
9868 if (! DECL_ABSTRACT (node))
9869 add_location_or_const_value_attribute (parm_die, node);
9874 /* We were called with some kind of a ..._TYPE node. */
9875 add_type_attribute (parm_die, node, 0, 0, context_die);
9885 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9886 at the end of an (ANSI prototyped) formal parameters list. */
9889 gen_unspecified_parameters_die (decl_or_type, context_die)
9891 dw_die_ref context_die;
9893 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
9896 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9897 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9898 parameters as specified in some function type specification (except for
9899 those which appear as part of a function *definition*). */
9902 gen_formal_types_die (function_or_method_type, context_die)
9903 tree function_or_method_type;
9904 dw_die_ref context_die;
9907 tree formal_type = NULL;
9908 tree first_parm_type;
9911 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9913 arg = DECL_ARGUMENTS (function_or_method_type);
9914 function_or_method_type = TREE_TYPE (function_or_method_type);
9919 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9921 /* Make our first pass over the list of formal parameter types and output a
9922 DW_TAG_formal_parameter DIE for each one. */
9923 for (link = first_parm_type; link; )
9925 dw_die_ref parm_die;
9927 formal_type = TREE_VALUE (link);
9928 if (formal_type == void_type_node)
9931 /* Output a (nameless) DIE to represent the formal parameter itself. */
9932 parm_die = gen_formal_parameter_die (formal_type, context_die);
9933 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9934 && link == first_parm_type)
9935 || (arg && DECL_ARTIFICIAL (arg)))
9936 add_AT_flag (parm_die, DW_AT_artificial, 1);
9938 link = TREE_CHAIN (link);
9940 arg = TREE_CHAIN (arg);
9943 /* If this function type has an ellipsis, add a
9944 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9945 if (formal_type != void_type_node)
9946 gen_unspecified_parameters_die (function_or_method_type, context_die);
9948 /* Make our second (and final) pass over the list of formal parameter types
9949 and output DIEs to represent those types (as necessary). */
9950 for (link = TYPE_ARG_TYPES (function_or_method_type);
9951 link && TREE_VALUE (link);
9952 link = TREE_CHAIN (link))
9953 gen_type_die (TREE_VALUE (link), context_die);
9956 /* We want to generate the DIE for TYPE so that we can generate the
9957 die for MEMBER, which has been defined; we will need to refer back
9958 to the member declaration nested within TYPE. If we're trying to
9959 generate minimal debug info for TYPE, processing TYPE won't do the
9960 trick; we need to attach the member declaration by hand. */
9963 gen_type_die_for_member (type, member, context_die)
9965 dw_die_ref context_die;
9967 gen_type_die (type, context_die);
9969 /* If we're trying to avoid duplicate debug info, we may not have
9970 emitted the member decl for this function. Emit it now. */
9971 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9972 && ! lookup_decl_die (member))
9974 if (decl_ultimate_origin (member))
9977 push_decl_scope (type);
9978 if (TREE_CODE (member) == FUNCTION_DECL)
9979 gen_subprogram_die (member, lookup_type_die (type));
9981 gen_variable_die (member, lookup_type_die (type));
9987 /* Generate the DWARF2 info for the "abstract" instance of a function which we
9988 may later generate inlined and/or out-of-line instances of. */
9991 dwarf2out_abstract_function (decl)
9997 int was_abstract = DECL_ABSTRACT (decl);
9999 /* Make sure we have the actual abstract inline, not a clone. */
10000 decl = DECL_ORIGIN (decl);
10002 old_die = lookup_decl_die (decl);
10003 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10004 /* We've already generated the abstract instance. */
10007 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10008 we don't get confused by DECL_ABSTRACT. */
10009 if (debug_info_level > DINFO_LEVEL_TERSE)
10011 context = decl_class_context (decl);
10013 gen_type_die_for_member
10014 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
10017 /* Pretend we've just finished compiling this function. */
10018 save_fn = current_function_decl;
10019 current_function_decl = decl;
10021 set_decl_abstract_flags (decl, 1);
10022 dwarf2out_decl (decl);
10023 if (! was_abstract)
10024 set_decl_abstract_flags (decl, 0);
10026 current_function_decl = save_fn;
10029 /* Generate a DIE to represent a declared function (either file-scope or
10033 gen_subprogram_die (decl, context_die)
10035 dw_die_ref context_die;
10037 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10038 tree origin = decl_ultimate_origin (decl);
10039 dw_die_ref subr_die;
10043 dw_die_ref old_die = lookup_decl_die (decl);
10044 int declaration = (current_function_decl != decl
10045 || class_scope_p (context_die));
10047 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10048 started to generate the abstract instance of an inline, decided to output
10049 its containing class, and proceeded to emit the declaration of the inline
10050 from the member list for the class. If so, DECLARATION takes priority;
10051 we'll get back to the abstract instance when done with the class. */
10053 /* The class-scope declaration DIE must be the primary DIE. */
10054 if (origin && declaration && class_scope_p (context_die))
10061 if (origin != NULL)
10063 if (declaration && ! local_scope_p (context_die))
10066 /* Fixup die_parent for the abstract instance of a nested
10067 inline function. */
10068 if (old_die && old_die->die_parent == NULL)
10069 add_child_die (context_die, old_die);
10071 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10072 add_abstract_origin_attribute (subr_die, origin);
10076 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10078 if (!get_AT_flag (old_die, DW_AT_declaration)
10079 /* We can have a normal definition following an inline one in the
10080 case of redefinition of GNU C extern inlines.
10081 It seems reasonable to use AT_specification in this case. */
10082 && !get_AT_unsigned (old_die, DW_AT_inline))
10084 /* ??? This can happen if there is a bug in the program, for
10085 instance, if it has duplicate function definitions. Ideally,
10086 we should detect this case and ignore it. For now, if we have
10087 already reported an error, any error at all, then assume that
10088 we got here because of an input error, not a dwarf2 bug. */
10094 /* If the definition comes from the same place as the declaration,
10095 maybe use the old DIE. We always want the DIE for this function
10096 that has the *_pc attributes to be under comp_unit_die so the
10097 debugger can find it. We also need to do this for abstract
10098 instances of inlines, since the spec requires the out-of-line copy
10099 to have the same parent. For local class methods, this doesn't
10100 apply; we just use the old DIE. */
10101 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10102 && (DECL_ARTIFICIAL (decl)
10103 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10104 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10105 == (unsigned) DECL_SOURCE_LINE (decl)))))
10107 subr_die = old_die;
10109 /* Clear out the declaration attribute and the parm types. */
10110 remove_AT (subr_die, DW_AT_declaration);
10111 remove_children (subr_die);
10115 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10116 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10117 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10118 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10119 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10120 != (unsigned) DECL_SOURCE_LINE (decl))
10122 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10127 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10129 if (TREE_PUBLIC (decl))
10130 add_AT_flag (subr_die, DW_AT_external, 1);
10132 add_name_and_src_coords_attributes (subr_die, decl);
10133 if (debug_info_level > DINFO_LEVEL_TERSE)
10135 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
10136 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
10137 0, 0, context_die);
10140 add_pure_or_virtual_attribute (subr_die, decl);
10141 if (DECL_ARTIFICIAL (decl))
10142 add_AT_flag (subr_die, DW_AT_artificial, 1);
10144 if (TREE_PROTECTED (decl))
10145 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10146 else if (TREE_PRIVATE (decl))
10147 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10152 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10154 add_AT_flag (subr_die, DW_AT_declaration, 1);
10156 /* The first time we see a member function, it is in the context of
10157 the class to which it belongs. We make sure of this by emitting
10158 the class first. The next time is the definition, which is
10159 handled above. The two may come from the same source text. */
10160 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10161 equate_decl_number_to_die (decl, subr_die);
10164 else if (DECL_ABSTRACT (decl))
10166 if (DECL_INLINE (decl) && !flag_no_inline)
10168 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10169 inline functions, but not for extern inline functions.
10170 We can't get this completely correct because information
10171 about whether the function was declared inline is not
10173 if (DECL_DEFER_OUTPUT (decl))
10174 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10176 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10179 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10181 equate_decl_number_to_die (decl, subr_die);
10183 else if (!DECL_EXTERNAL (decl))
10185 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10186 equate_decl_number_to_die (decl, subr_die);
10188 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10189 current_funcdef_number);
10190 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10191 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10192 current_funcdef_number);
10193 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10195 add_pubname (decl, subr_die);
10196 add_arange (decl, subr_die);
10198 #ifdef MIPS_DEBUGGING_INFO
10199 /* Add a reference to the FDE for this routine. */
10200 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10203 /* Define the "frame base" location for this routine. We use the
10204 frame pointer or stack pointer registers, since the RTL for local
10205 variables is relative to one of them. */
10207 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10208 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10211 /* ??? This fails for nested inline functions, because context_display
10212 is not part of the state saved/restored for inline functions. */
10213 if (current_function_needs_context)
10214 add_AT_location_description (subr_die, DW_AT_static_link,
10215 lookup_static_chain (decl));
10219 /* Now output descriptions of the arguments for this function. This gets
10220 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10221 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10222 `...' at the end of the formal parameter list. In order to find out if
10223 there was a trailing ellipsis or not, we must instead look at the type
10224 associated with the FUNCTION_DECL. This will be a node of type
10225 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10226 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10227 an ellipsis at the end. */
10229 /* In the case where we are describing a mere function declaration, all we
10230 need to do here (and all we *can* do here) is to describe the *types* of
10231 its formal parameters. */
10232 if (debug_info_level <= DINFO_LEVEL_TERSE)
10234 else if (declaration)
10235 gen_formal_types_die (decl, subr_die);
10238 /* Generate DIEs to represent all known formal parameters */
10239 tree arg_decls = DECL_ARGUMENTS (decl);
10242 /* When generating DIEs, generate the unspecified_parameters DIE
10243 instead if we come across the arg "__builtin_va_alist" */
10244 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10245 if (TREE_CODE (parm) == PARM_DECL)
10247 if (DECL_NAME (parm)
10248 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10249 "__builtin_va_alist"))
10250 gen_unspecified_parameters_die (parm, subr_die);
10252 gen_decl_die (parm, subr_die);
10255 /* Decide whether we need an unspecified_parameters DIE at the end.
10256 There are 2 more cases to do this for: 1) the ansi ... declaration -
10257 this is detectable when the end of the arg list is not a
10258 void_type_node 2) an unprototyped function declaration (not a
10259 definition). This just means that we have no info about the
10260 parameters at all. */
10261 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10262 if (fn_arg_types != NULL)
10264 /* this is the prototyped case, check for ... */
10265 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10266 gen_unspecified_parameters_die (decl, subr_die);
10268 else if (DECL_INITIAL (decl) == NULL_TREE)
10269 gen_unspecified_parameters_die (decl, subr_die);
10272 /* Output Dwarf info for all of the stuff within the body of the function
10273 (if it has one - it may be just a declaration). */
10274 outer_scope = DECL_INITIAL (decl);
10276 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10277 a function. This BLOCK actually represents the outermost binding contour
10278 for the function, i.e. the contour in which the function's formal
10279 parameters and labels get declared. Curiously, it appears that the front
10280 end doesn't actually put the PARM_DECL nodes for the current function onto
10281 the BLOCK_VARS list for this outer scope, but are strung off of the
10282 DECL_ARGUMENTS list for the function instead.
10284 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10285 the LABEL_DECL nodes for the function however, and we output DWARF info
10286 for those in decls_for_scope. Just within the `outer_scope' there will be
10287 a BLOCK node representing the function's outermost pair of curly braces,
10288 and any blocks used for the base and member initializers of a C++
10289 constructor function. */
10290 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10292 current_function_has_inlines = 0;
10293 decls_for_scope (outer_scope, subr_die, 0);
10295 #if 0 && defined (MIPS_DEBUGGING_INFO)
10296 if (current_function_has_inlines)
10298 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10299 if (! comp_unit_has_inlines)
10301 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10302 comp_unit_has_inlines = 1;
10309 /* Generate a DIE to represent a declared data object. */
10312 gen_variable_die (decl, context_die)
10314 dw_die_ref context_die;
10316 tree origin = decl_ultimate_origin (decl);
10317 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
10319 dw_die_ref old_die = lookup_decl_die (decl);
10320 int declaration = (DECL_EXTERNAL (decl)
10321 || class_scope_p (context_die));
10323 if (origin != NULL)
10324 add_abstract_origin_attribute (var_die, origin);
10326 /* Loop unrolling can create multiple blocks that refer to the same
10327 static variable, so we must test for the DW_AT_declaration flag.
10329 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10330 copy decls and set the DECL_ABSTRACT flag on them instead of
10333 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10334 else if (old_die && TREE_STATIC (decl)
10335 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10337 /* This is a definition of a C++ class level static. */
10338 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10339 if (DECL_NAME (decl))
10341 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10343 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10344 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10346 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10347 != (unsigned) DECL_SOURCE_LINE (decl))
10349 add_AT_unsigned (var_die, DW_AT_decl_line,
10350 DECL_SOURCE_LINE (decl));
10355 add_name_and_src_coords_attributes (var_die, decl);
10356 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
10357 TREE_THIS_VOLATILE (decl), context_die);
10359 if (TREE_PUBLIC (decl))
10360 add_AT_flag (var_die, DW_AT_external, 1);
10362 if (DECL_ARTIFICIAL (decl))
10363 add_AT_flag (var_die, DW_AT_artificial, 1);
10365 if (TREE_PROTECTED (decl))
10366 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10367 else if (TREE_PRIVATE (decl))
10368 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10372 add_AT_flag (var_die, DW_AT_declaration, 1);
10374 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10375 equate_decl_number_to_die (decl, var_die);
10377 if (! declaration && ! DECL_ABSTRACT (decl))
10379 add_location_or_const_value_attribute (var_die, decl);
10380 add_pubname (decl, var_die);
10383 tree_add_const_value_attribute (var_die, decl);
10386 /* Generate a DIE to represent a label identifier. */
10389 gen_label_die (decl, context_die)
10391 dw_die_ref context_die;
10393 tree origin = decl_ultimate_origin (decl);
10394 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
10396 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10398 if (origin != NULL)
10399 add_abstract_origin_attribute (lbl_die, origin);
10401 add_name_and_src_coords_attributes (lbl_die, decl);
10403 if (DECL_ABSTRACT (decl))
10404 equate_decl_number_to_die (decl, lbl_die);
10407 insn = DECL_RTL (decl);
10409 /* Deleted labels are programmer specified labels which have been
10410 eliminated because of various optimisations. We still emit them
10411 here so that it is possible to put breakpoints on them. */
10412 if (GET_CODE (insn) == CODE_LABEL
10413 || ((GET_CODE (insn) == NOTE
10414 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10416 /* When optimization is enabled (via -O) some parts of the compiler
10417 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10418 represent source-level labels which were explicitly declared by
10419 the user. This really shouldn't be happening though, so catch
10420 it if it ever does happen. */
10421 if (INSN_DELETED_P (insn))
10424 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10425 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10430 /* Generate a DIE for a lexical block. */
10433 gen_lexical_block_die (stmt, context_die, depth)
10435 dw_die_ref context_die;
10438 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
10439 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10441 if (! BLOCK_ABSTRACT (stmt))
10443 if (BLOCK_FRAGMENT_CHAIN (stmt))
10447 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
10449 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10452 add_ranges (chain);
10453 chain = BLOCK_FRAGMENT_CHAIN (chain);
10460 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10461 BLOCK_NUMBER (stmt));
10462 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10463 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10464 BLOCK_NUMBER (stmt));
10465 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10469 decls_for_scope (stmt, stmt_die, depth);
10472 /* Generate a DIE for an inlined subprogram. */
10475 gen_inlined_subroutine_die (stmt, context_die, depth)
10477 dw_die_ref context_die;
10480 if (! BLOCK_ABSTRACT (stmt))
10482 dw_die_ref subr_die
10483 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
10484 tree decl = block_ultimate_origin (stmt);
10485 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10487 /* Emit info for the abstract instance first, if we haven't yet. */
10488 dwarf2out_abstract_function (decl);
10490 add_abstract_origin_attribute (subr_die, decl);
10491 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10492 BLOCK_NUMBER (stmt));
10493 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10494 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10495 BLOCK_NUMBER (stmt));
10496 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10497 decls_for_scope (stmt, subr_die, depth);
10498 current_function_has_inlines = 1;
10502 /* Generate a DIE for a field in a record, or structure. */
10505 gen_field_die (decl, context_die)
10507 dw_die_ref context_die;
10509 dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl);
10511 add_name_and_src_coords_attributes (decl_die, decl);
10512 add_type_attribute (decl_die, member_declared_type (decl),
10513 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10516 if (DECL_BIT_FIELD_TYPE (decl))
10518 add_byte_size_attribute (decl_die, decl);
10519 add_bit_size_attribute (decl_die, decl);
10520 add_bit_offset_attribute (decl_die, decl);
10523 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10524 add_data_member_location_attribute (decl_die, decl);
10526 if (DECL_ARTIFICIAL (decl))
10527 add_AT_flag (decl_die, DW_AT_artificial, 1);
10529 if (TREE_PROTECTED (decl))
10530 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10531 else if (TREE_PRIVATE (decl))
10532 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10536 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10537 Use modified_type_die instead.
10538 We keep this code here just in case these types of DIEs may be needed to
10539 represent certain things in other languages (e.g. Pascal) someday. */
10542 gen_pointer_type_die (type, context_die)
10544 dw_die_ref context_die;
10547 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
10549 equate_type_number_to_die (type, ptr_die);
10550 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10551 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10554 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10555 Use modified_type_die instead.
10556 We keep this code here just in case these types of DIEs may be needed to
10557 represent certain things in other languages (e.g. Pascal) someday. */
10560 gen_reference_type_die (type, context_die)
10562 dw_die_ref context_die;
10565 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
10567 equate_type_number_to_die (type, ref_die);
10568 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10569 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10573 /* Generate a DIE for a pointer to a member type. */
10576 gen_ptr_to_mbr_type_die (type, context_die)
10578 dw_die_ref context_die;
10581 = new_die (DW_TAG_ptr_to_member_type,
10582 scope_die_for (type, context_die), type);
10584 equate_type_number_to_die (type, ptr_die);
10585 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10586 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10587 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10590 /* Generate the DIE for the compilation unit. */
10593 gen_compile_unit_die (filename)
10594 const char *filename;
10597 char producer[250];
10598 const char *wd = getpwd ();
10599 const char *language_string = lang_hooks.name;
10602 die = new_die (DW_TAG_compile_unit, NULL, NULL);
10603 add_name_attribute (die, filename);
10605 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10606 add_AT_string (die, DW_AT_comp_dir, wd);
10608 sprintf (producer, "%s %s", language_string, version_string);
10610 #ifdef MIPS_DEBUGGING_INFO
10611 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10612 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10613 not appear in the producer string, the debugger reaches the conclusion
10614 that the object file is stripped and has no debugging information.
10615 To get the MIPS/SGI debugger to believe that there is debugging
10616 information in the object file, we add a -g to the producer string. */
10617 if (debug_info_level > DINFO_LEVEL_TERSE)
10618 strcat (producer, " -g");
10621 add_AT_string (die, DW_AT_producer, producer);
10623 if (strcmp (language_string, "GNU C++") == 0)
10624 language = DW_LANG_C_plus_plus;
10625 else if (strcmp (language_string, "GNU Ada") == 0)
10626 language = DW_LANG_Ada83;
10627 else if (strcmp (language_string, "GNU F77") == 0)
10628 language = DW_LANG_Fortran77;
10629 else if (strcmp (language_string, "GNU Pascal") == 0)
10630 language = DW_LANG_Pascal83;
10631 else if (strcmp (language_string, "GNU Java") == 0)
10632 language = DW_LANG_Java;
10633 else if (flag_traditional)
10634 language = DW_LANG_C;
10636 language = DW_LANG_C89;
10638 add_AT_unsigned (die, DW_AT_language, language);
10642 /* Generate a DIE for a string type. */
10645 gen_string_type_die (type, context_die)
10647 dw_die_ref context_die;
10649 dw_die_ref type_die
10650 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
10652 equate_type_number_to_die (type, type_die);
10654 /* ??? Fudge the string length attribute for now.
10655 TODO: add string length info. */
10657 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10658 bound_representation (upper_bound, 0, 'u');
10662 /* Generate the DIE for a base class. */
10665 gen_inheritance_die (binfo, context_die)
10667 dw_die_ref context_die;
10669 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
10671 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10672 add_data_member_location_attribute (die, binfo);
10674 if (TREE_VIA_VIRTUAL (binfo))
10675 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10677 if (TREE_VIA_PUBLIC (binfo))
10678 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10679 else if (TREE_VIA_PROTECTED (binfo))
10680 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10683 /* Generate a DIE for a class member. */
10686 gen_member_die (type, context_die)
10688 dw_die_ref context_die;
10693 /* If this is not an incomplete type, output descriptions of each of its
10694 members. Note that as we output the DIEs necessary to represent the
10695 members of this record or union type, we will also be trying to output
10696 DIEs to represent the *types* of those members. However the `type'
10697 function (above) will specifically avoid generating type DIEs for member
10698 types *within* the list of member DIEs for this (containing) type except
10699 for those types (of members) which are explicitly marked as also being
10700 members of this (containing) type themselves. The g++ front- end can
10701 force any given type to be treated as a member of some other (containing)
10702 type by setting the TYPE_CONTEXT of the given (member) type to point to
10703 the TREE node representing the appropriate (containing) type. */
10705 /* First output info about the base classes. */
10706 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10708 tree bases = TYPE_BINFO_BASETYPES (type);
10709 int n_bases = TREE_VEC_LENGTH (bases);
10712 for (i = 0; i < n_bases; i++)
10713 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10716 /* Now output info about the data members and type members. */
10717 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10719 /* If we thought we were generating minimal debug info for TYPE
10720 and then changed our minds, some of the member declarations
10721 may have already been defined. Don't define them again, but
10722 do put them in the right order. */
10724 child = lookup_decl_die (member);
10726 splice_child_die (context_die, child);
10728 gen_decl_die (member, context_die);
10731 /* Now output info about the function members (if any). */
10732 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10734 /* Don't include clones in the member list. */
10735 if (DECL_ABSTRACT_ORIGIN (member))
10738 child = lookup_decl_die (member);
10740 splice_child_die (context_die, child);
10742 gen_decl_die (member, context_die);
10746 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10747 is set, we pretend that the type was never defined, so we only get the
10748 member DIEs needed by later specification DIEs. */
10751 gen_struct_or_union_type_die (type, context_die)
10753 dw_die_ref context_die;
10755 dw_die_ref type_die = lookup_type_die (type);
10756 dw_die_ref scope_die = 0;
10758 int complete = (TYPE_SIZE (type)
10759 && (! TYPE_STUB_DECL (type)
10760 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10762 if (type_die && ! complete)
10765 if (TYPE_CONTEXT (type) != NULL_TREE
10766 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10769 scope_die = scope_die_for (type, context_die);
10771 if (! type_die || (nested && scope_die == comp_unit_die))
10772 /* First occurrence of type or toplevel definition of nested class. */
10774 dw_die_ref old_die = type_die;
10776 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10777 ? DW_TAG_structure_type : DW_TAG_union_type,
10779 equate_type_number_to_die (type, type_die);
10781 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10783 add_name_attribute (type_die, type_tag (type));
10786 remove_AT (type_die, DW_AT_declaration);
10788 /* If this type has been completed, then give it a byte_size attribute and
10789 then give a list of members. */
10792 /* Prevent infinite recursion in cases where the type of some member of
10793 this type is expressed in terms of this type itself. */
10794 TREE_ASM_WRITTEN (type) = 1;
10795 add_byte_size_attribute (type_die, type);
10796 if (TYPE_STUB_DECL (type) != NULL_TREE)
10797 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10799 /* If the first reference to this type was as the return type of an
10800 inline function, then it may not have a parent. Fix this now. */
10801 if (type_die->die_parent == NULL)
10802 add_child_die (scope_die, type_die);
10804 push_decl_scope (type);
10805 gen_member_die (type, type_die);
10808 /* GNU extension: Record what type our vtable lives in. */
10809 if (TYPE_VFIELD (type))
10811 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10813 gen_type_die (vtype, context_die);
10814 add_AT_die_ref (type_die, DW_AT_containing_type,
10815 lookup_type_die (vtype));
10820 add_AT_flag (type_die, DW_AT_declaration, 1);
10822 /* We don't need to do this for function-local types. */
10823 if (! decl_function_context (TYPE_STUB_DECL (type)))
10824 VARRAY_PUSH_TREE (incomplete_types, type);
10828 /* Generate a DIE for a subroutine _type_. */
10831 gen_subroutine_type_die (type, context_die)
10833 dw_die_ref context_die;
10835 tree return_type = TREE_TYPE (type);
10836 dw_die_ref subr_die
10837 = new_die (DW_TAG_subroutine_type,
10838 scope_die_for (type, context_die), type);
10840 equate_type_number_to_die (type, subr_die);
10841 add_prototyped_attribute (subr_die, type);
10842 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10843 gen_formal_types_die (type, subr_die);
10846 /* Generate a DIE for a type definition */
10849 gen_typedef_die (decl, context_die)
10851 dw_die_ref context_die;
10853 dw_die_ref type_die;
10856 if (TREE_ASM_WRITTEN (decl))
10859 TREE_ASM_WRITTEN (decl) = 1;
10860 type_die = new_die (DW_TAG_typedef, context_die, decl);
10861 origin = decl_ultimate_origin (decl);
10862 if (origin != NULL)
10863 add_abstract_origin_attribute (type_die, origin);
10868 add_name_and_src_coords_attributes (type_die, decl);
10869 if (DECL_ORIGINAL_TYPE (decl))
10871 type = DECL_ORIGINAL_TYPE (decl);
10873 if (type == TREE_TYPE (decl))
10876 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10879 type = TREE_TYPE (decl);
10881 add_type_attribute (type_die, type, TREE_READONLY (decl),
10882 TREE_THIS_VOLATILE (decl), context_die);
10885 if (DECL_ABSTRACT (decl))
10886 equate_decl_number_to_die (decl, type_die);
10889 /* Generate a type description DIE. */
10892 gen_type_die (type, context_die)
10894 dw_die_ref context_die;
10898 if (type == NULL_TREE || type == error_mark_node)
10901 /* We are going to output a DIE to represent the unqualified version of
10902 this type (i.e. without any const or volatile qualifiers) so get the
10903 main variant (i.e. the unqualified version) of this type now. */
10904 type = type_main_variant (type);
10906 if (TREE_ASM_WRITTEN (type))
10909 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10910 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10912 TREE_ASM_WRITTEN (type) = 1;
10913 gen_decl_die (TYPE_NAME (type), context_die);
10917 switch (TREE_CODE (type))
10923 case REFERENCE_TYPE:
10924 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10925 ensures that the gen_type_die recursion will terminate even if the
10926 type is recursive. Recursive types are possible in Ada. */
10927 /* ??? We could perhaps do this for all types before the switch
10929 TREE_ASM_WRITTEN (type) = 1;
10931 /* For these types, all that is required is that we output a DIE (or a
10932 set of DIEs) to represent the "basis" type. */
10933 gen_type_die (TREE_TYPE (type), context_die);
10937 /* This code is used for C++ pointer-to-data-member types.
10938 Output a description of the relevant class type. */
10939 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10941 /* Output a description of the type of the object pointed to. */
10942 gen_type_die (TREE_TYPE (type), context_die);
10944 /* Now output a DIE to represent this pointer-to-data-member type
10946 gen_ptr_to_mbr_type_die (type, context_die);
10950 gen_type_die (TYPE_DOMAIN (type), context_die);
10951 gen_set_type_die (type, context_die);
10955 gen_type_die (TREE_TYPE (type), context_die);
10956 abort (); /* No way to represent these in Dwarf yet! */
10959 case FUNCTION_TYPE:
10960 /* Force out return type (in case it wasn't forced out already). */
10961 gen_type_die (TREE_TYPE (type), context_die);
10962 gen_subroutine_type_die (type, context_die);
10966 /* Force out return type (in case it wasn't forced out already). */
10967 gen_type_die (TREE_TYPE (type), context_die);
10968 gen_subroutine_type_die (type, context_die);
10972 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10974 gen_type_die (TREE_TYPE (type), context_die);
10975 gen_string_type_die (type, context_die);
10978 gen_array_type_die (type, context_die);
10982 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10985 case ENUMERAL_TYPE:
10988 case QUAL_UNION_TYPE:
10989 /* If this is a nested type whose containing class hasn't been written
10990 out yet, writing it out will cover this one, too. This does not apply
10991 to instantiations of member class templates; they need to be added to
10992 the containing class as they are generated. FIXME: This hurts the
10993 idea of combining type decls from multiple TUs, since we can't predict
10994 what set of template instantiations we'll get. */
10995 if (TYPE_CONTEXT (type)
10996 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10997 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10999 gen_type_die (TYPE_CONTEXT (type), context_die);
11001 if (TREE_ASM_WRITTEN (type))
11004 /* If that failed, attach ourselves to the stub. */
11005 push_decl_scope (TYPE_CONTEXT (type));
11006 context_die = lookup_type_die (TYPE_CONTEXT (type));
11012 if (TREE_CODE (type) == ENUMERAL_TYPE)
11013 gen_enumeration_type_die (type, context_die);
11015 gen_struct_or_union_type_die (type, context_die);
11020 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11021 it up if it is ever completed. gen_*_type_die will set it for us
11022 when appropriate. */
11031 /* No DIEs needed for fundamental types. */
11035 /* No Dwarf representation currently defined. */
11042 TREE_ASM_WRITTEN (type) = 1;
11045 /* Generate a DIE for a tagged type instantiation. */
11048 gen_tagged_type_instantiation_die (type, context_die)
11050 dw_die_ref context_die;
11052 if (type == NULL_TREE || type == error_mark_node)
11055 /* We are going to output a DIE to represent the unqualified version of
11056 this type (i.e. without any const or volatile qualifiers) so make sure
11057 that we have the main variant (i.e. the unqualified version) of this
11059 if (type != type_main_variant (type))
11062 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11063 an instance of an unresolved type. */
11065 switch (TREE_CODE (type))
11070 case ENUMERAL_TYPE:
11071 gen_inlined_enumeration_type_die (type, context_die);
11075 gen_inlined_structure_type_die (type, context_die);
11079 case QUAL_UNION_TYPE:
11080 gen_inlined_union_type_die (type, context_die);
11088 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11089 things which are local to the given block. */
11092 gen_block_die (stmt, context_die, depth)
11094 dw_die_ref context_die;
11097 int must_output_die = 0;
11100 enum tree_code origin_code;
11102 /* Ignore blocks never really used to make RTL. */
11103 if (stmt == NULL_TREE || !TREE_USED (stmt)
11104 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11107 /* If the block is one fragment of a non-contiguous block, do not
11108 process the variables, since they will have been done by the
11109 origin block. Do process subblocks. */
11110 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11114 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
11115 gen_block_die (sub, context_die, depth + 1);
11120 /* Determine the "ultimate origin" of this block. This block may be an
11121 inlined instance of an inlined instance of inline function, so we have
11122 to trace all of the way back through the origin chain to find out what
11123 sort of node actually served as the original seed for the creation of
11124 the current block. */
11125 origin = block_ultimate_origin (stmt);
11126 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11128 /* Determine if we need to output any Dwarf DIEs at all to represent this
11130 if (origin_code == FUNCTION_DECL)
11131 /* The outer scopes for inlinings *must* always be represented. We
11132 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11133 must_output_die = 1;
11136 /* In the case where the current block represents an inlining of the
11137 "body block" of an inline function, we must *NOT* output any DIE for
11138 this block because we have already output a DIE to represent the whole
11139 inlined function scope and the "body block" of any function doesn't
11140 really represent a different scope according to ANSI C rules. So we
11141 check here to make sure that this block does not represent a "body
11142 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11143 if (! is_body_block (origin ? origin : stmt))
11145 /* Determine if this block directly contains any "significant"
11146 local declarations which we will need to output DIEs for. */
11147 if (debug_info_level > DINFO_LEVEL_TERSE)
11148 /* We are not in terse mode so *any* local declaration counts
11149 as being a "significant" one. */
11150 must_output_die = (BLOCK_VARS (stmt) != NULL);
11152 /* We are in terse mode, so only local (nested) function
11153 definitions count as "significant" local declarations. */
11154 for (decl = BLOCK_VARS (stmt);
11155 decl != NULL; decl = TREE_CHAIN (decl))
11156 if (TREE_CODE (decl) == FUNCTION_DECL
11157 && DECL_INITIAL (decl))
11159 must_output_die = 1;
11165 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11166 DIE for any block which contains no significant local declarations at
11167 all. Rather, in such cases we just call `decls_for_scope' so that any
11168 needed Dwarf info for any sub-blocks will get properly generated. Note
11169 that in terse mode, our definition of what constitutes a "significant"
11170 local declaration gets restricted to include only inlined function
11171 instances and local (nested) function definitions. */
11172 if (must_output_die)
11174 if (origin_code == FUNCTION_DECL)
11175 gen_inlined_subroutine_die (stmt, context_die, depth);
11177 gen_lexical_block_die (stmt, context_die, depth);
11180 decls_for_scope (stmt, context_die, depth);
11183 /* Generate all of the decls declared within a given scope and (recursively)
11184 all of its sub-blocks. */
11187 decls_for_scope (stmt, context_die, depth)
11189 dw_die_ref context_die;
11195 /* Ignore blocks never really used to make RTL. */
11196 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11199 /* Output the DIEs to represent all of the data objects and typedefs
11200 declared directly within this block but not within any nested
11201 sub-blocks. Also, nested function and tag DIEs have been
11202 generated with a parent of NULL; fix that up now. */
11203 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
11207 if (TREE_CODE (decl) == FUNCTION_DECL)
11208 die = lookup_decl_die (decl);
11209 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11210 die = lookup_type_die (TREE_TYPE (decl));
11214 if (die != NULL && die->die_parent == NULL)
11215 add_child_die (context_die, die);
11217 gen_decl_die (decl, context_die);
11220 /* Output the DIEs to represent all sub-blocks (and the items declared
11221 therein) of this block. */
11222 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11224 subblocks = BLOCK_CHAIN (subblocks))
11225 gen_block_die (subblocks, context_die, depth + 1);
11228 /* Is this a typedef we can avoid emitting? */
11231 is_redundant_typedef (decl)
11234 if (TYPE_DECL_IS_STUB (decl))
11237 if (DECL_ARTIFICIAL (decl)
11238 && DECL_CONTEXT (decl)
11239 && is_tagged_type (DECL_CONTEXT (decl))
11240 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11241 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11242 /* Also ignore the artificial member typedef for the class name. */
11248 /* Generate Dwarf debug information for a decl described by DECL. */
11251 gen_decl_die (decl, context_die)
11253 dw_die_ref context_die;
11257 if (DECL_P (decl) && DECL_IGNORED_P (decl))
11260 switch (TREE_CODE (decl))
11266 /* The individual enumerators of an enum type get output when we output
11267 the Dwarf representation of the relevant enum type itself. */
11270 case FUNCTION_DECL:
11271 /* Don't output any DIEs to represent mere function declarations,
11272 unless they are class members or explicit block externs. */
11273 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11274 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11277 /* If we're emitting a clone, emit info for the abstract instance. */
11278 if (DECL_ORIGIN (decl) != decl)
11279 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11281 /* If we're emitting an out-of-line copy of an inline function,
11282 emit info for the abstract instance and set up to refer to it. */
11283 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11284 && ! class_scope_p (context_die)
11285 /* dwarf2out_abstract_function won't emit a die if this is just
11286 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11287 that case, because that works only if we have a die. */
11288 && DECL_INITIAL (decl) != NULL_TREE)
11290 dwarf2out_abstract_function (decl);
11291 set_decl_origin_self (decl);
11294 /* Otherwise we're emitting the primary DIE for this decl. */
11295 else if (debug_info_level > DINFO_LEVEL_TERSE)
11297 /* Before we describe the FUNCTION_DECL itself, make sure that we
11298 have described its return type. */
11299 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11301 /* And its virtual context. */
11302 if (DECL_VINDEX (decl) != NULL_TREE)
11303 gen_type_die (DECL_CONTEXT (decl), context_die);
11305 /* And its containing type. */
11306 origin = decl_class_context (decl);
11307 if (origin != NULL_TREE)
11308 gen_type_die_for_member (origin, decl, context_die);
11311 /* Now output a DIE to represent the function itself. */
11312 gen_subprogram_die (decl, context_die);
11316 /* If we are in terse mode, don't generate any DIEs to represent any
11317 actual typedefs. */
11318 if (debug_info_level <= DINFO_LEVEL_TERSE)
11321 /* In the special case of a TYPE_DECL node representing the declaration
11322 of some type tag, if the given TYPE_DECL is marked as having been
11323 instantiated from some other (original) TYPE_DECL node (e.g. one which
11324 was generated within the original definition of an inline function) we
11325 have to generate a special (abbreviated) DW_TAG_structure_type,
11326 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11327 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11329 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11333 if (is_redundant_typedef (decl))
11334 gen_type_die (TREE_TYPE (decl), context_die);
11336 /* Output a DIE to represent the typedef itself. */
11337 gen_typedef_die (decl, context_die);
11341 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11342 gen_label_die (decl, context_die);
11346 /* If we are in terse mode, don't generate any DIEs to represent any
11347 variable declarations or definitions. */
11348 if (debug_info_level <= DINFO_LEVEL_TERSE)
11351 /* Output any DIEs that are needed to specify the type of this data
11353 gen_type_die (TREE_TYPE (decl), context_die);
11355 /* And its containing type. */
11356 origin = decl_class_context (decl);
11357 if (origin != NULL_TREE)
11358 gen_type_die_for_member (origin, decl, context_die);
11360 /* Now output the DIE to represent the data object itself. This gets
11361 complicated because of the possibility that the VAR_DECL really
11362 represents an inlined instance of a formal parameter for an inline
11364 origin = decl_ultimate_origin (decl);
11365 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11366 gen_formal_parameter_die (decl, context_die);
11368 gen_variable_die (decl, context_die);
11372 /* Ignore the nameless fields that are used to skip bits but handle C++
11373 anonymous unions. */
11374 if (DECL_NAME (decl) != NULL_TREE
11375 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11377 gen_type_die (member_declared_type (decl), context_die);
11378 gen_field_die (decl, context_die);
11383 gen_type_die (TREE_TYPE (decl), context_die);
11384 gen_formal_parameter_die (decl, context_die);
11387 case NAMESPACE_DECL:
11388 /* Ignore for now. */
11397 mark_limbo_die_list (ptr)
11398 void *ptr ATTRIBUTE_UNUSED;
11400 limbo_die_node *node;
11401 for (node = limbo_die_list; node ; node = node->next)
11402 ggc_mark_tree (node->created_for);
11405 /* Add Ada "use" clause information for SGI Workshop debugger. */
11408 dwarf2out_add_library_unit_info (filename, context_list)
11409 const char *filename;
11410 const char *context_list;
11412 unsigned int file_index;
11414 if (filename != NULL)
11416 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
11417 tree context_list_decl
11418 = build_decl (LABEL_DECL, get_identifier (context_list),
11421 TREE_PUBLIC (context_list_decl) = TRUE;
11422 add_name_attribute (unit_die, context_list);
11423 file_index = lookup_filename (filename);
11424 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11425 add_pubname (context_list_decl, unit_die);
11429 /* Output debug information for global decl DECL. Called from toplev.c after
11430 compilation proper has finished. */
11433 dwarf2out_global_decl (decl)
11436 /* Output DWARF2 information for file-scope tentative data object
11437 declarations, file-scope (extern) function declarations (which had no
11438 corresponding body) and file-scope tagged type declarations and
11439 definitions which have not yet been forced out. */
11440 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11441 dwarf2out_decl (decl);
11444 /* Write the debugging output for DECL. */
11447 dwarf2out_decl (decl)
11450 dw_die_ref context_die = comp_unit_die;
11452 switch (TREE_CODE (decl))
11457 case FUNCTION_DECL:
11458 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11459 builtin function. Explicit programmer-supplied declarations of
11460 these same functions should NOT be ignored however. */
11461 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11464 /* What we would really like to do here is to filter out all mere
11465 file-scope declarations of file-scope functions which are never
11466 referenced later within this translation unit (and keep all of ones
11467 that *are* referenced later on) but we aren't clairvoyant, so we have
11468 no idea which functions will be referenced in the future (i.e. later
11469 on within the current translation unit). So here we just ignore all
11470 file-scope function declarations which are not also definitions. If
11471 and when the debugger needs to know something about these functions,
11472 it will have to hunt around and find the DWARF information associated
11473 with the definition of the function.
11475 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11476 nodes represent definitions and which ones represent mere
11477 declarations. We have to check DECL_INITIAL instead. That's because
11478 the C front-end supports some weird semantics for "extern inline"
11479 function definitions. These can get inlined within the current
11480 translation unit (an thus, we need to generate Dwarf info for their
11481 abstract instances so that the Dwarf info for the concrete inlined
11482 instances can have something to refer to) but the compiler never
11483 generates any out-of-lines instances of such things (despite the fact
11484 that they *are* definitions).
11486 The important point is that the C front-end marks these "extern
11487 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11488 them anyway. Note that the C++ front-end also plays some similar games
11489 for inline function definitions appearing within include files which
11490 also contain `#pragma interface' pragmas. */
11491 if (DECL_INITIAL (decl) == NULL_TREE)
11494 /* If we're a nested function, initially use a parent of NULL; if we're
11495 a plain function, this will be fixed up in decls_for_scope. If
11496 we're a method, it will be ignored, since we already have a DIE. */
11497 if (decl_function_context (decl))
11498 context_die = NULL;
11502 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11503 declaration and if the declaration was never even referenced from
11504 within this entire compilation unit. We suppress these DIEs in
11505 order to save space in the .debug section (by eliminating entries
11506 which are probably useless). Note that we must not suppress
11507 block-local extern declarations (whether used or not) because that
11508 would screw-up the debugger's name lookup mechanism and cause it to
11509 miss things which really ought to be in scope at a given point. */
11510 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11513 /* If we are in terse mode, don't generate any DIEs to represent any
11514 variable declarations or definitions. */
11515 if (debug_info_level <= DINFO_LEVEL_TERSE)
11520 /* Don't emit stubs for types unless they are needed by other DIEs. */
11521 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11524 /* Don't bother trying to generate any DIEs to represent any of the
11525 normal built-in types for the language we are compiling. */
11526 if (DECL_SOURCE_LINE (decl) == 0)
11528 /* OK, we need to generate one for `bool' so GDB knows what type
11529 comparisons have. */
11530 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11531 == DW_LANG_C_plus_plus)
11532 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
11533 && ! DECL_IGNORED_P (decl))
11534 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11539 /* If we are in terse mode, don't generate any DIEs for types. */
11540 if (debug_info_level <= DINFO_LEVEL_TERSE)
11543 /* If we're a function-scope tag, initially use a parent of NULL;
11544 this will be fixed up in decls_for_scope. */
11545 if (decl_function_context (decl))
11546 context_die = NULL;
11554 gen_decl_die (decl, context_die);
11557 /* Output a marker (i.e. a label) for the beginning of the generated code for
11558 a lexical block. */
11561 dwarf2out_begin_block (line, blocknum)
11562 unsigned int line ATTRIBUTE_UNUSED;
11563 unsigned int blocknum;
11565 function_section (current_function_decl);
11566 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11569 /* Output a marker (i.e. a label) for the end of the generated code for a
11573 dwarf2out_end_block (line, blocknum)
11574 unsigned int line ATTRIBUTE_UNUSED;
11575 unsigned int blocknum;
11577 function_section (current_function_decl);
11578 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11581 /* Returns nonzero if it is appropriate not to emit any debugging
11582 information for BLOCK, because it doesn't contain any instructions.
11584 Don't allow this for blocks with nested functions or local classes
11585 as we would end up with orphans, and in the presence of scheduling
11586 we may end up calling them anyway. */
11589 dwarf2out_ignore_block (block)
11594 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11595 if (TREE_CODE (decl) == FUNCTION_DECL
11596 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11602 /* Lookup FILE_NAME (in the list of filenames that we know about here in
11603 dwarf2out.c) and return its "index". The index of each (known) filename is
11604 just a unique number which is associated with only that one filename. We
11605 need such numbers for the sake of generating labels (in the .debug_sfnames
11606 section) and references to those files numbers (in the .debug_srcinfo
11607 and.debug_macinfo sections). If the filename given as an argument is not
11608 found in our current list, add it to the list and assign it the next
11609 available unique index number. In order to speed up searches, we remember
11610 the index of the filename was looked up last. This handles the majority of
11614 lookup_filename (file_name)
11615 const char *file_name;
11619 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11620 if (strcmp (file_name, "<internal>") == 0
11621 || strcmp (file_name, "<built-in>") == 0)
11624 /* Check to see if the file name that was searched on the previous
11625 call matches this file name. If so, return the index. */
11626 if (file_table.last_lookup_index != 0)
11627 if (0 == strcmp (file_name,
11628 file_table.table[file_table.last_lookup_index]))
11629 return file_table.last_lookup_index;
11631 /* Didn't match the previous lookup, search the table */
11632 for (i = 1; i < file_table.in_use; i++)
11633 if (strcmp (file_name, file_table.table[i]) == 0)
11635 file_table.last_lookup_index = i;
11639 /* Prepare to add a new table entry by making sure there is enough space in
11640 the table to do so. If not, expand the current table. */
11641 if (i == file_table.allocated)
11643 file_table.allocated = i + FILE_TABLE_INCREMENT;
11644 file_table.table = (char **)
11645 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11648 /* Add the new entry to the end of the filename table. */
11649 file_table.table[i] = xstrdup (file_name);
11650 file_table.in_use = i + 1;
11651 file_table.last_lookup_index = i;
11653 if (DWARF2_ASM_LINE_DEBUG_INFO)
11654 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11662 /* Allocate the initial hunk of the file_table. */
11663 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11664 file_table.allocated = FILE_TABLE_INCREMENT;
11666 /* Skip the first entry - file numbers begin at 1. */
11667 file_table.in_use = 1;
11668 file_table.last_lookup_index = 0;
11671 /* Output a label to mark the beginning of a source code line entry
11672 and record information relating to this source line, in
11673 'line_info_table' for later output of the .debug_line section. */
11676 dwarf2out_source_line (line, filename)
11678 const char *filename;
11680 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11682 function_section (current_function_decl);
11684 /* If requested, emit something human-readable. */
11685 if (flag_debug_asm)
11686 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11689 if (DWARF2_ASM_LINE_DEBUG_INFO)
11691 unsigned file_num = lookup_filename (filename);
11693 /* Emit the .loc directive understood by GNU as. */
11694 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11696 /* Indicate that line number info exists. */
11697 line_info_table_in_use++;
11699 /* Indicate that multiple line number tables exist. */
11700 if (DECL_SECTION_NAME (current_function_decl))
11701 separate_line_info_table_in_use++;
11703 else if (DECL_SECTION_NAME (current_function_decl))
11705 dw_separate_line_info_ref line_info;
11706 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11707 separate_line_info_table_in_use);
11709 /* expand the line info table if necessary */
11710 if (separate_line_info_table_in_use
11711 == separate_line_info_table_allocated)
11713 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11714 separate_line_info_table
11715 = (dw_separate_line_info_ref)
11716 xrealloc (separate_line_info_table,
11717 separate_line_info_table_allocated
11718 * sizeof (dw_separate_line_info_entry));
11721 /* Add the new entry at the end of the line_info_table. */
11723 = &separate_line_info_table[separate_line_info_table_in_use++];
11724 line_info->dw_file_num = lookup_filename (filename);
11725 line_info->dw_line_num = line;
11726 line_info->function = current_funcdef_number;
11730 dw_line_info_ref line_info;
11732 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11733 line_info_table_in_use);
11735 /* Expand the line info table if necessary. */
11736 if (line_info_table_in_use == line_info_table_allocated)
11738 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11740 = (dw_line_info_ref)
11741 xrealloc (line_info_table,
11742 (line_info_table_allocated
11743 * sizeof (dw_line_info_entry)));
11746 /* Add the new entry at the end of the line_info_table. */
11747 line_info = &line_info_table[line_info_table_in_use++];
11748 line_info->dw_file_num = lookup_filename (filename);
11749 line_info->dw_line_num = line;
11754 /* Record the beginning of a new source file. */
11757 dwarf2out_start_source_file (lineno, filename)
11758 unsigned int lineno;
11759 const char *filename;
11761 if (flag_eliminate_dwarf2_dups)
11763 /* Record the beginning of the file for break_out_includes. */
11764 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
11765 add_AT_string (bincl_die, DW_AT_name, filename);
11768 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11770 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11771 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11772 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11774 dw2_asm_output_data_uleb128 (lookup_filename (filename),
11775 "Filename we just started");
11779 /* Record the end of a source file. */
11782 dwarf2out_end_source_file (lineno)
11783 unsigned int lineno ATTRIBUTE_UNUSED;
11785 if (flag_eliminate_dwarf2_dups)
11786 /* Record the end of the file for break_out_includes. */
11787 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
11789 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11791 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11792 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11796 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11797 the tail part of the directive line, i.e. the part which is past the
11798 initial whitespace, #, whitespace, directive-name, whitespace part. */
11801 dwarf2out_define (lineno, buffer)
11802 unsigned lineno ATTRIBUTE_UNUSED;
11803 const char *buffer ATTRIBUTE_UNUSED;
11805 static int initialized = 0;
11808 dwarf2out_start_source_file (0, primary_filename);
11812 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11814 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11815 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11816 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11817 dw2_asm_output_nstring (buffer, -1, "The macro");
11821 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11822 the tail part of the directive line, i.e. the part which is past the
11823 initial whitespace, #, whitespace, directive-name, whitespace part. */
11826 dwarf2out_undef (lineno, buffer)
11827 unsigned lineno ATTRIBUTE_UNUSED;
11828 const char *buffer ATTRIBUTE_UNUSED;
11830 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11832 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11833 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
11834 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11835 dw2_asm_output_nstring (buffer, -1, "The macro");
11839 /* Set up for Dwarf output at the start of compilation. */
11842 dwarf2out_init (main_input_filename)
11843 const char *main_input_filename;
11845 init_file_table ();
11847 /* Remember the name of the primary input file. */
11848 primary_filename = main_input_filename;
11850 /* Add it to the file table first, under the assumption that we'll
11851 be emitting line number data for it first, which avoids having
11852 to add an initial DW_LNS_set_file. */
11853 lookup_filename (main_input_filename);
11855 /* Allocate the initial hunk of the decl_die_table. */
11857 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11858 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11859 decl_die_table_in_use = 0;
11861 /* Allocate the initial hunk of the decl_scope_table. */
11862 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
11863 ggc_add_tree_varray_root (&decl_scope_table, 1);
11865 /* Allocate the initial hunk of the abbrev_die_table. */
11867 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11868 sizeof (dw_die_ref));
11869 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11870 /* Zero-th entry is allocated, but unused */
11871 abbrev_die_table_in_use = 1;
11873 /* Allocate the initial hunk of the line_info_table. */
11875 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11876 sizeof (dw_line_info_entry));
11877 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11879 /* Zero-th entry is allocated, but unused */
11880 line_info_table_in_use = 1;
11882 /* Generate the initial DIE for the .debug section. Note that the (string)
11883 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11884 will (typically) be a relative pathname and that this pathname should be
11885 taken as being relative to the directory from which the compiler was
11886 invoked when the given (base) source file was compiled. */
11887 comp_unit_die = gen_compile_unit_die (main_input_filename);
11889 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
11890 ggc_add_tree_varray_root (&incomplete_types, 1);
11892 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11893 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11895 ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list);
11897 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11898 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
11899 DEBUG_ABBREV_SECTION_LABEL, 0);
11900 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11901 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11903 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
11905 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11906 DEBUG_INFO_SECTION_LABEL, 0);
11907 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11908 DEBUG_LINE_SECTION_LABEL, 0);
11909 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
11910 DEBUG_RANGES_SECTION_LABEL, 0);
11911 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
11912 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11913 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
11914 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11915 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
11916 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11918 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11920 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11921 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
11922 DEBUG_MACINFO_SECTION_LABEL, 0);
11923 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
11926 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11929 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11933 /* Allocate a string in .debug_str hash table. */
11936 indirect_string_alloc (tab)
11937 hash_table *tab ATTRIBUTE_UNUSED;
11939 struct indirect_string_node *node;
11941 node = xmalloc (sizeof (struct indirect_string_node));
11942 node->refcount = 0;
11944 node->label = NULL;
11946 return (hashnode) node;
11949 /* A helper function for dwarf2out_finish called through
11950 ht_forall. Emit one queued .debug_str string. */
11953 output_indirect_string (pfile, h, v)
11954 struct cpp_reader *pfile ATTRIBUTE_UNUSED;
11956 const PTR v ATTRIBUTE_UNUSED;
11958 struct indirect_string_node *node = (struct indirect_string_node *) h;
11960 if (node->form == DW_FORM_strp)
11962 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
11963 ASM_OUTPUT_LABEL (asm_out_file, node->label);
11964 assemble_string ((const char *) HT_STR (&node->id),
11965 HT_LEN (&node->id) + 1);
11971 /* Output stuff that dwarf requires at the end of every file,
11972 and generate the DWARF-2 debugging info. */
11975 dwarf2out_finish (input_filename)
11976 const char *input_filename ATTRIBUTE_UNUSED;
11978 limbo_die_node *node, *next_node;
11979 dw_die_ref die = 0;
11981 /* Traverse the limbo die list, and add parent/child links. The only
11982 dies without parents that should be here are concrete instances of
11983 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11984 For concrete instances, we can get the parent die from the abstract
11986 for (node = limbo_die_list; node; node = next_node)
11988 next_node = node->next;
11991 if (die->die_parent == NULL)
11993 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11997 add_child_die (origin->die_parent, die);
11998 else if (die == comp_unit_die)
12000 else if (node->created_for
12001 && ((DECL_P (node->created_for)
12002 && (context = DECL_CONTEXT (node->created_for)))
12003 || (TYPE_P (node->created_for)
12004 && (context = TYPE_CONTEXT (node->created_for))))
12005 && TREE_CODE (context) == FUNCTION_DECL)
12007 /* In certain situations, the lexical block containing a
12008 nested function can be optimized away, which results
12009 in the nested function die being orphaned. Likewise
12010 with the return type of that nested function. Force
12011 this to be a child of the containing function. */
12012 origin = lookup_decl_die (context);
12015 add_child_die (origin, die);
12017 else if (errorcount > 0 || sorrycount > 0)
12018 /* It's OK to be confused by errors in the input. */
12019 add_child_die (comp_unit_die, die);
12027 limbo_die_list = NULL;
12029 /* Walk through the list of incomplete types again, trying once more to
12030 emit full debugging info for them. */
12031 retry_incomplete_types ();
12033 /* We need to reverse all the dies before break_out_includes, or
12034 we'll see the end of an include file before the beginning. */
12035 reverse_all_dies (comp_unit_die);
12037 /* Generate separate CUs for each of the include files we've seen.
12038 They will go into limbo_die_list. */
12039 if (flag_eliminate_dwarf2_dups)
12040 break_out_includes (comp_unit_die);
12042 /* Traverse the DIE's and add add sibling attributes to those DIE's
12043 that have children. */
12044 add_sibling_attributes (comp_unit_die);
12045 for (node = limbo_die_list; node; node = node->next)
12046 add_sibling_attributes (node->die);
12048 /* Output a terminator label for the .text section. */
12050 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
12052 /* Output the source line correspondence table. We must do this
12053 even if there is no line information. Otherwise, on an empty
12054 translation unit, we will generate a present, but empty,
12055 .debug_info section. IRIX 6.5 `nm' will then complain when
12056 examining the file. */
12057 if (! DWARF2_ASM_LINE_DEBUG_INFO)
12059 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12060 output_line_info ();
12063 /* Output location list section if necessary. */
12064 if (have_location_lists)
12066 /* Output the location lists info. */
12067 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
12068 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
12069 DEBUG_LOC_SECTION_LABEL, 0);
12070 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
12071 output_location_lists (die);
12072 have_location_lists = 0;
12075 /* We can only use the low/high_pc attributes if all of the code was
12077 if (separate_line_info_table_in_use == 0)
12079 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
12080 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
12083 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12084 "base address". Use zero so that these addresses become absolute. */
12085 else if (have_location_lists || ranges_table_in_use)
12086 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
12088 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12089 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
12090 debug_line_section_label);
12092 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12093 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
12095 /* Output all of the compilation units. We put the main one last so that
12096 the offsets are available to output_pubnames. */
12097 for (node = limbo_die_list; node; node = node->next)
12098 output_comp_unit (node->die);
12100 output_comp_unit (comp_unit_die);
12102 /* Output the abbreviation table. */
12103 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12104 output_abbrev_section ();
12106 /* Output public names table if necessary. */
12107 if (pubname_table_in_use)
12109 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
12110 output_pubnames ();
12113 /* Output the address range information. We only put functions in the arange
12114 table, so don't write it out if we don't have any. */
12115 if (fde_table_in_use)
12117 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
12121 /* Output ranges section if necessary. */
12122 if (ranges_table_in_use)
12124 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
12125 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12129 /* Have to end the primary source file. */
12130 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12132 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12133 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12136 /* If we emitted any DW_FORM_strp form attribute, output the string
12138 if (debug_str_hash)
12139 ht_forall (debug_str_hash, output_indirect_string, NULL);
12141 #endif /* DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO */