1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
43 #include "hard-reg-set.h"
45 #include "insn-config.h"
53 #include "dwarf2out.h"
54 #include "dwarf2asm.h"
60 #include "diagnostic.h"
63 #include "langhooks.h"
64 #include "hashtable.h"
66 #ifdef DWARF2_DEBUGGING_INFO
67 static void dwarf2out_source_line PARAMS ((unsigned int, const char *));
70 /* DWARF2 Abbreviation Glossary:
71 CFA = Canonical Frame Address
72 a fixed address on the stack which identifies a call frame.
73 We define it to be the value of SP just before the call insn.
74 The CFA register and offset, which may change during the course
75 of the function, are used to calculate its value at runtime.
76 CFI = Call Frame Instruction
77 an instruction for the DWARF2 abstract machine
78 CIE = Common Information Entry
79 information describing information common to one or more FDEs
80 DIE = Debugging Information Entry
81 FDE = Frame Description Entry
82 information describing the stack call frame, in particular,
83 how to restore registers
85 DW_CFA_... = DWARF2 CFA call frame instruction
86 DW_TAG_... = DWARF2 DIE tag */
88 /* Decide whether we want to emit frame unwind information for the current
94 return (write_symbols == DWARF2_DEBUG
95 || write_symbols == VMS_AND_DWARF2_DEBUG
96 #ifdef DWARF2_FRAME_INFO
99 #ifdef DWARF2_UNWIND_INFO
100 || flag_unwind_tables
101 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
106 /* The size of the target's pointer type. */
108 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
111 /* Default version of targetm.eh_frame_section. Note this must appear
112 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
116 default_eh_frame_section ()
118 #ifdef EH_FRAME_SECTION_NAME
119 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
121 tree label = get_file_function_name ('F');
124 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
125 (*targetm.asm_out.globalize_label) (asm_out_file, IDENTIFIER_POINTER (label));
126 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
130 /* Array of RTXes referenced by the debugging information, which therefore
131 must be kept around forever. */
132 static GTY(()) varray_type used_rtx_varray;
134 /* A pointer to the base of a list of incomplete types which might be
135 completed at some later time. incomplete_types_list needs to be a VARRAY
136 because we want to tell the garbage collector about it. */
137 static GTY(()) varray_type incomplete_types;
139 /* A pointer to the base of a table of references to declaration
140 scopes. This table is a display which tracks the nesting
141 of declaration scopes at the current scope and containing
142 scopes. This table is used to find the proper place to
143 define type declaration DIE's. */
144 static GTY(()) varray_type decl_scope_table;
146 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
148 /* How to start an assembler comment. */
149 #ifndef ASM_COMMENT_START
150 #define ASM_COMMENT_START ";#"
153 typedef struct dw_cfi_struct *dw_cfi_ref;
154 typedef struct dw_fde_struct *dw_fde_ref;
155 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
157 /* Call frames are described using a sequence of Call Frame
158 Information instructions. The register number, offset
159 and address fields are provided as possible operands;
160 their use is selected by the opcode field. */
162 typedef union dw_cfi_oprnd_struct
164 unsigned long dw_cfi_reg_num;
165 long int dw_cfi_offset;
166 const char *dw_cfi_addr;
167 struct dw_loc_descr_struct *dw_cfi_loc;
171 typedef struct dw_cfi_struct
173 dw_cfi_ref dw_cfi_next;
174 enum dwarf_call_frame_info dw_cfi_opc;
175 dw_cfi_oprnd dw_cfi_oprnd1;
176 dw_cfi_oprnd dw_cfi_oprnd2;
180 /* This is how we define the location of the CFA. We use to handle it
181 as REG + OFFSET all the time, but now it can be more complex.
182 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
183 Instead of passing around REG and OFFSET, we pass a copy
184 of this structure. */
185 typedef struct cfa_loc
190 int indirect; /* 1 if CFA is accessed via a dereference. */
193 /* All call frame descriptions (FDE's) in the GCC generated DWARF
194 refer to a single Common Information Entry (CIE), defined at
195 the beginning of the .debug_frame section. This use of a single
196 CIE obviates the need to keep track of multiple CIE's
197 in the DWARF generation routines below. */
199 typedef struct dw_fde_struct
201 const char *dw_fde_begin;
202 const char *dw_fde_current_label;
203 const char *dw_fde_end;
204 dw_cfi_ref dw_fde_cfi;
205 unsigned funcdef_number;
206 unsigned all_throwers_are_sibcalls : 1;
207 unsigned nothrow : 1;
208 unsigned uses_eh_lsda : 1;
212 /* Maximum size (in bytes) of an artificially generated label. */
213 #define MAX_ARTIFICIAL_LABEL_BYTES 30
215 /* The size of addresses as they appear in the Dwarf 2 data.
216 Some architectures use word addresses to refer to code locations,
217 but Dwarf 2 info always uses byte addresses. On such machines,
218 Dwarf 2 addresses need to be larger than the architecture's
220 #ifndef DWARF2_ADDR_SIZE
221 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
224 /* The size in bytes of a DWARF field indicating an offset or length
225 relative to a debug info section, specified to be 4 bytes in the
226 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
229 #ifndef DWARF_OFFSET_SIZE
230 #define DWARF_OFFSET_SIZE 4
233 #define DWARF_VERSION 2
235 /* Round SIZE up to the nearest BOUNDARY. */
236 #define DWARF_ROUND(SIZE,BOUNDARY) \
237 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
239 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
240 #ifndef DWARF_CIE_DATA_ALIGNMENT
241 #ifdef STACK_GROWS_DOWNWARD
242 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
244 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
248 /* A pointer to the base of a table that contains frame description
249 information for each routine. */
250 static dw_fde_ref fde_table;
252 /* Number of elements currently allocated for fde_table. */
253 static unsigned fde_table_allocated;
255 /* Number of elements in fde_table currently in use. */
256 static unsigned fde_table_in_use;
258 /* Size (in elements) of increments by which we may expand the
260 #define FDE_TABLE_INCREMENT 256
262 /* A list of call frame insns for the CIE. */
263 static dw_cfi_ref cie_cfi_head;
265 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
266 attribute that accelerates the lookup of the FDE associated
267 with the subprogram. This variable holds the table index of the FDE
268 associated with the current function (body) definition. */
269 static unsigned current_funcdef_fde;
271 struct ht *debug_str_hash;
273 struct indirect_string_node
275 struct ht_identifier id;
276 unsigned int refcount;
281 /* Forward declarations for functions defined in this file. */
283 static char *stripattributes PARAMS ((const char *));
284 static const char *dwarf_cfi_name PARAMS ((unsigned));
285 static dw_cfi_ref new_cfi PARAMS ((void));
286 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
287 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
288 static void lookup_cfa_1 PARAMS ((dw_cfi_ref,
290 static void lookup_cfa PARAMS ((dw_cfa_location *));
291 static void reg_save PARAMS ((const char *, unsigned,
293 static void initial_return_save PARAMS ((rtx));
294 static long stack_adjust_offset PARAMS ((rtx));
295 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
296 static void output_call_frame_info PARAMS ((int));
297 static void dwarf2out_stack_adjust PARAMS ((rtx));
298 static void queue_reg_save PARAMS ((const char *, rtx, long));
299 static void flush_queued_reg_saves PARAMS ((void));
300 static bool clobbers_queued_reg_save PARAMS ((rtx));
301 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
303 /* Support for complex CFA locations. */
304 static void output_cfa_loc PARAMS ((dw_cfi_ref));
305 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
306 struct dw_loc_descr_struct *));
307 static struct dw_loc_descr_struct *build_cfa_loc
308 PARAMS ((dw_cfa_location *));
309 static void def_cfa_1 PARAMS ((const char *,
312 /* How to start an assembler comment. */
313 #ifndef ASM_COMMENT_START
314 #define ASM_COMMENT_START ";#"
317 /* Data and reference forms for relocatable data. */
318 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
319 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
321 #ifndef DEBUG_FRAME_SECTION
322 #define DEBUG_FRAME_SECTION ".debug_frame"
325 #ifndef FUNC_BEGIN_LABEL
326 #define FUNC_BEGIN_LABEL "LFB"
329 #ifndef FUNC_END_LABEL
330 #define FUNC_END_LABEL "LFE"
333 #define FRAME_BEGIN_LABEL "Lframe"
334 #define CIE_AFTER_SIZE_LABEL "LSCIE"
335 #define CIE_END_LABEL "LECIE"
336 #define FDE_LABEL "LSFDE"
337 #define FDE_AFTER_SIZE_LABEL "LASFDE"
338 #define FDE_END_LABEL "LEFDE"
339 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
340 #define LINE_NUMBER_END_LABEL "LELT"
341 #define LN_PROLOG_AS_LABEL "LASLTP"
342 #define LN_PROLOG_END_LABEL "LELTP"
343 #define DIE_LABEL_PREFIX "DW"
345 /* The DWARF 2 CFA column which tracks the return address. Normally this
346 is the column for PC, or the first column after all of the hard
348 #ifndef DWARF_FRAME_RETURN_COLUMN
350 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
352 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
356 /* The mapping from gcc register number to DWARF 2 CFA column number. By
357 default, we just provide columns for all registers. */
358 #ifndef DWARF_FRAME_REGNUM
359 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
362 /* The offset from the incoming value of %sp to the top of the stack frame
363 for the current function. */
364 #ifndef INCOMING_FRAME_SP_OFFSET
365 #define INCOMING_FRAME_SP_OFFSET 0
368 /* Hook used by __throw. */
371 expand_builtin_dwarf_fp_regnum ()
373 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
376 /* Return a pointer to a copy of the section string name S with all
377 attributes stripped off, and an asterisk prepended (for assemble_name). */
383 char *stripped = xmalloc (strlen (s) + 2);
388 while (*s && *s != ',')
395 /* Generate code to initialize the register size table. */
398 expand_builtin_init_dwarf_reg_sizes (address)
402 enum machine_mode mode = TYPE_MODE (char_type_node);
403 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
404 rtx mem = gen_rtx_MEM (BLKmode, addr);
406 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
407 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
409 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
410 HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]);
415 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
419 /* Convert a DWARF call frame info. operation to its string name */
422 dwarf_cfi_name (cfi_opc)
427 case DW_CFA_advance_loc:
428 return "DW_CFA_advance_loc";
430 return "DW_CFA_offset";
432 return "DW_CFA_restore";
436 return "DW_CFA_set_loc";
437 case DW_CFA_advance_loc1:
438 return "DW_CFA_advance_loc1";
439 case DW_CFA_advance_loc2:
440 return "DW_CFA_advance_loc2";
441 case DW_CFA_advance_loc4:
442 return "DW_CFA_advance_loc4";
443 case DW_CFA_offset_extended:
444 return "DW_CFA_offset_extended";
445 case DW_CFA_restore_extended:
446 return "DW_CFA_restore_extended";
447 case DW_CFA_undefined:
448 return "DW_CFA_undefined";
449 case DW_CFA_same_value:
450 return "DW_CFA_same_value";
451 case DW_CFA_register:
452 return "DW_CFA_register";
453 case DW_CFA_remember_state:
454 return "DW_CFA_remember_state";
455 case DW_CFA_restore_state:
456 return "DW_CFA_restore_state";
458 return "DW_CFA_def_cfa";
459 case DW_CFA_def_cfa_register:
460 return "DW_CFA_def_cfa_register";
461 case DW_CFA_def_cfa_offset:
462 return "DW_CFA_def_cfa_offset";
465 case DW_CFA_def_cfa_expression:
466 return "DW_CFA_def_cfa_expression";
467 case DW_CFA_expression:
468 return "DW_CFA_expression";
469 case DW_CFA_offset_extended_sf:
470 return "DW_CFA_offset_extended_sf";
471 case DW_CFA_def_cfa_sf:
472 return "DW_CFA_def_cfa_sf";
473 case DW_CFA_def_cfa_offset_sf:
474 return "DW_CFA_def_cfa_offset_sf";
476 /* SGI/MIPS specific */
477 case DW_CFA_MIPS_advance_loc8:
478 return "DW_CFA_MIPS_advance_loc8";
481 case DW_CFA_GNU_window_save:
482 return "DW_CFA_GNU_window_save";
483 case DW_CFA_GNU_args_size:
484 return "DW_CFA_GNU_args_size";
485 case DW_CFA_GNU_negative_offset_extended:
486 return "DW_CFA_GNU_negative_offset_extended";
489 return "DW_CFA_<unknown>";
493 /* Return a pointer to a newly allocated Call Frame Instruction. */
495 static inline dw_cfi_ref
498 dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
500 cfi->dw_cfi_next = NULL;
501 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
502 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
507 /* Add a Call Frame Instruction to list of instructions. */
510 add_cfi (list_head, cfi)
511 dw_cfi_ref *list_head;
516 /* Find the end of the chain. */
517 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
523 /* Generate a new label for the CFI info to refer to. */
526 dwarf2out_cfi_label ()
528 static char label[20];
529 static unsigned long label_num = 0;
531 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
532 ASM_OUTPUT_LABEL (asm_out_file, label);
536 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
537 or to the CIE if LABEL is NULL. */
540 add_fde_cfi (label, cfi)
546 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
549 label = dwarf2out_cfi_label ();
551 if (fde->dw_fde_current_label == NULL
552 || strcmp (label, fde->dw_fde_current_label) != 0)
556 fde->dw_fde_current_label = label = xstrdup (label);
558 /* Set the location counter to the new label. */
560 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
561 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
562 add_cfi (&fde->dw_fde_cfi, xcfi);
565 add_cfi (&fde->dw_fde_cfi, cfi);
569 add_cfi (&cie_cfi_head, cfi);
572 /* Subroutine of lookup_cfa. */
575 lookup_cfa_1 (cfi, loc)
577 dw_cfa_location *loc;
579 switch (cfi->dw_cfi_opc)
581 case DW_CFA_def_cfa_offset:
582 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
584 case DW_CFA_def_cfa_register:
585 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
588 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
589 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
591 case DW_CFA_def_cfa_expression:
592 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
599 /* Find the previous value for the CFA. */
603 dw_cfa_location *loc;
607 loc->reg = (unsigned long) -1;
610 loc->base_offset = 0;
612 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
613 lookup_cfa_1 (cfi, loc);
615 if (fde_table_in_use)
617 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
618 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
619 lookup_cfa_1 (cfi, loc);
623 /* The current rule for calculating the DWARF2 canonical frame address. */
624 static dw_cfa_location cfa;
626 /* The register used for saving registers to the stack, and its offset
628 static dw_cfa_location cfa_store;
630 /* The running total of the size of arguments pushed onto the stack. */
631 static long args_size;
633 /* The last args_size we actually output. */
634 static long old_args_size;
636 /* Entry point to update the canonical frame address (CFA).
637 LABEL is passed to add_fde_cfi. The value of CFA is now to be
638 calculated from REG+OFFSET. */
641 dwarf2out_def_cfa (label, reg, offset)
651 def_cfa_1 (label, &loc);
654 /* This routine does the actual work. The CFA is now calculated from
655 the dw_cfa_location structure. */
658 def_cfa_1 (label, loc_p)
660 dw_cfa_location *loc_p;
663 dw_cfa_location old_cfa, loc;
668 if (cfa_store.reg == loc.reg && loc.indirect == 0)
669 cfa_store.offset = loc.offset;
671 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
672 lookup_cfa (&old_cfa);
674 /* If nothing changed, no need to issue any call frame instructions. */
675 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
676 && loc.indirect == old_cfa.indirect
677 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
682 if (loc.reg == old_cfa.reg && !loc.indirect)
684 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
685 indicating the CFA register did not change but the offset
687 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
688 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
691 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
692 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
695 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
696 indicating the CFA register has changed to <register> but the
697 offset has not changed. */
698 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
699 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
703 else if (loc.indirect == 0)
705 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
706 indicating the CFA register has changed to <register> with
707 the specified offset. */
708 cfi->dw_cfi_opc = DW_CFA_def_cfa;
709 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
710 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
714 /* Construct a DW_CFA_def_cfa_expression instruction to
715 calculate the CFA using a full location expression since no
716 register-offset pair is available. */
717 struct dw_loc_descr_struct *loc_list;
719 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
720 loc_list = build_cfa_loc (&loc);
721 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
724 add_fde_cfi (label, cfi);
727 /* Add the CFI for saving a register. REG is the CFA column number.
728 LABEL is passed to add_fde_cfi.
729 If SREG is -1, the register is saved at OFFSET from the CFA;
730 otherwise it is saved in SREG. */
733 reg_save (label, reg, sreg, offset)
739 dw_cfi_ref cfi = new_cfi ();
741 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
743 /* The following comparison is correct. -1 is used to indicate that
744 the value isn't a register number. */
745 if (sreg == (unsigned int) -1)
748 /* The register number won't fit in 6 bits, so we have to use
750 cfi->dw_cfi_opc = DW_CFA_offset_extended;
752 cfi->dw_cfi_opc = DW_CFA_offset;
754 #ifdef ENABLE_CHECKING
756 /* If we get an offset that is not a multiple of
757 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
758 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
760 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
762 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
766 offset /= DWARF_CIE_DATA_ALIGNMENT;
768 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
770 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
772 else if (sreg == reg)
773 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
777 cfi->dw_cfi_opc = DW_CFA_register;
778 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
781 add_fde_cfi (label, cfi);
784 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
785 This CFI tells the unwinder that it needs to restore the window registers
786 from the previous frame's window save area.
788 ??? Perhaps we should note in the CIE where windows are saved (instead of
789 assuming 0(cfa)) and what registers are in the window. */
792 dwarf2out_window_save (label)
795 dw_cfi_ref cfi = new_cfi ();
797 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
798 add_fde_cfi (label, cfi);
801 /* Add a CFI to update the running total of the size of arguments
802 pushed onto the stack. */
805 dwarf2out_args_size (label, size)
811 if (size == old_args_size)
814 old_args_size = size;
817 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
818 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
819 add_fde_cfi (label, cfi);
822 /* Entry point for saving a register to the stack. REG is the GCC register
823 number. LABEL and OFFSET are passed to reg_save. */
826 dwarf2out_reg_save (label, reg, offset)
831 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
834 /* Entry point for saving the return address in the stack.
835 LABEL and OFFSET are passed to reg_save. */
838 dwarf2out_return_save (label, offset)
842 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
845 /* Entry point for saving the return address in a register.
846 LABEL and SREG are passed to reg_save. */
849 dwarf2out_return_reg (label, sreg)
853 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
856 /* Record the initial position of the return address. RTL is
857 INCOMING_RETURN_ADDR_RTX. */
860 initial_return_save (rtl)
863 unsigned int reg = (unsigned int) -1;
864 HOST_WIDE_INT offset = 0;
866 switch (GET_CODE (rtl))
869 /* RA is in a register. */
870 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
874 /* RA is on the stack. */
876 switch (GET_CODE (rtl))
879 if (REGNO (rtl) != STACK_POINTER_REGNUM)
885 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
887 offset = INTVAL (XEXP (rtl, 1));
891 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
893 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));
915 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
918 /* Given a SET, calculate the amount of stack adjustment it
922 stack_adjust_offset (pattern)
925 rtx src = SET_SRC (pattern);
926 rtx dest = SET_DEST (pattern);
927 HOST_WIDE_INT offset = 0;
930 if (dest == stack_pointer_rtx)
932 /* (set (reg sp) (plus (reg sp) (const_int))) */
933 code = GET_CODE (src);
934 if (! (code == PLUS || code == MINUS)
935 || XEXP (src, 0) != stack_pointer_rtx
936 || GET_CODE (XEXP (src, 1)) != CONST_INT)
939 offset = INTVAL (XEXP (src, 1));
943 else if (GET_CODE (dest) == MEM)
945 /* (set (mem (pre_dec (reg sp))) (foo)) */
946 src = XEXP (dest, 0);
947 code = GET_CODE (src);
953 if (XEXP (src, 0) == stack_pointer_rtx)
955 rtx val = XEXP (XEXP (src, 1), 1);
956 /* We handle only adjustments by constant amount. */
957 if (GET_CODE (XEXP (src, 1)) != PLUS ||
958 GET_CODE (val) != CONST_INT)
960 offset = -INTVAL (val);
967 if (XEXP (src, 0) == stack_pointer_rtx)
969 offset = GET_MODE_SIZE (GET_MODE (dest));
976 if (XEXP (src, 0) == stack_pointer_rtx)
978 offset = -GET_MODE_SIZE (GET_MODE (dest));
993 /* Check INSN to see if it looks like a push or a stack adjustment, and
994 make a note of it if it does. EH uses this information to find out how
995 much extra space it needs to pop off the stack. */
998 dwarf2out_stack_adjust (insn)
1001 HOST_WIDE_INT offset;
1005 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1007 /* Extract the size of the args from the CALL rtx itself. */
1008 insn = PATTERN (insn);
1009 if (GET_CODE (insn) == PARALLEL)
1010 insn = XVECEXP (insn, 0, 0);
1011 if (GET_CODE (insn) == SET)
1012 insn = SET_SRC (insn);
1013 if (GET_CODE (insn) != CALL)
1016 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1020 /* If only calls can throw, and we have a frame pointer,
1021 save up adjustments until we see the CALL_INSN. */
1022 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1025 if (GET_CODE (insn) == BARRIER)
1027 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1028 the compiler will have already emitted a stack adjustment, but
1029 doesn't bother for calls to noreturn functions. */
1030 #ifdef STACK_GROWS_DOWNWARD
1031 offset = -args_size;
1036 else if (GET_CODE (PATTERN (insn)) == SET)
1037 offset = stack_adjust_offset (PATTERN (insn));
1038 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1039 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1041 /* There may be stack adjustments inside compound insns. Search
1043 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1044 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1045 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1053 if (cfa.reg == STACK_POINTER_REGNUM)
1054 cfa.offset += offset;
1056 #ifndef STACK_GROWS_DOWNWARD
1060 args_size += offset;
1064 label = dwarf2out_cfi_label ();
1065 def_cfa_1 (label, &cfa);
1066 dwarf2out_args_size (label, args_size);
1069 /* We delay emitting a register save until either (a) we reach the end
1070 of the prologue or (b) the register is clobbered. This clusters
1071 register saves so that there are fewer pc advances. */
1073 struct queued_reg_save
1075 struct queued_reg_save *next;
1080 static struct queued_reg_save *queued_reg_saves;
1081 static const char *last_reg_save_label;
1084 queue_reg_save (label, reg, offset)
1089 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1091 q->next = queued_reg_saves;
1093 q->cfa_offset = offset;
1094 queued_reg_saves = q;
1096 last_reg_save_label = label;
1100 flush_queued_reg_saves ()
1102 struct queued_reg_save *q, *next;
1104 for (q = queued_reg_saves; q; q = next)
1106 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1111 queued_reg_saves = NULL;
1112 last_reg_save_label = NULL;
1116 clobbers_queued_reg_save (insn)
1119 struct queued_reg_save *q;
1121 for (q = queued_reg_saves; q; q = q->next)
1122 if (modified_in_p (q->reg, insn))
1129 /* A temporary register holding an integral value used in adjusting SP
1130 or setting up the store_reg. The "offset" field holds the integer
1131 value, not an offset. */
1132 static dw_cfa_location cfa_temp;
1134 /* Record call frame debugging information for an expression EXPR,
1135 which either sets SP or FP (adjusting how we calculate the frame
1136 address) or saves a register to the stack. LABEL indicates the
1139 This function encodes a state machine mapping rtxes to actions on
1140 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1141 users need not read the source code.
1143 The High-Level Picture
1145 Changes in the register we use to calculate the CFA: Currently we
1146 assume that if you copy the CFA register into another register, we
1147 should take the other one as the new CFA register; this seems to
1148 work pretty well. If it's wrong for some target, it's simple
1149 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1151 Changes in the register we use for saving registers to the stack:
1152 This is usually SP, but not always. Again, we deduce that if you
1153 copy SP into another register (and SP is not the CFA register),
1154 then the new register is the one we will be using for register
1155 saves. This also seems to work.
1157 Register saves: There's not much guesswork about this one; if
1158 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1159 register save, and the register used to calculate the destination
1160 had better be the one we think we're using for this purpose.
1162 Except: If the register being saved is the CFA register, and the
1163 offset is non-zero, we are saving the CFA, so we assume we have to
1164 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1165 the intent is to save the value of SP from the previous frame.
1167 Invariants / Summaries of Rules
1169 cfa current rule for calculating the CFA. It usually
1170 consists of a register and an offset.
1171 cfa_store register used by prologue code to save things to the stack
1172 cfa_store.offset is the offset from the value of
1173 cfa_store.reg to the actual CFA
1174 cfa_temp register holding an integral value. cfa_temp.offset
1175 stores the value, which will be used to adjust the
1176 stack pointer. cfa_temp is also used like cfa_store,
1177 to track stores to the stack via fp or a temp reg.
1179 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1180 with cfa.reg as the first operand changes the cfa.reg and its
1181 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1184 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1185 expression yielding a constant. This sets cfa_temp.reg
1186 and cfa_temp.offset.
1188 Rule 5: Create a new register cfa_store used to save items to the
1191 Rules 10-14: Save a register to the stack. Define offset as the
1192 difference of the original location and cfa_store's
1193 location (or cfa_temp's location if cfa_temp is used).
1197 "{a,b}" indicates a choice of a xor b.
1198 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1201 (set <reg1> <reg2>:cfa.reg)
1202 effects: cfa.reg = <reg1>
1203 cfa.offset unchanged
1204 cfa_temp.reg = <reg1>
1205 cfa_temp.offset = cfa.offset
1208 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1209 {<const_int>,<reg>:cfa_temp.reg}))
1210 effects: cfa.reg = sp if fp used
1211 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1212 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1213 if cfa_store.reg==sp
1216 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1217 effects: cfa.reg = fp
1218 cfa_offset += +/- <const_int>
1221 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1222 constraints: <reg1> != fp
1224 effects: cfa.reg = <reg1>
1225 cfa_temp.reg = <reg1>
1226 cfa_temp.offset = cfa.offset
1229 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1230 constraints: <reg1> != fp
1232 effects: cfa_store.reg = <reg1>
1233 cfa_store.offset = cfa.offset - cfa_temp.offset
1236 (set <reg> <const_int>)
1237 effects: cfa_temp.reg = <reg>
1238 cfa_temp.offset = <const_int>
1241 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1242 effects: cfa_temp.reg = <reg1>
1243 cfa_temp.offset |= <const_int>
1246 (set <reg> (high <exp>))
1250 (set <reg> (lo_sum <exp> <const_int>))
1251 effects: cfa_temp.reg = <reg>
1252 cfa_temp.offset = <const_int>
1255 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1256 effects: cfa_store.offset -= <const_int>
1257 cfa.offset = cfa_store.offset if cfa.reg == sp
1259 cfa.base_offset = -cfa_store.offset
1262 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1263 effects: cfa_store.offset += -/+ mode_size(mem)
1264 cfa.offset = cfa_store.offset if cfa.reg == sp
1266 cfa.base_offset = -cfa_store.offset
1269 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1272 effects: cfa.reg = <reg1>
1273 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1276 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1277 effects: cfa.reg = <reg1>
1278 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1281 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1282 effects: cfa.reg = <reg1>
1283 cfa.base_offset = -cfa_temp.offset
1284 cfa_temp.offset -= mode_size(mem) */
1287 dwarf2out_frame_debug_expr (expr, label)
1292 HOST_WIDE_INT offset;
1294 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1295 the PARALLEL independently. The first element is always processed if
1296 it is a SET. This is for backward compatibility. Other elements
1297 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1298 flag is set in them. */
1299 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1302 int limit = XVECLEN (expr, 0);
1304 for (par_index = 0; par_index < limit; par_index++)
1305 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1306 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1308 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1313 if (GET_CODE (expr) != SET)
1316 src = SET_SRC (expr);
1317 dest = SET_DEST (expr);
1319 switch (GET_CODE (dest))
1323 /* Update the CFA rule wrt SP or FP. Make sure src is
1324 relative to the current CFA register. */
1325 switch (GET_CODE (src))
1327 /* Setting FP from SP. */
1329 if (cfa.reg == (unsigned) REGNO (src))
1335 /* We used to require that dest be either SP or FP, but the
1336 ARM copies SP to a temporary register, and from there to
1337 FP. So we just rely on the backends to only set
1338 RTX_FRAME_RELATED_P on appropriate insns. */
1339 cfa.reg = REGNO (dest);
1340 cfa_temp.reg = cfa.reg;
1341 cfa_temp.offset = cfa.offset;
1347 if (dest == stack_pointer_rtx)
1351 switch (GET_CODE (XEXP (src, 1)))
1354 offset = INTVAL (XEXP (src, 1));
1357 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1359 offset = cfa_temp.offset;
1365 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1367 /* Restoring SP from FP in the epilogue. */
1368 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1370 cfa.reg = STACK_POINTER_REGNUM;
1372 else if (GET_CODE (src) == LO_SUM)
1373 /* Assume we've set the source reg of the LO_SUM from sp. */
1375 else if (XEXP (src, 0) != stack_pointer_rtx)
1378 if (GET_CODE (src) != MINUS)
1380 if (cfa.reg == STACK_POINTER_REGNUM)
1381 cfa.offset += offset;
1382 if (cfa_store.reg == STACK_POINTER_REGNUM)
1383 cfa_store.offset += offset;
1385 else if (dest == hard_frame_pointer_rtx)
1388 /* Either setting the FP from an offset of the SP,
1389 or adjusting the FP */
1390 if (! frame_pointer_needed)
1393 if (GET_CODE (XEXP (src, 0)) == REG
1394 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1395 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1397 offset = INTVAL (XEXP (src, 1));
1398 if (GET_CODE (src) != MINUS)
1400 cfa.offset += offset;
1401 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1408 if (GET_CODE (src) == MINUS)
1412 if (GET_CODE (XEXP (src, 0)) == REG
1413 && REGNO (XEXP (src, 0)) == cfa.reg
1414 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1416 /* Setting a temporary CFA register that will be copied
1417 into the FP later on. */
1418 offset = - INTVAL (XEXP (src, 1));
1419 cfa.offset += offset;
1420 cfa.reg = REGNO (dest);
1421 /* Or used to save regs to the stack. */
1422 cfa_temp.reg = cfa.reg;
1423 cfa_temp.offset = cfa.offset;
1427 else if (GET_CODE (XEXP (src, 0)) == REG
1428 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1429 && XEXP (src, 1) == stack_pointer_rtx)
1431 /* Setting a scratch register that we will use instead
1432 of SP for saving registers to the stack. */
1433 if (cfa.reg != STACK_POINTER_REGNUM)
1435 cfa_store.reg = REGNO (dest);
1436 cfa_store.offset = cfa.offset - cfa_temp.offset;
1440 else if (GET_CODE (src) == LO_SUM
1441 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1443 cfa_temp.reg = REGNO (dest);
1444 cfa_temp.offset = INTVAL (XEXP (src, 1));
1453 cfa_temp.reg = REGNO (dest);
1454 cfa_temp.offset = INTVAL (src);
1459 if (GET_CODE (XEXP (src, 0)) != REG
1460 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1461 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1464 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1465 cfa_temp.reg = REGNO (dest);
1466 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1469 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1470 which will fill in all of the bits. */
1479 def_cfa_1 (label, &cfa);
1483 if (GET_CODE (src) != REG)
1486 /* Saving a register to the stack. Make sure dest is relative to the
1488 switch (GET_CODE (XEXP (dest, 0)))
1493 /* We can't handle variable size modifications. */
1494 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1496 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1498 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1499 || cfa_store.reg != STACK_POINTER_REGNUM)
1502 cfa_store.offset += offset;
1503 if (cfa.reg == STACK_POINTER_REGNUM)
1504 cfa.offset = cfa_store.offset;
1506 offset = -cfa_store.offset;
1512 offset = GET_MODE_SIZE (GET_MODE (dest));
1513 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1516 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1517 || cfa_store.reg != STACK_POINTER_REGNUM)
1520 cfa_store.offset += offset;
1521 if (cfa.reg == STACK_POINTER_REGNUM)
1522 cfa.offset = cfa_store.offset;
1524 offset = -cfa_store.offset;
1528 /* With an offset. */
1532 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1534 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1535 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1538 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1539 offset -= cfa_store.offset;
1540 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1541 offset -= cfa_temp.offset;
1547 /* Without an offset. */
1549 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1550 offset = -cfa_store.offset;
1551 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1552 offset = -cfa_temp.offset;
1559 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1561 offset = -cfa_temp.offset;
1562 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1569 if (REGNO (src) != STACK_POINTER_REGNUM
1570 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1571 && (unsigned) REGNO (src) == cfa.reg)
1573 /* We're storing the current CFA reg into the stack. */
1575 if (cfa.offset == 0)
1577 /* If the source register is exactly the CFA, assume
1578 we're saving SP like any other register; this happens
1580 def_cfa_1 (label, &cfa);
1581 queue_reg_save (label, stack_pointer_rtx, offset);
1586 /* Otherwise, we'll need to look in the stack to
1587 calculate the CFA. */
1588 rtx x = XEXP (dest, 0);
1590 if (GET_CODE (x) != REG)
1592 if (GET_CODE (x) != REG)
1595 cfa.reg = REGNO (x);
1596 cfa.base_offset = offset;
1598 def_cfa_1 (label, &cfa);
1603 def_cfa_1 (label, &cfa);
1604 queue_reg_save (label, src, offset);
1612 /* Record call frame debugging information for INSN, which either
1613 sets SP or FP (adjusting how we calculate the frame address) or saves a
1614 register to the stack. If INSN is NULL_RTX, initialize our state. */
1617 dwarf2out_frame_debug (insn)
1623 if (insn == NULL_RTX)
1625 /* Flush any queued register saves. */
1626 flush_queued_reg_saves ();
1628 /* Set up state for generating call frame debug info. */
1630 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1633 cfa.reg = STACK_POINTER_REGNUM;
1636 cfa_temp.offset = 0;
1640 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1641 flush_queued_reg_saves ();
1643 if (! RTX_FRAME_RELATED_P (insn))
1645 if (!ACCUMULATE_OUTGOING_ARGS)
1646 dwarf2out_stack_adjust (insn);
1651 label = dwarf2out_cfi_label ();
1652 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1654 insn = XEXP (src, 0);
1656 insn = PATTERN (insn);
1658 dwarf2out_frame_debug_expr (insn, label);
1661 /* Output a Call Frame Information opcode and its operand(s). */
1664 output_cfi (cfi, fde, for_eh)
1669 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1670 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1671 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1672 "DW_CFA_advance_loc 0x%lx",
1673 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1674 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1676 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1677 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1678 "DW_CFA_offset, column 0x%lx",
1679 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1680 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1682 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1683 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1684 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1685 "DW_CFA_restore, column 0x%lx",
1686 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1689 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1690 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1692 switch (cfi->dw_cfi_opc)
1694 case DW_CFA_set_loc:
1696 dw2_asm_output_encoded_addr_rtx (
1697 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1698 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1701 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1702 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1705 case DW_CFA_advance_loc1:
1706 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1707 fde->dw_fde_current_label, NULL);
1708 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1711 case DW_CFA_advance_loc2:
1712 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1713 fde->dw_fde_current_label, NULL);
1714 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1717 case DW_CFA_advance_loc4:
1718 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1719 fde->dw_fde_current_label, NULL);
1720 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1723 case DW_CFA_MIPS_advance_loc8:
1724 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1725 fde->dw_fde_current_label, NULL);
1726 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1729 case DW_CFA_offset_extended:
1730 case DW_CFA_def_cfa:
1731 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1733 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1736 case DW_CFA_offset_extended_sf:
1737 case DW_CFA_def_cfa_sf:
1738 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1740 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1743 case DW_CFA_restore_extended:
1744 case DW_CFA_undefined:
1745 case DW_CFA_same_value:
1746 case DW_CFA_def_cfa_register:
1747 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1751 case DW_CFA_register:
1752 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1754 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1758 case DW_CFA_def_cfa_offset:
1759 case DW_CFA_GNU_args_size:
1760 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1763 case DW_CFA_def_cfa_offset_sf:
1764 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1767 case DW_CFA_GNU_window_save:
1770 case DW_CFA_def_cfa_expression:
1771 case DW_CFA_expression:
1772 output_cfa_loc (cfi);
1775 case DW_CFA_GNU_negative_offset_extended:
1776 /* Obsoleted by DW_CFA_offset_extended_sf. */
1785 /* Output the call frame information used to used to record information
1786 that relates to calculating the frame pointer, and records the
1787 location of saved registers. */
1790 output_call_frame_info (for_eh)
1796 char l1[20], l2[20], section_start_label[20];
1797 int any_lsda_needed = 0;
1798 char augmentation[6];
1799 int augmentation_size;
1800 int fde_encoding = DW_EH_PE_absptr;
1801 int per_encoding = DW_EH_PE_absptr;
1802 int lsda_encoding = DW_EH_PE_absptr;
1804 /* Don't emit a CIE if there won't be any FDEs. */
1805 if (fde_table_in_use == 0)
1808 /* If we don't have any functions we'll want to unwind out of, don't emit any
1809 EH unwind information. */
1812 int any_eh_needed = flag_asynchronous_unwind_tables;
1814 for (i = 0; i < fde_table_in_use; i++)
1815 if (fde_table[i].uses_eh_lsda)
1816 any_eh_needed = any_lsda_needed = 1;
1817 else if (! fde_table[i].nothrow)
1820 if (! any_eh_needed)
1824 /* We're going to be generating comments, so turn on app. */
1829 (*targetm.asm_out.eh_frame_section) ();
1831 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1833 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1834 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1836 /* Output the CIE. */
1837 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1838 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1839 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1840 "Length of Common Information Entry");
1841 ASM_OUTPUT_LABEL (asm_out_file, l1);
1843 /* Now that the CIE pointer is PC-relative for EH,
1844 use 0 to identify the CIE. */
1845 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1846 (for_eh ? 0 : DW_CIE_ID),
1847 "CIE Identifier Tag");
1849 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1851 augmentation[0] = 0;
1852 augmentation_size = 0;
1858 z Indicates that a uleb128 is present to size the
1859 augmentation section.
1860 L Indicates the encoding (and thus presence) of
1861 an LSDA pointer in the FDE augmentation.
1862 R Indicates a non-default pointer encoding for
1864 P Indicates the presence of an encoding + language
1865 personality routine in the CIE augmentation. */
1867 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1868 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1869 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1871 p = augmentation + 1;
1872 if (eh_personality_libfunc)
1875 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1877 if (any_lsda_needed)
1880 augmentation_size += 1;
1882 if (fde_encoding != DW_EH_PE_absptr)
1885 augmentation_size += 1;
1887 if (p > augmentation + 1)
1889 augmentation[0] = 'z';
1893 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1894 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1896 int offset = ( 4 /* Length */
1898 + 1 /* CIE version */
1899 + strlen (augmentation) + 1 /* Augmentation */
1900 + size_of_uleb128 (1) /* Code alignment */
1901 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1903 + 1 /* Augmentation size */
1904 + 1 /* Personality encoding */ );
1905 int pad = -offset & (PTR_SIZE - 1);
1907 augmentation_size += pad;
1909 /* Augmentations should be small, so there's scarce need to
1910 iterate for a solution. Die if we exceed one uleb128 byte. */
1911 if (size_of_uleb128 (augmentation_size) != 1)
1916 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1917 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1918 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1919 "CIE Data Alignment Factor");
1920 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1922 if (augmentation[0])
1924 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1925 if (eh_personality_libfunc)
1927 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1928 eh_data_format_name (per_encoding));
1929 dw2_asm_output_encoded_addr_rtx (per_encoding,
1930 eh_personality_libfunc, NULL);
1933 if (any_lsda_needed)
1934 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1935 eh_data_format_name (lsda_encoding));
1937 if (fde_encoding != DW_EH_PE_absptr)
1938 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1939 eh_data_format_name (fde_encoding));
1942 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1943 output_cfi (cfi, NULL, for_eh);
1945 /* Pad the CIE out to an address sized boundary. */
1946 ASM_OUTPUT_ALIGN (asm_out_file,
1947 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1948 ASM_OUTPUT_LABEL (asm_out_file, l2);
1950 /* Loop through all of the FDE's. */
1951 for (i = 0; i < fde_table_in_use; i++)
1953 fde = &fde_table[i];
1955 /* Don't emit EH unwind info for leaf functions that don't need it. */
1956 if (!flag_asynchronous_unwind_tables && for_eh
1957 && (fde->nothrow || fde->all_throwers_are_sibcalls)
1958 && !fde->uses_eh_lsda)
1961 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1962 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1963 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1964 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1966 ASM_OUTPUT_LABEL (asm_out_file, l1);
1969 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
1971 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
1976 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1977 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1978 "FDE initial location");
1979 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1980 fde->dw_fde_end, fde->dw_fde_begin,
1981 "FDE address range");
1985 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1986 "FDE initial location");
1987 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1988 fde->dw_fde_end, fde->dw_fde_begin,
1989 "FDE address range");
1992 if (augmentation[0])
1994 if (any_lsda_needed)
1996 int size = size_of_encoded_value (lsda_encoding);
1998 if (lsda_encoding == DW_EH_PE_aligned)
2000 int offset = ( 4 /* Length */
2001 + 4 /* CIE offset */
2002 + 2 * size_of_encoded_value (fde_encoding)
2003 + 1 /* Augmentation size */ );
2004 int pad = -offset & (PTR_SIZE - 1);
2007 if (size_of_uleb128 (size) != 1)
2011 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2013 if (fde->uses_eh_lsda)
2015 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2016 fde->funcdef_number);
2017 dw2_asm_output_encoded_addr_rtx (
2018 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2019 "Language Specific Data Area");
2023 if (lsda_encoding == DW_EH_PE_aligned)
2024 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2026 (size_of_encoded_value (lsda_encoding), 0,
2027 "Language Specific Data Area (none)");
2031 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2034 /* Loop through the Call Frame Instructions associated with
2036 fde->dw_fde_current_label = fde->dw_fde_begin;
2037 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2038 output_cfi (cfi, fde, for_eh);
2040 /* Pad the FDE out to an address sized boundary. */
2041 ASM_OUTPUT_ALIGN (asm_out_file,
2042 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2043 ASM_OUTPUT_LABEL (asm_out_file, l2);
2046 #ifndef EH_FRAME_SECTION_NAME
2048 dw2_asm_output_data (4, 0, "End of Table");
2050 #ifdef MIPS_DEBUGGING_INFO
2051 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2052 get a value of 0. Putting .align 0 after the label fixes it. */
2053 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2056 /* Turn off app to make assembly quicker. */
2061 /* Output a marker (i.e. a label) for the beginning of a function, before
2065 dwarf2out_begin_prologue (line, file)
2066 unsigned int line ATTRIBUTE_UNUSED;
2067 const char *file ATTRIBUTE_UNUSED;
2069 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2072 current_function_func_begin_label = 0;
2074 #ifdef IA64_UNWIND_INFO
2075 /* ??? current_function_func_begin_label is also used by except.c
2076 for call-site information. We must emit this label if it might
2078 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2079 && ! dwarf2out_do_frame ())
2082 if (! dwarf2out_do_frame ())
2086 function_section (current_function_decl);
2087 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2088 current_function_funcdef_no);
2089 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2090 current_function_funcdef_no);
2091 current_function_func_begin_label = get_identifier (label);
2093 #ifdef IA64_UNWIND_INFO
2094 /* We can elide the fde allocation if we're not emitting debug info. */
2095 if (! dwarf2out_do_frame ())
2099 /* Expand the fde table if necessary. */
2100 if (fde_table_in_use == fde_table_allocated)
2102 fde_table_allocated += FDE_TABLE_INCREMENT;
2104 = (dw_fde_ref) xrealloc (fde_table,
2105 fde_table_allocated * sizeof (dw_fde_node));
2108 /* Record the FDE associated with this function. */
2109 current_funcdef_fde = fde_table_in_use;
2111 /* Add the new FDE at the end of the fde_table. */
2112 fde = &fde_table[fde_table_in_use++];
2113 fde->dw_fde_begin = xstrdup (label);
2114 fde->dw_fde_current_label = NULL;
2115 fde->dw_fde_end = NULL;
2116 fde->dw_fde_cfi = NULL;
2117 fde->funcdef_number = current_function_funcdef_no;
2118 fde->nothrow = current_function_nothrow;
2119 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2120 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2122 args_size = old_args_size = 0;
2124 /* We only want to output line number information for the genuine dwarf2
2125 prologue case, not the eh frame case. */
2126 #ifdef DWARF2_DEBUGGING_INFO
2128 dwarf2out_source_line (line, file);
2132 /* Output a marker (i.e. a label) for the absolute end of the generated code
2133 for a function definition. This gets called *after* the epilogue code has
2137 dwarf2out_end_epilogue (line, file)
2138 unsigned int line ATTRIBUTE_UNUSED;
2139 const char *file ATTRIBUTE_UNUSED;
2142 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2144 /* Output a label to mark the endpoint of the code generated for this
2146 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2147 current_function_funcdef_no);
2148 ASM_OUTPUT_LABEL (asm_out_file, label);
2149 fde = &fde_table[fde_table_in_use - 1];
2150 fde->dw_fde_end = xstrdup (label);
2154 dwarf2out_frame_init ()
2156 /* Allocate the initial hunk of the fde_table. */
2157 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2158 fde_table_allocated = FDE_TABLE_INCREMENT;
2159 fde_table_in_use = 0;
2161 /* Generate the CFA instructions common to all FDE's. Do it now for the
2162 sake of lookup_cfa. */
2164 #ifdef DWARF2_UNWIND_INFO
2165 /* On entry, the Canonical Frame Address is at SP. */
2166 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2167 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2172 dwarf2out_frame_finish ()
2174 /* Output call frame information. */
2175 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2176 output_call_frame_info (0);
2178 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2179 output_call_frame_info (1);
2182 /* And now, the subset of the debugging information support code necessary
2183 for emitting location expressions. */
2185 /* We need some way to distinguish DW_OP_addr with a direct symbol
2186 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2187 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2190 typedef struct dw_val_struct *dw_val_ref;
2191 typedef struct die_struct *dw_die_ref;
2192 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2193 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2195 /* Each DIE may have a series of attribute/value pairs. Values
2196 can take on several forms. The forms that are used in this
2197 implementation are listed below. */
2202 dw_val_class_offset,
2204 dw_val_class_loc_list,
2205 dw_val_class_range_list,
2207 dw_val_class_unsigned_const,
2208 dw_val_class_long_long,
2211 dw_val_class_die_ref,
2212 dw_val_class_fde_ref,
2213 dw_val_class_lbl_id,
2214 dw_val_class_lbl_offset,
2219 /* Describe a double word constant value. */
2220 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2222 typedef struct dw_long_long_struct
2229 /* Describe a floating point constant value. */
2231 typedef struct dw_fp_struct
2238 /* The dw_val_node describes an attribute's value, as it is
2239 represented internally. */
2241 typedef struct dw_val_struct
2243 dw_val_class val_class;
2247 long unsigned val_offset;
2248 dw_loc_list_ref val_loc_list;
2249 dw_loc_descr_ref val_loc;
2251 long unsigned val_unsigned;
2252 dw_long_long_const val_long_long;
2253 dw_float_const val_float;
2259 unsigned val_fde_index;
2260 struct indirect_string_node *val_str;
2262 unsigned char val_flag;
2268 /* Locations in memory are described using a sequence of stack machine
2271 typedef struct dw_loc_descr_struct
2273 dw_loc_descr_ref dw_loc_next;
2274 enum dwarf_location_atom dw_loc_opc;
2275 dw_val_node dw_loc_oprnd1;
2276 dw_val_node dw_loc_oprnd2;
2281 /* Location lists are ranges + location descriptions for that range,
2282 so you can track variables that are in different places over
2283 their entire life. */
2284 typedef struct dw_loc_list_struct
2286 dw_loc_list_ref dw_loc_next;
2287 const char *begin; /* Label for begin address of range */
2288 const char *end; /* Label for end address of range */
2289 char *ll_symbol; /* Label for beginning of location list.
2290 Only on head of list */
2291 const char *section; /* Section this loclist is relative to */
2292 dw_loc_descr_ref expr;
2295 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2296 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2299 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2301 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2302 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2303 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2304 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2306 /* Convert a DWARF stack opcode into its string name. */
2309 dwarf_stack_op_name (op)
2315 case INTERNAL_DW_OP_tls_addr:
2316 return "DW_OP_addr";
2318 return "DW_OP_deref";
2320 return "DW_OP_const1u";
2322 return "DW_OP_const1s";
2324 return "DW_OP_const2u";
2326 return "DW_OP_const2s";
2328 return "DW_OP_const4u";
2330 return "DW_OP_const4s";
2332 return "DW_OP_const8u";
2334 return "DW_OP_const8s";
2336 return "DW_OP_constu";
2338 return "DW_OP_consts";
2342 return "DW_OP_drop";
2344 return "DW_OP_over";
2346 return "DW_OP_pick";
2348 return "DW_OP_swap";
2352 return "DW_OP_xderef";
2360 return "DW_OP_minus";
2372 return "DW_OP_plus";
2373 case DW_OP_plus_uconst:
2374 return "DW_OP_plus_uconst";
2380 return "DW_OP_shra";
2398 return "DW_OP_skip";
2400 return "DW_OP_lit0";
2402 return "DW_OP_lit1";
2404 return "DW_OP_lit2";
2406 return "DW_OP_lit3";
2408 return "DW_OP_lit4";
2410 return "DW_OP_lit5";
2412 return "DW_OP_lit6";
2414 return "DW_OP_lit7";
2416 return "DW_OP_lit8";
2418 return "DW_OP_lit9";
2420 return "DW_OP_lit10";
2422 return "DW_OP_lit11";
2424 return "DW_OP_lit12";
2426 return "DW_OP_lit13";
2428 return "DW_OP_lit14";
2430 return "DW_OP_lit15";
2432 return "DW_OP_lit16";
2434 return "DW_OP_lit17";
2436 return "DW_OP_lit18";
2438 return "DW_OP_lit19";
2440 return "DW_OP_lit20";
2442 return "DW_OP_lit21";
2444 return "DW_OP_lit22";
2446 return "DW_OP_lit23";
2448 return "DW_OP_lit24";
2450 return "DW_OP_lit25";
2452 return "DW_OP_lit26";
2454 return "DW_OP_lit27";
2456 return "DW_OP_lit28";
2458 return "DW_OP_lit29";
2460 return "DW_OP_lit30";
2462 return "DW_OP_lit31";
2464 return "DW_OP_reg0";
2466 return "DW_OP_reg1";
2468 return "DW_OP_reg2";
2470 return "DW_OP_reg3";
2472 return "DW_OP_reg4";
2474 return "DW_OP_reg5";
2476 return "DW_OP_reg6";
2478 return "DW_OP_reg7";
2480 return "DW_OP_reg8";
2482 return "DW_OP_reg9";
2484 return "DW_OP_reg10";
2486 return "DW_OP_reg11";
2488 return "DW_OP_reg12";
2490 return "DW_OP_reg13";
2492 return "DW_OP_reg14";
2494 return "DW_OP_reg15";
2496 return "DW_OP_reg16";
2498 return "DW_OP_reg17";
2500 return "DW_OP_reg18";
2502 return "DW_OP_reg19";
2504 return "DW_OP_reg20";
2506 return "DW_OP_reg21";
2508 return "DW_OP_reg22";
2510 return "DW_OP_reg23";
2512 return "DW_OP_reg24";
2514 return "DW_OP_reg25";
2516 return "DW_OP_reg26";
2518 return "DW_OP_reg27";
2520 return "DW_OP_reg28";
2522 return "DW_OP_reg29";
2524 return "DW_OP_reg30";
2526 return "DW_OP_reg31";
2528 return "DW_OP_breg0";
2530 return "DW_OP_breg1";
2532 return "DW_OP_breg2";
2534 return "DW_OP_breg3";
2536 return "DW_OP_breg4";
2538 return "DW_OP_breg5";
2540 return "DW_OP_breg6";
2542 return "DW_OP_breg7";
2544 return "DW_OP_breg8";
2546 return "DW_OP_breg9";
2548 return "DW_OP_breg10";
2550 return "DW_OP_breg11";
2552 return "DW_OP_breg12";
2554 return "DW_OP_breg13";
2556 return "DW_OP_breg14";
2558 return "DW_OP_breg15";
2560 return "DW_OP_breg16";
2562 return "DW_OP_breg17";
2564 return "DW_OP_breg18";
2566 return "DW_OP_breg19";
2568 return "DW_OP_breg20";
2570 return "DW_OP_breg21";
2572 return "DW_OP_breg22";
2574 return "DW_OP_breg23";
2576 return "DW_OP_breg24";
2578 return "DW_OP_breg25";
2580 return "DW_OP_breg26";
2582 return "DW_OP_breg27";
2584 return "DW_OP_breg28";
2586 return "DW_OP_breg29";
2588 return "DW_OP_breg30";
2590 return "DW_OP_breg31";
2592 return "DW_OP_regx";
2594 return "DW_OP_fbreg";
2596 return "DW_OP_bregx";
2598 return "DW_OP_piece";
2599 case DW_OP_deref_size:
2600 return "DW_OP_deref_size";
2601 case DW_OP_xderef_size:
2602 return "DW_OP_xderef_size";
2605 case DW_OP_push_object_address:
2606 return "DW_OP_push_object_address";
2608 return "DW_OP_call2";
2610 return "DW_OP_call4";
2611 case DW_OP_call_ref:
2612 return "DW_OP_call_ref";
2613 case DW_OP_GNU_push_tls_address:
2614 return "DW_OP_GNU_push_tls_address";
2616 return "OP_<unknown>";
2620 /* Return a pointer to a newly allocated location description. Location
2621 descriptions are simple expression terms that can be strung
2622 together to form more complicated location (address) descriptions. */
2624 static inline dw_loc_descr_ref
2625 new_loc_descr (op, oprnd1, oprnd2)
2626 enum dwarf_location_atom op;
2627 unsigned long oprnd1;
2628 unsigned long oprnd2;
2630 /* Use xcalloc here so we clear out all of the long_long constant in
2632 dw_loc_descr_ref descr
2633 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2635 descr->dw_loc_opc = op;
2636 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2637 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2638 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2639 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2645 /* Add a location description term to a location description expression. */
2648 add_loc_descr (list_head, descr)
2649 dw_loc_descr_ref *list_head;
2650 dw_loc_descr_ref descr;
2652 dw_loc_descr_ref *d;
2654 /* Find the end of the chain. */
2655 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2661 /* Return the size of a location descriptor. */
2663 static unsigned long
2664 size_of_loc_descr (loc)
2665 dw_loc_descr_ref loc;
2667 unsigned long size = 1;
2669 switch (loc->dw_loc_opc)
2672 case INTERNAL_DW_OP_tls_addr:
2673 size += DWARF2_ADDR_SIZE;
2692 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2695 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2700 case DW_OP_plus_uconst:
2701 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2739 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2742 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2745 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2748 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2749 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2752 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2754 case DW_OP_deref_size:
2755 case DW_OP_xderef_size:
2764 case DW_OP_call_ref:
2765 size += DWARF2_ADDR_SIZE;
2774 /* Return the size of a series of location descriptors. */
2776 static unsigned long
2778 dw_loc_descr_ref loc;
2782 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2784 loc->dw_loc_addr = size;
2785 size += size_of_loc_descr (loc);
2791 /* Output location description stack opcode's operands (if any). */
2794 output_loc_operands (loc)
2795 dw_loc_descr_ref loc;
2797 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2798 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2800 switch (loc->dw_loc_opc)
2802 #ifdef DWARF2_DEBUGGING_INFO
2804 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2808 dw2_asm_output_data (2, val1->v.val_int, NULL);
2812 dw2_asm_output_data (4, val1->v.val_int, NULL);
2816 if (HOST_BITS_PER_LONG < 64)
2818 dw2_asm_output_data (8, val1->v.val_int, NULL);
2825 if (val1->val_class == dw_val_class_loc)
2826 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2830 dw2_asm_output_data (2, offset, NULL);
2843 /* We currently don't make any attempt to make sure these are
2844 aligned properly like we do for the main unwind info, so
2845 don't support emitting things larger than a byte if we're
2846 only doing unwinding. */
2851 dw2_asm_output_data (1, val1->v.val_int, NULL);
2854 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2857 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2860 dw2_asm_output_data (1, val1->v.val_int, NULL);
2862 case DW_OP_plus_uconst:
2863 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2897 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2900 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2903 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2906 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2907 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2910 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2912 case DW_OP_deref_size:
2913 case DW_OP_xderef_size:
2914 dw2_asm_output_data (1, val1->v.val_int, NULL);
2917 case INTERNAL_DW_OP_tls_addr:
2918 #ifdef ASM_OUTPUT_DWARF_DTPREL
2919 ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE,
2921 fputc ('\n', asm_out_file);
2928 /* Other codes have no operands. */
2933 /* Output a sequence of location operations. */
2936 output_loc_sequence (loc)
2937 dw_loc_descr_ref loc;
2939 for (; loc != NULL; loc = loc->dw_loc_next)
2941 /* Output the opcode. */
2942 dw2_asm_output_data (1, loc->dw_loc_opc,
2943 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2945 /* Output the operand(s) (if any). */
2946 output_loc_operands (loc);
2950 /* This routine will generate the correct assembly data for a location
2951 description based on a cfi entry with a complex address. */
2954 output_cfa_loc (cfi)
2957 dw_loc_descr_ref loc;
2960 /* Output the size of the block. */
2961 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2962 size = size_of_locs (loc);
2963 dw2_asm_output_data_uleb128 (size, NULL);
2965 /* Now output the operations themselves. */
2966 output_loc_sequence (loc);
2969 /* This function builds a dwarf location descriptor sequence from
2970 a dw_cfa_location. */
2972 static struct dw_loc_descr_struct *
2974 dw_cfa_location *cfa;
2976 struct dw_loc_descr_struct *head, *tmp;
2978 if (cfa->indirect == 0)
2981 if (cfa->base_offset)
2984 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2986 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2988 else if (cfa->reg <= 31)
2989 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2991 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2993 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2994 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2995 add_loc_descr (&head, tmp);
2996 if (cfa->offset != 0)
2998 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2999 add_loc_descr (&head, tmp);
3005 /* This function fills in aa dw_cfa_location structure from a dwarf location
3006 descriptor sequence. */
3009 get_cfa_from_loc_descr (cfa, loc)
3010 dw_cfa_location *cfa;
3011 struct dw_loc_descr_struct *loc;
3013 struct dw_loc_descr_struct *ptr;
3015 cfa->base_offset = 0;
3019 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3021 enum dwarf_location_atom op = ptr->dw_loc_opc;
3057 cfa->reg = op - DW_OP_reg0;
3060 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3094 cfa->reg = op - DW_OP_breg0;
3095 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3098 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3099 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3104 case DW_OP_plus_uconst:
3105 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3108 internal_error ("DW_LOC_OP %s not implemented\n",
3109 dwarf_stack_op_name (ptr->dw_loc_opc));
3113 #endif /* .debug_frame support */
3115 /* And now, the support for symbolic debugging information. */
3116 #ifdef DWARF2_DEBUGGING_INFO
3118 /* .debug_str support. */
3119 static hashnode indirect_string_alloc PARAMS ((hash_table *));
3120 static int output_indirect_string PARAMS ((struct cpp_reader *,
3121 hashnode, const PTR));
3124 static void dwarf2out_init PARAMS ((const char *));
3125 static void dwarf2out_finish PARAMS ((const char *));
3126 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3127 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3128 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3129 static void dwarf2out_end_source_file PARAMS ((unsigned));
3130 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3131 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3132 static bool dwarf2out_ignore_block PARAMS ((tree));
3133 static void dwarf2out_global_decl PARAMS ((tree));
3134 static void dwarf2out_abstract_function PARAMS ((tree));
3136 /* The debug hooks structure. */
3138 const struct gcc_debug_hooks dwarf2_debug_hooks =
3144 dwarf2out_start_source_file,
3145 dwarf2out_end_source_file,
3146 dwarf2out_begin_block,
3147 dwarf2out_end_block,
3148 dwarf2out_ignore_block,
3149 dwarf2out_source_line,
3150 dwarf2out_begin_prologue,
3151 debug_nothing_int_charstar, /* end_prologue */
3152 dwarf2out_end_epilogue,
3153 debug_nothing_tree, /* begin_function */
3154 debug_nothing_int, /* end_function */
3155 dwarf2out_decl, /* function_decl */
3156 dwarf2out_global_decl,
3157 debug_nothing_tree, /* deferred_inline_function */
3158 /* The DWARF 2 backend tries to reduce debugging bloat by not
3159 emitting the abstract description of inline functions until
3160 something tries to reference them. */
3161 dwarf2out_abstract_function, /* outlining_inline_function */
3162 debug_nothing_rtx /* label */
3165 /* NOTE: In the comments in this file, many references are made to
3166 "Debugging Information Entries". This term is abbreviated as `DIE'
3167 throughout the remainder of this file. */
3169 /* An internal representation of the DWARF output is built, and then
3170 walked to generate the DWARF debugging info. The walk of the internal
3171 representation is done after the entire program has been compiled.
3172 The types below are used to describe the internal representation. */
3174 /* Various DIE's use offsets relative to the beginning of the
3175 .debug_info section to refer to each other. */
3177 typedef long int dw_offset;
3179 /* Define typedefs here to avoid circular dependencies. */
3181 typedef struct dw_attr_struct *dw_attr_ref;
3182 typedef struct dw_line_info_struct *dw_line_info_ref;
3183 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3184 typedef struct pubname_struct *pubname_ref;
3185 typedef struct dw_ranges_struct *dw_ranges_ref;
3187 /* Each entry in the line_info_table maintains the file and
3188 line number associated with the label generated for that
3189 entry. The label gives the PC value associated with
3190 the line number entry. */
3192 typedef struct dw_line_info_struct
3194 unsigned long dw_file_num;
3195 unsigned long dw_line_num;
3199 /* Line information for functions in separate sections; each one gets its
3201 typedef struct dw_separate_line_info_struct
3203 unsigned long dw_file_num;
3204 unsigned long dw_line_num;
3205 unsigned long function;
3207 dw_separate_line_info_entry;
3209 /* Each DIE attribute has a field specifying the attribute kind,
3210 a link to the next attribute in the chain, and an attribute value.
3211 Attributes are typically linked below the DIE they modify. */
3213 typedef struct dw_attr_struct
3215 enum dwarf_attribute dw_attr;
3216 dw_attr_ref dw_attr_next;
3217 dw_val_node dw_attr_val;
3221 /* The Debugging Information Entry (DIE) structure */
3223 typedef struct die_struct
3225 enum dwarf_tag die_tag;
3227 dw_attr_ref die_attr;
3228 dw_die_ref die_parent;
3229 dw_die_ref die_child;
3231 dw_offset die_offset;
3232 unsigned long die_abbrev;
3237 /* The pubname structure */
3239 typedef struct pubname_struct
3246 struct dw_ranges_struct
3251 /* The limbo die list structure. */
3252 typedef struct limbo_die_struct
3256 struct limbo_die_struct *next;
3260 /* How to start an assembler comment. */
3261 #ifndef ASM_COMMENT_START
3262 #define ASM_COMMENT_START ";#"
3265 /* Define a macro which returns non-zero for a TYPE_DECL which was
3266 implicitly generated for a tagged type.
3268 Note that unlike the gcc front end (which generates a NULL named
3269 TYPE_DECL node for each complete tagged type, each array type, and
3270 each function type node created) the g++ front end generates a
3271 _named_ TYPE_DECL node for each tagged type node created.
3272 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3273 generate a DW_TAG_typedef DIE for them. */
3275 #define TYPE_DECL_IS_STUB(decl) \
3276 (DECL_NAME (decl) == NULL_TREE \
3277 || (DECL_ARTIFICIAL (decl) \
3278 && is_tagged_type (TREE_TYPE (decl)) \
3279 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3280 /* This is necessary for stub decls that \
3281 appear in nested inline functions. */ \
3282 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3283 && (decl_ultimate_origin (decl) \
3284 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3286 /* Information concerning the compilation unit's programming
3287 language, and compiler version. */
3289 /* Fixed size portion of the DWARF compilation unit header. */
3290 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3292 /* Fixed size portion of public names info. */
3293 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3295 /* Fixed size portion of the address range info. */
3296 #define DWARF_ARANGES_HEADER_SIZE \
3297 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3298 - DWARF_OFFSET_SIZE)
3300 /* Size of padding portion in the address range info. It must be
3301 aligned to twice the pointer size. */
3302 #define DWARF_ARANGES_PAD_SIZE \
3303 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3304 - (2 * DWARF_OFFSET_SIZE + 4))
3306 /* Use assembler line directives if available. */
3307 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3308 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3309 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3311 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3315 /* Minimum line offset in a special line info. opcode.
3316 This value was chosen to give a reasonable range of values. */
3317 #define DWARF_LINE_BASE -10
3319 /* First special line opcode - leave room for the standard opcodes. */
3320 #define DWARF_LINE_OPCODE_BASE 10
3322 /* Range of line offsets in a special line info. opcode. */
3323 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3325 /* Flag that indicates the initial value of the is_stmt_start flag.
3326 In the present implementation, we do not mark any lines as
3327 the beginning of a source statement, because that information
3328 is not made available by the GCC front-end. */
3329 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3331 /* This location is used by calc_die_sizes() to keep track
3332 the offset of each DIE within the .debug_info section. */
3333 static unsigned long next_die_offset;
3335 /* Record the root of the DIE's built for the current compilation unit. */
3336 static dw_die_ref comp_unit_die;
3338 /* A list of DIEs with a NULL parent waiting to be relocated. */
3339 static limbo_die_node *limbo_die_list = 0;
3341 /* Structure used by lookup_filename to manage sets of filenames. */
3347 unsigned last_lookup_index;
3350 /* Size (in elements) of increments by which we may expand the filename
3352 #define FILE_TABLE_INCREMENT 64
3354 /* Filenames referenced by this compilation unit. */
3355 static struct file_table file_table;
3357 /* Local pointer to the name of the main input file. Initialized in
3359 static const char *primary_filename;
3361 /* A pointer to the base of a table of references to DIE's that describe
3362 declarations. The table is indexed by DECL_UID() which is a unique
3363 number identifying each decl. */
3364 static dw_die_ref *decl_die_table;
3366 /* Number of elements currently allocated for the decl_die_table. */
3367 static unsigned decl_die_table_allocated;
3369 /* Number of elements in decl_die_table currently in use. */
3370 static unsigned decl_die_table_in_use;
3372 /* Size (in elements) of increments by which we may expand the
3374 #define DECL_DIE_TABLE_INCREMENT 256
3376 /* A pointer to the base of a list of references to DIE's that
3377 are uniquely identified by their tag, presence/absence of
3378 children DIE's, and list of attribute/value pairs. */
3379 static dw_die_ref *abbrev_die_table;
3381 /* Number of elements currently allocated for abbrev_die_table. */
3382 static unsigned abbrev_die_table_allocated;
3384 /* Number of elements in type_die_table currently in use. */
3385 static unsigned abbrev_die_table_in_use;
3387 /* Size (in elements) of increments by which we may expand the
3388 abbrev_die_table. */
3389 #define ABBREV_DIE_TABLE_INCREMENT 256
3391 /* A pointer to the base of a table that contains line information
3392 for each source code line in .text in the compilation unit. */
3393 static dw_line_info_ref line_info_table;
3395 /* Number of elements currently allocated for line_info_table. */
3396 static unsigned line_info_table_allocated;
3398 /* Number of elements in separate_line_info_table currently in use. */
3399 static unsigned separate_line_info_table_in_use;
3401 /* A pointer to the base of a table that contains line information
3402 for each source code line outside of .text in the compilation unit. */
3403 static dw_separate_line_info_ref separate_line_info_table;
3405 /* Number of elements currently allocated for separate_line_info_table. */
3406 static unsigned separate_line_info_table_allocated;
3408 /* Number of elements in line_info_table currently in use. */
3409 static unsigned line_info_table_in_use;
3411 /* Size (in elements) of increments by which we may expand the
3413 #define LINE_INFO_TABLE_INCREMENT 1024
3415 /* A pointer to the base of a table that contains a list of publicly
3416 accessible names. */
3417 static pubname_ref pubname_table;
3419 /* Number of elements currently allocated for pubname_table. */
3420 static unsigned pubname_table_allocated;
3422 /* Number of elements in pubname_table currently in use. */
3423 static unsigned pubname_table_in_use;
3425 /* Size (in elements) of increments by which we may expand the
3427 #define PUBNAME_TABLE_INCREMENT 64
3429 /* Array of dies for which we should generate .debug_arange info. */
3430 static dw_die_ref *arange_table;
3432 /* Number of elements currently allocated for arange_table. */
3433 static unsigned arange_table_allocated;
3435 /* Number of elements in arange_table currently in use. */
3436 static unsigned arange_table_in_use;
3438 /* Size (in elements) of increments by which we may expand the
3440 #define ARANGE_TABLE_INCREMENT 64
3442 /* Array of dies for which we should generate .debug_ranges info. */
3443 static dw_ranges_ref ranges_table;
3445 /* Number of elements currently allocated for ranges_table. */
3446 static unsigned ranges_table_allocated;
3448 /* Number of elements in ranges_table currently in use. */
3449 static unsigned ranges_table_in_use;
3451 /* Size (in elements) of increments by which we may expand the
3453 #define RANGES_TABLE_INCREMENT 64
3455 /* Whether we have location lists that need outputting */
3456 static unsigned have_location_lists;
3458 /* Record whether the function being analyzed contains inlined functions. */
3459 static int current_function_has_inlines;
3460 #if 0 && defined (MIPS_DEBUGGING_INFO)
3461 static int comp_unit_has_inlines;
3464 /* Forward declarations for functions defined in this file. */
3466 static int is_pseudo_reg PARAMS ((rtx));
3467 static tree type_main_variant PARAMS ((tree));
3468 static int is_tagged_type PARAMS ((tree));
3469 static const char *dwarf_tag_name PARAMS ((unsigned));
3470 static const char *dwarf_attr_name PARAMS ((unsigned));
3471 static const char *dwarf_form_name PARAMS ((unsigned));
3473 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3475 static tree decl_ultimate_origin PARAMS ((tree));
3476 static tree block_ultimate_origin PARAMS ((tree));
3477 static tree decl_class_context PARAMS ((tree));
3478 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3479 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
3480 static void add_AT_flag PARAMS ((dw_die_ref,
3481 enum dwarf_attribute,
3483 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3484 static void add_AT_int PARAMS ((dw_die_ref,
3485 enum dwarf_attribute, long));
3486 static inline long int AT_int PARAMS ((dw_attr_ref));
3487 static void add_AT_unsigned PARAMS ((dw_die_ref,
3488 enum dwarf_attribute,
3490 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
3491 static void add_AT_long_long PARAMS ((dw_die_ref,
3492 enum dwarf_attribute,
3495 static void add_AT_float PARAMS ((dw_die_ref,
3496 enum dwarf_attribute,
3498 static void add_AT_string PARAMS ((dw_die_ref,
3499 enum dwarf_attribute,
3501 static inline const char *AT_string PARAMS ((dw_attr_ref));
3502 static int AT_string_form PARAMS ((dw_attr_ref));
3503 static void add_AT_die_ref PARAMS ((dw_die_ref,
3504 enum dwarf_attribute,
3506 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
3507 static inline int AT_ref_external PARAMS ((dw_attr_ref));
3508 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
3509 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3510 enum dwarf_attribute,
3512 static void add_AT_loc PARAMS ((dw_die_ref,
3513 enum dwarf_attribute,
3515 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
3516 static void add_AT_loc_list PARAMS ((dw_die_ref,
3517 enum dwarf_attribute,
3519 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
3520 static void add_AT_addr PARAMS ((dw_die_ref,
3521 enum dwarf_attribute,
3523 static inline rtx AT_addr PARAMS ((dw_attr_ref));
3524 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3525 enum dwarf_attribute,
3527 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3528 enum dwarf_attribute,
3530 static void add_AT_offset PARAMS ((dw_die_ref,
3531 enum dwarf_attribute,
3533 static void add_AT_range_list PARAMS ((dw_die_ref,
3534 enum dwarf_attribute,
3536 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
3537 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3538 enum dwarf_attribute));
3539 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3540 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3541 static const char *get_AT_string PARAMS ((dw_die_ref,
3542 enum dwarf_attribute));
3543 static int get_AT_flag PARAMS ((dw_die_ref,
3544 enum dwarf_attribute));
3545 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3546 enum dwarf_attribute));
3547 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3548 enum dwarf_attribute));
3549 static int is_c_family PARAMS ((void));
3550 static int is_cxx PARAMS ((void));
3551 static int is_java PARAMS ((void));
3552 static int is_fortran PARAMS ((void));
3553 static void remove_AT PARAMS ((dw_die_ref,
3554 enum dwarf_attribute));
3555 static inline void free_die PARAMS ((dw_die_ref));
3556 static void remove_children PARAMS ((dw_die_ref));
3557 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3558 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref,
3560 static dw_die_ref lookup_type_die PARAMS ((tree));
3561 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3562 static dw_die_ref lookup_decl_die PARAMS ((tree));
3563 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3564 static void print_spaces PARAMS ((FILE *));
3565 static void print_die PARAMS ((dw_die_ref, FILE *));
3566 static void print_dwarf_line_table PARAMS ((FILE *));
3567 static void reverse_die_lists PARAMS ((dw_die_ref));
3568 static void reverse_all_dies PARAMS ((dw_die_ref));
3569 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3570 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3571 static void loc_checksum PARAMS ((dw_loc_descr_ref,
3573 static void attr_checksum PARAMS ((dw_attr_ref,
3575 static void die_checksum PARAMS ((dw_die_ref,
3577 static void compute_section_prefix PARAMS ((dw_die_ref));
3578 static int is_type_die PARAMS ((dw_die_ref));
3579 static int is_comdat_die PARAMS ((dw_die_ref));
3580 static int is_symbol_die PARAMS ((dw_die_ref));
3581 static void assign_symbol_names PARAMS ((dw_die_ref));
3582 static void break_out_includes PARAMS ((dw_die_ref));
3583 static void add_sibling_attributes PARAMS ((dw_die_ref));
3584 static void build_abbrev_table PARAMS ((dw_die_ref));
3585 static void output_location_lists PARAMS ((dw_die_ref));
3586 static int constant_size PARAMS ((long unsigned));
3587 static unsigned long size_of_die PARAMS ((dw_die_ref));
3588 static void calc_die_sizes PARAMS ((dw_die_ref));
3589 static void mark_dies PARAMS ((dw_die_ref));
3590 static void unmark_dies PARAMS ((dw_die_ref));
3591 static unsigned long size_of_pubnames PARAMS ((void));
3592 static unsigned long size_of_aranges PARAMS ((void));
3593 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3594 static void output_value_format PARAMS ((dw_attr_ref));
3595 static void output_abbrev_section PARAMS ((void));
3596 static void output_die_symbol PARAMS ((dw_die_ref));
3597 static void output_die PARAMS ((dw_die_ref));
3598 static void output_compilation_unit_header PARAMS ((void));
3599 static void output_comp_unit PARAMS ((dw_die_ref));
3600 static const char *dwarf2_name PARAMS ((tree, int));
3601 static void add_pubname PARAMS ((tree, dw_die_ref));
3602 static void output_pubnames PARAMS ((void));
3603 static void add_arange PARAMS ((tree, dw_die_ref));
3604 static void output_aranges PARAMS ((void));
3605 static unsigned int add_ranges PARAMS ((tree));
3606 static void output_ranges PARAMS ((void));
3607 static void output_line_info PARAMS ((void));
3608 static void output_file_names PARAMS ((void));
3609 static dw_die_ref base_type_die PARAMS ((tree));
3610 static tree root_type PARAMS ((tree));
3611 static int is_base_type PARAMS ((tree));
3612 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3613 static int type_is_enum PARAMS ((tree));
3614 static unsigned int reg_number PARAMS ((rtx));
3615 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3616 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3617 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3618 static int is_based_loc PARAMS ((rtx));
3619 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3620 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3621 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3622 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3623 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3624 static tree field_type PARAMS ((tree));
3625 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3626 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3627 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3628 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3629 static void add_AT_location_description PARAMS ((dw_die_ref,
3630 enum dwarf_attribute,
3632 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3633 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3634 static rtx rtl_for_decl_location PARAMS ((tree));
3635 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3636 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3637 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3638 static void add_bound_info PARAMS ((dw_die_ref,
3639 enum dwarf_attribute, tree));
3640 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3641 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3642 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3643 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3644 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3645 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3646 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3647 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3648 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3649 static void push_decl_scope PARAMS ((tree));
3650 static void pop_decl_scope PARAMS ((void));
3651 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3652 static inline int local_scope_p PARAMS ((dw_die_ref));
3653 static inline int class_scope_p PARAMS ((dw_die_ref));
3654 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3656 static const char *type_tag PARAMS ((tree));
3657 static tree member_declared_type PARAMS ((tree));
3659 static const char *decl_start_label PARAMS ((tree));
3661 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3662 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3664 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3666 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3667 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3668 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3669 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3670 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3671 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3672 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3673 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3674 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3675 static void gen_label_die PARAMS ((tree, dw_die_ref));
3676 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3677 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3678 static void gen_field_die PARAMS ((tree, dw_die_ref));
3679 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3680 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3681 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3682 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3683 static void gen_member_die PARAMS ((tree, dw_die_ref));
3684 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3685 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3686 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3687 static void gen_type_die PARAMS ((tree, dw_die_ref));
3688 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3689 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3690 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3691 static int is_redundant_typedef PARAMS ((tree));
3692 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3693 static unsigned lookup_filename PARAMS ((const char *));
3694 static void init_file_table PARAMS ((void));
3695 static void retry_incomplete_types PARAMS ((void));
3696 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3697 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3698 static int file_info_cmp PARAMS ((const void *, const void *));
3699 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3700 const char *, const char *,
3701 const char *, unsigned));
3702 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3704 const char *, const char *, const char *));
3705 static void output_loc_list PARAMS ((dw_loc_list_ref));
3706 static char *gen_internal_sym PARAMS ((const char *));
3707 static void mark_limbo_die_list PARAMS ((void *));
3709 /* Section names used to hold DWARF debugging information. */
3710 #ifndef DEBUG_INFO_SECTION
3711 #define DEBUG_INFO_SECTION ".debug_info"
3713 #ifndef DEBUG_ABBREV_SECTION
3714 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3716 #ifndef DEBUG_ARANGES_SECTION
3717 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3719 #ifndef DEBUG_MACINFO_SECTION
3720 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3722 #ifndef DEBUG_LINE_SECTION
3723 #define DEBUG_LINE_SECTION ".debug_line"
3725 #ifndef DEBUG_LOC_SECTION
3726 #define DEBUG_LOC_SECTION ".debug_loc"
3728 #ifndef DEBUG_PUBNAMES_SECTION
3729 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3731 #ifndef DEBUG_STR_SECTION
3732 #define DEBUG_STR_SECTION ".debug_str"
3734 #ifndef DEBUG_RANGES_SECTION
3735 #define DEBUG_RANGES_SECTION ".debug_ranges"
3738 /* Standard ELF section names for compiled code and data. */
3739 #ifndef TEXT_SECTION_NAME
3740 #define TEXT_SECTION_NAME ".text"
3743 /* Section flags for .debug_str section. */
3744 #ifdef HAVE_GAS_SHF_MERGE
3745 #define DEBUG_STR_SECTION_FLAGS \
3746 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3748 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3751 /* Labels we insert at beginning sections we can reference instead of
3752 the section names themselves. */
3754 #ifndef TEXT_SECTION_LABEL
3755 #define TEXT_SECTION_LABEL "Ltext"
3757 #ifndef DEBUG_LINE_SECTION_LABEL
3758 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3760 #ifndef DEBUG_INFO_SECTION_LABEL
3761 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3763 #ifndef DEBUG_ABBREV_SECTION_LABEL
3764 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3766 #ifndef DEBUG_LOC_SECTION_LABEL
3767 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3769 #ifndef DEBUG_RANGES_SECTION_LABEL
3770 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3772 #ifndef DEBUG_MACINFO_SECTION_LABEL
3773 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3776 /* Definitions of defaults for formats and names of various special
3777 (artificial) labels which may be generated within this file (when the -g
3778 options is used and DWARF_DEBUGGING_INFO is in effect.
3779 If necessary, these may be overridden from within the tm.h file, but
3780 typically, overriding these defaults is unnecessary. */
3782 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3783 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3784 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3785 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3786 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3787 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3788 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3789 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3791 #ifndef TEXT_END_LABEL
3792 #define TEXT_END_LABEL "Letext"
3794 #ifndef BLOCK_BEGIN_LABEL
3795 #define BLOCK_BEGIN_LABEL "LBB"
3797 #ifndef BLOCK_END_LABEL
3798 #define BLOCK_END_LABEL "LBE"
3800 #ifndef LINE_CODE_LABEL
3801 #define LINE_CODE_LABEL "LM"
3803 #ifndef SEPARATE_LINE_CODE_LABEL
3804 #define SEPARATE_LINE_CODE_LABEL "LSM"
3807 /* We allow a language front-end to designate a function that is to be
3808 called to "demangle" any name before it it put into a DIE. */
3810 static const char *(*demangle_name_func) PARAMS ((const char *));
3813 dwarf2out_set_demangle_name_func (func)
3814 const char *(*func) PARAMS ((const char *));
3816 demangle_name_func = func;
3819 /* Test if rtl node points to a pseudo register. */
3825 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3826 || (GET_CODE (rtl) == SUBREG
3827 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3830 /* Return a reference to a type, with its const and volatile qualifiers
3834 type_main_variant (type)
3837 type = TYPE_MAIN_VARIANT (type);
3839 /* ??? There really should be only one main variant among any group of
3840 variants of a given type (and all of the MAIN_VARIANT values for all
3841 members of the group should point to that one type) but sometimes the C
3842 front-end messes this up for array types, so we work around that bug
3844 if (TREE_CODE (type) == ARRAY_TYPE)
3845 while (type != TYPE_MAIN_VARIANT (type))
3846 type = TYPE_MAIN_VARIANT (type);
3851 /* Return non-zero if the given type node represents a tagged type. */
3854 is_tagged_type (type)
3857 enum tree_code code = TREE_CODE (type);
3859 return (code == RECORD_TYPE || code == UNION_TYPE
3860 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3863 /* Convert a DIE tag into its string name. */
3866 dwarf_tag_name (tag)
3871 case DW_TAG_padding:
3872 return "DW_TAG_padding";
3873 case DW_TAG_array_type:
3874 return "DW_TAG_array_type";
3875 case DW_TAG_class_type:
3876 return "DW_TAG_class_type";
3877 case DW_TAG_entry_point:
3878 return "DW_TAG_entry_point";
3879 case DW_TAG_enumeration_type:
3880 return "DW_TAG_enumeration_type";
3881 case DW_TAG_formal_parameter:
3882 return "DW_TAG_formal_parameter";
3883 case DW_TAG_imported_declaration:
3884 return "DW_TAG_imported_declaration";
3886 return "DW_TAG_label";
3887 case DW_TAG_lexical_block:
3888 return "DW_TAG_lexical_block";
3890 return "DW_TAG_member";
3891 case DW_TAG_pointer_type:
3892 return "DW_TAG_pointer_type";
3893 case DW_TAG_reference_type:
3894 return "DW_TAG_reference_type";
3895 case DW_TAG_compile_unit:
3896 return "DW_TAG_compile_unit";
3897 case DW_TAG_string_type:
3898 return "DW_TAG_string_type";
3899 case DW_TAG_structure_type:
3900 return "DW_TAG_structure_type";
3901 case DW_TAG_subroutine_type:
3902 return "DW_TAG_subroutine_type";
3903 case DW_TAG_typedef:
3904 return "DW_TAG_typedef";
3905 case DW_TAG_union_type:
3906 return "DW_TAG_union_type";
3907 case DW_TAG_unspecified_parameters:
3908 return "DW_TAG_unspecified_parameters";
3909 case DW_TAG_variant:
3910 return "DW_TAG_variant";
3911 case DW_TAG_common_block:
3912 return "DW_TAG_common_block";
3913 case DW_TAG_common_inclusion:
3914 return "DW_TAG_common_inclusion";
3915 case DW_TAG_inheritance:
3916 return "DW_TAG_inheritance";
3917 case DW_TAG_inlined_subroutine:
3918 return "DW_TAG_inlined_subroutine";
3920 return "DW_TAG_module";
3921 case DW_TAG_ptr_to_member_type:
3922 return "DW_TAG_ptr_to_member_type";
3923 case DW_TAG_set_type:
3924 return "DW_TAG_set_type";
3925 case DW_TAG_subrange_type:
3926 return "DW_TAG_subrange_type";
3927 case DW_TAG_with_stmt:
3928 return "DW_TAG_with_stmt";
3929 case DW_TAG_access_declaration:
3930 return "DW_TAG_access_declaration";
3931 case DW_TAG_base_type:
3932 return "DW_TAG_base_type";
3933 case DW_TAG_catch_block:
3934 return "DW_TAG_catch_block";
3935 case DW_TAG_const_type:
3936 return "DW_TAG_const_type";
3937 case DW_TAG_constant:
3938 return "DW_TAG_constant";
3939 case DW_TAG_enumerator:
3940 return "DW_TAG_enumerator";
3941 case DW_TAG_file_type:
3942 return "DW_TAG_file_type";
3944 return "DW_TAG_friend";
3945 case DW_TAG_namelist:
3946 return "DW_TAG_namelist";
3947 case DW_TAG_namelist_item:
3948 return "DW_TAG_namelist_item";
3949 case DW_TAG_packed_type:
3950 return "DW_TAG_packed_type";
3951 case DW_TAG_subprogram:
3952 return "DW_TAG_subprogram";
3953 case DW_TAG_template_type_param:
3954 return "DW_TAG_template_type_param";
3955 case DW_TAG_template_value_param:
3956 return "DW_TAG_template_value_param";
3957 case DW_TAG_thrown_type:
3958 return "DW_TAG_thrown_type";
3959 case DW_TAG_try_block:
3960 return "DW_TAG_try_block";
3961 case DW_TAG_variant_part:
3962 return "DW_TAG_variant_part";
3963 case DW_TAG_variable:
3964 return "DW_TAG_variable";
3965 case DW_TAG_volatile_type:
3966 return "DW_TAG_volatile_type";
3967 case DW_TAG_MIPS_loop:
3968 return "DW_TAG_MIPS_loop";
3969 case DW_TAG_format_label:
3970 return "DW_TAG_format_label";
3971 case DW_TAG_function_template:
3972 return "DW_TAG_function_template";
3973 case DW_TAG_class_template:
3974 return "DW_TAG_class_template";
3975 case DW_TAG_GNU_BINCL:
3976 return "DW_TAG_GNU_BINCL";
3977 case DW_TAG_GNU_EINCL:
3978 return "DW_TAG_GNU_EINCL";
3980 return "DW_TAG_<unknown>";
3984 /* Convert a DWARF attribute code into its string name. */
3987 dwarf_attr_name (attr)
3993 return "DW_AT_sibling";
3994 case DW_AT_location:
3995 return "DW_AT_location";
3997 return "DW_AT_name";
3998 case DW_AT_ordering:
3999 return "DW_AT_ordering";
4000 case DW_AT_subscr_data:
4001 return "DW_AT_subscr_data";
4002 case DW_AT_byte_size:
4003 return "DW_AT_byte_size";
4004 case DW_AT_bit_offset:
4005 return "DW_AT_bit_offset";
4006 case DW_AT_bit_size:
4007 return "DW_AT_bit_size";
4008 case DW_AT_element_list:
4009 return "DW_AT_element_list";
4010 case DW_AT_stmt_list:
4011 return "DW_AT_stmt_list";
4013 return "DW_AT_low_pc";
4015 return "DW_AT_high_pc";
4016 case DW_AT_language:
4017 return "DW_AT_language";
4019 return "DW_AT_member";
4021 return "DW_AT_discr";
4022 case DW_AT_discr_value:
4023 return "DW_AT_discr_value";
4024 case DW_AT_visibility:
4025 return "DW_AT_visibility";
4027 return "DW_AT_import";
4028 case DW_AT_string_length:
4029 return "DW_AT_string_length";
4030 case DW_AT_common_reference:
4031 return "DW_AT_common_reference";
4032 case DW_AT_comp_dir:
4033 return "DW_AT_comp_dir";
4034 case DW_AT_const_value:
4035 return "DW_AT_const_value";
4036 case DW_AT_containing_type:
4037 return "DW_AT_containing_type";
4038 case DW_AT_default_value:
4039 return "DW_AT_default_value";
4041 return "DW_AT_inline";
4042 case DW_AT_is_optional:
4043 return "DW_AT_is_optional";
4044 case DW_AT_lower_bound:
4045 return "DW_AT_lower_bound";
4046 case DW_AT_producer:
4047 return "DW_AT_producer";
4048 case DW_AT_prototyped:
4049 return "DW_AT_prototyped";
4050 case DW_AT_return_addr:
4051 return "DW_AT_return_addr";
4052 case DW_AT_start_scope:
4053 return "DW_AT_start_scope";
4054 case DW_AT_stride_size:
4055 return "DW_AT_stride_size";
4056 case DW_AT_upper_bound:
4057 return "DW_AT_upper_bound";
4058 case DW_AT_abstract_origin:
4059 return "DW_AT_abstract_origin";
4060 case DW_AT_accessibility:
4061 return "DW_AT_accessibility";
4062 case DW_AT_address_class:
4063 return "DW_AT_address_class";
4064 case DW_AT_artificial:
4065 return "DW_AT_artificial";
4066 case DW_AT_base_types:
4067 return "DW_AT_base_types";
4068 case DW_AT_calling_convention:
4069 return "DW_AT_calling_convention";
4071 return "DW_AT_count";
4072 case DW_AT_data_member_location:
4073 return "DW_AT_data_member_location";
4074 case DW_AT_decl_column:
4075 return "DW_AT_decl_column";
4076 case DW_AT_decl_file:
4077 return "DW_AT_decl_file";
4078 case DW_AT_decl_line:
4079 return "DW_AT_decl_line";
4080 case DW_AT_declaration:
4081 return "DW_AT_declaration";
4082 case DW_AT_discr_list:
4083 return "DW_AT_discr_list";
4084 case DW_AT_encoding:
4085 return "DW_AT_encoding";
4086 case DW_AT_external:
4087 return "DW_AT_external";
4088 case DW_AT_frame_base:
4089 return "DW_AT_frame_base";
4091 return "DW_AT_friend";
4092 case DW_AT_identifier_case:
4093 return "DW_AT_identifier_case";
4094 case DW_AT_macro_info:
4095 return "DW_AT_macro_info";
4096 case DW_AT_namelist_items:
4097 return "DW_AT_namelist_items";
4098 case DW_AT_priority:
4099 return "DW_AT_priority";
4101 return "DW_AT_segment";
4102 case DW_AT_specification:
4103 return "DW_AT_specification";
4104 case DW_AT_static_link:
4105 return "DW_AT_static_link";
4107 return "DW_AT_type";
4108 case DW_AT_use_location:
4109 return "DW_AT_use_location";
4110 case DW_AT_variable_parameter:
4111 return "DW_AT_variable_parameter";
4112 case DW_AT_virtuality:
4113 return "DW_AT_virtuality";
4114 case DW_AT_vtable_elem_location:
4115 return "DW_AT_vtable_elem_location";
4117 case DW_AT_allocated:
4118 return "DW_AT_allocated";
4119 case DW_AT_associated:
4120 return "DW_AT_associated";
4121 case DW_AT_data_location:
4122 return "DW_AT_data_location";
4124 return "DW_AT_stride";
4125 case DW_AT_entry_pc:
4126 return "DW_AT_entry_pc";
4127 case DW_AT_use_UTF8:
4128 return "DW_AT_use_UTF8";
4129 case DW_AT_extension:
4130 return "DW_AT_extension";
4132 return "DW_AT_ranges";
4133 case DW_AT_trampoline:
4134 return "DW_AT_trampoline";
4135 case DW_AT_call_column:
4136 return "DW_AT_call_column";
4137 case DW_AT_call_file:
4138 return "DW_AT_call_file";
4139 case DW_AT_call_line:
4140 return "DW_AT_call_line";
4142 case DW_AT_MIPS_fde:
4143 return "DW_AT_MIPS_fde";
4144 case DW_AT_MIPS_loop_begin:
4145 return "DW_AT_MIPS_loop_begin";
4146 case DW_AT_MIPS_tail_loop_begin:
4147 return "DW_AT_MIPS_tail_loop_begin";
4148 case DW_AT_MIPS_epilog_begin:
4149 return "DW_AT_MIPS_epilog_begin";
4150 case DW_AT_MIPS_loop_unroll_factor:
4151 return "DW_AT_MIPS_loop_unroll_factor";
4152 case DW_AT_MIPS_software_pipeline_depth:
4153 return "DW_AT_MIPS_software_pipeline_depth";
4154 case DW_AT_MIPS_linkage_name:
4155 return "DW_AT_MIPS_linkage_name";
4156 case DW_AT_MIPS_stride:
4157 return "DW_AT_MIPS_stride";
4158 case DW_AT_MIPS_abstract_name:
4159 return "DW_AT_MIPS_abstract_name";
4160 case DW_AT_MIPS_clone_origin:
4161 return "DW_AT_MIPS_clone_origin";
4162 case DW_AT_MIPS_has_inlines:
4163 return "DW_AT_MIPS_has_inlines";
4165 case DW_AT_sf_names:
4166 return "DW_AT_sf_names";
4167 case DW_AT_src_info:
4168 return "DW_AT_src_info";
4169 case DW_AT_mac_info:
4170 return "DW_AT_mac_info";
4171 case DW_AT_src_coords:
4172 return "DW_AT_src_coords";
4173 case DW_AT_body_begin:
4174 return "DW_AT_body_begin";
4175 case DW_AT_body_end:
4176 return "DW_AT_body_end";
4177 case DW_AT_GNU_vector:
4178 return "DW_AT_GNU_vector";
4180 case DW_AT_VMS_rtnbeg_pd_address:
4181 return "DW_AT_VMS_rtnbeg_pd_address";
4184 return "DW_AT_<unknown>";
4188 /* Convert a DWARF value form code into its string name. */
4191 dwarf_form_name (form)
4197 return "DW_FORM_addr";
4198 case DW_FORM_block2:
4199 return "DW_FORM_block2";
4200 case DW_FORM_block4:
4201 return "DW_FORM_block4";
4203 return "DW_FORM_data2";
4205 return "DW_FORM_data4";
4207 return "DW_FORM_data8";
4208 case DW_FORM_string:
4209 return "DW_FORM_string";
4211 return "DW_FORM_block";
4212 case DW_FORM_block1:
4213 return "DW_FORM_block1";
4215 return "DW_FORM_data1";
4217 return "DW_FORM_flag";
4219 return "DW_FORM_sdata";
4221 return "DW_FORM_strp";
4223 return "DW_FORM_udata";
4224 case DW_FORM_ref_addr:
4225 return "DW_FORM_ref_addr";
4227 return "DW_FORM_ref1";
4229 return "DW_FORM_ref2";
4231 return "DW_FORM_ref4";
4233 return "DW_FORM_ref8";
4234 case DW_FORM_ref_udata:
4235 return "DW_FORM_ref_udata";
4236 case DW_FORM_indirect:
4237 return "DW_FORM_indirect";
4239 return "DW_FORM_<unknown>";
4243 /* Convert a DWARF type code into its string name. */
4247 dwarf_type_encoding_name (enc)
4252 case DW_ATE_address:
4253 return "DW_ATE_address";
4254 case DW_ATE_boolean:
4255 return "DW_ATE_boolean";
4256 case DW_ATE_complex_float:
4257 return "DW_ATE_complex_float";
4259 return "DW_ATE_float";
4261 return "DW_ATE_signed";
4262 case DW_ATE_signed_char:
4263 return "DW_ATE_signed_char";
4264 case DW_ATE_unsigned:
4265 return "DW_ATE_unsigned";
4266 case DW_ATE_unsigned_char:
4267 return "DW_ATE_unsigned_char";
4269 return "DW_ATE_<unknown>";
4274 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4275 instance of an inlined instance of a decl which is local to an inline
4276 function, so we have to trace all of the way back through the origin chain
4277 to find out what sort of node actually served as the original seed for the
4281 decl_ultimate_origin (decl)
4284 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4285 nodes in the function to point to themselves; ignore that if
4286 we're trying to output the abstract instance of this function. */
4287 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4290 #ifdef ENABLE_CHECKING
4291 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4292 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4293 most distant ancestor, this should never happen. */
4297 return DECL_ABSTRACT_ORIGIN (decl);
4300 /* Determine the "ultimate origin" of a block. The block may be an inlined
4301 instance of an inlined instance of a block which is local to an inline
4302 function, so we have to trace all of the way back through the origin chain
4303 to find out what sort of node actually served as the original seed for the
4307 block_ultimate_origin (block)
4310 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4312 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4313 nodes in the function to point to themselves; ignore that if
4314 we're trying to output the abstract instance of this function. */
4315 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4318 if (immediate_origin == NULL_TREE)
4323 tree lookahead = immediate_origin;
4327 ret_val = lookahead;
4328 lookahead = (TREE_CODE (ret_val) == BLOCK
4329 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4331 while (lookahead != NULL && lookahead != ret_val);
4337 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4338 of a virtual function may refer to a base class, so we check the 'this'
4342 decl_class_context (decl)
4345 tree context = NULL_TREE;
4347 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4348 context = DECL_CONTEXT (decl);
4350 context = TYPE_MAIN_VARIANT
4351 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4353 if (context && !TYPE_P (context))
4354 context = NULL_TREE;
4359 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4360 addition order, and correct that in reverse_all_dies. */
4363 add_dwarf_attr (die, attr)
4367 if (die != NULL && attr != NULL)
4369 attr->dw_attr_next = die->die_attr;
4370 die->die_attr = attr;
4374 static inline dw_val_class
4378 return a->dw_attr_val.val_class;
4381 /* Add a flag value attribute to a DIE. */
4384 add_AT_flag (die, attr_kind, flag)
4386 enum dwarf_attribute attr_kind;
4389 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4391 attr->dw_attr_next = NULL;
4392 attr->dw_attr = attr_kind;
4393 attr->dw_attr_val.val_class = dw_val_class_flag;
4394 attr->dw_attr_val.v.val_flag = flag;
4395 add_dwarf_attr (die, attr);
4398 static inline unsigned
4402 if (a && AT_class (a) == dw_val_class_flag)
4403 return a->dw_attr_val.v.val_flag;
4408 /* Add a signed integer attribute value to a DIE. */
4411 add_AT_int (die, attr_kind, int_val)
4413 enum dwarf_attribute attr_kind;
4416 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4418 attr->dw_attr_next = NULL;
4419 attr->dw_attr = attr_kind;
4420 attr->dw_attr_val.val_class = dw_val_class_const;
4421 attr->dw_attr_val.v.val_int = int_val;
4422 add_dwarf_attr (die, attr);
4425 static inline long int
4429 if (a && AT_class (a) == dw_val_class_const)
4430 return a->dw_attr_val.v.val_int;
4435 /* Add an unsigned integer attribute value to a DIE. */
4438 add_AT_unsigned (die, attr_kind, unsigned_val)
4440 enum dwarf_attribute attr_kind;
4441 unsigned long unsigned_val;
4443 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4445 attr->dw_attr_next = NULL;
4446 attr->dw_attr = attr_kind;
4447 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4448 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4449 add_dwarf_attr (die, attr);
4452 static inline unsigned long
4456 if (a && AT_class (a) == dw_val_class_unsigned_const)
4457 return a->dw_attr_val.v.val_unsigned;
4462 /* Add an unsigned double integer attribute value to a DIE. */
4465 add_AT_long_long (die, attr_kind, val_hi, val_low)
4467 enum dwarf_attribute attr_kind;
4468 unsigned long val_hi;
4469 unsigned long val_low;
4471 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4473 attr->dw_attr_next = NULL;
4474 attr->dw_attr = attr_kind;
4475 attr->dw_attr_val.val_class = dw_val_class_long_long;
4476 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4477 attr->dw_attr_val.v.val_long_long.low = val_low;
4478 add_dwarf_attr (die, attr);
4481 /* Add a floating point attribute value to a DIE and return it. */
4484 add_AT_float (die, attr_kind, length, array)
4486 enum dwarf_attribute attr_kind;
4490 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4492 attr->dw_attr_next = NULL;
4493 attr->dw_attr = attr_kind;
4494 attr->dw_attr_val.val_class = dw_val_class_float;
4495 attr->dw_attr_val.v.val_float.length = length;
4496 attr->dw_attr_val.v.val_float.array = array;
4497 add_dwarf_attr (die, attr);
4500 /* Add a string attribute value to a DIE. */
4503 add_AT_string (die, attr_kind, str)
4505 enum dwarf_attribute attr_kind;
4508 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4509 struct indirect_string_node *node;
4511 if (! debug_str_hash)
4513 debug_str_hash = ht_create (10);
4514 debug_str_hash->alloc_node = indirect_string_alloc;
4517 node = (struct indirect_string_node *)
4518 ht_lookup (debug_str_hash, (const unsigned char *) str,
4519 strlen (str), HT_ALLOC);
4522 attr->dw_attr_next = NULL;
4523 attr->dw_attr = attr_kind;
4524 attr->dw_attr_val.val_class = dw_val_class_str;
4525 attr->dw_attr_val.v.val_str = node;
4526 add_dwarf_attr (die, attr);
4529 static inline const char *
4533 if (a && AT_class (a) == dw_val_class_str)
4534 return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id);
4539 /* Find out whether a string should be output inline in DIE
4540 or out-of-line in .debug_str section. */
4546 if (a && AT_class (a) == dw_val_class_str)
4548 struct indirect_string_node *node;
4550 extern int const_labelno;
4553 node = a->dw_attr_val.v.val_str;
4557 len = HT_LEN (&node->id) + 1;
4559 /* If the string is shorter or equal to the size of the reference, it is
4560 always better to put it inline. */
4561 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4562 return node->form = DW_FORM_string;
4564 /* If we cannot expect the linker to merge strings in .debug_str
4565 section, only put it into .debug_str if it is worth even in this
4567 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4568 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4569 return node->form = DW_FORM_string;
4571 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4573 node->label = xstrdup (label);
4575 return node->form = DW_FORM_strp;
4581 /* Add a DIE reference attribute value to a DIE. */
4584 add_AT_die_ref (die, attr_kind, targ_die)
4586 enum dwarf_attribute attr_kind;
4587 dw_die_ref targ_die;
4589 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4591 attr->dw_attr_next = NULL;
4592 attr->dw_attr = attr_kind;
4593 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4594 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4595 attr->dw_attr_val.v.val_die_ref.external = 0;
4596 add_dwarf_attr (die, attr);
4599 static inline dw_die_ref
4603 if (a && AT_class (a) == dw_val_class_die_ref)
4604 return a->dw_attr_val.v.val_die_ref.die;
4613 if (a && AT_class (a) == dw_val_class_die_ref)
4614 return a->dw_attr_val.v.val_die_ref.external;
4620 set_AT_ref_external (a, i)
4624 if (a && AT_class (a) == dw_val_class_die_ref)
4625 a->dw_attr_val.v.val_die_ref.external = i;
4630 /* Add an FDE reference attribute value to a DIE. */
4633 add_AT_fde_ref (die, attr_kind, targ_fde)
4635 enum dwarf_attribute attr_kind;
4638 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4640 attr->dw_attr_next = NULL;
4641 attr->dw_attr = attr_kind;
4642 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4643 attr->dw_attr_val.v.val_fde_index = targ_fde;
4644 add_dwarf_attr (die, attr);
4647 /* Add a location description attribute value to a DIE. */
4650 add_AT_loc (die, attr_kind, loc)
4652 enum dwarf_attribute attr_kind;
4653 dw_loc_descr_ref loc;
4655 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4657 attr->dw_attr_next = NULL;
4658 attr->dw_attr = attr_kind;
4659 attr->dw_attr_val.val_class = dw_val_class_loc;
4660 attr->dw_attr_val.v.val_loc = loc;
4661 add_dwarf_attr (die, attr);
4664 static inline dw_loc_descr_ref
4668 if (a && AT_class (a) == dw_val_class_loc)
4669 return a->dw_attr_val.v.val_loc;
4675 add_AT_loc_list (die, attr_kind, loc_list)
4677 enum dwarf_attribute attr_kind;
4678 dw_loc_list_ref loc_list;
4680 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4682 attr->dw_attr_next = NULL;
4683 attr->dw_attr = attr_kind;
4684 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4685 attr->dw_attr_val.v.val_loc_list = loc_list;
4686 add_dwarf_attr (die, attr);
4687 have_location_lists = 1;
4690 static inline dw_loc_list_ref
4694 if (a && AT_class (a) == dw_val_class_loc_list)
4695 return a->dw_attr_val.v.val_loc_list;
4700 /* Add an address constant attribute value to a DIE. */
4703 add_AT_addr (die, attr_kind, addr)
4705 enum dwarf_attribute attr_kind;
4708 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4710 attr->dw_attr_next = NULL;
4711 attr->dw_attr = attr_kind;
4712 attr->dw_attr_val.val_class = dw_val_class_addr;
4713 attr->dw_attr_val.v.val_addr = addr;
4714 add_dwarf_attr (die, attr);
4721 if (a && AT_class (a) == dw_val_class_addr)
4722 return a->dw_attr_val.v.val_addr;
4727 /* Add a label identifier attribute value to a DIE. */
4730 add_AT_lbl_id (die, attr_kind, lbl_id)
4732 enum dwarf_attribute attr_kind;
4735 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4737 attr->dw_attr_next = NULL;
4738 attr->dw_attr = attr_kind;
4739 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4740 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4741 add_dwarf_attr (die, attr);
4744 /* Add a section offset attribute value to a DIE. */
4747 add_AT_lbl_offset (die, attr_kind, label)
4749 enum dwarf_attribute attr_kind;
4752 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4754 attr->dw_attr_next = NULL;
4755 attr->dw_attr = attr_kind;
4756 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4757 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4758 add_dwarf_attr (die, attr);
4761 /* Add an offset attribute value to a DIE. */
4764 add_AT_offset (die, attr_kind, offset)
4766 enum dwarf_attribute attr_kind;
4767 unsigned long offset;
4769 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4771 attr->dw_attr_next = NULL;
4772 attr->dw_attr = attr_kind;
4773 attr->dw_attr_val.val_class = dw_val_class_offset;
4774 attr->dw_attr_val.v.val_offset = offset;
4775 add_dwarf_attr (die, attr);
4778 /* Add an range_list attribute value to a DIE. */
4781 add_AT_range_list (die, attr_kind, offset)
4783 enum dwarf_attribute attr_kind;
4784 unsigned long offset;
4786 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4788 attr->dw_attr_next = NULL;
4789 attr->dw_attr = attr_kind;
4790 attr->dw_attr_val.val_class = dw_val_class_range_list;
4791 attr->dw_attr_val.v.val_offset = offset;
4792 add_dwarf_attr (die, attr);
4795 static inline const char *
4799 if (a && (AT_class (a) == dw_val_class_lbl_id
4800 || AT_class (a) == dw_val_class_lbl_offset))
4801 return a->dw_attr_val.v.val_lbl_id;
4806 /* Get the attribute of type attr_kind. */
4808 static inline dw_attr_ref
4809 get_AT (die, attr_kind)
4811 enum dwarf_attribute attr_kind;
4814 dw_die_ref spec = NULL;
4818 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4819 if (a->dw_attr == attr_kind)
4821 else if (a->dw_attr == DW_AT_specification
4822 || a->dw_attr == DW_AT_abstract_origin)
4826 return get_AT (spec, attr_kind);
4832 /* Return the "low pc" attribute value, typically associated with a subprogram
4833 DIE. Return null if the "low pc" attribute is either not present, or if it
4834 cannot be represented as an assembler label identifier. */
4836 static inline const char *
4840 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4842 return a ? AT_lbl (a) : NULL;
4845 /* Return the "high pc" attribute value, typically associated with a subprogram
4846 DIE. Return null if the "high pc" attribute is either not present, or if it
4847 cannot be represented as an assembler label identifier. */
4849 static inline const char *
4853 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4855 return a ? AT_lbl (a) : NULL;
4858 /* Return the value of the string attribute designated by ATTR_KIND, or
4859 NULL if it is not present. */
4861 static inline const char *
4862 get_AT_string (die, attr_kind)
4864 enum dwarf_attribute attr_kind;
4866 dw_attr_ref a = get_AT (die, attr_kind);
4868 return a ? AT_string (a) : NULL;
4871 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4872 if it is not present. */
4875 get_AT_flag (die, attr_kind)
4877 enum dwarf_attribute attr_kind;
4879 dw_attr_ref a = get_AT (die, attr_kind);
4881 return a ? AT_flag (a) : 0;
4884 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4885 if it is not present. */
4887 static inline unsigned
4888 get_AT_unsigned (die, attr_kind)
4890 enum dwarf_attribute attr_kind;
4892 dw_attr_ref a = get_AT (die, attr_kind);
4894 return a ? AT_unsigned (a) : 0;
4897 static inline dw_die_ref
4898 get_AT_ref (die, attr_kind)
4900 enum dwarf_attribute attr_kind;
4902 dw_attr_ref a = get_AT (die, attr_kind);
4904 return a ? AT_ref (a) : NULL;
4910 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4912 return (lang == DW_LANG_C || lang == DW_LANG_C89
4913 || lang == DW_LANG_C_plus_plus);
4919 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4920 == DW_LANG_C_plus_plus);
4926 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4928 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4934 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4936 return (lang == DW_LANG_Java);
4939 /* Free up the memory used by A. */
4941 static inline void free_AT PARAMS ((dw_attr_ref));
4946 switch (AT_class (a))
4948 case dw_val_class_str:
4949 if (a->dw_attr_val.v.val_str->refcount)
4950 a->dw_attr_val.v.val_str->refcount--;
4953 case dw_val_class_lbl_id:
4954 case dw_val_class_lbl_offset:
4955 free (a->dw_attr_val.v.val_lbl_id);
4958 case dw_val_class_float:
4959 free (a->dw_attr_val.v.val_float.array);
4969 /* Remove the specified attribute if present. */
4972 remove_AT (die, attr_kind)
4974 enum dwarf_attribute attr_kind;
4977 dw_attr_ref removed = NULL;
4981 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4982 if ((*p)->dw_attr == attr_kind)
4985 *p = (*p)->dw_attr_next;
4994 /* Free up the memory used by DIE. */
5000 remove_children (die);
5004 /* Discard the children of this DIE. */
5007 remove_children (die)
5010 dw_die_ref child_die = die->die_child;
5012 die->die_child = NULL;
5014 while (child_die != NULL)
5016 dw_die_ref tmp_die = child_die;
5019 child_die = child_die->die_sib;
5021 for (a = tmp_die->die_attr; a != NULL;)
5023 dw_attr_ref tmp_a = a;
5025 a = a->dw_attr_next;
5033 /* Add a child DIE below its parent. We build the lists up in reverse
5034 addition order, and correct that in reverse_all_dies. */
5037 add_child_die (die, child_die)
5039 dw_die_ref child_die;
5041 if (die != NULL && child_die != NULL)
5043 if (die == child_die)
5046 child_die->die_parent = die;
5047 child_die->die_sib = die->die_child;
5048 die->die_child = child_die;
5052 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5053 is the specification, to the front of PARENT's list of children. */
5056 splice_child_die (parent, child)
5057 dw_die_ref parent, child;
5061 /* We want the declaration DIE from inside the class, not the
5062 specification DIE at toplevel. */
5063 if (child->die_parent != parent)
5065 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5071 if (child->die_parent != parent
5072 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
5075 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5078 *p = child->die_sib;
5082 child->die_sib = parent->die_child;
5083 parent->die_child = child;
5086 /* Return a pointer to a newly created DIE node. */
5088 static inline dw_die_ref
5089 new_die (tag_value, parent_die, t)
5090 enum dwarf_tag tag_value;
5091 dw_die_ref parent_die;
5094 dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5096 die->die_tag = tag_value;
5098 if (parent_die != NULL)
5099 add_child_die (parent_die, die);
5102 limbo_die_node *limbo_node;
5104 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5105 limbo_node->die = die;
5106 limbo_node->created_for = t;
5107 limbo_node->next = limbo_die_list;
5108 limbo_die_list = limbo_node;
5114 /* Return the DIE associated with the given type specifier. */
5116 static inline dw_die_ref
5117 lookup_type_die (type)
5120 return TYPE_SYMTAB_DIE (type);
5123 /* Equate a DIE to a given type specifier. */
5126 equate_type_number_to_die (type, type_die)
5128 dw_die_ref type_die;
5130 TYPE_SYMTAB_DIE (type) = type_die;
5133 /* Return the DIE associated with a given declaration. */
5135 static inline dw_die_ref
5136 lookup_decl_die (decl)
5139 unsigned decl_id = DECL_UID (decl);
5141 return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
5144 /* Equate a DIE to a particular declaration. */
5147 equate_decl_number_to_die (decl, decl_die)
5149 dw_die_ref decl_die;
5151 unsigned int decl_id = DECL_UID (decl);
5152 unsigned int num_allocated;
5154 if (decl_id >= decl_die_table_allocated)
5157 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5158 / DECL_DIE_TABLE_INCREMENT)
5159 * DECL_DIE_TABLE_INCREMENT;
5162 = (dw_die_ref *) xrealloc (decl_die_table,
5163 sizeof (dw_die_ref) * num_allocated);
5165 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5166 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5167 decl_die_table_allocated = num_allocated;
5170 if (decl_id >= decl_die_table_in_use)
5171 decl_die_table_in_use = (decl_id + 1);
5173 decl_die_table[decl_id] = decl_die;
5176 /* Keep track of the number of spaces used to indent the
5177 output of the debugging routines that print the structure of
5178 the DIE internal representation. */
5179 static int print_indent;
5181 /* Indent the line the number of spaces given by print_indent. */
5184 print_spaces (outfile)
5187 fprintf (outfile, "%*s", print_indent, "");
5190 /* Print the information associated with a given DIE, and its children.
5191 This routine is a debugging aid only. */
5194 print_die (die, outfile)
5201 print_spaces (outfile);
5202 fprintf (outfile, "DIE %4lu: %s\n",
5203 die->die_offset, dwarf_tag_name (die->die_tag));
5204 print_spaces (outfile);
5205 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5206 fprintf (outfile, " offset: %lu\n", die->die_offset);
5208 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5210 print_spaces (outfile);
5211 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5213 switch (AT_class (a))
5215 case dw_val_class_addr:
5216 fprintf (outfile, "address");
5218 case dw_val_class_offset:
5219 fprintf (outfile, "offset");
5221 case dw_val_class_loc:
5222 fprintf (outfile, "location descriptor");
5224 case dw_val_class_loc_list:
5225 fprintf (outfile, "location list -> label:%s",
5226 AT_loc_list (a)->ll_symbol);
5228 case dw_val_class_range_list:
5229 fprintf (outfile, "range list");
5231 case dw_val_class_const:
5232 fprintf (outfile, "%ld", AT_int (a));
5234 case dw_val_class_unsigned_const:
5235 fprintf (outfile, "%lu", AT_unsigned (a));
5237 case dw_val_class_long_long:
5238 fprintf (outfile, "constant (%lu,%lu)",
5239 a->dw_attr_val.v.val_long_long.hi,
5240 a->dw_attr_val.v.val_long_long.low);
5242 case dw_val_class_float:
5243 fprintf (outfile, "floating-point constant");
5245 case dw_val_class_flag:
5246 fprintf (outfile, "%u", AT_flag (a));
5248 case dw_val_class_die_ref:
5249 if (AT_ref (a) != NULL)
5251 if (AT_ref (a)->die_symbol)
5252 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5254 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5257 fprintf (outfile, "die -> <null>");
5259 case dw_val_class_lbl_id:
5260 case dw_val_class_lbl_offset:
5261 fprintf (outfile, "label: %s", AT_lbl (a));
5263 case dw_val_class_str:
5264 if (AT_string (a) != NULL)
5265 fprintf (outfile, "\"%s\"", AT_string (a));
5267 fprintf (outfile, "<null>");
5273 fprintf (outfile, "\n");
5276 if (die->die_child != NULL)
5279 for (c = die->die_child; c != NULL; c = c->die_sib)
5280 print_die (c, outfile);
5284 if (print_indent == 0)
5285 fprintf (outfile, "\n");
5288 /* Print the contents of the source code line number correspondence table.
5289 This routine is a debugging aid only. */
5292 print_dwarf_line_table (outfile)
5296 dw_line_info_ref line_info;
5298 fprintf (outfile, "\n\nDWARF source line information\n");
5299 for (i = 1; i < line_info_table_in_use; i++)
5301 line_info = &line_info_table[i];
5302 fprintf (outfile, "%5d: ", i);
5303 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5304 fprintf (outfile, "%6ld", line_info->dw_line_num);
5305 fprintf (outfile, "\n");
5308 fprintf (outfile, "\n\n");
5311 /* Print the information collected for a given DIE. */
5314 debug_dwarf_die (die)
5317 print_die (die, stderr);
5320 /* Print all DWARF information collected for the compilation unit.
5321 This routine is a debugging aid only. */
5327 print_die (comp_unit_die, stderr);
5328 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5329 print_dwarf_line_table (stderr);
5332 /* We build up the lists of children and attributes by pushing new ones
5333 onto the beginning of the list. Reverse the lists for DIE so that
5334 they are in order of addition. */
5337 reverse_die_lists (die)
5340 dw_die_ref c, cp, cn;
5341 dw_attr_ref a, ap, an;
5343 for (a = die->die_attr, ap = 0; a; a = an)
5345 an = a->dw_attr_next;
5346 a->dw_attr_next = ap;
5352 for (c = die->die_child, cp = 0; c; c = cn)
5359 die->die_child = cp;
5362 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5363 reverse all dies in add_sibling_attributes, which runs through all the dies,
5364 it would reverse all the dies. Now, however, since we don't call
5365 reverse_die_lists in add_sibling_attributes, we need a routine to
5366 recursively reverse all the dies. This is that routine. */
5369 reverse_all_dies (die)
5374 reverse_die_lists (die);
5376 for (c = die->die_child; c; c = c->die_sib)
5377 reverse_all_dies (c);
5380 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5381 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5382 DIE that marks the start of the DIEs for this include file. */
5385 push_new_compile_unit (old_unit, bincl_die)
5386 dw_die_ref old_unit, bincl_die;
5388 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5389 dw_die_ref new_unit = gen_compile_unit_die (filename);
5391 new_unit->die_sib = old_unit;
5395 /* Close an include-file CU and reopen the enclosing one. */
5398 pop_compile_unit (old_unit)
5399 dw_die_ref old_unit;
5401 dw_die_ref new_unit = old_unit->die_sib;
5403 old_unit->die_sib = NULL;
5407 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5408 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5410 /* Calculate the checksum of a location expression. */
5413 loc_checksum (loc, ctx)
5414 dw_loc_descr_ref loc;
5415 struct md5_ctx *ctx;
5417 CHECKSUM (loc->dw_loc_opc);
5418 CHECKSUM (loc->dw_loc_oprnd1);
5419 CHECKSUM (loc->dw_loc_oprnd2);
5422 /* Calculate the checksum of an attribute. */
5425 attr_checksum (at, ctx)
5427 struct md5_ctx *ctx;
5429 dw_loc_descr_ref loc;
5432 CHECKSUM (at->dw_attr);
5434 /* We don't care about differences in file numbering. */
5435 if (at->dw_attr == DW_AT_decl_file
5436 /* Or that this was compiled with a different compiler snapshot; if
5437 the output is the same, that's what matters. */
5438 || at->dw_attr == DW_AT_producer)
5441 switch (AT_class (at))
5443 case dw_val_class_const:
5444 CHECKSUM (at->dw_attr_val.v.val_int);
5446 case dw_val_class_unsigned_const:
5447 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5449 case dw_val_class_long_long:
5450 CHECKSUM (at->dw_attr_val.v.val_long_long);
5452 case dw_val_class_float:
5453 CHECKSUM (at->dw_attr_val.v.val_float);
5455 case dw_val_class_flag:
5456 CHECKSUM (at->dw_attr_val.v.val_flag);
5458 case dw_val_class_str:
5459 CHECKSUM_STRING (AT_string (at));
5462 case dw_val_class_addr:
5464 switch (GET_CODE (r))
5467 CHECKSUM_STRING (XSTR (r, 0));
5475 case dw_val_class_offset:
5476 CHECKSUM (at->dw_attr_val.v.val_offset);
5479 case dw_val_class_loc:
5480 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5481 loc_checksum (loc, ctx);
5484 case dw_val_class_die_ref:
5485 if (AT_ref (at)->die_offset)
5486 CHECKSUM (AT_ref (at)->die_offset);
5487 /* FIXME else use target die name or something. */
5489 case dw_val_class_fde_ref:
5490 case dw_val_class_lbl_id:
5491 case dw_val_class_lbl_offset:
5499 /* Calculate the checksum of a DIE. */
5502 die_checksum (die, ctx)
5504 struct md5_ctx *ctx;
5509 CHECKSUM (die->die_tag);
5511 for (a = die->die_attr; a; a = a->dw_attr_next)
5512 attr_checksum (a, ctx);
5514 for (c = die->die_child; c; c = c->die_sib)
5515 die_checksum (c, ctx);
5519 #undef CHECKSUM_STRING
5521 /* The prefix to attach to symbols on DIEs in the current comdat debug
5523 static char *comdat_symbol_id;
5525 /* The index of the current symbol within the current comdat CU. */
5526 static unsigned int comdat_symbol_number;
5528 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5529 children, and set comdat_symbol_id accordingly. */
5532 compute_section_prefix (unit_die)
5533 dw_die_ref unit_die;
5535 const char *base = lbasename (get_AT_string (unit_die, DW_AT_name));
5536 char *name = (char *) alloca (strlen (base) + 64);
5539 unsigned char checksum[16];
5542 /* Compute the checksum of the DIE, then append part of it as hex digits to
5543 the name filename of the unit. */
5545 md5_init_ctx (&ctx);
5546 die_checksum (unit_die, &ctx);
5547 md5_finish_ctx (&ctx, checksum);
5549 sprintf (name, "%s.", base);
5550 clean_symbol_name (name);
5552 p = name + strlen (name);
5553 for (i = 0; i < 4; i++)
5555 sprintf (p, "%.2x", checksum[i]);
5559 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5560 comdat_symbol_number = 0;
5563 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5569 switch (die->die_tag)
5571 case DW_TAG_array_type:
5572 case DW_TAG_class_type:
5573 case DW_TAG_enumeration_type:
5574 case DW_TAG_pointer_type:
5575 case DW_TAG_reference_type:
5576 case DW_TAG_string_type:
5577 case DW_TAG_structure_type:
5578 case DW_TAG_subroutine_type:
5579 case DW_TAG_union_type:
5580 case DW_TAG_ptr_to_member_type:
5581 case DW_TAG_set_type:
5582 case DW_TAG_subrange_type:
5583 case DW_TAG_base_type:
5584 case DW_TAG_const_type:
5585 case DW_TAG_file_type:
5586 case DW_TAG_packed_type:
5587 case DW_TAG_volatile_type:
5594 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5595 Basically, we want to choose the bits that are likely to be shared between
5596 compilations (types) and leave out the bits that are specific to individual
5597 compilations (functions). */
5603 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5604 we do for stabs. The advantage is a greater likelihood of sharing between
5605 objects that don't include headers in the same order (and therefore would
5606 put the base types in a different comdat). jason 8/28/00 */
5608 if (c->die_tag == DW_TAG_base_type)
5611 if (c->die_tag == DW_TAG_pointer_type
5612 || c->die_tag == DW_TAG_reference_type
5613 || c->die_tag == DW_TAG_const_type
5614 || c->die_tag == DW_TAG_volatile_type)
5616 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5618 return t ? is_comdat_die (t) : 0;
5621 return is_type_die (c);
5624 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5625 compilation unit. */
5631 return (is_type_die (c)
5632 || (get_AT (c, DW_AT_declaration)
5633 && !get_AT (c, DW_AT_specification)));
5637 gen_internal_sym (prefix)
5641 static int label_num;
5643 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5644 return xstrdup (buf);
5647 /* Assign symbols to all worthy DIEs under DIE. */
5650 assign_symbol_names (die)
5655 if (is_symbol_die (die))
5657 if (comdat_symbol_id)
5659 char *p = alloca (strlen (comdat_symbol_id) + 64);
5661 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5662 comdat_symbol_id, comdat_symbol_number++);
5663 die->die_symbol = xstrdup (p);
5666 die->die_symbol = gen_internal_sym ("LDIE");
5669 for (c = die->die_child; c != NULL; c = c->die_sib)
5670 assign_symbol_names (c);
5673 /* Traverse the DIE (which is always comp_unit_die), and set up
5674 additional compilation units for each of the include files we see
5675 bracketed by BINCL/EINCL. */
5678 break_out_includes (die)
5682 dw_die_ref unit = NULL;
5683 limbo_die_node *node;
5685 for (ptr = &(die->die_child); *ptr;)
5687 dw_die_ref c = *ptr;
5689 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
5690 || (unit && is_comdat_die (c)))
5692 /* This DIE is for a secondary CU; remove it from the main one. */
5695 if (c->die_tag == DW_TAG_GNU_BINCL)
5697 unit = push_new_compile_unit (unit, c);
5700 else if (c->die_tag == DW_TAG_GNU_EINCL)
5702 unit = pop_compile_unit (unit);
5706 add_child_die (unit, c);
5710 /* Leave this DIE in the main CU. */
5711 ptr = &(c->die_sib);
5717 /* We can only use this in debugging, since the frontend doesn't check
5718 to make sure that we leave every include file we enter. */
5723 assign_symbol_names (die);
5724 for (node = limbo_die_list; node; node = node->next)
5726 compute_section_prefix (node->die);
5727 assign_symbol_names (node->die);
5731 /* Traverse the DIE and add a sibling attribute if it may have the
5732 effect of speeding up access to siblings. To save some space,
5733 avoid generating sibling attributes for DIE's without children. */
5736 add_sibling_attributes (die)
5741 if (die->die_tag != DW_TAG_compile_unit
5742 && die->die_sib && die->die_child != NULL)
5743 /* Add the sibling link to the front of the attribute list. */
5744 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5746 for (c = die->die_child; c != NULL; c = c->die_sib)
5747 add_sibling_attributes (c);
5750 /* Output all location lists for the DIE and its children. */
5753 output_location_lists (die)
5759 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5760 if (AT_class (d_attr) == dw_val_class_loc_list)
5761 output_loc_list (AT_loc_list (d_attr));
5763 for (c = die->die_child; c != NULL; c = c->die_sib)
5764 output_location_lists (c);
5768 /* The format of each DIE (and its attribute value pairs) is encoded in an
5769 abbreviation table. This routine builds the abbreviation table and assigns
5770 a unique abbreviation id for each abbreviation entry. The children of each
5771 die are visited recursively. */
5774 build_abbrev_table (die)
5777 unsigned long abbrev_id;
5778 unsigned int n_alloc;
5780 dw_attr_ref d_attr, a_attr;
5782 /* Scan the DIE references, and mark as external any that refer to
5783 DIEs from other CUs (i.e. those which are not marked). */
5784 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5785 if (AT_class (d_attr) == dw_val_class_die_ref
5786 && AT_ref (d_attr)->die_mark == 0)
5788 if (AT_ref (d_attr)->die_symbol == 0)
5791 set_AT_ref_external (d_attr, 1);
5794 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5796 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5798 if (abbrev->die_tag == die->die_tag)
5800 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5802 a_attr = abbrev->die_attr;
5803 d_attr = die->die_attr;
5805 while (a_attr != NULL && d_attr != NULL)
5807 if ((a_attr->dw_attr != d_attr->dw_attr)
5808 || (value_format (a_attr) != value_format (d_attr)))
5811 a_attr = a_attr->dw_attr_next;
5812 d_attr = d_attr->dw_attr_next;
5815 if (a_attr == NULL && d_attr == NULL)
5821 if (abbrev_id >= abbrev_die_table_in_use)
5823 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5825 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5827 = (dw_die_ref *) xrealloc (abbrev_die_table,
5828 sizeof (dw_die_ref) * n_alloc);
5830 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5831 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5832 abbrev_die_table_allocated = n_alloc;
5835 ++abbrev_die_table_in_use;
5836 abbrev_die_table[abbrev_id] = die;
5839 die->die_abbrev = abbrev_id;
5840 for (c = die->die_child; c != NULL; c = c->die_sib)
5841 build_abbrev_table (c);
5844 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5847 constant_size (value)
5848 long unsigned value;
5855 log = floor_log2 (value);
5858 log = 1 << (floor_log2 (log) + 1);
5863 /* Return the size of a DIE as it is represented in the
5864 .debug_info section. */
5866 static unsigned long
5870 unsigned long size = 0;
5873 size += size_of_uleb128 (die->die_abbrev);
5874 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5876 switch (AT_class (a))
5878 case dw_val_class_addr:
5879 size += DWARF2_ADDR_SIZE;
5881 case dw_val_class_offset:
5882 size += DWARF_OFFSET_SIZE;
5884 case dw_val_class_loc:
5886 unsigned long lsize = size_of_locs (AT_loc (a));
5889 size += constant_size (lsize);
5893 case dw_val_class_loc_list:
5894 size += DWARF_OFFSET_SIZE;
5896 case dw_val_class_range_list:
5897 size += DWARF_OFFSET_SIZE;
5899 case dw_val_class_const:
5900 size += size_of_sleb128 (AT_int (a));
5902 case dw_val_class_unsigned_const:
5903 size += constant_size (AT_unsigned (a));
5905 case dw_val_class_long_long:
5906 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5908 case dw_val_class_float:
5909 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5911 case dw_val_class_flag:
5914 case dw_val_class_die_ref:
5915 size += DWARF_OFFSET_SIZE;
5917 case dw_val_class_fde_ref:
5918 size += DWARF_OFFSET_SIZE;
5920 case dw_val_class_lbl_id:
5921 size += DWARF2_ADDR_SIZE;
5923 case dw_val_class_lbl_offset:
5924 size += DWARF_OFFSET_SIZE;
5926 case dw_val_class_str:
5927 if (AT_string_form (a) == DW_FORM_strp)
5928 size += DWARF_OFFSET_SIZE;
5930 size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1;
5940 /* Size the debugging information associated with a given DIE. Visits the
5941 DIE's children recursively. Updates the global variable next_die_offset, on
5942 each time through. Uses the current value of next_die_offset to update the
5943 die_offset field in each DIE. */
5946 calc_die_sizes (die)
5951 die->die_offset = next_die_offset;
5952 next_die_offset += size_of_die (die);
5954 for (c = die->die_child; c != NULL; c = c->die_sib)
5957 if (die->die_child != NULL)
5958 /* Count the null byte used to terminate sibling lists. */
5959 next_die_offset += 1;
5962 /* Set the marks for a die and its children. We do this so
5963 that we know whether or not a reference needs to use FORM_ref_addr; only
5964 DIEs in the same CU will be marked. We used to clear out the offset
5965 and use that as the flag, but ran into ordering problems. */
5974 for (c = die->die_child; c; c = c->die_sib)
5978 /* Clear the marks for a die and its children. */
5987 for (c = die->die_child; c; c = c->die_sib)
5991 /* Return the size of the .debug_pubnames table generated for the
5992 compilation unit. */
5994 static unsigned long
6000 size = DWARF_PUBNAMES_HEADER_SIZE;
6001 for (i = 0; i < pubname_table_in_use; i++)
6003 pubname_ref p = &pubname_table[i];
6004 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
6007 size += DWARF_OFFSET_SIZE;
6011 /* Return the size of the information in the .debug_aranges section. */
6013 static unsigned long
6018 size = DWARF_ARANGES_HEADER_SIZE;
6020 /* Count the address/length pair for this compilation unit. */
6021 size += 2 * DWARF2_ADDR_SIZE;
6022 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6024 /* Count the two zero words used to terminated the address range table. */
6025 size += 2 * DWARF2_ADDR_SIZE;
6029 /* Select the encoding of an attribute value. */
6031 static enum dwarf_form
6035 switch (a->dw_attr_val.val_class)
6037 case dw_val_class_addr:
6038 return DW_FORM_addr;
6039 case dw_val_class_range_list:
6040 case dw_val_class_offset:
6041 if (DWARF_OFFSET_SIZE == 4)
6042 return DW_FORM_data4;
6043 if (DWARF_OFFSET_SIZE == 8)
6044 return DW_FORM_data8;
6046 case dw_val_class_loc_list:
6047 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6048 .debug_loc section */
6049 return DW_FORM_data4;
6050 case dw_val_class_loc:
6051 switch (constant_size (size_of_locs (AT_loc (a))))
6054 return DW_FORM_block1;
6056 return DW_FORM_block2;
6060 case dw_val_class_const:
6061 return DW_FORM_sdata;
6062 case dw_val_class_unsigned_const:
6063 switch (constant_size (AT_unsigned (a)))
6066 return DW_FORM_data1;
6068 return DW_FORM_data2;
6070 return DW_FORM_data4;
6072 return DW_FORM_data8;
6076 case dw_val_class_long_long:
6077 return DW_FORM_block1;
6078 case dw_val_class_float:
6079 return DW_FORM_block1;
6080 case dw_val_class_flag:
6081 return DW_FORM_flag;
6082 case dw_val_class_die_ref:
6083 if (AT_ref_external (a))
6084 return DW_FORM_ref_addr;
6087 case dw_val_class_fde_ref:
6088 return DW_FORM_data;
6089 case dw_val_class_lbl_id:
6090 return DW_FORM_addr;
6091 case dw_val_class_lbl_offset:
6092 return DW_FORM_data;
6093 case dw_val_class_str:
6094 return AT_string_form (a);
6101 /* Output the encoding of an attribute value. */
6104 output_value_format (a)
6107 enum dwarf_form form = value_format (a);
6109 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6112 /* Output the .debug_abbrev section which defines the DIE abbreviation
6116 output_abbrev_section ()
6118 unsigned long abbrev_id;
6122 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6124 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6126 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6127 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6128 dwarf_tag_name (abbrev->die_tag));
6130 if (abbrev->die_child != NULL)
6131 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6133 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6135 for (a_attr = abbrev->die_attr; a_attr != NULL;
6136 a_attr = a_attr->dw_attr_next)
6138 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6139 dwarf_attr_name (a_attr->dw_attr));
6140 output_value_format (a_attr);
6143 dw2_asm_output_data (1, 0, NULL);
6144 dw2_asm_output_data (1, 0, NULL);
6147 /* Terminate the table. */
6148 dw2_asm_output_data (1, 0, NULL);
6151 /* Output a symbol we can use to refer to this DIE from another CU. */
6154 output_die_symbol (die)
6157 char *sym = die->die_symbol;
6162 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6163 /* We make these global, not weak; if the target doesn't support
6164 .linkonce, it doesn't support combining the sections, so debugging
6166 (*targetm.asm_out.globalize_label) (asm_out_file, sym);
6168 ASM_OUTPUT_LABEL (asm_out_file, sym);
6171 /* Return a new location list, given the begin and end range, and the
6172 expression. gensym tells us whether to generate a new internal symbol for
6173 this location list node, which is done for the head of the list only. */
6175 static inline dw_loc_list_ref
6176 new_loc_list (expr, begin, end, section, gensym)
6177 dw_loc_descr_ref expr;
6180 const char *section;
6183 dw_loc_list_ref retlist
6184 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6186 retlist->begin = begin;
6188 retlist->expr = expr;
6189 retlist->section = section;
6191 retlist->ll_symbol = gen_internal_sym ("LLST");
6196 /* Add a location description expression to a location list */
6199 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6200 dw_loc_list_ref *list_head;
6201 dw_loc_descr_ref descr;
6204 const char *section;
6208 /* Find the end of the chain. */
6209 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6212 /* Add a new location list node to the list */
6213 *d = new_loc_list (descr, begin, end, section, 0);
6216 /* Output the location list given to us */
6219 output_loc_list (list_head)
6220 dw_loc_list_ref list_head;
6222 dw_loc_list_ref curr = list_head;
6224 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6226 /* ??? This shouldn't be needed now that we've forced the
6227 compilation unit base address to zero when there is code
6228 in more than one section. */
6229 if (strcmp (curr->section, ".text") == 0)
6231 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6232 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
6233 "Location list base address specifier fake entry");
6234 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6235 "Location list base address specifier base");
6238 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
6242 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6243 "Location list begin address (%s)",
6244 list_head->ll_symbol);
6245 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6246 "Location list end address (%s)",
6247 list_head->ll_symbol);
6248 size = size_of_locs (curr->expr);
6250 /* Output the block length for this list of location operations. */
6253 dw2_asm_output_data (2, size, "%s", "Location expression size");
6255 output_loc_sequence (curr->expr);
6258 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6259 "Location list terminator begin (%s)",
6260 list_head->ll_symbol);
6261 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6262 "Location list terminator end (%s)",
6263 list_head->ll_symbol);
6266 /* Output the DIE and its attributes. Called recursively to generate
6267 the definitions of each child DIE. */
6277 /* If someone in another CU might refer to us, set up a symbol for
6278 them to point to. */
6279 if (die->die_symbol)
6280 output_die_symbol (die);
6282 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6283 die->die_offset, dwarf_tag_name (die->die_tag));
6285 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6287 const char *name = dwarf_attr_name (a->dw_attr);
6289 switch (AT_class (a))
6291 case dw_val_class_addr:
6292 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6295 case dw_val_class_offset:
6296 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6300 case dw_val_class_range_list:
6302 char *p = strchr (ranges_section_label, '\0');
6304 sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset);
6305 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6311 case dw_val_class_loc:
6312 size = size_of_locs (AT_loc (a));
6314 /* Output the block length for this list of location operations. */
6315 dw2_asm_output_data (constant_size (size), size, "%s", name);
6317 output_loc_sequence (AT_loc (a));
6320 case dw_val_class_const:
6321 /* ??? It would be slightly more efficient to use a scheme like is
6322 used for unsigned constants below, but gdb 4.x does not sign
6323 extend. Gdb 5.x does sign extend. */
6324 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6327 case dw_val_class_unsigned_const:
6328 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6329 AT_unsigned (a), "%s", name);
6332 case dw_val_class_long_long:
6334 unsigned HOST_WIDE_INT first, second;
6336 dw2_asm_output_data (1,
6337 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6340 if (WORDS_BIG_ENDIAN)
6342 first = a->dw_attr_val.v.val_long_long.hi;
6343 second = a->dw_attr_val.v.val_long_long.low;
6347 first = a->dw_attr_val.v.val_long_long.low;
6348 second = a->dw_attr_val.v.val_long_long.hi;
6351 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6352 first, "long long constant");
6353 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6358 case dw_val_class_float:
6362 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6365 for (i = 0; i < a->dw_attr_val.v.val_float.length; i++)
6366 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6367 "fp constant word %u", i);
6371 case dw_val_class_flag:
6372 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6375 case dw_val_class_loc_list:
6377 char *sym = AT_loc_list (a)->ll_symbol;
6381 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6382 loc_section_label, "%s", name);
6386 case dw_val_class_die_ref:
6387 if (AT_ref_external (a))
6389 char *sym = AT_ref (a)->die_symbol;
6393 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6395 else if (AT_ref (a)->die_offset == 0)
6398 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6402 case dw_val_class_fde_ref:
6406 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6407 a->dw_attr_val.v.val_fde_index * 2);
6408 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6412 case dw_val_class_lbl_id:
6413 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6416 case dw_val_class_lbl_offset:
6417 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6420 case dw_val_class_str:
6421 if (AT_string_form (a) == DW_FORM_strp)
6422 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6423 a->dw_attr_val.v.val_str->label,
6424 "%s: \"%s\"", name, AT_string (a));
6426 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6434 for (c = die->die_child; c != NULL; c = c->die_sib)
6437 /* Add null byte to terminate sibling list. */
6438 if (die->die_child != NULL)
6439 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6443 /* Output the compilation unit that appears at the beginning of the
6444 .debug_info section, and precedes the DIE descriptions. */
6447 output_compilation_unit_header ()
6449 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6450 "Length of Compilation Unit Info");
6451 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6452 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6453 "Offset Into Abbrev. Section");
6454 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6457 /* Output the compilation unit DIE and its children. */
6460 output_comp_unit (die)
6463 const char *secname;
6465 /* Even if there are no children of this DIE, we must output the information
6466 about the compilation unit. Otherwise, on an empty translation unit, we
6467 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6468 will then complain when examining the file. First mark all the DIEs in
6469 this CU so we know which get local refs. */
6472 build_abbrev_table (die);
6474 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6475 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6476 calc_die_sizes (die);
6478 if (die->die_symbol)
6480 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6482 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6484 die->die_symbol = NULL;
6487 secname = (const char *) DEBUG_INFO_SECTION;
6489 /* Output debugging information. */
6490 named_section_flags (secname, SECTION_DEBUG);
6491 output_compilation_unit_header ();
6494 /* Leave the marks on the main CU, so we can check them in
6496 if (die->die_symbol)
6500 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6501 output of lang_hooks.decl_printable_name for C++ looks like
6502 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6505 dwarf2_name (decl, scope)
6509 return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0);
6512 /* Add a new entry to .debug_pubnames if appropriate. */
6515 add_pubname (decl, die)
6521 if (! TREE_PUBLIC (decl))
6524 if (pubname_table_in_use == pubname_table_allocated)
6526 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6528 = (pubname_ref) xrealloc (pubname_table,
6529 (pubname_table_allocated
6530 * sizeof (pubname_entry)));
6533 p = &pubname_table[pubname_table_in_use++];
6535 p->name = xstrdup (dwarf2_name (decl, 1));
6538 /* Output the public names table used to speed up access to externally
6539 visible names. For now, only generate entries for externally
6540 visible procedures. */
6546 unsigned long pubnames_length = size_of_pubnames ();
6548 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6549 "Length of Public Names Info");
6550 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6551 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6552 "Offset of Compilation Unit Info");
6553 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6554 "Compilation Unit Length");
6556 for (i = 0; i < pubname_table_in_use; i++)
6558 pubname_ref pub = &pubname_table[i];
6560 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6561 if (pub->die->die_mark == 0)
6564 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6567 dw2_asm_output_nstring (pub->name, -1, "external name");
6570 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6573 /* Add a new entry to .debug_aranges if appropriate. */
6576 add_arange (decl, die)
6580 if (! DECL_SECTION_NAME (decl))
6583 if (arange_table_in_use == arange_table_allocated)
6585 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6586 arange_table = (dw_die_ref *)
6587 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6590 arange_table[arange_table_in_use++] = die;
6593 /* Output the information that goes into the .debug_aranges table.
6594 Namely, define the beginning and ending address range of the
6595 text section generated for this compilation unit. */
6601 unsigned long aranges_length = size_of_aranges ();
6603 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6604 "Length of Address Ranges Info");
6605 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6606 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6607 "Offset of Compilation Unit Info");
6608 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6609 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6611 /* We need to align to twice the pointer size here. */
6612 if (DWARF_ARANGES_PAD_SIZE)
6614 /* Pad using a 2 byte words so that padding is correct for any
6616 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6617 2 * DWARF2_ADDR_SIZE);
6618 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6619 dw2_asm_output_data (2, 0, NULL);
6622 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6623 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6624 text_section_label, "Length");
6626 for (i = 0; i < arange_table_in_use; i++)
6628 dw_die_ref die = arange_table[i];
6630 /* We shouldn't see aranges for DIEs outside of the main CU. */
6631 if (die->die_mark == 0)
6634 if (die->die_tag == DW_TAG_subprogram)
6636 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6638 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6639 get_AT_low_pc (die), "Length");
6643 /* A static variable; extract the symbol from DW_AT_location.
6644 Note that this code isn't currently hit, as we only emit
6645 aranges for functions (jason 9/23/99). */
6646 dw_attr_ref a = get_AT (die, DW_AT_location);
6647 dw_loc_descr_ref loc;
6649 if (! a || AT_class (a) != dw_val_class_loc)
6653 if (loc->dw_loc_opc != DW_OP_addr)
6656 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6657 loc->dw_loc_oprnd1.v.val_addr, "Address");
6658 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6659 get_AT_unsigned (die, DW_AT_byte_size),
6664 /* Output the terminator words. */
6665 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6666 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6669 /* Add a new entry to .debug_ranges. Return the offset at which it
6676 unsigned int in_use = ranges_table_in_use;
6678 if (in_use == ranges_table_allocated)
6680 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6681 ranges_table = (dw_ranges_ref)
6682 xrealloc (ranges_table, (ranges_table_allocated
6683 * sizeof (struct dw_ranges_struct)));
6686 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6687 ranges_table_in_use = in_use + 1;
6689 return in_use * 2 * DWARF2_ADDR_SIZE;
6696 static const char *const start_fmt = "Offset 0x%x";
6697 const char *fmt = start_fmt;
6699 for (i = 0; i < ranges_table_in_use; i++)
6701 int block_num = ranges_table[i].block_num;
6705 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6706 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6708 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6709 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6711 /* If all code is in the text section, then the compilation
6712 unit base address defaults to DW_AT_low_pc, which is the
6713 base of the text section. */
6714 if (separate_line_info_table_in_use == 0)
6716 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6718 fmt, i * 2 * DWARF2_ADDR_SIZE);
6719 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6720 text_section_label, NULL);
6723 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6724 compilation unit base address to zero, which allows us to
6725 use absolute addresses, and not worry about whether the
6726 target supports cross-section arithmetic. */
6729 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6730 fmt, i * 2 * DWARF2_ADDR_SIZE);
6731 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6738 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6739 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6745 /* Data structure containing information about input files. */
6748 char *path; /* Complete file name. */
6749 char *fname; /* File name part. */
6750 int length; /* Length of entire string. */
6751 int file_idx; /* Index in input file table. */
6752 int dir_idx; /* Index in directory table. */
6755 /* Data structure containing information about directories with source
6759 char *path; /* Path including directory name. */
6760 int length; /* Path length. */
6761 int prefix; /* Index of directory entry which is a prefix. */
6762 int count; /* Number of files in this directory. */
6763 int dir_idx; /* Index of directory used as base. */
6764 int used; /* Used in the end? */
6767 /* Callback function for file_info comparison. We sort by looking at
6768 the directories in the path. */
6771 file_info_cmp (p1, p2)
6775 const struct file_info *s1 = p1;
6776 const struct file_info *s2 = p2;
6780 /* Take care of file names without directories. We need to make sure that
6781 we return consistent values to qsort since some will get confused if
6782 we return the same value when identical operands are passed in opposite
6783 orders. So if neither has a directory, return 0 and otherwise return
6784 1 or -1 depending on which one has the directory. */
6785 if ((s1->path == s1->fname || s2->path == s2->fname))
6786 return (s2->path == s2->fname) - (s1->path == s1->fname);
6788 cp1 = (unsigned char *) s1->path;
6789 cp2 = (unsigned char *) s2->path;
6795 /* Reached the end of the first path? If so, handle like above. */
6796 if ((cp1 == (unsigned char *) s1->fname)
6797 || (cp2 == (unsigned char *) s2->fname))
6798 return ((cp2 == (unsigned char *) s2->fname)
6799 - (cp1 == (unsigned char *) s1->fname));
6801 /* Character of current path component the same? */
6802 else if (*cp1 != *cp2)
6807 /* Output the directory table and the file name table. We try to minimize
6808 the total amount of memory needed. A heuristic is used to avoid large
6809 slowdowns with many input files. */
6812 output_file_names ()
6814 struct file_info *files;
6815 struct dir_info *dirs;
6824 /* Allocate the various arrays we need. */
6825 files = (struct file_info *) alloca (file_table.in_use
6826 * sizeof (struct file_info));
6827 dirs = (struct dir_info *) alloca (file_table.in_use
6828 * sizeof (struct dir_info));
6830 /* Sort the file names. */
6831 for (i = 1; i < (int) file_table.in_use; i++)
6835 /* Skip all leading "./". */
6836 f = file_table.table[i];
6837 while (f[0] == '.' && f[1] == '/')
6840 /* Create a new array entry. */
6842 files[i].length = strlen (f);
6843 files[i].file_idx = i;
6845 /* Search for the file name part. */
6846 f = strrchr (f, '/');
6847 files[i].fname = f == NULL ? files[i].path : f + 1;
6850 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6852 /* Find all the different directories used. */
6853 dirs[0].path = files[1].path;
6854 dirs[0].length = files[1].fname - files[1].path;
6855 dirs[0].prefix = -1;
6857 dirs[0].dir_idx = 0;
6859 files[1].dir_idx = 0;
6862 for (i = 2; i < (int) file_table.in_use; i++)
6863 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6864 && memcmp (dirs[ndirs - 1].path, files[i].path,
6865 dirs[ndirs - 1].length) == 0)
6867 /* Same directory as last entry. */
6868 files[i].dir_idx = ndirs - 1;
6869 ++dirs[ndirs - 1].count;
6875 /* This is a new directory. */
6876 dirs[ndirs].path = files[i].path;
6877 dirs[ndirs].length = files[i].fname - files[i].path;
6878 dirs[ndirs].count = 1;
6879 dirs[ndirs].dir_idx = ndirs;
6880 dirs[ndirs].used = 0;
6881 files[i].dir_idx = ndirs;
6883 /* Search for a prefix. */
6884 dirs[ndirs].prefix = -1;
6885 for (j = 0; j < ndirs; j++)
6886 if (dirs[j].length < dirs[ndirs].length
6887 && dirs[j].length > 1
6888 && (dirs[ndirs].prefix == -1
6889 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6890 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6891 dirs[ndirs].prefix = j;
6896 /* Now to the actual work. We have to find a subset of the directories which
6897 allow expressing the file name using references to the directory table
6898 with the least amount of characters. We do not do an exhaustive search
6899 where we would have to check out every combination of every single
6900 possible prefix. Instead we use a heuristic which provides nearly optimal
6901 results in most cases and never is much off. */
6902 saved = (int *) alloca (ndirs * sizeof (int));
6903 savehere = (int *) alloca (ndirs * sizeof (int));
6905 memset (saved, '\0', ndirs * sizeof (saved[0]));
6906 for (i = 0; i < ndirs; i++)
6911 /* We can always save some space for the current directory. But this
6912 does not mean it will be enough to justify adding the directory. */
6913 savehere[i] = dirs[i].length;
6914 total = (savehere[i] - saved[i]) * dirs[i].count;
6916 for (j = i + 1; j < ndirs; j++)
6919 if (saved[j] < dirs[i].length)
6921 /* Determine whether the dirs[i] path is a prefix of the
6926 while (k != -1 && k != i)
6931 /* Yes it is. We can possibly safe some memory but
6932 writing the filenames in dirs[j] relative to
6934 savehere[j] = dirs[i].length;
6935 total += (savehere[j] - saved[j]) * dirs[j].count;
6940 /* Check whether we can safe enough to justify adding the dirs[i]
6942 if (total > dirs[i].length + 1)
6944 /* It's worthwhile adding. */
6945 for (j = i; j < ndirs; j++)
6946 if (savehere[j] > 0)
6948 /* Remember how much we saved for this directory so far. */
6949 saved[j] = savehere[j];
6951 /* Remember the prefix directory. */
6952 dirs[j].dir_idx = i;
6957 /* We have to emit them in the order they appear in the file_table array
6958 since the index is used in the debug info generation. To do this
6959 efficiently we generate a back-mapping of the indices first. */
6960 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6961 for (i = 1; i < (int) file_table.in_use; i++)
6963 backmap[files[i].file_idx] = i;
6965 /* Mark this directory as used. */
6966 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6969 /* That was it. We are ready to emit the information. First emit the
6970 directory name table. We have to make sure the first actually emitted
6971 directory name has index one; zero is reserved for the current working
6972 directory. Make sure we do not confuse these indices with the one for the
6973 constructed table (even though most of the time they are identical). */
6975 idx_offset = dirs[0].length > 0 ? 1 : 0;
6976 for (i = 1 - idx_offset; i < ndirs; i++)
6977 if (dirs[i].used != 0)
6979 dirs[i].used = idx++;
6980 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6981 "Directory Entry: 0x%x", dirs[i].used);
6984 dw2_asm_output_data (1, 0, "End directory table");
6986 /* Correct the index for the current working directory entry if it
6988 if (idx_offset == 0)
6991 /* Now write all the file names. */
6992 for (i = 1; i < (int) file_table.in_use; i++)
6994 int file_idx = backmap[i];
6995 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6997 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6998 "File Entry: 0x%x", i);
7000 /* Include directory index. */
7001 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
7003 /* Modification time. */
7004 dw2_asm_output_data_uleb128 (0, NULL);
7006 /* File length in bytes. */
7007 dw2_asm_output_data_uleb128 (0, NULL);
7010 dw2_asm_output_data (1, 0, "End file name table");
7014 /* Output the source line number correspondence information. This
7015 information goes into the .debug_line section. */
7020 char l1[20], l2[20], p1[20], p2[20];
7021 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7022 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7025 unsigned long lt_index;
7026 unsigned long current_line;
7029 unsigned long current_file;
7030 unsigned long function;
7032 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7033 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7034 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7035 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7037 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7038 "Length of Source Line Info");
7039 ASM_OUTPUT_LABEL (asm_out_file, l1);
7041 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7042 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7043 ASM_OUTPUT_LABEL (asm_out_file, p1);
7045 /* Define the architecture-dependent minimum instruction length (in
7046 bytes). In this implementation of DWARF, this field is used for
7047 information purposes only. Since GCC generates assembly language,
7048 we have no a priori knowledge of how many instruction bytes are
7049 generated for each source line, and therefore can use only the
7050 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7051 commands. Accordingly, we fix this as `1', which is "correct
7052 enough" for all architectures, and don't let the target override. */
7053 dw2_asm_output_data (1, 1,
7054 "Minimum Instruction Length");
7056 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7057 "Default is_stmt_start flag");
7058 dw2_asm_output_data (1, DWARF_LINE_BASE,
7059 "Line Base Value (Special Opcodes)");
7060 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7061 "Line Range Value (Special Opcodes)");
7062 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7063 "Special Opcode Base");
7065 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7069 case DW_LNS_advance_pc:
7070 case DW_LNS_advance_line:
7071 case DW_LNS_set_file:
7072 case DW_LNS_set_column:
7073 case DW_LNS_fixed_advance_pc:
7081 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7085 /* Write out the information about the files we use. */
7086 output_file_names ();
7087 ASM_OUTPUT_LABEL (asm_out_file, p2);
7089 /* We used to set the address register to the first location in the text
7090 section here, but that didn't accomplish anything since we already
7091 have a line note for the opening brace of the first function. */
7093 /* Generate the line number to PC correspondence table, encoded as
7094 a series of state machine operations. */
7097 strcpy (prev_line_label, text_section_label);
7098 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7100 dw_line_info_ref line_info = &line_info_table[lt_index];
7103 /* Disable this optimization for now; GDB wants to see two line notes
7104 at the beginning of a function so it can find the end of the
7107 /* Don't emit anything for redundant notes. Just updating the
7108 address doesn't accomplish anything, because we already assume
7109 that anything after the last address is this line. */
7110 if (line_info->dw_line_num == current_line
7111 && line_info->dw_file_num == current_file)
7115 /* Emit debug info for the address of the current line.
7117 Unfortunately, we have little choice here currently, and must always
7118 use the most general form. GCC does not know the address delta
7119 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7120 attributes which will give an upper bound on the address range. We
7121 could perhaps use length attributes to determine when it is safe to
7122 use DW_LNS_fixed_advance_pc. */
7124 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7127 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7128 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7129 "DW_LNS_fixed_advance_pc");
7130 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7134 /* This can handle any delta. This takes
7135 4+DWARF2_ADDR_SIZE bytes. */
7136 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7137 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7138 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7139 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7142 strcpy (prev_line_label, line_label);
7144 /* Emit debug info for the source file of the current line, if
7145 different from the previous line. */
7146 if (line_info->dw_file_num != current_file)
7148 current_file = line_info->dw_file_num;
7149 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7150 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7151 file_table.table[current_file]);
7154 /* Emit debug info for the current line number, choosing the encoding
7155 that uses the least amount of space. */
7156 if (line_info->dw_line_num != current_line)
7158 line_offset = line_info->dw_line_num - current_line;
7159 line_delta = line_offset - DWARF_LINE_BASE;
7160 current_line = line_info->dw_line_num;
7161 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7162 /* This can handle deltas from -10 to 234, using the current
7163 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7165 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7166 "line %lu", current_line);
7169 /* This can handle any delta. This takes at least 4 bytes,
7170 depending on the value being encoded. */
7171 dw2_asm_output_data (1, DW_LNS_advance_line,
7172 "advance to line %lu", current_line);
7173 dw2_asm_output_data_sleb128 (line_offset, NULL);
7174 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7178 /* We still need to start a new row, so output a copy insn. */
7179 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7182 /* Emit debug info for the address of the end of the function. */
7185 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7186 "DW_LNS_fixed_advance_pc");
7187 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7191 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7192 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7193 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7194 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7197 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7198 dw2_asm_output_data_uleb128 (1, NULL);
7199 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7204 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7206 dw_separate_line_info_ref line_info
7207 = &separate_line_info_table[lt_index];
7210 /* Don't emit anything for redundant notes. */
7211 if (line_info->dw_line_num == current_line
7212 && line_info->dw_file_num == current_file
7213 && line_info->function == function)
7217 /* Emit debug info for the address of the current line. If this is
7218 a new function, or the first line of a function, then we need
7219 to handle it differently. */
7220 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7222 if (function != line_info->function)
7224 function = line_info->function;
7226 /* Set the address register to the first line in the function */
7227 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7228 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7229 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7230 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7234 /* ??? See the DW_LNS_advance_pc comment above. */
7237 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7238 "DW_LNS_fixed_advance_pc");
7239 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7243 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7244 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7245 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7246 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7250 strcpy (prev_line_label, line_label);
7252 /* Emit debug info for the source file of the current line, if
7253 different from the previous line. */
7254 if (line_info->dw_file_num != current_file)
7256 current_file = line_info->dw_file_num;
7257 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7258 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7259 file_table.table[current_file]);
7262 /* Emit debug info for the current line number, choosing the encoding
7263 that uses the least amount of space. */
7264 if (line_info->dw_line_num != current_line)
7266 line_offset = line_info->dw_line_num - current_line;
7267 line_delta = line_offset - DWARF_LINE_BASE;
7268 current_line = line_info->dw_line_num;
7269 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7270 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7271 "line %lu", current_line);
7274 dw2_asm_output_data (1, DW_LNS_advance_line,
7275 "advance to line %lu", current_line);
7276 dw2_asm_output_data_sleb128 (line_offset, NULL);
7277 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7281 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7289 /* If we're done with a function, end its sequence. */
7290 if (lt_index == separate_line_info_table_in_use
7291 || separate_line_info_table[lt_index].function != function)
7296 /* Emit debug info for the address of the end of the function. */
7297 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7300 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7301 "DW_LNS_fixed_advance_pc");
7302 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7306 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7307 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7308 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7309 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7312 /* Output the marker for the end of this sequence. */
7313 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7314 dw2_asm_output_data_uleb128 (1, NULL);
7315 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7319 /* Output the marker for the end of the line number info. */
7320 ASM_OUTPUT_LABEL (asm_out_file, l2);
7323 /* Given a pointer to a tree node for some base type, return a pointer to
7324 a DIE that describes the given type.
7326 This routine must only be called for GCC type nodes that correspond to
7327 Dwarf base (fundamental) types. */
7330 base_type_die (type)
7333 dw_die_ref base_type_result;
7334 const char *type_name;
7335 enum dwarf_type encoding;
7336 tree name = TYPE_NAME (type);
7338 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7343 if (TREE_CODE (name) == TYPE_DECL)
7344 name = DECL_NAME (name);
7346 type_name = IDENTIFIER_POINTER (name);
7349 type_name = "__unknown__";
7351 switch (TREE_CODE (type))
7354 /* Carefully distinguish the C character types, without messing
7355 up if the language is not C. Note that we check only for the names
7356 that contain spaces; other names might occur by coincidence in other
7358 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7359 && (type == char_type_node
7360 || ! strcmp (type_name, "signed char")
7361 || ! strcmp (type_name, "unsigned char"))))
7363 if (TREE_UNSIGNED (type))
7364 encoding = DW_ATE_unsigned;
7366 encoding = DW_ATE_signed;
7369 /* else fall through. */
7372 /* GNU Pascal/Ada CHAR type. Not used in C. */
7373 if (TREE_UNSIGNED (type))
7374 encoding = DW_ATE_unsigned_char;
7376 encoding = DW_ATE_signed_char;
7380 encoding = DW_ATE_float;
7383 /* Dwarf2 doesn't know anything about complex ints, so use
7384 a user defined type for it. */
7386 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7387 encoding = DW_ATE_complex_float;
7389 encoding = DW_ATE_lo_user;
7393 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7394 encoding = DW_ATE_boolean;
7398 /* No other TREE_CODEs are Dwarf fundamental types. */
7402 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
7403 if (demangle_name_func)
7404 type_name = (*demangle_name_func) (type_name);
7406 add_AT_string (base_type_result, DW_AT_name, type_name);
7407 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7408 int_size_in_bytes (type));
7409 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7411 return base_type_result;
7414 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7415 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7416 a given type is generally the same as the given type, except that if the
7417 given type is a pointer or reference type, then the root type of the given
7418 type is the root type of the "basis" type for the pointer or reference
7419 type. (This definition of the "root" type is recursive.) Also, the root
7420 type of a `const' qualified type or a `volatile' qualified type is the
7421 root type of the given type without the qualifiers. */
7427 if (TREE_CODE (type) == ERROR_MARK)
7428 return error_mark_node;
7430 switch (TREE_CODE (type))
7433 return error_mark_node;
7436 case REFERENCE_TYPE:
7437 return type_main_variant (root_type (TREE_TYPE (type)));
7440 return type_main_variant (type);
7444 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7445 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7451 switch (TREE_CODE (type))
7466 case QUAL_UNION_TYPE:
7471 case REFERENCE_TYPE:
7485 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7486 entry that chains various modifiers in front of the given type. */
7489 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7492 int is_volatile_type;
7493 dw_die_ref context_die;
7495 enum tree_code code = TREE_CODE (type);
7496 dw_die_ref mod_type_die = NULL;
7497 dw_die_ref sub_die = NULL;
7498 tree item_type = NULL;
7500 if (code != ERROR_MARK)
7502 tree qualified_type;
7504 /* See if we already have the appropriately qualified variant of
7507 = get_qualified_type (type,
7508 ((is_const_type ? TYPE_QUAL_CONST : 0)
7510 ? TYPE_QUAL_VOLATILE : 0)));
7512 /* If we do, then we can just use its DIE, if it exists. */
7515 mod_type_die = lookup_type_die (qualified_type);
7517 return mod_type_die;
7520 /* Handle C typedef types. */
7521 if (qualified_type && TYPE_NAME (qualified_type)
7522 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7523 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7525 tree type_name = TYPE_NAME (qualified_type);
7526 tree dtype = TREE_TYPE (type_name);
7528 if (qualified_type == dtype)
7530 /* For a named type, use the typedef. */
7531 gen_type_die (qualified_type, context_die);
7532 mod_type_die = lookup_type_die (qualified_type);
7534 else if (is_const_type < TYPE_READONLY (dtype)
7535 || is_volatile_type < TYPE_VOLATILE (dtype))
7536 /* cv-unqualified version of named type. Just use the unnamed
7537 type to which it refers. */
7539 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7540 is_const_type, is_volatile_type,
7543 /* Else cv-qualified version of named type; fall through. */
7549 else if (is_const_type)
7551 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
7552 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7554 else if (is_volatile_type)
7556 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
7557 sub_die = modified_type_die (type, 0, 0, context_die);
7559 else if (code == POINTER_TYPE)
7561 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
7562 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7564 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7566 item_type = TREE_TYPE (type);
7568 else if (code == REFERENCE_TYPE)
7570 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
7571 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7573 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7575 item_type = TREE_TYPE (type);
7577 else if (is_base_type (type))
7578 mod_type_die = base_type_die (type);
7581 gen_type_die (type, context_die);
7583 /* We have to get the type_main_variant here (and pass that to the
7584 `lookup_type_die' routine) because the ..._TYPE node we have
7585 might simply be a *copy* of some original type node (where the
7586 copy was created to help us keep track of typedef names) and
7587 that copy might have a different TYPE_UID from the original
7589 if (TREE_CODE (type) != VECTOR_TYPE)
7590 mod_type_die = lookup_type_die (type_main_variant (type));
7592 /* Vectors have the debugging information in the type,
7593 not the main variant. */
7594 mod_type_die = lookup_type_die (type);
7595 if (mod_type_die == NULL)
7599 /* We want to equate the qualified type to the die below. */
7600 type = qualified_type;
7604 equate_type_number_to_die (type, mod_type_die);
7606 /* We must do this after the equate_type_number_to_die call, in case
7607 this is a recursive type. This ensures that the modified_type_die
7608 recursion will terminate even if the type is recursive. Recursive
7609 types are possible in Ada. */
7610 sub_die = modified_type_die (item_type,
7611 TYPE_READONLY (item_type),
7612 TYPE_VOLATILE (item_type),
7615 if (sub_die != NULL)
7616 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7618 return mod_type_die;
7621 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7622 an enumerated type. */
7628 return TREE_CODE (type) == ENUMERAL_TYPE;
7631 /* Return the register number described by a given RTL node. */
7637 unsigned regno = REGNO (rtl);
7639 if (regno >= FIRST_PSEUDO_REGISTER)
7642 return DBX_REGISTER_NUMBER (regno);
7645 /* Return a location descriptor that designates a machine register or
7646 zero if there is no such. */
7648 static dw_loc_descr_ref
7649 reg_loc_descriptor (rtl)
7652 dw_loc_descr_ref loc_result = NULL;
7655 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7658 reg = reg_number (rtl);
7660 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7662 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7667 /* Return a location descriptor that designates a constant. */
7669 static dw_loc_descr_ref
7670 int_loc_descriptor (i)
7673 enum dwarf_location_atom op;
7675 /* Pick the smallest representation of a constant, rather than just
7676 defaulting to the LEB encoding. */
7680 op = DW_OP_lit0 + i;
7683 else if (i <= 0xffff)
7685 else if (HOST_BITS_PER_WIDE_INT == 32
7695 else if (i >= -0x8000)
7697 else if (HOST_BITS_PER_WIDE_INT == 32
7698 || i >= -0x80000000)
7704 return new_loc_descr (op, i, 0);
7707 /* Return a location descriptor that designates a base+offset location. */
7709 static dw_loc_descr_ref
7710 based_loc_descr (reg, offset)
7714 dw_loc_descr_ref loc_result;
7715 /* For the "frame base", we use the frame pointer or stack pointer
7716 registers, since the RTL for local variables is relative to one of
7718 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7719 ? HARD_FRAME_POINTER_REGNUM
7720 : STACK_POINTER_REGNUM);
7723 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7725 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7727 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7732 /* Return true if this RTL expression describes a base+offset calculation. */
7738 return (GET_CODE (rtl) == PLUS
7739 && ((GET_CODE (XEXP (rtl, 0)) == REG
7740 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
7741 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7744 /* The following routine converts the RTL for a variable or parameter
7745 (resident in memory) into an equivalent Dwarf representation of a
7746 mechanism for getting the address of that same variable onto the top of a
7747 hypothetical "address evaluation" stack.
7749 When creating memory location descriptors, we are effectively transforming
7750 the RTL for a memory-resident object into its Dwarf postfix expression
7751 equivalent. This routine recursively descends an RTL tree, turning
7752 it into Dwarf postfix code as it goes.
7754 MODE is the mode of the memory reference, needed to handle some
7755 autoincrement addressing modes.
7757 Return 0 if we can't represent the location. */
7759 static dw_loc_descr_ref
7760 mem_loc_descriptor (rtl, mode)
7762 enum machine_mode mode;
7764 dw_loc_descr_ref mem_loc_result = NULL;
7766 /* Note that for a dynamically sized array, the location we will generate a
7767 description of here will be the lowest numbered location which is
7768 actually within the array. That's *not* necessarily the same as the
7769 zeroth element of the array. */
7771 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7772 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7775 switch (GET_CODE (rtl))
7780 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7781 just fall into the SUBREG code. */
7783 /* ... fall through ... */
7786 /* The case of a subreg may arise when we have a local (register)
7787 variable or a formal (register) parameter which doesn't quite fill
7788 up an entire register. For now, just assume that it is
7789 legitimate to make the Dwarf info refer to the whole register which
7790 contains the given subreg. */
7791 rtl = SUBREG_REG (rtl);
7793 /* ... fall through ... */
7796 /* Whenever a register number forms a part of the description of the
7797 method for calculating the (dynamic) address of a memory resident
7798 object, DWARF rules require the register number be referred to as
7799 a "base register". This distinction is not based in any way upon
7800 what category of register the hardware believes the given register
7801 belongs to. This is strictly DWARF terminology we're dealing with
7802 here. Note that in cases where the location of a memory-resident
7803 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7804 OP_CONST (0)) the actual DWARF location descriptor that we generate
7805 may just be OP_BASEREG (basereg). This may look deceptively like
7806 the object in question was allocated to a register (rather than in
7807 memory) so DWARF consumers need to be aware of the subtle
7808 distinction between OP_REG and OP_BASEREG. */
7809 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
7810 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7814 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7815 if (mem_loc_result != 0)
7816 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7820 /* Some ports can transform a symbol ref into a label ref, because
7821 the symbol ref is too far away and has to be dumped into a constant
7825 /* Alternatively, the symbol in the constant pool might be referenced
7826 by a different symbol. */
7827 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
7830 rtx tmp = get_pool_constant_mark (rtl, &marked);
7832 if (GET_CODE (tmp) == SYMBOL_REF)
7835 if (CONSTANT_POOL_ADDRESS_P (tmp))
7836 get_pool_constant_mark (tmp, &marked);
7841 /* If all references to this pool constant were optimized away,
7842 it was not output and thus we can't represent it.
7843 FIXME: might try to use DW_OP_const_value here, though
7844 DW_OP_piece complicates it. */
7849 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7850 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7851 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
7852 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
7856 /* Extract the PLUS expression nested inside and fall into
7858 rtl = XEXP (rtl, 1);
7863 /* Turn these into a PLUS expression and fall into the PLUS code
7865 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7866 GEN_INT (GET_CODE (rtl) == PRE_INC
7867 ? GET_MODE_UNIT_SIZE (mode)
7868 : -GET_MODE_UNIT_SIZE (mode)));
7870 /* ... fall through ... */
7874 if (is_based_loc (rtl))
7875 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7876 INTVAL (XEXP (rtl, 1)));
7879 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7880 if (mem_loc_result == 0)
7883 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7884 && INTVAL (XEXP (rtl, 1)) >= 0)
7885 add_loc_descr (&mem_loc_result,
7886 new_loc_descr (DW_OP_plus_uconst,
7887 INTVAL (XEXP (rtl, 1)), 0));
7890 add_loc_descr (&mem_loc_result,
7891 mem_loc_descriptor (XEXP (rtl, 1), mode));
7892 add_loc_descr (&mem_loc_result,
7893 new_loc_descr (DW_OP_plus, 0, 0));
7900 /* If a pseudo-reg is optimized away, it is possible for it to
7901 be replaced with a MEM containing a multiply. */
7902 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
7903 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
7905 if (op0 == 0 || op1 == 0)
7908 mem_loc_result = op0;
7909 add_loc_descr (&mem_loc_result, op1);
7910 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7915 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7919 /* If this is a MEM, return its address. Otherwise, we can't
7921 if (GET_CODE (XEXP (rtl, 0)) == MEM)
7922 return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode);
7930 return mem_loc_result;
7933 /* Return a descriptor that describes the concatenation of two locations.
7934 This is typically a complex variable. */
7936 static dw_loc_descr_ref
7937 concat_loc_descriptor (x0, x1)
7940 dw_loc_descr_ref cc_loc_result = NULL;
7941 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
7942 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
7944 if (x0_ref == 0 || x1_ref == 0)
7947 cc_loc_result = x0_ref;
7948 add_loc_descr (&cc_loc_result,
7949 new_loc_descr (DW_OP_piece,
7950 GET_MODE_SIZE (GET_MODE (x0)), 0));
7952 add_loc_descr (&cc_loc_result, x1_ref);
7953 add_loc_descr (&cc_loc_result,
7954 new_loc_descr (DW_OP_piece,
7955 GET_MODE_SIZE (GET_MODE (x1)), 0));
7957 return cc_loc_result;
7960 /* Output a proper Dwarf location descriptor for a variable or parameter
7961 which is either allocated in a register or in a memory location. For a
7962 register, we just generate an OP_REG and the register number. For a
7963 memory location we provide a Dwarf postfix expression describing how to
7964 generate the (dynamic) address of the object onto the address stack.
7966 If we don't know how to describe it, return 0. */
7968 static dw_loc_descr_ref
7969 loc_descriptor (rtl)
7972 dw_loc_descr_ref loc_result = NULL;
7974 switch (GET_CODE (rtl))
7977 /* The case of a subreg may arise when we have a local (register)
7978 variable or a formal (register) parameter which doesn't quite fill
7979 up an entire register. For now, just assume that it is
7980 legitimate to make the Dwarf info refer to the whole register which
7981 contains the given subreg. */
7982 rtl = SUBREG_REG (rtl);
7984 /* ... fall through ... */
7987 loc_result = reg_loc_descriptor (rtl);
7991 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7995 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8005 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8006 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8007 looking for an address. Otherwise, we return a value. If we can't make a
8008 descriptor, return 0. */
8010 static dw_loc_descr_ref
8011 loc_descriptor_from_tree (loc, addressp)
8015 dw_loc_descr_ref ret, ret1;
8017 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
8018 enum dwarf_location_atom op;
8020 /* ??? Most of the time we do not take proper care for sign/zero
8021 extending the values properly. Hopefully this won't be a real
8024 switch (TREE_CODE (loc))
8029 case WITH_RECORD_EXPR:
8030 case PLACEHOLDER_EXPR:
8031 /* This case involves extracting fields from an object to determine the
8032 position of other fields. We don't try to encode this here. The
8033 only user of this is Ada, which encodes the needed information using
8034 the names of types. */
8041 /* We can support this only if we can look through conversions and
8042 find an INDIRECT_EXPR. */
8043 for (loc = TREE_OPERAND (loc, 0);
8044 TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR
8045 || TREE_CODE (loc) == NON_LVALUE_EXPR
8046 || TREE_CODE (loc) == VIEW_CONVERT_EXPR
8047 || TREE_CODE (loc) == SAVE_EXPR;
8048 loc = TREE_OPERAND (loc, 0))
8051 return (TREE_CODE (loc) == INDIRECT_REF
8052 ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp)
8056 if (DECL_THREAD_LOCAL (loc))
8060 #ifndef ASM_OUTPUT_DWARF_DTPREL
8061 /* If this is not defined, we have no way to emit the data. */
8065 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8066 look up addresses of objects in the current module. */
8067 if (! (*targetm.binds_local_p) (loc))
8070 rtl = rtl_for_decl_location (loc);
8071 if (rtl == NULL_RTX)
8074 if (GET_CODE (rtl) != MEM)
8076 rtl = XEXP (rtl, 0);
8077 if (! CONSTANT_P (rtl))
8080 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
8081 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8082 ret->dw_loc_oprnd1.v.val_addr = rtl;
8084 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
8085 add_loc_descr (&ret, ret1);
8094 rtx rtl = rtl_for_decl_location (loc);
8096 if (rtl == NULL_RTX)
8098 else if (CONSTANT_P (rtl))
8100 ret = new_loc_descr (DW_OP_addr, 0, 0);
8101 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8102 ret->dw_loc_oprnd1.v.val_addr = rtl;
8107 enum machine_mode mode = GET_MODE (rtl);
8109 if (GET_CODE (rtl) == MEM)
8112 rtl = XEXP (rtl, 0);
8115 ret = mem_loc_descriptor (rtl, mode);
8121 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8126 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
8130 case NON_LVALUE_EXPR:
8131 case VIEW_CONVERT_EXPR:
8133 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8138 case ARRAY_RANGE_REF:
8141 HOST_WIDE_INT bitsize, bitpos, bytepos;
8142 enum machine_mode mode;
8145 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8146 &unsignedp, &volatilep);
8151 ret = loc_descriptor_from_tree (obj, 1);
8153 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
8156 if (offset != NULL_TREE)
8158 /* Variable offset. */
8159 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8160 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8166 bytepos = bitpos / BITS_PER_UNIT;
8168 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8169 else if (bytepos < 0)
8171 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8172 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8178 if (host_integerp (loc, 0))
8179 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8184 case TRUTH_AND_EXPR:
8185 case TRUTH_ANDIF_EXPR:
8190 case TRUTH_XOR_EXPR:
8196 case TRUTH_ORIF_EXPR:
8201 case TRUNC_DIV_EXPR:
8209 case TRUNC_MOD_EXPR:
8222 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8226 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8227 && host_integerp (TREE_OPERAND (loc, 1), 0))
8229 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8233 add_loc_descr (&ret,
8234 new_loc_descr (DW_OP_plus_uconst,
8235 tree_low_cst (TREE_OPERAND (loc, 1),
8245 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8252 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8259 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8266 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8281 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8282 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8283 if (ret == 0 || ret1 == 0)
8286 add_loc_descr (&ret, ret1);
8287 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8290 case TRUTH_NOT_EXPR:
8304 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8308 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8312 loc = build (COND_EXPR, TREE_TYPE (loc),
8313 build (LT_EXPR, integer_type_node,
8314 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8315 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8317 /* ... fall through ... */
8321 dw_loc_descr_ref lhs
8322 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8323 dw_loc_descr_ref rhs
8324 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8325 dw_loc_descr_ref bra_node, jump_node, tmp;
8327 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8328 if (ret == 0 || lhs == 0 || rhs == 0)
8331 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8332 add_loc_descr (&ret, bra_node);
8334 add_loc_descr (&ret, rhs);
8335 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8336 add_loc_descr (&ret, jump_node);
8338 add_loc_descr (&ret, lhs);
8339 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8340 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
8342 /* ??? Need a node to point the skip at. Use a nop. */
8343 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8344 add_loc_descr (&ret, tmp);
8345 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8346 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8354 /* Show if we can't fill the request for an address. */
8355 if (addressp && indirect_p == 0)
8358 /* If we've got an address and don't want one, dereference. */
8359 if (!addressp && indirect_p > 0)
8361 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8363 if (size > DWARF2_ADDR_SIZE || size == -1)
8365 else if (size == DWARF2_ADDR_SIZE)
8368 op = DW_OP_deref_size;
8370 add_loc_descr (&ret, new_loc_descr (op, size, 0));
8376 /* Given a value, round it up to the lowest multiple of `boundary'
8377 which is not less than the value itself. */
8379 static inline HOST_WIDE_INT
8380 ceiling (value, boundary)
8381 HOST_WIDE_INT value;
8382 unsigned int boundary;
8384 return (((value + boundary - 1) / boundary) * boundary);
8387 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8388 pointer to the declared type for the relevant field variable, or return
8389 `integer_type_node' if the given node turns out to be an
8398 if (TREE_CODE (decl) == ERROR_MARK)
8399 return integer_type_node;
8401 type = DECL_BIT_FIELD_TYPE (decl);
8402 if (type == NULL_TREE)
8403 type = TREE_TYPE (decl);
8408 /* Given a pointer to a tree node, return the alignment in bits for
8409 it, or else return BITS_PER_WORD if the node actually turns out to
8410 be an ERROR_MARK node. */
8412 static inline unsigned
8413 simple_type_align_in_bits (type)
8416 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8419 static inline unsigned
8420 simple_decl_align_in_bits (decl)
8423 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8426 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8427 node, return the size in bits for the type if it is a constant, or else
8428 return the alignment for the type if the type's size is not constant, or
8429 else return BITS_PER_WORD if the type actually turns out to be an
8432 static inline unsigned HOST_WIDE_INT
8433 simple_type_size_in_bits (type)
8437 if (TREE_CODE (type) == ERROR_MARK)
8438 return BITS_PER_WORD;
8439 else if (TYPE_SIZE (type) == NULL_TREE)
8441 else if (host_integerp (TYPE_SIZE (type), 1))
8442 return tree_low_cst (TYPE_SIZE (type), 1);
8444 return TYPE_ALIGN (type);
8447 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8448 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8449 or return 0 if we are unable to determine what that offset is, either
8450 because the argument turns out to be a pointer to an ERROR_MARK node, or
8451 because the offset is actually variable. (We can't handle the latter case
8454 static HOST_WIDE_INT
8455 field_byte_offset (decl)
8458 unsigned int type_align_in_bits;
8459 unsigned int decl_align_in_bits;
8460 unsigned HOST_WIDE_INT type_size_in_bits;
8461 HOST_WIDE_INT object_offset_in_bits;
8463 tree field_size_tree;
8464 HOST_WIDE_INT bitpos_int;
8465 HOST_WIDE_INT deepest_bitpos;
8466 unsigned HOST_WIDE_INT field_size_in_bits;
8468 if (TREE_CODE (decl) == ERROR_MARK)
8470 else if (TREE_CODE (decl) != FIELD_DECL)
8473 type = field_type (decl);
8474 field_size_tree = DECL_SIZE (decl);
8476 /* The size could be unspecified if there was an error, or for
8477 a flexible array member. */
8478 if (! field_size_tree)
8479 field_size_tree = bitsize_zero_node;
8481 /* We cannot yet cope with fields whose positions are variable, so
8482 for now, when we see such things, we simply return 0. Someday, we may
8483 be able to handle such cases, but it will be damn difficult. */
8484 if (! host_integerp (bit_position (decl), 0))
8487 bitpos_int = int_bit_position (decl);
8489 /* If we don't know the size of the field, pretend it's a full word. */
8490 if (host_integerp (field_size_tree, 1))
8491 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8493 field_size_in_bits = BITS_PER_WORD;
8495 type_size_in_bits = simple_type_size_in_bits (type);
8496 type_align_in_bits = simple_type_align_in_bits (type);
8497 decl_align_in_bits = simple_decl_align_in_bits (decl);
8499 /* The GCC front-end doesn't make any attempt to keep track of the starting
8500 bit offset (relative to the start of the containing structure type) of the
8501 hypothetical "containing object" for a bit-field. Thus, when computing
8502 the byte offset value for the start of the "containing object" of a
8503 bit-field, we must deduce this information on our own. This can be rather
8504 tricky to do in some cases. For example, handling the following structure
8505 type definition when compiling for an i386/i486 target (which only aligns
8506 long long's to 32-bit boundaries) can be very tricky:
8508 struct S { int field1; long long field2:31; };
8510 Fortunately, there is a simple rule-of-thumb which can be used in such
8511 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8512 structure shown above. It decides to do this based upon one simple rule
8513 for bit-field allocation. GCC allocates each "containing object" for each
8514 bit-field at the first (i.e. lowest addressed) legitimate alignment
8515 boundary (based upon the required minimum alignment for the declared type
8516 of the field) which it can possibly use, subject to the condition that
8517 there is still enough available space remaining in the containing object
8518 (when allocated at the selected point) to fully accommodate all of the
8519 bits of the bit-field itself.
8521 This simple rule makes it obvious why GCC allocates 8 bytes for each
8522 object of the structure type shown above. When looking for a place to
8523 allocate the "containing object" for `field2', the compiler simply tries
8524 to allocate a 64-bit "containing object" at each successive 32-bit
8525 boundary (starting at zero) until it finds a place to allocate that 64-
8526 bit field such that at least 31 contiguous (and previously unallocated)
8527 bits remain within that selected 64 bit field. (As it turns out, for the
8528 example above, the compiler finds it is OK to allocate the "containing
8529 object" 64-bit field at bit-offset zero within the structure type.)
8531 Here we attempt to work backwards from the limited set of facts we're
8532 given, and we try to deduce from those facts, where GCC must have believed
8533 that the containing object started (within the structure type). The value
8534 we deduce is then used (by the callers of this routine) to generate
8535 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8536 and, in the case of DW_AT_location, regular fields as well). */
8538 /* Figure out the bit-distance from the start of the structure to the
8539 "deepest" bit of the bit-field. */
8540 deepest_bitpos = bitpos_int + field_size_in_bits;
8542 /* This is the tricky part. Use some fancy footwork to deduce where the
8543 lowest addressed bit of the containing object must be. */
8544 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8546 /* Round up to type_align by default. This works best for bitfields. */
8547 object_offset_in_bits += type_align_in_bits - 1;
8548 object_offset_in_bits /= type_align_in_bits;
8549 object_offset_in_bits *= type_align_in_bits;
8551 if (object_offset_in_bits > bitpos_int)
8553 /* Sigh, the decl must be packed. */
8554 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8556 /* Round up to decl_align instead. */
8557 object_offset_in_bits += decl_align_in_bits - 1;
8558 object_offset_in_bits /= decl_align_in_bits;
8559 object_offset_in_bits *= decl_align_in_bits;
8562 return object_offset_in_bits / BITS_PER_UNIT;
8565 /* The following routines define various Dwarf attributes and any data
8566 associated with them. */
8568 /* Add a location description attribute value to a DIE.
8570 This emits location attributes suitable for whole variables and
8571 whole parameters. Note that the location attributes for struct fields are
8572 generated by the routine `data_member_location_attribute' below. */
8575 add_AT_location_description (die, attr_kind, descr)
8577 enum dwarf_attribute attr_kind;
8578 dw_loc_descr_ref descr;
8581 add_AT_loc (die, attr_kind, descr);
8584 /* Attach the specialized form of location attribute used for data members of
8585 struct and union types. In the special case of a FIELD_DECL node which
8586 represents a bit-field, the "offset" part of this special location
8587 descriptor must indicate the distance in bytes from the lowest-addressed
8588 byte of the containing struct or union type to the lowest-addressed byte of
8589 the "containing object" for the bit-field. (See the `field_byte_offset'
8592 For any given bit-field, the "containing object" is a hypothetical object
8593 (of some integral or enum type) within which the given bit-field lives. The
8594 type of this hypothetical "containing object" is always the same as the
8595 declared type of the individual bit-field itself (for GCC anyway... the
8596 DWARF spec doesn't actually mandate this). Note that it is the size (in
8597 bytes) of the hypothetical "containing object" which will be given in the
8598 DW_AT_byte_size attribute for this bit-field. (See the
8599 `byte_size_attribute' function below.) It is also used when calculating the
8600 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8604 add_data_member_location_attribute (die, decl)
8609 dw_loc_descr_ref loc_descr = 0;
8611 if (TREE_CODE (decl) == TREE_VEC)
8613 /* We're working on the TAG_inheritance for a base class. */
8614 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
8616 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8617 aren't at a fixed offset from all (sub)objects of the same
8618 type. We need to extract the appropriate offset from our
8619 vtable. The following dwarf expression means
8621 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8623 This is specific to the V3 ABI, of course. */
8625 dw_loc_descr_ref tmp;
8627 /* Make a copy of the object address. */
8628 tmp = new_loc_descr (DW_OP_dup, 0, 0);
8629 add_loc_descr (&loc_descr, tmp);
8631 /* Extract the vtable address. */
8632 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8633 add_loc_descr (&loc_descr, tmp);
8635 /* Calculate the address of the offset. */
8636 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
8640 tmp = int_loc_descriptor (-offset);
8641 add_loc_descr (&loc_descr, tmp);
8642 tmp = new_loc_descr (DW_OP_minus, 0, 0);
8643 add_loc_descr (&loc_descr, tmp);
8645 /* Extract the offset. */
8646 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8647 add_loc_descr (&loc_descr, tmp);
8649 /* Add it to the object address. */
8650 tmp = new_loc_descr (DW_OP_plus, 0, 0);
8651 add_loc_descr (&loc_descr, tmp);
8654 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8657 offset = field_byte_offset (decl);
8661 enum dwarf_location_atom op;
8663 /* The DWARF2 standard says that we should assume that the structure
8664 address is already on the stack, so we can specify a structure field
8665 address by using DW_OP_plus_uconst. */
8667 #ifdef MIPS_DEBUGGING_INFO
8668 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8669 operator correctly. It works only if we leave the offset on the
8673 op = DW_OP_plus_uconst;
8676 loc_descr = new_loc_descr (op, offset, 0);
8679 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8682 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8683 does not have a "location" either in memory or in a register. These
8684 things can arise in GNU C when a constant is passed as an actual parameter
8685 to an inlined function. They can also arise in C++ where declared
8686 constants do not necessarily get memory "homes". */
8689 add_const_value_attribute (die, rtl)
8693 switch (GET_CODE (rtl))
8696 /* Note that a CONST_INT rtx could represent either an integer
8697 or a floating-point constant. A CONST_INT is used whenever
8698 the constant will fit into a single word. In all such
8699 cases, the original mode of the constant value is wiped
8700 out, and the CONST_INT rtx is assigned VOIDmode. */
8702 HOST_WIDE_INT val = INTVAL (rtl);
8704 /* ??? We really should be using HOST_WIDE_INT throughout. */
8705 if (val < 0 && (long) val == val)
8706 add_AT_int (die, DW_AT_const_value, (long) val);
8707 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
8708 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8711 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8712 add_AT_long_long (die, DW_AT_const_value,
8713 val >> HOST_BITS_PER_LONG, val);
8722 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8723 floating-point constant. A CONST_DOUBLE is used whenever the
8724 constant requires more than one word in order to be adequately
8725 represented. We output CONST_DOUBLEs as blocks. */
8727 enum machine_mode mode = GET_MODE (rtl);
8729 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8731 unsigned length = GET_MODE_SIZE (mode) / 4;
8732 long *array = (long *) xmalloc (sizeof (long) * length);
8735 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8739 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8743 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8748 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8755 add_AT_float (die, DW_AT_const_value, length, array);
8759 /* ??? We really should be using HOST_WIDE_INT throughout. */
8760 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8763 add_AT_long_long (die, DW_AT_const_value,
8764 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8770 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8776 add_AT_addr (die, DW_AT_const_value, rtl);
8777 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
8781 /* In cases where an inlined instance of an inline function is passed
8782 the address of an `auto' variable (which is local to the caller) we
8783 can get a situation where the DECL_RTL of the artificial local
8784 variable (for the inlining) which acts as a stand-in for the
8785 corresponding formal parameter (of the inline function) will look
8786 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8787 exactly a compile-time constant expression, but it isn't the address
8788 of the (artificial) local variable either. Rather, it represents the
8789 *value* which the artificial local variable always has during its
8790 lifetime. We currently have no way to represent such quasi-constant
8791 values in Dwarf, so for now we just punt and generate nothing. */
8795 /* No other kinds of rtx should be possible here. */
8802 rtl_for_decl_location (decl)
8807 /* Here we have to decide where we are going to say the parameter "lives"
8808 (as far as the debugger is concerned). We only have a couple of
8809 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8811 DECL_RTL normally indicates where the parameter lives during most of the
8812 activation of the function. If optimization is enabled however, this
8813 could be either NULL or else a pseudo-reg. Both of those cases indicate
8814 that the parameter doesn't really live anywhere (as far as the code
8815 generation parts of GCC are concerned) during most of the function's
8816 activation. That will happen (for example) if the parameter is never
8817 referenced within the function.
8819 We could just generate a location descriptor here for all non-NULL
8820 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8821 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8822 where DECL_RTL is NULL or is a pseudo-reg.
8824 Note however that we can only get away with using DECL_INCOMING_RTL as
8825 a backup substitute for DECL_RTL in certain limited cases. In cases
8826 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8827 we can be sure that the parameter was passed using the same type as it is
8828 declared to have within the function, and that its DECL_INCOMING_RTL
8829 points us to a place where a value of that type is passed.
8831 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8832 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8833 because in these cases DECL_INCOMING_RTL points us to a value of some
8834 type which is *different* from the type of the parameter itself. Thus,
8835 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8836 such cases, the debugger would end up (for example) trying to fetch a
8837 `float' from a place which actually contains the first part of a
8838 `double'. That would lead to really incorrect and confusing
8839 output at debug-time.
8841 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8842 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8843 are a couple of exceptions however. On little-endian machines we can
8844 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8845 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8846 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8847 when (on a little-endian machine) a non-prototyped function has a
8848 parameter declared to be of type `short' or `char'. In such cases,
8849 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8850 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8851 passed `int' value. If the debugger then uses that address to fetch
8852 a `short' or a `char' (on a little-endian machine) the result will be
8853 the correct data, so we allow for such exceptional cases below.
8855 Note that our goal here is to describe the place where the given formal
8856 parameter lives during most of the function's activation (i.e. between the
8857 end of the prologue and the start of the epilogue). We'll do that as best
8858 as we can. Note however that if the given formal parameter is modified
8859 sometime during the execution of the function, then a stack backtrace (at
8860 debug-time) will show the function as having been called with the *new*
8861 value rather than the value which was originally passed in. This happens
8862 rarely enough that it is not a major problem, but it *is* a problem, and
8865 A future version of dwarf2out.c may generate two additional attributes for
8866 any given DW_TAG_formal_parameter DIE which will describe the "passed
8867 type" and the "passed location" for the given formal parameter in addition
8868 to the attributes we now generate to indicate the "declared type" and the
8869 "active location" for each parameter. This additional set of attributes
8870 could be used by debuggers for stack backtraces. Separately, note that
8871 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8872 This happens (for example) for inlined-instances of inline function formal
8873 parameters which are never referenced. This really shouldn't be
8874 happening. All PARM_DECL nodes should get valid non-NULL
8875 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8876 values for inlined instances of inline function parameters, so when we see
8877 such cases, we are just out-of-luck for the time being (until integrate.c
8880 /* Use DECL_RTL as the "location" unless we find something better. */
8881 rtl = DECL_RTL_IF_SET (decl);
8883 /* When generating abstract instances, ignore everything except
8884 constants and symbols living in memory. */
8885 if (! reload_completed)
8888 && (CONSTANT_P (rtl)
8889 || (GET_CODE (rtl) == MEM
8890 && CONSTANT_P (XEXP (rtl, 0)))))
8892 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8893 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
8899 else if (TREE_CODE (decl) == PARM_DECL)
8901 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8903 tree declared_type = type_main_variant (TREE_TYPE (decl));
8904 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8906 /* This decl represents a formal parameter which was optimized out.
8907 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8908 all cases where (rtl == NULL_RTX) just below. */
8909 if (declared_type == passed_type)
8910 rtl = DECL_INCOMING_RTL (decl);
8911 else if (! BYTES_BIG_ENDIAN
8912 && TREE_CODE (declared_type) == INTEGER_TYPE
8913 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8914 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8915 rtl = DECL_INCOMING_RTL (decl);
8918 /* If the parm was passed in registers, but lives on the stack, then
8919 make a big endian correction if the mode of the type of the
8920 parameter is not the same as the mode of the rtl. */
8921 /* ??? This is the same series of checks that are made in dbxout.c before
8922 we reach the big endian correction code there. It isn't clear if all
8923 of these checks are necessary here, but keeping them all is the safe
8925 else if (GET_CODE (rtl) == MEM
8926 && XEXP (rtl, 0) != const0_rtx
8927 && ! CONSTANT_P (XEXP (rtl, 0))
8928 /* Not passed in memory. */
8929 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8930 /* Not passed by invisible reference. */
8931 && (GET_CODE (XEXP (rtl, 0)) != REG
8932 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8933 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8934 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8935 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8938 /* Big endian correction check. */
8940 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8941 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8944 int offset = (UNITS_PER_WORD
8945 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8947 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8948 plus_constant (XEXP (rtl, 0), offset));
8952 if (rtl != NULL_RTX)
8954 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8955 #ifdef LEAF_REG_REMAP
8956 if (current_function_uses_only_leaf_regs)
8957 leaf_renumber_regs_insn (rtl);
8961 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8962 and will have been substituted directly into all expressions that use it.
8963 C does not have such a concept, but C++ and other languages do. */
8964 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
8966 /* If a variable is initialized with a string constant without embedded
8967 zeros, build CONST_STRING. */
8968 if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8969 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
8971 tree arrtype = TREE_TYPE (decl);
8972 tree enttype = TREE_TYPE (arrtype);
8973 tree domain = TYPE_DOMAIN (arrtype);
8974 tree init = DECL_INITIAL (decl);
8975 enum machine_mode mode = TYPE_MODE (enttype);
8977 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
8979 && integer_zerop (TYPE_MIN_VALUE (domain))
8980 && compare_tree_int (TYPE_MAX_VALUE (domain),
8981 TREE_STRING_LENGTH (init) - 1) == 0
8982 && ((size_t) TREE_STRING_LENGTH (init)
8983 == strlen (TREE_STRING_POINTER (init)) + 1))
8984 rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init));
8986 /* If the initializer is something that we know will expand into an
8987 immediate RTL constant, expand it now. Expanding anything else
8988 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
8989 else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST
8990 || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST)
8992 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
8993 EXPAND_INITIALIZER);
8994 /* If expand_expr returns a MEM, it wasn't immediate. */
8995 if (rtl && GET_CODE (rtl) == MEM)
9000 #ifdef ASM_SIMPLIFY_DWARF_ADDR
9002 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
9005 /* If we don't look past the constant pool, we risk emitting a
9006 reference to a constant pool entry that isn't referenced from
9007 code, and thus is not emitted. */
9009 rtl = avoid_constant_pool_reference (rtl);
9014 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
9015 data attribute for a variable or a parameter. We generate the
9016 DW_AT_const_value attribute only in those cases where the given variable
9017 or parameter does not have a true "location" either in memory or in a
9018 register. This can happen (for example) when a constant is passed as an
9019 actual argument in a call to an inline function. (It's possible that
9020 these things can crop up in other ways also.) Note that one type of
9021 constant value which can be passed into an inlined function is a constant
9022 pointer. This can happen for example if an actual argument in an inlined
9023 function call evaluates to a compile-time constant address. */
9026 add_location_or_const_value_attribute (die, decl)
9031 dw_loc_descr_ref descr;
9033 if (TREE_CODE (decl) == ERROR_MARK)
9035 else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
9038 rtl = rtl_for_decl_location (decl);
9039 if (rtl == NULL_RTX)
9042 switch (GET_CODE (rtl))
9045 /* The address of a variable that was optimized away;
9046 don't emit anything. */
9056 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9057 add_const_value_attribute (die, rtl);
9061 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
9063 /* Need loc_descriptor_from_tree since that's where we know
9064 how to handle TLS variables. Want the object's address
9065 since the top-level DW_AT_location assumes such. See
9066 the confusion in loc_descriptor for reference. */
9067 descr = loc_descriptor_from_tree (decl, 1);
9074 descr = loc_descriptor (rtl);
9076 add_AT_location_description (die, DW_AT_location, descr);
9084 /* If we don't have a copy of this variable in memory for some reason (such
9085 as a C++ member constant that doesn't have an out-of-line definition),
9086 we should tell the debugger about the constant value. */
9089 tree_add_const_value_attribute (var_die, decl)
9093 tree init = DECL_INITIAL (decl);
9094 tree type = TREE_TYPE (decl);
9096 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
9097 && initializer_constant_valid_p (init, type) == null_pointer_node)
9102 switch (TREE_CODE (type))
9105 if (host_integerp (init, 0))
9106 add_AT_unsigned (var_die, DW_AT_const_value,
9107 tree_low_cst (init, 0));
9109 add_AT_long_long (var_die, DW_AT_const_value,
9110 TREE_INT_CST_HIGH (init),
9111 TREE_INT_CST_LOW (init));
9118 /* Generate an DW_AT_name attribute given some string value to be included as
9119 the value of the attribute. */
9122 add_name_attribute (die, name_string)
9124 const char *name_string;
9126 if (name_string != NULL && *name_string != 0)
9128 if (demangle_name_func)
9129 name_string = (*demangle_name_func) (name_string);
9131 add_AT_string (die, DW_AT_name, name_string);
9135 /* Given a tree node describing an array bound (either lower or upper) output
9136 a representation for that bound. */
9139 add_bound_info (subrange_die, bound_attr, bound)
9140 dw_die_ref subrange_die;
9141 enum dwarf_attribute bound_attr;
9144 switch (TREE_CODE (bound))
9149 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9151 if (! host_integerp (bound, 0)
9152 || (bound_attr == DW_AT_lower_bound
9153 && (((is_c_family () || is_java ()) && integer_zerop (bound))
9154 || (is_fortran () && integer_onep (bound)))))
9155 /* use the default */
9158 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
9163 case NON_LVALUE_EXPR:
9164 case VIEW_CONVERT_EXPR:
9165 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
9169 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9170 access the upper bound values may be bogus. If they refer to a
9171 register, they may only describe how to get at these values at the
9172 points in the generated code right after they have just been
9173 computed. Worse yet, in the typical case, the upper bound values
9174 will not even *be* computed in the optimized code (though the
9175 number of elements will), so these SAVE_EXPRs are entirely
9176 bogus. In order to compensate for this fact, we check here to see
9177 if optimization is enabled, and if so, we don't add an attribute
9178 for the (unknown and unknowable) upper bound. This should not
9179 cause too much trouble for existing (stupid?) debuggers because
9180 they have to deal with empty upper bounds location descriptions
9181 anyway in order to be able to deal with incomplete array types.
9182 Of course an intelligent debugger (GDB?) should be able to
9183 comprehend that a missing upper bound specification in an array
9184 type used for a storage class `auto' local array variable
9185 indicates that the upper bound is both unknown (at compile- time)
9186 and unknowable (at run-time) due to optimization.
9188 We assume that a MEM rtx is safe because gcc wouldn't put the
9189 value there unless it was going to be used repeatedly in the
9190 function, i.e. for cleanups. */
9191 if (SAVE_EXPR_RTL (bound)
9192 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9194 dw_die_ref ctx = lookup_decl_die (current_function_decl);
9195 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound);
9196 rtx loc = SAVE_EXPR_RTL (bound);
9198 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9199 it references an outer function's frame. */
9200 if (GET_CODE (loc) == MEM)
9202 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9204 if (XEXP (loc, 0) != new_addr)
9205 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9208 add_AT_flag (decl_die, DW_AT_artificial, 1);
9209 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9210 add_AT_location_description (decl_die, DW_AT_location,
9211 loc_descriptor (loc));
9212 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9215 /* Else leave out the attribute. */
9221 dw_die_ref decl_die = lookup_decl_die (bound);
9223 /* ??? Can this happen, or should the variable have been bound
9224 first? Probably it can, since I imagine that we try to create
9225 the types of parameters in the order in which they exist in
9226 the list, and won't have created a forward reference to a
9228 if (decl_die != NULL)
9229 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9235 /* Otherwise try to create a stack operation procedure to
9236 evaluate the value of the array bound. */
9238 dw_die_ref ctx, decl_die;
9239 dw_loc_descr_ref loc;
9241 loc = loc_descriptor_from_tree (bound, 0);
9245 if (current_function_decl == 0)
9246 ctx = comp_unit_die;
9248 ctx = lookup_decl_die (current_function_decl);
9250 /* If we weren't able to find a context, it's most likely the case
9251 that we are processing the return type of the function. So
9252 make a SAVE_EXPR to point to it and have the limbo DIE code
9253 find the proper die. The save_expr function doesn't always
9254 make a SAVE_EXPR, so do it ourselves. */
9256 bound = build (SAVE_EXPR, TREE_TYPE (bound), bound,
9257 current_function_decl, NULL_TREE);
9259 decl_die = new_die (DW_TAG_variable, ctx, bound);
9260 add_AT_flag (decl_die, DW_AT_artificial, 1);
9261 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9262 add_AT_loc (decl_die, DW_AT_location, loc);
9264 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9270 /* Note that the block of subscript information for an array type also
9271 includes information about the element type of type given array type. */
9274 add_subscript_info (type_die, type)
9275 dw_die_ref type_die;
9278 #ifndef MIPS_DEBUGGING_INFO
9279 unsigned dimension_number;
9282 dw_die_ref subrange_die;
9284 /* The GNU compilers represent multidimensional array types as sequences of
9285 one dimensional array types whose element types are themselves array
9286 types. Here we squish that down, so that each multidimensional array
9287 type gets only one array_type DIE in the Dwarf debugging info. The draft
9288 Dwarf specification say that we are allowed to do this kind of
9289 compression in C (because there is no difference between an array or
9290 arrays and a multidimensional array in C) but for other source languages
9291 (e.g. Ada) we probably shouldn't do this. */
9293 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9294 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9295 We work around this by disabling this feature. See also
9296 gen_array_type_die. */
9297 #ifndef MIPS_DEBUGGING_INFO
9298 for (dimension_number = 0;
9299 TREE_CODE (type) == ARRAY_TYPE;
9300 type = TREE_TYPE (type), dimension_number++)
9303 tree domain = TYPE_DOMAIN (type);
9305 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9306 and (in GNU C only) variable bounds. Handle all three forms
9308 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
9311 /* We have an array type with specified bounds. */
9312 lower = TYPE_MIN_VALUE (domain);
9313 upper = TYPE_MAX_VALUE (domain);
9315 /* define the index type. */
9316 if (TREE_TYPE (domain))
9318 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9319 TREE_TYPE field. We can't emit debug info for this
9320 because it is an unnamed integral type. */
9321 if (TREE_CODE (domain) == INTEGER_TYPE
9322 && TYPE_NAME (domain) == NULL_TREE
9323 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9324 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9327 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9331 /* ??? If upper is NULL, the array has unspecified length,
9332 but it does have a lower bound. This happens with Fortran
9334 Since the debugger is definitely going to need to know N
9335 to produce useful results, go ahead and output the lower
9336 bound solo, and hope the debugger can cope. */
9338 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9340 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9343 /* Otherwise we have an array type with an unspecified length. The
9344 DWARF-2 spec does not say how to handle this; let's just leave out the
9350 add_byte_size_attribute (die, tree_node)
9356 switch (TREE_CODE (tree_node))
9364 case QUAL_UNION_TYPE:
9365 size = int_size_in_bytes (tree_node);
9368 /* For a data member of a struct or union, the DW_AT_byte_size is
9369 generally given as the number of bytes normally allocated for an
9370 object of the *declared* type of the member itself. This is true
9371 even for bit-fields. */
9372 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9378 /* Note that `size' might be -1 when we get to this point. If it is, that
9379 indicates that the byte size of the entity in question is variable. We
9380 have no good way of expressing this fact in Dwarf at the present time,
9381 so just let the -1 pass on through. */
9382 add_AT_unsigned (die, DW_AT_byte_size, size);
9385 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9386 which specifies the distance in bits from the highest order bit of the
9387 "containing object" for the bit-field to the highest order bit of the
9390 For any given bit-field, the "containing object" is a hypothetical object
9391 (of some integral or enum type) within which the given bit-field lives. The
9392 type of this hypothetical "containing object" is always the same as the
9393 declared type of the individual bit-field itself. The determination of the
9394 exact location of the "containing object" for a bit-field is rather
9395 complicated. It's handled by the `field_byte_offset' function (above).
9397 Note that it is the size (in bytes) of the hypothetical "containing object"
9398 which will be given in the DW_AT_byte_size attribute for this bit-field.
9399 (See `byte_size_attribute' above). */
9402 add_bit_offset_attribute (die, decl)
9406 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9407 tree type = DECL_BIT_FIELD_TYPE (decl);
9408 HOST_WIDE_INT bitpos_int;
9409 HOST_WIDE_INT highest_order_object_bit_offset;
9410 HOST_WIDE_INT highest_order_field_bit_offset;
9411 HOST_WIDE_INT unsigned bit_offset;
9413 /* Must be a field and a bit field. */
9415 || TREE_CODE (decl) != FIELD_DECL)
9418 /* We can't yet handle bit-fields whose offsets are variable, so if we
9419 encounter such things, just return without generating any attribute
9420 whatsoever. Likewise for variable or too large size. */
9421 if (! host_integerp (bit_position (decl), 0)
9422 || ! host_integerp (DECL_SIZE (decl), 1))
9425 bitpos_int = int_bit_position (decl);
9427 /* Note that the bit offset is always the distance (in bits) from the
9428 highest-order bit of the "containing object" to the highest-order bit of
9429 the bit-field itself. Since the "high-order end" of any object or field
9430 is different on big-endian and little-endian machines, the computation
9431 below must take account of these differences. */
9432 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9433 highest_order_field_bit_offset = bitpos_int;
9435 if (! BYTES_BIG_ENDIAN)
9437 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9438 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9442 = (! BYTES_BIG_ENDIAN
9443 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9444 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9446 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9449 /* For a FIELD_DECL node which represents a bit field, output an attribute
9450 which specifies the length in bits of the given field. */
9453 add_bit_size_attribute (die, decl)
9457 /* Must be a field and a bit field. */
9458 if (TREE_CODE (decl) != FIELD_DECL
9459 || ! DECL_BIT_FIELD_TYPE (decl))
9462 if (host_integerp (DECL_SIZE (decl), 1))
9463 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9466 /* If the compiled language is ANSI C, then add a 'prototyped'
9467 attribute, if arg types are given for the parameters of a function. */
9470 add_prototyped_attribute (die, func_type)
9474 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9475 && TYPE_ARG_TYPES (func_type) != NULL)
9476 add_AT_flag (die, DW_AT_prototyped, 1);
9479 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9480 by looking in either the type declaration or object declaration
9484 add_abstract_origin_attribute (die, origin)
9488 dw_die_ref origin_die = NULL;
9490 if (TREE_CODE (origin) != FUNCTION_DECL)
9492 /* We may have gotten separated from the block for the inlined
9493 function, if we're in an exception handler or some such; make
9494 sure that the abstract function has been written out.
9496 Doing this for nested functions is wrong, however; functions are
9497 distinct units, and our context might not even be inline. */
9501 fn = TYPE_STUB_DECL (fn);
9503 fn = decl_function_context (fn);
9505 dwarf2out_abstract_function (fn);
9508 if (DECL_P (origin))
9509 origin_die = lookup_decl_die (origin);
9510 else if (TYPE_P (origin))
9511 origin_die = lookup_type_die (origin);
9513 if (origin_die == NULL)
9516 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9519 /* We do not currently support the pure_virtual attribute. */
9522 add_pure_or_virtual_attribute (die, func_decl)
9526 if (DECL_VINDEX (func_decl))
9528 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9530 if (host_integerp (DECL_VINDEX (func_decl), 0))
9531 add_AT_loc (die, DW_AT_vtable_elem_location,
9532 new_loc_descr (DW_OP_constu,
9533 tree_low_cst (DECL_VINDEX (func_decl), 0),
9536 /* GNU extension: Record what type this method came from originally. */
9537 if (debug_info_level > DINFO_LEVEL_TERSE)
9538 add_AT_die_ref (die, DW_AT_containing_type,
9539 lookup_type_die (DECL_CONTEXT (func_decl)));
9543 /* Add source coordinate attributes for the given decl. */
9546 add_src_coords_attributes (die, decl)
9550 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9552 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9553 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9556 /* Add an DW_AT_name attribute and source coordinate attribute for the
9557 given decl, but only if it actually has a name. */
9560 add_name_and_src_coords_attributes (die, decl)
9566 decl_name = DECL_NAME (decl);
9567 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9569 add_name_attribute (die, dwarf2_name (decl, 0));
9570 if (! DECL_ARTIFICIAL (decl))
9571 add_src_coords_attributes (die, decl);
9573 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9574 && TREE_PUBLIC (decl)
9575 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9576 && !DECL_ABSTRACT (decl))
9577 add_AT_string (die, DW_AT_MIPS_linkage_name,
9578 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9581 #ifdef VMS_DEBUGGING_INFO
9582 /* Get the function's name, as described by its RTL. This may be different
9583 from the DECL_NAME name used in the source file. */
9584 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
9586 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
9587 XEXP (DECL_RTL (decl), 0));
9588 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
9593 /* Push a new declaration scope. */
9596 push_decl_scope (scope)
9599 VARRAY_PUSH_TREE (decl_scope_table, scope);
9602 /* Pop a declaration scope. */
9607 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9610 VARRAY_POP (decl_scope_table);
9613 /* Return the DIE for the scope that immediately contains this type.
9614 Non-named types get global scope. Named types nested in other
9615 types get their containing scope if it's open, or global scope
9616 otherwise. All other types (i.e. function-local named types) get
9617 the current active scope. */
9620 scope_die_for (t, context_die)
9622 dw_die_ref context_die;
9624 dw_die_ref scope_die = NULL;
9625 tree containing_scope;
9628 /* Non-types always go in the current scope. */
9632 containing_scope = TYPE_CONTEXT (t);
9634 /* Ignore namespaces for the moment. */
9635 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9636 containing_scope = NULL_TREE;
9638 /* Ignore function type "scopes" from the C frontend. They mean that
9639 a tagged type is local to a parmlist of a function declarator, but
9640 that isn't useful to DWARF. */
9641 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9642 containing_scope = NULL_TREE;
9644 if (containing_scope == NULL_TREE)
9645 scope_die = comp_unit_die;
9646 else if (TYPE_P (containing_scope))
9648 /* For types, we can just look up the appropriate DIE. But
9649 first we check to see if we're in the middle of emitting it
9650 so we know where the new DIE should go. */
9651 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9652 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
9657 if (debug_info_level > DINFO_LEVEL_TERSE
9658 && !TREE_ASM_WRITTEN (containing_scope))
9661 /* If none of the current dies are suitable, we get file scope. */
9662 scope_die = comp_unit_die;
9665 scope_die = lookup_type_die (containing_scope);
9668 scope_die = context_die;
9673 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9676 local_scope_p (context_die)
9677 dw_die_ref context_die;
9679 for (; context_die; context_die = context_die->die_parent)
9680 if (context_die->die_tag == DW_TAG_inlined_subroutine
9681 || context_die->die_tag == DW_TAG_subprogram)
9687 /* Returns nonzero if CONTEXT_DIE is a class. */
9690 class_scope_p (context_die)
9691 dw_die_ref context_die;
9694 && (context_die->die_tag == DW_TAG_structure_type
9695 || context_die->die_tag == DW_TAG_union_type));
9698 /* Many forms of DIEs require a "type description" attribute. This
9699 routine locates the proper "type descriptor" die for the type given
9700 by 'type', and adds an DW_AT_type attribute below the given die. */
9703 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9704 dw_die_ref object_die;
9708 dw_die_ref context_die;
9710 enum tree_code code = TREE_CODE (type);
9711 dw_die_ref type_die = NULL;
9713 /* ??? If this type is an unnamed subrange type of an integral or
9714 floating-point type, use the inner type. This is because we have no
9715 support for unnamed types in base_type_die. This can happen if this is
9716 an Ada subrange type. Correct solution is emit a subrange type die. */
9717 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9718 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9719 type = TREE_TYPE (type), code = TREE_CODE (type);
9721 if (code == ERROR_MARK
9722 /* Handle a special case. For functions whose return type is void, we
9723 generate *no* type attribute. (Note that no object may have type
9724 `void', so this only applies to function return types). */
9725 || code == VOID_TYPE)
9728 type_die = modified_type_die (type,
9729 decl_const || TYPE_READONLY (type),
9730 decl_volatile || TYPE_VOLATILE (type),
9733 if (type_die != NULL)
9734 add_AT_die_ref (object_die, DW_AT_type, type_die);
9737 /* Given a tree pointer to a struct, class, union, or enum type node, return
9738 a pointer to the (string) tag name for the given type, or zero if the type
9739 was declared without a tag. */
9745 const char *name = 0;
9747 if (TYPE_NAME (type) != 0)
9751 /* Find the IDENTIFIER_NODE for the type name. */
9752 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9753 t = TYPE_NAME (type);
9755 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9756 a TYPE_DECL node, regardless of whether or not a `typedef' was
9758 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9759 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9760 t = DECL_NAME (TYPE_NAME (type));
9762 /* Now get the name as a string, or invent one. */
9764 name = IDENTIFIER_POINTER (t);
9767 return (name == 0 || *name == '\0') ? 0 : name;
9770 /* Return the type associated with a data member, make a special check
9771 for bit field types. */
9774 member_declared_type (member)
9777 return (DECL_BIT_FIELD_TYPE (member)
9778 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
9781 /* Get the decl's label, as described by its RTL. This may be different
9782 from the DECL_NAME name used in the source file. */
9786 decl_start_label (decl)
9792 x = DECL_RTL (decl);
9793 if (GET_CODE (x) != MEM)
9797 if (GET_CODE (x) != SYMBOL_REF)
9800 fnname = XSTR (x, 0);
9805 /* These routines generate the internal representation of the DIE's for
9806 the compilation unit. Debugging information is collected by walking
9807 the declaration trees passed in from dwarf2out_decl(). */
9810 gen_array_type_die (type, context_die)
9812 dw_die_ref context_die;
9814 dw_die_ref scope_die = scope_die_for (type, context_die);
9815 dw_die_ref array_die;
9818 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9819 the inner array type comes before the outer array type. Thus we must
9820 call gen_type_die before we call new_die. See below also. */
9821 #ifdef MIPS_DEBUGGING_INFO
9822 gen_type_die (TREE_TYPE (type), context_die);
9825 array_die = new_die (DW_TAG_array_type, scope_die, type);
9826 add_name_attribute (array_die, type_tag (type));
9827 equate_type_number_to_die (type, array_die);
9829 if (TREE_CODE (type) == VECTOR_TYPE)
9831 /* The frontend feeds us a representation for the vector as a struct
9832 containing an array. Pull out the array type. */
9833 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
9834 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
9838 /* We default the array ordering. SDB will probably do
9839 the right things even if DW_AT_ordering is not present. It's not even
9840 an issue until we start to get into multidimensional arrays anyway. If
9841 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9842 then we'll have to put the DW_AT_ordering attribute back in. (But if
9843 and when we find out that we need to put these in, we will only do so
9844 for multidimensional arrays. */
9845 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9848 #ifdef MIPS_DEBUGGING_INFO
9849 /* The SGI compilers handle arrays of unknown bound by setting
9850 AT_declaration and not emitting any subrange DIEs. */
9851 if (! TYPE_DOMAIN (type))
9852 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9855 add_subscript_info (array_die, type);
9857 /* Add representation of the type of the elements of this array type. */
9858 element_type = TREE_TYPE (type);
9860 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9861 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9862 We work around this by disabling this feature. See also
9863 add_subscript_info. */
9864 #ifndef MIPS_DEBUGGING_INFO
9865 while (TREE_CODE (element_type) == ARRAY_TYPE)
9866 element_type = TREE_TYPE (element_type);
9868 gen_type_die (element_type, context_die);
9871 add_type_attribute (array_die, element_type, 0, 0, context_die);
9875 gen_set_type_die (type, context_die)
9877 dw_die_ref context_die;
9880 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
9882 equate_type_number_to_die (type, type_die);
9883 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9888 gen_entry_point_die (decl, context_die)
9890 dw_die_ref context_die;
9892 tree origin = decl_ultimate_origin (decl);
9893 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
9896 add_abstract_origin_attribute (decl_die, origin);
9899 add_name_and_src_coords_attributes (decl_die, decl);
9900 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9904 if (DECL_ABSTRACT (decl))
9905 equate_decl_number_to_die (decl, decl_die);
9907 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9911 /* Walk through the list of incomplete types again, trying once more to
9912 emit full debugging info for them. */
9915 retry_incomplete_types ()
9919 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
9920 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
9923 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9926 gen_inlined_enumeration_type_die (type, context_die)
9928 dw_die_ref context_die;
9930 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
9932 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9933 be incomplete and such types are not marked. */
9934 add_abstract_origin_attribute (type_die, type);
9937 /* Generate a DIE to represent an inlined instance of a structure type. */
9940 gen_inlined_structure_type_die (type, context_die)
9942 dw_die_ref context_die;
9944 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
9946 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9947 be incomplete and such types are not marked. */
9948 add_abstract_origin_attribute (type_die, type);
9951 /* Generate a DIE to represent an inlined instance of a union type. */
9954 gen_inlined_union_type_die (type, context_die)
9956 dw_die_ref context_die;
9958 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
9960 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9961 be incomplete and such types are not marked. */
9962 add_abstract_origin_attribute (type_die, type);
9965 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9966 include all of the information about the enumeration values also. Each
9967 enumerated type name/value is listed as a child of the enumerated type
9971 gen_enumeration_type_die (type, context_die)
9973 dw_die_ref context_die;
9975 dw_die_ref type_die = lookup_type_die (type);
9977 if (type_die == NULL)
9979 type_die = new_die (DW_TAG_enumeration_type,
9980 scope_die_for (type, context_die), type);
9981 equate_type_number_to_die (type, type_die);
9982 add_name_attribute (type_die, type_tag (type));
9984 else if (! TYPE_SIZE (type))
9987 remove_AT (type_die, DW_AT_declaration);
9989 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9990 given enum type is incomplete, do not generate the DW_AT_byte_size
9991 attribute or the DW_AT_element_list attribute. */
9992 if (TYPE_SIZE (type))
9996 TREE_ASM_WRITTEN (type) = 1;
9997 add_byte_size_attribute (type_die, type);
9998 if (TYPE_STUB_DECL (type) != NULL_TREE)
9999 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10001 /* If the first reference to this type was as the return type of an
10002 inline function, then it may not have a parent. Fix this now. */
10003 if (type_die->die_parent == NULL)
10004 add_child_die (scope_die_for (type, context_die), type_die);
10006 for (link = TYPE_FIELDS (type);
10007 link != NULL; link = TREE_CHAIN (link))
10009 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
10011 add_name_attribute (enum_die,
10012 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
10014 if (host_integerp (TREE_VALUE (link), 0))
10016 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
10017 add_AT_int (enum_die, DW_AT_const_value,
10018 tree_low_cst (TREE_VALUE (link), 0));
10020 add_AT_unsigned (enum_die, DW_AT_const_value,
10021 tree_low_cst (TREE_VALUE (link), 0));
10026 add_AT_flag (type_die, DW_AT_declaration, 1);
10029 /* Generate a DIE to represent either a real live formal parameter decl or to
10030 represent just the type of some formal parameter position in some function
10033 Note that this routine is a bit unusual because its argument may be a
10034 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
10035 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
10036 node. If it's the former then this function is being called to output a
10037 DIE to represent a formal parameter object (or some inlining thereof). If
10038 it's the latter, then this function is only being called to output a
10039 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
10040 argument type of some subprogram type. */
10043 gen_formal_parameter_die (node, context_die)
10045 dw_die_ref context_die;
10047 dw_die_ref parm_die
10048 = new_die (DW_TAG_formal_parameter, context_die, node);
10051 switch (TREE_CODE_CLASS (TREE_CODE (node)))
10054 origin = decl_ultimate_origin (node);
10055 if (origin != NULL)
10056 add_abstract_origin_attribute (parm_die, origin);
10059 add_name_and_src_coords_attributes (parm_die, node);
10060 add_type_attribute (parm_die, TREE_TYPE (node),
10061 TREE_READONLY (node),
10062 TREE_THIS_VOLATILE (node),
10064 if (DECL_ARTIFICIAL (node))
10065 add_AT_flag (parm_die, DW_AT_artificial, 1);
10068 equate_decl_number_to_die (node, parm_die);
10069 if (! DECL_ABSTRACT (node))
10070 add_location_or_const_value_attribute (parm_die, node);
10075 /* We were called with some kind of a ..._TYPE node. */
10076 add_type_attribute (parm_die, node, 0, 0, context_die);
10086 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10087 at the end of an (ANSI prototyped) formal parameters list. */
10090 gen_unspecified_parameters_die (decl_or_type, context_die)
10092 dw_die_ref context_die;
10094 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
10097 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10098 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10099 parameters as specified in some function type specification (except for
10100 those which appear as part of a function *definition*). */
10103 gen_formal_types_die (function_or_method_type, context_die)
10104 tree function_or_method_type;
10105 dw_die_ref context_die;
10108 tree formal_type = NULL;
10109 tree first_parm_type;
10112 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
10114 arg = DECL_ARGUMENTS (function_or_method_type);
10115 function_or_method_type = TREE_TYPE (function_or_method_type);
10120 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
10122 /* Make our first pass over the list of formal parameter types and output a
10123 DW_TAG_formal_parameter DIE for each one. */
10124 for (link = first_parm_type; link; )
10126 dw_die_ref parm_die;
10128 formal_type = TREE_VALUE (link);
10129 if (formal_type == void_type_node)
10132 /* Output a (nameless) DIE to represent the formal parameter itself. */
10133 parm_die = gen_formal_parameter_die (formal_type, context_die);
10134 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
10135 && link == first_parm_type)
10136 || (arg && DECL_ARTIFICIAL (arg)))
10137 add_AT_flag (parm_die, DW_AT_artificial, 1);
10139 link = TREE_CHAIN (link);
10141 arg = TREE_CHAIN (arg);
10144 /* If this function type has an ellipsis, add a
10145 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10146 if (formal_type != void_type_node)
10147 gen_unspecified_parameters_die (function_or_method_type, context_die);
10149 /* Make our second (and final) pass over the list of formal parameter types
10150 and output DIEs to represent those types (as necessary). */
10151 for (link = TYPE_ARG_TYPES (function_or_method_type);
10152 link && TREE_VALUE (link);
10153 link = TREE_CHAIN (link))
10154 gen_type_die (TREE_VALUE (link), context_die);
10157 /* We want to generate the DIE for TYPE so that we can generate the
10158 die for MEMBER, which has been defined; we will need to refer back
10159 to the member declaration nested within TYPE. If we're trying to
10160 generate minimal debug info for TYPE, processing TYPE won't do the
10161 trick; we need to attach the member declaration by hand. */
10164 gen_type_die_for_member (type, member, context_die)
10166 dw_die_ref context_die;
10168 gen_type_die (type, context_die);
10170 /* If we're trying to avoid duplicate debug info, we may not have
10171 emitted the member decl for this function. Emit it now. */
10172 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10173 && ! lookup_decl_die (member))
10175 if (decl_ultimate_origin (member))
10178 push_decl_scope (type);
10179 if (TREE_CODE (member) == FUNCTION_DECL)
10180 gen_subprogram_die (member, lookup_type_die (type));
10182 gen_variable_die (member, lookup_type_die (type));
10188 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10189 may later generate inlined and/or out-of-line instances of. */
10192 dwarf2out_abstract_function (decl)
10195 dw_die_ref old_die;
10198 int was_abstract = DECL_ABSTRACT (decl);
10200 /* Make sure we have the actual abstract inline, not a clone. */
10201 decl = DECL_ORIGIN (decl);
10203 old_die = lookup_decl_die (decl);
10204 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10205 /* We've already generated the abstract instance. */
10208 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10209 we don't get confused by DECL_ABSTRACT. */
10210 if (debug_info_level > DINFO_LEVEL_TERSE)
10212 context = decl_class_context (decl);
10214 gen_type_die_for_member
10215 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
10218 /* Pretend we've just finished compiling this function. */
10219 save_fn = current_function_decl;
10220 current_function_decl = decl;
10222 set_decl_abstract_flags (decl, 1);
10223 dwarf2out_decl (decl);
10224 if (! was_abstract)
10225 set_decl_abstract_flags (decl, 0);
10227 current_function_decl = save_fn;
10230 /* Generate a DIE to represent a declared function (either file-scope or
10234 gen_subprogram_die (decl, context_die)
10236 dw_die_ref context_die;
10238 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10239 tree origin = decl_ultimate_origin (decl);
10240 dw_die_ref subr_die;
10244 dw_die_ref old_die = lookup_decl_die (decl);
10245 int declaration = (current_function_decl != decl
10246 || class_scope_p (context_die));
10248 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10249 started to generate the abstract instance of an inline, decided to output
10250 its containing class, and proceeded to emit the declaration of the inline
10251 from the member list for the class. If so, DECLARATION takes priority;
10252 we'll get back to the abstract instance when done with the class. */
10254 /* The class-scope declaration DIE must be the primary DIE. */
10255 if (origin && declaration && class_scope_p (context_die))
10262 if (origin != NULL)
10264 if (declaration && ! local_scope_p (context_die))
10267 /* Fixup die_parent for the abstract instance of a nested
10268 inline function. */
10269 if (old_die && old_die->die_parent == NULL)
10270 add_child_die (context_die, old_die);
10272 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10273 add_abstract_origin_attribute (subr_die, origin);
10277 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10279 if (!get_AT_flag (old_die, DW_AT_declaration)
10280 /* We can have a normal definition following an inline one in the
10281 case of redefinition of GNU C extern inlines.
10282 It seems reasonable to use AT_specification in this case. */
10283 && !get_AT_unsigned (old_die, DW_AT_inline))
10285 /* ??? This can happen if there is a bug in the program, for
10286 instance, if it has duplicate function definitions. Ideally,
10287 we should detect this case and ignore it. For now, if we have
10288 already reported an error, any error at all, then assume that
10289 we got here because of an input error, not a dwarf2 bug. */
10295 /* If the definition comes from the same place as the declaration,
10296 maybe use the old DIE. We always want the DIE for this function
10297 that has the *_pc attributes to be under comp_unit_die so the
10298 debugger can find it. We also need to do this for abstract
10299 instances of inlines, since the spec requires the out-of-line copy
10300 to have the same parent. For local class methods, this doesn't
10301 apply; we just use the old DIE. */
10302 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10303 && (DECL_ARTIFICIAL (decl)
10304 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10305 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10306 == (unsigned) DECL_SOURCE_LINE (decl)))))
10308 subr_die = old_die;
10310 /* Clear out the declaration attribute and the parm types. */
10311 remove_AT (subr_die, DW_AT_declaration);
10312 remove_children (subr_die);
10316 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10317 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10318 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10319 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10320 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10321 != (unsigned) DECL_SOURCE_LINE (decl))
10323 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10328 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10330 if (TREE_PUBLIC (decl))
10331 add_AT_flag (subr_die, DW_AT_external, 1);
10333 add_name_and_src_coords_attributes (subr_die, decl);
10334 if (debug_info_level > DINFO_LEVEL_TERSE)
10336 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
10337 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
10338 0, 0, context_die);
10341 add_pure_or_virtual_attribute (subr_die, decl);
10342 if (DECL_ARTIFICIAL (decl))
10343 add_AT_flag (subr_die, DW_AT_artificial, 1);
10345 if (TREE_PROTECTED (decl))
10346 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10347 else if (TREE_PRIVATE (decl))
10348 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10353 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10355 add_AT_flag (subr_die, DW_AT_declaration, 1);
10357 /* The first time we see a member function, it is in the context of
10358 the class to which it belongs. We make sure of this by emitting
10359 the class first. The next time is the definition, which is
10360 handled above. The two may come from the same source text. */
10361 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10362 equate_decl_number_to_die (decl, subr_die);
10365 else if (DECL_ABSTRACT (decl))
10367 if (DECL_INLINE (decl) && !flag_no_inline)
10369 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10370 inline functions, but not for extern inline functions.
10371 We can't get this completely correct because information
10372 about whether the function was declared inline is not
10374 if (DECL_DEFER_OUTPUT (decl))
10375 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10377 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10380 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10382 equate_decl_number_to_die (decl, subr_die);
10384 else if (!DECL_EXTERNAL (decl))
10386 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10387 equate_decl_number_to_die (decl, subr_die);
10389 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10390 current_function_funcdef_no);
10391 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10392 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10393 current_function_funcdef_no);
10394 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10396 add_pubname (decl, subr_die);
10397 add_arange (decl, subr_die);
10399 #ifdef MIPS_DEBUGGING_INFO
10400 /* Add a reference to the FDE for this routine. */
10401 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10404 /* Define the "frame base" location for this routine. We use the
10405 frame pointer or stack pointer registers, since the RTL for local
10406 variables is relative to one of them. */
10408 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10409 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10412 /* ??? This fails for nested inline functions, because context_display
10413 is not part of the state saved/restored for inline functions. */
10414 if (current_function_needs_context)
10415 add_AT_location_description (subr_die, DW_AT_static_link,
10416 loc_descriptor (lookup_static_chain (decl)));
10420 /* Now output descriptions of the arguments for this function. This gets
10421 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10422 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10423 `...' at the end of the formal parameter list. In order to find out if
10424 there was a trailing ellipsis or not, we must instead look at the type
10425 associated with the FUNCTION_DECL. This will be a node of type
10426 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10427 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10428 an ellipsis at the end. */
10430 /* In the case where we are describing a mere function declaration, all we
10431 need to do here (and all we *can* do here) is to describe the *types* of
10432 its formal parameters. */
10433 if (debug_info_level <= DINFO_LEVEL_TERSE)
10435 else if (declaration)
10436 gen_formal_types_die (decl, subr_die);
10439 /* Generate DIEs to represent all known formal parameters */
10440 tree arg_decls = DECL_ARGUMENTS (decl);
10443 /* When generating DIEs, generate the unspecified_parameters DIE
10444 instead if we come across the arg "__builtin_va_alist" */
10445 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10446 if (TREE_CODE (parm) == PARM_DECL)
10448 if (DECL_NAME (parm)
10449 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10450 "__builtin_va_alist"))
10451 gen_unspecified_parameters_die (parm, subr_die);
10453 gen_decl_die (parm, subr_die);
10456 /* Decide whether we need an unspecified_parameters DIE at the end.
10457 There are 2 more cases to do this for: 1) the ansi ... declaration -
10458 this is detectable when the end of the arg list is not a
10459 void_type_node 2) an unprototyped function declaration (not a
10460 definition). This just means that we have no info about the
10461 parameters at all. */
10462 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10463 if (fn_arg_types != NULL)
10465 /* this is the prototyped case, check for ... */
10466 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10467 gen_unspecified_parameters_die (decl, subr_die);
10469 else if (DECL_INITIAL (decl) == NULL_TREE)
10470 gen_unspecified_parameters_die (decl, subr_die);
10473 /* Output Dwarf info for all of the stuff within the body of the function
10474 (if it has one - it may be just a declaration). */
10475 outer_scope = DECL_INITIAL (decl);
10477 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10478 a function. This BLOCK actually represents the outermost binding contour
10479 for the function, i.e. the contour in which the function's formal
10480 parameters and labels get declared. Curiously, it appears that the front
10481 end doesn't actually put the PARM_DECL nodes for the current function onto
10482 the BLOCK_VARS list for this outer scope, but are strung off of the
10483 DECL_ARGUMENTS list for the function instead.
10485 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10486 the LABEL_DECL nodes for the function however, and we output DWARF info
10487 for those in decls_for_scope. Just within the `outer_scope' there will be
10488 a BLOCK node representing the function's outermost pair of curly braces,
10489 and any blocks used for the base and member initializers of a C++
10490 constructor function. */
10491 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10493 current_function_has_inlines = 0;
10494 decls_for_scope (outer_scope, subr_die, 0);
10496 #if 0 && defined (MIPS_DEBUGGING_INFO)
10497 if (current_function_has_inlines)
10499 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10500 if (! comp_unit_has_inlines)
10502 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10503 comp_unit_has_inlines = 1;
10510 /* Generate a DIE to represent a declared data object. */
10513 gen_variable_die (decl, context_die)
10515 dw_die_ref context_die;
10517 tree origin = decl_ultimate_origin (decl);
10518 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
10520 dw_die_ref old_die = lookup_decl_die (decl);
10521 int declaration = (DECL_EXTERNAL (decl)
10522 || class_scope_p (context_die));
10524 if (origin != NULL)
10525 add_abstract_origin_attribute (var_die, origin);
10527 /* Loop unrolling can create multiple blocks that refer to the same
10528 static variable, so we must test for the DW_AT_declaration flag.
10530 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10531 copy decls and set the DECL_ABSTRACT flag on them instead of
10534 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10535 else if (old_die && TREE_STATIC (decl)
10536 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10538 /* This is a definition of a C++ class level static. */
10539 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10540 if (DECL_NAME (decl))
10542 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10544 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10545 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10547 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10548 != (unsigned) DECL_SOURCE_LINE (decl))
10550 add_AT_unsigned (var_die, DW_AT_decl_line,
10551 DECL_SOURCE_LINE (decl));
10556 add_name_and_src_coords_attributes (var_die, decl);
10557 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
10558 TREE_THIS_VOLATILE (decl), context_die);
10560 if (TREE_PUBLIC (decl))
10561 add_AT_flag (var_die, DW_AT_external, 1);
10563 if (DECL_ARTIFICIAL (decl))
10564 add_AT_flag (var_die, DW_AT_artificial, 1);
10566 if (TREE_PROTECTED (decl))
10567 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10568 else if (TREE_PRIVATE (decl))
10569 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10573 add_AT_flag (var_die, DW_AT_declaration, 1);
10575 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10576 equate_decl_number_to_die (decl, var_die);
10578 if (! declaration && ! DECL_ABSTRACT (decl))
10580 add_location_or_const_value_attribute (var_die, decl);
10581 add_pubname (decl, var_die);
10584 tree_add_const_value_attribute (var_die, decl);
10587 /* Generate a DIE to represent a label identifier. */
10590 gen_label_die (decl, context_die)
10592 dw_die_ref context_die;
10594 tree origin = decl_ultimate_origin (decl);
10595 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
10597 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10599 if (origin != NULL)
10600 add_abstract_origin_attribute (lbl_die, origin);
10602 add_name_and_src_coords_attributes (lbl_die, decl);
10604 if (DECL_ABSTRACT (decl))
10605 equate_decl_number_to_die (decl, lbl_die);
10608 insn = DECL_RTL (decl);
10610 /* Deleted labels are programmer specified labels which have been
10611 eliminated because of various optimisations. We still emit them
10612 here so that it is possible to put breakpoints on them. */
10613 if (GET_CODE (insn) == CODE_LABEL
10614 || ((GET_CODE (insn) == NOTE
10615 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10617 /* When optimization is enabled (via -O) some parts of the compiler
10618 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10619 represent source-level labels which were explicitly declared by
10620 the user. This really shouldn't be happening though, so catch
10621 it if it ever does happen. */
10622 if (INSN_DELETED_P (insn))
10625 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10626 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10631 /* Generate a DIE for a lexical block. */
10634 gen_lexical_block_die (stmt, context_die, depth)
10636 dw_die_ref context_die;
10639 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
10640 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10642 if (! BLOCK_ABSTRACT (stmt))
10644 if (BLOCK_FRAGMENT_CHAIN (stmt))
10648 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
10650 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10653 add_ranges (chain);
10654 chain = BLOCK_FRAGMENT_CHAIN (chain);
10661 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10662 BLOCK_NUMBER (stmt));
10663 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10664 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10665 BLOCK_NUMBER (stmt));
10666 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10670 decls_for_scope (stmt, stmt_die, depth);
10673 /* Generate a DIE for an inlined subprogram. */
10676 gen_inlined_subroutine_die (stmt, context_die, depth)
10678 dw_die_ref context_die;
10681 if (! BLOCK_ABSTRACT (stmt))
10683 dw_die_ref subr_die
10684 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
10685 tree decl = block_ultimate_origin (stmt);
10686 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10688 /* Emit info for the abstract instance first, if we haven't yet. */
10689 dwarf2out_abstract_function (decl);
10691 add_abstract_origin_attribute (subr_die, decl);
10692 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10693 BLOCK_NUMBER (stmt));
10694 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10695 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10696 BLOCK_NUMBER (stmt));
10697 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10698 decls_for_scope (stmt, subr_die, depth);
10699 current_function_has_inlines = 1;
10702 /* We may get here if we're the outer block of function A that was
10703 inlined into function B that was inlined into function C. When
10704 generating debugging info for C, dwarf2out_abstract_function(B)
10705 would mark all inlined blocks as abstract, including this one.
10706 So, we wouldn't (and shouldn't) expect labels to be generated
10707 for this one. Instead, just emit debugging info for
10708 declarations within the block. This is particularly important
10709 in the case of initializers of arguments passed from B to us:
10710 if they're statement expressions containing declarations, we
10711 wouldn't generate dies for their abstract variables, and then,
10712 when generating dies for the real variables, we'd die (pun
10714 gen_lexical_block_die (stmt, context_die, depth);
10717 /* Generate a DIE for a field in a record, or structure. */
10720 gen_field_die (decl, context_die)
10722 dw_die_ref context_die;
10724 dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl);
10726 add_name_and_src_coords_attributes (decl_die, decl);
10727 add_type_attribute (decl_die, member_declared_type (decl),
10728 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10731 if (DECL_BIT_FIELD_TYPE (decl))
10733 add_byte_size_attribute (decl_die, decl);
10734 add_bit_size_attribute (decl_die, decl);
10735 add_bit_offset_attribute (decl_die, decl);
10738 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10739 add_data_member_location_attribute (decl_die, decl);
10741 if (DECL_ARTIFICIAL (decl))
10742 add_AT_flag (decl_die, DW_AT_artificial, 1);
10744 if (TREE_PROTECTED (decl))
10745 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10746 else if (TREE_PRIVATE (decl))
10747 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10751 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10752 Use modified_type_die instead.
10753 We keep this code here just in case these types of DIEs may be needed to
10754 represent certain things in other languages (e.g. Pascal) someday. */
10757 gen_pointer_type_die (type, context_die)
10759 dw_die_ref context_die;
10762 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
10764 equate_type_number_to_die (type, ptr_die);
10765 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10766 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10769 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10770 Use modified_type_die instead.
10771 We keep this code here just in case these types of DIEs may be needed to
10772 represent certain things in other languages (e.g. Pascal) someday. */
10775 gen_reference_type_die (type, context_die)
10777 dw_die_ref context_die;
10780 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
10782 equate_type_number_to_die (type, ref_die);
10783 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10784 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10788 /* Generate a DIE for a pointer to a member type. */
10791 gen_ptr_to_mbr_type_die (type, context_die)
10793 dw_die_ref context_die;
10796 = new_die (DW_TAG_ptr_to_member_type,
10797 scope_die_for (type, context_die), type);
10799 equate_type_number_to_die (type, ptr_die);
10800 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10801 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10802 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10805 /* Generate the DIE for the compilation unit. */
10808 gen_compile_unit_die (filename)
10809 const char *filename;
10812 char producer[250];
10813 const char *wd = getpwd ();
10814 const char *language_string = lang_hooks.name;
10817 die = new_die (DW_TAG_compile_unit, NULL, NULL);
10818 add_name_attribute (die, filename);
10820 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10821 add_AT_string (die, DW_AT_comp_dir, wd);
10823 sprintf (producer, "%s %s", language_string, version_string);
10825 #ifdef MIPS_DEBUGGING_INFO
10826 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10827 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10828 not appear in the producer string, the debugger reaches the conclusion
10829 that the object file is stripped and has no debugging information.
10830 To get the MIPS/SGI debugger to believe that there is debugging
10831 information in the object file, we add a -g to the producer string. */
10832 if (debug_info_level > DINFO_LEVEL_TERSE)
10833 strcat (producer, " -g");
10836 add_AT_string (die, DW_AT_producer, producer);
10838 if (strcmp (language_string, "GNU C++") == 0)
10839 language = DW_LANG_C_plus_plus;
10840 else if (strcmp (language_string, "GNU Ada") == 0)
10841 language = DW_LANG_Ada83;
10842 else if (strcmp (language_string, "GNU F77") == 0)
10843 language = DW_LANG_Fortran77;
10844 else if (strcmp (language_string, "GNU Pascal") == 0)
10845 language = DW_LANG_Pascal83;
10846 else if (strcmp (language_string, "GNU Java") == 0)
10847 language = DW_LANG_Java;
10849 language = DW_LANG_C89;
10851 add_AT_unsigned (die, DW_AT_language, language);
10855 /* Generate a DIE for a string type. */
10858 gen_string_type_die (type, context_die)
10860 dw_die_ref context_die;
10862 dw_die_ref type_die
10863 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
10865 equate_type_number_to_die (type, type_die);
10867 /* ??? Fudge the string length attribute for now.
10868 TODO: add string length info. */
10870 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10871 bound_representation (upper_bound, 0, 'u');
10875 /* Generate the DIE for a base class. */
10878 gen_inheritance_die (binfo, context_die)
10880 dw_die_ref context_die;
10882 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
10884 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10885 add_data_member_location_attribute (die, binfo);
10887 if (TREE_VIA_VIRTUAL (binfo))
10888 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10890 if (TREE_VIA_PUBLIC (binfo))
10891 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10892 else if (TREE_VIA_PROTECTED (binfo))
10893 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10896 /* Generate a DIE for a class member. */
10899 gen_member_die (type, context_die)
10901 dw_die_ref context_die;
10906 /* If this is not an incomplete type, output descriptions of each of its
10907 members. Note that as we output the DIEs necessary to represent the
10908 members of this record or union type, we will also be trying to output
10909 DIEs to represent the *types* of those members. However the `type'
10910 function (above) will specifically avoid generating type DIEs for member
10911 types *within* the list of member DIEs for this (containing) type except
10912 for those types (of members) which are explicitly marked as also being
10913 members of this (containing) type themselves. The g++ front- end can
10914 force any given type to be treated as a member of some other (containing)
10915 type by setting the TYPE_CONTEXT of the given (member) type to point to
10916 the TREE node representing the appropriate (containing) type. */
10918 /* First output info about the base classes. */
10919 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10921 tree bases = TYPE_BINFO_BASETYPES (type);
10922 int n_bases = TREE_VEC_LENGTH (bases);
10925 for (i = 0; i < n_bases; i++)
10926 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10929 /* Now output info about the data members and type members. */
10930 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10932 /* If we thought we were generating minimal debug info for TYPE
10933 and then changed our minds, some of the member declarations
10934 may have already been defined. Don't define them again, but
10935 do put them in the right order. */
10937 child = lookup_decl_die (member);
10939 splice_child_die (context_die, child);
10941 gen_decl_die (member, context_die);
10944 /* Now output info about the function members (if any). */
10945 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10947 /* Don't include clones in the member list. */
10948 if (DECL_ABSTRACT_ORIGIN (member))
10951 child = lookup_decl_die (member);
10953 splice_child_die (context_die, child);
10955 gen_decl_die (member, context_die);
10959 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10960 is set, we pretend that the type was never defined, so we only get the
10961 member DIEs needed by later specification DIEs. */
10964 gen_struct_or_union_type_die (type, context_die)
10966 dw_die_ref context_die;
10968 dw_die_ref type_die = lookup_type_die (type);
10969 dw_die_ref scope_die = 0;
10971 int complete = (TYPE_SIZE (type)
10972 && (! TYPE_STUB_DECL (type)
10973 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10975 if (type_die && ! complete)
10978 if (TYPE_CONTEXT (type) != NULL_TREE
10979 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10982 scope_die = scope_die_for (type, context_die);
10984 if (! type_die || (nested && scope_die == comp_unit_die))
10985 /* First occurrence of type or toplevel definition of nested class. */
10987 dw_die_ref old_die = type_die;
10989 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10990 ? DW_TAG_structure_type : DW_TAG_union_type,
10992 equate_type_number_to_die (type, type_die);
10994 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10996 add_name_attribute (type_die, type_tag (type));
10999 remove_AT (type_die, DW_AT_declaration);
11001 /* If this type has been completed, then give it a byte_size attribute and
11002 then give a list of members. */
11005 /* Prevent infinite recursion in cases where the type of some member of
11006 this type is expressed in terms of this type itself. */
11007 TREE_ASM_WRITTEN (type) = 1;
11008 add_byte_size_attribute (type_die, type);
11009 if (TYPE_STUB_DECL (type) != NULL_TREE)
11010 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
11012 /* If the first reference to this type was as the return type of an
11013 inline function, then it may not have a parent. Fix this now. */
11014 if (type_die->die_parent == NULL)
11015 add_child_die (scope_die, type_die);
11017 push_decl_scope (type);
11018 gen_member_die (type, type_die);
11021 /* GNU extension: Record what type our vtable lives in. */
11022 if (TYPE_VFIELD (type))
11024 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
11026 gen_type_die (vtype, context_die);
11027 add_AT_die_ref (type_die, DW_AT_containing_type,
11028 lookup_type_die (vtype));
11033 add_AT_flag (type_die, DW_AT_declaration, 1);
11035 /* We don't need to do this for function-local types. */
11036 if (TYPE_STUB_DECL (type)
11037 && ! decl_function_context (TYPE_STUB_DECL (type)))
11038 VARRAY_PUSH_TREE (incomplete_types, type);
11042 /* Generate a DIE for a subroutine _type_. */
11045 gen_subroutine_type_die (type, context_die)
11047 dw_die_ref context_die;
11049 tree return_type = TREE_TYPE (type);
11050 dw_die_ref subr_die
11051 = new_die (DW_TAG_subroutine_type,
11052 scope_die_for (type, context_die), type);
11054 equate_type_number_to_die (type, subr_die);
11055 add_prototyped_attribute (subr_die, type);
11056 add_type_attribute (subr_die, return_type, 0, 0, context_die);
11057 gen_formal_types_die (type, subr_die);
11060 /* Generate a DIE for a type definition */
11063 gen_typedef_die (decl, context_die)
11065 dw_die_ref context_die;
11067 dw_die_ref type_die;
11070 if (TREE_ASM_WRITTEN (decl))
11073 TREE_ASM_WRITTEN (decl) = 1;
11074 type_die = new_die (DW_TAG_typedef, context_die, decl);
11075 origin = decl_ultimate_origin (decl);
11076 if (origin != NULL)
11077 add_abstract_origin_attribute (type_die, origin);
11082 add_name_and_src_coords_attributes (type_die, decl);
11083 if (DECL_ORIGINAL_TYPE (decl))
11085 type = DECL_ORIGINAL_TYPE (decl);
11087 if (type == TREE_TYPE (decl))
11090 equate_type_number_to_die (TREE_TYPE (decl), type_die);
11093 type = TREE_TYPE (decl);
11095 add_type_attribute (type_die, type, TREE_READONLY (decl),
11096 TREE_THIS_VOLATILE (decl), context_die);
11099 if (DECL_ABSTRACT (decl))
11100 equate_decl_number_to_die (decl, type_die);
11103 /* Generate a type description DIE. */
11106 gen_type_die (type, context_die)
11108 dw_die_ref context_die;
11112 if (type == NULL_TREE || type == error_mark_node)
11115 /* We are going to output a DIE to represent the unqualified version
11116 of this type (i.e. without any const or volatile qualifiers) so
11117 get the main variant (i.e. the unqualified version) of this type
11118 now. (Vectors are special because the debugging info is in the
11119 cloned type itself). */
11120 if (TREE_CODE (type) != VECTOR_TYPE)
11121 type = type_main_variant (type);
11123 if (TREE_ASM_WRITTEN (type))
11126 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11127 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
11129 /* Prevent broken recursion; we can't hand off to the same type. */
11130 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type)
11133 TREE_ASM_WRITTEN (type) = 1;
11134 gen_decl_die (TYPE_NAME (type), context_die);
11138 switch (TREE_CODE (type))
11144 case REFERENCE_TYPE:
11145 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11146 ensures that the gen_type_die recursion will terminate even if the
11147 type is recursive. Recursive types are possible in Ada. */
11148 /* ??? We could perhaps do this for all types before the switch
11150 TREE_ASM_WRITTEN (type) = 1;
11152 /* For these types, all that is required is that we output a DIE (or a
11153 set of DIEs) to represent the "basis" type. */
11154 gen_type_die (TREE_TYPE (type), context_die);
11158 /* This code is used for C++ pointer-to-data-member types.
11159 Output a description of the relevant class type. */
11160 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
11162 /* Output a description of the type of the object pointed to. */
11163 gen_type_die (TREE_TYPE (type), context_die);
11165 /* Now output a DIE to represent this pointer-to-data-member type
11167 gen_ptr_to_mbr_type_die (type, context_die);
11171 gen_type_die (TYPE_DOMAIN (type), context_die);
11172 gen_set_type_die (type, context_die);
11176 gen_type_die (TREE_TYPE (type), context_die);
11177 abort (); /* No way to represent these in Dwarf yet! */
11180 case FUNCTION_TYPE:
11181 /* Force out return type (in case it wasn't forced out already). */
11182 gen_type_die (TREE_TYPE (type), context_die);
11183 gen_subroutine_type_die (type, context_die);
11187 /* Force out return type (in case it wasn't forced out already). */
11188 gen_type_die (TREE_TYPE (type), context_die);
11189 gen_subroutine_type_die (type, context_die);
11193 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
11195 gen_type_die (TREE_TYPE (type), context_die);
11196 gen_string_type_die (type, context_die);
11199 gen_array_type_die (type, context_die);
11203 gen_array_type_die (type, context_die);
11206 case ENUMERAL_TYPE:
11209 case QUAL_UNION_TYPE:
11210 /* If this is a nested type whose containing class hasn't been written
11211 out yet, writing it out will cover this one, too. This does not apply
11212 to instantiations of member class templates; they need to be added to
11213 the containing class as they are generated. FIXME: This hurts the
11214 idea of combining type decls from multiple TUs, since we can't predict
11215 what set of template instantiations we'll get. */
11216 if (TYPE_CONTEXT (type)
11217 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
11218 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
11220 gen_type_die (TYPE_CONTEXT (type), context_die);
11222 if (TREE_ASM_WRITTEN (type))
11225 /* If that failed, attach ourselves to the stub. */
11226 push_decl_scope (TYPE_CONTEXT (type));
11227 context_die = lookup_type_die (TYPE_CONTEXT (type));
11233 if (TREE_CODE (type) == ENUMERAL_TYPE)
11234 gen_enumeration_type_die (type, context_die);
11236 gen_struct_or_union_type_die (type, context_die);
11241 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11242 it up if it is ever completed. gen_*_type_die will set it for us
11243 when appropriate. */
11252 /* No DIEs needed for fundamental types. */
11256 /* No Dwarf representation currently defined. */
11263 TREE_ASM_WRITTEN (type) = 1;
11266 /* Generate a DIE for a tagged type instantiation. */
11269 gen_tagged_type_instantiation_die (type, context_die)
11271 dw_die_ref context_die;
11273 if (type == NULL_TREE || type == error_mark_node)
11276 /* We are going to output a DIE to represent the unqualified version of
11277 this type (i.e. without any const or volatile qualifiers) so make sure
11278 that we have the main variant (i.e. the unqualified version) of this
11280 if (type != type_main_variant (type))
11283 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11284 an instance of an unresolved type. */
11286 switch (TREE_CODE (type))
11291 case ENUMERAL_TYPE:
11292 gen_inlined_enumeration_type_die (type, context_die);
11296 gen_inlined_structure_type_die (type, context_die);
11300 case QUAL_UNION_TYPE:
11301 gen_inlined_union_type_die (type, context_die);
11309 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11310 things which are local to the given block. */
11313 gen_block_die (stmt, context_die, depth)
11315 dw_die_ref context_die;
11318 int must_output_die = 0;
11321 enum tree_code origin_code;
11323 /* Ignore blocks never really used to make RTL. */
11324 if (stmt == NULL_TREE || !TREE_USED (stmt)
11325 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11328 /* If the block is one fragment of a non-contiguous block, do not
11329 process the variables, since they will have been done by the
11330 origin block. Do process subblocks. */
11331 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11335 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
11336 gen_block_die (sub, context_die, depth + 1);
11341 /* Determine the "ultimate origin" of this block. This block may be an
11342 inlined instance of an inlined instance of inline function, so we have
11343 to trace all of the way back through the origin chain to find out what
11344 sort of node actually served as the original seed for the creation of
11345 the current block. */
11346 origin = block_ultimate_origin (stmt);
11347 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11349 /* Determine if we need to output any Dwarf DIEs at all to represent this
11351 if (origin_code == FUNCTION_DECL)
11352 /* The outer scopes for inlinings *must* always be represented. We
11353 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11354 must_output_die = 1;
11357 /* In the case where the current block represents an inlining of the
11358 "body block" of an inline function, we must *NOT* output any DIE for
11359 this block because we have already output a DIE to represent the whole
11360 inlined function scope and the "body block" of any function doesn't
11361 really represent a different scope according to ANSI C rules. So we
11362 check here to make sure that this block does not represent a "body
11363 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11364 if (! is_body_block (origin ? origin : stmt))
11366 /* Determine if this block directly contains any "significant"
11367 local declarations which we will need to output DIEs for. */
11368 if (debug_info_level > DINFO_LEVEL_TERSE)
11369 /* We are not in terse mode so *any* local declaration counts
11370 as being a "significant" one. */
11371 must_output_die = (BLOCK_VARS (stmt) != NULL);
11373 /* We are in terse mode, so only local (nested) function
11374 definitions count as "significant" local declarations. */
11375 for (decl = BLOCK_VARS (stmt);
11376 decl != NULL; decl = TREE_CHAIN (decl))
11377 if (TREE_CODE (decl) == FUNCTION_DECL
11378 && DECL_INITIAL (decl))
11380 must_output_die = 1;
11386 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11387 DIE for any block which contains no significant local declarations at
11388 all. Rather, in such cases we just call `decls_for_scope' so that any
11389 needed Dwarf info for any sub-blocks will get properly generated. Note
11390 that in terse mode, our definition of what constitutes a "significant"
11391 local declaration gets restricted to include only inlined function
11392 instances and local (nested) function definitions. */
11393 if (must_output_die)
11395 if (origin_code == FUNCTION_DECL)
11396 gen_inlined_subroutine_die (stmt, context_die, depth);
11398 gen_lexical_block_die (stmt, context_die, depth);
11401 decls_for_scope (stmt, context_die, depth);
11404 /* Generate all of the decls declared within a given scope and (recursively)
11405 all of its sub-blocks. */
11408 decls_for_scope (stmt, context_die, depth)
11410 dw_die_ref context_die;
11416 /* Ignore blocks never really used to make RTL. */
11417 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11420 /* Output the DIEs to represent all of the data objects and typedefs
11421 declared directly within this block but not within any nested
11422 sub-blocks. Also, nested function and tag DIEs have been
11423 generated with a parent of NULL; fix that up now. */
11424 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
11428 if (TREE_CODE (decl) == FUNCTION_DECL)
11429 die = lookup_decl_die (decl);
11430 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11431 die = lookup_type_die (TREE_TYPE (decl));
11435 if (die != NULL && die->die_parent == NULL)
11436 add_child_die (context_die, die);
11438 gen_decl_die (decl, context_die);
11441 /* Output the DIEs to represent all sub-blocks (and the items declared
11442 therein) of this block. */
11443 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11445 subblocks = BLOCK_CHAIN (subblocks))
11446 gen_block_die (subblocks, context_die, depth + 1);
11449 /* Is this a typedef we can avoid emitting? */
11452 is_redundant_typedef (decl)
11455 if (TYPE_DECL_IS_STUB (decl))
11458 if (DECL_ARTIFICIAL (decl)
11459 && DECL_CONTEXT (decl)
11460 && is_tagged_type (DECL_CONTEXT (decl))
11461 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11462 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11463 /* Also ignore the artificial member typedef for the class name. */
11469 /* Generate Dwarf debug information for a decl described by DECL. */
11472 gen_decl_die (decl, context_die)
11474 dw_die_ref context_die;
11478 if (DECL_P (decl) && DECL_IGNORED_P (decl))
11481 switch (TREE_CODE (decl))
11487 /* The individual enumerators of an enum type get output when we output
11488 the Dwarf representation of the relevant enum type itself. */
11491 case FUNCTION_DECL:
11492 /* Don't output any DIEs to represent mere function declarations,
11493 unless they are class members or explicit block externs. */
11494 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11495 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11498 /* If we're emitting a clone, emit info for the abstract instance. */
11499 if (DECL_ORIGIN (decl) != decl)
11500 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11502 /* If we're emitting an out-of-line copy of an inline function,
11503 emit info for the abstract instance and set up to refer to it. */
11504 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11505 && ! class_scope_p (context_die)
11506 /* dwarf2out_abstract_function won't emit a die if this is just
11507 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11508 that case, because that works only if we have a die. */
11509 && DECL_INITIAL (decl) != NULL_TREE)
11511 dwarf2out_abstract_function (decl);
11512 set_decl_origin_self (decl);
11515 /* Otherwise we're emitting the primary DIE for this decl. */
11516 else if (debug_info_level > DINFO_LEVEL_TERSE)
11518 /* Before we describe the FUNCTION_DECL itself, make sure that we
11519 have described its return type. */
11520 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11522 /* And its virtual context. */
11523 if (DECL_VINDEX (decl) != NULL_TREE)
11524 gen_type_die (DECL_CONTEXT (decl), context_die);
11526 /* And its containing type. */
11527 origin = decl_class_context (decl);
11528 if (origin != NULL_TREE)
11529 gen_type_die_for_member (origin, decl, context_die);
11532 /* Now output a DIE to represent the function itself. */
11533 gen_subprogram_die (decl, context_die);
11537 /* If we are in terse mode, don't generate any DIEs to represent any
11538 actual typedefs. */
11539 if (debug_info_level <= DINFO_LEVEL_TERSE)
11542 /* In the special case of a TYPE_DECL node representing the declaration
11543 of some type tag, if the given TYPE_DECL is marked as having been
11544 instantiated from some other (original) TYPE_DECL node (e.g. one which
11545 was generated within the original definition of an inline function) we
11546 have to generate a special (abbreviated) DW_TAG_structure_type,
11547 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11548 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11550 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11554 if (is_redundant_typedef (decl))
11555 gen_type_die (TREE_TYPE (decl), context_die);
11557 /* Output a DIE to represent the typedef itself. */
11558 gen_typedef_die (decl, context_die);
11562 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11563 gen_label_die (decl, context_die);
11567 /* If we are in terse mode, don't generate any DIEs to represent any
11568 variable declarations or definitions. */
11569 if (debug_info_level <= DINFO_LEVEL_TERSE)
11572 /* Output any DIEs that are needed to specify the type of this data
11574 gen_type_die (TREE_TYPE (decl), context_die);
11576 /* And its containing type. */
11577 origin = decl_class_context (decl);
11578 if (origin != NULL_TREE)
11579 gen_type_die_for_member (origin, decl, context_die);
11581 /* Now output the DIE to represent the data object itself. This gets
11582 complicated because of the possibility that the VAR_DECL really
11583 represents an inlined instance of a formal parameter for an inline
11585 origin = decl_ultimate_origin (decl);
11586 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11587 gen_formal_parameter_die (decl, context_die);
11589 gen_variable_die (decl, context_die);
11593 /* Ignore the nameless fields that are used to skip bits but handle C++
11594 anonymous unions. */
11595 if (DECL_NAME (decl) != NULL_TREE
11596 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11598 gen_type_die (member_declared_type (decl), context_die);
11599 gen_field_die (decl, context_die);
11604 gen_type_die (TREE_TYPE (decl), context_die);
11605 gen_formal_parameter_die (decl, context_die);
11608 case NAMESPACE_DECL:
11609 /* Ignore for now. */
11618 mark_limbo_die_list (ptr)
11619 void *ptr ATTRIBUTE_UNUSED;
11621 limbo_die_node *node;
11622 for (node = limbo_die_list; node; node = node->next)
11623 ggc_mark_tree (node->created_for);
11626 /* Add Ada "use" clause information for SGI Workshop debugger. */
11629 dwarf2out_add_library_unit_info (filename, context_list)
11630 const char *filename;
11631 const char *context_list;
11633 unsigned int file_index;
11635 if (filename != NULL)
11637 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
11638 tree context_list_decl
11639 = build_decl (LABEL_DECL, get_identifier (context_list),
11642 TREE_PUBLIC (context_list_decl) = TRUE;
11643 add_name_attribute (unit_die, context_list);
11644 file_index = lookup_filename (filename);
11645 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11646 add_pubname (context_list_decl, unit_die);
11650 /* Output debug information for global decl DECL. Called from toplev.c after
11651 compilation proper has finished. */
11654 dwarf2out_global_decl (decl)
11657 /* Output DWARF2 information for file-scope tentative data object
11658 declarations, file-scope (extern) function declarations (which had no
11659 corresponding body) and file-scope tagged type declarations and
11660 definitions which have not yet been forced out. */
11661 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11662 dwarf2out_decl (decl);
11665 /* Write the debugging output for DECL. */
11668 dwarf2out_decl (decl)
11671 dw_die_ref context_die = comp_unit_die;
11673 switch (TREE_CODE (decl))
11678 case FUNCTION_DECL:
11679 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11680 builtin function. Explicit programmer-supplied declarations of
11681 these same functions should NOT be ignored however. */
11682 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11685 /* What we would really like to do here is to filter out all mere
11686 file-scope declarations of file-scope functions which are never
11687 referenced later within this translation unit (and keep all of ones
11688 that *are* referenced later on) but we aren't clairvoyant, so we have
11689 no idea which functions will be referenced in the future (i.e. later
11690 on within the current translation unit). So here we just ignore all
11691 file-scope function declarations which are not also definitions. If
11692 and when the debugger needs to know something about these functions,
11693 it will have to hunt around and find the DWARF information associated
11694 with the definition of the function.
11696 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11697 nodes represent definitions and which ones represent mere
11698 declarations. We have to check DECL_INITIAL instead. That's because
11699 the C front-end supports some weird semantics for "extern inline"
11700 function definitions. These can get inlined within the current
11701 translation unit (an thus, we need to generate Dwarf info for their
11702 abstract instances so that the Dwarf info for the concrete inlined
11703 instances can have something to refer to) but the compiler never
11704 generates any out-of-lines instances of such things (despite the fact
11705 that they *are* definitions).
11707 The important point is that the C front-end marks these "extern
11708 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11709 them anyway. Note that the C++ front-end also plays some similar games
11710 for inline function definitions appearing within include files which
11711 also contain `#pragma interface' pragmas. */
11712 if (DECL_INITIAL (decl) == NULL_TREE)
11715 /* If we're a nested function, initially use a parent of NULL; if we're
11716 a plain function, this will be fixed up in decls_for_scope. If
11717 we're a method, it will be ignored, since we already have a DIE. */
11718 if (decl_function_context (decl))
11719 context_die = NULL;
11723 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11724 declaration and if the declaration was never even referenced from
11725 within this entire compilation unit. We suppress these DIEs in
11726 order to save space in the .debug section (by eliminating entries
11727 which are probably useless). Note that we must not suppress
11728 block-local extern declarations (whether used or not) because that
11729 would screw-up the debugger's name lookup mechanism and cause it to
11730 miss things which really ought to be in scope at a given point. */
11731 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11734 /* If we are in terse mode, don't generate any DIEs to represent any
11735 variable declarations or definitions. */
11736 if (debug_info_level <= DINFO_LEVEL_TERSE)
11741 /* Don't emit stubs for types unless they are needed by other DIEs. */
11742 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11745 /* Don't bother trying to generate any DIEs to represent any of the
11746 normal built-in types for the language we are compiling. */
11747 if (DECL_SOURCE_LINE (decl) == 0)
11749 /* OK, we need to generate one for `bool' so GDB knows what type
11750 comparisons have. */
11751 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11752 == DW_LANG_C_plus_plus)
11753 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
11754 && ! DECL_IGNORED_P (decl))
11755 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11760 /* If we are in terse mode, don't generate any DIEs for types. */
11761 if (debug_info_level <= DINFO_LEVEL_TERSE)
11764 /* If we're a function-scope tag, initially use a parent of NULL;
11765 this will be fixed up in decls_for_scope. */
11766 if (decl_function_context (decl))
11767 context_die = NULL;
11775 gen_decl_die (decl, context_die);
11778 /* Output a marker (i.e. a label) for the beginning of the generated code for
11779 a lexical block. */
11782 dwarf2out_begin_block (line, blocknum)
11783 unsigned int line ATTRIBUTE_UNUSED;
11784 unsigned int blocknum;
11786 function_section (current_function_decl);
11787 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11790 /* Output a marker (i.e. a label) for the end of the generated code for a
11794 dwarf2out_end_block (line, blocknum)
11795 unsigned int line ATTRIBUTE_UNUSED;
11796 unsigned int blocknum;
11798 function_section (current_function_decl);
11799 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11802 /* Returns nonzero if it is appropriate not to emit any debugging
11803 information for BLOCK, because it doesn't contain any instructions.
11805 Don't allow this for blocks with nested functions or local classes
11806 as we would end up with orphans, and in the presence of scheduling
11807 we may end up calling them anyway. */
11810 dwarf2out_ignore_block (block)
11815 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11816 if (TREE_CODE (decl) == FUNCTION_DECL
11817 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11823 /* Lookup FILE_NAME (in the list of filenames that we know about here in
11824 dwarf2out.c) and return its "index". The index of each (known) filename is
11825 just a unique number which is associated with only that one filename. We
11826 need such numbers for the sake of generating labels (in the .debug_sfnames
11827 section) and references to those files numbers (in the .debug_srcinfo
11828 and.debug_macinfo sections). If the filename given as an argument is not
11829 found in our current list, add it to the list and assign it the next
11830 available unique index number. In order to speed up searches, we remember
11831 the index of the filename was looked up last. This handles the majority of
11835 lookup_filename (file_name)
11836 const char *file_name;
11840 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11841 if (strcmp (file_name, "<internal>") == 0
11842 || strcmp (file_name, "<built-in>") == 0)
11845 /* Check to see if the file name that was searched on the previous
11846 call matches this file name. If so, return the index. */
11847 if (file_table.last_lookup_index != 0)
11848 if (0 == strcmp (file_name,
11849 file_table.table[file_table.last_lookup_index]))
11850 return file_table.last_lookup_index;
11852 /* Didn't match the previous lookup, search the table */
11853 for (i = 1; i < file_table.in_use; i++)
11854 if (strcmp (file_name, file_table.table[i]) == 0)
11856 file_table.last_lookup_index = i;
11860 /* Prepare to add a new table entry by making sure there is enough space in
11861 the table to do so. If not, expand the current table. */
11862 if (i == file_table.allocated)
11864 file_table.allocated = i + FILE_TABLE_INCREMENT;
11865 file_table.table = (char **)
11866 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11869 /* Add the new entry to the end of the filename table. */
11870 file_table.table[i] = xstrdup (file_name);
11871 file_table.in_use = i + 1;
11872 file_table.last_lookup_index = i;
11874 if (DWARF2_ASM_LINE_DEBUG_INFO)
11876 fprintf (asm_out_file, "\t.file %u ", i);
11877 output_quoted_string (asm_out_file, file_name);
11878 fputc ('\n', asm_out_file);
11887 /* Allocate the initial hunk of the file_table. */
11888 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11889 file_table.allocated = FILE_TABLE_INCREMENT;
11891 /* Skip the first entry - file numbers begin at 1. */
11892 file_table.in_use = 1;
11893 file_table.last_lookup_index = 0;
11896 /* Output a label to mark the beginning of a source code line entry
11897 and record information relating to this source line, in
11898 'line_info_table' for later output of the .debug_line section. */
11901 dwarf2out_source_line (line, filename)
11903 const char *filename;
11905 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11907 function_section (current_function_decl);
11909 /* If requested, emit something human-readable. */
11910 if (flag_debug_asm)
11911 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11914 if (DWARF2_ASM_LINE_DEBUG_INFO)
11916 unsigned file_num = lookup_filename (filename);
11918 /* Emit the .loc directive understood by GNU as. */
11919 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11921 /* Indicate that line number info exists. */
11922 line_info_table_in_use++;
11924 /* Indicate that multiple line number tables exist. */
11925 if (DECL_SECTION_NAME (current_function_decl))
11926 separate_line_info_table_in_use++;
11928 else if (DECL_SECTION_NAME (current_function_decl))
11930 dw_separate_line_info_ref line_info;
11931 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11932 separate_line_info_table_in_use);
11934 /* expand the line info table if necessary */
11935 if (separate_line_info_table_in_use
11936 == separate_line_info_table_allocated)
11938 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11939 separate_line_info_table
11940 = (dw_separate_line_info_ref)
11941 xrealloc (separate_line_info_table,
11942 separate_line_info_table_allocated
11943 * sizeof (dw_separate_line_info_entry));
11946 /* Add the new entry at the end of the line_info_table. */
11948 = &separate_line_info_table[separate_line_info_table_in_use++];
11949 line_info->dw_file_num = lookup_filename (filename);
11950 line_info->dw_line_num = line;
11951 line_info->function = current_function_funcdef_no;
11955 dw_line_info_ref line_info;
11957 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11958 line_info_table_in_use);
11960 /* Expand the line info table if necessary. */
11961 if (line_info_table_in_use == line_info_table_allocated)
11963 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11965 = (dw_line_info_ref)
11966 xrealloc (line_info_table,
11967 (line_info_table_allocated
11968 * sizeof (dw_line_info_entry)));
11971 /* Add the new entry at the end of the line_info_table. */
11972 line_info = &line_info_table[line_info_table_in_use++];
11973 line_info->dw_file_num = lookup_filename (filename);
11974 line_info->dw_line_num = line;
11979 /* Record the beginning of a new source file. */
11982 dwarf2out_start_source_file (lineno, filename)
11983 unsigned int lineno;
11984 const char *filename;
11986 if (flag_eliminate_dwarf2_dups)
11988 /* Record the beginning of the file for break_out_includes. */
11989 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
11990 add_AT_string (bincl_die, DW_AT_name, filename);
11993 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11995 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11996 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11997 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11999 dw2_asm_output_data_uleb128 (lookup_filename (filename),
12000 "Filename we just started");
12004 /* Record the end of a source file. */
12007 dwarf2out_end_source_file (lineno)
12008 unsigned int lineno ATTRIBUTE_UNUSED;
12010 if (flag_eliminate_dwarf2_dups)
12011 /* Record the end of the file for break_out_includes. */
12012 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
12014 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12016 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12017 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12021 /* Called from debug_define in toplev.c. The `buffer' parameter contains
12022 the tail part of the directive line, i.e. the part which is past the
12023 initial whitespace, #, whitespace, directive-name, whitespace part. */
12026 dwarf2out_define (lineno, buffer)
12027 unsigned lineno ATTRIBUTE_UNUSED;
12028 const char *buffer ATTRIBUTE_UNUSED;
12030 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12032 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12033 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
12034 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12035 dw2_asm_output_nstring (buffer, -1, "The macro");
12039 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
12040 the tail part of the directive line, i.e. the part which is past the
12041 initial whitespace, #, whitespace, directive-name, whitespace part. */
12044 dwarf2out_undef (lineno, buffer)
12045 unsigned lineno ATTRIBUTE_UNUSED;
12046 const char *buffer ATTRIBUTE_UNUSED;
12048 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12050 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12051 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
12052 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12053 dw2_asm_output_nstring (buffer, -1, "The macro");
12057 /* Set up for Dwarf output at the start of compilation. */
12060 dwarf2out_init (main_input_filename)
12061 const char *main_input_filename;
12063 init_file_table ();
12065 /* Remember the name of the primary input file. */
12066 primary_filename = main_input_filename;
12068 /* Add it to the file table first, under the assumption that we'll
12069 be emitting line number data for it first, which avoids having
12070 to add an initial DW_LNS_set_file. */
12071 lookup_filename (main_input_filename);
12073 /* Allocate the initial hunk of the decl_die_table. */
12075 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
12076 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
12077 decl_die_table_in_use = 0;
12079 /* Allocate the initial hunk of the decl_scope_table. */
12080 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
12082 /* Allocate the initial hunk of the abbrev_die_table. */
12084 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
12085 sizeof (dw_die_ref));
12086 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
12087 /* Zero-th entry is allocated, but unused */
12088 abbrev_die_table_in_use = 1;
12090 /* Allocate the initial hunk of the line_info_table. */
12092 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
12093 sizeof (dw_line_info_entry));
12094 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
12096 /* Zero-th entry is allocated, but unused */
12097 line_info_table_in_use = 1;
12099 /* Generate the initial DIE for the .debug section. Note that the (string)
12100 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12101 will (typically) be a relative pathname and that this pathname should be
12102 taken as being relative to the directory from which the compiler was
12103 invoked when the given (base) source file was compiled. */
12104 comp_unit_die = gen_compile_unit_die (main_input_filename);
12106 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
12108 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
12110 ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list);
12112 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
12113 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
12114 DEBUG_ABBREV_SECTION_LABEL, 0);
12115 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12116 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
12118 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
12120 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
12121 DEBUG_INFO_SECTION_LABEL, 0);
12122 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
12123 DEBUG_LINE_SECTION_LABEL, 0);
12124 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
12125 DEBUG_RANGES_SECTION_LABEL, 0);
12126 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12127 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
12128 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
12129 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
12130 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12131 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
12133 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12135 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12136 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
12137 DEBUG_MACINFO_SECTION_LABEL, 0);
12138 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
12141 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12144 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
12148 /* Allocate a string in .debug_str hash table. */
12151 indirect_string_alloc (tab)
12152 hash_table *tab ATTRIBUTE_UNUSED;
12154 struct indirect_string_node *node;
12156 node = xmalloc (sizeof (struct indirect_string_node));
12157 node->refcount = 0;
12159 node->label = NULL;
12161 return (hashnode) node;
12164 /* A helper function for dwarf2out_finish called through
12165 ht_forall. Emit one queued .debug_str string. */
12168 output_indirect_string (pfile, h, v)
12169 struct cpp_reader *pfile ATTRIBUTE_UNUSED;
12171 const PTR v ATTRIBUTE_UNUSED;
12173 struct indirect_string_node *node = (struct indirect_string_node *) h;
12175 if (node->form == DW_FORM_strp)
12177 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
12178 ASM_OUTPUT_LABEL (asm_out_file, node->label);
12179 assemble_string ((const char *) HT_STR (&node->id),
12180 HT_LEN (&node->id) + 1);
12186 /* Output stuff that dwarf requires at the end of every file,
12187 and generate the DWARF-2 debugging info. */
12190 dwarf2out_finish (input_filename)
12191 const char *input_filename ATTRIBUTE_UNUSED;
12193 limbo_die_node *node, *next_node;
12194 dw_die_ref die = 0;
12196 /* Traverse the limbo die list, and add parent/child links. The only
12197 dies without parents that should be here are concrete instances of
12198 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12199 For concrete instances, we can get the parent die from the abstract
12201 for (node = limbo_die_list; node; node = next_node)
12203 next_node = node->next;
12206 if (die->die_parent == NULL)
12208 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
12212 add_child_die (origin->die_parent, die);
12213 else if (die == comp_unit_die)
12215 /* If this was an expression for a bound involved in a function
12216 return type, it may be a SAVE_EXPR for which we weren't able
12217 to find a DIE previously. So try now. */
12218 else if (node->created_for
12219 && TREE_CODE (node->created_for) == SAVE_EXPR
12220 && 0 != (origin = (lookup_decl_die
12222 (node->created_for)))))
12223 add_child_die (origin, die);
12224 else if (errorcount > 0 || sorrycount > 0)
12225 /* It's OK to be confused by errors in the input. */
12226 add_child_die (comp_unit_die, die);
12227 else if (node->created_for
12228 && ((DECL_P (node->created_for)
12229 && (context = DECL_CONTEXT (node->created_for)))
12230 || (TYPE_P (node->created_for)
12231 && (context = TYPE_CONTEXT (node->created_for))))
12232 && TREE_CODE (context) == FUNCTION_DECL)
12234 /* In certain situations, the lexical block containing a
12235 nested function can be optimized away, which results
12236 in the nested function die being orphaned. Likewise
12237 with the return type of that nested function. Force
12238 this to be a child of the containing function. */
12239 origin = lookup_decl_die (context);
12242 add_child_die (origin, die);
12251 limbo_die_list = NULL;
12253 /* Walk through the list of incomplete types again, trying once more to
12254 emit full debugging info for them. */
12255 retry_incomplete_types ();
12257 /* We need to reverse all the dies before break_out_includes, or
12258 we'll see the end of an include file before the beginning. */
12259 reverse_all_dies (comp_unit_die);
12261 /* Generate separate CUs for each of the include files we've seen.
12262 They will go into limbo_die_list. */
12263 if (flag_eliminate_dwarf2_dups)
12264 break_out_includes (comp_unit_die);
12266 /* Traverse the DIE's and add add sibling attributes to those DIE's
12267 that have children. */
12268 add_sibling_attributes (comp_unit_die);
12269 for (node = limbo_die_list; node; node = node->next)
12270 add_sibling_attributes (node->die);
12272 /* Output a terminator label for the .text section. */
12274 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
12276 /* Output the source line correspondence table. We must do this
12277 even if there is no line information. Otherwise, on an empty
12278 translation unit, we will generate a present, but empty,
12279 .debug_info section. IRIX 6.5 `nm' will then complain when
12280 examining the file. */
12281 if (! DWARF2_ASM_LINE_DEBUG_INFO)
12283 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12284 output_line_info ();
12287 /* Output location list section if necessary. */
12288 if (have_location_lists)
12290 /* Output the location lists info. */
12291 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
12292 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
12293 DEBUG_LOC_SECTION_LABEL, 0);
12294 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
12295 output_location_lists (die);
12296 have_location_lists = 0;
12299 /* We can only use the low/high_pc attributes if all of the code was
12301 if (separate_line_info_table_in_use == 0)
12303 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
12304 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
12307 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12308 "base address". Use zero so that these addresses become absolute. */
12309 else if (have_location_lists || ranges_table_in_use)
12310 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
12312 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12313 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
12314 debug_line_section_label);
12316 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12317 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
12319 /* Output all of the compilation units. We put the main one last so that
12320 the offsets are available to output_pubnames. */
12321 for (node = limbo_die_list; node; node = node->next)
12322 output_comp_unit (node->die);
12324 output_comp_unit (comp_unit_die);
12326 /* Output the abbreviation table. */
12327 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12328 output_abbrev_section ();
12330 /* Output public names table if necessary. */
12331 if (pubname_table_in_use)
12333 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
12334 output_pubnames ();
12337 /* Output the address range information. We only put functions in the arange
12338 table, so don't write it out if we don't have any. */
12339 if (fde_table_in_use)
12341 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
12345 /* Output ranges section if necessary. */
12346 if (ranges_table_in_use)
12348 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
12349 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12353 /* Have to end the primary source file. */
12354 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12356 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12357 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12358 dw2_asm_output_data (1, 0, "End compilation unit");
12361 /* If we emitted any DW_FORM_strp form attribute, output the string
12363 if (debug_str_hash)
12364 ht_forall (debug_str_hash, output_indirect_string, NULL);
12368 /* This should never be used, but its address is needed for comparisons. */
12369 const struct gcc_debug_hooks dwarf2_debug_hooks;
12371 #endif /* DWARF2_DEBUGGING_INFO */
12373 #include "gt-dwarf2out.h"