1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of 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 #ifdef DWARF2_FRAME_INFO
97 #ifdef DWARF2_UNWIND_INFO
99 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
104 /* The number of the current function definition for which debugging
105 information is being generated. These numbers range from 1 up to the
106 maximum number of function definitions contained within the current
107 compilation unit. These numbers are used to create unique label id's
108 unique to each function definition. */
109 unsigned current_funcdef_number = 0;
111 /* The size of the target's pointer type. */
113 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
116 /* Default version of targetm.eh_frame_section. Note this must appear
117 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
121 default_eh_frame_section ()
123 #ifdef EH_FRAME_SECTION_NAME
124 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
126 tree label = get_file_function_name ('F');
129 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
130 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
131 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
135 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
137 /* How to start an assembler comment. */
138 #ifndef ASM_COMMENT_START
139 #define ASM_COMMENT_START ";#"
142 typedef struct dw_cfi_struct *dw_cfi_ref;
143 typedef struct dw_fde_struct *dw_fde_ref;
144 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
146 /* Call frames are described using a sequence of Call Frame
147 Information instructions. The register number, offset
148 and address fields are provided as possible operands;
149 their use is selected by the opcode field. */
151 typedef union dw_cfi_oprnd_struct
153 unsigned long dw_cfi_reg_num;
154 long int dw_cfi_offset;
155 const char *dw_cfi_addr;
156 struct dw_loc_descr_struct *dw_cfi_loc;
160 typedef struct dw_cfi_struct
162 dw_cfi_ref dw_cfi_next;
163 enum dwarf_call_frame_info dw_cfi_opc;
164 dw_cfi_oprnd dw_cfi_oprnd1;
165 dw_cfi_oprnd dw_cfi_oprnd2;
169 /* This is how we define the location of the CFA. We use to handle it
170 as REG + OFFSET all the time, but now it can be more complex.
171 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
172 Instead of passing around REG and OFFSET, we pass a copy
173 of this structure. */
174 typedef struct cfa_loc
179 int indirect; /* 1 if CFA is accessed via a dereference. */
182 /* All call frame descriptions (FDE's) in the GCC generated DWARF
183 refer to a single Common Information Entry (CIE), defined at
184 the beginning of the .debug_frame section. This use of a single
185 CIE obviates the need to keep track of multiple CIE's
186 in the DWARF generation routines below. */
188 typedef struct dw_fde_struct
190 const char *dw_fde_begin;
191 const char *dw_fde_current_label;
192 const char *dw_fde_end;
193 dw_cfi_ref dw_fde_cfi;
194 unsigned funcdef_number;
195 unsigned nothrow : 1;
196 unsigned uses_eh_lsda : 1;
200 /* Maximum size (in bytes) of an artificially generated label. */
201 #define MAX_ARTIFICIAL_LABEL_BYTES 30
203 /* The size of addresses as they appear in the Dwarf 2 data.
204 Some architectures use word addresses to refer to code locations,
205 but Dwarf 2 info always uses byte addresses. On such machines,
206 Dwarf 2 addresses need to be larger than the architecture's
208 #ifndef DWARF2_ADDR_SIZE
209 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
212 /* The size in bytes of a DWARF field indicating an offset or length
213 relative to a debug info section, specified to be 4 bytes in the
214 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
217 #ifndef DWARF_OFFSET_SIZE
218 #define DWARF_OFFSET_SIZE 4
221 #define DWARF_VERSION 2
223 /* Round SIZE up to the nearest BOUNDARY. */
224 #define DWARF_ROUND(SIZE,BOUNDARY) \
225 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
227 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
228 #ifndef DWARF_CIE_DATA_ALIGNMENT
229 #ifdef STACK_GROWS_DOWNWARD
230 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
232 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
234 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
236 /* A pointer to the base of a table that contains frame description
237 information for each routine. */
238 static dw_fde_ref fde_table;
240 /* Number of elements currently allocated for fde_table. */
241 static unsigned fde_table_allocated;
243 /* Number of elements in fde_table currently in use. */
244 static unsigned fde_table_in_use;
246 /* Size (in elements) of increments by which we may expand the
248 #define FDE_TABLE_INCREMENT 256
250 /* A list of call frame insns for the CIE. */
251 static dw_cfi_ref cie_cfi_head;
253 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
254 attribute that accelerates the lookup of the FDE associated
255 with the subprogram. This variable holds the table index of the FDE
256 associated with the current function (body) definition. */
257 static unsigned current_funcdef_fde;
259 struct ht *debug_str_hash;
261 struct indirect_string_node
263 struct ht_identifier id;
264 unsigned int refcount;
269 /* Forward declarations for functions defined in this file. */
271 static char *stripattributes PARAMS ((const char *));
272 static const char *dwarf_cfi_name PARAMS ((unsigned));
273 static dw_cfi_ref new_cfi PARAMS ((void));
274 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
275 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
276 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
277 static void lookup_cfa PARAMS ((dw_cfa_location *));
278 static void reg_save PARAMS ((const char *, unsigned,
280 static void initial_return_save PARAMS ((rtx));
281 static long stack_adjust_offset PARAMS ((rtx));
282 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
283 static void output_call_frame_info PARAMS ((int));
284 static void dwarf2out_stack_adjust PARAMS ((rtx));
285 static void queue_reg_save PARAMS ((const char *, rtx, long));
286 static void flush_queued_reg_saves PARAMS ((void));
287 static bool clobbers_queued_reg_save PARAMS ((rtx));
288 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
290 /* Support for complex CFA locations. */
291 static void output_cfa_loc PARAMS ((dw_cfi_ref));
292 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
293 struct dw_loc_descr_struct *));
294 static struct dw_loc_descr_struct *build_cfa_loc
295 PARAMS ((dw_cfa_location *));
296 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
298 /* .debug_str support. */
299 static hashnode indirect_string_alloc PARAMS ((hash_table *));
300 static int output_indirect_string PARAMS ((struct cpp_reader *,
301 hashnode, const PTR));
303 /* How to start an assembler comment. */
304 #ifndef ASM_COMMENT_START
305 #define ASM_COMMENT_START ";#"
308 /* Data and reference forms for relocatable data. */
309 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
310 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
312 /* Pseudo-op for defining a new section. */
313 #ifndef SECTION_ASM_OP
314 #define SECTION_ASM_OP "\t.section\t"
317 #ifndef DEBUG_FRAME_SECTION
318 #define DEBUG_FRAME_SECTION ".debug_frame"
321 #ifndef FUNC_BEGIN_LABEL
322 #define FUNC_BEGIN_LABEL "LFB"
324 #ifndef FUNC_END_LABEL
325 #define FUNC_END_LABEL "LFE"
327 #define FRAME_BEGIN_LABEL "Lframe"
328 #define CIE_AFTER_SIZE_LABEL "LSCIE"
329 #define CIE_END_LABEL "LECIE"
330 #define CIE_LENGTH_LABEL "LLCIE"
331 #define FDE_LABEL "LSFDE"
332 #define FDE_AFTER_SIZE_LABEL "LASFDE"
333 #define FDE_END_LABEL "LEFDE"
334 #define FDE_LENGTH_LABEL "LLFDE"
335 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
336 #define LINE_NUMBER_END_LABEL "LELT"
337 #define LN_PROLOG_AS_LABEL "LASLTP"
338 #define LN_PROLOG_END_LABEL "LELTP"
339 #define DIE_LABEL_PREFIX "DW"
341 /* Definitions of defaults for various types of primitive assembly language
342 output operations. These may be overridden from within the tm.h file,
343 but typically, that is unnecessary. */
346 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
347 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
349 fprintf (FILE, "%s", SET_ASM_OP); \
350 assemble_name (FILE, SY); \
352 assemble_name (FILE, HI); \
354 assemble_name (FILE, LO); \
357 #endif /* SET_ASM_OP */
359 /* The DWARF 2 CFA column which tracks the return address. Normally this
360 is the column for PC, or the first column after all of the hard
362 #ifndef DWARF_FRAME_RETURN_COLUMN
364 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
366 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
370 /* The mapping from gcc register number to DWARF 2 CFA column number. By
371 default, we just provide columns for all registers. */
372 #ifndef DWARF_FRAME_REGNUM
373 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
376 /* Hook used by __throw. */
379 expand_builtin_dwarf_fp_regnum ()
381 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
384 /* The offset from the incoming value of %sp to the top of the stack frame
385 for the current function. */
386 #ifndef INCOMING_FRAME_SP_OFFSET
387 #define INCOMING_FRAME_SP_OFFSET 0
390 /* Return a pointer to a copy of the section string name S with all
391 attributes stripped off, and an asterisk prepended (for assemble_name). */
397 char *stripped = xmalloc (strlen (s) + 2);
402 while (*s && *s != ',')
409 /* Generate code to initialize the register size table. */
412 expand_builtin_init_dwarf_reg_sizes (address)
416 enum machine_mode mode = TYPE_MODE (char_type_node);
417 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
418 rtx mem = gen_rtx_MEM (mode, addr);
420 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
422 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
423 int size = GET_MODE_SIZE (reg_raw_mode[i]);
428 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
432 /* Convert a DWARF call frame info. operation to its string name */
435 dwarf_cfi_name (cfi_opc)
440 case DW_CFA_advance_loc:
441 return "DW_CFA_advance_loc";
443 return "DW_CFA_offset";
445 return "DW_CFA_restore";
449 return "DW_CFA_set_loc";
450 case DW_CFA_advance_loc1:
451 return "DW_CFA_advance_loc1";
452 case DW_CFA_advance_loc2:
453 return "DW_CFA_advance_loc2";
454 case DW_CFA_advance_loc4:
455 return "DW_CFA_advance_loc4";
456 case DW_CFA_offset_extended:
457 return "DW_CFA_offset_extended";
458 case DW_CFA_restore_extended:
459 return "DW_CFA_restore_extended";
460 case DW_CFA_undefined:
461 return "DW_CFA_undefined";
462 case DW_CFA_same_value:
463 return "DW_CFA_same_value";
464 case DW_CFA_register:
465 return "DW_CFA_register";
466 case DW_CFA_remember_state:
467 return "DW_CFA_remember_state";
468 case DW_CFA_restore_state:
469 return "DW_CFA_restore_state";
471 return "DW_CFA_def_cfa";
472 case DW_CFA_def_cfa_register:
473 return "DW_CFA_def_cfa_register";
474 case DW_CFA_def_cfa_offset:
475 return "DW_CFA_def_cfa_offset";
476 case DW_CFA_def_cfa_expression:
477 return "DW_CFA_def_cfa_expression";
479 /* SGI/MIPS specific */
480 case DW_CFA_MIPS_advance_loc8:
481 return "DW_CFA_MIPS_advance_loc8";
484 case DW_CFA_GNU_window_save:
485 return "DW_CFA_GNU_window_save";
486 case DW_CFA_GNU_args_size:
487 return "DW_CFA_GNU_args_size";
488 case DW_CFA_GNU_negative_offset_extended:
489 return "DW_CFA_GNU_negative_offset_extended";
492 return "DW_CFA_<unknown>";
496 /* Return a pointer to a newly allocated Call Frame Instruction. */
498 static inline dw_cfi_ref
501 dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
503 cfi->dw_cfi_next = NULL;
504 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
505 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
510 /* Add a Call Frame Instruction to list of instructions. */
513 add_cfi (list_head, cfi)
514 dw_cfi_ref *list_head;
519 /* Find the end of the chain. */
520 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
526 /* Generate a new label for the CFI info to refer to. */
529 dwarf2out_cfi_label ()
531 static char label[20];
532 static unsigned long label_num = 0;
534 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
535 ASM_OUTPUT_LABEL (asm_out_file, label);
540 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
541 or to the CIE if LABEL is NULL. */
544 add_fde_cfi (label, cfi)
550 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
553 label = dwarf2out_cfi_label ();
555 if (fde->dw_fde_current_label == NULL
556 || strcmp (label, fde->dw_fde_current_label) != 0)
560 fde->dw_fde_current_label = label = xstrdup (label);
562 /* Set the location counter to the new label. */
564 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
565 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
566 add_cfi (&fde->dw_fde_cfi, xcfi);
569 add_cfi (&fde->dw_fde_cfi, cfi);
573 add_cfi (&cie_cfi_head, cfi);
576 /* Subroutine of lookup_cfa. */
579 lookup_cfa_1 (cfi, loc)
581 dw_cfa_location *loc;
583 switch (cfi->dw_cfi_opc)
585 case DW_CFA_def_cfa_offset:
586 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
588 case DW_CFA_def_cfa_register:
589 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
592 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
593 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
595 case DW_CFA_def_cfa_expression:
596 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
603 /* Find the previous value for the CFA. */
607 dw_cfa_location *loc;
611 loc->reg = (unsigned long) -1;
614 loc->base_offset = 0;
616 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
617 lookup_cfa_1 (cfi, loc);
619 if (fde_table_in_use)
621 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
622 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
623 lookup_cfa_1 (cfi, loc);
627 /* The current rule for calculating the DWARF2 canonical frame address. */
628 static dw_cfa_location cfa;
630 /* The register used for saving registers to the stack, and its offset
632 static dw_cfa_location cfa_store;
634 /* The running total of the size of arguments pushed onto the stack. */
635 static long args_size;
637 /* The last args_size we actually output. */
638 static long old_args_size;
640 /* Entry point to update the canonical frame address (CFA).
641 LABEL is passed to add_fde_cfi. The value of CFA is now to be
642 calculated from REG+OFFSET. */
645 dwarf2out_def_cfa (label, reg, offset)
655 def_cfa_1 (label, &loc);
658 /* This routine does the actual work. The CFA is now calculated from
659 the dw_cfa_location structure. */
661 def_cfa_1 (label, loc_p)
663 dw_cfa_location *loc_p;
666 dw_cfa_location old_cfa, loc;
671 if (cfa_store.reg == loc.reg && loc.indirect == 0)
672 cfa_store.offset = loc.offset;
674 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
675 lookup_cfa (&old_cfa);
677 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
678 loc.indirect == old_cfa.indirect)
680 if (loc.indirect == 0
681 || loc.base_offset == old_cfa.base_offset)
682 /* Nothing changed so no need to issue any call frame
689 if (loc.reg == old_cfa.reg && !loc.indirect)
691 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
692 indicating the CFA register did not change but the offset
694 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
695 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
698 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
699 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
702 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
703 indicating the CFA register has changed to <register> but the
704 offset has not changed. */
705 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
706 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
710 else if (loc.indirect == 0)
712 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
713 indicating the CFA register has changed to <register> with
714 the specified offset. */
715 cfi->dw_cfi_opc = DW_CFA_def_cfa;
716 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
717 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
721 /* Construct a DW_CFA_def_cfa_expression instruction to
722 calculate the CFA using a full location expression since no
723 register-offset pair is available. */
724 struct dw_loc_descr_struct *loc_list;
725 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
726 loc_list = build_cfa_loc (&loc);
727 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
730 add_fde_cfi (label, cfi);
733 /* Add the CFI for saving a register. REG is the CFA column number.
734 LABEL is passed to add_fde_cfi.
735 If SREG is -1, the register is saved at OFFSET from the CFA;
736 otherwise it is saved in SREG. */
739 reg_save (label, reg, sreg, offset)
745 dw_cfi_ref cfi = new_cfi ();
747 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
749 /* The following comparison is correct. -1 is used to indicate that
750 the value isn't a register number. */
751 if (sreg == (unsigned int) -1)
754 /* The register number won't fit in 6 bits, so we have to use
756 cfi->dw_cfi_opc = DW_CFA_offset_extended;
758 cfi->dw_cfi_opc = DW_CFA_offset;
760 #ifdef ENABLE_CHECKING
762 /* If we get an offset that is not a multiple of
763 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
764 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
766 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
768 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
772 offset /= DWARF_CIE_DATA_ALIGNMENT;
775 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
778 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
780 else if (sreg == reg)
781 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
785 cfi->dw_cfi_opc = DW_CFA_register;
786 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
789 add_fde_cfi (label, cfi);
792 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
793 This CFI tells the unwinder that it needs to restore the window registers
794 from the previous frame's window save area.
796 ??? Perhaps we should note in the CIE where windows are saved (instead of
797 assuming 0(cfa)) and what registers are in the window. */
800 dwarf2out_window_save (label)
803 dw_cfi_ref cfi = new_cfi ();
804 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
805 add_fde_cfi (label, cfi);
808 /* Add a CFI to update the running total of the size of arguments
809 pushed onto the stack. */
812 dwarf2out_args_size (label, size)
818 if (size == old_args_size)
820 old_args_size = size;
823 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
824 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
825 add_fde_cfi (label, cfi);
828 /* Entry point for saving a register to the stack. REG is the GCC register
829 number. LABEL and OFFSET are passed to reg_save. */
832 dwarf2out_reg_save (label, reg, offset)
837 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
840 /* Entry point for saving the return address in the stack.
841 LABEL and OFFSET are passed to reg_save. */
844 dwarf2out_return_save (label, offset)
848 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
851 /* Entry point for saving the return address in a register.
852 LABEL and SREG are passed to reg_save. */
855 dwarf2out_return_reg (label, sreg)
859 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
862 /* Record the initial position of the return address. RTL is
863 INCOMING_RETURN_ADDR_RTX. */
866 initial_return_save (rtl)
869 unsigned int reg = (unsigned int) -1;
872 switch (GET_CODE (rtl))
875 /* RA is in a register. */
876 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
879 /* RA is on the stack. */
881 switch (GET_CODE (rtl))
884 if (REGNO (rtl) != STACK_POINTER_REGNUM)
889 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
891 offset = INTVAL (XEXP (rtl, 1));
894 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
896 offset = -INTVAL (XEXP (rtl, 1));
903 /* The return address is at some offset from any value we can
904 actually load. For instance, on the SPARC it is in %i7+8. Just
905 ignore the offset for now; it doesn't matter for unwinding frames. */
906 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
908 initial_return_save (XEXP (rtl, 0));
914 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
917 /* Given a SET, calculate the amount of stack adjustment it
921 stack_adjust_offset (pattern)
924 rtx src = SET_SRC (pattern);
925 rtx dest = SET_DEST (pattern);
929 if (dest == stack_pointer_rtx)
931 /* (set (reg sp) (plus (reg sp) (const_int))) */
932 code = GET_CODE (src);
933 if (! (code == PLUS || code == MINUS)
934 || XEXP (src, 0) != stack_pointer_rtx
935 || GET_CODE (XEXP (src, 1)) != CONST_INT)
938 offset = INTVAL (XEXP (src, 1));
940 else if (GET_CODE (dest) == MEM)
942 /* (set (mem (pre_dec (reg sp))) (foo)) */
943 src = XEXP (dest, 0);
944 code = GET_CODE (src);
946 if (! (code == PRE_DEC || code == PRE_INC
947 || code == PRE_MODIFY)
948 || XEXP (src, 0) != stack_pointer_rtx)
951 if (code == PRE_MODIFY)
953 rtx val = XEXP (XEXP (src, 1), 1);
954 /* We handle only adjustments by constant amount. */
955 if (GET_CODE (XEXP (src, 1)) != PLUS ||
956 GET_CODE (val) != CONST_INT)
958 offset = -INTVAL (val);
960 else offset = GET_MODE_SIZE (GET_MODE (dest));
965 if (code == PLUS || code == PRE_INC)
971 /* Check INSN to see if it looks like a push or a stack adjustment, and
972 make a note of it if it does. EH uses this information to find out how
973 much extra space it needs to pop off the stack. */
976 dwarf2out_stack_adjust (insn)
982 if (!flag_asynchronous_unwind_tables
983 && GET_CODE (insn) == CALL_INSN)
985 /* Extract the size of the args from the CALL rtx itself. */
987 insn = PATTERN (insn);
988 if (GET_CODE (insn) == PARALLEL)
989 insn = XVECEXP (insn, 0, 0);
990 if (GET_CODE (insn) == SET)
991 insn = SET_SRC (insn);
992 if (GET_CODE (insn) != CALL)
994 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
998 /* If only calls can throw, and we have a frame pointer,
999 save up adjustments until we see the CALL_INSN. */
1000 else if (!flag_asynchronous_unwind_tables
1001 && cfa.reg != STACK_POINTER_REGNUM)
1004 if (GET_CODE (insn) == BARRIER)
1006 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1007 the compiler will have already emitted a stack adjustment, but
1008 doesn't bother for calls to noreturn functions. */
1009 #ifdef STACK_GROWS_DOWNWARD
1010 offset = -args_size;
1015 else if (GET_CODE (PATTERN (insn)) == SET)
1017 offset = stack_adjust_offset (PATTERN (insn));
1019 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1020 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1022 /* There may be stack adjustments inside compound insns. Search
1027 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1029 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1030 if (GET_CODE (pattern) == SET)
1031 offset += stack_adjust_offset (pattern);
1040 if (cfa.reg == STACK_POINTER_REGNUM)
1041 cfa.offset += offset;
1043 #ifndef STACK_GROWS_DOWNWARD
1046 args_size += offset;
1050 label = dwarf2out_cfi_label ();
1051 def_cfa_1 (label, &cfa);
1052 dwarf2out_args_size (label, args_size);
1055 /* We delay emitting a register save until either (a) we reach the end
1056 of the prologue or (b) the register is clobbered. This clusters
1057 register saves so that there are fewer pc advances. */
1059 struct queued_reg_save
1061 struct queued_reg_save *next;
1066 static struct queued_reg_save *queued_reg_saves;
1067 static const char *last_reg_save_label;
1070 queue_reg_save (label, reg, offset)
1075 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1077 q->next = queued_reg_saves;
1079 q->cfa_offset = offset;
1080 queued_reg_saves = q;
1082 last_reg_save_label = label;
1086 flush_queued_reg_saves ()
1088 struct queued_reg_save *q, *next;
1090 for (q = queued_reg_saves; q ; q = next)
1092 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1097 queued_reg_saves = NULL;
1098 last_reg_save_label = NULL;
1102 clobbers_queued_reg_save (insn)
1105 struct queued_reg_save *q;
1107 for (q = queued_reg_saves; q ; q = q->next)
1108 if (modified_in_p (q->reg, insn))
1115 /* A temporary register holding an integral value used in adjusting SP
1116 or setting up the store_reg. The "offset" field holds the integer
1117 value, not an offset. */
1118 static dw_cfa_location cfa_temp;
1120 /* Record call frame debugging information for an expression EXPR,
1121 which either sets SP or FP (adjusting how we calculate the frame
1122 address) or saves a register to the stack. LABEL indicates the
1125 This function encodes a state machine mapping rtxes to actions on
1126 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1127 users need not read the source code.
1129 The High-Level Picture
1131 Changes in the register we use to calculate the CFA: Currently we
1132 assume that if you copy the CFA register into another register, we
1133 should take the other one as the new CFA register; this seems to
1134 work pretty well. If it's wrong for some target, it's simple
1135 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1137 Changes in the register we use for saving registers to the stack:
1138 This is usually SP, but not always. Again, we deduce that if you
1139 copy SP into another register (and SP is not the CFA register),
1140 then the new register is the one we will be using for register
1141 saves. This also seems to work.
1143 Register saves: There's not much guesswork about this one; if
1144 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1145 register save, and the register used to calculate the destination
1146 had better be the one we think we're using for this purpose.
1148 Except: If the register being saved is the CFA register, and the
1149 offset is non-zero, we are saving the CFA, so we assume we have to
1150 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1151 the intent is to save the value of SP from the previous frame.
1153 Invariants / Summaries of Rules
1155 cfa current rule for calculating the CFA. It usually
1156 consists of a register and an offset.
1157 cfa_store register used by prologue code to save things to the stack
1158 cfa_store.offset is the offset from the value of
1159 cfa_store.reg to the actual CFA
1160 cfa_temp register holding an integral value. cfa_temp.offset
1161 stores the value, which will be used to adjust the
1162 stack pointer. cfa_temp is also used like cfa_store,
1163 to track stores to the stack via fp or a temp reg.
1165 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1166 with cfa.reg as the first operand changes the cfa.reg and its
1167 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1170 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1171 expression yielding a constant. This sets cfa_temp.reg
1172 and cfa_temp.offset.
1174 Rule 5: Create a new register cfa_store used to save items to the
1177 Rules 10-14: Save a register to the stack. Define offset as the
1178 difference of the original location and cfa_store's
1179 location (or cfa_temp's location if cfa_temp is used).
1183 "{a,b}" indicates a choice of a xor b.
1184 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1187 (set <reg1> <reg2>:cfa.reg)
1188 effects: cfa.reg = <reg1>
1189 cfa.offset unchanged
1190 cfa_temp.reg = <reg1>
1191 cfa_temp.offset = cfa.offset
1194 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1195 effects: cfa.reg = sp if fp used
1196 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1197 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1198 if cfa_store.reg==sp
1201 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1202 effects: cfa.reg = fp
1203 cfa_offset += +/- <const_int>
1206 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1207 constraints: <reg1> != fp
1209 effects: cfa.reg = <reg1>
1210 cfa_temp.reg = <reg1>
1211 cfa_temp.offset = cfa.offset
1214 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1215 constraints: <reg1> != fp
1217 effects: cfa_store.reg = <reg1>
1218 cfa_store.offset = cfa.offset - cfa_temp.offset
1221 (set <reg> <const_int>)
1222 effects: cfa_temp.reg = <reg>
1223 cfa_temp.offset = <const_int>
1226 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1227 effects: cfa_temp.reg = <reg1>
1228 cfa_temp.offset |= <const_int>
1231 (set <reg> (high <exp>))
1235 (set <reg> (lo_sum <exp> <const_int>))
1236 effects: cfa_temp.reg = <reg>
1237 cfa_temp.offset = <const_int>
1240 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1241 effects: cfa_store.offset -= <const_int>
1242 cfa.offset = cfa_store.offset if cfa.reg == sp
1244 cfa.base_offset = -cfa_store.offset
1247 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1248 effects: cfa_store.offset += -/+ mode_size(mem)
1249 cfa.offset = cfa_store.offset if cfa.reg == sp
1251 cfa.base_offset = -cfa_store.offset
1254 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>)
1255 effects: cfa.reg = <reg1>
1256 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1259 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1260 effects: cfa.reg = <reg1>
1261 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1264 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1265 effects: cfa.reg = <reg1>
1266 cfa.base_offset = -cfa_temp.offset
1267 cfa_temp.offset -= mode_size(mem) */
1270 dwarf2out_frame_debug_expr (expr, label)
1277 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1278 the PARALLEL independently. The first element is always processed if
1279 it is a SET. This is for backward compatibility. Other elements
1280 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1281 flag is set in them. */
1283 if (GET_CODE (expr) == PARALLEL
1284 || GET_CODE (expr) == SEQUENCE)
1287 int limit = XVECLEN (expr, 0);
1289 for (par_index = 0; par_index < limit; par_index++)
1291 rtx x = XVECEXP (expr, 0, par_index);
1293 if (GET_CODE (x) == SET &&
1294 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1295 dwarf2out_frame_debug_expr (x, label);
1300 if (GET_CODE (expr) != SET)
1303 src = SET_SRC (expr);
1304 dest = SET_DEST (expr);
1306 switch (GET_CODE (dest))
1310 /* Update the CFA rule wrt SP or FP. Make sure src is
1311 relative to the current CFA register. */
1312 switch (GET_CODE (src))
1314 /* Setting FP from SP. */
1316 if (cfa.reg == (unsigned) REGNO (src))
1322 /* We used to require that dest be either SP or FP, but the
1323 ARM copies SP to a temporary register, and from there to
1324 FP. So we just rely on the backends to only set
1325 RTX_FRAME_RELATED_P on appropriate insns. */
1326 cfa.reg = REGNO (dest);
1327 cfa_temp.reg = cfa.reg;
1328 cfa_temp.offset = cfa.offset;
1334 if (dest == stack_pointer_rtx)
1338 switch (GET_CODE (XEXP (src, 1)))
1341 offset = INTVAL (XEXP (src, 1));
1344 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1346 offset = cfa_temp.offset;
1352 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1354 /* Restoring SP from FP in the epilogue. */
1355 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1357 cfa.reg = STACK_POINTER_REGNUM;
1359 else if (GET_CODE (src) == LO_SUM)
1360 /* Assume we've set the source reg of the LO_SUM from sp. */
1362 else if (XEXP (src, 0) != stack_pointer_rtx)
1365 if (GET_CODE (src) != MINUS)
1367 if (cfa.reg == STACK_POINTER_REGNUM)
1368 cfa.offset += offset;
1369 if (cfa_store.reg == STACK_POINTER_REGNUM)
1370 cfa_store.offset += offset;
1372 else if (dest == hard_frame_pointer_rtx)
1375 /* Either setting the FP from an offset of the SP,
1376 or adjusting the FP */
1377 if (! frame_pointer_needed)
1380 if (GET_CODE (XEXP (src, 0)) == REG
1381 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1382 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1384 offset = INTVAL (XEXP (src, 1));
1385 if (GET_CODE (src) != MINUS)
1387 cfa.offset += offset;
1388 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1395 if (GET_CODE (src) == MINUS)
1399 if (GET_CODE (XEXP (src, 0)) == REG
1400 && REGNO (XEXP (src, 0)) == cfa.reg
1401 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1403 /* Setting a temporary CFA register that will be copied
1404 into the FP later on. */
1405 offset = - INTVAL (XEXP (src, 1));
1406 cfa.offset += offset;
1407 cfa.reg = REGNO (dest);
1408 /* Or used to save regs to the stack. */
1409 cfa_temp.reg = cfa.reg;
1410 cfa_temp.offset = cfa.offset;
1413 else if (GET_CODE (XEXP (src, 0)) == REG
1414 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1415 && XEXP (src, 1) == stack_pointer_rtx)
1417 /* Setting a scratch register that we will use instead
1418 of SP for saving registers to the stack. */
1419 if (cfa.reg != STACK_POINTER_REGNUM)
1421 cfa_store.reg = REGNO (dest);
1422 cfa_store.offset = cfa.offset - cfa_temp.offset;
1425 else if (GET_CODE (src) == LO_SUM
1426 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1428 cfa_temp.reg = REGNO (dest);
1429 cfa_temp.offset = INTVAL (XEXP (src, 1));
1438 cfa_temp.reg = REGNO (dest);
1439 cfa_temp.offset = INTVAL (src);
1444 if (GET_CODE (XEXP (src, 0)) != REG
1445 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1446 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1448 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1449 cfa_temp.reg = REGNO (dest);
1450 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1453 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1454 which will fill in all of the bits. */
1462 def_cfa_1 (label, &cfa);
1466 if (GET_CODE (src) != REG)
1469 /* Saving a register to the stack. Make sure dest is relative to the
1471 switch (GET_CODE (XEXP (dest, 0)))
1476 /* We can't handle variable size modifications. */
1477 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1479 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1481 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1482 || cfa_store.reg != STACK_POINTER_REGNUM)
1484 cfa_store.offset += offset;
1485 if (cfa.reg == STACK_POINTER_REGNUM)
1486 cfa.offset = cfa_store.offset;
1488 offset = -cfa_store.offset;
1493 offset = GET_MODE_SIZE (GET_MODE (dest));
1494 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1497 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1498 || cfa_store.reg != STACK_POINTER_REGNUM)
1500 cfa_store.offset += offset;
1501 if (cfa.reg == STACK_POINTER_REGNUM)
1502 cfa.offset = cfa_store.offset;
1504 offset = -cfa_store.offset;
1508 /* With an offset. */
1512 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1514 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1515 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1518 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1519 offset -= cfa_store.offset;
1520 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1521 offset -= cfa_temp.offset;
1527 /* Without an offset. */
1529 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1530 offset = -cfa_store.offset;
1531 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1532 offset = -cfa_temp.offset;
1539 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1541 offset = -cfa_temp.offset;
1542 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1549 if (REGNO (src) != STACK_POINTER_REGNUM
1550 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1551 && (unsigned) REGNO (src) == cfa.reg)
1553 /* We're storing the current CFA reg into the stack. */
1555 if (cfa.offset == 0)
1557 /* If the source register is exactly the CFA, assume
1558 we're saving SP like any other register; this happens
1561 def_cfa_1 (label, &cfa);
1562 queue_reg_save (label, stack_pointer_rtx, offset);
1567 /* Otherwise, we'll need to look in the stack to
1568 calculate the CFA. */
1570 rtx x = XEXP (dest, 0);
1571 if (GET_CODE (x) != REG)
1573 if (GET_CODE (x) != REG)
1575 cfa.reg = (unsigned) REGNO (x);
1576 cfa.base_offset = offset;
1578 def_cfa_1 (label, &cfa);
1583 def_cfa_1 (label, &cfa);
1584 queue_reg_save (label, src, offset);
1592 /* Record call frame debugging information for INSN, which either
1593 sets SP or FP (adjusting how we calculate the frame address) or saves a
1594 register to the stack. If INSN is NULL_RTX, initialize our state. */
1597 dwarf2out_frame_debug (insn)
1603 if (insn == NULL_RTX)
1605 /* Flush any queued register saves. */
1606 flush_queued_reg_saves ();
1608 /* Set up state for generating call frame debug info. */
1610 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1612 cfa.reg = STACK_POINTER_REGNUM;
1615 cfa_temp.offset = 0;
1619 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1620 flush_queued_reg_saves ();
1622 if (! RTX_FRAME_RELATED_P (insn))
1624 if (!ACCUMULATE_OUTGOING_ARGS)
1625 dwarf2out_stack_adjust (insn);
1629 label = dwarf2out_cfi_label ();
1631 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1633 insn = XEXP (src, 0);
1635 insn = PATTERN (insn);
1637 dwarf2out_frame_debug_expr (insn, label);
1640 /* Output a Call Frame Information opcode and its operand(s). */
1643 output_cfi (cfi, fde, for_eh)
1648 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1650 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1651 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1652 "DW_CFA_advance_loc 0x%lx",
1653 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1655 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1657 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1658 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1659 "DW_CFA_offset, column 0x%lx",
1660 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1661 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1663 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1665 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1666 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1667 "DW_CFA_restore, column 0x%lx",
1668 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1672 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1673 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1675 switch (cfi->dw_cfi_opc)
1677 case DW_CFA_set_loc:
1679 dw2_asm_output_encoded_addr_rtx (
1680 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1681 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1684 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1685 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1687 case DW_CFA_advance_loc1:
1688 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1689 fde->dw_fde_current_label, NULL);
1690 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1692 case DW_CFA_advance_loc2:
1693 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1694 fde->dw_fde_current_label, NULL);
1695 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1697 case DW_CFA_advance_loc4:
1698 dw2_asm_output_delta (4, 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;
1702 case DW_CFA_MIPS_advance_loc8:
1703 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1704 fde->dw_fde_current_label, NULL);
1705 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1707 case DW_CFA_offset_extended:
1708 case DW_CFA_GNU_negative_offset_extended:
1709 case DW_CFA_def_cfa:
1710 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1711 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1713 case DW_CFA_restore_extended:
1714 case DW_CFA_undefined:
1715 case DW_CFA_same_value:
1716 case DW_CFA_def_cfa_register:
1717 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1719 case DW_CFA_register:
1720 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1721 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1723 case DW_CFA_def_cfa_offset:
1724 case DW_CFA_GNU_args_size:
1725 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1727 case DW_CFA_GNU_window_save:
1729 case DW_CFA_def_cfa_expression:
1730 output_cfa_loc (cfi);
1738 /* Output the call frame information used to used to record information
1739 that relates to calculating the frame pointer, and records the
1740 location of saved registers. */
1743 output_call_frame_info (for_eh)
1749 char l1[20], l2[20], section_start_label[20];
1750 int any_lsda_needed = 0;
1751 char augmentation[6];
1752 int augmentation_size;
1753 int fde_encoding = DW_EH_PE_absptr;
1754 int per_encoding = DW_EH_PE_absptr;
1755 int lsda_encoding = DW_EH_PE_absptr;
1757 /* If we don't have any functions we'll want to unwind out of, don't
1758 emit any EH unwind information. */
1761 int any_eh_needed = flag_asynchronous_unwind_tables;
1762 for (i = 0; i < fde_table_in_use; ++i)
1763 if (fde_table[i].uses_eh_lsda)
1764 any_eh_needed = any_lsda_needed = 1;
1765 else if (! fde_table[i].nothrow)
1768 if (! any_eh_needed)
1772 /* We're going to be generating comments, so turn on app. */
1777 (*targetm.asm_out.eh_frame_section) ();
1779 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1781 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1782 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1784 /* Output the CIE. */
1785 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1786 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1787 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1788 "Length of Common Information Entry");
1789 ASM_OUTPUT_LABEL (asm_out_file, l1);
1791 /* Now that the CIE pointer is PC-relative for EH,
1792 use 0 to identify the CIE. */
1793 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1794 (for_eh ? 0 : DW_CIE_ID),
1795 "CIE Identifier Tag");
1797 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1799 augmentation[0] = 0;
1800 augmentation_size = 0;
1806 z Indicates that a uleb128 is present to size the
1807 augmentation section.
1808 L Indicates the encoding (and thus presence) of
1809 an LSDA pointer in the FDE augmentation.
1810 R Indicates a non-default pointer encoding for
1812 P Indicates the presence of an encoding + language
1813 personality routine in the CIE augmentation. */
1815 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1816 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1817 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1819 p = augmentation + 1;
1820 if (eh_personality_libfunc)
1823 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1825 if (any_lsda_needed)
1828 augmentation_size += 1;
1830 if (fde_encoding != DW_EH_PE_absptr)
1833 augmentation_size += 1;
1835 if (p > augmentation + 1)
1837 augmentation[0] = 'z';
1841 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1842 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1844 int offset = ( 4 /* Length */
1846 + 1 /* CIE version */
1847 + strlen (augmentation) + 1 /* Augmentation */
1848 + size_of_uleb128 (1) /* Code alignment */
1849 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1851 + 1 /* Augmentation size */
1852 + 1 /* Personality encoding */ );
1853 int pad = -offset & (PTR_SIZE - 1);
1855 augmentation_size += pad;
1857 /* Augmentations should be small, so there's scarce need to
1858 iterate for a solution. Die if we exceed one uleb128 byte. */
1859 if (size_of_uleb128 (augmentation_size) != 1)
1863 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1865 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1867 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1868 "CIE Data Alignment Factor");
1870 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1872 if (augmentation[0])
1874 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1875 if (eh_personality_libfunc)
1877 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1878 eh_data_format_name (per_encoding));
1879 dw2_asm_output_encoded_addr_rtx (per_encoding,
1880 eh_personality_libfunc, NULL);
1882 if (any_lsda_needed)
1883 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1884 eh_data_format_name (lsda_encoding));
1885 if (fde_encoding != DW_EH_PE_absptr)
1886 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1887 eh_data_format_name (fde_encoding));
1890 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1891 output_cfi (cfi, NULL, for_eh);
1893 /* Pad the CIE out to an address sized boundary. */
1894 ASM_OUTPUT_ALIGN (asm_out_file,
1895 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1896 ASM_OUTPUT_LABEL (asm_out_file, l2);
1898 /* Loop through all of the FDE's. */
1899 for (i = 0; i < fde_table_in_use; ++i)
1901 fde = &fde_table[i];
1903 /* Don't emit EH unwind info for leaf functions that don't need it. */
1904 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1907 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1908 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1909 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1910 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1912 ASM_OUTPUT_LABEL (asm_out_file, l1);
1915 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
1917 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
1922 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1923 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1924 "FDE initial location");
1925 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1926 fde->dw_fde_end, fde->dw_fde_begin,
1927 "FDE address range");
1931 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1932 "FDE initial location");
1933 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1934 fde->dw_fde_end, fde->dw_fde_begin,
1935 "FDE address range");
1938 if (augmentation[0])
1940 if (any_lsda_needed)
1942 int size = size_of_encoded_value (lsda_encoding);
1944 if (lsda_encoding == DW_EH_PE_aligned)
1946 int offset = ( 4 /* Length */
1947 + 4 /* CIE offset */
1948 + 2 * size_of_encoded_value (fde_encoding)
1949 + 1 /* Augmentation size */ );
1950 int pad = -offset & (PTR_SIZE - 1);
1953 if (size_of_uleb128 (size) != 1)
1957 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1959 if (fde->uses_eh_lsda)
1961 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
1962 fde->funcdef_number);
1963 dw2_asm_output_encoded_addr_rtx (
1964 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
1965 "Language Specific Data Area");
1969 if (lsda_encoding == DW_EH_PE_aligned)
1970 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1971 dw2_asm_output_data (size_of_encoded_value (lsda_encoding),
1972 0, "Language Specific Data Area (none)");
1976 dw2_asm_output_data_uleb128 (0, "Augmentation size");
1979 /* Loop through the Call Frame Instructions associated with
1981 fde->dw_fde_current_label = fde->dw_fde_begin;
1982 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1983 output_cfi (cfi, fde, for_eh);
1985 /* Pad the FDE out to an address sized boundary. */
1986 ASM_OUTPUT_ALIGN (asm_out_file,
1987 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1988 ASM_OUTPUT_LABEL (asm_out_file, l2);
1991 #ifndef EH_FRAME_SECTION_NAME
1993 dw2_asm_output_data (4, 0, "End of Table");
1995 #ifdef MIPS_DEBUGGING_INFO
1996 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1997 get a value of 0. Putting .align 0 after the label fixes it. */
1998 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2001 /* Turn off app to make assembly quicker. */
2006 /* Output a marker (i.e. a label) for the beginning of a function, before
2010 dwarf2out_begin_prologue (line, file)
2011 unsigned int line ATTRIBUTE_UNUSED;
2012 const char *file ATTRIBUTE_UNUSED;
2014 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2017 current_function_func_begin_label = 0;
2019 #ifdef IA64_UNWIND_INFO
2020 /* ??? current_function_func_begin_label is also used by except.c
2021 for call-site information. We must emit this label if it might
2023 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2024 && ! dwarf2out_do_frame ())
2027 if (! dwarf2out_do_frame ())
2031 ++current_funcdef_number;
2033 function_section (current_function_decl);
2034 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2035 current_funcdef_number);
2036 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2037 current_funcdef_number);
2038 current_function_func_begin_label = get_identifier (label);
2040 #ifdef IA64_UNWIND_INFO
2041 /* We can elide the fde allocation if we're not emitting debug info. */
2042 if (! dwarf2out_do_frame ())
2046 /* Expand the fde table if necessary. */
2047 if (fde_table_in_use == fde_table_allocated)
2049 fde_table_allocated += FDE_TABLE_INCREMENT;
2051 = (dw_fde_ref) xrealloc (fde_table,
2052 fde_table_allocated * sizeof (dw_fde_node));
2055 /* Record the FDE associated with this function. */
2056 current_funcdef_fde = fde_table_in_use;
2058 /* Add the new FDE at the end of the fde_table. */
2059 fde = &fde_table[fde_table_in_use++];
2060 fde->dw_fde_begin = xstrdup (label);
2061 fde->dw_fde_current_label = NULL;
2062 fde->dw_fde_end = NULL;
2063 fde->dw_fde_cfi = NULL;
2064 fde->funcdef_number = current_funcdef_number;
2065 fde->nothrow = current_function_nothrow;
2066 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2068 args_size = old_args_size = 0;
2070 /* We only want to output line number information for the genuine
2071 dwarf2 prologue case, not the eh frame case. */
2072 #ifdef DWARF2_DEBUGGING_INFO
2074 dwarf2out_source_line (line, file);
2078 /* Output a marker (i.e. a label) for the absolute end of the generated code
2079 for a function definition. This gets called *after* the epilogue code has
2083 dwarf2out_end_epilogue ()
2086 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2088 /* Output a label to mark the endpoint of the code generated for this
2090 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2091 ASM_OUTPUT_LABEL (asm_out_file, label);
2092 fde = &fde_table[fde_table_in_use - 1];
2093 fde->dw_fde_end = xstrdup (label);
2097 dwarf2out_frame_init ()
2099 /* Allocate the initial hunk of the fde_table. */
2100 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2101 fde_table_allocated = FDE_TABLE_INCREMENT;
2102 fde_table_in_use = 0;
2104 /* Generate the CFA instructions common to all FDE's. Do it now for the
2105 sake of lookup_cfa. */
2107 #ifdef DWARF2_UNWIND_INFO
2108 /* On entry, the Canonical Frame Address is at SP. */
2109 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2110 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2115 dwarf2out_frame_finish ()
2117 /* Output call frame information. */
2118 if (write_symbols == DWARF2_DEBUG)
2119 output_call_frame_info (0);
2120 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2121 output_call_frame_info (1);
2124 /* And now, the subset of the debugging information support code necessary
2125 for emitting location expressions. */
2127 typedef struct dw_val_struct *dw_val_ref;
2128 typedef struct die_struct *dw_die_ref;
2129 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2130 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2132 /* Each DIE may have a series of attribute/value pairs. Values
2133 can take on several forms. The forms that are used in this
2134 implementation are listed below. */
2139 dw_val_class_offset,
2141 dw_val_class_loc_list,
2143 dw_val_class_unsigned_const,
2144 dw_val_class_long_long,
2147 dw_val_class_die_ref,
2148 dw_val_class_fde_ref,
2149 dw_val_class_lbl_id,
2150 dw_val_class_lbl_offset,
2155 /* Describe a double word constant value. */
2156 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2158 typedef struct dw_long_long_struct
2165 /* Describe a floating point constant value. */
2167 typedef struct dw_fp_struct
2174 /* The dw_val_node describes an attribute's value, as it is
2175 represented internally. */
2177 typedef struct dw_val_struct
2179 dw_val_class val_class;
2183 long unsigned val_offset;
2184 dw_loc_list_ref val_loc_list;
2185 dw_loc_descr_ref val_loc;
2187 long unsigned val_unsigned;
2188 dw_long_long_const val_long_long;
2189 dw_float_const val_float;
2194 unsigned val_fde_index;
2195 struct indirect_string_node *val_str;
2197 unsigned char val_flag;
2203 /* Locations in memory are described using a sequence of stack machine
2206 typedef struct dw_loc_descr_struct
2208 dw_loc_descr_ref dw_loc_next;
2209 enum dwarf_location_atom dw_loc_opc;
2210 dw_val_node dw_loc_oprnd1;
2211 dw_val_node dw_loc_oprnd2;
2216 /* Location lists are ranges + location descriptions for that range,
2217 so you can track variables that are in different places over
2218 their entire life. */
2219 typedef struct dw_loc_list_struct
2221 dw_loc_list_ref dw_loc_next;
2222 const char *begin; /* Label for begin address of range */
2223 const char *end; /* Label for end address of range */
2224 char *ll_symbol; /* Label for beginning of location list. Only on head of list */
2225 const char *section; /* Section this loclist is relative to */
2226 dw_loc_descr_ref expr;
2229 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2230 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2233 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2235 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2236 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2237 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2238 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2240 /* Convert a DWARF stack opcode into its string name. */
2243 dwarf_stack_op_name (op)
2249 return "DW_OP_addr";
2251 return "DW_OP_deref";
2253 return "DW_OP_const1u";
2255 return "DW_OP_const1s";
2257 return "DW_OP_const2u";
2259 return "DW_OP_const2s";
2261 return "DW_OP_const4u";
2263 return "DW_OP_const4s";
2265 return "DW_OP_const8u";
2267 return "DW_OP_const8s";
2269 return "DW_OP_constu";
2271 return "DW_OP_consts";
2275 return "DW_OP_drop";
2277 return "DW_OP_over";
2279 return "DW_OP_pick";
2281 return "DW_OP_swap";
2285 return "DW_OP_xderef";
2293 return "DW_OP_minus";
2305 return "DW_OP_plus";
2306 case DW_OP_plus_uconst:
2307 return "DW_OP_plus_uconst";
2313 return "DW_OP_shra";
2331 return "DW_OP_skip";
2333 return "DW_OP_lit0";
2335 return "DW_OP_lit1";
2337 return "DW_OP_lit2";
2339 return "DW_OP_lit3";
2341 return "DW_OP_lit4";
2343 return "DW_OP_lit5";
2345 return "DW_OP_lit6";
2347 return "DW_OP_lit7";
2349 return "DW_OP_lit8";
2351 return "DW_OP_lit9";
2353 return "DW_OP_lit10";
2355 return "DW_OP_lit11";
2357 return "DW_OP_lit12";
2359 return "DW_OP_lit13";
2361 return "DW_OP_lit14";
2363 return "DW_OP_lit15";
2365 return "DW_OP_lit16";
2367 return "DW_OP_lit17";
2369 return "DW_OP_lit18";
2371 return "DW_OP_lit19";
2373 return "DW_OP_lit20";
2375 return "DW_OP_lit21";
2377 return "DW_OP_lit22";
2379 return "DW_OP_lit23";
2381 return "DW_OP_lit24";
2383 return "DW_OP_lit25";
2385 return "DW_OP_lit26";
2387 return "DW_OP_lit27";
2389 return "DW_OP_lit28";
2391 return "DW_OP_lit29";
2393 return "DW_OP_lit30";
2395 return "DW_OP_lit31";
2397 return "DW_OP_reg0";
2399 return "DW_OP_reg1";
2401 return "DW_OP_reg2";
2403 return "DW_OP_reg3";
2405 return "DW_OP_reg4";
2407 return "DW_OP_reg5";
2409 return "DW_OP_reg6";
2411 return "DW_OP_reg7";
2413 return "DW_OP_reg8";
2415 return "DW_OP_reg9";
2417 return "DW_OP_reg10";
2419 return "DW_OP_reg11";
2421 return "DW_OP_reg12";
2423 return "DW_OP_reg13";
2425 return "DW_OP_reg14";
2427 return "DW_OP_reg15";
2429 return "DW_OP_reg16";
2431 return "DW_OP_reg17";
2433 return "DW_OP_reg18";
2435 return "DW_OP_reg19";
2437 return "DW_OP_reg20";
2439 return "DW_OP_reg21";
2441 return "DW_OP_reg22";
2443 return "DW_OP_reg23";
2445 return "DW_OP_reg24";
2447 return "DW_OP_reg25";
2449 return "DW_OP_reg26";
2451 return "DW_OP_reg27";
2453 return "DW_OP_reg28";
2455 return "DW_OP_reg29";
2457 return "DW_OP_reg30";
2459 return "DW_OP_reg31";
2461 return "DW_OP_breg0";
2463 return "DW_OP_breg1";
2465 return "DW_OP_breg2";
2467 return "DW_OP_breg3";
2469 return "DW_OP_breg4";
2471 return "DW_OP_breg5";
2473 return "DW_OP_breg6";
2475 return "DW_OP_breg7";
2477 return "DW_OP_breg8";
2479 return "DW_OP_breg9";
2481 return "DW_OP_breg10";
2483 return "DW_OP_breg11";
2485 return "DW_OP_breg12";
2487 return "DW_OP_breg13";
2489 return "DW_OP_breg14";
2491 return "DW_OP_breg15";
2493 return "DW_OP_breg16";
2495 return "DW_OP_breg17";
2497 return "DW_OP_breg18";
2499 return "DW_OP_breg19";
2501 return "DW_OP_breg20";
2503 return "DW_OP_breg21";
2505 return "DW_OP_breg22";
2507 return "DW_OP_breg23";
2509 return "DW_OP_breg24";
2511 return "DW_OP_breg25";
2513 return "DW_OP_breg26";
2515 return "DW_OP_breg27";
2517 return "DW_OP_breg28";
2519 return "DW_OP_breg29";
2521 return "DW_OP_breg30";
2523 return "DW_OP_breg31";
2525 return "DW_OP_regx";
2527 return "DW_OP_fbreg";
2529 return "DW_OP_bregx";
2531 return "DW_OP_piece";
2532 case DW_OP_deref_size:
2533 return "DW_OP_deref_size";
2534 case DW_OP_xderef_size:
2535 return "DW_OP_xderef_size";
2539 return "OP_<unknown>";
2543 /* Return a pointer to a newly allocated location description. Location
2544 descriptions are simple expression terms that can be strung
2545 together to form more complicated location (address) descriptions. */
2547 static inline dw_loc_descr_ref
2548 new_loc_descr (op, oprnd1, oprnd2)
2549 enum dwarf_location_atom op;
2550 unsigned long oprnd1;
2551 unsigned long oprnd2;
2553 /* Use xcalloc here so we clear out all of the long_long constant in
2555 dw_loc_descr_ref descr
2556 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2558 descr->dw_loc_opc = op;
2559 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2560 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2561 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2562 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2568 /* Add a location description term to a location description expression. */
2571 add_loc_descr (list_head, descr)
2572 dw_loc_descr_ref *list_head;
2573 dw_loc_descr_ref descr;
2575 dw_loc_descr_ref *d;
2577 /* Find the end of the chain. */
2578 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2584 /* Return the size of a location descriptor. */
2586 static unsigned long
2587 size_of_loc_descr (loc)
2588 dw_loc_descr_ref loc;
2590 unsigned long size = 1;
2592 switch (loc->dw_loc_opc)
2595 size += DWARF2_ADDR_SIZE;
2614 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2617 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2622 case DW_OP_plus_uconst:
2623 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2661 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2664 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2667 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2670 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2671 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2674 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2676 case DW_OP_deref_size:
2677 case DW_OP_xderef_size:
2687 /* Return the size of a series of location descriptors. */
2689 static unsigned long
2691 dw_loc_descr_ref loc;
2693 unsigned long size = 0;
2695 for (; loc != NULL; loc = loc->dw_loc_next)
2697 loc->dw_loc_addr = size;
2698 size += size_of_loc_descr (loc);
2704 /* Output location description stack opcode's operands (if any). */
2707 output_loc_operands (loc)
2708 dw_loc_descr_ref loc;
2710 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2711 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2713 switch (loc->dw_loc_opc)
2715 #ifdef DWARF2_DEBUGGING_INFO
2717 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2721 dw2_asm_output_data (2, val1->v.val_int, NULL);
2725 dw2_asm_output_data (4, val1->v.val_int, NULL);
2729 if (HOST_BITS_PER_LONG < 64)
2731 dw2_asm_output_data (8, val1->v.val_int, NULL);
2738 if (val1->val_class == dw_val_class_loc)
2739 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2743 dw2_asm_output_data (2, offset, NULL);
2756 /* We currently don't make any attempt to make sure these are
2757 aligned properly like we do for the main unwind info, so
2758 don't support emitting things larger than a byte if we're
2759 only doing unwinding. */
2764 dw2_asm_output_data (1, val1->v.val_int, NULL);
2767 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2770 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2773 dw2_asm_output_data (1, val1->v.val_int, NULL);
2775 case DW_OP_plus_uconst:
2776 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2810 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2813 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2816 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2819 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2820 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2823 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2825 case DW_OP_deref_size:
2826 case DW_OP_xderef_size:
2827 dw2_asm_output_data (1, val1->v.val_int, NULL);
2830 /* Other codes have no operands. */
2835 /* Output a sequence of location operations. */
2838 output_loc_sequence (loc)
2839 dw_loc_descr_ref loc;
2841 for (; loc != NULL; loc = loc->dw_loc_next)
2843 /* Output the opcode. */
2844 dw2_asm_output_data (1, loc->dw_loc_opc,
2845 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2847 /* Output the operand(s) (if any). */
2848 output_loc_operands (loc);
2852 /* This routine will generate the correct assembly data for a location
2853 description based on a cfi entry with a complex address. */
2856 output_cfa_loc (cfi)
2859 dw_loc_descr_ref loc;
2862 /* Output the size of the block. */
2863 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2864 size = size_of_locs (loc);
2865 dw2_asm_output_data_uleb128 (size, NULL);
2867 /* Now output the operations themselves. */
2868 output_loc_sequence (loc);
2871 /* This function builds a dwarf location descriptor sequence from
2872 a dw_cfa_location. */
2874 static struct dw_loc_descr_struct *
2876 dw_cfa_location *cfa;
2878 struct dw_loc_descr_struct *head, *tmp;
2880 if (cfa->indirect == 0)
2883 if (cfa->base_offset)
2886 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2888 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2890 else if (cfa->reg <= 31)
2891 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2893 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2894 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2895 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2896 add_loc_descr (&head, tmp);
2897 if (cfa->offset != 0)
2899 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2900 add_loc_descr (&head, tmp);
2905 /* This function fills in aa dw_cfa_location structure from a
2906 dwarf location descriptor sequence. */
2909 get_cfa_from_loc_descr (cfa, loc)
2910 dw_cfa_location *cfa;
2911 struct dw_loc_descr_struct *loc;
2913 struct dw_loc_descr_struct *ptr;
2915 cfa->base_offset = 0;
2919 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2921 enum dwarf_location_atom op = ptr->dw_loc_opc;
2956 cfa->reg = op - DW_OP_reg0;
2959 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2993 cfa->reg = op - DW_OP_breg0;
2994 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2997 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2998 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3003 case DW_OP_plus_uconst:
3004 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3007 internal_error ("DW_LOC_OP %s not implemented\n",
3008 dwarf_stack_op_name (ptr->dw_loc_opc));
3012 #endif /* .debug_frame support */
3014 /* And now, the support for symbolic debugging information. */
3015 #ifdef DWARF2_DEBUGGING_INFO
3017 static void dwarf2out_init PARAMS ((const char *));
3018 static void dwarf2out_finish PARAMS ((const char *));
3019 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3020 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3021 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3022 static void dwarf2out_end_source_file PARAMS ((unsigned));
3023 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3024 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3025 static bool dwarf2out_ignore_block PARAMS ((tree));
3026 static void dwarf2out_global_decl PARAMS ((tree));
3027 static void dwarf2out_abstract_function PARAMS ((tree));
3029 /* The debug hooks structure. */
3031 struct gcc_debug_hooks dwarf2_debug_hooks =
3037 dwarf2out_start_source_file,
3038 dwarf2out_end_source_file,
3039 dwarf2out_begin_block,
3040 dwarf2out_end_block,
3041 dwarf2out_ignore_block,
3042 dwarf2out_source_line,
3043 dwarf2out_begin_prologue,
3044 debug_nothing_int, /* end_prologue */
3045 dwarf2out_end_epilogue,
3046 debug_nothing_tree, /* begin_function */
3047 debug_nothing_int, /* end_function */
3048 dwarf2out_decl, /* function_decl */
3049 dwarf2out_global_decl,
3050 debug_nothing_tree, /* deferred_inline_function */
3051 /* The DWARF 2 backend tries to reduce debugging bloat by not
3052 emitting the abstract description of inline functions until
3053 something tries to reference them. */
3054 dwarf2out_abstract_function, /* outlining_inline_function */
3055 debug_nothing_rtx /* label */
3058 /* NOTE: In the comments in this file, many references are made to
3059 "Debugging Information Entries". This term is abbreviated as `DIE'
3060 throughout the remainder of this file. */
3062 /* An internal representation of the DWARF output is built, and then
3063 walked to generate the DWARF debugging info. The walk of the internal
3064 representation is done after the entire program has been compiled.
3065 The types below are used to describe the internal representation. */
3067 /* Various DIE's use offsets relative to the beginning of the
3068 .debug_info section to refer to each other. */
3070 typedef long int dw_offset;
3072 /* Define typedefs here to avoid circular dependencies. */
3074 typedef struct dw_attr_struct *dw_attr_ref;
3075 typedef struct dw_line_info_struct *dw_line_info_ref;
3076 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3077 typedef struct pubname_struct *pubname_ref;
3078 typedef struct dw_ranges_struct *dw_ranges_ref;
3080 /* Each entry in the line_info_table maintains the file and
3081 line number associated with the label generated for that
3082 entry. The label gives the PC value associated with
3083 the line number entry. */
3085 typedef struct dw_line_info_struct
3087 unsigned long dw_file_num;
3088 unsigned long dw_line_num;
3092 /* Line information for functions in separate sections; each one gets its
3094 typedef struct dw_separate_line_info_struct
3096 unsigned long dw_file_num;
3097 unsigned long dw_line_num;
3098 unsigned long function;
3100 dw_separate_line_info_entry;
3102 /* Each DIE attribute has a field specifying the attribute kind,
3103 a link to the next attribute in the chain, and an attribute value.
3104 Attributes are typically linked below the DIE they modify. */
3106 typedef struct dw_attr_struct
3108 enum dwarf_attribute dw_attr;
3109 dw_attr_ref dw_attr_next;
3110 dw_val_node dw_attr_val;
3114 /* The Debugging Information Entry (DIE) structure */
3116 typedef struct die_struct
3118 enum dwarf_tag die_tag;
3120 dw_attr_ref die_attr;
3121 dw_die_ref die_parent;
3122 dw_die_ref die_child;
3124 dw_offset die_offset;
3125 unsigned long die_abbrev;
3130 /* The pubname structure */
3132 typedef struct pubname_struct
3139 struct dw_ranges_struct
3144 /* The limbo die list structure. */
3145 typedef struct limbo_die_struct
3148 struct limbo_die_struct *next;
3152 /* How to start an assembler comment. */
3153 #ifndef ASM_COMMENT_START
3154 #define ASM_COMMENT_START ";#"
3157 /* Define a macro which returns non-zero for a TYPE_DECL which was
3158 implicitly generated for a tagged type.
3160 Note that unlike the gcc front end (which generates a NULL named
3161 TYPE_DECL node for each complete tagged type, each array type, and
3162 each function type node created) the g++ front end generates a
3163 _named_ TYPE_DECL node for each tagged type node created.
3164 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3165 generate a DW_TAG_typedef DIE for them. */
3167 #define TYPE_DECL_IS_STUB(decl) \
3168 (DECL_NAME (decl) == NULL_TREE \
3169 || (DECL_ARTIFICIAL (decl) \
3170 && is_tagged_type (TREE_TYPE (decl)) \
3171 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3172 /* This is necessary for stub decls that \
3173 appear in nested inline functions. */ \
3174 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3175 && (decl_ultimate_origin (decl) \
3176 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3178 /* Information concerning the compilation unit's programming
3179 language, and compiler version. */
3181 extern int flag_traditional;
3183 /* Fixed size portion of the DWARF compilation unit header. */
3184 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3186 /* Fixed size portion of debugging line information prolog. */
3187 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3189 /* Fixed size portion of public names info. */
3190 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3192 /* Fixed size portion of the address range info. */
3193 #define DWARF_ARANGES_HEADER_SIZE \
3194 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3195 - DWARF_OFFSET_SIZE)
3197 /* Size of padding portion in the address range info. It must be
3198 aligned to twice the pointer size. */
3199 #define DWARF_ARANGES_PAD_SIZE \
3200 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3201 - (2 * DWARF_OFFSET_SIZE + 4))
3203 /* Use assembler line directives if available. */
3204 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3205 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3206 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3208 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3212 /* Define the architecture-dependent minimum instruction length (in bytes).
3213 In this implementation of DWARF, this field is used for information
3214 purposes only. Since GCC generates assembly language, we have
3215 no a priori knowledge of how many instruction bytes are generated
3216 for each source line, and therefore can use only the DW_LNE_set_address
3217 and DW_LNS_fixed_advance_pc line information commands. */
3219 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3220 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3223 /* Minimum line offset in a special line info. opcode.
3224 This value was chosen to give a reasonable range of values. */
3225 #define DWARF_LINE_BASE -10
3227 /* First special line opcode - leave room for the standard opcodes. */
3228 #define DWARF_LINE_OPCODE_BASE 10
3230 /* Range of line offsets in a special line info. opcode. */
3231 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3233 /* Flag that indicates the initial value of the is_stmt_start flag.
3234 In the present implementation, we do not mark any lines as
3235 the beginning of a source statement, because that information
3236 is not made available by the GCC front-end. */
3237 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3239 /* This location is used by calc_die_sizes() to keep track
3240 the offset of each DIE within the .debug_info section. */
3241 static unsigned long next_die_offset;
3243 /* Record the root of the DIE's built for the current compilation unit. */
3244 static dw_die_ref comp_unit_die;
3246 /* A list of DIEs with a NULL parent waiting to be relocated. */
3247 static limbo_die_node *limbo_die_list = 0;
3249 /* Structure used by lookup_filename to manage sets of filenames. */
3255 unsigned last_lookup_index;
3258 /* Size (in elements) of increments by which we may expand the filename
3260 #define FILE_TABLE_INCREMENT 64
3262 /* Filenames referenced by this compilation unit. */
3263 static struct file_table file_table;
3265 /* Local pointer to the name of the main input file. Initialized in
3267 static const char *primary_filename;
3269 /* A pointer to the base of a table of references to DIE's that describe
3270 declarations. The table is indexed by DECL_UID() which is a unique
3271 number identifying each decl. */
3272 static dw_die_ref *decl_die_table;
3274 /* Number of elements currently allocated for the decl_die_table. */
3275 static unsigned decl_die_table_allocated;
3277 /* Number of elements in decl_die_table currently in use. */
3278 static unsigned decl_die_table_in_use;
3280 /* Size (in elements) of increments by which we may expand the
3282 #define DECL_DIE_TABLE_INCREMENT 256
3284 /* A pointer to the base of a table of references to declaration
3285 scopes. This table is a display which tracks the nesting
3286 of declaration scopes at the current scope and containing
3287 scopes. This table is used to find the proper place to
3288 define type declaration DIE's. */
3289 varray_type decl_scope_table;
3291 /* A pointer to the base of a list of references to DIE's that
3292 are uniquely identified by their tag, presence/absence of
3293 children DIE's, and list of attribute/value pairs. */
3294 static dw_die_ref *abbrev_die_table;
3296 /* Number of elements currently allocated for abbrev_die_table. */
3297 static unsigned abbrev_die_table_allocated;
3299 /* Number of elements in type_die_table currently in use. */
3300 static unsigned abbrev_die_table_in_use;
3302 /* Size (in elements) of increments by which we may expand the
3303 abbrev_die_table. */
3304 #define ABBREV_DIE_TABLE_INCREMENT 256
3306 /* A pointer to the base of a table that contains line information
3307 for each source code line in .text in the compilation unit. */
3308 static dw_line_info_ref line_info_table;
3310 /* Number of elements currently allocated for line_info_table. */
3311 static unsigned line_info_table_allocated;
3313 /* Number of elements in separate_line_info_table currently in use. */
3314 static unsigned separate_line_info_table_in_use;
3316 /* A pointer to the base of a table that contains line information
3317 for each source code line outside of .text in the compilation unit. */
3318 static dw_separate_line_info_ref separate_line_info_table;
3320 /* Number of elements currently allocated for separate_line_info_table. */
3321 static unsigned separate_line_info_table_allocated;
3323 /* Number of elements in line_info_table currently in use. */
3324 static unsigned line_info_table_in_use;
3326 /* Size (in elements) of increments by which we may expand the
3328 #define LINE_INFO_TABLE_INCREMENT 1024
3330 /* A pointer to the base of a table that contains a list of publicly
3331 accessible names. */
3332 static pubname_ref pubname_table;
3334 /* Number of elements currently allocated for pubname_table. */
3335 static unsigned pubname_table_allocated;
3337 /* Number of elements in pubname_table currently in use. */
3338 static unsigned pubname_table_in_use;
3340 /* Size (in elements) of increments by which we may expand the
3342 #define PUBNAME_TABLE_INCREMENT 64
3344 /* Array of dies for which we should generate .debug_arange info. */
3345 static dw_die_ref *arange_table;
3347 /* Number of elements currently allocated for arange_table. */
3348 static unsigned arange_table_allocated;
3350 /* Number of elements in arange_table currently in use. */
3351 static unsigned arange_table_in_use;
3353 /* Size (in elements) of increments by which we may expand the
3355 #define ARANGE_TABLE_INCREMENT 64
3357 /* Array of dies for which we should generate .debug_ranges info. */
3358 static dw_ranges_ref ranges_table;
3360 /* Number of elements currently allocated for ranges_table. */
3361 static unsigned ranges_table_allocated;
3363 /* Number of elements in ranges_table currently in use. */
3364 static unsigned ranges_table_in_use;
3366 /* Size (in elements) of increments by which we may expand the
3368 #define RANGES_TABLE_INCREMENT 64
3370 /* Whether we have location lists that need outputting */
3371 static unsigned have_location_lists;
3373 /* A pointer to the base of a list of incomplete types which might be
3374 completed at some later time. incomplete_types_list needs to be a VARRAY
3375 because we want to tell the garbage collector about it. If we don't tell
3376 the garbage collector about it, we can garbage collect live data.
3378 varray_type incomplete_types;
3380 /* Record whether the function being analyzed contains inlined functions. */
3381 static int current_function_has_inlines;
3382 #if 0 && defined (MIPS_DEBUGGING_INFO)
3383 static int comp_unit_has_inlines;
3386 /* Array of RTXes referenced by the debugging information, which therefore
3387 must be kept around forever. We do this rather than perform GC on
3388 the dwarf info because almost all of the dwarf info lives forever, and
3389 it's easier to support non-GC frontends this way. */
3390 static varray_type used_rtx_varray;
3392 /* Forward declarations for functions defined in this file. */
3394 static int is_pseudo_reg PARAMS ((rtx));
3395 static tree type_main_variant PARAMS ((tree));
3396 static int is_tagged_type PARAMS ((tree));
3397 static const char *dwarf_tag_name PARAMS ((unsigned));
3398 static const char *dwarf_attr_name PARAMS ((unsigned));
3399 static const char *dwarf_form_name PARAMS ((unsigned));
3401 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3403 static tree decl_ultimate_origin PARAMS ((tree));
3404 static tree block_ultimate_origin PARAMS ((tree));
3405 static tree decl_class_context PARAMS ((tree));
3406 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3407 static void add_AT_flag PARAMS ((dw_die_ref,
3408 enum dwarf_attribute,
3410 static void add_AT_int PARAMS ((dw_die_ref,
3411 enum dwarf_attribute, long));
3412 static void add_AT_unsigned PARAMS ((dw_die_ref,
3413 enum dwarf_attribute,
3415 static void add_AT_long_long PARAMS ((dw_die_ref,
3416 enum dwarf_attribute,
3419 static void add_AT_float PARAMS ((dw_die_ref,
3420 enum dwarf_attribute,
3422 static void add_AT_string PARAMS ((dw_die_ref,
3423 enum dwarf_attribute,
3425 static void add_AT_die_ref PARAMS ((dw_die_ref,
3426 enum dwarf_attribute,
3428 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3429 enum dwarf_attribute,
3431 static void add_AT_loc PARAMS ((dw_die_ref,
3432 enum dwarf_attribute,
3434 static void add_AT_loc_list PARAMS ((dw_die_ref,
3435 enum dwarf_attribute,
3437 static void add_AT_addr PARAMS ((dw_die_ref,
3438 enum dwarf_attribute,
3440 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3441 enum dwarf_attribute,
3443 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3444 enum dwarf_attribute,
3446 static void add_AT_offset PARAMS ((dw_die_ref,
3447 enum dwarf_attribute,
3449 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3450 enum dwarf_attribute));
3451 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3452 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3453 static const char *get_AT_string PARAMS ((dw_die_ref,
3454 enum dwarf_attribute));
3455 static int get_AT_flag PARAMS ((dw_die_ref,
3456 enum dwarf_attribute));
3457 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3458 enum dwarf_attribute));
3459 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3460 enum dwarf_attribute));
3461 static int is_c_family PARAMS ((void));
3462 static int is_java PARAMS ((void));
3463 static int is_fortran PARAMS ((void));
3464 static void remove_AT PARAMS ((dw_die_ref,
3465 enum dwarf_attribute));
3466 static void remove_children PARAMS ((dw_die_ref));
3467 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3468 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3469 static dw_die_ref lookup_type_die PARAMS ((tree));
3470 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3471 static dw_die_ref lookup_decl_die PARAMS ((tree));
3472 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3473 static void print_spaces PARAMS ((FILE *));
3474 static void print_die PARAMS ((dw_die_ref, FILE *));
3475 static void print_dwarf_line_table PARAMS ((FILE *));
3476 static void reverse_die_lists PARAMS ((dw_die_ref));
3477 static void reverse_all_dies PARAMS ((dw_die_ref));
3478 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3479 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3480 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3481 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3482 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3483 static void compute_section_prefix PARAMS ((dw_die_ref));
3484 static int is_type_die PARAMS ((dw_die_ref));
3485 static int is_comdat_die PARAMS ((dw_die_ref));
3486 static int is_symbol_die PARAMS ((dw_die_ref));
3487 static void assign_symbol_names PARAMS ((dw_die_ref));
3488 static void break_out_includes PARAMS ((dw_die_ref));
3489 static void add_sibling_attributes PARAMS ((dw_die_ref));
3490 static void build_abbrev_table PARAMS ((dw_die_ref));
3491 static void output_location_lists PARAMS ((dw_die_ref));
3492 static int constant_size PARAMS ((long unsigned));
3493 static unsigned long size_of_die PARAMS ((dw_die_ref));
3494 static void calc_die_sizes PARAMS ((dw_die_ref));
3495 static void mark_dies PARAMS ((dw_die_ref));
3496 static void unmark_dies PARAMS ((dw_die_ref));
3497 static unsigned long size_of_pubnames PARAMS ((void));
3498 static unsigned long size_of_aranges PARAMS ((void));
3499 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3500 static void output_value_format PARAMS ((dw_attr_ref));
3501 static void output_abbrev_section PARAMS ((void));
3502 static void output_die_symbol PARAMS ((dw_die_ref));
3503 static void output_die PARAMS ((dw_die_ref));
3504 static void output_compilation_unit_header PARAMS ((void));
3505 static void output_comp_unit PARAMS ((dw_die_ref));
3506 static const char *dwarf2_name PARAMS ((tree, int));
3507 static void add_pubname PARAMS ((tree, dw_die_ref));
3508 static void output_pubnames PARAMS ((void));
3509 static void add_arange PARAMS ((tree, dw_die_ref));
3510 static void output_aranges PARAMS ((void));
3511 static unsigned int add_ranges PARAMS ((tree));
3512 static void output_ranges PARAMS ((void));
3513 static void output_line_info PARAMS ((void));
3514 static void output_file_names PARAMS ((void));
3515 static dw_die_ref base_type_die PARAMS ((tree));
3516 static tree root_type PARAMS ((tree));
3517 static int is_base_type PARAMS ((tree));
3518 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3519 static int type_is_enum PARAMS ((tree));
3520 static unsigned int reg_number PARAMS ((rtx));
3521 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3522 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3523 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3524 static int is_based_loc PARAMS ((rtx));
3525 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3526 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3527 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3528 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3529 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3530 static tree field_type PARAMS ((tree));
3531 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3532 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3533 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3534 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3535 static void add_AT_location_description PARAMS ((dw_die_ref,
3536 enum dwarf_attribute, rtx));
3537 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3538 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3539 static rtx rtl_for_decl_location PARAMS ((tree));
3540 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3541 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3542 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3543 static void add_bound_info PARAMS ((dw_die_ref,
3544 enum dwarf_attribute, tree));
3545 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3546 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3547 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3548 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3549 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3550 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3551 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3552 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3553 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3554 static void push_decl_scope PARAMS ((tree));
3555 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3556 static void pop_decl_scope PARAMS ((void));
3557 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3559 static const char *type_tag PARAMS ((tree));
3560 static tree member_declared_type PARAMS ((tree));
3562 static const char *decl_start_label PARAMS ((tree));
3564 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3565 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3567 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3569 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3570 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3571 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3572 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3573 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3574 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3575 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3576 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3577 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3578 static void gen_label_die PARAMS ((tree, dw_die_ref));
3579 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3580 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3581 static void gen_field_die PARAMS ((tree, dw_die_ref));
3582 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3583 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3584 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3585 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3586 static void gen_member_die PARAMS ((tree, dw_die_ref));
3587 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3588 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3589 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3590 static void gen_type_die PARAMS ((tree, dw_die_ref));
3591 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3592 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3593 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3594 static int is_redundant_typedef PARAMS ((tree));
3595 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3596 static unsigned lookup_filename PARAMS ((const char *));
3597 static void init_file_table PARAMS ((void));
3598 static void add_incomplete_type PARAMS ((tree));
3599 static void retry_incomplete_types PARAMS ((void));
3600 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3601 static rtx save_rtx PARAMS ((rtx));
3602 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3603 static int file_info_cmp PARAMS ((const void *, const void *));
3604 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3605 const char *, const char *,
3606 const char *, unsigned));
3607 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3609 const char *, const char *, const char *));
3610 static void output_loc_list PARAMS ((dw_loc_list_ref));
3611 static char *gen_internal_sym PARAMS ((const char *));
3613 /* Section names used to hold DWARF debugging information. */
3614 #ifndef DEBUG_INFO_SECTION
3615 #define DEBUG_INFO_SECTION ".debug_info"
3617 #ifndef DEBUG_ABBREV_SECTION
3618 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3620 #ifndef DEBUG_ARANGES_SECTION
3621 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3623 #ifndef DEBUG_MACINFO_SECTION
3624 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3626 #ifndef DEBUG_LINE_SECTION
3627 #define DEBUG_LINE_SECTION ".debug_line"
3629 #ifndef DEBUG_LOC_SECTION
3630 #define DEBUG_LOC_SECTION ".debug_loc"
3632 #ifndef DEBUG_PUBNAMES_SECTION
3633 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3635 #ifndef DEBUG_STR_SECTION
3636 #define DEBUG_STR_SECTION ".debug_str"
3638 #ifndef DEBUG_RANGES_SECTION
3639 #define DEBUG_RANGES_SECTION ".debug_ranges"
3642 /* Standard ELF section names for compiled code and data. */
3643 #ifndef TEXT_SECTION_NAME
3644 #define TEXT_SECTION_NAME ".text"
3647 /* Section flags for .debug_str section. */
3648 #ifdef HAVE_GAS_SHF_MERGE
3649 #define DEBUG_STR_SECTION_FLAGS \
3650 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3652 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3655 /* Labels we insert at beginning sections we can reference instead of
3656 the section names themselves. */
3658 #ifndef TEXT_SECTION_LABEL
3659 #define TEXT_SECTION_LABEL "Ltext"
3661 #ifndef DEBUG_LINE_SECTION_LABEL
3662 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3664 #ifndef DEBUG_INFO_SECTION_LABEL
3665 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3667 #ifndef DEBUG_ABBREV_SECTION_LABEL
3668 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3670 #ifndef DEBUG_LOC_SECTION_LABEL
3671 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3673 #ifndef DEBUG_MACINFO_SECTION_LABEL
3674 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3677 /* Definitions of defaults for formats and names of various special
3678 (artificial) labels which may be generated within this file (when the -g
3679 options is used and DWARF_DEBUGGING_INFO is in effect.
3680 If necessary, these may be overridden from within the tm.h file, but
3681 typically, overriding these defaults is unnecessary. */
3683 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3684 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3685 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3686 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3687 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3688 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3689 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3690 #ifndef TEXT_END_LABEL
3691 #define TEXT_END_LABEL "Letext"
3693 #ifndef DATA_END_LABEL
3694 #define DATA_END_LABEL "Ledata"
3696 #ifndef BSS_END_LABEL
3697 #define BSS_END_LABEL "Lebss"
3699 #ifndef BLOCK_BEGIN_LABEL
3700 #define BLOCK_BEGIN_LABEL "LBB"
3702 #ifndef BLOCK_END_LABEL
3703 #define BLOCK_END_LABEL "LBE"
3705 #ifndef BODY_BEGIN_LABEL
3706 #define BODY_BEGIN_LABEL "Lbb"
3708 #ifndef BODY_END_LABEL
3709 #define BODY_END_LABEL "Lbe"
3711 #ifndef LINE_CODE_LABEL
3712 #define LINE_CODE_LABEL "LM"
3714 #ifndef SEPARATE_LINE_CODE_LABEL
3715 #define SEPARATE_LINE_CODE_LABEL "LSM"
3718 /* We allow a language front-end to designate a function that is to be
3719 called to "demangle" any name before it it put into a DIE. */
3721 static const char *(*demangle_name_func) PARAMS ((const char *));
3724 dwarf2out_set_demangle_name_func (func)
3725 const char *(*func) PARAMS ((const char *));
3727 demangle_name_func = func;
3730 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3731 that means adding it to used_rtx_varray. If not, that means making
3732 a copy on the permanent_obstack. */
3738 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3743 /* Test if rtl node points to a pseudo register. */
3749 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3750 || (GET_CODE (rtl) == SUBREG
3751 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3754 /* Return a reference to a type, with its const and volatile qualifiers
3758 type_main_variant (type)
3761 type = TYPE_MAIN_VARIANT (type);
3763 /* There really should be only one main variant among any group of variants
3764 of a given type (and all of the MAIN_VARIANT values for all members of
3765 the group should point to that one type) but sometimes the C front-end
3766 messes this up for array types, so we work around that bug here. */
3768 if (TREE_CODE (type) == ARRAY_TYPE)
3769 while (type != TYPE_MAIN_VARIANT (type))
3770 type = TYPE_MAIN_VARIANT (type);
3775 /* Return non-zero if the given type node represents a tagged type. */
3778 is_tagged_type (type)
3781 enum tree_code code = TREE_CODE (type);
3783 return (code == RECORD_TYPE || code == UNION_TYPE
3784 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3787 /* Convert a DIE tag into its string name. */
3790 dwarf_tag_name (tag)
3795 case DW_TAG_padding:
3796 return "DW_TAG_padding";
3797 case DW_TAG_array_type:
3798 return "DW_TAG_array_type";
3799 case DW_TAG_class_type:
3800 return "DW_TAG_class_type";
3801 case DW_TAG_entry_point:
3802 return "DW_TAG_entry_point";
3803 case DW_TAG_enumeration_type:
3804 return "DW_TAG_enumeration_type";
3805 case DW_TAG_formal_parameter:
3806 return "DW_TAG_formal_parameter";
3807 case DW_TAG_imported_declaration:
3808 return "DW_TAG_imported_declaration";
3810 return "DW_TAG_label";
3811 case DW_TAG_lexical_block:
3812 return "DW_TAG_lexical_block";
3814 return "DW_TAG_member";
3815 case DW_TAG_pointer_type:
3816 return "DW_TAG_pointer_type";
3817 case DW_TAG_reference_type:
3818 return "DW_TAG_reference_type";
3819 case DW_TAG_compile_unit:
3820 return "DW_TAG_compile_unit";
3821 case DW_TAG_string_type:
3822 return "DW_TAG_string_type";
3823 case DW_TAG_structure_type:
3824 return "DW_TAG_structure_type";
3825 case DW_TAG_subroutine_type:
3826 return "DW_TAG_subroutine_type";
3827 case DW_TAG_typedef:
3828 return "DW_TAG_typedef";
3829 case DW_TAG_union_type:
3830 return "DW_TAG_union_type";
3831 case DW_TAG_unspecified_parameters:
3832 return "DW_TAG_unspecified_parameters";
3833 case DW_TAG_variant:
3834 return "DW_TAG_variant";
3835 case DW_TAG_common_block:
3836 return "DW_TAG_common_block";
3837 case DW_TAG_common_inclusion:
3838 return "DW_TAG_common_inclusion";
3839 case DW_TAG_inheritance:
3840 return "DW_TAG_inheritance";
3841 case DW_TAG_inlined_subroutine:
3842 return "DW_TAG_inlined_subroutine";
3844 return "DW_TAG_module";
3845 case DW_TAG_ptr_to_member_type:
3846 return "DW_TAG_ptr_to_member_type";
3847 case DW_TAG_set_type:
3848 return "DW_TAG_set_type";
3849 case DW_TAG_subrange_type:
3850 return "DW_TAG_subrange_type";
3851 case DW_TAG_with_stmt:
3852 return "DW_TAG_with_stmt";
3853 case DW_TAG_access_declaration:
3854 return "DW_TAG_access_declaration";
3855 case DW_TAG_base_type:
3856 return "DW_TAG_base_type";
3857 case DW_TAG_catch_block:
3858 return "DW_TAG_catch_block";
3859 case DW_TAG_const_type:
3860 return "DW_TAG_const_type";
3861 case DW_TAG_constant:
3862 return "DW_TAG_constant";
3863 case DW_TAG_enumerator:
3864 return "DW_TAG_enumerator";
3865 case DW_TAG_file_type:
3866 return "DW_TAG_file_type";
3868 return "DW_TAG_friend";
3869 case DW_TAG_namelist:
3870 return "DW_TAG_namelist";
3871 case DW_TAG_namelist_item:
3872 return "DW_TAG_namelist_item";
3873 case DW_TAG_packed_type:
3874 return "DW_TAG_packed_type";
3875 case DW_TAG_subprogram:
3876 return "DW_TAG_subprogram";
3877 case DW_TAG_template_type_param:
3878 return "DW_TAG_template_type_param";
3879 case DW_TAG_template_value_param:
3880 return "DW_TAG_template_value_param";
3881 case DW_TAG_thrown_type:
3882 return "DW_TAG_thrown_type";
3883 case DW_TAG_try_block:
3884 return "DW_TAG_try_block";
3885 case DW_TAG_variant_part:
3886 return "DW_TAG_variant_part";
3887 case DW_TAG_variable:
3888 return "DW_TAG_variable";
3889 case DW_TAG_volatile_type:
3890 return "DW_TAG_volatile_type";
3891 case DW_TAG_MIPS_loop:
3892 return "DW_TAG_MIPS_loop";
3893 case DW_TAG_format_label:
3894 return "DW_TAG_format_label";
3895 case DW_TAG_function_template:
3896 return "DW_TAG_function_template";
3897 case DW_TAG_class_template:
3898 return "DW_TAG_class_template";
3899 case DW_TAG_GNU_BINCL:
3900 return "DW_TAG_GNU_BINCL";
3901 case DW_TAG_GNU_EINCL:
3902 return "DW_TAG_GNU_EINCL";
3904 return "DW_TAG_<unknown>";
3908 /* Convert a DWARF attribute code into its string name. */
3911 dwarf_attr_name (attr)
3917 return "DW_AT_sibling";
3918 case DW_AT_location:
3919 return "DW_AT_location";
3921 return "DW_AT_name";
3922 case DW_AT_ordering:
3923 return "DW_AT_ordering";
3924 case DW_AT_subscr_data:
3925 return "DW_AT_subscr_data";
3926 case DW_AT_byte_size:
3927 return "DW_AT_byte_size";
3928 case DW_AT_bit_offset:
3929 return "DW_AT_bit_offset";
3930 case DW_AT_bit_size:
3931 return "DW_AT_bit_size";
3932 case DW_AT_element_list:
3933 return "DW_AT_element_list";
3934 case DW_AT_stmt_list:
3935 return "DW_AT_stmt_list";
3937 return "DW_AT_low_pc";
3939 return "DW_AT_high_pc";
3940 case DW_AT_language:
3941 return "DW_AT_language";
3943 return "DW_AT_member";
3945 return "DW_AT_discr";
3946 case DW_AT_discr_value:
3947 return "DW_AT_discr_value";
3948 case DW_AT_visibility:
3949 return "DW_AT_visibility";
3951 return "DW_AT_import";
3952 case DW_AT_string_length:
3953 return "DW_AT_string_length";
3954 case DW_AT_common_reference:
3955 return "DW_AT_common_reference";
3956 case DW_AT_comp_dir:
3957 return "DW_AT_comp_dir";
3958 case DW_AT_const_value:
3959 return "DW_AT_const_value";
3960 case DW_AT_containing_type:
3961 return "DW_AT_containing_type";
3962 case DW_AT_default_value:
3963 return "DW_AT_default_value";
3965 return "DW_AT_inline";
3966 case DW_AT_is_optional:
3967 return "DW_AT_is_optional";
3968 case DW_AT_lower_bound:
3969 return "DW_AT_lower_bound";
3970 case DW_AT_producer:
3971 return "DW_AT_producer";
3972 case DW_AT_prototyped:
3973 return "DW_AT_prototyped";
3974 case DW_AT_return_addr:
3975 return "DW_AT_return_addr";
3976 case DW_AT_start_scope:
3977 return "DW_AT_start_scope";
3978 case DW_AT_stride_size:
3979 return "DW_AT_stride_size";
3980 case DW_AT_upper_bound:
3981 return "DW_AT_upper_bound";
3982 case DW_AT_abstract_origin:
3983 return "DW_AT_abstract_origin";
3984 case DW_AT_accessibility:
3985 return "DW_AT_accessibility";
3986 case DW_AT_address_class:
3987 return "DW_AT_address_class";
3988 case DW_AT_artificial:
3989 return "DW_AT_artificial";
3990 case DW_AT_base_types:
3991 return "DW_AT_base_types";
3992 case DW_AT_calling_convention:
3993 return "DW_AT_calling_convention";
3995 return "DW_AT_count";
3996 case DW_AT_data_member_location:
3997 return "DW_AT_data_member_location";
3998 case DW_AT_decl_column:
3999 return "DW_AT_decl_column";
4000 case DW_AT_decl_file:
4001 return "DW_AT_decl_file";
4002 case DW_AT_decl_line:
4003 return "DW_AT_decl_line";
4004 case DW_AT_declaration:
4005 return "DW_AT_declaration";
4006 case DW_AT_discr_list:
4007 return "DW_AT_discr_list";
4008 case DW_AT_encoding:
4009 return "DW_AT_encoding";
4010 case DW_AT_external:
4011 return "DW_AT_external";
4012 case DW_AT_frame_base:
4013 return "DW_AT_frame_base";
4015 return "DW_AT_friend";
4016 case DW_AT_identifier_case:
4017 return "DW_AT_identifier_case";
4018 case DW_AT_macro_info:
4019 return "DW_AT_macro_info";
4020 case DW_AT_namelist_items:
4021 return "DW_AT_namelist_items";
4022 case DW_AT_priority:
4023 return "DW_AT_priority";
4025 return "DW_AT_segment";
4026 case DW_AT_specification:
4027 return "DW_AT_specification";
4028 case DW_AT_static_link:
4029 return "DW_AT_static_link";
4031 return "DW_AT_type";
4032 case DW_AT_use_location:
4033 return "DW_AT_use_location";
4034 case DW_AT_variable_parameter:
4035 return "DW_AT_variable_parameter";
4036 case DW_AT_virtuality:
4037 return "DW_AT_virtuality";
4038 case DW_AT_vtable_elem_location:
4039 return "DW_AT_vtable_elem_location";
4041 case DW_AT_allocated:
4042 return "DW_AT_allocated";
4043 case DW_AT_associated:
4044 return "DW_AT_associated";
4045 case DW_AT_data_location:
4046 return "DW_AT_data_location";
4048 return "DW_AT_stride";
4049 case DW_AT_entry_pc:
4050 return "DW_AT_entry_pc";
4051 case DW_AT_use_UTF8:
4052 return "DW_AT_use_UTF8";
4053 case DW_AT_extension:
4054 return "DW_AT_extension";
4056 return "DW_AT_ranges";
4057 case DW_AT_trampoline:
4058 return "DW_AT_trampoline";
4059 case DW_AT_call_column:
4060 return "DW_AT_call_column";
4061 case DW_AT_call_file:
4062 return "DW_AT_call_file";
4063 case DW_AT_call_line:
4064 return "DW_AT_call_line";
4066 case DW_AT_MIPS_fde:
4067 return "DW_AT_MIPS_fde";
4068 case DW_AT_MIPS_loop_begin:
4069 return "DW_AT_MIPS_loop_begin";
4070 case DW_AT_MIPS_tail_loop_begin:
4071 return "DW_AT_MIPS_tail_loop_begin";
4072 case DW_AT_MIPS_epilog_begin:
4073 return "DW_AT_MIPS_epilog_begin";
4074 case DW_AT_MIPS_loop_unroll_factor:
4075 return "DW_AT_MIPS_loop_unroll_factor";
4076 case DW_AT_MIPS_software_pipeline_depth:
4077 return "DW_AT_MIPS_software_pipeline_depth";
4078 case DW_AT_MIPS_linkage_name:
4079 return "DW_AT_MIPS_linkage_name";
4080 case DW_AT_MIPS_stride:
4081 return "DW_AT_MIPS_stride";
4082 case DW_AT_MIPS_abstract_name:
4083 return "DW_AT_MIPS_abstract_name";
4084 case DW_AT_MIPS_clone_origin:
4085 return "DW_AT_MIPS_clone_origin";
4086 case DW_AT_MIPS_has_inlines:
4087 return "DW_AT_MIPS_has_inlines";
4089 case DW_AT_sf_names:
4090 return "DW_AT_sf_names";
4091 case DW_AT_src_info:
4092 return "DW_AT_src_info";
4093 case DW_AT_mac_info:
4094 return "DW_AT_mac_info";
4095 case DW_AT_src_coords:
4096 return "DW_AT_src_coords";
4097 case DW_AT_body_begin:
4098 return "DW_AT_body_begin";
4099 case DW_AT_body_end:
4100 return "DW_AT_body_end";
4102 return "DW_AT_<unknown>";
4106 /* Convert a DWARF value form code into its string name. */
4109 dwarf_form_name (form)
4115 return "DW_FORM_addr";
4116 case DW_FORM_block2:
4117 return "DW_FORM_block2";
4118 case DW_FORM_block4:
4119 return "DW_FORM_block4";
4121 return "DW_FORM_data2";
4123 return "DW_FORM_data4";
4125 return "DW_FORM_data8";
4126 case DW_FORM_string:
4127 return "DW_FORM_string";
4129 return "DW_FORM_block";
4130 case DW_FORM_block1:
4131 return "DW_FORM_block1";
4133 return "DW_FORM_data1";
4135 return "DW_FORM_flag";
4137 return "DW_FORM_sdata";
4139 return "DW_FORM_strp";
4141 return "DW_FORM_udata";
4142 case DW_FORM_ref_addr:
4143 return "DW_FORM_ref_addr";
4145 return "DW_FORM_ref1";
4147 return "DW_FORM_ref2";
4149 return "DW_FORM_ref4";
4151 return "DW_FORM_ref8";
4152 case DW_FORM_ref_udata:
4153 return "DW_FORM_ref_udata";
4154 case DW_FORM_indirect:
4155 return "DW_FORM_indirect";
4157 return "DW_FORM_<unknown>";
4161 /* Convert a DWARF type code into its string name. */
4165 dwarf_type_encoding_name (enc)
4170 case DW_ATE_address:
4171 return "DW_ATE_address";
4172 case DW_ATE_boolean:
4173 return "DW_ATE_boolean";
4174 case DW_ATE_complex_float:
4175 return "DW_ATE_complex_float";
4177 return "DW_ATE_float";
4179 return "DW_ATE_signed";
4180 case DW_ATE_signed_char:
4181 return "DW_ATE_signed_char";
4182 case DW_ATE_unsigned:
4183 return "DW_ATE_unsigned";
4184 case DW_ATE_unsigned_char:
4185 return "DW_ATE_unsigned_char";
4187 return "DW_ATE_<unknown>";
4192 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4193 instance of an inlined instance of a decl which is local to an inline
4194 function, so we have to trace all of the way back through the origin chain
4195 to find out what sort of node actually served as the original seed for the
4199 decl_ultimate_origin (decl)
4202 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4203 nodes in the function to point to themselves; ignore that if
4204 we're trying to output the abstract instance of this function. */
4205 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4208 #ifdef ENABLE_CHECKING
4209 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4210 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4211 most distant ancestor, this should never happen. */
4215 return DECL_ABSTRACT_ORIGIN (decl);
4218 /* Determine the "ultimate origin" of a block. The block may be an inlined
4219 instance of an inlined instance of a block which is local to an inline
4220 function, so we have to trace all of the way back through the origin chain
4221 to find out what sort of node actually served as the original seed for the
4225 block_ultimate_origin (block)
4228 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4230 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4231 nodes in the function to point to themselves; ignore that if
4232 we're trying to output the abstract instance of this function. */
4233 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4236 if (immediate_origin == NULL_TREE)
4241 tree lookahead = immediate_origin;
4245 ret_val = lookahead;
4246 lookahead = (TREE_CODE (ret_val) == BLOCK)
4247 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4250 while (lookahead != NULL && lookahead != ret_val);
4256 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4257 of a virtual function may refer to a base class, so we check the 'this'
4261 decl_class_context (decl)
4264 tree context = NULL_TREE;
4266 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4267 context = DECL_CONTEXT (decl);
4269 context = TYPE_MAIN_VARIANT
4270 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4272 if (context && !TYPE_P (context))
4273 context = NULL_TREE;
4278 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4279 addition order, and correct that in reverse_all_dies. */
4282 add_dwarf_attr (die, attr)
4286 if (die != NULL && attr != NULL)
4288 attr->dw_attr_next = die->die_attr;
4289 die->die_attr = attr;
4293 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4294 static inline dw_val_class
4298 return a->dw_attr_val.val_class;
4301 /* Add a flag value attribute to a DIE. */
4304 add_AT_flag (die, attr_kind, flag)
4306 enum dwarf_attribute attr_kind;
4309 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4311 attr->dw_attr_next = NULL;
4312 attr->dw_attr = attr_kind;
4313 attr->dw_attr_val.val_class = dw_val_class_flag;
4314 attr->dw_attr_val.v.val_flag = flag;
4315 add_dwarf_attr (die, attr);
4318 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4319 static inline unsigned
4323 if (a && AT_class (a) == dw_val_class_flag)
4324 return a->dw_attr_val.v.val_flag;
4329 /* Add a signed integer attribute value to a DIE. */
4332 add_AT_int (die, attr_kind, int_val)
4334 enum dwarf_attribute attr_kind;
4337 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4339 attr->dw_attr_next = NULL;
4340 attr->dw_attr = attr_kind;
4341 attr->dw_attr_val.val_class = dw_val_class_const;
4342 attr->dw_attr_val.v.val_int = int_val;
4343 add_dwarf_attr (die, attr);
4346 static inline long int AT_int PARAMS ((dw_attr_ref));
4347 static inline long int
4351 if (a && AT_class (a) == dw_val_class_const)
4352 return a->dw_attr_val.v.val_int;
4357 /* Add an unsigned integer attribute value to a DIE. */
4360 add_AT_unsigned (die, attr_kind, unsigned_val)
4362 enum dwarf_attribute attr_kind;
4363 unsigned long unsigned_val;
4365 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4367 attr->dw_attr_next = NULL;
4368 attr->dw_attr = attr_kind;
4369 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4370 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4371 add_dwarf_attr (die, attr);
4374 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4375 static inline unsigned long
4379 if (a && AT_class (a) == dw_val_class_unsigned_const)
4380 return a->dw_attr_val.v.val_unsigned;
4385 /* Add an unsigned double integer attribute value to a DIE. */
4388 add_AT_long_long (die, attr_kind, val_hi, val_low)
4390 enum dwarf_attribute attr_kind;
4391 unsigned long val_hi;
4392 unsigned long val_low;
4394 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4396 attr->dw_attr_next = NULL;
4397 attr->dw_attr = attr_kind;
4398 attr->dw_attr_val.val_class = dw_val_class_long_long;
4399 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4400 attr->dw_attr_val.v.val_long_long.low = val_low;
4401 add_dwarf_attr (die, attr);
4404 /* Add a floating point attribute value to a DIE and return it. */
4407 add_AT_float (die, attr_kind, length, array)
4409 enum dwarf_attribute attr_kind;
4413 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4415 attr->dw_attr_next = NULL;
4416 attr->dw_attr = attr_kind;
4417 attr->dw_attr_val.val_class = dw_val_class_float;
4418 attr->dw_attr_val.v.val_float.length = length;
4419 attr->dw_attr_val.v.val_float.array = array;
4420 add_dwarf_attr (die, attr);
4423 /* Add a string attribute value to a DIE. */
4426 add_AT_string (die, attr_kind, str)
4428 enum dwarf_attribute attr_kind;
4431 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4432 struct indirect_string_node *node;
4434 if (! debug_str_hash)
4436 debug_str_hash = ht_create (10);
4437 debug_str_hash->alloc_node = indirect_string_alloc;
4440 node = (struct indirect_string_node *)
4441 ht_lookup (debug_str_hash, (const unsigned char *) str,
4442 strlen (str), HT_ALLOC);
4445 attr->dw_attr_next = NULL;
4446 attr->dw_attr = attr_kind;
4447 attr->dw_attr_val.val_class = dw_val_class_str;
4448 attr->dw_attr_val.v.val_str = node;
4449 add_dwarf_attr (die, attr);
4452 static inline const char *AT_string PARAMS ((dw_attr_ref));
4453 static inline const char *
4457 if (a && AT_class (a) == dw_val_class_str)
4458 return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id);
4463 /* Find out whether a string should be output inline in DIE
4464 or out-of-line in .debug_str section. */
4466 static int AT_string_form PARAMS ((dw_attr_ref));
4471 if (a && AT_class (a) == dw_val_class_str)
4473 struct indirect_string_node *node;
4475 extern int const_labelno;
4478 node = a->dw_attr_val.v.val_str;
4482 len = HT_LEN (&node->id) + 1;
4484 /* If the string is shorter or equal to the size
4485 of the reference, it is always better to put it
4487 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4488 return node->form = DW_FORM_string;
4490 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0)
4492 /* If we cannot expect the linker to merge strings
4493 in .debug_str section, only put it into .debug_str
4494 if it is worth even in this single module. */
4495 if ((len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4496 return node->form = DW_FORM_string;
4499 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4501 node->label = xstrdup (label);
4502 return node->form = DW_FORM_strp;
4508 /* Add a DIE reference attribute value to a DIE. */
4511 add_AT_die_ref (die, attr_kind, targ_die)
4513 enum dwarf_attribute attr_kind;
4514 dw_die_ref targ_die;
4516 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4518 attr->dw_attr_next = NULL;
4519 attr->dw_attr = attr_kind;
4520 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4521 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4522 attr->dw_attr_val.v.val_die_ref.external = 0;
4523 add_dwarf_attr (die, attr);
4526 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4527 static inline dw_die_ref
4531 if (a && AT_class (a) == dw_val_class_die_ref)
4532 return a->dw_attr_val.v.val_die_ref.die;
4537 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4542 if (a && AT_class (a) == dw_val_class_die_ref)
4543 return a->dw_attr_val.v.val_die_ref.external;
4548 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4550 set_AT_ref_external (a, i)
4554 if (a && AT_class (a) == dw_val_class_die_ref)
4555 a->dw_attr_val.v.val_die_ref.external = i;
4560 /* Add an FDE reference attribute value to a DIE. */
4563 add_AT_fde_ref (die, attr_kind, targ_fde)
4565 enum dwarf_attribute attr_kind;
4568 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4570 attr->dw_attr_next = NULL;
4571 attr->dw_attr = attr_kind;
4572 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4573 attr->dw_attr_val.v.val_fde_index = targ_fde;
4574 add_dwarf_attr (die, attr);
4577 /* Add a location description attribute value to a DIE. */
4580 add_AT_loc (die, attr_kind, loc)
4582 enum dwarf_attribute attr_kind;
4583 dw_loc_descr_ref loc;
4585 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4587 attr->dw_attr_next = NULL;
4588 attr->dw_attr = attr_kind;
4589 attr->dw_attr_val.val_class = dw_val_class_loc;
4590 attr->dw_attr_val.v.val_loc = loc;
4591 add_dwarf_attr (die, attr);
4594 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4595 static inline dw_loc_descr_ref
4599 if (a && AT_class (a) == dw_val_class_loc)
4600 return a->dw_attr_val.v.val_loc;
4606 add_AT_loc_list (die, attr_kind, loc_list)
4608 enum dwarf_attribute attr_kind;
4609 dw_loc_list_ref loc_list;
4611 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4613 attr->dw_attr_next = NULL;
4614 attr->dw_attr = attr_kind;
4615 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4616 attr->dw_attr_val.v.val_loc_list = loc_list;
4617 add_dwarf_attr (die, attr);
4618 have_location_lists = 1;
4621 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
4623 static inline dw_loc_list_ref
4627 if (a && AT_class (a) == dw_val_class_loc_list)
4628 return a->dw_attr_val.v.val_loc_list;
4633 /* Add an address constant attribute value to a DIE. */
4636 add_AT_addr (die, attr_kind, addr)
4638 enum dwarf_attribute attr_kind;
4641 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4643 attr->dw_attr_next = NULL;
4644 attr->dw_attr = attr_kind;
4645 attr->dw_attr_val.val_class = dw_val_class_addr;
4646 attr->dw_attr_val.v.val_addr = addr;
4647 add_dwarf_attr (die, attr);
4650 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4655 if (a && AT_class (a) == dw_val_class_addr)
4656 return a->dw_attr_val.v.val_addr;
4661 /* Add a label identifier attribute value to a DIE. */
4664 add_AT_lbl_id (die, attr_kind, lbl_id)
4666 enum dwarf_attribute attr_kind;
4669 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4671 attr->dw_attr_next = NULL;
4672 attr->dw_attr = attr_kind;
4673 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4674 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4675 add_dwarf_attr (die, attr);
4678 /* Add a section offset attribute value to a DIE. */
4681 add_AT_lbl_offset (die, attr_kind, label)
4683 enum dwarf_attribute attr_kind;
4686 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4688 attr->dw_attr_next = NULL;
4689 attr->dw_attr = attr_kind;
4690 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4691 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4692 add_dwarf_attr (die, attr);
4695 /* Add an offset attribute value to a DIE. */
4698 add_AT_offset (die, attr_kind, offset)
4700 enum dwarf_attribute attr_kind;
4701 unsigned long offset;
4703 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4705 attr->dw_attr_next = NULL;
4706 attr->dw_attr = attr_kind;
4707 attr->dw_attr_val.val_class = dw_val_class_offset;
4708 attr->dw_attr_val.v.val_offset = offset;
4709 add_dwarf_attr (die, attr);
4712 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4713 static inline const char *
4717 if (a && (AT_class (a) == dw_val_class_lbl_id
4718 || AT_class (a) == dw_val_class_lbl_offset))
4719 return a->dw_attr_val.v.val_lbl_id;
4724 /* Get the attribute of type attr_kind. */
4726 static inline dw_attr_ref
4727 get_AT (die, attr_kind)
4729 enum dwarf_attribute attr_kind;
4732 dw_die_ref spec = NULL;
4736 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4738 if (a->dw_attr == attr_kind)
4741 if (a->dw_attr == DW_AT_specification
4742 || a->dw_attr == DW_AT_abstract_origin)
4747 return get_AT (spec, attr_kind);
4753 /* Return the "low pc" attribute value, typically associated with
4754 a subprogram DIE. Return null if the "low pc" attribute is
4755 either not present, or if it cannot be represented as an
4756 assembler label identifier. */
4758 static inline const char *
4762 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4763 return a ? AT_lbl (a) : NULL;
4766 /* Return the "high pc" attribute value, typically associated with
4767 a subprogram DIE. Return null if the "high pc" attribute is
4768 either not present, or if it cannot be represented as an
4769 assembler label identifier. */
4771 static inline const char *
4775 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4776 return a ? AT_lbl (a) : NULL;
4779 /* Return the value of the string attribute designated by ATTR_KIND, or
4780 NULL if it is not present. */
4782 static inline const char *
4783 get_AT_string (die, attr_kind)
4785 enum dwarf_attribute attr_kind;
4787 dw_attr_ref a = get_AT (die, attr_kind);
4788 return a ? AT_string (a) : NULL;
4791 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4792 if it is not present. */
4795 get_AT_flag (die, attr_kind)
4797 enum dwarf_attribute attr_kind;
4799 dw_attr_ref a = get_AT (die, attr_kind);
4800 return a ? AT_flag (a) : 0;
4803 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4804 if it is not present. */
4806 static inline unsigned
4807 get_AT_unsigned (die, attr_kind)
4809 enum dwarf_attribute attr_kind;
4811 dw_attr_ref a = get_AT (die, attr_kind);
4812 return a ? AT_unsigned (a) : 0;
4815 static inline dw_die_ref
4816 get_AT_ref (die, attr_kind)
4818 enum dwarf_attribute attr_kind;
4820 dw_attr_ref a = get_AT (die, attr_kind);
4821 return a ? AT_ref (a) : NULL;
4827 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4829 return (lang == DW_LANG_C || lang == DW_LANG_C89
4830 || lang == DW_LANG_C_plus_plus);
4836 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4837 == DW_LANG_C_plus_plus);
4843 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4845 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4851 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4853 return (lang == DW_LANG_Java);
4856 /* Free up the memory used by A. */
4858 static inline void free_AT PARAMS ((dw_attr_ref));
4863 switch (AT_class (a))
4865 case dw_val_class_str:
4866 if (a->dw_attr_val.v.val_str->refcount)
4867 a->dw_attr_val.v.val_str->refcount--;
4870 case dw_val_class_lbl_id:
4871 case dw_val_class_lbl_offset:
4872 free (a->dw_attr_val.v.val_lbl_id);
4875 case dw_val_class_float:
4876 free (a->dw_attr_val.v.val_float.array);
4886 /* Remove the specified attribute if present. */
4889 remove_AT (die, attr_kind)
4891 enum dwarf_attribute attr_kind;
4894 dw_attr_ref removed = NULL;
4898 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4899 if ((*p)->dw_attr == attr_kind)
4902 *p = (*p)->dw_attr_next;
4911 /* Free up the memory used by DIE. */
4913 static inline void free_die PARAMS ((dw_die_ref));
4918 remove_children (die);
4922 /* Discard the children of this DIE. */
4925 remove_children (die)
4928 dw_die_ref child_die = die->die_child;
4930 die->die_child = NULL;
4932 while (child_die != NULL)
4934 dw_die_ref tmp_die = child_die;
4937 child_die = child_die->die_sib;
4939 for (a = tmp_die->die_attr; a != NULL;)
4941 dw_attr_ref tmp_a = a;
4943 a = a->dw_attr_next;
4951 /* Add a child DIE below its parent. We build the lists up in reverse
4952 addition order, and correct that in reverse_all_dies. */
4955 add_child_die (die, child_die)
4957 dw_die_ref child_die;
4959 if (die != NULL && child_die != NULL)
4961 if (die == child_die)
4963 child_die->die_parent = die;
4964 child_die->die_sib = die->die_child;
4965 die->die_child = child_die;
4969 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4970 is the specification, to the front of PARENT's list of children. */
4973 splice_child_die (parent, child)
4974 dw_die_ref parent, child;
4978 /* We want the declaration DIE from inside the class, not the
4979 specification DIE at toplevel. */
4980 if (child->die_parent != parent)
4982 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4987 if (child->die_parent != parent
4988 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4991 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4994 *p = child->die_sib;
4998 child->die_sib = parent->die_child;
4999 parent->die_child = child;
5002 /* Return a pointer to a newly created DIE node. */
5004 static inline dw_die_ref
5005 new_die (tag_value, parent_die)
5006 enum dwarf_tag tag_value;
5007 dw_die_ref parent_die;
5009 dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5011 die->die_tag = tag_value;
5013 if (parent_die != NULL)
5014 add_child_die (parent_die, die);
5017 limbo_die_node *limbo_node;
5019 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5020 limbo_node->die = die;
5021 limbo_node->next = limbo_die_list;
5022 limbo_die_list = limbo_node;
5028 /* Return the DIE associated with the given type specifier. */
5030 static inline dw_die_ref
5031 lookup_type_die (type)
5034 if (TREE_CODE (type) == VECTOR_TYPE)
5035 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
5036 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
5039 /* Equate a DIE to a given type specifier. */
5042 equate_type_number_to_die (type, type_die)
5044 dw_die_ref type_die;
5046 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
5049 /* Return the DIE associated with a given declaration. */
5051 static inline dw_die_ref
5052 lookup_decl_die (decl)
5055 unsigned decl_id = DECL_UID (decl);
5057 return (decl_id < decl_die_table_in_use
5058 ? decl_die_table[decl_id] : NULL);
5061 /* Equate a DIE to a particular declaration. */
5064 equate_decl_number_to_die (decl, decl_die)
5066 dw_die_ref decl_die;
5068 unsigned decl_id = DECL_UID (decl);
5069 unsigned num_allocated;
5071 if (decl_id >= decl_die_table_allocated)
5074 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5075 / DECL_DIE_TABLE_INCREMENT)
5076 * DECL_DIE_TABLE_INCREMENT;
5079 = (dw_die_ref *) xrealloc (decl_die_table,
5080 sizeof (dw_die_ref) * num_allocated);
5082 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5083 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5084 decl_die_table_allocated = num_allocated;
5087 if (decl_id >= decl_die_table_in_use)
5088 decl_die_table_in_use = (decl_id + 1);
5090 decl_die_table[decl_id] = decl_die;
5093 /* Keep track of the number of spaces used to indent the
5094 output of the debugging routines that print the structure of
5095 the DIE internal representation. */
5096 static int print_indent;
5098 /* Indent the line the number of spaces given by print_indent. */
5101 print_spaces (outfile)
5104 fprintf (outfile, "%*s", print_indent, "");
5107 /* Print the information associated with a given DIE, and its children.
5108 This routine is a debugging aid only. */
5111 print_die (die, outfile)
5118 print_spaces (outfile);
5119 fprintf (outfile, "DIE %4lu: %s\n",
5120 die->die_offset, dwarf_tag_name (die->die_tag));
5121 print_spaces (outfile);
5122 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5123 fprintf (outfile, " offset: %lu\n", die->die_offset);
5125 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5127 print_spaces (outfile);
5128 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5130 switch (AT_class (a))
5132 case dw_val_class_addr:
5133 fprintf (outfile, "address");
5135 case dw_val_class_offset:
5136 fprintf (outfile, "offset");
5138 case dw_val_class_loc:
5139 fprintf (outfile, "location descriptor");
5141 case dw_val_class_loc_list:
5142 fprintf (outfile, "location list -> label:%s",
5143 AT_loc_list (a)->ll_symbol);
5145 case dw_val_class_const:
5146 fprintf (outfile, "%ld", AT_int (a));
5148 case dw_val_class_unsigned_const:
5149 fprintf (outfile, "%lu", AT_unsigned (a));
5151 case dw_val_class_long_long:
5152 fprintf (outfile, "constant (%lu,%lu)",
5153 a->dw_attr_val.v.val_long_long.hi,
5154 a->dw_attr_val.v.val_long_long.low);
5156 case dw_val_class_float:
5157 fprintf (outfile, "floating-point constant");
5159 case dw_val_class_flag:
5160 fprintf (outfile, "%u", AT_flag (a));
5162 case dw_val_class_die_ref:
5163 if (AT_ref (a) != NULL)
5165 if (AT_ref (a)->die_symbol)
5166 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5168 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5171 fprintf (outfile, "die -> <null>");
5173 case dw_val_class_lbl_id:
5174 case dw_val_class_lbl_offset:
5175 fprintf (outfile, "label: %s", AT_lbl (a));
5177 case dw_val_class_str:
5178 if (AT_string (a) != NULL)
5179 fprintf (outfile, "\"%s\"", AT_string (a));
5181 fprintf (outfile, "<null>");
5187 fprintf (outfile, "\n");
5190 if (die->die_child != NULL)
5193 for (c = die->die_child; c != NULL; c = c->die_sib)
5194 print_die (c, outfile);
5198 if (print_indent == 0)
5199 fprintf (outfile, "\n");
5202 /* Print the contents of the source code line number correspondence table.
5203 This routine is a debugging aid only. */
5206 print_dwarf_line_table (outfile)
5210 dw_line_info_ref line_info;
5212 fprintf (outfile, "\n\nDWARF source line information\n");
5213 for (i = 1; i < line_info_table_in_use; ++i)
5215 line_info = &line_info_table[i];
5216 fprintf (outfile, "%5d: ", i);
5217 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5218 fprintf (outfile, "%6ld", line_info->dw_line_num);
5219 fprintf (outfile, "\n");
5222 fprintf (outfile, "\n\n");
5225 /* Print the information collected for a given DIE. */
5228 debug_dwarf_die (die)
5231 print_die (die, stderr);
5234 /* Print all DWARF information collected for the compilation unit.
5235 This routine is a debugging aid only. */
5241 print_die (comp_unit_die, stderr);
5242 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5243 print_dwarf_line_table (stderr);
5246 /* We build up the lists of children and attributes by pushing new ones
5247 onto the beginning of the list. Reverse the lists for DIE so that
5248 they are in order of addition. */
5251 reverse_die_lists (die)
5254 dw_die_ref c, cp, cn;
5255 dw_attr_ref a, ap, an;
5257 for (a = die->die_attr, ap = 0; a; a = an)
5259 an = a->dw_attr_next;
5260 a->dw_attr_next = ap;
5265 for (c = die->die_child, cp = 0; c; c = cn)
5271 die->die_child = cp;
5274 /* reverse_die_lists only reverses the single die you pass it. Since
5275 we used to reverse all dies in add_sibling_attributes, which runs
5276 through all the dies, it would reverse all the dies. Now, however,
5277 since we don't call reverse_die_lists in add_sibling_attributes, we
5278 need a routine to recursively reverse all the dies. This is that
5282 reverse_all_dies (die)
5287 reverse_die_lists (die);
5289 for (c = die->die_child; c; c = c->die_sib)
5290 reverse_all_dies (c);
5293 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5294 the CU for the enclosing include file, if any. BINCL_DIE is the
5295 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5299 push_new_compile_unit (old_unit, bincl_die)
5300 dw_die_ref old_unit, bincl_die;
5302 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5303 dw_die_ref new_unit = gen_compile_unit_die (filename);
5304 new_unit->die_sib = old_unit;
5308 /* Close an include-file CU and reopen the enclosing one. */
5311 pop_compile_unit (old_unit)
5312 dw_die_ref old_unit;
5314 dw_die_ref new_unit = old_unit->die_sib;
5315 old_unit->die_sib = NULL;
5319 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5320 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5322 /* Calculate the checksum of a location expression. */
5325 loc_checksum (loc, ctx)
5326 dw_loc_descr_ref loc;
5327 struct md5_ctx *ctx;
5329 PROCESS (loc->dw_loc_opc);
5330 PROCESS (loc->dw_loc_oprnd1);
5331 PROCESS (loc->dw_loc_oprnd2);
5334 /* Calculate the checksum of an attribute. */
5337 attr_checksum (at, ctx)
5339 struct md5_ctx *ctx;
5341 dw_loc_descr_ref loc;
5344 PROCESS (at->dw_attr);
5346 /* We don't care about differences in file numbering. */
5347 if (at->dw_attr == DW_AT_decl_file
5348 /* Or that this was compiled with a different compiler snapshot; if
5349 the output is the same, that's what matters. */
5350 || at->dw_attr == DW_AT_producer)
5353 switch (AT_class (at))
5355 case dw_val_class_const:
5356 PROCESS (at->dw_attr_val.v.val_int);
5358 case dw_val_class_unsigned_const:
5359 PROCESS (at->dw_attr_val.v.val_unsigned);
5361 case dw_val_class_long_long:
5362 PROCESS (at->dw_attr_val.v.val_long_long);
5364 case dw_val_class_float:
5365 PROCESS (at->dw_attr_val.v.val_float);
5367 case dw_val_class_flag:
5368 PROCESS (at->dw_attr_val.v.val_flag);
5371 case dw_val_class_str:
5372 PROCESS_STRING (AT_string (at));
5375 case dw_val_class_addr:
5377 switch (GET_CODE (r))
5380 PROCESS_STRING (XSTR (r, 0));
5388 case dw_val_class_offset:
5389 PROCESS (at->dw_attr_val.v.val_offset);
5392 case dw_val_class_loc:
5393 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5394 loc_checksum (loc, ctx);
5397 case dw_val_class_die_ref:
5398 if (AT_ref (at)->die_offset)
5399 PROCESS (AT_ref (at)->die_offset);
5400 /* FIXME else use target die name or something. */
5402 case dw_val_class_fde_ref:
5403 case dw_val_class_lbl_id:
5404 case dw_val_class_lbl_offset:
5412 /* Calculate the checksum of a DIE. */
5415 die_checksum (die, ctx)
5417 struct md5_ctx *ctx;
5422 PROCESS (die->die_tag);
5424 for (a = die->die_attr; a; a = a->dw_attr_next)
5425 attr_checksum (a, ctx);
5427 for (c = die->die_child; c; c = c->die_sib)
5428 die_checksum (c, ctx);
5432 #undef PROCESS_STRING
5434 /* The prefix to attach to symbols on DIEs in the current comdat debug
5436 static char *comdat_symbol_id;
5438 /* The index of the current symbol within the current comdat CU. */
5439 static unsigned int comdat_symbol_number;
5441 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5442 children, and set comdat_symbol_id accordingly. */
5445 compute_section_prefix (unit_die)
5446 dw_die_ref unit_die;
5450 unsigned char checksum[16];
5453 md5_init_ctx (&ctx);
5454 die_checksum (unit_die, &ctx);
5455 md5_finish_ctx (&ctx, checksum);
5458 const char *p = lbasename (get_AT_string (unit_die, DW_AT_name));
5459 name = (char *) alloca (strlen (p) + 64);
5460 sprintf (name, "%s.", p);
5463 clean_symbol_name (name);
5466 char *p = name + strlen (name);
5467 for (i = 0; i < 4; ++i)
5469 sprintf (p, "%.2x", checksum[i]);
5474 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5475 comdat_symbol_number = 0;
5478 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5484 switch (die->die_tag)
5486 case DW_TAG_array_type:
5487 case DW_TAG_class_type:
5488 case DW_TAG_enumeration_type:
5489 case DW_TAG_pointer_type:
5490 case DW_TAG_reference_type:
5491 case DW_TAG_string_type:
5492 case DW_TAG_structure_type:
5493 case DW_TAG_subroutine_type:
5494 case DW_TAG_union_type:
5495 case DW_TAG_ptr_to_member_type:
5496 case DW_TAG_set_type:
5497 case DW_TAG_subrange_type:
5498 case DW_TAG_base_type:
5499 case DW_TAG_const_type:
5500 case DW_TAG_file_type:
5501 case DW_TAG_packed_type:
5502 case DW_TAG_volatile_type:
5509 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5510 Basically, we want to choose the bits that are likely to be shared between
5511 compilations (types) and leave out the bits that are specific to individual
5512 compilations (functions). */
5519 /* I think we want to leave base types and __vtbl_ptr_type in the
5520 main CU, as we do for stabs. The advantage is a greater
5521 likelihood of sharing between objects that don't include headers
5522 in the same order (and therefore would put the base types in a
5523 different comdat). jason 8/28/00 */
5524 if (c->die_tag == DW_TAG_base_type)
5527 if (c->die_tag == DW_TAG_pointer_type
5528 || c->die_tag == DW_TAG_reference_type
5529 || c->die_tag == DW_TAG_const_type
5530 || c->die_tag == DW_TAG_volatile_type)
5532 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5533 return t ? is_comdat_die (t) : 0;
5537 return is_type_die (c);
5540 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5541 compilation unit. */
5547 if (is_type_die (c))
5549 if (get_AT (c, DW_AT_declaration)
5550 && ! get_AT (c, DW_AT_specification))
5556 gen_internal_sym (prefix)
5560 static int label_num;
5561 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5562 return xstrdup (buf);
5565 /* Assign symbols to all worthy DIEs under DIE. */
5568 assign_symbol_names (die)
5573 if (is_symbol_die (die))
5575 if (comdat_symbol_id)
5577 char *p = alloca (strlen (comdat_symbol_id) + 64);
5578 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5579 comdat_symbol_id, comdat_symbol_number++);
5580 die->die_symbol = xstrdup (p);
5583 die->die_symbol = gen_internal_sym ("LDIE");
5586 for (c = die->die_child; c != NULL; c = c->die_sib)
5587 assign_symbol_names (c);
5590 /* Traverse the DIE (which is always comp_unit_die), and set up
5591 additional compilation units for each of the include files we see
5592 bracketed by BINCL/EINCL. */
5595 break_out_includes (die)
5599 dw_die_ref unit = NULL;
5600 limbo_die_node *node;
5602 for (ptr = &(die->die_child); *ptr; )
5604 dw_die_ref c = *ptr;
5606 if (c->die_tag == DW_TAG_GNU_BINCL
5607 || c->die_tag == DW_TAG_GNU_EINCL
5608 || (unit && is_comdat_die (c)))
5610 /* This DIE is for a secondary CU; remove it from the main one. */
5613 if (c->die_tag == DW_TAG_GNU_BINCL)
5615 unit = push_new_compile_unit (unit, c);
5618 else if (c->die_tag == DW_TAG_GNU_EINCL)
5620 unit = pop_compile_unit (unit);
5624 add_child_die (unit, c);
5628 /* Leave this DIE in the main CU. */
5629 ptr = &(c->die_sib);
5635 /* We can only use this in debugging, since the frontend doesn't check
5636 to make sure that we leave every include file we enter. */
5641 assign_symbol_names (die);
5642 for (node = limbo_die_list; node; node = node->next)
5644 compute_section_prefix (node->die);
5645 assign_symbol_names (node->die);
5649 /* Traverse the DIE and add a sibling attribute if it may have the
5650 effect of speeding up access to siblings. To save some space,
5651 avoid generating sibling attributes for DIE's without children. */
5654 add_sibling_attributes (die)
5659 if (die->die_tag != DW_TAG_compile_unit
5660 && die->die_sib && die->die_child != NULL)
5661 /* Add the sibling link to the front of the attribute list. */
5662 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5664 for (c = die->die_child; c != NULL; c = c->die_sib)
5665 add_sibling_attributes (c);
5668 /* Output all location lists for the DIE and it's children */
5670 output_location_lists (die)
5675 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5677 if (AT_class (d_attr) == dw_val_class_loc_list)
5679 output_loc_list (AT_loc_list (d_attr));
5682 for (c = die->die_child; c != NULL; c = c->die_sib)
5683 output_location_lists (c);
5686 /* The format of each DIE (and its attribute value pairs)
5687 is encoded in an abbreviation table. This routine builds the
5688 abbreviation table and assigns a unique abbreviation id for
5689 each abbreviation entry. The children of each die are visited
5693 build_abbrev_table (die)
5696 unsigned long abbrev_id;
5697 unsigned int n_alloc;
5699 dw_attr_ref d_attr, a_attr;
5701 /* Scan the DIE references, and mark as external any that refer to
5702 DIEs from other CUs (i.e. those which are not marked). */
5703 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5705 if (AT_class (d_attr) == dw_val_class_die_ref
5706 && AT_ref (d_attr)->die_mark == 0)
5708 if (AT_ref (d_attr)->die_symbol == 0)
5710 set_AT_ref_external (d_attr, 1);
5714 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5716 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5718 if (abbrev->die_tag == die->die_tag)
5720 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5722 a_attr = abbrev->die_attr;
5723 d_attr = die->die_attr;
5725 while (a_attr != NULL && d_attr != NULL)
5727 if ((a_attr->dw_attr != d_attr->dw_attr)
5728 || (value_format (a_attr) != value_format (d_attr)))
5731 a_attr = a_attr->dw_attr_next;
5732 d_attr = d_attr->dw_attr_next;
5735 if (a_attr == NULL && d_attr == NULL)
5741 if (abbrev_id >= abbrev_die_table_in_use)
5743 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5745 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5747 = (dw_die_ref *) xrealloc (abbrev_die_table,
5748 sizeof (dw_die_ref) * n_alloc);
5750 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5751 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5752 abbrev_die_table_allocated = n_alloc;
5755 ++abbrev_die_table_in_use;
5756 abbrev_die_table[abbrev_id] = die;
5759 die->die_abbrev = abbrev_id;
5760 for (c = die->die_child; c != NULL; c = c->die_sib)
5761 build_abbrev_table (c);
5764 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5767 constant_size (value)
5768 long unsigned value;
5775 log = floor_log2 (value);
5778 log = 1 << (floor_log2 (log) + 1);
5783 /* Return the size of a DIE, as it is represented in the
5784 .debug_info section. */
5786 static unsigned long
5790 unsigned long size = 0;
5793 size += size_of_uleb128 (die->die_abbrev);
5794 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5796 switch (AT_class (a))
5798 case dw_val_class_addr:
5799 size += DWARF2_ADDR_SIZE;
5801 case dw_val_class_offset:
5802 size += DWARF_OFFSET_SIZE;
5804 case dw_val_class_loc:
5806 unsigned long lsize = size_of_locs (AT_loc (a));
5809 size += constant_size (lsize);
5813 case dw_val_class_loc_list:
5814 size += DWARF_OFFSET_SIZE;
5816 case dw_val_class_const:
5817 size += size_of_sleb128 (AT_int (a));
5819 case dw_val_class_unsigned_const:
5820 size += constant_size (AT_unsigned (a));
5822 case dw_val_class_long_long:
5823 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5825 case dw_val_class_float:
5826 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5828 case dw_val_class_flag:
5831 case dw_val_class_die_ref:
5832 size += DWARF_OFFSET_SIZE;
5834 case dw_val_class_fde_ref:
5835 size += DWARF_OFFSET_SIZE;
5837 case dw_val_class_lbl_id:
5838 size += DWARF2_ADDR_SIZE;
5840 case dw_val_class_lbl_offset:
5841 size += DWARF_OFFSET_SIZE;
5843 case dw_val_class_str:
5844 if (AT_string_form (a) == DW_FORM_strp)
5845 size += DWARF_OFFSET_SIZE;
5847 size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1;
5857 /* Size the debugging information associated with a given DIE.
5858 Visits the DIE's children recursively. Updates the global
5859 variable next_die_offset, on each time through. Uses the
5860 current value of next_die_offset to update the die_offset
5861 field in each DIE. */
5864 calc_die_sizes (die)
5868 die->die_offset = next_die_offset;
5869 next_die_offset += size_of_die (die);
5871 for (c = die->die_child; c != NULL; c = c->die_sib)
5874 if (die->die_child != NULL)
5875 /* Count the null byte used to terminate sibling lists. */
5876 next_die_offset += 1;
5879 /* Set the marks for a die and its children. We do this so
5880 that we know whether or not a reference needs to use FORM_ref_addr; only
5881 DIEs in the same CU will be marked. We used to clear out the offset
5882 and use that as the flag, but ran into ordering problems. */
5890 for (c = die->die_child; c; c = c->die_sib)
5894 /* Clear the marks for a die and its children. */
5902 for (c = die->die_child; c; c = c->die_sib)
5906 /* Return the size of the .debug_pubnames table generated for the
5907 compilation unit. */
5909 static unsigned long
5915 size = DWARF_PUBNAMES_HEADER_SIZE;
5916 for (i = 0; i < pubname_table_in_use; ++i)
5918 pubname_ref p = &pubname_table[i];
5919 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
5922 size += DWARF_OFFSET_SIZE;
5926 /* Return the size of the information in the .debug_aranges section. */
5928 static unsigned long
5933 size = DWARF_ARANGES_HEADER_SIZE;
5935 /* Count the address/length pair for this compilation unit. */
5936 size += 2 * DWARF2_ADDR_SIZE;
5937 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5939 /* Count the two zero words used to terminated the address range table. */
5940 size += 2 * DWARF2_ADDR_SIZE;
5944 /* Select the encoding of an attribute value. */
5946 static enum dwarf_form
5950 switch (a->dw_attr_val.val_class)
5952 case dw_val_class_addr:
5953 return DW_FORM_addr;
5954 case dw_val_class_offset:
5955 if (DWARF_OFFSET_SIZE == 4)
5956 return DW_FORM_data4;
5957 if (DWARF_OFFSET_SIZE == 8)
5958 return DW_FORM_data8;
5960 case dw_val_class_loc_list:
5961 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
5962 .debug_loc section */
5963 return DW_FORM_data4;
5964 case dw_val_class_loc:
5965 switch (constant_size (size_of_locs (AT_loc (a))))
5968 return DW_FORM_block1;
5970 return DW_FORM_block2;
5974 case dw_val_class_const:
5975 return DW_FORM_sdata;
5976 case dw_val_class_unsigned_const:
5977 switch (constant_size (AT_unsigned (a)))
5980 return DW_FORM_data1;
5982 return DW_FORM_data2;
5984 return DW_FORM_data4;
5986 return DW_FORM_data8;
5990 case dw_val_class_long_long:
5991 return DW_FORM_block1;
5992 case dw_val_class_float:
5993 return DW_FORM_block1;
5994 case dw_val_class_flag:
5995 return DW_FORM_flag;
5996 case dw_val_class_die_ref:
5997 if (AT_ref_external (a))
5998 return DW_FORM_ref_addr;
6001 case dw_val_class_fde_ref:
6002 return DW_FORM_data;
6003 case dw_val_class_lbl_id:
6004 return DW_FORM_addr;
6005 case dw_val_class_lbl_offset:
6006 return DW_FORM_data;
6007 case dw_val_class_str:
6008 return AT_string_form (a);
6015 /* Output the encoding of an attribute value. */
6018 output_value_format (a)
6021 enum dwarf_form form = value_format (a);
6022 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6025 /* Output the .debug_abbrev section which defines the DIE abbreviation
6029 output_abbrev_section ()
6031 unsigned long abbrev_id;
6034 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6036 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6038 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6040 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6041 dwarf_tag_name (abbrev->die_tag));
6043 if (abbrev->die_child != NULL)
6044 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6046 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6048 for (a_attr = abbrev->die_attr; a_attr != NULL;
6049 a_attr = a_attr->dw_attr_next)
6051 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6052 dwarf_attr_name (a_attr->dw_attr));
6053 output_value_format (a_attr);
6056 dw2_asm_output_data (1, 0, NULL);
6057 dw2_asm_output_data (1, 0, NULL);
6060 /* Terminate the table. */
6061 dw2_asm_output_data (1, 0, NULL);
6064 /* Output a symbol we can use to refer to this DIE from another CU. */
6067 output_die_symbol (die)
6070 char *sym = die->die_symbol;
6075 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6076 /* We make these global, not weak; if the target doesn't support
6077 .linkonce, it doesn't support combining the sections, so debugging
6079 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6080 ASM_OUTPUT_LABEL (asm_out_file, sym);
6083 /* Return a new location list, given the begin and end range, and the
6084 expression. gensym tells us whether to generate a new internal
6085 symbol for this location list node, which is done for the head of
6087 static inline dw_loc_list_ref
6088 new_loc_list (expr, begin, end, section, gensym)
6089 dw_loc_descr_ref expr;
6092 const char *section;
6095 dw_loc_list_ref retlist
6096 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6097 retlist->begin = begin;
6099 retlist->expr = expr;
6100 retlist->section = section;
6102 retlist->ll_symbol = gen_internal_sym ("LLST");
6106 /* Add a location description expression to a location list */
6108 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6109 dw_loc_list_ref *list_head;
6110 dw_loc_descr_ref descr;
6113 const char *section;
6117 /* Find the end of the chain. */
6118 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6120 /* Add a new location list node to the list */
6121 *d = new_loc_list (descr, begin, end, section, 0);
6124 /* Output the location list given to us */
6126 output_loc_list (list_head)
6127 dw_loc_list_ref list_head;
6129 dw_loc_list_ref curr=list_head;
6130 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6132 /* ??? This shouldn't be needed now that we've forced the
6133 compilation unit base address to zero when there is code
6134 in more than one section. */
6135 if (strcmp (curr->section, ".text") == 0)
6137 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6138 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT)0,
6139 "Location list base address specifier fake entry");
6140 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6141 "Location list base address specifier base");
6143 for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
6146 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6147 "Location list begin address (%s)",
6148 list_head->ll_symbol);
6149 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6150 "Location list end address (%s)",
6151 list_head->ll_symbol);
6152 size = size_of_locs (curr->expr);
6154 /* Output the block length for this list of location operations. */
6155 dw2_asm_output_data (constant_size (size), size, "%s",
6156 "Location expression size");
6158 output_loc_sequence (curr->expr);
6160 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6161 "Location list terminator begin (%s)",
6162 list_head->ll_symbol);
6163 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6164 "Location list terminator end (%s)",
6165 list_head->ll_symbol);
6168 /* Output the DIE and its attributes. Called recursively to generate
6169 the definitions of each child DIE. */
6179 /* If someone in another CU might refer to us, set up a symbol for
6180 them to point to. */
6181 if (die->die_symbol)
6182 output_die_symbol (die);
6184 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6185 die->die_offset, dwarf_tag_name (die->die_tag));
6187 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6189 const char *name = dwarf_attr_name (a->dw_attr);
6191 switch (AT_class (a))
6193 case dw_val_class_addr:
6194 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6197 case dw_val_class_offset:
6198 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6202 case dw_val_class_loc:
6203 size = size_of_locs (AT_loc (a));
6205 /* Output the block length for this list of location operations. */
6206 dw2_asm_output_data (constant_size (size), size, "%s", name);
6208 output_loc_sequence (AT_loc (a));
6211 case dw_val_class_const:
6212 /* ??? It would be slightly more efficient to use a scheme like is
6213 used for unsigned constants below, but gdb 4.x does not sign
6214 extend. Gdb 5.x does sign extend. */
6215 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6218 case dw_val_class_unsigned_const:
6219 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6220 AT_unsigned (a), "%s", name);
6223 case dw_val_class_long_long:
6225 unsigned HOST_WIDE_INT first, second;
6227 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6230 if (WORDS_BIG_ENDIAN)
6232 first = a->dw_attr_val.v.val_long_long.hi;
6233 second = a->dw_attr_val.v.val_long_long.low;
6237 first = a->dw_attr_val.v.val_long_long.low;
6238 second = a->dw_attr_val.v.val_long_long.hi;
6240 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6241 first, "long long constant");
6242 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6247 case dw_val_class_float:
6251 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6254 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6255 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6256 "fp constant word %u", i);
6260 case dw_val_class_flag:
6261 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6264 case dw_val_class_loc_list:
6266 char *sym = AT_loc_list (a)->ll_symbol;
6269 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6270 loc_section_label, "%s", name);
6274 case dw_val_class_die_ref:
6275 if (AT_ref_external (a))
6277 char *sym = AT_ref (a)->die_symbol;
6280 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6282 else if (AT_ref (a)->die_offset == 0)
6285 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6289 case dw_val_class_fde_ref:
6292 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6293 a->dw_attr_val.v.val_fde_index * 2);
6294 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6298 case dw_val_class_lbl_id:
6299 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6302 case dw_val_class_lbl_offset:
6303 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6306 case dw_val_class_str:
6307 if (AT_string_form (a) == DW_FORM_strp)
6308 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6309 a->dw_attr_val.v.val_str->label,
6312 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6320 for (c = die->die_child; c != NULL; c = c->die_sib)
6323 if (die->die_child != NULL)
6325 /* Add null byte to terminate sibling list. */
6326 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6331 /* Output the compilation unit that appears at the beginning of the
6332 .debug_info section, and precedes the DIE descriptions. */
6335 output_compilation_unit_header ()
6337 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6338 "Length of Compilation Unit Info");
6340 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6342 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6343 "Offset Into Abbrev. Section");
6345 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6348 /* Output the compilation unit DIE and its children. */
6351 output_comp_unit (die)
6354 const char *secname;
6356 /* Even if there are no children of this DIE, we must output the
6357 information about the compilation unit. Otherwise, on an empty
6358 translation unit, we will generate a present, but empty,
6359 .debug_info section. IRIX 6.5 `nm' will then complain when
6362 Mark all the DIEs in this CU so we know which get local refs. */
6365 build_abbrev_table (die);
6367 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6368 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6369 calc_die_sizes (die);
6371 if (die->die_symbol)
6373 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6374 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6376 die->die_symbol = NULL;
6379 secname = (const char *) DEBUG_INFO_SECTION;
6381 /* Output debugging information. */
6382 named_section_flags (secname, SECTION_DEBUG);
6383 output_compilation_unit_header ();
6386 /* Leave the marks on the main CU, so we can check them in
6388 if (die->die_symbol)
6392 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6393 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6394 argument list, and maybe the scope. */
6397 dwarf2_name (decl, scope)
6401 return (*decl_printable_name) (decl, scope ? 1 : 0);
6404 /* Add a new entry to .debug_pubnames if appropriate. */
6407 add_pubname (decl, die)
6413 if (! TREE_PUBLIC (decl))
6416 if (pubname_table_in_use == pubname_table_allocated)
6418 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6419 pubname_table = (pubname_ref) xrealloc
6420 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6423 p = &pubname_table[pubname_table_in_use++];
6426 p->name = xstrdup (dwarf2_name (decl, 1));
6429 /* Output the public names table used to speed up access to externally
6430 visible names. For now, only generate entries for externally
6431 visible procedures. */
6437 unsigned long pubnames_length = size_of_pubnames ();
6439 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6440 "Length of Public Names Info");
6442 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6444 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6445 "Offset of Compilation Unit Info");
6447 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6448 "Compilation Unit Length");
6450 for (i = 0; i < pubname_table_in_use; ++i)
6452 pubname_ref pub = &pubname_table[i];
6454 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6455 if (pub->die->die_mark == 0)
6458 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6461 dw2_asm_output_nstring (pub->name, -1, "external name");
6464 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6467 /* Add a new entry to .debug_aranges if appropriate. */
6470 add_arange (decl, die)
6474 if (! DECL_SECTION_NAME (decl))
6477 if (arange_table_in_use == arange_table_allocated)
6479 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6480 arange_table = (dw_die_ref *)
6481 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6484 arange_table[arange_table_in_use++] = die;
6487 /* Output the information that goes into the .debug_aranges table.
6488 Namely, define the beginning and ending address range of the
6489 text section generated for this compilation unit. */
6495 unsigned long aranges_length = size_of_aranges ();
6497 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6498 "Length of Address Ranges Info");
6500 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6502 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6503 "Offset of Compilation Unit Info");
6505 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6507 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6509 /* We need to align to twice the pointer size here. */
6510 if (DWARF_ARANGES_PAD_SIZE)
6512 /* Pad using a 2 byte words so that padding is correct for any
6514 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6515 2 * DWARF2_ADDR_SIZE);
6516 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6517 dw2_asm_output_data (2, 0, NULL);
6520 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6521 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6522 text_section_label, "Length");
6524 for (i = 0; i < arange_table_in_use; ++i)
6526 dw_die_ref die = arange_table[i];
6528 /* We shouldn't see aranges for DIEs outside of the main CU. */
6529 if (die->die_mark == 0)
6532 if (die->die_tag == DW_TAG_subprogram)
6534 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6536 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6537 get_AT_low_pc (die), "Length");
6541 /* A static variable; extract the symbol from DW_AT_location.
6542 Note that this code isn't currently hit, as we only emit
6543 aranges for functions (jason 9/23/99). */
6545 dw_attr_ref a = get_AT (die, DW_AT_location);
6546 dw_loc_descr_ref loc;
6547 if (! a || AT_class (a) != dw_val_class_loc)
6551 if (loc->dw_loc_opc != DW_OP_addr)
6554 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6555 loc->dw_loc_oprnd1.v.val_addr, "Address");
6556 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6557 get_AT_unsigned (die, DW_AT_byte_size),
6562 /* Output the terminator words. */
6563 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6564 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6567 /* Add a new entry to .debug_ranges. Return the offset at which it
6574 unsigned int in_use = ranges_table_in_use;
6576 if (in_use == ranges_table_allocated)
6578 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6579 ranges_table = (dw_ranges_ref)
6580 xrealloc (ranges_table, (ranges_table_allocated
6581 * sizeof (struct dw_ranges_struct)));
6584 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6585 ranges_table_in_use = in_use + 1;
6587 return in_use * 2 * DWARF2_ADDR_SIZE;
6594 static const char *const start_fmt = "Offset 0x%x";
6595 const char *fmt = start_fmt;
6597 for (i = 0; i < ranges_table_in_use; ++i)
6599 int block_num = ranges_table[i].block_num;
6603 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6604 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6606 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6607 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6609 /* If all code is in the text section, then the compilation
6610 unit base address defaults to DW_AT_low_pc, which is the
6611 base of the text section. */
6612 if (separate_line_info_table_in_use == 0)
6614 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6616 fmt, i * 2 * DWARF2_ADDR_SIZE);
6617 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6618 text_section_label, NULL);
6620 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6621 compilation unit base address to zero, which allows us to
6622 use absolute addresses, and not worry about whether the
6623 target supports cross-section arithmetic. */
6626 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6627 fmt, i * 2 * DWARF2_ADDR_SIZE);
6628 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6635 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6636 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6642 /* Data structure containing information about input files. */
6645 char *path; /* Complete file name. */
6646 char *fname; /* File name part. */
6647 int length; /* Length of entire string. */
6648 int file_idx; /* Index in input file table. */
6649 int dir_idx; /* Index in directory table. */
6652 /* Data structure containing information about directories with source
6656 char *path; /* Path including directory name. */
6657 int length; /* Path length. */
6658 int prefix; /* Index of directory entry which is a prefix. */
6659 int count; /* Number of files in this directory. */
6660 int dir_idx; /* Index of directory used as base. */
6661 int used; /* Used in the end? */
6664 /* Callback function for file_info comparison. We sort by looking at
6665 the directories in the path. */
6668 file_info_cmp (p1, p2)
6672 const struct file_info *s1 = p1;
6673 const struct file_info *s2 = p2;
6677 /* Take care of file names without directories. We need to make sure that
6678 we return consistent values to qsort since some will get confused if
6679 we return the same value when identical operands are passed in opposite
6680 orders. So if neither has a directory, return 0 and otherwise return
6681 1 or -1 depending on which one has the directory. */
6682 if ((s1->path == s1->fname || s2->path == s2->fname))
6683 return (s2->path == s2->fname) - (s1->path == s1->fname);
6685 cp1 = (unsigned char *) s1->path;
6686 cp2 = (unsigned char *) s2->path;
6692 /* Reached the end of the first path? If so, handle like above. */
6693 if ((cp1 == (unsigned char *) s1->fname)
6694 || (cp2 == (unsigned char *) s2->fname))
6695 return ((cp2 == (unsigned char *) s2->fname)
6696 - (cp1 == (unsigned char *) s1->fname));
6698 /* Character of current path component the same? */
6699 else if (*cp1 != *cp2)
6704 /* Output the directory table and the file name table. We try to minimize
6705 the total amount of memory needed. A heuristic is used to avoid large
6706 slowdowns with many input files. */
6708 output_file_names ()
6710 struct file_info *files;
6711 struct dir_info *dirs;
6720 /* Allocate the various arrays we need. */
6721 files = (struct file_info *) alloca (file_table.in_use
6722 * sizeof (struct file_info));
6723 dirs = (struct dir_info *) alloca (file_table.in_use
6724 * sizeof (struct dir_info));
6726 /* Sort the file names. */
6727 for (i = 1; i < (int) file_table.in_use; ++i)
6731 /* Skip all leading "./". */
6732 f = file_table.table[i];
6733 while (f[0] == '.' && f[1] == '/')
6736 /* Create a new array entry. */
6738 files[i].length = strlen (f);
6739 files[i].file_idx = i;
6741 /* Search for the file name part. */
6742 f = strrchr (f, '/');
6743 files[i].fname = f == NULL ? files[i].path : f + 1;
6745 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6747 /* Find all the different directories used. */
6748 dirs[0].path = files[1].path;
6749 dirs[0].length = files[1].fname - files[1].path;
6750 dirs[0].prefix = -1;
6752 dirs[0].dir_idx = 0;
6754 files[1].dir_idx = 0;
6757 for (i = 2; i < (int) file_table.in_use; ++i)
6758 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6759 && memcmp (dirs[ndirs - 1].path, files[i].path,
6760 dirs[ndirs - 1].length) == 0)
6762 /* Same directory as last entry. */
6763 files[i].dir_idx = ndirs - 1;
6764 ++dirs[ndirs - 1].count;
6770 /* This is a new directory. */
6771 dirs[ndirs].path = files[i].path;
6772 dirs[ndirs].length = files[i].fname - files[i].path;
6773 dirs[ndirs].count = 1;
6774 dirs[ndirs].dir_idx = ndirs;
6775 dirs[ndirs].used = 0;
6776 files[i].dir_idx = ndirs;
6778 /* Search for a prefix. */
6779 dirs[ndirs].prefix = -1;
6780 for (j = 0; j < ndirs; ++j)
6781 if (dirs[j].length < dirs[ndirs].length
6782 && dirs[j].length > 1
6783 && (dirs[ndirs].prefix == -1
6784 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6785 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6786 dirs[ndirs].prefix = j;
6791 /* Now to the actual work. We have to find a subset of the
6792 directories which allow expressing the file name using references
6793 to the directory table with the least amount of characters. We
6794 do not do an exhaustive search where we would have to check out
6795 every combination of every single possible prefix. Instead we
6796 use a heuristic which provides nearly optimal results in most
6797 cases and never is much off. */
6798 saved = (int *) alloca (ndirs * sizeof (int));
6799 savehere = (int *) alloca (ndirs * sizeof (int));
6801 memset (saved, '\0', ndirs * sizeof (saved[0]));
6802 for (i = 0; i < ndirs; ++i)
6807 /* We can always save some space for the current directory. But
6808 this does not mean it will be enough to justify adding the
6810 savehere[i] = dirs[i].length;
6811 total = (savehere[i] - saved[i]) * dirs[i].count;
6813 for (j = i + 1; j < ndirs; ++j)
6817 if (saved[j] < dirs[i].length)
6819 /* Determine whether the dirs[i] path is a prefix of the
6824 while (k != -1 && k != i)
6829 /* Yes it is. We can possibly safe some memory but
6830 writing the filenames in dirs[j] relative to
6832 savehere[j] = dirs[i].length;
6833 total += (savehere[j] - saved[j]) * dirs[j].count;
6838 /* Check whether we can safe enough to justify adding the dirs[i]
6840 if (total > dirs[i].length + 1)
6842 /* It's worthwhile adding. */
6843 for (j = i; j < ndirs; ++j)
6844 if (savehere[j] > 0)
6846 /* Remember how much we saved for this directory so far. */
6847 saved[j] = savehere[j];
6849 /* Remember the prefix directory. */
6850 dirs[j].dir_idx = i;
6855 /* We have to emit them in the order they appear in the file_table
6856 array since the index is used in the debug info generation. To
6857 do this efficiently we generate a back-mapping of the indices
6859 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6860 for (i = 1; i < (int) file_table.in_use; ++i)
6862 backmap[files[i].file_idx] = i;
6863 /* Mark this directory as used. */
6864 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6867 /* That was it. We are ready to emit the information. First the
6868 directory name table. Here we have to make sure that the first
6869 actually emitted directory name has the index one. Zero is
6870 reserved for the current working directory. Make sure we do not
6871 confuse these indices with the one for the constructed table
6872 (even though most of the time they are identical). */
6874 idx_offset = dirs[0].length > 0 ? 1 : 0;
6875 for (i = 1 - idx_offset; i < ndirs; ++i)
6876 if (dirs[i].used != 0)
6878 dirs[i].used = idx++;
6879 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6880 "Directory Entry: 0x%x", dirs[i].used);
6882 dw2_asm_output_data (1, 0, "End directory table");
6884 /* Correct the index for the current working directory entry if it
6886 if (idx_offset == 0)
6889 /* Now write all the file names. */
6890 for (i = 1; i < (int) file_table.in_use; ++i)
6892 int file_idx = backmap[i];
6893 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6895 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6896 "File Entry: 0x%x", i);
6898 /* Include directory index. */
6899 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6901 /* Modification time. */
6902 dw2_asm_output_data_uleb128 (0, NULL);
6904 /* File length in bytes. */
6905 dw2_asm_output_data_uleb128 (0, NULL);
6907 dw2_asm_output_data (1, 0, "End file name table");
6911 /* Output the source line number correspondence information. This
6912 information goes into the .debug_line section. */
6917 char l1[20], l2[20], p1[20], p2[20];
6918 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6919 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6922 unsigned long lt_index;
6923 unsigned long current_line;
6926 unsigned long current_file;
6927 unsigned long function;
6929 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6930 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6931 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6932 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6934 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6935 "Length of Source Line Info");
6936 ASM_OUTPUT_LABEL (asm_out_file, l1);
6938 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6940 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6941 ASM_OUTPUT_LABEL (asm_out_file, p1);
6943 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6944 "Minimum Instruction Length");
6946 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6947 "Default is_stmt_start flag");
6949 dw2_asm_output_data (1, DWARF_LINE_BASE,
6950 "Line Base Value (Special Opcodes)");
6952 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6953 "Line Range Value (Special Opcodes)");
6955 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6956 "Special Opcode Base");
6958 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6962 case DW_LNS_advance_pc:
6963 case DW_LNS_advance_line:
6964 case DW_LNS_set_file:
6965 case DW_LNS_set_column:
6966 case DW_LNS_fixed_advance_pc:
6974 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6978 /* Write out the information about the files we use. */
6979 output_file_names ();
6980 ASM_OUTPUT_LABEL (asm_out_file, p2);
6982 /* We used to set the address register to the first location in the text
6983 section here, but that didn't accomplish anything since we already
6984 have a line note for the opening brace of the first function. */
6986 /* Generate the line number to PC correspondence table, encoded as
6987 a series of state machine operations. */
6990 strcpy (prev_line_label, text_section_label);
6991 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6993 dw_line_info_ref line_info = &line_info_table[lt_index];
6996 /* Disable this optimization for now; GDB wants to see two line notes
6997 at the beginning of a function so it can find the end of the
7000 /* Don't emit anything for redundant notes. Just updating the
7001 address doesn't accomplish anything, because we already assume
7002 that anything after the last address is this line. */
7003 if (line_info->dw_line_num == current_line
7004 && line_info->dw_file_num == current_file)
7008 /* Emit debug info for the address of the current line.
7010 Unfortunately, we have little choice here currently, and must always
7011 use the most general form. Gcc does not know the address delta
7012 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7013 attributes which will give an upper bound on the address range. We
7014 could perhaps use length attributes to determine when it is safe to
7015 use DW_LNS_fixed_advance_pc. */
7017 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7020 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7021 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7022 "DW_LNS_fixed_advance_pc");
7023 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7027 /* This can handle any delta. This takes
7028 4+DWARF2_ADDR_SIZE bytes. */
7029 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7030 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7031 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7032 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7034 strcpy (prev_line_label, line_label);
7036 /* Emit debug info for the source file of the current line, if
7037 different from the previous line. */
7038 if (line_info->dw_file_num != current_file)
7040 current_file = line_info->dw_file_num;
7041 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7042 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7043 file_table.table[current_file]);
7046 /* Emit debug info for the current line number, choosing the encoding
7047 that uses the least amount of space. */
7048 if (line_info->dw_line_num != current_line)
7050 line_offset = line_info->dw_line_num - current_line;
7051 line_delta = line_offset - DWARF_LINE_BASE;
7052 current_line = line_info->dw_line_num;
7053 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7055 /* This can handle deltas from -10 to 234, using the current
7056 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7058 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7059 "line %lu", current_line);
7063 /* This can handle any delta. This takes at least 4 bytes,
7064 depending on the value being encoded. */
7065 dw2_asm_output_data (1, DW_LNS_advance_line,
7066 "advance to line %lu", current_line);
7067 dw2_asm_output_data_sleb128 (line_offset, NULL);
7068 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7073 /* We still need to start a new row, so output a copy insn. */
7074 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7078 /* Emit debug info for the address of the end of the function. */
7081 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7082 "DW_LNS_fixed_advance_pc");
7083 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7087 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7088 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7089 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7090 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7093 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7094 dw2_asm_output_data_uleb128 (1, NULL);
7095 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7100 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7102 dw_separate_line_info_ref line_info
7103 = &separate_line_info_table[lt_index];
7106 /* Don't emit anything for redundant notes. */
7107 if (line_info->dw_line_num == current_line
7108 && line_info->dw_file_num == current_file
7109 && line_info->function == function)
7113 /* Emit debug info for the address of the current line. If this is
7114 a new function, or the first line of a function, then we need
7115 to handle it differently. */
7116 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7118 if (function != line_info->function)
7120 function = line_info->function;
7122 /* Set the address register to the first line in the function */
7123 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7124 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7125 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7126 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7130 /* ??? See the DW_LNS_advance_pc comment above. */
7133 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7134 "DW_LNS_fixed_advance_pc");
7135 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7139 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7140 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7141 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7142 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7145 strcpy (prev_line_label, line_label);
7147 /* Emit debug info for the source file of the current line, if
7148 different from the previous line. */
7149 if (line_info->dw_file_num != current_file)
7151 current_file = line_info->dw_file_num;
7152 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7153 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7154 file_table.table[current_file]);
7157 /* Emit debug info for the current line number, choosing the encoding
7158 that uses the least amount of space. */
7159 if (line_info->dw_line_num != current_line)
7161 line_offset = line_info->dw_line_num - current_line;
7162 line_delta = line_offset - DWARF_LINE_BASE;
7163 current_line = line_info->dw_line_num;
7164 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7165 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7166 "line %lu", current_line);
7169 dw2_asm_output_data (1, DW_LNS_advance_line,
7170 "advance to line %lu", current_line);
7171 dw2_asm_output_data_sleb128 (line_offset, NULL);
7172 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7176 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7183 /* If we're done with a function, end its sequence. */
7184 if (lt_index == separate_line_info_table_in_use
7185 || separate_line_info_table[lt_index].function != function)
7190 /* Emit debug info for the address of the end of the function. */
7191 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
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);
7206 /* Output the marker for the end of this sequence. */
7207 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7208 dw2_asm_output_data_uleb128 (1, NULL);
7209 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7213 /* Output the marker for the end of the line number info. */
7214 ASM_OUTPUT_LABEL (asm_out_file, l2);
7217 /* Given a pointer to a tree node for some base type, return a pointer to
7218 a DIE that describes the given type.
7220 This routine must only be called for GCC type nodes that correspond to
7221 Dwarf base (fundamental) types. */
7224 base_type_die (type)
7227 dw_die_ref base_type_result;
7228 const char *type_name;
7229 enum dwarf_type encoding;
7230 tree name = TYPE_NAME (type);
7232 if (TREE_CODE (type) == ERROR_MARK
7233 || TREE_CODE (type) == VOID_TYPE)
7238 if (TREE_CODE (name) == TYPE_DECL)
7239 name = DECL_NAME (name);
7241 type_name = IDENTIFIER_POINTER (name);
7244 type_name = "__unknown__";
7246 switch (TREE_CODE (type))
7249 /* Carefully distinguish the C character types, without messing
7250 up if the language is not C. Note that we check only for the names
7251 that contain spaces; other names might occur by coincidence in other
7253 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7254 && (type == char_type_node
7255 || ! strcmp (type_name, "signed char")
7256 || ! strcmp (type_name, "unsigned char"))))
7258 if (TREE_UNSIGNED (type))
7259 encoding = DW_ATE_unsigned;
7261 encoding = DW_ATE_signed;
7264 /* else fall through. */
7267 /* GNU Pascal/Ada CHAR type. Not used in C. */
7268 if (TREE_UNSIGNED (type))
7269 encoding = DW_ATE_unsigned_char;
7271 encoding = DW_ATE_signed_char;
7275 encoding = DW_ATE_float;
7278 /* Dwarf2 doesn't know anything about complex ints, so use
7279 a user defined type for it. */
7281 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7282 encoding = DW_ATE_complex_float;
7284 encoding = DW_ATE_lo_user;
7288 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7289 encoding = DW_ATE_boolean;
7293 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7296 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7297 if (demangle_name_func)
7298 type_name = (*demangle_name_func) (type_name);
7300 add_AT_string (base_type_result, DW_AT_name, type_name);
7301 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7302 int_size_in_bytes (type));
7303 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7305 return base_type_result;
7308 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7309 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7310 a given type is generally the same as the given type, except that if the
7311 given type is a pointer or reference type, then the root type of the given
7312 type is the root type of the "basis" type for the pointer or reference
7313 type. (This definition of the "root" type is recursive.) Also, the root
7314 type of a `const' qualified type or a `volatile' qualified type is the
7315 root type of the given type without the qualifiers. */
7321 if (TREE_CODE (type) == ERROR_MARK)
7322 return error_mark_node;
7324 switch (TREE_CODE (type))
7327 return error_mark_node;
7330 case REFERENCE_TYPE:
7331 return type_main_variant (root_type (TREE_TYPE (type)));
7334 return type_main_variant (type);
7338 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7339 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7345 switch (TREE_CODE (type))
7360 case QUAL_UNION_TYPE:
7365 case REFERENCE_TYPE:
7379 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7380 entry that chains various modifiers in front of the given type. */
7383 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7386 int is_volatile_type;
7387 dw_die_ref context_die;
7389 enum tree_code code = TREE_CODE (type);
7390 dw_die_ref mod_type_die = NULL;
7391 dw_die_ref sub_die = NULL;
7392 tree item_type = NULL;
7394 if (code != ERROR_MARK)
7396 tree qualified_type;
7398 /* See if we already have the appropriately qualified variant of
7401 = get_qualified_type (type,
7402 ((is_const_type ? TYPE_QUAL_CONST : 0)
7404 ? TYPE_QUAL_VOLATILE : 0)));
7405 /* If we do, then we can just use its DIE, if it exists. */
7408 mod_type_die = lookup_type_die (qualified_type);
7410 return mod_type_die;
7413 /* Handle C typedef types. */
7414 if (qualified_type && TYPE_NAME (qualified_type)
7415 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7416 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7418 tree type_name = TYPE_NAME (qualified_type);
7419 tree dtype = TREE_TYPE (type_name);
7420 if (qualified_type == dtype)
7422 /* For a named type, use the typedef. */
7423 gen_type_die (qualified_type, context_die);
7424 mod_type_die = lookup_type_die (qualified_type);
7427 else if (is_const_type < TYPE_READONLY (dtype)
7428 || is_volatile_type < TYPE_VOLATILE (dtype))
7429 /* cv-unqualified version of named type. Just use the unnamed
7430 type to which it refers. */
7432 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7433 is_const_type, is_volatile_type,
7435 /* Else cv-qualified version of named type; fall through. */
7441 else if (is_const_type)
7443 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7444 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7446 else if (is_volatile_type)
7448 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7449 sub_die = modified_type_die (type, 0, 0, context_die);
7451 else if (code == POINTER_TYPE)
7453 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7454 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7456 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7458 item_type = TREE_TYPE (type);
7460 else if (code == REFERENCE_TYPE)
7462 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7463 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7465 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7467 item_type = TREE_TYPE (type);
7469 else if (is_base_type (type))
7470 mod_type_die = base_type_die (type);
7473 gen_type_die (type, context_die);
7475 /* We have to get the type_main_variant here (and pass that to the
7476 `lookup_type_die' routine) because the ..._TYPE node we have
7477 might simply be a *copy* of some original type node (where the
7478 copy was created to help us keep track of typedef names) and
7479 that copy might have a different TYPE_UID from the original
7481 mod_type_die = lookup_type_die (type_main_variant (type));
7482 if (mod_type_die == NULL)
7486 /* We want to equate the qualified type to the die below. */
7488 type = qualified_type;
7491 equate_type_number_to_die (type, mod_type_die);
7493 /* We must do this after the equate_type_number_to_die call, in case
7494 this is a recursive type. This ensures that the modified_type_die
7495 recursion will terminate even if the type is recursive. Recursive
7496 types are possible in Ada. */
7497 sub_die = modified_type_die (item_type,
7498 TYPE_READONLY (item_type),
7499 TYPE_VOLATILE (item_type),
7502 if (sub_die != NULL)
7503 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7505 return mod_type_die;
7508 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7509 an enumerated type. */
7515 return TREE_CODE (type) == ENUMERAL_TYPE;
7518 /* Return the register number described by a given RTL node. */
7524 unsigned regno = REGNO (rtl);
7526 if (regno >= FIRST_PSEUDO_REGISTER)
7529 return DBX_REGISTER_NUMBER (regno);
7532 /* Return a location descriptor that designates a machine register or
7533 zero if there is no such. */
7535 static dw_loc_descr_ref
7536 reg_loc_descriptor (rtl)
7539 dw_loc_descr_ref loc_result = NULL;
7542 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7545 reg = reg_number (rtl);
7547 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7549 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7554 /* Return a location descriptor that designates a constant. */
7556 static dw_loc_descr_ref
7557 int_loc_descriptor (i)
7560 enum dwarf_location_atom op;
7562 /* Pick the smallest representation of a constant, rather than just
7563 defaulting to the LEB encoding. */
7567 op = DW_OP_lit0 + i;
7570 else if (i <= 0xffff)
7572 else if (HOST_BITS_PER_WIDE_INT == 32
7582 else if (i >= -0x8000)
7584 else if (HOST_BITS_PER_WIDE_INT == 32
7585 || i >= -0x80000000)
7591 return new_loc_descr (op, i, 0);
7594 /* Return a location descriptor that designates a base+offset location. */
7596 static dw_loc_descr_ref
7597 based_loc_descr (reg, offset)
7601 dw_loc_descr_ref loc_result;
7602 /* For the "frame base", we use the frame pointer or stack pointer
7603 registers, since the RTL for local variables is relative to one of
7605 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7606 ? HARD_FRAME_POINTER_REGNUM
7607 : STACK_POINTER_REGNUM);
7610 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7612 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7614 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7619 /* Return true if this RTL expression describes a base+offset calculation. */
7625 return (GET_CODE (rtl) == PLUS
7626 && ((GET_CODE (XEXP (rtl, 0)) == REG
7627 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
7628 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7631 /* The following routine converts the RTL for a variable or parameter
7632 (resident in memory) into an equivalent Dwarf representation of a
7633 mechanism for getting the address of that same variable onto the top of a
7634 hypothetical "address evaluation" stack.
7636 When creating memory location descriptors, we are effectively transforming
7637 the RTL for a memory-resident object into its Dwarf postfix expression
7638 equivalent. This routine recursively descends an RTL tree, turning
7639 it into Dwarf postfix code as it goes.
7641 MODE is the mode of the memory reference, needed to handle some
7642 autoincrement addressing modes.
7644 Return 0 if we can't represent the location. */
7646 static dw_loc_descr_ref
7647 mem_loc_descriptor (rtl, mode)
7649 enum machine_mode mode;
7651 dw_loc_descr_ref mem_loc_result = NULL;
7653 /* Note that for a dynamically sized array, the location we will generate a
7654 description of here will be the lowest numbered location which is
7655 actually within the array. That's *not* necessarily the same as the
7656 zeroth element of the array. */
7658 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7659 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7662 switch (GET_CODE (rtl))
7667 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7668 just fall into the SUBREG code. */
7673 /* The case of a subreg may arise when we have a local (register)
7674 variable or a formal (register) parameter which doesn't quite fill
7675 up an entire register. For now, just assume that it is
7676 legitimate to make the Dwarf info refer to the whole register which
7677 contains the given subreg. */
7678 rtl = SUBREG_REG (rtl);
7683 /* Whenever a register number forms a part of the description of the
7684 method for calculating the (dynamic) address of a memory resident
7685 object, DWARF rules require the register number be referred to as
7686 a "base register". This distinction is not based in any way upon
7687 what category of register the hardware believes the given register
7688 belongs to. This is strictly DWARF terminology we're dealing with
7689 here. Note that in cases where the location of a memory-resident
7690 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7691 OP_CONST (0)) the actual DWARF location descriptor that we generate
7692 may just be OP_BASEREG (basereg). This may look deceptively like
7693 the object in question was allocated to a register (rather than in
7694 memory) so DWARF consumers need to be aware of the subtle
7695 distinction between OP_REG and OP_BASEREG. */
7696 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
7697 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7701 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7702 if (mem_loc_result != 0)
7703 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7707 /* Some ports can transform a symbol ref into a label ref, because
7708 the symbol ref is too far away and has to be dumped into a constant
7712 /* Alternatively, the symbol in the constant pool might be referenced
7713 by a different symbol. */
7714 if (GET_CODE (rtl) == SYMBOL_REF
7715 && CONSTANT_POOL_ADDRESS_P (rtl))
7717 rtx tmp = get_pool_constant (rtl);
7718 if (GET_CODE (tmp) == SYMBOL_REF)
7722 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7723 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7724 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7728 /* Extract the PLUS expression nested inside and fall into
7730 rtl = XEXP (rtl, 1);
7735 /* Turn these into a PLUS expression and fall into the PLUS code
7737 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7738 GEN_INT (GET_CODE (rtl) == PRE_INC
7739 ? GET_MODE_UNIT_SIZE (mode)
7740 : -GET_MODE_UNIT_SIZE (mode)));
7746 if (is_based_loc (rtl))
7747 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7748 INTVAL (XEXP (rtl, 1)));
7751 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7752 if (mem_loc_result == 0)
7755 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7756 && INTVAL (XEXP (rtl, 1)) >= 0)
7757 add_loc_descr (&mem_loc_result,
7758 new_loc_descr (DW_OP_plus_uconst,
7759 INTVAL (XEXP (rtl, 1)), 0));
7762 add_loc_descr (&mem_loc_result,
7763 mem_loc_descriptor (XEXP (rtl, 1), mode));
7764 add_loc_descr (&mem_loc_result,
7765 new_loc_descr (DW_OP_plus, 0, 0));
7772 /* If a pseudo-reg is optimized away, it is possible for it to
7773 be replaced with a MEM containing a multiply. */
7774 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
7775 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
7777 if (op0 == 0 || op1 == 0)
7780 mem_loc_result = op0;
7781 add_loc_descr (&mem_loc_result, op1);
7782 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7787 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7794 return mem_loc_result;
7797 /* Return a descriptor that describes the concatenation of two locations.
7798 This is typically a complex variable. */
7800 static dw_loc_descr_ref
7801 concat_loc_descriptor (x0, x1)
7804 dw_loc_descr_ref cc_loc_result = NULL;
7805 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
7806 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
7808 if (x0_ref == 0 || x1_ref == 0)
7811 cc_loc_result = x0_ref;
7812 add_loc_descr (&cc_loc_result,
7813 new_loc_descr (DW_OP_piece,
7814 GET_MODE_SIZE (GET_MODE (x0)), 0));
7816 add_loc_descr (&cc_loc_result, x1_ref);
7817 add_loc_descr (&cc_loc_result,
7818 new_loc_descr (DW_OP_piece,
7819 GET_MODE_SIZE (GET_MODE (x1)), 0));
7821 return cc_loc_result;
7824 /* Output a proper Dwarf location descriptor for a variable or parameter
7825 which is either allocated in a register or in a memory location. For a
7826 register, we just generate an OP_REG and the register number. For a
7827 memory location we provide a Dwarf postfix expression describing how to
7828 generate the (dynamic) address of the object onto the address stack.
7830 If we don't know how to describe it, return 0. */
7832 static dw_loc_descr_ref
7833 loc_descriptor (rtl)
7836 dw_loc_descr_ref loc_result = NULL;
7838 switch (GET_CODE (rtl))
7841 /* The case of a subreg may arise when we have a local (register)
7842 variable or a formal (register) parameter which doesn't quite fill
7843 up an entire register. For now, just assume that it is
7844 legitimate to make the Dwarf info refer to the whole register which
7845 contains the given subreg. */
7846 rtl = SUBREG_REG (rtl);
7851 loc_result = reg_loc_descriptor (rtl);
7855 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7859 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7869 /* Similar, but generate the descriptor from trees instead of rtl.
7870 This comes up particularly with variable length arrays. If ADDRESSP
7871 is nonzero, we are looking for an address. Otherwise, we return a
7872 value. If we can't find a value, return 0. */
7874 static dw_loc_descr_ref
7875 loc_descriptor_from_tree (loc, addressp)
7879 dw_loc_descr_ref ret, ret1;
7881 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7882 enum dwarf_location_atom op;
7884 /* ??? Most of the time we do not take proper care for sign/zero
7885 extending the values properly. Hopefully this won't be a real
7888 switch (TREE_CODE (loc))
7893 case WITH_RECORD_EXPR:
7894 case PLACEHOLDER_EXPR:
7895 /* This case involves extracting fields from an object to determine the
7896 position of other fields. We don't try to encode this here. The
7897 only user of this is Ada, which encodes the needed information using
7898 the names of types. */
7904 rtx rtl = rtl_for_decl_location (loc);
7905 enum machine_mode mode = GET_MODE (rtl);
7907 if (rtl == NULL_RTX)
7909 else if (CONSTANT_P (rtl))
7911 ret = new_loc_descr (DW_OP_addr, 0, 0);
7912 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7913 ret->dw_loc_oprnd1.v.val_addr = rtl;
7918 if (GET_CODE (rtl) == MEM)
7921 rtl = XEXP (rtl, 0);
7923 ret = mem_loc_descriptor (rtl, mode);
7929 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7934 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
7938 case NON_LVALUE_EXPR:
7939 case VIEW_CONVERT_EXPR:
7941 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7946 case ARRAY_RANGE_REF:
7949 HOST_WIDE_INT bitsize, bitpos, bytepos;
7950 enum machine_mode mode;
7953 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7954 &unsignedp, &volatilep);
7959 ret = loc_descriptor_from_tree (obj, 1);
7961 || bitpos % BITS_PER_UNIT != 0
7962 || bitsize % BITS_PER_UNIT != 0)
7965 if (offset != NULL_TREE)
7967 /* Variable offset. */
7968 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7969 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7975 bytepos = bitpos / BITS_PER_UNIT;
7977 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7978 else if (bytepos < 0)
7980 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7981 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7987 if (host_integerp (loc, 0))
7988 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8005 case TRUNC_DIV_EXPR:
8013 case TRUNC_MOD_EXPR:
8026 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8030 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8031 && host_integerp (TREE_OPERAND (loc, 1), 0))
8033 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8037 add_loc_descr (&ret,
8038 new_loc_descr (DW_OP_plus_uconst,
8039 tree_low_cst (TREE_OPERAND (loc, 1),
8048 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8055 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8062 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8069 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8084 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8085 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8086 if (ret == 0 || ret1 == 0)
8089 add_loc_descr (&ret, ret1);
8090 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8106 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8110 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8114 loc = build (COND_EXPR, TREE_TYPE (loc),
8115 build (LT_EXPR, integer_type_node,
8116 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8117 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8122 dw_loc_descr_ref lhs
8123 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8124 dw_loc_descr_ref rhs
8125 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8126 dw_loc_descr_ref bra_node, jump_node, tmp;
8128 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8129 if (ret == 0 || lhs == 0 || rhs == 0)
8132 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8133 add_loc_descr (&ret, bra_node);
8135 add_loc_descr (&ret, rhs);
8136 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8137 add_loc_descr (&ret, jump_node);
8139 add_loc_descr (&ret, lhs);
8140 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8141 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
8143 /* ??? Need a node to point the skip at. Use a nop. */
8144 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8145 add_loc_descr (&ret, tmp);
8146 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8147 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8155 /* Show if we can't fill the request for an address. */
8156 if (addressp && indirect_p == 0)
8159 /* If we've got an address and don't want one, dereference. */
8160 if (!addressp && indirect_p > 0)
8162 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8164 if (size > DWARF2_ADDR_SIZE || size == -1)
8166 if (size == DWARF2_ADDR_SIZE)
8169 op = DW_OP_deref_size;
8171 add_loc_descr (&ret, new_loc_descr (op, size, 0));
8177 /* Given a value, round it up to the lowest multiple of `boundary'
8178 which is not less than the value itself. */
8180 static inline HOST_WIDE_INT
8181 ceiling (value, boundary)
8182 HOST_WIDE_INT value;
8183 unsigned int boundary;
8185 return (((value + boundary - 1) / boundary) * boundary);
8188 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8189 pointer to the declared type for the relevant field variable, or return
8190 `integer_type_node' if the given node turns out to be an
8199 if (TREE_CODE (decl) == ERROR_MARK)
8200 return integer_type_node;
8202 type = DECL_BIT_FIELD_TYPE (decl);
8203 if (type == NULL_TREE)
8204 type = TREE_TYPE (decl);
8209 /* Given a pointer to a tree node, return the alignment in bits for
8210 it, or else return BITS_PER_WORD if the node actually turns out to
8211 be an ERROR_MARK node. */
8213 static inline unsigned
8214 simple_type_align_in_bits (type)
8217 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8220 static inline unsigned
8221 simple_decl_align_in_bits (decl)
8224 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8227 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8228 node, return the size in bits for the type if it is a constant, or else
8229 return the alignment for the type if the type's size is not constant, or
8230 else return BITS_PER_WORD if the type actually turns out to be an
8233 static inline unsigned HOST_WIDE_INT
8234 simple_type_size_in_bits (type)
8237 tree type_size_tree;
8239 if (TREE_CODE (type) == ERROR_MARK)
8240 return BITS_PER_WORD;
8241 type_size_tree = TYPE_SIZE (type);
8243 if (type_size_tree == NULL_TREE)
8245 if (! host_integerp (type_size_tree, 1))
8246 return TYPE_ALIGN (type);
8247 return tree_low_cst (type_size_tree, 1);
8250 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8251 return the byte offset of the lowest addressed byte of the "containing
8252 object" for the given FIELD_DECL, or return 0 if we are unable to
8253 determine what that offset is, either because the argument turns out to
8254 be a pointer to an ERROR_MARK node, or because the offset is actually
8255 variable. (We can't handle the latter case just yet). */
8257 static HOST_WIDE_INT
8258 field_byte_offset (decl)
8261 unsigned int type_align_in_bits;
8262 unsigned int decl_align_in_bits;
8263 unsigned HOST_WIDE_INT type_size_in_bits;
8264 HOST_WIDE_INT object_offset_in_bits;
8265 HOST_WIDE_INT object_offset_in_bytes;
8267 tree field_size_tree;
8268 HOST_WIDE_INT bitpos_int;
8269 HOST_WIDE_INT deepest_bitpos;
8270 unsigned HOST_WIDE_INT field_size_in_bits;
8272 if (TREE_CODE (decl) == ERROR_MARK)
8275 if (TREE_CODE (decl) != FIELD_DECL)
8278 type = field_type (decl);
8279 field_size_tree = DECL_SIZE (decl);
8281 /* The size could be unspecified if there was an error, or for
8282 a flexible array member. */
8283 if (! field_size_tree)
8284 field_size_tree = bitsize_zero_node;
8286 /* We cannot yet cope with fields whose positions are variable, so
8287 for now, when we see such things, we simply return 0. Someday, we may
8288 be able to handle such cases, but it will be damn difficult. */
8289 if (! host_integerp (bit_position (decl), 0))
8292 bitpos_int = int_bit_position (decl);
8294 /* If we don't know the size of the field, pretend it's a full word. */
8295 if (host_integerp (field_size_tree, 1))
8296 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8298 field_size_in_bits = BITS_PER_WORD;
8300 type_size_in_bits = simple_type_size_in_bits (type);
8301 type_align_in_bits = simple_type_align_in_bits (type);
8302 decl_align_in_bits = simple_decl_align_in_bits (decl);
8304 /* Note that the GCC front-end doesn't make any attempt to keep track of
8305 the starting bit offset (relative to the start of the containing
8306 structure type) of the hypothetical "containing object" for a bit-
8307 field. Thus, when computing the byte offset value for the start of the
8308 "containing object" of a bit-field, we must deduce this information on
8309 our own. This can be rather tricky to do in some cases. For example,
8310 handling the following structure type definition when compiling for an
8311 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8314 struct S { int field1; long long field2:31; };
8316 Fortunately, there is a simple rule-of-thumb which can be
8317 used in such cases. When compiling for an i386/i486, GCC will allocate
8318 8 bytes for the structure shown above. It decides to do this based upon
8319 one simple rule for bit-field allocation. Quite simply, GCC allocates
8320 each "containing object" for each bit-field at the first (i.e. lowest
8321 addressed) legitimate alignment boundary (based upon the required
8322 minimum alignment for the declared type of the field) which it can
8323 possibly use, subject to the condition that there is still enough
8324 available space remaining in the containing object (when allocated at
8325 the selected point) to fully accommodate all of the bits of the
8326 bit-field itself. This simple rule makes it obvious why GCC allocates
8327 8 bytes for each object of the structure type shown above. When looking
8328 for a place to allocate the "containing object" for `field2', the
8329 compiler simply tries to allocate a 64-bit "containing object" at each
8330 successive 32-bit boundary (starting at zero) until it finds a place to
8331 allocate that 64- bit field such that at least 31 contiguous (and
8332 previously unallocated) bits remain within that selected 64 bit field.
8333 (As it turns out, for the example above, the compiler finds that it is
8334 OK to allocate the "containing object" 64-bit field at bit-offset zero
8335 within the structure type.) Here we attempt to work backwards from the
8336 limited set of facts we're given, and we try to deduce from those facts,
8337 where GCC must have believed that the containing object started (within
8338 the structure type). The value we deduce is then used (by the callers of
8339 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8340 for fields (both bit-fields and, in the case of DW_AT_location, regular
8343 /* Figure out the bit-distance from the start of the structure to the
8344 "deepest" bit of the bit-field. */
8345 deepest_bitpos = bitpos_int + field_size_in_bits;
8347 /* This is the tricky part. Use some fancy footwork to deduce where the
8348 lowest addressed bit of the containing object must be. */
8349 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8351 /* Round up to type_align by default. This works best for bitfields. */
8352 object_offset_in_bits += type_align_in_bits - 1;
8353 object_offset_in_bits /= type_align_in_bits;
8354 object_offset_in_bits *= type_align_in_bits;
8356 if (object_offset_in_bits > bitpos_int)
8358 /* Sigh, the decl must be packed. */
8359 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8361 /* Round up to decl_align instead. */
8362 object_offset_in_bits += decl_align_in_bits - 1;
8363 object_offset_in_bits /= decl_align_in_bits;
8364 object_offset_in_bits *= decl_align_in_bits;
8367 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8369 return object_offset_in_bytes;
8372 /* The following routines define various Dwarf attributes and any data
8373 associated with them. */
8375 /* Add a location description attribute value to a DIE.
8377 This emits location attributes suitable for whole variables and
8378 whole parameters. Note that the location attributes for struct fields are
8379 generated by the routine `data_member_location_attribute' below. */
8382 add_AT_location_description (die, attr_kind, rtl)
8384 enum dwarf_attribute attr_kind;
8387 dw_loc_descr_ref descr = loc_descriptor (rtl);
8390 add_AT_loc (die, attr_kind, descr);
8393 /* Attach the specialized form of location attribute used for data
8394 members of struct and union types. In the special case of a
8395 FIELD_DECL node which represents a bit-field, the "offset" part
8396 of this special location descriptor must indicate the distance
8397 in bytes from the lowest-addressed byte of the containing struct
8398 or union type to the lowest-addressed byte of the "containing
8399 object" for the bit-field. (See the `field_byte_offset' function
8400 above).. For any given bit-field, the "containing object" is a
8401 hypothetical object (of some integral or enum type) within which
8402 the given bit-field lives. The type of this hypothetical
8403 "containing object" is always the same as the declared type of
8404 the individual bit-field itself (for GCC anyway... the DWARF
8405 spec doesn't actually mandate this). Note that it is the size
8406 (in bytes) of the hypothetical "containing object" which will
8407 be given in the DW_AT_byte_size attribute for this bit-field.
8408 (See the `byte_size_attribute' function below.) It is also used
8409 when calculating the value of the DW_AT_bit_offset attribute.
8410 (See the `bit_offset_attribute' function below). */
8413 add_data_member_location_attribute (die, decl)
8418 dw_loc_descr_ref loc_descr = 0;
8420 if (TREE_CODE (decl) == TREE_VEC)
8422 /* We're working on the TAG_inheritance for a base class. */
8424 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
8426 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8427 aren't at a fixed offset from all (sub)objects of the same
8428 type. We need to extract the appropriate offset from our
8429 vtable. The following dwarf expression means
8431 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8433 This is specific to the V3 ABI, of course. */
8435 dw_loc_descr_ref tmp;
8436 /* Make a copy of the object address. */
8437 tmp = new_loc_descr (DW_OP_dup, 0, 0);
8438 add_loc_descr (&loc_descr, tmp);
8439 /* Extract the vtable address. */
8440 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8441 add_loc_descr (&loc_descr, tmp);
8442 /* Calculate the address of the offset. */
8443 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
8446 tmp = int_loc_descriptor (-offset);
8447 add_loc_descr (&loc_descr, tmp);
8448 tmp = new_loc_descr (DW_OP_minus, 0, 0);
8449 add_loc_descr (&loc_descr, tmp);
8450 /* Extract the offset. */
8451 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8452 add_loc_descr (&loc_descr, tmp);
8453 /* Add it to the object address. */
8454 tmp = new_loc_descr (DW_OP_plus, 0, 0);
8455 add_loc_descr (&loc_descr, tmp);
8458 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8461 offset = field_byte_offset (decl);
8465 enum dwarf_location_atom op;
8467 /* The DWARF2 standard says that we should assume that the structure address
8468 is already on the stack, so we can specify a structure field address
8469 by using DW_OP_plus_uconst. */
8471 #ifdef MIPS_DEBUGGING_INFO
8472 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8473 correctly. It works only if we leave the offset on the stack. */
8476 op = DW_OP_plus_uconst;
8479 loc_descr = new_loc_descr (op, offset, 0);
8481 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8484 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8485 does not have a "location" either in memory or in a register. These
8486 things can arise in GNU C when a constant is passed as an actual parameter
8487 to an inlined function. They can also arise in C++ where declared
8488 constants do not necessarily get memory "homes". */
8491 add_const_value_attribute (die, rtl)
8495 switch (GET_CODE (rtl))
8498 /* Note that a CONST_INT rtx could represent either an integer
8499 or a floating-point constant. A CONST_INT is used whenever
8500 the constant will fit into a single word. In all such
8501 cases, the original mode of the constant value is wiped
8502 out, and the CONST_INT rtx is assigned VOIDmode. */
8504 HOST_WIDE_INT val = INTVAL (rtl);
8506 /* ??? We really should be using HOST_WIDE_INT throughout. */
8507 if (val < 0 && (long) val == val)
8508 add_AT_int (die, DW_AT_const_value, (long) val);
8509 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
8510 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8513 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8514 add_AT_long_long (die, DW_AT_const_value,
8515 val >> HOST_BITS_PER_LONG, val);
8524 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8525 floating-point constant. A CONST_DOUBLE is used whenever the
8526 constant requires more than one word in order to be adequately
8527 represented. We output CONST_DOUBLEs as blocks. */
8529 enum machine_mode mode = GET_MODE (rtl);
8531 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8533 unsigned length = GET_MODE_SIZE (mode) / 4;
8534 long *array = (long *) xmalloc (sizeof (long) * length);
8537 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8541 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8545 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8550 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8557 add_AT_float (die, DW_AT_const_value, length, array);
8561 /* ??? We really should be using HOST_WIDE_INT throughout. */
8562 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8564 add_AT_long_long (die, DW_AT_const_value,
8565 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8571 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8577 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8581 /* In cases where an inlined instance of an inline function is passed
8582 the address of an `auto' variable (which is local to the caller) we
8583 can get a situation where the DECL_RTL of the artificial local
8584 variable (for the inlining) which acts as a stand-in for the
8585 corresponding formal parameter (of the inline function) will look
8586 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8587 exactly a compile-time constant expression, but it isn't the address
8588 of the (artificial) local variable either. Rather, it represents the
8589 *value* which the artificial local variable always has during its
8590 lifetime. We currently have no way to represent such quasi-constant
8591 values in Dwarf, so for now we just punt and generate nothing. */
8595 /* No other kinds of rtx should be possible here. */
8602 rtl_for_decl_location (decl)
8607 /* Here we have to decide where we are going to say the parameter "lives"
8608 (as far as the debugger is concerned). We only have a couple of
8609 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8611 DECL_RTL normally indicates where the parameter lives during most of the
8612 activation of the function. If optimization is enabled however, this
8613 could be either NULL or else a pseudo-reg. Both of those cases indicate
8614 that the parameter doesn't really live anywhere (as far as the code
8615 generation parts of GCC are concerned) during most of the function's
8616 activation. That will happen (for example) if the parameter is never
8617 referenced within the function.
8619 We could just generate a location descriptor here for all non-NULL
8620 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8621 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8622 where DECL_RTL is NULL or is a pseudo-reg.
8624 Note however that we can only get away with using DECL_INCOMING_RTL as
8625 a backup substitute for DECL_RTL in certain limited cases. In cases
8626 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8627 we can be sure that the parameter was passed using the same type as it is
8628 declared to have within the function, and that its DECL_INCOMING_RTL
8629 points us to a place where a value of that type is passed.
8631 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8632 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8633 because in these cases DECL_INCOMING_RTL points us to a value of some
8634 type which is *different* from the type of the parameter itself. Thus,
8635 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8636 such cases, the debugger would end up (for example) trying to fetch a
8637 `float' from a place which actually contains the first part of a
8638 `double'. That would lead to really incorrect and confusing
8639 output at debug-time.
8641 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8642 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8643 are a couple of exceptions however. On little-endian machines we can
8644 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8645 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8646 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8647 when (on a little-endian machine) a non-prototyped function has a
8648 parameter declared to be of type `short' or `char'. In such cases,
8649 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8650 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8651 passed `int' value. If the debugger then uses that address to fetch
8652 a `short' or a `char' (on a little-endian machine) the result will be
8653 the correct data, so we allow for such exceptional cases below.
8655 Note that our goal here is to describe the place where the given formal
8656 parameter lives during most of the function's activation (i.e. between
8657 the end of the prologue and the start of the epilogue). We'll do that
8658 as best as we can. Note however that if the given formal parameter is
8659 modified sometime during the execution of the function, then a stack
8660 backtrace (at debug-time) will show the function as having been
8661 called with the *new* value rather than the value which was
8662 originally passed in. This happens rarely enough that it is not
8663 a major problem, but it *is* a problem, and I'd like to fix it.
8665 A future version of dwarf2out.c may generate two additional
8666 attributes for any given DW_TAG_formal_parameter DIE which will
8667 describe the "passed type" and the "passed location" for the
8668 given formal parameter in addition to the attributes we now
8669 generate to indicate the "declared type" and the "active
8670 location" for each parameter. This additional set of attributes
8671 could be used by debuggers for stack backtraces. Separately, note
8672 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8673 NULL also. This happens (for example) for inlined-instances of
8674 inline function formal parameters which are never referenced.
8675 This really shouldn't be happening. All PARM_DECL nodes should
8676 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8677 doesn't currently generate these values for inlined instances of
8678 inline function parameters, so when we see such cases, we are
8679 just out-of-luck for the time being (until integrate.c
8682 /* Use DECL_RTL as the "location" unless we find something better. */
8683 rtl = DECL_RTL_IF_SET (decl);
8685 if (TREE_CODE (decl) == PARM_DECL)
8687 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8689 tree declared_type = type_main_variant (TREE_TYPE (decl));
8690 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8692 /* This decl represents a formal parameter which was optimized out.
8693 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8694 all* cases where (rtl == NULL_RTX) just below. */
8695 if (declared_type == passed_type)
8696 rtl = DECL_INCOMING_RTL (decl);
8697 else if (! BYTES_BIG_ENDIAN
8698 && TREE_CODE (declared_type) == INTEGER_TYPE
8699 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8700 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8701 rtl = DECL_INCOMING_RTL (decl);
8704 /* If the parm was passed in registers, but lives on the stack, then
8705 make a big endian correction if the mode of the type of the
8706 parameter is not the same as the mode of the rtl. */
8707 /* ??? This is the same series of checks that are made in dbxout.c before
8708 we reach the big endian correction code there. It isn't clear if all
8709 of these checks are necessary here, but keeping them all is the safe
8711 else if (GET_CODE (rtl) == MEM
8712 && XEXP (rtl, 0) != const0_rtx
8713 && ! CONSTANT_P (XEXP (rtl, 0))
8714 /* Not passed in memory. */
8715 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8716 /* Not passed by invisible reference. */
8717 && (GET_CODE (XEXP (rtl, 0)) != REG
8718 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8719 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8720 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8721 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8724 /* Big endian correction check. */
8726 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8727 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8730 int offset = (UNITS_PER_WORD
8731 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8732 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8733 plus_constant (XEXP (rtl, 0), offset));
8737 if (rtl != NULL_RTX)
8739 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8740 #ifdef LEAF_REG_REMAP
8741 if (current_function_uses_only_leaf_regs)
8742 leaf_renumber_regs_insn (rtl);
8746 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time
8747 constant, and will have been substituted directly into all
8748 expressions that use it. C does not have such a concept, but
8749 C++ and other languages do. */
8750 else if (DECL_INITIAL (decl))
8752 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
8753 EXPAND_INITIALIZER);
8759 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8760 data attribute for a variable or a parameter. We generate the
8761 DW_AT_const_value attribute only in those cases where the given variable
8762 or parameter does not have a true "location" either in memory or in a
8763 register. This can happen (for example) when a constant is passed as an
8764 actual argument in a call to an inline function. (It's possible that
8765 these things can crop up in other ways also.) Note that one type of
8766 constant value which can be passed into an inlined function is a constant
8767 pointer. This can happen for example if an actual argument in an inlined
8768 function call evaluates to a compile-time constant address. */
8771 add_location_or_const_value_attribute (die, decl)
8777 if (TREE_CODE (decl) == ERROR_MARK)
8780 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8783 rtl = rtl_for_decl_location (decl);
8784 if (rtl == NULL_RTX)
8787 /* If we don't look past the constant pool, we risk emitting a
8788 reference to a constant pool entry that isn't referenced from
8789 code, and thus is not emitted. */
8790 rtl = avoid_constant_pool_reference (rtl);
8792 switch (GET_CODE (rtl))
8795 /* The address of a variable that was optimized away; don't emit
8806 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8807 add_const_value_attribute (die, rtl);
8814 add_AT_location_description (die, DW_AT_location, rtl);
8822 /* If we don't have a copy of this variable in memory for some reason (such
8823 as a C++ member constant that doesn't have an out-of-line definition),
8824 we should tell the debugger about the constant value. */
8827 tree_add_const_value_attribute (var_die, decl)
8831 tree init = DECL_INITIAL (decl);
8832 tree type = TREE_TYPE (decl);
8834 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8835 && initializer_constant_valid_p (init, type) == null_pointer_node)
8840 switch (TREE_CODE (type))
8843 if (host_integerp (init, 0))
8844 add_AT_unsigned (var_die, DW_AT_const_value,
8845 TREE_INT_CST_LOW (init));
8847 add_AT_long_long (var_die, DW_AT_const_value,
8848 TREE_INT_CST_HIGH (init),
8849 TREE_INT_CST_LOW (init));
8856 /* Generate an DW_AT_name attribute given some string value to be included as
8857 the value of the attribute. */
8860 add_name_attribute (die, name_string)
8862 const char *name_string;
8864 if (name_string != NULL && *name_string != 0)
8866 if (demangle_name_func)
8867 name_string = (*demangle_name_func) (name_string);
8869 add_AT_string (die, DW_AT_name, name_string);
8873 /* Given a tree node describing an array bound (either lower or upper) output
8874 a representation for that bound. */
8877 add_bound_info (subrange_die, bound_attr, bound)
8878 dw_die_ref subrange_die;
8879 enum dwarf_attribute bound_attr;
8882 switch (TREE_CODE (bound))
8887 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8889 if (! host_integerp (bound, 0)
8890 || (bound_attr == DW_AT_lower_bound
8891 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8892 || (is_fortran () && integer_onep (bound)))))
8893 /* use the default */
8896 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8901 case NON_LVALUE_EXPR:
8902 case VIEW_CONVERT_EXPR:
8903 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8907 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8908 access the upper bound values may be bogus. If they refer to a
8909 register, they may only describe how to get at these values at the
8910 points in the generated code right after they have just been
8911 computed. Worse yet, in the typical case, the upper bound values
8912 will not even *be* computed in the optimized code (though the
8913 number of elements will), so these SAVE_EXPRs are entirely
8914 bogus. In order to compensate for this fact, we check here to see
8915 if optimization is enabled, and if so, we don't add an attribute
8916 for the (unknown and unknowable) upper bound. This should not
8917 cause too much trouble for existing (stupid?) debuggers because
8918 they have to deal with empty upper bounds location descriptions
8919 anyway in order to be able to deal with incomplete array types.
8920 Of course an intelligent debugger (GDB?) should be able to
8921 comprehend that a missing upper bound specification in an array
8922 type used for a storage class `auto' local array variable
8923 indicates that the upper bound is both unknown (at compile- time)
8924 and unknowable (at run-time) due to optimization.
8926 We assume that a MEM rtx is safe because gcc wouldn't put the
8927 value there unless it was going to be used repeatedly in the
8928 function, i.e. for cleanups. */
8929 if (SAVE_EXPR_RTL (bound)
8930 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8932 dw_die_ref ctx = lookup_decl_die (current_function_decl);
8933 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8934 rtx loc = SAVE_EXPR_RTL (bound);
8936 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8937 it references an outer function's frame. */
8939 if (GET_CODE (loc) == MEM)
8941 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8943 if (XEXP (loc, 0) != new_addr)
8944 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8947 add_AT_flag (decl_die, DW_AT_artificial, 1);
8948 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8949 add_AT_location_description (decl_die, DW_AT_location, loc);
8950 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8953 /* Else leave out the attribute. */
8959 dw_die_ref decl_die = lookup_decl_die (bound);
8961 /* ??? Can this happen, or should the variable have been bound
8962 first? Probably it can, since I imagine that we try to create
8963 the types of parameters in the order in which they exist in
8964 the list, and won't have created a forward reference to a
8966 if (decl_die != NULL)
8967 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8973 /* Otherwise try to create a stack operation procedure to
8974 evaluate the value of the array bound. */
8976 dw_die_ref ctx, decl_die;
8977 dw_loc_descr_ref loc;
8979 loc = loc_descriptor_from_tree (bound, 0);
8983 if (current_function_decl == 0)
8984 ctx = comp_unit_die;
8986 ctx = lookup_decl_die (current_function_decl);
8988 decl_die = new_die (DW_TAG_variable, ctx);
8989 add_AT_flag (decl_die, DW_AT_artificial, 1);
8990 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8991 add_AT_loc (decl_die, DW_AT_location, loc);
8993 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8999 /* Note that the block of subscript information for an array type also
9000 includes information about the element type of type given array type. */
9003 add_subscript_info (type_die, type)
9004 dw_die_ref type_die;
9007 #ifndef MIPS_DEBUGGING_INFO
9008 unsigned dimension_number;
9011 dw_die_ref subrange_die;
9013 /* The GNU compilers represent multidimensional array types as sequences of
9014 one dimensional array types whose element types are themselves array
9015 types. Here we squish that down, so that each multidimensional array
9016 type gets only one array_type DIE in the Dwarf debugging info. The draft
9017 Dwarf specification say that we are allowed to do this kind of
9018 compression in C (because there is no difference between an array or
9019 arrays and a multidimensional array in C) but for other source languages
9020 (e.g. Ada) we probably shouldn't do this. */
9022 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9023 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9024 We work around this by disabling this feature. See also
9025 gen_array_type_die. */
9026 #ifndef MIPS_DEBUGGING_INFO
9027 for (dimension_number = 0;
9028 TREE_CODE (type) == ARRAY_TYPE;
9029 type = TREE_TYPE (type), dimension_number++)
9032 tree domain = TYPE_DOMAIN (type);
9034 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9035 and (in GNU C only) variable bounds. Handle all three forms
9037 subrange_die = new_die (DW_TAG_subrange_type, type_die);
9040 /* We have an array type with specified bounds. */
9041 lower = TYPE_MIN_VALUE (domain);
9042 upper = TYPE_MAX_VALUE (domain);
9044 /* define the index type. */
9045 if (TREE_TYPE (domain))
9047 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9048 TREE_TYPE field. We can't emit debug info for this
9049 because it is an unnamed integral type. */
9050 if (TREE_CODE (domain) == INTEGER_TYPE
9051 && TYPE_NAME (domain) == NULL_TREE
9052 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9053 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9056 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9060 /* ??? If upper is NULL, the array has unspecified length,
9061 but it does have a lower bound. This happens with Fortran
9063 Since the debugger is definitely going to need to know N
9064 to produce useful results, go ahead and output the lower
9065 bound solo, and hope the debugger can cope. */
9067 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9069 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9072 /* We have an array type with an unspecified length. The DWARF-2
9073 spec does not say how to handle this; let's just leave out the
9077 #ifndef MIPS_DEBUGGING_INFO
9083 add_byte_size_attribute (die, tree_node)
9089 switch (TREE_CODE (tree_node))
9097 case QUAL_UNION_TYPE:
9098 size = int_size_in_bytes (tree_node);
9101 /* For a data member of a struct or union, the DW_AT_byte_size is
9102 generally given as the number of bytes normally allocated for an
9103 object of the *declared* type of the member itself. This is true
9104 even for bit-fields. */
9105 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9111 /* Note that `size' might be -1 when we get to this point. If it is, that
9112 indicates that the byte size of the entity in question is variable. We
9113 have no good way of expressing this fact in Dwarf at the present time,
9114 so just let the -1 pass on through. */
9116 add_AT_unsigned (die, DW_AT_byte_size, size);
9119 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9120 which specifies the distance in bits from the highest order bit of the
9121 "containing object" for the bit-field to the highest order bit of the
9124 For any given bit-field, the "containing object" is a hypothetical
9125 object (of some integral or enum type) within which the given bit-field
9126 lives. The type of this hypothetical "containing object" is always the
9127 same as the declared type of the individual bit-field itself. The
9128 determination of the exact location of the "containing object" for a
9129 bit-field is rather complicated. It's handled by the
9130 `field_byte_offset' function (above).
9132 Note that it is the size (in bytes) of the hypothetical "containing object"
9133 which will be given in the DW_AT_byte_size attribute for this bit-field.
9134 (See `byte_size_attribute' above). */
9137 add_bit_offset_attribute (die, decl)
9141 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9142 tree type = DECL_BIT_FIELD_TYPE (decl);
9143 HOST_WIDE_INT bitpos_int;
9144 HOST_WIDE_INT highest_order_object_bit_offset;
9145 HOST_WIDE_INT highest_order_field_bit_offset;
9146 HOST_WIDE_INT unsigned bit_offset;
9148 /* Must be a field and a bit field. */
9150 || TREE_CODE (decl) != FIELD_DECL)
9153 /* We can't yet handle bit-fields whose offsets are variable, so if we
9154 encounter such things, just return without generating any attribute
9155 whatsoever. Likewise for variable or too large size. */
9156 if (! host_integerp (bit_position (decl), 0)
9157 || ! host_integerp (DECL_SIZE (decl), 1))
9160 bitpos_int = int_bit_position (decl);
9162 /* Note that the bit offset is always the distance (in bits) from the
9163 highest-order bit of the "containing object" to the highest-order bit of
9164 the bit-field itself. Since the "high-order end" of any object or field
9165 is different on big-endian and little-endian machines, the computation
9166 below must take account of these differences. */
9167 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9168 highest_order_field_bit_offset = bitpos_int;
9170 if (! BYTES_BIG_ENDIAN)
9172 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9173 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9177 = (! BYTES_BIG_ENDIAN
9178 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9179 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9181 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9184 /* For a FIELD_DECL node which represents a bit field, output an attribute
9185 which specifies the length in bits of the given field. */
9188 add_bit_size_attribute (die, decl)
9192 /* Must be a field and a bit field. */
9193 if (TREE_CODE (decl) != FIELD_DECL
9194 || ! DECL_BIT_FIELD_TYPE (decl))
9197 if (host_integerp (DECL_SIZE (decl), 1))
9198 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9201 /* If the compiled language is ANSI C, then add a 'prototyped'
9202 attribute, if arg types are given for the parameters of a function. */
9205 add_prototyped_attribute (die, func_type)
9209 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9210 && TYPE_ARG_TYPES (func_type) != NULL)
9211 add_AT_flag (die, DW_AT_prototyped, 1);
9214 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9215 by looking in either the type declaration or object declaration
9219 add_abstract_origin_attribute (die, origin)
9223 dw_die_ref origin_die = NULL;
9225 if (TREE_CODE (origin) != FUNCTION_DECL)
9227 /* We may have gotten separated from the block for the inlined
9228 function, if we're in an exception handler or some such; make
9229 sure that the abstract function has been written out.
9231 Doing this for nested functions is wrong, however; functions are
9232 distinct units, and our context might not even be inline. */
9235 fn = TYPE_STUB_DECL (fn);
9236 fn = decl_function_context (fn);
9238 dwarf2out_abstract_function (fn);
9241 if (DECL_P (origin))
9242 origin_die = lookup_decl_die (origin);
9243 else if (TYPE_P (origin))
9244 origin_die = lookup_type_die (origin);
9246 if (origin_die == NULL)
9249 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9252 /* We do not currently support the pure_virtual attribute. */
9255 add_pure_or_virtual_attribute (die, func_decl)
9259 if (DECL_VINDEX (func_decl))
9261 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9263 if (host_integerp (DECL_VINDEX (func_decl), 0))
9264 add_AT_loc (die, DW_AT_vtable_elem_location,
9265 new_loc_descr (DW_OP_constu,
9266 tree_low_cst (DECL_VINDEX (func_decl), 0),
9269 /* GNU extension: Record what type this method came from originally. */
9270 if (debug_info_level > DINFO_LEVEL_TERSE)
9271 add_AT_die_ref (die, DW_AT_containing_type,
9272 lookup_type_die (DECL_CONTEXT (func_decl)));
9276 /* Add source coordinate attributes for the given decl. */
9279 add_src_coords_attributes (die, decl)
9283 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9285 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9286 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9289 /* Add an DW_AT_name attribute and source coordinate attribute for the
9290 given decl, but only if it actually has a name. */
9293 add_name_and_src_coords_attributes (die, decl)
9299 decl_name = DECL_NAME (decl);
9300 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9302 add_name_attribute (die, dwarf2_name (decl, 0));
9303 if (! DECL_ARTIFICIAL (decl))
9304 add_src_coords_attributes (die, decl);
9306 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9307 && TREE_PUBLIC (decl)
9308 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9309 && !DECL_ABSTRACT (decl))
9310 add_AT_string (die, DW_AT_MIPS_linkage_name,
9311 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9315 /* Push a new declaration scope. */
9318 push_decl_scope (scope)
9321 VARRAY_PUSH_TREE (decl_scope_table, scope);
9324 /* Pop a declaration scope. */
9328 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9330 VARRAY_POP (decl_scope_table);
9333 /* Return the DIE for the scope that immediately contains this type.
9334 Non-named types get global scope. Named types nested in other
9335 types get their containing scope if it's open, or global scope
9336 otherwise. All other types (i.e. function-local named types) get
9337 the current active scope. */
9340 scope_die_for (t, context_die)
9342 dw_die_ref context_die;
9344 dw_die_ref scope_die = NULL;
9345 tree containing_scope;
9348 /* Non-types always go in the current scope. */
9352 containing_scope = TYPE_CONTEXT (t);
9354 /* Ignore namespaces for the moment. */
9355 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9356 containing_scope = NULL_TREE;
9358 /* Ignore function type "scopes" from the C frontend. They mean that
9359 a tagged type is local to a parmlist of a function declarator, but
9360 that isn't useful to DWARF. */
9361 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9362 containing_scope = NULL_TREE;
9364 if (containing_scope == NULL_TREE)
9365 scope_die = comp_unit_die;
9366 else if (TYPE_P (containing_scope))
9368 /* For types, we can just look up the appropriate DIE. But
9369 first we check to see if we're in the middle of emitting it
9370 so we know where the new DIE should go. */
9372 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9373 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
9378 if (debug_info_level > DINFO_LEVEL_TERSE
9379 && !TREE_ASM_WRITTEN (containing_scope))
9382 /* If none of the current dies are suitable, we get file scope. */
9383 scope_die = comp_unit_die;
9386 scope_die = lookup_type_die (containing_scope);
9389 scope_die = context_die;
9394 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9396 static inline int local_scope_p PARAMS ((dw_die_ref));
9398 local_scope_p (context_die)
9399 dw_die_ref context_die;
9401 for (; context_die; context_die = context_die->die_parent)
9402 if (context_die->die_tag == DW_TAG_inlined_subroutine
9403 || context_die->die_tag == DW_TAG_subprogram)
9408 /* Returns nonzero iff CONTEXT_DIE is a class. */
9410 static inline int class_scope_p PARAMS ((dw_die_ref));
9412 class_scope_p (context_die)
9413 dw_die_ref context_die;
9416 && (context_die->die_tag == DW_TAG_structure_type
9417 || context_die->die_tag == DW_TAG_union_type));
9420 /* Many forms of DIEs require a "type description" attribute. This
9421 routine locates the proper "type descriptor" die for the type given
9422 by 'type', and adds an DW_AT_type attribute below the given die. */
9425 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9426 dw_die_ref object_die;
9430 dw_die_ref context_die;
9432 enum tree_code code = TREE_CODE (type);
9433 dw_die_ref type_die = NULL;
9435 /* ??? If this type is an unnamed subrange type of an integral or
9436 floating-point type, use the inner type. This is because we have no
9437 support for unnamed types in base_type_die. This can happen if this is
9438 an Ada subrange type. Correct solution is emit a subrange type die. */
9439 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9440 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9441 type = TREE_TYPE (type), code = TREE_CODE (type);
9443 if (code == ERROR_MARK)
9446 /* Handle a special case. For functions whose return type is void, we
9447 generate *no* type attribute. (Note that no object may have type
9448 `void', so this only applies to function return types). */
9449 if (code == VOID_TYPE)
9452 type_die = modified_type_die (type,
9453 decl_const || TYPE_READONLY (type),
9454 decl_volatile || TYPE_VOLATILE (type),
9456 if (type_die != NULL)
9457 add_AT_die_ref (object_die, DW_AT_type, type_die);
9460 /* Given a tree pointer to a struct, class, union, or enum type node, return
9461 a pointer to the (string) tag name for the given type, or zero if the type
9462 was declared without a tag. */
9468 const char *name = 0;
9470 if (TYPE_NAME (type) != 0)
9474 /* Find the IDENTIFIER_NODE for the type name. */
9475 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9476 t = TYPE_NAME (type);
9478 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9479 a TYPE_DECL node, regardless of whether or not a `typedef' was
9481 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9482 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9483 t = DECL_NAME (TYPE_NAME (type));
9485 /* Now get the name as a string, or invent one. */
9487 name = IDENTIFIER_POINTER (t);
9490 return (name == 0 || *name == '\0') ? 0 : name;
9493 /* Return the type associated with a data member, make a special check
9494 for bit field types. */
9497 member_declared_type (member)
9500 return (DECL_BIT_FIELD_TYPE (member)
9501 ? DECL_BIT_FIELD_TYPE (member)
9502 : TREE_TYPE (member));
9505 /* Get the decl's label, as described by its RTL. This may be different
9506 from the DECL_NAME name used in the source file. */
9510 decl_start_label (decl)
9515 x = DECL_RTL (decl);
9516 if (GET_CODE (x) != MEM)
9520 if (GET_CODE (x) != SYMBOL_REF)
9523 fnname = XSTR (x, 0);
9528 /* These routines generate the internal representation of the DIE's for
9529 the compilation unit. Debugging information is collected by walking
9530 the declaration trees passed in from dwarf2out_decl(). */
9533 gen_array_type_die (type, context_die)
9535 dw_die_ref context_die;
9537 dw_die_ref scope_die = scope_die_for (type, context_die);
9538 dw_die_ref array_die;
9541 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9542 the inner array type comes before the outer array type. Thus we must
9543 call gen_type_die before we call new_die. See below also. */
9544 #ifdef MIPS_DEBUGGING_INFO
9545 gen_type_die (TREE_TYPE (type), context_die);
9548 array_die = new_die (DW_TAG_array_type, scope_die);
9551 /* We default the array ordering. SDB will probably do
9552 the right things even if DW_AT_ordering is not present. It's not even
9553 an issue until we start to get into multidimensional arrays anyway. If
9554 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9555 then we'll have to put the DW_AT_ordering attribute back in. (But if
9556 and when we find out that we need to put these in, we will only do so
9557 for multidimensional arrays. */
9558 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9561 #ifdef MIPS_DEBUGGING_INFO
9562 /* The SGI compilers handle arrays of unknown bound by setting
9563 AT_declaration and not emitting any subrange DIEs. */
9564 if (! TYPE_DOMAIN (type))
9565 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9568 add_subscript_info (array_die, type);
9570 add_name_attribute (array_die, type_tag (type));
9571 equate_type_number_to_die (type, array_die);
9573 /* Add representation of the type of the elements of this array type. */
9574 element_type = TREE_TYPE (type);
9576 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9577 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9578 We work around this by disabling this feature. See also
9579 add_subscript_info. */
9580 #ifndef MIPS_DEBUGGING_INFO
9581 while (TREE_CODE (element_type) == ARRAY_TYPE)
9582 element_type = TREE_TYPE (element_type);
9584 gen_type_die (element_type, context_die);
9587 add_type_attribute (array_die, element_type, 0, 0, context_die);
9591 gen_set_type_die (type, context_die)
9593 dw_die_ref context_die;
9596 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9598 equate_type_number_to_die (type, type_die);
9599 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9604 gen_entry_point_die (decl, context_die)
9606 dw_die_ref context_die;
9608 tree origin = decl_ultimate_origin (decl);
9609 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9611 add_abstract_origin_attribute (decl_die, origin);
9614 add_name_and_src_coords_attributes (decl_die, decl);
9615 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9619 if (DECL_ABSTRACT (decl))
9620 equate_decl_number_to_die (decl, decl_die);
9622 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9626 /* Remember a type in the incomplete_types_list. */
9628 add_incomplete_type (type)
9631 VARRAY_PUSH_TREE (incomplete_types, type);
9634 /* Walk through the list of incomplete types again, trying once more to
9635 emit full debugging info for them. */
9638 retry_incomplete_types ()
9641 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
9643 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
9647 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9650 gen_inlined_enumeration_type_die (type, context_die)
9652 dw_die_ref context_die;
9654 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die);
9655 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9656 be incomplete and such types are not marked. */
9657 add_abstract_origin_attribute (type_die, type);
9660 /* Generate a DIE to represent an inlined instance of a structure type. */
9663 gen_inlined_structure_type_die (type, context_die)
9665 dw_die_ref context_die;
9667 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9669 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9670 be incomplete and such types are not marked. */
9671 add_abstract_origin_attribute (type_die, type);
9674 /* Generate a DIE to represent an inlined instance of a union type. */
9677 gen_inlined_union_type_die (type, context_die)
9679 dw_die_ref context_die;
9681 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9683 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9684 be incomplete and such types are not marked. */
9685 add_abstract_origin_attribute (type_die, type);
9688 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9689 include all of the information about the enumeration values also. Each
9690 enumerated type name/value is listed as a child of the enumerated type
9694 gen_enumeration_type_die (type, context_die)
9696 dw_die_ref context_die;
9698 dw_die_ref type_die = lookup_type_die (type);
9700 if (type_die == NULL)
9702 type_die = new_die (DW_TAG_enumeration_type,
9703 scope_die_for (type, context_die));
9704 equate_type_number_to_die (type, type_die);
9705 add_name_attribute (type_die, type_tag (type));
9707 else if (! TYPE_SIZE (type))
9710 remove_AT (type_die, DW_AT_declaration);
9712 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9713 given enum type is incomplete, do not generate the DW_AT_byte_size
9714 attribute or the DW_AT_element_list attribute. */
9715 if (TYPE_SIZE (type))
9719 TREE_ASM_WRITTEN (type) = 1;
9720 add_byte_size_attribute (type_die, type);
9721 if (TYPE_STUB_DECL (type) != NULL_TREE)
9722 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9724 /* If the first reference to this type was as the return type of an
9725 inline function, then it may not have a parent. Fix this now. */
9726 if (type_die->die_parent == NULL)
9727 add_child_die (scope_die_for (type, context_die), type_die);
9729 for (link = TYPE_FIELDS (type);
9730 link != NULL; link = TREE_CHAIN (link))
9732 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9734 add_name_attribute (enum_die,
9735 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9737 if (host_integerp (TREE_VALUE (link), 0))
9739 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9740 add_AT_int (enum_die, DW_AT_const_value,
9741 tree_low_cst (TREE_VALUE (link), 0));
9743 add_AT_unsigned (enum_die, DW_AT_const_value,
9744 tree_low_cst (TREE_VALUE (link), 0));
9749 add_AT_flag (type_die, DW_AT_declaration, 1);
9752 /* Generate a DIE to represent either a real live formal parameter decl or to
9753 represent just the type of some formal parameter position in some function
9756 Note that this routine is a bit unusual because its argument may be a
9757 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9758 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9759 node. If it's the former then this function is being called to output a
9760 DIE to represent a formal parameter object (or some inlining thereof). If
9761 it's the latter, then this function is only being called to output a
9762 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9763 argument type of some subprogram type. */
9766 gen_formal_parameter_die (node, context_die)
9768 dw_die_ref context_die;
9771 = new_die (DW_TAG_formal_parameter, context_die);
9774 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9777 origin = decl_ultimate_origin (node);
9779 add_abstract_origin_attribute (parm_die, origin);
9782 add_name_and_src_coords_attributes (parm_die, node);
9783 add_type_attribute (parm_die, TREE_TYPE (node),
9784 TREE_READONLY (node),
9785 TREE_THIS_VOLATILE (node),
9787 if (DECL_ARTIFICIAL (node))
9788 add_AT_flag (parm_die, DW_AT_artificial, 1);
9791 equate_decl_number_to_die (node, parm_die);
9792 if (! DECL_ABSTRACT (node))
9793 add_location_or_const_value_attribute (parm_die, node);
9798 /* We were called with some kind of a ..._TYPE node. */
9799 add_type_attribute (parm_die, node, 0, 0, context_die);
9809 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9810 at the end of an (ANSI prototyped) formal parameters list. */
9813 gen_unspecified_parameters_die (decl_or_type, context_die)
9814 tree decl_or_type ATTRIBUTE_UNUSED;
9815 dw_die_ref context_die;
9817 new_die (DW_TAG_unspecified_parameters, context_die);
9820 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9821 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9822 parameters as specified in some function type specification (except for
9823 those which appear as part of a function *definition*). */
9826 gen_formal_types_die (function_or_method_type, context_die)
9827 tree function_or_method_type;
9828 dw_die_ref context_die;
9831 tree formal_type = NULL;
9832 tree first_parm_type;
9835 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9837 arg = DECL_ARGUMENTS (function_or_method_type);
9838 function_or_method_type = TREE_TYPE (function_or_method_type);
9843 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9845 /* Make our first pass over the list of formal parameter types and output a
9846 DW_TAG_formal_parameter DIE for each one. */
9847 for (link = first_parm_type; link; )
9849 dw_die_ref parm_die;
9851 formal_type = TREE_VALUE (link);
9852 if (formal_type == void_type_node)
9855 /* Output a (nameless) DIE to represent the formal parameter itself. */
9856 parm_die = gen_formal_parameter_die (formal_type, context_die);
9857 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9858 && link == first_parm_type)
9859 || (arg && DECL_ARTIFICIAL (arg)))
9860 add_AT_flag (parm_die, DW_AT_artificial, 1);
9862 link = TREE_CHAIN (link);
9864 arg = TREE_CHAIN (arg);
9867 /* If this function type has an ellipsis, add a
9868 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9869 if (formal_type != void_type_node)
9870 gen_unspecified_parameters_die (function_or_method_type, context_die);
9872 /* Make our second (and final) pass over the list of formal parameter types
9873 and output DIEs to represent those types (as necessary). */
9874 for (link = TYPE_ARG_TYPES (function_or_method_type);
9876 link = TREE_CHAIN (link))
9878 formal_type = TREE_VALUE (link);
9879 if (formal_type == void_type_node)
9882 gen_type_die (formal_type, context_die);
9886 /* We want to generate the DIE for TYPE so that we can generate the
9887 die for MEMBER, which has been defined; we will need to refer back
9888 to the member declaration nested within TYPE. If we're trying to
9889 generate minimal debug info for TYPE, processing TYPE won't do the
9890 trick; we need to attach the member declaration by hand. */
9893 gen_type_die_for_member (type, member, context_die)
9895 dw_die_ref context_die;
9897 gen_type_die (type, context_die);
9899 /* If we're trying to avoid duplicate debug info, we may not have
9900 emitted the member decl for this function. Emit it now. */
9901 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9902 && ! lookup_decl_die (member))
9904 if (decl_ultimate_origin (member))
9907 push_decl_scope (type);
9908 if (TREE_CODE (member) == FUNCTION_DECL)
9909 gen_subprogram_die (member, lookup_type_die (type));
9911 gen_variable_die (member, lookup_type_die (type));
9916 /* Generate the DWARF2 info for the "abstract" instance
9917 of a function which we may later generate inlined and/or
9918 out-of-line instances of. */
9921 dwarf2out_abstract_function (decl)
9927 int was_abstract = DECL_ABSTRACT (decl);
9929 /* Make sure we have the actual abstract inline, not a clone. */
9930 decl = DECL_ORIGIN (decl);
9932 old_die = lookup_decl_die (decl);
9933 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9934 /* We've already generated the abstract instance. */
9937 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9938 we don't get confused by DECL_ABSTRACT. */
9939 if (debug_info_level > DINFO_LEVEL_TERSE)
9941 context = decl_class_context (decl);
9943 gen_type_die_for_member
9944 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9947 /* Pretend we've just finished compiling this function. */
9948 save_fn = current_function_decl;
9949 current_function_decl = decl;
9951 set_decl_abstract_flags (decl, 1);
9952 dwarf2out_decl (decl);
9954 set_decl_abstract_flags (decl, 0);
9956 current_function_decl = save_fn;
9959 /* Generate a DIE to represent a declared function (either file-scope or
9963 gen_subprogram_die (decl, context_die)
9965 dw_die_ref context_die;
9967 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9968 tree origin = decl_ultimate_origin (decl);
9969 dw_die_ref subr_die;
9973 dw_die_ref old_die = lookup_decl_die (decl);
9974 int declaration = (current_function_decl != decl
9975 || class_scope_p (context_die));
9977 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9978 be true, if we started to generate the abstract instance of an inline,
9979 decided to output its containing class, and proceeded to emit the
9980 declaration of the inline from the member list for the class. In that
9981 case, `declaration' takes priority; we'll get back to the abstract
9982 instance when we're done with the class. */
9984 /* The class-scope declaration DIE must be the primary DIE. */
9985 if (origin && declaration && class_scope_p (context_die))
9994 if (declaration && ! local_scope_p (context_die))
9997 /* Fixup die_parent for the abstract instance of a nested
9999 if (old_die && old_die->die_parent == NULL)
10000 add_child_die (context_die, old_die);
10002 subr_die = new_die (DW_TAG_subprogram, context_die);
10003 add_abstract_origin_attribute (subr_die, origin);
10007 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10009 if (!get_AT_flag (old_die, DW_AT_declaration)
10010 /* We can have a normal definition following an inline one in the
10011 case of redefinition of GNU C extern inlines.
10012 It seems reasonable to use AT_specification in this case. */
10013 && !get_AT_unsigned (old_die, DW_AT_inline))
10015 /* ??? This can happen if there is a bug in the program, for
10016 instance, if it has duplicate function definitions. Ideally,
10017 we should detect this case and ignore it. For now, if we have
10018 already reported an error, any error at all, then assume that
10019 we got here because of an input error, not a dwarf2 bug. */
10025 /* If the definition comes from the same place as the declaration,
10026 maybe use the old DIE. We always want the DIE for this function
10027 that has the *_pc attributes to be under comp_unit_die so the
10028 debugger can find it. We also need to do this for abstract
10029 instances of inlines, since the spec requires the out-of-line copy
10030 to have the same parent. For local class methods, this doesn't
10031 apply; we just use the old DIE. */
10032 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10033 && (DECL_ARTIFICIAL (decl)
10034 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10035 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10036 == (unsigned) DECL_SOURCE_LINE (decl)))))
10038 subr_die = old_die;
10040 /* Clear out the declaration attribute and the parm types. */
10041 remove_AT (subr_die, DW_AT_declaration);
10042 remove_children (subr_die);
10046 subr_die = new_die (DW_TAG_subprogram, context_die);
10047 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10048 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10049 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10050 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10051 != (unsigned) DECL_SOURCE_LINE (decl))
10053 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10058 subr_die = new_die (DW_TAG_subprogram, context_die);
10060 if (TREE_PUBLIC (decl))
10061 add_AT_flag (subr_die, DW_AT_external, 1);
10063 add_name_and_src_coords_attributes (subr_die, decl);
10064 if (debug_info_level > DINFO_LEVEL_TERSE)
10066 tree type = TREE_TYPE (decl);
10068 add_prototyped_attribute (subr_die, type);
10069 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
10072 add_pure_or_virtual_attribute (subr_die, decl);
10073 if (DECL_ARTIFICIAL (decl))
10074 add_AT_flag (subr_die, DW_AT_artificial, 1);
10075 if (TREE_PROTECTED (decl))
10076 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10077 else if (TREE_PRIVATE (decl))
10078 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10083 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
10085 add_AT_flag (subr_die, DW_AT_declaration, 1);
10087 /* The first time we see a member function, it is in the context of
10088 the class to which it belongs. We make sure of this by emitting
10089 the class first. The next time is the definition, which is
10090 handled above. The two may come from the same source text. */
10091 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10092 equate_decl_number_to_die (decl, subr_die);
10095 else if (DECL_ABSTRACT (decl))
10097 if (DECL_INLINE (decl) && !flag_no_inline)
10099 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10100 inline functions, but not for extern inline functions.
10101 We can't get this completely correct because information
10102 about whether the function was declared inline is not
10104 if (DECL_DEFER_OUTPUT (decl))
10105 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10107 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10110 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10112 equate_decl_number_to_die (decl, subr_die);
10114 else if (!DECL_EXTERNAL (decl))
10116 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
10117 equate_decl_number_to_die (decl, subr_die);
10119 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10120 current_funcdef_number);
10121 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10122 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10123 current_funcdef_number);
10124 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10126 add_pubname (decl, subr_die);
10127 add_arange (decl, subr_die);
10129 #ifdef MIPS_DEBUGGING_INFO
10130 /* Add a reference to the FDE for this routine. */
10131 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10134 /* Define the "frame base" location for this routine. We use the
10135 frame pointer or stack pointer registers, since the RTL for local
10136 variables is relative to one of them. */
10138 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10139 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10142 /* ??? This fails for nested inline functions, because context_display
10143 is not part of the state saved/restored for inline functions. */
10144 if (current_function_needs_context)
10145 add_AT_location_description (subr_die, DW_AT_static_link,
10146 lookup_static_chain (decl));
10150 /* Now output descriptions of the arguments for this function. This gets
10151 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10152 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10153 `...' at the end of the formal parameter list. In order to find out if
10154 there was a trailing ellipsis or not, we must instead look at the type
10155 associated with the FUNCTION_DECL. This will be a node of type
10156 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10157 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10158 an ellipsis at the end. */
10160 /* In the case where we are describing a mere function declaration, all we
10161 need to do here (and all we *can* do here) is to describe the *types* of
10162 its formal parameters. */
10163 if (debug_info_level <= DINFO_LEVEL_TERSE)
10165 else if (declaration)
10166 gen_formal_types_die (decl, subr_die);
10169 /* Generate DIEs to represent all known formal parameters */
10170 tree arg_decls = DECL_ARGUMENTS (decl);
10173 /* When generating DIEs, generate the unspecified_parameters DIE
10174 instead if we come across the arg "__builtin_va_alist" */
10175 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10176 if (TREE_CODE (parm) == PARM_DECL)
10178 if (DECL_NAME (parm)
10179 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10180 "__builtin_va_alist"))
10181 gen_unspecified_parameters_die (parm, subr_die);
10183 gen_decl_die (parm, subr_die);
10186 /* Decide whether we need an unspecified_parameters DIE at the end.
10187 There are 2 more cases to do this for: 1) the ansi ... declaration -
10188 this is detectable when the end of the arg list is not a
10189 void_type_node 2) an unprototyped function declaration (not a
10190 definition). This just means that we have no info about the
10191 parameters at all. */
10192 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10193 if (fn_arg_types != NULL)
10195 /* this is the prototyped case, check for ... */
10196 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10197 gen_unspecified_parameters_die (decl, subr_die);
10199 else if (DECL_INITIAL (decl) == NULL_TREE)
10200 gen_unspecified_parameters_die (decl, subr_die);
10203 /* Output Dwarf info for all of the stuff within the body of the function
10204 (if it has one - it may be just a declaration). */
10205 outer_scope = DECL_INITIAL (decl);
10207 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
10208 node created to represent a function. This outermost BLOCK actually
10209 represents the outermost binding contour for the function, i.e. the
10210 contour in which the function's formal parameters and labels get
10211 declared. Curiously, it appears that the front end doesn't actually
10212 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
10213 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
10214 list for the function instead.) The BLOCK_VARS list for the
10215 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
10216 the function however, and we output DWARF info for those in
10217 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
10218 node representing the function's outermost pair of curly braces, and
10219 any blocks used for the base and member initializers of a C++
10220 constructor function. */
10221 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10223 current_function_has_inlines = 0;
10224 decls_for_scope (outer_scope, subr_die, 0);
10226 #if 0 && defined (MIPS_DEBUGGING_INFO)
10227 if (current_function_has_inlines)
10229 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10230 if (! comp_unit_has_inlines)
10232 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10233 comp_unit_has_inlines = 1;
10240 /* Generate a DIE to represent a declared data object. */
10243 gen_variable_die (decl, context_die)
10245 dw_die_ref context_die;
10247 tree origin = decl_ultimate_origin (decl);
10248 dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
10250 dw_die_ref old_die = lookup_decl_die (decl);
10251 int declaration = (DECL_EXTERNAL (decl)
10252 || class_scope_p (context_die));
10254 if (origin != NULL)
10255 add_abstract_origin_attribute (var_die, origin);
10256 /* Loop unrolling can create multiple blocks that refer to the same
10257 static variable, so we must test for the DW_AT_declaration flag. */
10258 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10259 copy decls and set the DECL_ABSTRACT flag on them instead of
10261 /* ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10262 else if (old_die && TREE_STATIC (decl)
10263 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10265 /* This is a definition of a C++ class level static. */
10266 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10267 if (DECL_NAME (decl))
10269 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10271 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10272 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10274 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10275 != (unsigned) DECL_SOURCE_LINE (decl))
10277 add_AT_unsigned (var_die, DW_AT_decl_line,
10278 DECL_SOURCE_LINE (decl));
10283 add_name_and_src_coords_attributes (var_die, decl);
10284 add_type_attribute (var_die, TREE_TYPE (decl),
10285 TREE_READONLY (decl),
10286 TREE_THIS_VOLATILE (decl), context_die);
10288 if (TREE_PUBLIC (decl))
10289 add_AT_flag (var_die, DW_AT_external, 1);
10291 if (DECL_ARTIFICIAL (decl))
10292 add_AT_flag (var_die, DW_AT_artificial, 1);
10294 if (TREE_PROTECTED (decl))
10295 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10297 else if (TREE_PRIVATE (decl))
10298 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10302 add_AT_flag (var_die, DW_AT_declaration, 1);
10304 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10305 equate_decl_number_to_die (decl, var_die);
10307 if (! declaration && ! DECL_ABSTRACT (decl))
10309 add_location_or_const_value_attribute (var_die, decl);
10310 add_pubname (decl, var_die);
10313 tree_add_const_value_attribute (var_die, decl);
10316 /* Generate a DIE to represent a label identifier. */
10319 gen_label_die (decl, context_die)
10321 dw_die_ref context_die;
10323 tree origin = decl_ultimate_origin (decl);
10324 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10326 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10328 if (origin != NULL)
10329 add_abstract_origin_attribute (lbl_die, origin);
10331 add_name_and_src_coords_attributes (lbl_die, decl);
10333 if (DECL_ABSTRACT (decl))
10334 equate_decl_number_to_die (decl, lbl_die);
10337 insn = DECL_RTL (decl);
10339 /* Deleted labels are programmer specified labels which have been
10340 eliminated because of various optimisations. We still emit them
10341 here so that it is possible to put breakpoints on them. */
10342 if (GET_CODE (insn) == CODE_LABEL
10343 || ((GET_CODE (insn) == NOTE
10344 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10346 /* When optimization is enabled (via -O) some parts of the compiler
10347 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10348 represent source-level labels which were explicitly declared by
10349 the user. This really shouldn't be happening though, so catch
10350 it if it ever does happen. */
10351 if (INSN_DELETED_P (insn))
10354 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10355 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10360 /* Generate a DIE for a lexical block. */
10363 gen_lexical_block_die (stmt, context_die, depth)
10365 dw_die_ref context_die;
10368 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10369 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10371 if (! BLOCK_ABSTRACT (stmt))
10373 if (BLOCK_FRAGMENT_CHAIN (stmt))
10377 add_AT_offset (stmt_die, DW_AT_ranges, add_ranges (stmt));
10379 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10382 add_ranges (chain);
10383 chain = BLOCK_FRAGMENT_CHAIN (chain);
10390 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10391 BLOCK_NUMBER (stmt));
10392 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10393 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10394 BLOCK_NUMBER (stmt));
10395 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10399 decls_for_scope (stmt, stmt_die, depth);
10402 /* Generate a DIE for an inlined subprogram. */
10405 gen_inlined_subroutine_die (stmt, context_die, depth)
10407 dw_die_ref context_die;
10410 if (! BLOCK_ABSTRACT (stmt))
10412 dw_die_ref subr_die
10413 = new_die (DW_TAG_inlined_subroutine, context_die);
10414 tree decl = block_ultimate_origin (stmt);
10415 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10417 /* Emit info for the abstract instance first, if we haven't yet. */
10418 dwarf2out_abstract_function (decl);
10420 add_abstract_origin_attribute (subr_die, decl);
10421 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10422 BLOCK_NUMBER (stmt));
10423 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10424 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10425 BLOCK_NUMBER (stmt));
10426 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10427 decls_for_scope (stmt, subr_die, depth);
10428 current_function_has_inlines = 1;
10432 /* Generate a DIE for a field in a record, or structure. */
10435 gen_field_die (decl, context_die)
10437 dw_die_ref context_die;
10439 dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10441 add_name_and_src_coords_attributes (decl_die, decl);
10442 add_type_attribute (decl_die, member_declared_type (decl),
10443 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10446 /* If this is a bit field... */
10447 if (DECL_BIT_FIELD_TYPE (decl))
10449 add_byte_size_attribute (decl_die, decl);
10450 add_bit_size_attribute (decl_die, decl);
10451 add_bit_offset_attribute (decl_die, decl);
10454 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10455 add_data_member_location_attribute (decl_die, decl);
10457 if (DECL_ARTIFICIAL (decl))
10458 add_AT_flag (decl_die, DW_AT_artificial, 1);
10460 if (TREE_PROTECTED (decl))
10461 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10463 else if (TREE_PRIVATE (decl))
10464 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10468 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10469 Use modified_type_die instead.
10470 We keep this code here just in case these types of DIEs may be needed to
10471 represent certain things in other languages (e.g. Pascal) someday. */
10473 gen_pointer_type_die (type, context_die)
10475 dw_die_ref context_die;
10478 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10480 equate_type_number_to_die (type, ptr_die);
10481 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10482 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10485 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10486 Use modified_type_die instead.
10487 We keep this code here just in case these types of DIEs may be needed to
10488 represent certain things in other languages (e.g. Pascal) someday. */
10490 gen_reference_type_die (type, context_die)
10492 dw_die_ref context_die;
10495 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10497 equate_type_number_to_die (type, ref_die);
10498 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10499 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10503 /* Generate a DIE for a pointer to a member type. */
10505 gen_ptr_to_mbr_type_die (type, context_die)
10507 dw_die_ref context_die;
10510 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10512 equate_type_number_to_die (type, ptr_die);
10513 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10514 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10515 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10518 /* Generate the DIE for the compilation unit. */
10521 gen_compile_unit_die (filename)
10522 const char *filename;
10525 char producer[250];
10526 const char *wd = getpwd ();
10527 const char *language_string = lang_hooks.name;
10530 die = new_die (DW_TAG_compile_unit, NULL);
10531 add_name_attribute (die, filename);
10533 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10534 add_AT_string (die, DW_AT_comp_dir, wd);
10536 sprintf (producer, "%s %s", language_string, version_string);
10538 #ifdef MIPS_DEBUGGING_INFO
10539 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10540 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10541 not appear in the producer string, the debugger reaches the conclusion
10542 that the object file is stripped and has no debugging information.
10543 To get the MIPS/SGI debugger to believe that there is debugging
10544 information in the object file, we add a -g to the producer string. */
10545 if (debug_info_level > DINFO_LEVEL_TERSE)
10546 strcat (producer, " -g");
10549 add_AT_string (die, DW_AT_producer, producer);
10551 if (strcmp (language_string, "GNU C++") == 0)
10552 language = DW_LANG_C_plus_plus;
10553 else if (strcmp (language_string, "GNU Ada") == 0)
10554 language = DW_LANG_Ada83;
10555 else if (strcmp (language_string, "GNU F77") == 0)
10556 language = DW_LANG_Fortran77;
10557 else if (strcmp (language_string, "GNU Pascal") == 0)
10558 language = DW_LANG_Pascal83;
10559 else if (strcmp (language_string, "GNU Java") == 0)
10560 language = DW_LANG_Java;
10561 else if (flag_traditional)
10562 language = DW_LANG_C;
10564 language = DW_LANG_C89;
10566 add_AT_unsigned (die, DW_AT_language, language);
10571 /* Generate a DIE for a string type. */
10574 gen_string_type_die (type, context_die)
10576 dw_die_ref context_die;
10578 dw_die_ref type_die
10579 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10581 equate_type_number_to_die (type, type_die);
10583 /* Fudge the string length attribute for now. */
10585 /* TODO: add string length info.
10586 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10587 bound_representation (upper_bound, 0, 'u'); */
10590 /* Generate the DIE for a base class. */
10593 gen_inheritance_die (binfo, context_die)
10595 dw_die_ref context_die;
10597 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10599 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10600 add_data_member_location_attribute (die, binfo);
10602 if (TREE_VIA_VIRTUAL (binfo))
10603 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10604 if (TREE_VIA_PUBLIC (binfo))
10605 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10606 else if (TREE_VIA_PROTECTED (binfo))
10607 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10610 /* Generate a DIE for a class member. */
10613 gen_member_die (type, context_die)
10615 dw_die_ref context_die;
10620 /* If this is not an incomplete type, output descriptions of each of its
10621 members. Note that as we output the DIEs necessary to represent the
10622 members of this record or union type, we will also be trying to output
10623 DIEs to represent the *types* of those members. However the `type'
10624 function (above) will specifically avoid generating type DIEs for member
10625 types *within* the list of member DIEs for this (containing) type except
10626 for those types (of members) which are explicitly marked as also being
10627 members of this (containing) type themselves. The g++ front- end can
10628 force any given type to be treated as a member of some other
10629 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10630 to point to the TREE node representing the appropriate (containing)
10633 /* First output info about the base classes. */
10634 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10636 tree bases = TYPE_BINFO_BASETYPES (type);
10637 int n_bases = TREE_VEC_LENGTH (bases);
10640 for (i = 0; i < n_bases; i++)
10641 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10644 /* Now output info about the data members and type members. */
10645 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10647 /* If we thought we were generating minimal debug info for TYPE
10648 and then changed our minds, some of the member declarations
10649 may have already been defined. Don't define them again, but
10650 do put them in the right order. */
10652 child = lookup_decl_die (member);
10654 splice_child_die (context_die, child);
10656 gen_decl_die (member, context_die);
10659 /* Now output info about the function members (if any). */
10660 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10662 /* Don't include clones in the member list. */
10663 if (DECL_ABSTRACT_ORIGIN (member))
10666 child = lookup_decl_die (member);
10668 splice_child_die (context_die, child);
10670 gen_decl_die (member, context_die);
10674 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10675 is set, we pretend that the type was never defined, so we only get the
10676 member DIEs needed by later specification DIEs. */
10679 gen_struct_or_union_type_die (type, context_die)
10681 dw_die_ref context_die;
10683 dw_die_ref type_die = lookup_type_die (type);
10684 dw_die_ref scope_die = 0;
10686 int complete = (TYPE_SIZE (type)
10687 && (! TYPE_STUB_DECL (type)
10688 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10690 if (type_die && ! complete)
10693 if (TYPE_CONTEXT (type) != NULL_TREE
10694 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10697 scope_die = scope_die_for (type, context_die);
10699 if (! type_die || (nested && scope_die == comp_unit_die))
10700 /* First occurrence of type or toplevel definition of nested class. */
10702 dw_die_ref old_die = type_die;
10704 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10705 ? DW_TAG_structure_type : DW_TAG_union_type,
10707 equate_type_number_to_die (type, type_die);
10709 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10711 add_name_attribute (type_die, type_tag (type));
10714 remove_AT (type_die, DW_AT_declaration);
10716 /* If this type has been completed, then give it a byte_size attribute and
10717 then give a list of members. */
10720 /* Prevent infinite recursion in cases where the type of some member of
10721 this type is expressed in terms of this type itself. */
10722 TREE_ASM_WRITTEN (type) = 1;
10723 add_byte_size_attribute (type_die, type);
10724 if (TYPE_STUB_DECL (type) != NULL_TREE)
10725 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10727 /* If the first reference to this type was as the return type of an
10728 inline function, then it may not have a parent. Fix this now. */
10729 if (type_die->die_parent == NULL)
10730 add_child_die (scope_die, type_die);
10732 push_decl_scope (type);
10733 gen_member_die (type, type_die);
10736 /* GNU extension: Record what type our vtable lives in. */
10737 if (TYPE_VFIELD (type))
10739 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10741 gen_type_die (vtype, context_die);
10742 add_AT_die_ref (type_die, DW_AT_containing_type,
10743 lookup_type_die (vtype));
10748 add_AT_flag (type_die, DW_AT_declaration, 1);
10750 /* We don't need to do this for function-local types. */
10751 if (! decl_function_context (TYPE_STUB_DECL (type)))
10752 add_incomplete_type (type);
10756 /* Generate a DIE for a subroutine _type_. */
10759 gen_subroutine_type_die (type, context_die)
10761 dw_die_ref context_die;
10763 tree return_type = TREE_TYPE (type);
10764 dw_die_ref subr_die
10765 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10767 equate_type_number_to_die (type, subr_die);
10768 add_prototyped_attribute (subr_die, type);
10769 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10770 gen_formal_types_die (type, subr_die);
10773 /* Generate a DIE for a type definition */
10776 gen_typedef_die (decl, context_die)
10778 dw_die_ref context_die;
10780 dw_die_ref type_die;
10783 if (TREE_ASM_WRITTEN (decl))
10785 TREE_ASM_WRITTEN (decl) = 1;
10787 type_die = new_die (DW_TAG_typedef, context_die);
10788 origin = decl_ultimate_origin (decl);
10789 if (origin != NULL)
10790 add_abstract_origin_attribute (type_die, origin);
10794 add_name_and_src_coords_attributes (type_die, decl);
10795 if (DECL_ORIGINAL_TYPE (decl))
10797 type = DECL_ORIGINAL_TYPE (decl);
10799 if (type == TREE_TYPE (decl))
10802 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10805 type = TREE_TYPE (decl);
10806 add_type_attribute (type_die, type, TREE_READONLY (decl),
10807 TREE_THIS_VOLATILE (decl), context_die);
10810 if (DECL_ABSTRACT (decl))
10811 equate_decl_number_to_die (decl, type_die);
10814 /* Generate a type description DIE. */
10817 gen_type_die (type, context_die)
10819 dw_die_ref context_die;
10823 if (type == NULL_TREE || type == error_mark_node)
10826 /* We are going to output a DIE to represent the unqualified version of
10827 this type (i.e. without any const or volatile qualifiers) so get the
10828 main variant (i.e. the unqualified version) of this type now. */
10829 type = type_main_variant (type);
10831 if (TREE_ASM_WRITTEN (type))
10834 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10835 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10837 TREE_ASM_WRITTEN (type) = 1;
10838 gen_decl_die (TYPE_NAME (type), context_die);
10842 switch (TREE_CODE (type))
10848 case REFERENCE_TYPE:
10849 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10850 ensures that the gen_type_die recursion will terminate even if the
10851 type is recursive. Recursive types are possible in Ada. */
10852 /* ??? We could perhaps do this for all types before the switch
10854 TREE_ASM_WRITTEN (type) = 1;
10856 /* For these types, all that is required is that we output a DIE (or a
10857 set of DIEs) to represent the "basis" type. */
10858 gen_type_die (TREE_TYPE (type), context_die);
10862 /* This code is used for C++ pointer-to-data-member types.
10863 Output a description of the relevant class type. */
10864 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10866 /* Output a description of the type of the object pointed to. */
10867 gen_type_die (TREE_TYPE (type), context_die);
10869 /* Now output a DIE to represent this pointer-to-data-member type
10871 gen_ptr_to_mbr_type_die (type, context_die);
10875 gen_type_die (TYPE_DOMAIN (type), context_die);
10876 gen_set_type_die (type, context_die);
10880 gen_type_die (TREE_TYPE (type), context_die);
10881 abort (); /* No way to represent these in Dwarf yet! */
10884 case FUNCTION_TYPE:
10885 /* Force out return type (in case it wasn't forced out already). */
10886 gen_type_die (TREE_TYPE (type), context_die);
10887 gen_subroutine_type_die (type, context_die);
10891 /* Force out return type (in case it wasn't forced out already). */
10892 gen_type_die (TREE_TYPE (type), context_die);
10893 gen_subroutine_type_die (type, context_die);
10897 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10899 gen_type_die (TREE_TYPE (type), context_die);
10900 gen_string_type_die (type, context_die);
10903 gen_array_type_die (type, context_die);
10907 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10910 case ENUMERAL_TYPE:
10913 case QUAL_UNION_TYPE:
10914 /* If this is a nested type whose containing class hasn't been
10915 written out yet, writing it out will cover this one, too.
10916 This does not apply to instantiations of member class templates;
10917 they need to be added to the containing class as they are
10918 generated. FIXME: This hurts the idea of combining type decls
10919 from multiple TUs, since we can't predict what set of template
10920 instantiations we'll get. */
10921 if (TYPE_CONTEXT (type)
10922 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10923 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10925 gen_type_die (TYPE_CONTEXT (type), context_die);
10927 if (TREE_ASM_WRITTEN (type))
10930 /* If that failed, attach ourselves to the stub. */
10931 push_decl_scope (TYPE_CONTEXT (type));
10932 context_die = lookup_type_die (TYPE_CONTEXT (type));
10938 if (TREE_CODE (type) == ENUMERAL_TYPE)
10939 gen_enumeration_type_die (type, context_die);
10941 gen_struct_or_union_type_die (type, context_die);
10946 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10947 it up if it is ever completed. gen_*_type_die will set it for us
10948 when appropriate. */
10957 /* No DIEs needed for fundamental types. */
10961 /* No Dwarf representation currently defined. */
10968 TREE_ASM_WRITTEN (type) = 1;
10971 /* Generate a DIE for a tagged type instantiation. */
10974 gen_tagged_type_instantiation_die (type, context_die)
10976 dw_die_ref context_die;
10978 if (type == NULL_TREE || type == error_mark_node)
10981 /* We are going to output a DIE to represent the unqualified version of
10982 this type (i.e. without any const or volatile qualifiers) so make sure
10983 that we have the main variant (i.e. the unqualified version) of this
10985 if (type != type_main_variant (type))
10988 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10989 an instance of an unresolved type. */
10991 switch (TREE_CODE (type))
10996 case ENUMERAL_TYPE:
10997 gen_inlined_enumeration_type_die (type, context_die);
11001 gen_inlined_structure_type_die (type, context_die);
11005 case QUAL_UNION_TYPE:
11006 gen_inlined_union_type_die (type, context_die);
11014 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11015 things which are local to the given block. */
11018 gen_block_die (stmt, context_die, depth)
11020 dw_die_ref context_die;
11023 int must_output_die = 0;
11026 enum tree_code origin_code;
11028 /* Ignore blocks never really used to make RTL. */
11029 if (stmt == NULL_TREE || !TREE_USED (stmt)
11030 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11033 /* If the block is one fragment of a non-contiguous block, do not
11034 process the variables, since they will have been done by the
11035 origin block. Do process subblocks. */
11036 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11040 for (sub= BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
11041 gen_block_die (sub, context_die, depth + 1);
11045 /* Determine the "ultimate origin" of this block. This block may be an
11046 inlined instance of an inlined instance of inline function, so we have
11047 to trace all of the way back through the origin chain to find out what
11048 sort of node actually served as the original seed for the creation of
11049 the current block. */
11050 origin = block_ultimate_origin (stmt);
11051 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11053 /* Determine if we need to output any Dwarf DIEs at all to represent this
11055 if (origin_code == FUNCTION_DECL)
11056 /* The outer scopes for inlinings *must* always be represented. We
11057 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11058 must_output_die = 1;
11061 /* In the case where the current block represents an inlining of the
11062 "body block" of an inline function, we must *NOT* output any DIE for
11063 this block because we have already output a DIE to represent the
11064 whole inlined function scope and the "body block" of any function
11065 doesn't really represent a different scope according to ANSI C
11066 rules. So we check here to make sure that this block does not
11067 represent a "body block inlining" before trying to set the
11068 `must_output_die' flag. */
11069 if (! is_body_block (origin ? origin : stmt))
11071 /* Determine if this block directly contains any "significant"
11072 local declarations which we will need to output DIEs for. */
11073 if (debug_info_level > DINFO_LEVEL_TERSE)
11074 /* We are not in terse mode so *any* local declaration counts
11075 as being a "significant" one. */
11076 must_output_die = (BLOCK_VARS (stmt) != NULL);
11078 /* We are in terse mode, so only local (nested) function
11079 definitions count as "significant" local declarations. */
11080 for (decl = BLOCK_VARS (stmt);
11081 decl != NULL; decl = TREE_CHAIN (decl))
11082 if (TREE_CODE (decl) == FUNCTION_DECL
11083 && DECL_INITIAL (decl))
11085 must_output_die = 1;
11091 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11092 DIE for any block which contains no significant local declarations at
11093 all. Rather, in such cases we just call `decls_for_scope' so that any
11094 needed Dwarf info for any sub-blocks will get properly generated. Note
11095 that in terse mode, our definition of what constitutes a "significant"
11096 local declaration gets restricted to include only inlined function
11097 instances and local (nested) function definitions. */
11098 if (must_output_die)
11100 if (origin_code == FUNCTION_DECL)
11101 gen_inlined_subroutine_die (stmt, context_die, depth);
11103 gen_lexical_block_die (stmt, context_die, depth);
11106 decls_for_scope (stmt, context_die, depth);
11109 /* Generate all of the decls declared within a given scope and (recursively)
11110 all of its sub-blocks. */
11113 decls_for_scope (stmt, context_die, depth)
11115 dw_die_ref context_die;
11121 /* Ignore blocks never really used to make RTL. */
11122 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11125 /* Output the DIEs to represent all of the data objects and typedefs
11126 declared directly within this block but not within any nested
11127 sub-blocks. Also, nested function and tag DIEs have been
11128 generated with a parent of NULL; fix that up now. */
11129 for (decl = BLOCK_VARS (stmt);
11130 decl != NULL; decl = TREE_CHAIN (decl))
11134 if (TREE_CODE (decl) == FUNCTION_DECL)
11135 die = lookup_decl_die (decl);
11136 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11137 die = lookup_type_die (TREE_TYPE (decl));
11141 if (die != NULL && die->die_parent == NULL)
11142 add_child_die (context_die, die);
11144 gen_decl_die (decl, context_die);
11147 /* Output the DIEs to represent all sub-blocks (and the items declared
11148 therein) of this block. */
11149 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11151 subblocks = BLOCK_CHAIN (subblocks))
11152 gen_block_die (subblocks, context_die, depth + 1);
11155 /* Is this a typedef we can avoid emitting? */
11158 is_redundant_typedef (decl)
11161 if (TYPE_DECL_IS_STUB (decl))
11164 if (DECL_ARTIFICIAL (decl)
11165 && DECL_CONTEXT (decl)
11166 && is_tagged_type (DECL_CONTEXT (decl))
11167 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11168 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11169 /* Also ignore the artificial member typedef for the class name. */
11175 /* Generate Dwarf debug information for a decl described by DECL. */
11178 gen_decl_die (decl, context_die)
11180 dw_die_ref context_die;
11184 if (TREE_CODE (decl) == ERROR_MARK)
11187 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11188 if (DECL_IGNORED_P (decl))
11191 switch (TREE_CODE (decl))
11194 /* The individual enumerators of an enum type get output when we output
11195 the Dwarf representation of the relevant enum type itself. */
11198 case FUNCTION_DECL:
11199 /* Don't output any DIEs to represent mere function declarations,
11200 unless they are class members or explicit block externs. */
11201 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11202 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11205 /* If we're emitting a clone, emit info for the abstract instance. */
11206 if (DECL_ORIGIN (decl) != decl)
11207 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11208 /* If we're emitting an out-of-line copy of an inline function,
11209 emit info for the abstract instance and set up to refer to it. */
11210 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11211 && ! class_scope_p (context_die)
11212 /* dwarf2out_abstract_function won't emit a die if this is just
11213 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11214 that case, because that works only if we have a die. */
11215 && DECL_INITIAL (decl) != NULL_TREE)
11217 dwarf2out_abstract_function (decl);
11218 set_decl_origin_self (decl);
11220 /* Otherwise we're emitting the primary DIE for this decl. */
11221 else if (debug_info_level > DINFO_LEVEL_TERSE)
11223 /* Before we describe the FUNCTION_DECL itself, make sure that we
11224 have described its return type. */
11225 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11227 /* And its virtual context. */
11228 if (DECL_VINDEX (decl) != NULL_TREE)
11229 gen_type_die (DECL_CONTEXT (decl), context_die);
11231 /* And its containing type. */
11232 origin = decl_class_context (decl);
11233 if (origin != NULL_TREE)
11234 gen_type_die_for_member (origin, decl, context_die);
11237 /* Now output a DIE to represent the function itself. */
11238 gen_subprogram_die (decl, context_die);
11242 /* If we are in terse mode, don't generate any DIEs to represent any
11243 actual typedefs. */
11244 if (debug_info_level <= DINFO_LEVEL_TERSE)
11247 /* In the special case of a TYPE_DECL node representing the
11248 declaration of some type tag, if the given TYPE_DECL is marked as
11249 having been instantiated from some other (original) TYPE_DECL node
11250 (e.g. one which was generated within the original definition of an
11251 inline function) we have to generate a special (abbreviated)
11252 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
11254 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11256 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11260 if (is_redundant_typedef (decl))
11261 gen_type_die (TREE_TYPE (decl), context_die);
11263 /* Output a DIE to represent the typedef itself. */
11264 gen_typedef_die (decl, context_die);
11268 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11269 gen_label_die (decl, context_die);
11273 /* If we are in terse mode, don't generate any DIEs to represent any
11274 variable declarations or definitions. */
11275 if (debug_info_level <= DINFO_LEVEL_TERSE)
11278 /* Output any DIEs that are needed to specify the type of this data
11280 gen_type_die (TREE_TYPE (decl), context_die);
11282 /* And its containing type. */
11283 origin = decl_class_context (decl);
11284 if (origin != NULL_TREE)
11285 gen_type_die_for_member (origin, decl, context_die);
11287 /* Now output the DIE to represent the data object itself. This gets
11288 complicated because of the possibility that the VAR_DECL really
11289 represents an inlined instance of a formal parameter for an inline
11291 origin = decl_ultimate_origin (decl);
11292 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11293 gen_formal_parameter_die (decl, context_die);
11295 gen_variable_die (decl, context_die);
11299 /* Ignore the nameless fields that are used to skip bits, but
11300 handle C++ anonymous unions. */
11301 if (DECL_NAME (decl) != NULL_TREE
11302 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11304 gen_type_die (member_declared_type (decl), context_die);
11305 gen_field_die (decl, context_die);
11310 gen_type_die (TREE_TYPE (decl), context_die);
11311 gen_formal_parameter_die (decl, context_die);
11314 case NAMESPACE_DECL:
11315 /* Ignore for now. */
11323 /* Add Ada "use" clause information for SGI Workshop debugger. */
11326 dwarf2out_add_library_unit_info (filename, context_list)
11327 const char *filename;
11328 const char *context_list;
11330 unsigned int file_index;
11332 if (filename != NULL)
11334 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
11335 tree context_list_decl
11336 = build_decl (LABEL_DECL, get_identifier (context_list),
11339 TREE_PUBLIC (context_list_decl) = TRUE;
11340 add_name_attribute (unit_die, context_list);
11341 file_index = lookup_filename (filename);
11342 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11343 add_pubname (context_list_decl, unit_die);
11347 /* Debug information for a global DECL. Called from toplev.c after
11348 compilation proper has finished. */
11350 dwarf2out_global_decl (decl)
11353 /* Output DWARF2 information for file-scope tentative data object
11354 declarations, file-scope (extern) function declarations (which
11355 had no corresponding body) and file-scope tagged type
11356 declarations and definitions which have not yet been forced out. */
11358 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11359 dwarf2out_decl (decl);
11362 /* Write the debugging output for DECL. */
11365 dwarf2out_decl (decl)
11368 dw_die_ref context_die = comp_unit_die;
11370 if (TREE_CODE (decl) == ERROR_MARK)
11373 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11374 if (DECL_IGNORED_P (decl))
11377 switch (TREE_CODE (decl))
11379 case FUNCTION_DECL:
11380 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11381 builtin function. Explicit programmer-supplied declarations of
11382 these same functions should NOT be ignored however. */
11383 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11386 /* What we would really like to do here is to filter out all mere
11387 file-scope declarations of file-scope functions which are never
11388 referenced later within this translation unit (and keep all of ones
11389 that *are* referenced later on) but we aren't clairvoyant, so we have
11390 no idea which functions will be referenced in the future (i.e. later
11391 on within the current translation unit). So here we just ignore all
11392 file-scope function declarations which are not also definitions. If
11393 and when the debugger needs to know something about these functions,
11394 it will have to hunt around and find the DWARF information associated
11395 with the definition of the function. Note that we can't just check
11396 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11397 definitions and which ones represent mere declarations. We have to
11398 check `DECL_INITIAL' instead. That's because the C front-end
11399 supports some weird semantics for "extern inline" function
11400 definitions. These can get inlined within the current translation
11401 unit (an thus, we need to generate DWARF info for their abstract
11402 instances so that the DWARF info for the concrete inlined instances
11403 can have something to refer to) but the compiler never generates any
11404 out-of-lines instances of such things (despite the fact that they
11405 *are* definitions). The important point is that the C front-end
11406 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11407 to generate DWARF for them anyway. Note that the C++ front-end also
11408 plays some similar games for inline function definitions appearing
11409 within include files which also contain
11410 `#pragma interface' pragmas. */
11411 if (DECL_INITIAL (decl) == NULL_TREE)
11414 /* If we're a nested function, initially use a parent of NULL; if we're
11415 a plain function, this will be fixed up in decls_for_scope. If
11416 we're a method, it will be ignored, since we already have a DIE. */
11417 if (decl_function_context (decl))
11418 context_die = NULL;
11423 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11424 declaration and if the declaration was never even referenced from
11425 within this entire compilation unit. We suppress these DIEs in
11426 order to save space in the .debug section (by eliminating entries
11427 which are probably useless). Note that we must not suppress
11428 block-local extern declarations (whether used or not) because that
11429 would screw-up the debugger's name lookup mechanism and cause it to
11430 miss things which really ought to be in scope at a given point. */
11431 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11434 /* If we are in terse mode, don't generate any DIEs to represent any
11435 variable declarations or definitions. */
11436 if (debug_info_level <= DINFO_LEVEL_TERSE)
11441 /* Don't emit stubs for types unless they are needed by other DIEs. */
11442 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11445 /* Don't bother trying to generate any DIEs to represent any of the
11446 normal built-in types for the language we are compiling. */
11447 if (DECL_SOURCE_LINE (decl) == 0)
11449 /* OK, we need to generate one for `bool' so GDB knows what type
11450 comparisons have. */
11451 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11452 == DW_LANG_C_plus_plus)
11453 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11454 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11459 /* If we are in terse mode, don't generate any DIEs for types. */
11460 if (debug_info_level <= DINFO_LEVEL_TERSE)
11463 /* If we're a function-scope tag, initially use a parent of NULL;
11464 this will be fixed up in decls_for_scope. */
11465 if (decl_function_context (decl))
11466 context_die = NULL;
11474 gen_decl_die (decl, context_die);
11477 /* Output a marker (i.e. a label) for the beginning of the generated code for
11478 a lexical block. */
11481 dwarf2out_begin_block (line, blocknum)
11482 unsigned int line ATTRIBUTE_UNUSED;
11483 unsigned int blocknum;
11485 function_section (current_function_decl);
11486 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11489 /* Output a marker (i.e. a label) for the end of the generated code for a
11493 dwarf2out_end_block (line, blocknum)
11494 unsigned int line ATTRIBUTE_UNUSED;
11495 unsigned int blocknum;
11497 function_section (current_function_decl);
11498 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11501 /* Returns nonzero if it is appropriate not to emit any debugging
11502 information for BLOCK, because it doesn't contain any instructions.
11504 Don't allow this for blocks with nested functions or local classes
11505 as we would end up with orphans, and in the presence of scheduling
11506 we may end up calling them anyway. */
11509 dwarf2out_ignore_block (block)
11513 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11514 if (TREE_CODE (decl) == FUNCTION_DECL
11515 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11520 /* Lookup a filename (in the list of filenames that we know about here in
11521 dwarf2out.c) and return its "index". The index of each (known) filename is
11522 just a unique number which is associated with only that one filename.
11523 We need such numbers for the sake of generating labels
11524 (in the .debug_sfnames section) and references to those
11525 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11526 If the filename given as an argument is not found in our current list,
11527 add it to the list and assign it the next available unique index number.
11528 In order to speed up searches, we remember the index of the filename
11529 was looked up last. This handles the majority of all searches. */
11532 lookup_filename (file_name)
11533 const char *file_name;
11537 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11538 if (strcmp (file_name, "<internal>") == 0
11539 || strcmp (file_name, "<built-in>") == 0)
11542 /* Check to see if the file name that was searched on the previous
11543 call matches this file name. If so, return the index. */
11544 if (file_table.last_lookup_index != 0)
11545 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
11546 return file_table.last_lookup_index;
11548 /* Didn't match the previous lookup, search the table */
11549 for (i = 1; i < file_table.in_use; ++i)
11550 if (strcmp (file_name, file_table.table[i]) == 0)
11552 file_table.last_lookup_index = i;
11556 /* Prepare to add a new table entry by making sure there is enough space in
11557 the table to do so. If not, expand the current table. */
11558 if (i == file_table.allocated)
11560 file_table.allocated = i + FILE_TABLE_INCREMENT;
11561 file_table.table = (char **)
11562 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11565 /* Add the new entry to the end of the filename table. */
11566 file_table.table[i] = xstrdup (file_name);
11567 file_table.in_use = i + 1;
11568 file_table.last_lookup_index = i;
11570 if (DWARF2_ASM_LINE_DEBUG_INFO)
11571 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11579 /* Allocate the initial hunk of the file_table. */
11580 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11581 file_table.allocated = FILE_TABLE_INCREMENT;
11583 /* Skip the first entry - file numbers begin at 1. */
11584 file_table.in_use = 1;
11585 file_table.last_lookup_index = 0;
11588 /* Output a label to mark the beginning of a source code line entry
11589 and record information relating to this source line, in
11590 'line_info_table' for later output of the .debug_line section. */
11593 dwarf2out_source_line (line, filename)
11595 const char *filename;
11597 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11599 function_section (current_function_decl);
11601 /* If requested, emit something human-readable. */
11602 if (flag_debug_asm)
11603 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11606 if (DWARF2_ASM_LINE_DEBUG_INFO)
11608 unsigned file_num = lookup_filename (filename);
11610 /* Emit the .loc directive understood by GNU as. */
11611 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11613 /* Indicate that line number info exists. */
11614 ++line_info_table_in_use;
11616 /* Indicate that multiple line number tables exist. */
11617 if (DECL_SECTION_NAME (current_function_decl))
11618 ++separate_line_info_table_in_use;
11620 else if (DECL_SECTION_NAME (current_function_decl))
11622 dw_separate_line_info_ref line_info;
11623 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11624 separate_line_info_table_in_use);
11626 /* expand the line info table if necessary */
11627 if (separate_line_info_table_in_use
11628 == separate_line_info_table_allocated)
11630 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11631 separate_line_info_table
11632 = (dw_separate_line_info_ref)
11633 xrealloc (separate_line_info_table,
11634 separate_line_info_table_allocated
11635 * sizeof (dw_separate_line_info_entry));
11638 /* Add the new entry at the end of the line_info_table. */
11640 = &separate_line_info_table[separate_line_info_table_in_use++];
11641 line_info->dw_file_num = lookup_filename (filename);
11642 line_info->dw_line_num = line;
11643 line_info->function = current_funcdef_number;
11647 dw_line_info_ref line_info;
11649 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11650 line_info_table_in_use);
11652 /* Expand the line info table if necessary. */
11653 if (line_info_table_in_use == line_info_table_allocated)
11655 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11657 = (dw_line_info_ref)
11658 xrealloc (line_info_table,
11659 (line_info_table_allocated
11660 * sizeof (dw_line_info_entry)));
11663 /* Add the new entry at the end of the line_info_table. */
11664 line_info = &line_info_table[line_info_table_in_use++];
11665 line_info->dw_file_num = lookup_filename (filename);
11666 line_info->dw_line_num = line;
11671 /* Record the beginning of a new source file. */
11674 dwarf2out_start_source_file (lineno, filename)
11675 unsigned int lineno;
11676 const char *filename;
11678 if (flag_eliminate_dwarf2_dups)
11680 /* Record the beginning of the file for break_out_includes. */
11681 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11682 add_AT_string (bincl_die, DW_AT_name, filename);
11684 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11686 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11687 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11688 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11690 dw2_asm_output_data_uleb128 (lookup_filename (filename),
11691 "Filename we just started");
11695 /* Record the end of a source file. */
11698 dwarf2out_end_source_file (lineno)
11699 unsigned int lineno ATTRIBUTE_UNUSED;
11701 if (flag_eliminate_dwarf2_dups)
11703 /* Record the end of the file for break_out_includes. */
11704 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11706 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11708 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11709 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11713 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11714 the tail part of the directive line, i.e. the part which is past the
11715 initial whitespace, #, whitespace, directive-name, whitespace part. */
11718 dwarf2out_define (lineno, buffer)
11719 unsigned lineno ATTRIBUTE_UNUSED;
11720 const char *buffer ATTRIBUTE_UNUSED;
11722 static int initialized = 0;
11725 dwarf2out_start_source_file (0, primary_filename);
11728 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11730 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11731 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11732 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11733 dw2_asm_output_nstring (buffer, -1, "The macro");
11737 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11738 the tail part of the directive line, i.e. the part which is past the
11739 initial whitespace, #, whitespace, directive-name, whitespace part. */
11742 dwarf2out_undef (lineno, buffer)
11743 unsigned lineno ATTRIBUTE_UNUSED;
11744 const char *buffer ATTRIBUTE_UNUSED;
11746 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11748 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11749 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
11750 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11751 dw2_asm_output_nstring (buffer, -1, "The macro");
11755 /* Set up for Dwarf output at the start of compilation. */
11758 dwarf2out_init (main_input_filename)
11759 const char *main_input_filename;
11761 init_file_table ();
11763 /* Remember the name of the primary input file. */
11764 primary_filename = main_input_filename;
11766 /* Add it to the file table first, under the assumption that we'll
11767 be emitting line number data for it first, which avoids having
11768 to add an initial DW_LNS_set_file. */
11769 lookup_filename (main_input_filename);
11771 /* Allocate the initial hunk of the decl_die_table. */
11773 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11774 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11775 decl_die_table_in_use = 0;
11777 /* Allocate the initial hunk of the decl_scope_table. */
11778 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
11779 ggc_add_tree_varray_root (&decl_scope_table, 1);
11781 /* Allocate the initial hunk of the abbrev_die_table. */
11783 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11784 sizeof (dw_die_ref));
11785 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11786 /* Zero-th entry is allocated, but unused */
11787 abbrev_die_table_in_use = 1;
11789 /* Allocate the initial hunk of the line_info_table. */
11791 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11792 sizeof (dw_line_info_entry));
11793 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11794 /* Zero-th entry is allocated, but unused */
11795 line_info_table_in_use = 1;
11797 /* Generate the initial DIE for the .debug section. Note that the (string)
11798 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11799 will (typically) be a relative pathname and that this pathname should be
11800 taken as being relative to the directory from which the compiler was
11801 invoked when the given (base) source file was compiled. */
11802 comp_unit_die = gen_compile_unit_die (main_input_filename);
11804 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
11805 ggc_add_tree_varray_root (&incomplete_types, 1);
11807 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11808 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11810 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11811 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
11812 DEBUG_ABBREV_SECTION_LABEL, 0);
11813 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11814 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11816 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
11817 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11818 DEBUG_INFO_SECTION_LABEL, 0);
11819 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11820 DEBUG_LINE_SECTION_LABEL, 0);
11821 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
11822 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11823 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
11824 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11825 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
11826 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11827 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11829 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11830 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
11831 DEBUG_MACINFO_SECTION_LABEL, 0);
11832 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
11835 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11838 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11842 /* Allocate a string in .debug_str hash table. */
11845 indirect_string_alloc (tab)
11846 hash_table *tab ATTRIBUTE_UNUSED;
11848 struct indirect_string_node *node;
11850 node = xmalloc (sizeof (struct indirect_string_node));
11851 node->refcount = 0;
11853 node->label = NULL;
11854 return (hashnode) node;
11857 /* A helper function for dwarf2out_finish called through
11858 ht_forall. Emit one queued .debug_str string. */
11861 output_indirect_string (pfile, h, v)
11862 struct cpp_reader *pfile ATTRIBUTE_UNUSED;
11864 const PTR v ATTRIBUTE_UNUSED;
11866 struct indirect_string_node *node;
11868 node = (struct indirect_string_node *) h;
11869 if (node->form == DW_FORM_strp)
11871 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
11872 ASM_OUTPUT_LABEL (asm_out_file, node->label);
11873 assemble_string ((const char *) HT_STR (&node->id),
11874 HT_LEN (&node->id) + 1);
11879 /* Output stuff that dwarf requires at the end of every file,
11880 and generate the DWARF-2 debugging info. */
11883 dwarf2out_finish (input_filename)
11884 const char *input_filename ATTRIBUTE_UNUSED;
11886 limbo_die_node *node, *next_node;
11887 dw_die_ref die = 0;
11889 /* Traverse the limbo die list, and add parent/child links. The only
11890 dies without parents that should be here are concrete instances of
11891 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11892 For concrete instances, we can get the parent die from the abstract
11894 for (node = limbo_die_list; node; node = next_node)
11896 next_node = node->next;
11899 if (die->die_parent == NULL)
11901 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11903 add_child_die (origin->die_parent, die);
11904 else if (die == comp_unit_die)
11906 else if (errorcount > 0 || sorrycount > 0)
11907 /* It's OK to be confused by errors in the input. */
11908 add_child_die (comp_unit_die, die);
11914 limbo_die_list = NULL;
11916 /* Walk through the list of incomplete types again, trying once more to
11917 emit full debugging info for them. */
11918 retry_incomplete_types ();
11920 /* We need to reverse all the dies before break_out_includes, or
11921 we'll see the end of an include file before the beginning. */
11922 reverse_all_dies (comp_unit_die);
11924 /* Generate separate CUs for each of the include files we've seen.
11925 They will go into limbo_die_list. */
11926 if (flag_eliminate_dwarf2_dups)
11927 break_out_includes (comp_unit_die);
11929 /* Traverse the DIE's and add add sibling attributes to those DIE's
11930 that have children. */
11931 add_sibling_attributes (comp_unit_die);
11932 for (node = limbo_die_list; node; node = node->next)
11933 add_sibling_attributes (node->die);
11935 /* Output a terminator label for the .text section. */
11937 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11939 /* Output the source line correspondence table. We must do this
11940 even if there is no line information. Otherwise, on an empty
11941 translation unit, we will generate a present, but empty,
11942 .debug_info section. IRIX 6.5 `nm' will then complain when
11943 examining the file. */
11944 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11946 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
11947 output_line_info ();
11950 /* Output location list section if necessary. */
11951 if (have_location_lists)
11953 /* Output the location lists info. */
11954 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
11955 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
11956 DEBUG_LOC_SECTION_LABEL, 0);
11957 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
11958 output_location_lists (die);
11959 have_location_lists = 0;
11962 /* We can only use the low/high_pc attributes if all of the code was
11964 if (separate_line_info_table_in_use == 0)
11966 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11967 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11969 /* And if it wasn't, we need to give .debug_loc and .debug_ranges
11970 an appropriate "base address". Use zero so that these addresses
11971 become absolute. */
11972 else if (have_location_lists || ranges_table_in_use)
11973 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
11975 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11976 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11977 debug_line_section_label);
11979 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11980 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
11982 /* Output all of the compilation units. We put the main one last so that
11983 the offsets are available to output_pubnames. */
11984 for (node = limbo_die_list; node; node = node->next)
11985 output_comp_unit (node->die);
11986 output_comp_unit (comp_unit_die);
11988 /* Output the abbreviation table. */
11989 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
11990 output_abbrev_section ();
11992 if (pubname_table_in_use)
11994 /* Output public names table. */
11995 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
11996 output_pubnames ();
11999 /* We only put functions in the arange table, so don't write it out if
12000 we don't have any. */
12001 if (fde_table_in_use)
12003 /* Output the address range information. */
12004 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
12008 /* Output ranges section if necessary. */
12009 if (ranges_table_in_use)
12011 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
12015 /* Have to end the primary source file. */
12016 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12018 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12019 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12022 /* If we emitted any DW_FORM_strp form attribute, output string
12024 if (debug_str_hash)
12025 ht_forall (debug_str_hash, output_indirect_string, NULL);
12027 #endif /* DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO */