1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004 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
39 #include "coretypes.h"
46 #include "hard-reg-set.h"
48 #include "insn-config.h"
56 #include "dwarf2out.h"
57 #include "dwarf2asm.h"
63 #include "diagnostic.h"
66 #include "langhooks.h"
71 #ifdef DWARF2_DEBUGGING_INFO
72 static void dwarf2out_source_line (unsigned int, const char *);
75 /* DWARF2 Abbreviation Glossary:
76 CFA = Canonical Frame Address
77 a fixed address on the stack which identifies a call frame.
78 We define it to be the value of SP just before the call insn.
79 The CFA register and offset, which may change during the course
80 of the function, are used to calculate its value at runtime.
81 CFI = Call Frame Instruction
82 an instruction for the DWARF2 abstract machine
83 CIE = Common Information Entry
84 information describing information common to one or more FDEs
85 DIE = Debugging Information Entry
86 FDE = Frame Description Entry
87 information describing the stack call frame, in particular,
88 how to restore registers
90 DW_CFA_... = DWARF2 CFA call frame instruction
91 DW_TAG_... = DWARF2 DIE tag */
93 /* Decide whether we want to emit frame unwind information for the current
97 dwarf2out_do_frame (void)
99 return (write_symbols == DWARF2_DEBUG
100 || write_symbols == VMS_AND_DWARF2_DEBUG
101 #ifdef DWARF2_FRAME_INFO
104 #ifdef DWARF2_UNWIND_INFO
105 || flag_unwind_tables
106 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
111 /* The size of the target's pointer type. */
113 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
116 /* Various versions of targetm.eh_frame_section. Note these must appear
117 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro guards. */
119 /* Version of targetm.eh_frame_section for systems with named sections. */
121 named_section_eh_frame_section (void)
123 #ifdef EH_FRAME_SECTION_NAME
126 if (EH_TABLES_CAN_BE_READ_ONLY)
132 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
133 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
134 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
136 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
137 && (fde_encoding & 0x70) != DW_EH_PE_aligned
138 && (per_encoding & 0x70) != DW_EH_PE_absptr
139 && (per_encoding & 0x70) != DW_EH_PE_aligned
140 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
141 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
145 flags = SECTION_WRITE;
146 named_section_flags (EH_FRAME_SECTION_NAME, flags);
150 /* Version of targetm.eh_frame_section for systems using collect2. */
152 collect2_eh_frame_section (void)
154 tree label = get_file_function_name ('F');
157 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
158 targetm.asm_out.globalize_label (asm_out_file, IDENTIFIER_POINTER (label));
159 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
162 /* Default version of targetm.eh_frame_section. */
164 default_eh_frame_section (void)
166 #ifdef EH_FRAME_SECTION_NAME
167 named_section_eh_frame_section ();
169 collect2_eh_frame_section ();
173 /* Array of RTXes referenced by the debugging information, which therefore
174 must be kept around forever. */
175 static GTY(()) varray_type used_rtx_varray;
177 /* A pointer to the base of a list of incomplete types which might be
178 completed at some later time. incomplete_types_list needs to be a VARRAY
179 because we want to tell the garbage collector about it. */
180 static GTY(()) varray_type incomplete_types;
182 /* A pointer to the base of a table of references to declaration
183 scopes. This table is a display which tracks the nesting
184 of declaration scopes at the current scope and containing
185 scopes. This table is used to find the proper place to
186 define type declaration DIE's. */
187 static GTY(()) varray_type decl_scope_table;
189 /* How to start an assembler comment. */
190 #ifndef ASM_COMMENT_START
191 #define ASM_COMMENT_START ";#"
194 typedef struct dw_cfi_struct *dw_cfi_ref;
195 typedef struct dw_fde_struct *dw_fde_ref;
196 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
198 /* Call frames are described using a sequence of Call Frame
199 Information instructions. The register number, offset
200 and address fields are provided as possible operands;
201 their use is selected by the opcode field. */
203 enum dw_cfi_oprnd_type {
205 dw_cfi_oprnd_reg_num,
211 typedef union dw_cfi_oprnd_struct GTY(())
213 unsigned long GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
214 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
215 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
216 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
220 typedef struct dw_cfi_struct GTY(())
222 dw_cfi_ref dw_cfi_next;
223 enum dwarf_call_frame_info dw_cfi_opc;
224 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
226 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
231 /* This is how we define the location of the CFA. We use to handle it
232 as REG + OFFSET all the time, but now it can be more complex.
233 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
234 Instead of passing around REG and OFFSET, we pass a copy
235 of this structure. */
236 typedef struct cfa_loc GTY(())
239 HOST_WIDE_INT offset;
240 HOST_WIDE_INT base_offset;
241 int indirect; /* 1 if CFA is accessed via a dereference. */
244 /* All call frame descriptions (FDE's) in the GCC generated DWARF
245 refer to a single Common Information Entry (CIE), defined at
246 the beginning of the .debug_frame section. This use of a single
247 CIE obviates the need to keep track of multiple CIE's
248 in the DWARF generation routines below. */
250 typedef struct dw_fde_struct GTY(())
253 const char *dw_fde_begin;
254 const char *dw_fde_current_label;
255 const char *dw_fde_end;
256 dw_cfi_ref dw_fde_cfi;
257 unsigned funcdef_number;
258 unsigned all_throwers_are_sibcalls : 1;
259 unsigned nothrow : 1;
260 unsigned uses_eh_lsda : 1;
264 /* Maximum size (in bytes) of an artificially generated label. */
265 #define MAX_ARTIFICIAL_LABEL_BYTES 30
267 /* The size of addresses as they appear in the Dwarf 2 data.
268 Some architectures use word addresses to refer to code locations,
269 but Dwarf 2 info always uses byte addresses. On such machines,
270 Dwarf 2 addresses need to be larger than the architecture's
272 #ifndef DWARF2_ADDR_SIZE
273 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
276 /* The size in bytes of a DWARF field indicating an offset or length
277 relative to a debug info section, specified to be 4 bytes in the
278 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
281 #ifndef DWARF_OFFSET_SIZE
282 #define DWARF_OFFSET_SIZE 4
285 /* According to the (draft) DWARF 3 specification, the initial length
286 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
287 bytes are 0xffffffff, followed by the length stored in the next 8
290 However, the SGI/MIPS ABI uses an initial length which is equal to
291 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
293 #ifndef DWARF_INITIAL_LENGTH_SIZE
294 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
297 #define DWARF_VERSION 2
299 /* Round SIZE up to the nearest BOUNDARY. */
300 #define DWARF_ROUND(SIZE,BOUNDARY) \
301 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
303 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
304 #ifndef DWARF_CIE_DATA_ALIGNMENT
305 #ifdef STACK_GROWS_DOWNWARD
306 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
308 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
312 /* A pointer to the base of a table that contains frame description
313 information for each routine. */
314 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
316 /* Number of elements currently allocated for fde_table. */
317 static GTY(()) unsigned fde_table_allocated;
319 /* Number of elements in fde_table currently in use. */
320 static GTY(()) unsigned fde_table_in_use;
322 /* Size (in elements) of increments by which we may expand the
324 #define FDE_TABLE_INCREMENT 256
326 /* A list of call frame insns for the CIE. */
327 static GTY(()) dw_cfi_ref cie_cfi_head;
329 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
330 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
331 attribute that accelerates the lookup of the FDE associated
332 with the subprogram. This variable holds the table index of the FDE
333 associated with the current function (body) definition. */
334 static unsigned current_funcdef_fde;
337 struct indirect_string_node GTY(())
340 unsigned int refcount;
345 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
347 static GTY(()) int dw2_string_counter;
348 static GTY(()) unsigned long dwarf2out_cfi_label_num;
350 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
352 /* Forward declarations for functions defined in this file. */
354 static char *stripattributes (const char *);
355 static const char *dwarf_cfi_name (unsigned);
356 static dw_cfi_ref new_cfi (void);
357 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
358 static void add_fde_cfi (const char *, dw_cfi_ref);
359 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
360 static void lookup_cfa (dw_cfa_location *);
361 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
362 static void initial_return_save (rtx);
363 static HOST_WIDE_INT stack_adjust_offset (rtx);
364 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
365 static void output_call_frame_info (int);
366 static void dwarf2out_stack_adjust (rtx, bool);
367 static void flush_queued_reg_saves (void);
368 static bool clobbers_queued_reg_save (rtx);
369 static void dwarf2out_frame_debug_expr (rtx, const char *);
371 /* Support for complex CFA locations. */
372 static void output_cfa_loc (dw_cfi_ref);
373 static void get_cfa_from_loc_descr (dw_cfa_location *,
374 struct dw_loc_descr_struct *);
375 static struct dw_loc_descr_struct *build_cfa_loc
377 static void def_cfa_1 (const char *, dw_cfa_location *);
379 /* How to start an assembler comment. */
380 #ifndef ASM_COMMENT_START
381 #define ASM_COMMENT_START ";#"
384 /* Data and reference forms for relocatable data. */
385 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
386 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
388 #ifndef DEBUG_FRAME_SECTION
389 #define DEBUG_FRAME_SECTION ".debug_frame"
392 #ifndef FUNC_BEGIN_LABEL
393 #define FUNC_BEGIN_LABEL "LFB"
396 #ifndef FUNC_END_LABEL
397 #define FUNC_END_LABEL "LFE"
400 #ifndef FRAME_BEGIN_LABEL
401 #define FRAME_BEGIN_LABEL "Lframe"
403 #define CIE_AFTER_SIZE_LABEL "LSCIE"
404 #define CIE_END_LABEL "LECIE"
405 #define FDE_LABEL "LSFDE"
406 #define FDE_AFTER_SIZE_LABEL "LASFDE"
407 #define FDE_END_LABEL "LEFDE"
408 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
409 #define LINE_NUMBER_END_LABEL "LELT"
410 #define LN_PROLOG_AS_LABEL "LASLTP"
411 #define LN_PROLOG_END_LABEL "LELTP"
412 #define DIE_LABEL_PREFIX "DW"
414 /* The DWARF 2 CFA column which tracks the return address. Normally this
415 is the column for PC, or the first column after all of the hard
417 #ifndef DWARF_FRAME_RETURN_COLUMN
419 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
421 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
425 /* The mapping from gcc register number to DWARF 2 CFA column number. By
426 default, we just provide columns for all registers. */
427 #ifndef DWARF_FRAME_REGNUM
428 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
431 /* The offset from the incoming value of %sp to the top of the stack frame
432 for the current function. */
433 #ifndef INCOMING_FRAME_SP_OFFSET
434 #define INCOMING_FRAME_SP_OFFSET 0
437 /* Hook used by __throw. */
440 expand_builtin_dwarf_sp_column (void)
442 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
445 /* Return a pointer to a copy of the section string name S with all
446 attributes stripped off, and an asterisk prepended (for assemble_name). */
449 stripattributes (const char *s)
451 char *stripped = xmalloc (strlen (s) + 2);
456 while (*s && *s != ',')
463 /* Generate code to initialize the register size table. */
466 expand_builtin_init_dwarf_reg_sizes (tree address)
469 enum machine_mode mode = TYPE_MODE (char_type_node);
470 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
471 rtx mem = gen_rtx_MEM (BLKmode, addr);
472 bool wrote_return_column = false;
474 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
475 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
477 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
478 enum machine_mode save_mode = reg_raw_mode[i];
481 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
482 save_mode = choose_hard_reg_mode (i, 1, true);
483 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
485 if (save_mode == VOIDmode)
487 wrote_return_column = true;
489 size = GET_MODE_SIZE (save_mode);
493 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
496 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
497 gcc_assert (wrote_return_column);
498 i = DWARF_ALT_FRAME_RETURN_COLUMN;
499 wrote_return_column = false;
501 i = DWARF_FRAME_RETURN_COLUMN;
504 if (! wrote_return_column)
506 enum machine_mode save_mode = Pmode;
507 HOST_WIDE_INT offset = i * GET_MODE_SIZE (mode);
508 HOST_WIDE_INT size = GET_MODE_SIZE (save_mode);
509 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
513 /* Convert a DWARF call frame info. operation to its string name */
516 dwarf_cfi_name (unsigned int cfi_opc)
520 case DW_CFA_advance_loc:
521 return "DW_CFA_advance_loc";
523 return "DW_CFA_offset";
525 return "DW_CFA_restore";
529 return "DW_CFA_set_loc";
530 case DW_CFA_advance_loc1:
531 return "DW_CFA_advance_loc1";
532 case DW_CFA_advance_loc2:
533 return "DW_CFA_advance_loc2";
534 case DW_CFA_advance_loc4:
535 return "DW_CFA_advance_loc4";
536 case DW_CFA_offset_extended:
537 return "DW_CFA_offset_extended";
538 case DW_CFA_restore_extended:
539 return "DW_CFA_restore_extended";
540 case DW_CFA_undefined:
541 return "DW_CFA_undefined";
542 case DW_CFA_same_value:
543 return "DW_CFA_same_value";
544 case DW_CFA_register:
545 return "DW_CFA_register";
546 case DW_CFA_remember_state:
547 return "DW_CFA_remember_state";
548 case DW_CFA_restore_state:
549 return "DW_CFA_restore_state";
551 return "DW_CFA_def_cfa";
552 case DW_CFA_def_cfa_register:
553 return "DW_CFA_def_cfa_register";
554 case DW_CFA_def_cfa_offset:
555 return "DW_CFA_def_cfa_offset";
558 case DW_CFA_def_cfa_expression:
559 return "DW_CFA_def_cfa_expression";
560 case DW_CFA_expression:
561 return "DW_CFA_expression";
562 case DW_CFA_offset_extended_sf:
563 return "DW_CFA_offset_extended_sf";
564 case DW_CFA_def_cfa_sf:
565 return "DW_CFA_def_cfa_sf";
566 case DW_CFA_def_cfa_offset_sf:
567 return "DW_CFA_def_cfa_offset_sf";
569 /* SGI/MIPS specific */
570 case DW_CFA_MIPS_advance_loc8:
571 return "DW_CFA_MIPS_advance_loc8";
574 case DW_CFA_GNU_window_save:
575 return "DW_CFA_GNU_window_save";
576 case DW_CFA_GNU_args_size:
577 return "DW_CFA_GNU_args_size";
578 case DW_CFA_GNU_negative_offset_extended:
579 return "DW_CFA_GNU_negative_offset_extended";
582 return "DW_CFA_<unknown>";
586 /* Return a pointer to a newly allocated Call Frame Instruction. */
588 static inline dw_cfi_ref
591 dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node));
593 cfi->dw_cfi_next = NULL;
594 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
595 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
600 /* Add a Call Frame Instruction to list of instructions. */
603 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
607 /* Find the end of the chain. */
608 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
614 /* Generate a new label for the CFI info to refer to. */
617 dwarf2out_cfi_label (void)
619 static char label[20];
621 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
622 ASM_OUTPUT_LABEL (asm_out_file, label);
626 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
627 or to the CIE if LABEL is NULL. */
630 add_fde_cfi (const char *label, dw_cfi_ref cfi)
634 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
637 label = dwarf2out_cfi_label ();
639 if (fde->dw_fde_current_label == NULL
640 || strcmp (label, fde->dw_fde_current_label) != 0)
644 fde->dw_fde_current_label = label = xstrdup (label);
646 /* Set the location counter to the new label. */
648 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
649 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
650 add_cfi (&fde->dw_fde_cfi, xcfi);
653 add_cfi (&fde->dw_fde_cfi, cfi);
657 add_cfi (&cie_cfi_head, cfi);
660 /* Subroutine of lookup_cfa. */
663 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
665 switch (cfi->dw_cfi_opc)
667 case DW_CFA_def_cfa_offset:
668 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
670 case DW_CFA_def_cfa_register:
671 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
674 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
675 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
677 case DW_CFA_def_cfa_expression:
678 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
685 /* Find the previous value for the CFA. */
688 lookup_cfa (dw_cfa_location *loc)
692 loc->reg = (unsigned long) -1;
695 loc->base_offset = 0;
697 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
698 lookup_cfa_1 (cfi, loc);
700 if (fde_table_in_use)
702 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
703 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
704 lookup_cfa_1 (cfi, loc);
708 /* The current rule for calculating the DWARF2 canonical frame address. */
709 static dw_cfa_location cfa;
711 /* The register used for saving registers to the stack, and its offset
713 static dw_cfa_location cfa_store;
715 /* The running total of the size of arguments pushed onto the stack. */
716 static HOST_WIDE_INT args_size;
718 /* The last args_size we actually output. */
719 static HOST_WIDE_INT old_args_size;
721 /* Entry point to update the canonical frame address (CFA).
722 LABEL is passed to add_fde_cfi. The value of CFA is now to be
723 calculated from REG+OFFSET. */
726 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
733 def_cfa_1 (label, &loc);
736 /* This routine does the actual work. The CFA is now calculated from
737 the dw_cfa_location structure. */
740 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
743 dw_cfa_location old_cfa, loc;
748 if (cfa_store.reg == loc.reg && loc.indirect == 0)
749 cfa_store.offset = loc.offset;
751 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
752 lookup_cfa (&old_cfa);
754 /* If nothing changed, no need to issue any call frame instructions. */
755 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
756 && loc.indirect == old_cfa.indirect
757 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
762 if (loc.reg == old_cfa.reg && !loc.indirect)
764 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
765 indicating the CFA register did not change but the offset
767 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
768 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
771 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
772 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
775 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
776 indicating the CFA register has changed to <register> but the
777 offset has not changed. */
778 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
779 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
783 else if (loc.indirect == 0)
785 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
786 indicating the CFA register has changed to <register> with
787 the specified offset. */
788 cfi->dw_cfi_opc = DW_CFA_def_cfa;
789 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
790 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
794 /* Construct a DW_CFA_def_cfa_expression instruction to
795 calculate the CFA using a full location expression since no
796 register-offset pair is available. */
797 struct dw_loc_descr_struct *loc_list;
799 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
800 loc_list = build_cfa_loc (&loc);
801 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
804 add_fde_cfi (label, cfi);
807 /* Add the CFI for saving a register. REG is the CFA column number.
808 LABEL is passed to add_fde_cfi.
809 If SREG is -1, the register is saved at OFFSET from the CFA;
810 otherwise it is saved in SREG. */
813 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
815 dw_cfi_ref cfi = new_cfi ();
817 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
819 if (sreg == INVALID_REGNUM)
822 /* The register number won't fit in 6 bits, so we have to use
824 cfi->dw_cfi_opc = DW_CFA_offset_extended;
826 cfi->dw_cfi_opc = DW_CFA_offset;
828 #ifdef ENABLE_CHECKING
830 /* If we get an offset that is not a multiple of
831 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
832 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
834 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
836 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
839 offset /= DWARF_CIE_DATA_ALIGNMENT;
841 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
843 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
845 else if (sreg == reg)
846 cfi->dw_cfi_opc = DW_CFA_same_value;
849 cfi->dw_cfi_opc = DW_CFA_register;
850 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
853 add_fde_cfi (label, cfi);
856 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
857 This CFI tells the unwinder that it needs to restore the window registers
858 from the previous frame's window save area.
860 ??? Perhaps we should note in the CIE where windows are saved (instead of
861 assuming 0(cfa)) and what registers are in the window. */
864 dwarf2out_window_save (const char *label)
866 dw_cfi_ref cfi = new_cfi ();
868 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
869 add_fde_cfi (label, cfi);
872 /* Add a CFI to update the running total of the size of arguments
873 pushed onto the stack. */
876 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
880 if (size == old_args_size)
883 old_args_size = size;
886 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
887 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
888 add_fde_cfi (label, cfi);
891 /* Entry point for saving a register to the stack. REG is the GCC register
892 number. LABEL and OFFSET are passed to reg_save. */
895 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
897 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
900 /* Entry point for saving the return address in the stack.
901 LABEL and OFFSET are passed to reg_save. */
904 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
906 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
909 /* Entry point for saving the return address in a register.
910 LABEL and SREG are passed to reg_save. */
913 dwarf2out_return_reg (const char *label, unsigned int sreg)
915 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
918 /* Record the initial position of the return address. RTL is
919 INCOMING_RETURN_ADDR_RTX. */
922 initial_return_save (rtx rtl)
924 unsigned int reg = INVALID_REGNUM;
925 HOST_WIDE_INT offset = 0;
927 switch (GET_CODE (rtl))
930 /* RA is in a register. */
931 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
935 /* RA is on the stack. */
937 switch (GET_CODE (rtl))
940 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
945 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
946 offset = INTVAL (XEXP (rtl, 1));
950 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
951 offset = -INTVAL (XEXP (rtl, 1));
961 /* The return address is at some offset from any value we can
962 actually load. For instance, on the SPARC it is in %i7+8. Just
963 ignore the offset for now; it doesn't matter for unwinding frames. */
964 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
965 initial_return_save (XEXP (rtl, 0));
972 if (reg != DWARF_FRAME_RETURN_COLUMN)
973 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
976 /* Given a SET, calculate the amount of stack adjustment it
980 stack_adjust_offset (rtx pattern)
982 rtx src = SET_SRC (pattern);
983 rtx dest = SET_DEST (pattern);
984 HOST_WIDE_INT offset = 0;
987 if (dest == stack_pointer_rtx)
989 /* (set (reg sp) (plus (reg sp) (const_int))) */
990 code = GET_CODE (src);
991 if (! (code == PLUS || code == MINUS)
992 || XEXP (src, 0) != stack_pointer_rtx
993 || GET_CODE (XEXP (src, 1)) != CONST_INT)
996 offset = INTVAL (XEXP (src, 1));
1000 else if (MEM_P (dest))
1002 /* (set (mem (pre_dec (reg sp))) (foo)) */
1003 src = XEXP (dest, 0);
1004 code = GET_CODE (src);
1010 if (XEXP (src, 0) == stack_pointer_rtx)
1012 rtx val = XEXP (XEXP (src, 1), 1);
1013 /* We handle only adjustments by constant amount. */
1014 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1015 && GET_CODE (val) == CONST_INT);
1016 offset = -INTVAL (val);
1023 if (XEXP (src, 0) == stack_pointer_rtx)
1025 offset = GET_MODE_SIZE (GET_MODE (dest));
1032 if (XEXP (src, 0) == stack_pointer_rtx)
1034 offset = -GET_MODE_SIZE (GET_MODE (dest));
1049 /* Check INSN to see if it looks like a push or a stack adjustment, and
1050 make a note of it if it does. EH uses this information to find out how
1051 much extra space it needs to pop off the stack. */
1054 dwarf2out_stack_adjust (rtx insn, bool after_p)
1056 HOST_WIDE_INT offset;
1060 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1061 with this function. Proper support would require all frame-related
1062 insns to be marked, and to be able to handle saving state around
1063 epilogues textually in the middle of the function. */
1064 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1067 /* If only calls can throw, and we have a frame pointer,
1068 save up adjustments until we see the CALL_INSN. */
1069 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1071 if (CALL_P (insn) && !after_p)
1073 /* Extract the size of the args from the CALL rtx itself. */
1074 insn = PATTERN (insn);
1075 if (GET_CODE (insn) == PARALLEL)
1076 insn = XVECEXP (insn, 0, 0);
1077 if (GET_CODE (insn) == SET)
1078 insn = SET_SRC (insn);
1079 gcc_assert (GET_CODE (insn) == CALL);
1080 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1085 if (CALL_P (insn) && !after_p)
1087 if (!flag_asynchronous_unwind_tables)
1088 dwarf2out_args_size ("", args_size);
1091 else if (BARRIER_P (insn))
1093 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1094 the compiler will have already emitted a stack adjustment, but
1095 doesn't bother for calls to noreturn functions. */
1096 #ifdef STACK_GROWS_DOWNWARD
1097 offset = -args_size;
1102 else if (GET_CODE (PATTERN (insn)) == SET)
1103 offset = stack_adjust_offset (PATTERN (insn));
1104 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1105 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1107 /* There may be stack adjustments inside compound insns. Search
1109 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1110 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1111 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1119 if (cfa.reg == STACK_POINTER_REGNUM)
1120 cfa.offset += offset;
1122 #ifndef STACK_GROWS_DOWNWARD
1126 args_size += offset;
1130 label = dwarf2out_cfi_label ();
1131 def_cfa_1 (label, &cfa);
1132 if (flag_asynchronous_unwind_tables)
1133 dwarf2out_args_size (label, args_size);
1138 /* We delay emitting a register save until either (a) we reach the end
1139 of the prologue or (b) the register is clobbered. This clusters
1140 register saves so that there are fewer pc advances. */
1142 struct queued_reg_save GTY(())
1144 struct queued_reg_save *next;
1146 HOST_WIDE_INT cfa_offset;
1150 static GTY(()) struct queued_reg_save *queued_reg_saves;
1152 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1153 struct reg_saved_in_data GTY(()) {
1158 /* A list of registers saved in other registers.
1159 The list intentionally has a small maximum capacity of 4; if your
1160 port needs more than that, you might consider implementing a
1161 more efficient data structure. */
1162 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1163 static GTY(()) size_t num_regs_saved_in_regs;
1165 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1166 static const char *last_reg_save_label;
1168 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1169 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1172 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1174 struct queued_reg_save *q;
1176 /* Duplicates waste space, but it's also necessary to remove them
1177 for correctness, since the queue gets output in reverse
1179 for (q = queued_reg_saves; q != NULL; q = q->next)
1180 if (REGNO (q->reg) == REGNO (reg))
1185 q = ggc_alloc (sizeof (*q));
1186 q->next = queued_reg_saves;
1187 queued_reg_saves = q;
1191 q->cfa_offset = offset;
1192 q->saved_reg = sreg;
1194 last_reg_save_label = label;
1197 /* Output all the entries in QUEUED_REG_SAVES. */
1200 flush_queued_reg_saves (void)
1202 struct queued_reg_save *q;
1204 for (q = queued_reg_saves; q; q = q->next)
1207 unsigned int reg, sreg;
1209 for (i = 0; i < num_regs_saved_in_regs; i++)
1210 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1212 if (q->saved_reg && i == num_regs_saved_in_regs)
1214 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1215 num_regs_saved_in_regs++;
1217 if (i != num_regs_saved_in_regs)
1219 regs_saved_in_regs[i].orig_reg = q->reg;
1220 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1223 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1225 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1227 sreg = INVALID_REGNUM;
1228 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1231 queued_reg_saves = NULL;
1232 last_reg_save_label = NULL;
1235 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1236 location for? Or, does it clobber a register which we've previously
1237 said that some other register is saved in, and for which we now
1238 have a new location for? */
1241 clobbers_queued_reg_save (rtx insn)
1243 struct queued_reg_save *q;
1245 for (q = queued_reg_saves; q; q = q->next)
1248 if (modified_in_p (q->reg, insn))
1250 for (i = 0; i < num_regs_saved_in_regs; i++)
1251 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1252 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1259 /* What register, if any, is currently saved in REG? */
1262 reg_saved_in (rtx reg)
1264 unsigned int regn = REGNO (reg);
1266 struct queued_reg_save *q;
1268 for (q = queued_reg_saves; q; q = q->next)
1269 if (q->saved_reg && regn == REGNO (q->saved_reg))
1272 for (i = 0; i < num_regs_saved_in_regs; i++)
1273 if (regs_saved_in_regs[i].saved_in_reg
1274 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1275 return regs_saved_in_regs[i].orig_reg;
1281 /* A temporary register holding an integral value used in adjusting SP
1282 or setting up the store_reg. The "offset" field holds the integer
1283 value, not an offset. */
1284 static dw_cfa_location cfa_temp;
1286 /* Record call frame debugging information for an expression EXPR,
1287 which either sets SP or FP (adjusting how we calculate the frame
1288 address) or saves a register to the stack or another register.
1289 LABEL indicates the address of EXPR.
1291 This function encodes a state machine mapping rtxes to actions on
1292 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1293 users need not read the source code.
1295 The High-Level Picture
1297 Changes in the register we use to calculate the CFA: Currently we
1298 assume that if you copy the CFA register into another register, we
1299 should take the other one as the new CFA register; this seems to
1300 work pretty well. If it's wrong for some target, it's simple
1301 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1303 Changes in the register we use for saving registers to the stack:
1304 This is usually SP, but not always. Again, we deduce that if you
1305 copy SP into another register (and SP is not the CFA register),
1306 then the new register is the one we will be using for register
1307 saves. This also seems to work.
1309 Register saves: There's not much guesswork about this one; if
1310 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1311 register save, and the register used to calculate the destination
1312 had better be the one we think we're using for this purpose.
1313 It's also assumed that a copy from a call-saved register to another
1314 register is saving that register if RTX_FRAME_RELATED_P is set on
1315 that instruction. If the copy is from a call-saved register to
1316 the *same* register, that means that the register is now the same
1317 value as in the caller.
1319 Except: If the register being saved is the CFA register, and the
1320 offset is nonzero, we are saving the CFA, so we assume we have to
1321 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1322 the intent is to save the value of SP from the previous frame.
1324 In addition, if a register has previously been saved to a different
1327 Invariants / Summaries of Rules
1329 cfa current rule for calculating the CFA. It usually
1330 consists of a register and an offset.
1331 cfa_store register used by prologue code to save things to the stack
1332 cfa_store.offset is the offset from the value of
1333 cfa_store.reg to the actual CFA
1334 cfa_temp register holding an integral value. cfa_temp.offset
1335 stores the value, which will be used to adjust the
1336 stack pointer. cfa_temp is also used like cfa_store,
1337 to track stores to the stack via fp or a temp reg.
1339 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1340 with cfa.reg as the first operand changes the cfa.reg and its
1341 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1344 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1345 expression yielding a constant. This sets cfa_temp.reg
1346 and cfa_temp.offset.
1348 Rule 5: Create a new register cfa_store used to save items to the
1351 Rules 10-14: Save a register to the stack. Define offset as the
1352 difference of the original location and cfa_store's
1353 location (or cfa_temp's location if cfa_temp is used).
1357 "{a,b}" indicates a choice of a xor b.
1358 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1361 (set <reg1> <reg2>:cfa.reg)
1362 effects: cfa.reg = <reg1>
1363 cfa.offset unchanged
1364 cfa_temp.reg = <reg1>
1365 cfa_temp.offset = cfa.offset
1368 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1369 {<const_int>,<reg>:cfa_temp.reg}))
1370 effects: cfa.reg = sp if fp used
1371 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1372 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1373 if cfa_store.reg==sp
1376 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1377 effects: cfa.reg = fp
1378 cfa_offset += +/- <const_int>
1381 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1382 constraints: <reg1> != fp
1384 effects: cfa.reg = <reg1>
1385 cfa_temp.reg = <reg1>
1386 cfa_temp.offset = cfa.offset
1389 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1390 constraints: <reg1> != fp
1392 effects: cfa_store.reg = <reg1>
1393 cfa_store.offset = cfa.offset - cfa_temp.offset
1396 (set <reg> <const_int>)
1397 effects: cfa_temp.reg = <reg>
1398 cfa_temp.offset = <const_int>
1401 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1402 effects: cfa_temp.reg = <reg1>
1403 cfa_temp.offset |= <const_int>
1406 (set <reg> (high <exp>))
1410 (set <reg> (lo_sum <exp> <const_int>))
1411 effects: cfa_temp.reg = <reg>
1412 cfa_temp.offset = <const_int>
1415 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1416 effects: cfa_store.offset -= <const_int>
1417 cfa.offset = cfa_store.offset if cfa.reg == sp
1419 cfa.base_offset = -cfa_store.offset
1422 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1423 effects: cfa_store.offset += -/+ mode_size(mem)
1424 cfa.offset = cfa_store.offset if cfa.reg == sp
1426 cfa.base_offset = -cfa_store.offset
1429 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1432 effects: cfa.reg = <reg1>
1433 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1436 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1437 effects: cfa.reg = <reg1>
1438 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1441 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1442 effects: cfa.reg = <reg1>
1443 cfa.base_offset = -cfa_temp.offset
1444 cfa_temp.offset -= mode_size(mem)
1447 Â (set <reg> {unspec, unspec_volatile})
1448 Â effects: target-dependent */
1451 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1454 HOST_WIDE_INT offset;
1456 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1457 the PARALLEL independently. The first element is always processed if
1458 it is a SET. This is for backward compatibility. Other elements
1459 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1460 flag is set in them. */
1461 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1464 int limit = XVECLEN (expr, 0);
1466 for (par_index = 0; par_index < limit; par_index++)
1467 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1468 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1470 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1475 gcc_assert (GET_CODE (expr) == SET);
1477 src = SET_SRC (expr);
1478 dest = SET_DEST (expr);
1480 if (GET_CODE (src) == REG)
1482 rtx rsi = reg_saved_in (src);
1487 switch (GET_CODE (dest))
1490 switch (GET_CODE (src))
1492 /* Setting FP from SP. */
1494 if (cfa.reg == (unsigned) REGNO (src))
1497 /* Update the CFA rule wrt SP or FP. Make sure src is
1498 relative to the current CFA register.
1500 We used to require that dest be either SP or FP, but the
1501 ARM copies SP to a temporary register, and from there to
1502 FP. So we just rely on the backends to only set
1503 RTX_FRAME_RELATED_P on appropriate insns. */
1504 cfa.reg = REGNO (dest);
1505 cfa_temp.reg = cfa.reg;
1506 cfa_temp.offset = cfa.offset;
1510 /* Saving a register in a register. */
1511 gcc_assert (call_used_regs [REGNO (dest)]
1512 && (!fixed_regs [REGNO (dest)]
1513 /* For the SPARC and its register window. */
1514 || DWARF_FRAME_REGNUM (REGNO (src))
1515 == DWARF_FRAME_RETURN_COLUMN));
1516 queue_reg_save (label, src, dest, 0);
1523 if (dest == stack_pointer_rtx)
1527 switch (GET_CODE (XEXP (src, 1)))
1530 offset = INTVAL (XEXP (src, 1));
1533 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1535 offset = cfa_temp.offset;
1541 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1543 /* Restoring SP from FP in the epilogue. */
1544 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1545 cfa.reg = STACK_POINTER_REGNUM;
1547 else if (GET_CODE (src) == LO_SUM)
1548 /* Assume we've set the source reg of the LO_SUM from sp. */
1551 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1553 if (GET_CODE (src) != MINUS)
1555 if (cfa.reg == STACK_POINTER_REGNUM)
1556 cfa.offset += offset;
1557 if (cfa_store.reg == STACK_POINTER_REGNUM)
1558 cfa_store.offset += offset;
1560 else if (dest == hard_frame_pointer_rtx)
1563 /* Either setting the FP from an offset of the SP,
1564 or adjusting the FP */
1565 gcc_assert (frame_pointer_needed);
1567 gcc_assert (REG_P (XEXP (src, 0))
1568 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1569 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1570 offset = INTVAL (XEXP (src, 1));
1571 if (GET_CODE (src) != MINUS)
1573 cfa.offset += offset;
1574 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1578 gcc_assert (GET_CODE (src) != MINUS);
1581 if (REG_P (XEXP (src, 0))
1582 && REGNO (XEXP (src, 0)) == cfa.reg
1583 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1585 /* Setting a temporary CFA register that will be copied
1586 into the FP later on. */
1587 offset = - INTVAL (XEXP (src, 1));
1588 cfa.offset += offset;
1589 cfa.reg = REGNO (dest);
1590 /* Or used to save regs to the stack. */
1591 cfa_temp.reg = cfa.reg;
1592 cfa_temp.offset = cfa.offset;
1596 else if (REG_P (XEXP (src, 0))
1597 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1598 && XEXP (src, 1) == stack_pointer_rtx)
1600 /* Setting a scratch register that we will use instead
1601 of SP for saving registers to the stack. */
1602 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1603 cfa_store.reg = REGNO (dest);
1604 cfa_store.offset = cfa.offset - cfa_temp.offset;
1608 else if (GET_CODE (src) == LO_SUM
1609 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1611 cfa_temp.reg = REGNO (dest);
1612 cfa_temp.offset = INTVAL (XEXP (src, 1));
1621 cfa_temp.reg = REGNO (dest);
1622 cfa_temp.offset = INTVAL (src);
1627 gcc_assert (REG_P (XEXP (src, 0))
1628 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1629 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1631 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1632 cfa_temp.reg = REGNO (dest);
1633 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1636 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1637 which will fill in all of the bits. */
1644 case UNSPEC_VOLATILE:
1645 gcc_assert (targetm.dwarf_handle_frame_unspec);
1646 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
1653 def_cfa_1 (label, &cfa);
1657 gcc_assert (REG_P (src));
1659 /* Saving a register to the stack. Make sure dest is relative to the
1661 switch (GET_CODE (XEXP (dest, 0)))
1666 /* We can't handle variable size modifications. */
1667 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1669 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1671 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1672 && cfa_store.reg == STACK_POINTER_REGNUM);
1674 cfa_store.offset += offset;
1675 if (cfa.reg == STACK_POINTER_REGNUM)
1676 cfa.offset = cfa_store.offset;
1678 offset = -cfa_store.offset;
1684 offset = GET_MODE_SIZE (GET_MODE (dest));
1685 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1688 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1689 && cfa_store.reg == STACK_POINTER_REGNUM);
1691 cfa_store.offset += offset;
1692 if (cfa.reg == STACK_POINTER_REGNUM)
1693 cfa.offset = cfa_store.offset;
1695 offset = -cfa_store.offset;
1699 /* With an offset. */
1706 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT);
1707 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1708 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1711 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1713 if (cfa_store.reg == (unsigned) regno)
1714 offset -= cfa_store.offset;
1717 gcc_assert (cfa_temp.reg == (unsigned) regno);
1718 offset -= cfa_temp.offset;
1724 /* Without an offset. */
1727 int regno = REGNO (XEXP (dest, 0));
1729 if (cfa_store.reg == (unsigned) regno)
1730 offset = -cfa_store.offset;
1733 gcc_assert (cfa_temp.reg == (unsigned) regno);
1734 offset = -cfa_temp.offset;
1741 gcc_assert (cfa_temp.reg
1742 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1743 offset = -cfa_temp.offset;
1744 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1751 if (REGNO (src) != STACK_POINTER_REGNUM
1752 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1753 && (unsigned) REGNO (src) == cfa.reg)
1755 /* We're storing the current CFA reg into the stack. */
1757 if (cfa.offset == 0)
1759 /* If the source register is exactly the CFA, assume
1760 we're saving SP like any other register; this happens
1762 def_cfa_1 (label, &cfa);
1763 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1768 /* Otherwise, we'll need to look in the stack to
1769 calculate the CFA. */
1770 rtx x = XEXP (dest, 0);
1774 gcc_assert (REG_P (x));
1776 cfa.reg = REGNO (x);
1777 cfa.base_offset = offset;
1779 def_cfa_1 (label, &cfa);
1784 def_cfa_1 (label, &cfa);
1785 queue_reg_save (label, src, NULL_RTX, offset);
1793 /* Record call frame debugging information for INSN, which either
1794 sets SP or FP (adjusting how we calculate the frame address) or saves a
1795 register to the stack. If INSN is NULL_RTX, initialize our state.
1797 If AFTER_P is false, we're being called before the insn is emitted,
1798 otherwise after. Call instructions get invoked twice. */
1801 dwarf2out_frame_debug (rtx insn, bool after_p)
1806 if (insn == NULL_RTX)
1810 /* Flush any queued register saves. */
1811 flush_queued_reg_saves ();
1813 /* Set up state for generating call frame debug info. */
1816 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1818 cfa.reg = STACK_POINTER_REGNUM;
1821 cfa_temp.offset = 0;
1823 for (i = 0; i < num_regs_saved_in_regs; i++)
1825 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1826 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1828 num_regs_saved_in_regs = 0;
1832 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1833 flush_queued_reg_saves ();
1835 if (! RTX_FRAME_RELATED_P (insn))
1837 if (!ACCUMULATE_OUTGOING_ARGS)
1838 dwarf2out_stack_adjust (insn, after_p);
1842 label = dwarf2out_cfi_label ();
1843 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1845 insn = XEXP (src, 0);
1847 insn = PATTERN (insn);
1849 dwarf2out_frame_debug_expr (insn, label);
1854 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1855 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1856 (enum dwarf_call_frame_info cfi);
1858 static enum dw_cfi_oprnd_type
1859 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1864 case DW_CFA_GNU_window_save:
1865 return dw_cfi_oprnd_unused;
1867 case DW_CFA_set_loc:
1868 case DW_CFA_advance_loc1:
1869 case DW_CFA_advance_loc2:
1870 case DW_CFA_advance_loc4:
1871 case DW_CFA_MIPS_advance_loc8:
1872 return dw_cfi_oprnd_addr;
1875 case DW_CFA_offset_extended:
1876 case DW_CFA_def_cfa:
1877 case DW_CFA_offset_extended_sf:
1878 case DW_CFA_def_cfa_sf:
1879 case DW_CFA_restore_extended:
1880 case DW_CFA_undefined:
1881 case DW_CFA_same_value:
1882 case DW_CFA_def_cfa_register:
1883 case DW_CFA_register:
1884 return dw_cfi_oprnd_reg_num;
1886 case DW_CFA_def_cfa_offset:
1887 case DW_CFA_GNU_args_size:
1888 case DW_CFA_def_cfa_offset_sf:
1889 return dw_cfi_oprnd_offset;
1891 case DW_CFA_def_cfa_expression:
1892 case DW_CFA_expression:
1893 return dw_cfi_oprnd_loc;
1900 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1901 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1902 (enum dwarf_call_frame_info cfi);
1904 static enum dw_cfi_oprnd_type
1905 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1909 case DW_CFA_def_cfa:
1910 case DW_CFA_def_cfa_sf:
1912 case DW_CFA_offset_extended_sf:
1913 case DW_CFA_offset_extended:
1914 return dw_cfi_oprnd_offset;
1916 case DW_CFA_register:
1917 return dw_cfi_oprnd_reg_num;
1920 return dw_cfi_oprnd_unused;
1924 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1926 /* Map register numbers held in the call frame info that gcc has
1927 collected using DWARF_FRAME_REGNUM to those that should be output in
1928 .debug_frame and .eh_frame. */
1929 #ifndef DWARF2_FRAME_REG_OUT
1930 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
1933 /* Output a Call Frame Information opcode and its operand(s). */
1936 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
1939 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1940 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1941 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1942 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
1943 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1944 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1946 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1947 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
1948 "DW_CFA_offset, column 0x%lx", r);
1949 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1951 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1953 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1954 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
1955 "DW_CFA_restore, column 0x%lx", r);
1959 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1960 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1962 switch (cfi->dw_cfi_opc)
1964 case DW_CFA_set_loc:
1966 dw2_asm_output_encoded_addr_rtx (
1967 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1968 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1971 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1972 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1975 case DW_CFA_advance_loc1:
1976 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1977 fde->dw_fde_current_label, NULL);
1978 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1981 case DW_CFA_advance_loc2:
1982 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1983 fde->dw_fde_current_label, NULL);
1984 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1987 case DW_CFA_advance_loc4:
1988 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1989 fde->dw_fde_current_label, NULL);
1990 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1993 case DW_CFA_MIPS_advance_loc8:
1994 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1995 fde->dw_fde_current_label, NULL);
1996 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1999 case DW_CFA_offset_extended:
2000 case DW_CFA_def_cfa:
2001 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2002 dw2_asm_output_data_uleb128 (r, NULL);
2003 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2006 case DW_CFA_offset_extended_sf:
2007 case DW_CFA_def_cfa_sf:
2008 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2009 dw2_asm_output_data_uleb128 (r, NULL);
2010 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2013 case DW_CFA_restore_extended:
2014 case DW_CFA_undefined:
2015 case DW_CFA_same_value:
2016 case DW_CFA_def_cfa_register:
2017 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2018 dw2_asm_output_data_uleb128 (r, NULL);
2021 case DW_CFA_register:
2022 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2023 dw2_asm_output_data_uleb128 (r, NULL);
2024 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2025 dw2_asm_output_data_uleb128 (r, NULL);
2028 case DW_CFA_def_cfa_offset:
2029 case DW_CFA_GNU_args_size:
2030 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2033 case DW_CFA_def_cfa_offset_sf:
2034 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2037 case DW_CFA_GNU_window_save:
2040 case DW_CFA_def_cfa_expression:
2041 case DW_CFA_expression:
2042 output_cfa_loc (cfi);
2045 case DW_CFA_GNU_negative_offset_extended:
2046 /* Obsoleted by DW_CFA_offset_extended_sf. */
2055 /* Output the call frame information used to record information
2056 that relates to calculating the frame pointer, and records the
2057 location of saved registers. */
2060 output_call_frame_info (int for_eh)
2065 char l1[20], l2[20], section_start_label[20];
2066 bool any_lsda_needed = false;
2067 char augmentation[6];
2068 int augmentation_size;
2069 int fde_encoding = DW_EH_PE_absptr;
2070 int per_encoding = DW_EH_PE_absptr;
2071 int lsda_encoding = DW_EH_PE_absptr;
2073 /* Don't emit a CIE if there won't be any FDEs. */
2074 if (fde_table_in_use == 0)
2077 /* If we make FDEs linkonce, we may have to emit an empty label for
2078 an FDE that wouldn't otherwise be emitted. We want to avoid
2079 having an FDE kept around when the function it refers to is
2080 discarded. Example where this matters: a primary function
2081 template in C++ requires EH information, but an explicit
2082 specialization doesn't. */
2083 if (TARGET_USES_WEAK_UNWIND_INFO
2084 && ! flag_asynchronous_unwind_tables
2086 for (i = 0; i < fde_table_in_use; i++)
2087 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2088 && !fde_table[i].uses_eh_lsda
2089 && ! DECL_WEAK (fde_table[i].decl))
2090 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2091 for_eh, /* empty */ 1);
2093 /* If we don't have any functions we'll want to unwind out of, don't
2094 emit any EH unwind information. Note that if exceptions aren't
2095 enabled, we won't have collected nothrow information, and if we
2096 asked for asynchronous tables, we always want this info. */
2099 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2101 for (i = 0; i < fde_table_in_use; i++)
2102 if (fde_table[i].uses_eh_lsda)
2103 any_eh_needed = any_lsda_needed = true;
2104 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2105 any_eh_needed = true;
2106 else if (! fde_table[i].nothrow
2107 && ! fde_table[i].all_throwers_are_sibcalls)
2108 any_eh_needed = true;
2110 if (! any_eh_needed)
2114 /* We're going to be generating comments, so turn on app. */
2119 targetm.asm_out.eh_frame_section ();
2121 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
2123 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2124 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2126 /* Output the CIE. */
2127 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2128 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2129 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2130 "Length of Common Information Entry");
2131 ASM_OUTPUT_LABEL (asm_out_file, l1);
2133 /* Now that the CIE pointer is PC-relative for EH,
2134 use 0 to identify the CIE. */
2135 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2136 (for_eh ? 0 : DW_CIE_ID),
2137 "CIE Identifier Tag");
2139 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2141 augmentation[0] = 0;
2142 augmentation_size = 0;
2148 z Indicates that a uleb128 is present to size the
2149 augmentation section.
2150 L Indicates the encoding (and thus presence) of
2151 an LSDA pointer in the FDE augmentation.
2152 R Indicates a non-default pointer encoding for
2154 P Indicates the presence of an encoding + language
2155 personality routine in the CIE augmentation. */
2157 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2158 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2159 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2161 p = augmentation + 1;
2162 if (eh_personality_libfunc)
2165 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2167 if (any_lsda_needed)
2170 augmentation_size += 1;
2172 if (fde_encoding != DW_EH_PE_absptr)
2175 augmentation_size += 1;
2177 if (p > augmentation + 1)
2179 augmentation[0] = 'z';
2183 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2184 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2186 int offset = ( 4 /* Length */
2188 + 1 /* CIE version */
2189 + strlen (augmentation) + 1 /* Augmentation */
2190 + size_of_uleb128 (1) /* Code alignment */
2191 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2193 + 1 /* Augmentation size */
2194 + 1 /* Personality encoding */ );
2195 int pad = -offset & (PTR_SIZE - 1);
2197 augmentation_size += pad;
2199 /* Augmentations should be small, so there's scarce need to
2200 iterate for a solution. Die if we exceed one uleb128 byte. */
2201 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2205 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2206 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2207 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2208 "CIE Data Alignment Factor");
2210 if (DW_CIE_VERSION == 1)
2211 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
2213 dw2_asm_output_data_uleb128 (DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
2215 if (augmentation[0])
2217 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2218 if (eh_personality_libfunc)
2220 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2221 eh_data_format_name (per_encoding));
2222 dw2_asm_output_encoded_addr_rtx (per_encoding,
2223 eh_personality_libfunc, NULL);
2226 if (any_lsda_needed)
2227 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2228 eh_data_format_name (lsda_encoding));
2230 if (fde_encoding != DW_EH_PE_absptr)
2231 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2232 eh_data_format_name (fde_encoding));
2235 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2236 output_cfi (cfi, NULL, for_eh);
2238 /* Pad the CIE out to an address sized boundary. */
2239 ASM_OUTPUT_ALIGN (asm_out_file,
2240 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2241 ASM_OUTPUT_LABEL (asm_out_file, l2);
2243 /* Loop through all of the FDE's. */
2244 for (i = 0; i < fde_table_in_use; i++)
2246 fde = &fde_table[i];
2248 /* Don't emit EH unwind info for leaf functions that don't need it. */
2249 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2250 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2251 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2252 && !fde->uses_eh_lsda)
2255 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2256 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2257 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2258 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2259 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2261 ASM_OUTPUT_LABEL (asm_out_file, l1);
2264 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2266 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2271 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2272 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2273 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2275 "FDE initial location");
2276 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2277 fde->dw_fde_end, fde->dw_fde_begin,
2278 "FDE address range");
2282 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2283 "FDE initial location");
2284 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2285 fde->dw_fde_end, fde->dw_fde_begin,
2286 "FDE address range");
2289 if (augmentation[0])
2291 if (any_lsda_needed)
2293 int size = size_of_encoded_value (lsda_encoding);
2295 if (lsda_encoding == DW_EH_PE_aligned)
2297 int offset = ( 4 /* Length */
2298 + 4 /* CIE offset */
2299 + 2 * size_of_encoded_value (fde_encoding)
2300 + 1 /* Augmentation size */ );
2301 int pad = -offset & (PTR_SIZE - 1);
2304 gcc_assert (size_of_uleb128 (size) == 1);
2307 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2309 if (fde->uses_eh_lsda)
2311 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2312 fde->funcdef_number);
2313 dw2_asm_output_encoded_addr_rtx (
2314 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2315 "Language Specific Data Area");
2319 if (lsda_encoding == DW_EH_PE_aligned)
2320 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2322 (size_of_encoded_value (lsda_encoding), 0,
2323 "Language Specific Data Area (none)");
2327 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2330 /* Loop through the Call Frame Instructions associated with
2332 fde->dw_fde_current_label = fde->dw_fde_begin;
2333 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2334 output_cfi (cfi, fde, for_eh);
2336 /* Pad the FDE out to an address sized boundary. */
2337 ASM_OUTPUT_ALIGN (asm_out_file,
2338 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2339 ASM_OUTPUT_LABEL (asm_out_file, l2);
2342 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2343 dw2_asm_output_data (4, 0, "End of Table");
2344 #ifdef MIPS_DEBUGGING_INFO
2345 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2346 get a value of 0. Putting .align 0 after the label fixes it. */
2347 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2350 /* Turn off app to make assembly quicker. */
2355 /* Output a marker (i.e. a label) for the beginning of a function, before
2359 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2360 const char *file ATTRIBUTE_UNUSED)
2362 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2366 current_function_func_begin_label = NULL;
2368 #ifdef TARGET_UNWIND_INFO
2369 /* ??? current_function_func_begin_label is also used by except.c
2370 for call-site information. We must emit this label if it might
2372 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2373 && ! dwarf2out_do_frame ())
2376 if (! dwarf2out_do_frame ())
2380 function_section (current_function_decl);
2381 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2382 current_function_funcdef_no);
2383 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2384 current_function_funcdef_no);
2385 dup_label = xstrdup (label);
2386 current_function_func_begin_label = dup_label;
2388 #ifdef TARGET_UNWIND_INFO
2389 /* We can elide the fde allocation if we're not emitting debug info. */
2390 if (! dwarf2out_do_frame ())
2394 /* Expand the fde table if necessary. */
2395 if (fde_table_in_use == fde_table_allocated)
2397 fde_table_allocated += FDE_TABLE_INCREMENT;
2398 fde_table = ggc_realloc (fde_table,
2399 fde_table_allocated * sizeof (dw_fde_node));
2400 memset (fde_table + fde_table_in_use, 0,
2401 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2404 /* Record the FDE associated with this function. */
2405 current_funcdef_fde = fde_table_in_use;
2407 /* Add the new FDE at the end of the fde_table. */
2408 fde = &fde_table[fde_table_in_use++];
2409 fde->decl = current_function_decl;
2410 fde->dw_fde_begin = dup_label;
2411 fde->dw_fde_current_label = NULL;
2412 fde->dw_fde_end = NULL;
2413 fde->dw_fde_cfi = NULL;
2414 fde->funcdef_number = current_function_funcdef_no;
2415 fde->nothrow = TREE_NOTHROW (current_function_decl);
2416 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2417 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2419 args_size = old_args_size = 0;
2421 /* We only want to output line number information for the genuine dwarf2
2422 prologue case, not the eh frame case. */
2423 #ifdef DWARF2_DEBUGGING_INFO
2425 dwarf2out_source_line (line, file);
2429 /* Output a marker (i.e. a label) for the absolute end of the generated code
2430 for a function definition. This gets called *after* the epilogue code has
2434 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2435 const char *file ATTRIBUTE_UNUSED)
2438 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2440 /* Output a label to mark the endpoint of the code generated for this
2442 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2443 current_function_funcdef_no);
2444 ASM_OUTPUT_LABEL (asm_out_file, label);
2445 fde = &fde_table[fde_table_in_use - 1];
2446 fde->dw_fde_end = xstrdup (label);
2450 dwarf2out_frame_init (void)
2452 /* Allocate the initial hunk of the fde_table. */
2453 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2454 fde_table_allocated = FDE_TABLE_INCREMENT;
2455 fde_table_in_use = 0;
2457 /* Generate the CFA instructions common to all FDE's. Do it now for the
2458 sake of lookup_cfa. */
2460 #ifdef DWARF2_UNWIND_INFO
2461 /* On entry, the Canonical Frame Address is at SP. */
2462 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2463 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2468 dwarf2out_frame_finish (void)
2470 /* Output call frame information. */
2471 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2472 output_call_frame_info (0);
2474 #ifndef TARGET_UNWIND_INFO
2475 /* Output another copy for the unwinder. */
2476 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2477 output_call_frame_info (1);
2482 /* And now, the subset of the debugging information support code necessary
2483 for emitting location expressions. */
2485 /* We need some way to distinguish DW_OP_addr with a direct symbol
2486 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2487 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2490 typedef struct dw_val_struct *dw_val_ref;
2491 typedef struct die_struct *dw_die_ref;
2492 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2493 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2495 /* Each DIE may have a series of attribute/value pairs. Values
2496 can take on several forms. The forms that are used in this
2497 implementation are listed below. */
2502 dw_val_class_offset,
2504 dw_val_class_loc_list,
2505 dw_val_class_range_list,
2507 dw_val_class_unsigned_const,
2508 dw_val_class_long_long,
2511 dw_val_class_die_ref,
2512 dw_val_class_fde_ref,
2513 dw_val_class_lbl_id,
2514 dw_val_class_lbl_offset,
2518 /* Describe a double word constant value. */
2519 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2521 typedef struct dw_long_long_struct GTY(())
2528 /* Describe a floating point constant value, or a vector constant value. */
2530 typedef struct dw_vec_struct GTY(())
2532 unsigned char * GTY((length ("%h.length"))) array;
2538 /* The dw_val_node describes an attribute's value, as it is
2539 represented internally. */
2541 typedef struct dw_val_struct GTY(())
2543 enum dw_val_class val_class;
2544 union dw_val_struct_union
2546 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2547 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2548 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2549 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2550 HOST_WIDE_INT GTY ((default)) val_int;
2551 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2552 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2553 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2554 struct dw_val_die_union
2558 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2559 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2560 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2561 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2562 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2564 GTY ((desc ("%1.val_class"))) v;
2568 /* Locations in memory are described using a sequence of stack machine
2571 typedef struct dw_loc_descr_struct GTY(())
2573 dw_loc_descr_ref dw_loc_next;
2574 enum dwarf_location_atom dw_loc_opc;
2575 dw_val_node dw_loc_oprnd1;
2576 dw_val_node dw_loc_oprnd2;
2581 /* Location lists are ranges + location descriptions for that range,
2582 so you can track variables that are in different places over
2583 their entire life. */
2584 typedef struct dw_loc_list_struct GTY(())
2586 dw_loc_list_ref dw_loc_next;
2587 const char *begin; /* Label for begin address of range */
2588 const char *end; /* Label for end address of range */
2589 char *ll_symbol; /* Label for beginning of location list.
2590 Only on head of list */
2591 const char *section; /* Section this loclist is relative to */
2592 dw_loc_descr_ref expr;
2595 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2597 static const char *dwarf_stack_op_name (unsigned);
2598 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2599 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2600 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2601 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2602 static unsigned long size_of_locs (dw_loc_descr_ref);
2603 static void output_loc_operands (dw_loc_descr_ref);
2604 static void output_loc_sequence (dw_loc_descr_ref);
2606 /* Convert a DWARF stack opcode into its string name. */
2609 dwarf_stack_op_name (unsigned int op)
2614 case INTERNAL_DW_OP_tls_addr:
2615 return "DW_OP_addr";
2617 return "DW_OP_deref";
2619 return "DW_OP_const1u";
2621 return "DW_OP_const1s";
2623 return "DW_OP_const2u";
2625 return "DW_OP_const2s";
2627 return "DW_OP_const4u";
2629 return "DW_OP_const4s";
2631 return "DW_OP_const8u";
2633 return "DW_OP_const8s";
2635 return "DW_OP_constu";
2637 return "DW_OP_consts";
2641 return "DW_OP_drop";
2643 return "DW_OP_over";
2645 return "DW_OP_pick";
2647 return "DW_OP_swap";
2651 return "DW_OP_xderef";
2659 return "DW_OP_minus";
2671 return "DW_OP_plus";
2672 case DW_OP_plus_uconst:
2673 return "DW_OP_plus_uconst";
2679 return "DW_OP_shra";
2697 return "DW_OP_skip";
2699 return "DW_OP_lit0";
2701 return "DW_OP_lit1";
2703 return "DW_OP_lit2";
2705 return "DW_OP_lit3";
2707 return "DW_OP_lit4";
2709 return "DW_OP_lit5";
2711 return "DW_OP_lit6";
2713 return "DW_OP_lit7";
2715 return "DW_OP_lit8";
2717 return "DW_OP_lit9";
2719 return "DW_OP_lit10";
2721 return "DW_OP_lit11";
2723 return "DW_OP_lit12";
2725 return "DW_OP_lit13";
2727 return "DW_OP_lit14";
2729 return "DW_OP_lit15";
2731 return "DW_OP_lit16";
2733 return "DW_OP_lit17";
2735 return "DW_OP_lit18";
2737 return "DW_OP_lit19";
2739 return "DW_OP_lit20";
2741 return "DW_OP_lit21";
2743 return "DW_OP_lit22";
2745 return "DW_OP_lit23";
2747 return "DW_OP_lit24";
2749 return "DW_OP_lit25";
2751 return "DW_OP_lit26";
2753 return "DW_OP_lit27";
2755 return "DW_OP_lit28";
2757 return "DW_OP_lit29";
2759 return "DW_OP_lit30";
2761 return "DW_OP_lit31";
2763 return "DW_OP_reg0";
2765 return "DW_OP_reg1";
2767 return "DW_OP_reg2";
2769 return "DW_OP_reg3";
2771 return "DW_OP_reg4";
2773 return "DW_OP_reg5";
2775 return "DW_OP_reg6";
2777 return "DW_OP_reg7";
2779 return "DW_OP_reg8";
2781 return "DW_OP_reg9";
2783 return "DW_OP_reg10";
2785 return "DW_OP_reg11";
2787 return "DW_OP_reg12";
2789 return "DW_OP_reg13";
2791 return "DW_OP_reg14";
2793 return "DW_OP_reg15";
2795 return "DW_OP_reg16";
2797 return "DW_OP_reg17";
2799 return "DW_OP_reg18";
2801 return "DW_OP_reg19";
2803 return "DW_OP_reg20";
2805 return "DW_OP_reg21";
2807 return "DW_OP_reg22";
2809 return "DW_OP_reg23";
2811 return "DW_OP_reg24";
2813 return "DW_OP_reg25";
2815 return "DW_OP_reg26";
2817 return "DW_OP_reg27";
2819 return "DW_OP_reg28";
2821 return "DW_OP_reg29";
2823 return "DW_OP_reg30";
2825 return "DW_OP_reg31";
2827 return "DW_OP_breg0";
2829 return "DW_OP_breg1";
2831 return "DW_OP_breg2";
2833 return "DW_OP_breg3";
2835 return "DW_OP_breg4";
2837 return "DW_OP_breg5";
2839 return "DW_OP_breg6";
2841 return "DW_OP_breg7";
2843 return "DW_OP_breg8";
2845 return "DW_OP_breg9";
2847 return "DW_OP_breg10";
2849 return "DW_OP_breg11";
2851 return "DW_OP_breg12";
2853 return "DW_OP_breg13";
2855 return "DW_OP_breg14";
2857 return "DW_OP_breg15";
2859 return "DW_OP_breg16";
2861 return "DW_OP_breg17";
2863 return "DW_OP_breg18";
2865 return "DW_OP_breg19";
2867 return "DW_OP_breg20";
2869 return "DW_OP_breg21";
2871 return "DW_OP_breg22";
2873 return "DW_OP_breg23";
2875 return "DW_OP_breg24";
2877 return "DW_OP_breg25";
2879 return "DW_OP_breg26";
2881 return "DW_OP_breg27";
2883 return "DW_OP_breg28";
2885 return "DW_OP_breg29";
2887 return "DW_OP_breg30";
2889 return "DW_OP_breg31";
2891 return "DW_OP_regx";
2893 return "DW_OP_fbreg";
2895 return "DW_OP_bregx";
2897 return "DW_OP_piece";
2898 case DW_OP_deref_size:
2899 return "DW_OP_deref_size";
2900 case DW_OP_xderef_size:
2901 return "DW_OP_xderef_size";
2904 case DW_OP_push_object_address:
2905 return "DW_OP_push_object_address";
2907 return "DW_OP_call2";
2909 return "DW_OP_call4";
2910 case DW_OP_call_ref:
2911 return "DW_OP_call_ref";
2912 case DW_OP_GNU_push_tls_address:
2913 return "DW_OP_GNU_push_tls_address";
2915 return "OP_<unknown>";
2919 /* Return a pointer to a newly allocated location description. Location
2920 descriptions are simple expression terms that can be strung
2921 together to form more complicated location (address) descriptions. */
2923 static inline dw_loc_descr_ref
2924 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
2925 unsigned HOST_WIDE_INT oprnd2)
2927 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
2929 descr->dw_loc_opc = op;
2930 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2931 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2932 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2933 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2939 /* Add a location description term to a location description expression. */
2942 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
2944 dw_loc_descr_ref *d;
2946 /* Find the end of the chain. */
2947 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2953 /* Return the size of a location descriptor. */
2955 static unsigned long
2956 size_of_loc_descr (dw_loc_descr_ref loc)
2958 unsigned long size = 1;
2960 switch (loc->dw_loc_opc)
2963 case INTERNAL_DW_OP_tls_addr:
2964 size += DWARF2_ADDR_SIZE;
2983 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2986 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2991 case DW_OP_plus_uconst:
2992 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3030 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3033 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3036 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3039 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3040 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3043 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3045 case DW_OP_deref_size:
3046 case DW_OP_xderef_size:
3055 case DW_OP_call_ref:
3056 size += DWARF2_ADDR_SIZE;
3065 /* Return the size of a series of location descriptors. */
3067 static unsigned long
3068 size_of_locs (dw_loc_descr_ref loc)
3072 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
3074 loc->dw_loc_addr = size;
3075 size += size_of_loc_descr (loc);
3081 /* Output location description stack opcode's operands (if any). */
3084 output_loc_operands (dw_loc_descr_ref loc)
3086 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3087 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3089 switch (loc->dw_loc_opc)
3091 #ifdef DWARF2_DEBUGGING_INFO
3093 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3097 dw2_asm_output_data (2, val1->v.val_int, NULL);
3101 dw2_asm_output_data (4, val1->v.val_int, NULL);
3105 gcc_assert (HOST_BITS_PER_LONG >= 64);
3106 dw2_asm_output_data (8, val1->v.val_int, NULL);
3113 gcc_assert (val1->val_class == dw_val_class_loc);
3114 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3116 dw2_asm_output_data (2, offset, NULL);
3129 /* We currently don't make any attempt to make sure these are
3130 aligned properly like we do for the main unwind info, so
3131 don't support emitting things larger than a byte if we're
3132 only doing unwinding. */
3137 dw2_asm_output_data (1, val1->v.val_int, NULL);
3140 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3143 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3146 dw2_asm_output_data (1, val1->v.val_int, NULL);
3148 case DW_OP_plus_uconst:
3149 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3183 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3186 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3189 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3192 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3193 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3196 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3198 case DW_OP_deref_size:
3199 case DW_OP_xderef_size:
3200 dw2_asm_output_data (1, val1->v.val_int, NULL);
3203 case INTERNAL_DW_OP_tls_addr:
3204 #ifdef ASM_OUTPUT_DWARF_DTPREL
3205 ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE,
3207 fputc ('\n', asm_out_file);
3214 /* Other codes have no operands. */
3219 /* Output a sequence of location operations. */
3222 output_loc_sequence (dw_loc_descr_ref loc)
3224 for (; loc != NULL; loc = loc->dw_loc_next)
3226 /* Output the opcode. */
3227 dw2_asm_output_data (1, loc->dw_loc_opc,
3228 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3230 /* Output the operand(s) (if any). */
3231 output_loc_operands (loc);
3235 /* This routine will generate the correct assembly data for a location
3236 description based on a cfi entry with a complex address. */
3239 output_cfa_loc (dw_cfi_ref cfi)
3241 dw_loc_descr_ref loc;
3244 /* Output the size of the block. */
3245 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3246 size = size_of_locs (loc);
3247 dw2_asm_output_data_uleb128 (size, NULL);
3249 /* Now output the operations themselves. */
3250 output_loc_sequence (loc);
3253 /* This function builds a dwarf location descriptor sequence from
3254 a dw_cfa_location. */
3256 static struct dw_loc_descr_struct *
3257 build_cfa_loc (dw_cfa_location *cfa)
3259 struct dw_loc_descr_struct *head, *tmp;
3261 gcc_assert (cfa->indirect);
3263 if (cfa->base_offset)
3266 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3268 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3270 else if (cfa->reg <= 31)
3271 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3273 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3275 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3276 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3277 add_loc_descr (&head, tmp);
3278 if (cfa->offset != 0)
3280 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3281 add_loc_descr (&head, tmp);
3287 /* This function fills in aa dw_cfa_location structure from a dwarf location
3288 descriptor sequence. */
3291 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3293 struct dw_loc_descr_struct *ptr;
3295 cfa->base_offset = 0;
3299 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3301 enum dwarf_location_atom op = ptr->dw_loc_opc;
3337 cfa->reg = op - DW_OP_reg0;
3340 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3374 cfa->reg = op - DW_OP_breg0;
3375 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3378 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3379 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3384 case DW_OP_plus_uconst:
3385 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3388 internal_error ("DW_LOC_OP %s not implemented\n",
3389 dwarf_stack_op_name (ptr->dw_loc_opc));
3393 #endif /* .debug_frame support */
3395 /* And now, the support for symbolic debugging information. */
3396 #ifdef DWARF2_DEBUGGING_INFO
3398 /* .debug_str support. */
3399 static int output_indirect_string (void **, void *);
3401 static void dwarf2out_init (const char *);
3402 static void dwarf2out_finish (const char *);
3403 static void dwarf2out_define (unsigned int, const char *);
3404 static void dwarf2out_undef (unsigned int, const char *);
3405 static void dwarf2out_start_source_file (unsigned, const char *);
3406 static void dwarf2out_end_source_file (unsigned);
3407 static void dwarf2out_begin_block (unsigned, unsigned);
3408 static void dwarf2out_end_block (unsigned, unsigned);
3409 static bool dwarf2out_ignore_block (tree);
3410 static void dwarf2out_global_decl (tree);
3411 static void dwarf2out_type_decl (tree, int);
3412 static void dwarf2out_imported_module_or_decl (tree, tree);
3413 static void dwarf2out_abstract_function (tree);
3414 static void dwarf2out_var_location (rtx);
3415 static void dwarf2out_begin_function (tree);
3417 /* The debug hooks structure. */
3419 const struct gcc_debug_hooks dwarf2_debug_hooks =
3425 dwarf2out_start_source_file,
3426 dwarf2out_end_source_file,
3427 dwarf2out_begin_block,
3428 dwarf2out_end_block,
3429 dwarf2out_ignore_block,
3430 dwarf2out_source_line,
3431 dwarf2out_begin_prologue,
3432 debug_nothing_int_charstar, /* end_prologue */
3433 dwarf2out_end_epilogue,
3434 dwarf2out_begin_function,
3435 debug_nothing_int, /* end_function */
3436 dwarf2out_decl, /* function_decl */
3437 dwarf2out_global_decl,
3438 dwarf2out_type_decl, /* type_decl */
3439 dwarf2out_imported_module_or_decl,
3440 debug_nothing_tree, /* deferred_inline_function */
3441 /* The DWARF 2 backend tries to reduce debugging bloat by not
3442 emitting the abstract description of inline functions until
3443 something tries to reference them. */
3444 dwarf2out_abstract_function, /* outlining_inline_function */
3445 debug_nothing_rtx, /* label */
3446 debug_nothing_int, /* handle_pch */
3447 dwarf2out_var_location
3451 /* NOTE: In the comments in this file, many references are made to
3452 "Debugging Information Entries". This term is abbreviated as `DIE'
3453 throughout the remainder of this file. */
3455 /* An internal representation of the DWARF output is built, and then
3456 walked to generate the DWARF debugging info. The walk of the internal
3457 representation is done after the entire program has been compiled.
3458 The types below are used to describe the internal representation. */
3460 /* Various DIE's use offsets relative to the beginning of the
3461 .debug_info section to refer to each other. */
3463 typedef long int dw_offset;
3465 /* Define typedefs here to avoid circular dependencies. */
3467 typedef struct dw_attr_struct *dw_attr_ref;
3468 typedef struct dw_line_info_struct *dw_line_info_ref;
3469 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3470 typedef struct pubname_struct *pubname_ref;
3471 typedef struct dw_ranges_struct *dw_ranges_ref;
3473 /* Each entry in the line_info_table maintains the file and
3474 line number associated with the label generated for that
3475 entry. The label gives the PC value associated with
3476 the line number entry. */
3478 typedef struct dw_line_info_struct GTY(())
3480 unsigned long dw_file_num;
3481 unsigned long dw_line_num;
3485 /* Line information for functions in separate sections; each one gets its
3487 typedef struct dw_separate_line_info_struct GTY(())
3489 unsigned long dw_file_num;
3490 unsigned long dw_line_num;
3491 unsigned long function;
3493 dw_separate_line_info_entry;
3495 /* Each DIE attribute has a field specifying the attribute kind,
3496 a link to the next attribute in the chain, and an attribute value.
3497 Attributes are typically linked below the DIE they modify. */
3499 typedef struct dw_attr_struct GTY(())
3501 enum dwarf_attribute dw_attr;
3502 dw_attr_ref dw_attr_next;
3503 dw_val_node dw_attr_val;
3507 /* The Debugging Information Entry (DIE) structure */
3509 typedef struct die_struct GTY(())
3511 enum dwarf_tag die_tag;
3513 dw_attr_ref die_attr;
3514 dw_die_ref die_parent;
3515 dw_die_ref die_child;
3517 dw_die_ref die_definition; /* ref from a specification to its definition */
3518 dw_offset die_offset;
3519 unsigned long die_abbrev;
3521 unsigned int decl_id;
3525 /* The pubname structure */
3527 typedef struct pubname_struct GTY(())
3534 struct dw_ranges_struct GTY(())
3539 /* The limbo die list structure. */
3540 typedef struct limbo_die_struct GTY(())
3544 struct limbo_die_struct *next;
3548 /* How to start an assembler comment. */
3549 #ifndef ASM_COMMENT_START
3550 #define ASM_COMMENT_START ";#"
3553 /* Define a macro which returns nonzero for a TYPE_DECL which was
3554 implicitly generated for a tagged type.
3556 Note that unlike the gcc front end (which generates a NULL named
3557 TYPE_DECL node for each complete tagged type, each array type, and
3558 each function type node created) the g++ front end generates a
3559 _named_ TYPE_DECL node for each tagged type node created.
3560 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3561 generate a DW_TAG_typedef DIE for them. */
3563 #define TYPE_DECL_IS_STUB(decl) \
3564 (DECL_NAME (decl) == NULL_TREE \
3565 || (DECL_ARTIFICIAL (decl) \
3566 && is_tagged_type (TREE_TYPE (decl)) \
3567 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3568 /* This is necessary for stub decls that \
3569 appear in nested inline functions. */ \
3570 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3571 && (decl_ultimate_origin (decl) \
3572 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3574 /* Information concerning the compilation unit's programming
3575 language, and compiler version. */
3577 /* Fixed size portion of the DWARF compilation unit header. */
3578 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3579 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3581 /* Fixed size portion of public names info. */
3582 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3584 /* Fixed size portion of the address range info. */
3585 #define DWARF_ARANGES_HEADER_SIZE \
3586 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3587 DWARF2_ADDR_SIZE * 2) \
3588 - DWARF_INITIAL_LENGTH_SIZE)
3590 /* Size of padding portion in the address range info. It must be
3591 aligned to twice the pointer size. */
3592 #define DWARF_ARANGES_PAD_SIZE \
3593 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3594 DWARF2_ADDR_SIZE * 2) \
3595 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3597 /* Use assembler line directives if available. */
3598 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3599 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3600 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3602 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3606 /* Minimum line offset in a special line info. opcode.
3607 This value was chosen to give a reasonable range of values. */
3608 #define DWARF_LINE_BASE -10
3610 /* First special line opcode - leave room for the standard opcodes. */
3611 #define DWARF_LINE_OPCODE_BASE 10
3613 /* Range of line offsets in a special line info. opcode. */
3614 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3616 /* Flag that indicates the initial value of the is_stmt_start flag.
3617 In the present implementation, we do not mark any lines as
3618 the beginning of a source statement, because that information
3619 is not made available by the GCC front-end. */
3620 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3622 #ifdef DWARF2_DEBUGGING_INFO
3623 /* This location is used by calc_die_sizes() to keep track
3624 the offset of each DIE within the .debug_info section. */
3625 static unsigned long next_die_offset;
3628 /* Record the root of the DIE's built for the current compilation unit. */
3629 static GTY(()) dw_die_ref comp_unit_die;
3631 /* A list of DIEs with a NULL parent waiting to be relocated. */
3632 static GTY(()) limbo_die_node *limbo_die_list;
3634 /* Filenames referenced by this compilation unit. */
3635 static GTY(()) varray_type file_table;
3636 static GTY(()) varray_type file_table_emitted;
3637 static GTY(()) size_t file_table_last_lookup_index;
3639 /* A hash table of references to DIE's that describe declarations.
3640 The key is a DECL_UID() which is a unique number identifying each decl. */
3641 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3643 /* Node of the variable location list. */
3644 struct var_loc_node GTY ((chain_next ("%h.next")))
3646 rtx GTY (()) var_loc_note;
3647 const char * GTY (()) label;
3648 struct var_loc_node * GTY (()) next;
3651 /* Variable location list. */
3652 struct var_loc_list_def GTY (())
3654 struct var_loc_node * GTY (()) first;
3656 /* Do not mark the last element of the chained list because
3657 it is marked through the chain. */
3658 struct var_loc_node * GTY ((skip ("%h"))) last;
3660 /* DECL_UID of the variable decl. */
3661 unsigned int decl_id;
3663 typedef struct var_loc_list_def var_loc_list;
3666 /* Table of decl location linked lists. */
3667 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3669 /* A pointer to the base of a list of references to DIE's that
3670 are uniquely identified by their tag, presence/absence of
3671 children DIE's, and list of attribute/value pairs. */
3672 static GTY((length ("abbrev_die_table_allocated")))
3673 dw_die_ref *abbrev_die_table;
3675 /* Number of elements currently allocated for abbrev_die_table. */
3676 static GTY(()) unsigned abbrev_die_table_allocated;
3678 /* Number of elements in type_die_table currently in use. */
3679 static GTY(()) unsigned abbrev_die_table_in_use;
3681 /* Size (in elements) of increments by which we may expand the
3682 abbrev_die_table. */
3683 #define ABBREV_DIE_TABLE_INCREMENT 256
3685 /* A pointer to the base of a table that contains line information
3686 for each source code line in .text in the compilation unit. */
3687 static GTY((length ("line_info_table_allocated")))
3688 dw_line_info_ref line_info_table;
3690 /* Number of elements currently allocated for line_info_table. */
3691 static GTY(()) unsigned line_info_table_allocated;
3693 /* Number of elements in line_info_table currently in use. */
3694 static GTY(()) unsigned line_info_table_in_use;
3696 /* A pointer to the base of a table that contains line information
3697 for each source code line outside of .text in the compilation unit. */
3698 static GTY ((length ("separate_line_info_table_allocated")))
3699 dw_separate_line_info_ref separate_line_info_table;
3701 /* Number of elements currently allocated for separate_line_info_table. */
3702 static GTY(()) unsigned separate_line_info_table_allocated;
3704 /* Number of elements in separate_line_info_table currently in use. */
3705 static GTY(()) unsigned separate_line_info_table_in_use;
3707 /* Size (in elements) of increments by which we may expand the
3709 #define LINE_INFO_TABLE_INCREMENT 1024
3711 /* A pointer to the base of a table that contains a list of publicly
3712 accessible names. */
3713 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table;
3715 /* Number of elements currently allocated for pubname_table. */
3716 static GTY(()) unsigned pubname_table_allocated;
3718 /* Number of elements in pubname_table currently in use. */
3719 static GTY(()) unsigned pubname_table_in_use;
3721 /* Size (in elements) of increments by which we may expand the
3723 #define PUBNAME_TABLE_INCREMENT 64
3725 /* Array of dies for which we should generate .debug_arange info. */
3726 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
3728 /* Number of elements currently allocated for arange_table. */
3729 static GTY(()) unsigned arange_table_allocated;
3731 /* Number of elements in arange_table currently in use. */
3732 static GTY(()) unsigned arange_table_in_use;
3734 /* Size (in elements) of increments by which we may expand the
3736 #define ARANGE_TABLE_INCREMENT 64
3738 /* Array of dies for which we should generate .debug_ranges info. */
3739 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3741 /* Number of elements currently allocated for ranges_table. */
3742 static GTY(()) unsigned ranges_table_allocated;
3744 /* Number of elements in ranges_table currently in use. */
3745 static GTY(()) unsigned ranges_table_in_use;
3747 /* Size (in elements) of increments by which we may expand the
3749 #define RANGES_TABLE_INCREMENT 64
3751 /* Whether we have location lists that need outputting */
3752 static GTY(()) unsigned have_location_lists;
3754 /* Unique label counter. */
3755 static GTY(()) unsigned int loclabel_num;
3757 #ifdef DWARF2_DEBUGGING_INFO
3758 /* Record whether the function being analyzed contains inlined functions. */
3759 static int current_function_has_inlines;
3761 #if 0 && defined (MIPS_DEBUGGING_INFO)
3762 static int comp_unit_has_inlines;
3765 /* Number of file tables emitted in maybe_emit_file(). */
3766 static GTY(()) int emitcount = 0;
3768 /* Number of internal labels generated by gen_internal_sym(). */
3769 static GTY(()) int label_num;
3771 #ifdef DWARF2_DEBUGGING_INFO
3773 /* Forward declarations for functions defined in this file. */
3775 static int is_pseudo_reg (rtx);
3776 static tree type_main_variant (tree);
3777 static int is_tagged_type (tree);
3778 static const char *dwarf_tag_name (unsigned);
3779 static const char *dwarf_attr_name (unsigned);
3780 static const char *dwarf_form_name (unsigned);
3782 static const char *dwarf_type_encoding_name (unsigned);
3784 static tree decl_ultimate_origin (tree);
3785 static tree block_ultimate_origin (tree);
3786 static tree decl_class_context (tree);
3787 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3788 static inline enum dw_val_class AT_class (dw_attr_ref);
3789 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3790 static inline unsigned AT_flag (dw_attr_ref);
3791 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3792 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
3793 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3794 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
3795 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
3797 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3798 unsigned int, unsigned char *);
3799 static hashval_t debug_str_do_hash (const void *);
3800 static int debug_str_eq (const void *, const void *);
3801 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3802 static inline const char *AT_string (dw_attr_ref);
3803 static int AT_string_form (dw_attr_ref);
3804 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3805 static void add_AT_specification (dw_die_ref, dw_die_ref);
3806 static inline dw_die_ref AT_ref (dw_attr_ref);
3807 static inline int AT_ref_external (dw_attr_ref);
3808 static inline void set_AT_ref_external (dw_attr_ref, int);
3809 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3810 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3811 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3812 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3814 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3815 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3816 static inline rtx AT_addr (dw_attr_ref);
3817 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3818 static void add_AT_lbl_offset (dw_die_ref, enum dwarf_attribute, const char *);
3819 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3820 unsigned HOST_WIDE_INT);
3821 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3823 static inline const char *AT_lbl (dw_attr_ref);
3824 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3825 static const char *get_AT_low_pc (dw_die_ref);
3826 static const char *get_AT_hi_pc (dw_die_ref);
3827 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3828 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3829 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3830 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3831 static bool is_c_family (void);
3832 static bool is_cxx (void);
3833 static bool is_java (void);
3834 static bool is_fortran (void);
3835 static bool is_ada (void);
3836 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3837 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3838 static inline void free_die (dw_die_ref);
3839 static void remove_children (dw_die_ref);
3840 static void add_child_die (dw_die_ref, dw_die_ref);
3841 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3842 static dw_die_ref lookup_type_die (tree);
3843 static void equate_type_number_to_die (tree, dw_die_ref);
3844 static hashval_t decl_die_table_hash (const void *);
3845 static int decl_die_table_eq (const void *, const void *);
3846 static dw_die_ref lookup_decl_die (tree);
3847 static hashval_t decl_loc_table_hash (const void *);
3848 static int decl_loc_table_eq (const void *, const void *);
3849 static var_loc_list *lookup_decl_loc (tree);
3850 static void equate_decl_number_to_die (tree, dw_die_ref);
3851 static void add_var_loc_to_decl (tree, struct var_loc_node *);
3852 static void print_spaces (FILE *);
3853 static void print_die (dw_die_ref, FILE *);
3854 static void print_dwarf_line_table (FILE *);
3855 static void reverse_die_lists (dw_die_ref);
3856 static void reverse_all_dies (dw_die_ref);
3857 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3858 static dw_die_ref pop_compile_unit (dw_die_ref);
3859 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3860 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3861 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3862 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3863 static int same_dw_val_p (dw_val_node *, dw_val_node *, int *);
3864 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3865 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3866 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3867 static void compute_section_prefix (dw_die_ref);
3868 static int is_type_die (dw_die_ref);
3869 static int is_comdat_die (dw_die_ref);
3870 static int is_symbol_die (dw_die_ref);
3871 static void assign_symbol_names (dw_die_ref);
3872 static void break_out_includes (dw_die_ref);
3873 static hashval_t htab_cu_hash (const void *);
3874 static int htab_cu_eq (const void *, const void *);
3875 static void htab_cu_del (void *);
3876 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3877 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3878 static void add_sibling_attributes (dw_die_ref);
3879 static void build_abbrev_table (dw_die_ref);
3880 static void output_location_lists (dw_die_ref);
3881 static int constant_size (long unsigned);
3882 static unsigned long size_of_die (dw_die_ref);
3883 static void calc_die_sizes (dw_die_ref);
3884 static void mark_dies (dw_die_ref);
3885 static void unmark_dies (dw_die_ref);
3886 static void unmark_all_dies (dw_die_ref);
3887 static unsigned long size_of_pubnames (void);
3888 static unsigned long size_of_aranges (void);
3889 static enum dwarf_form value_format (dw_attr_ref);
3890 static void output_value_format (dw_attr_ref);
3891 static void output_abbrev_section (void);
3892 static void output_die_symbol (dw_die_ref);
3893 static void output_die (dw_die_ref);
3894 static void output_compilation_unit_header (void);
3895 static void output_comp_unit (dw_die_ref, int);
3896 static const char *dwarf2_name (tree, int);
3897 static void add_pubname (tree, dw_die_ref);
3898 static void output_pubnames (void);
3899 static void add_arange (tree, dw_die_ref);
3900 static void output_aranges (void);
3901 static unsigned int add_ranges (tree);
3902 static void output_ranges (void);
3903 static void output_line_info (void);
3904 static void output_file_names (void);
3905 static dw_die_ref base_type_die (tree);
3906 static tree root_type (tree);
3907 static int is_base_type (tree);
3908 static bool is_subrange_type (tree);
3909 static dw_die_ref subrange_type_die (tree, dw_die_ref);
3910 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
3911 static int type_is_enum (tree);
3912 static unsigned int dbx_reg_number (rtx);
3913 static dw_loc_descr_ref reg_loc_descriptor (rtx);
3914 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int);
3915 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx);
3916 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3917 static dw_loc_descr_ref based_loc_descr (unsigned, HOST_WIDE_INT, bool);
3918 static int is_based_loc (rtx);
3919 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode, bool);
3920 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx);
3921 static dw_loc_descr_ref loc_descriptor (rtx, bool);
3922 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
3923 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
3924 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3925 static tree field_type (tree);
3926 static unsigned int simple_type_align_in_bits (tree);
3927 static unsigned int simple_decl_align_in_bits (tree);
3928 static unsigned HOST_WIDE_INT simple_type_size_in_bits (tree);
3929 static HOST_WIDE_INT field_byte_offset (tree);
3930 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3932 static void add_data_member_location_attribute (dw_die_ref, tree);
3933 static void add_const_value_attribute (dw_die_ref, rtx);
3934 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3935 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
3936 static void insert_float (rtx, unsigned char *);
3937 static rtx rtl_for_decl_location (tree);
3938 static void add_location_or_const_value_attribute (dw_die_ref, tree,
3939 enum dwarf_attribute);
3940 static void tree_add_const_value_attribute (dw_die_ref, tree);
3941 static void add_name_attribute (dw_die_ref, const char *);
3942 static void add_comp_dir_attribute (dw_die_ref);
3943 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
3944 static void add_subscript_info (dw_die_ref, tree);
3945 static void add_byte_size_attribute (dw_die_ref, tree);
3946 static void add_bit_offset_attribute (dw_die_ref, tree);
3947 static void add_bit_size_attribute (dw_die_ref, tree);
3948 static void add_prototyped_attribute (dw_die_ref, tree);
3949 static void add_abstract_origin_attribute (dw_die_ref, tree);
3950 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3951 static void add_src_coords_attributes (dw_die_ref, tree);
3952 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3953 static void push_decl_scope (tree);
3954 static void pop_decl_scope (void);
3955 static dw_die_ref scope_die_for (tree, dw_die_ref);
3956 static inline int local_scope_p (dw_die_ref);
3957 static inline int class_or_namespace_scope_p (dw_die_ref);
3958 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
3959 static void add_calling_convention_attribute (dw_die_ref, tree);
3960 static const char *type_tag (tree);
3961 static tree member_declared_type (tree);
3963 static const char *decl_start_label (tree);
3965 static void gen_array_type_die (tree, dw_die_ref);
3966 static void gen_set_type_die (tree, dw_die_ref);
3968 static void gen_entry_point_die (tree, dw_die_ref);
3970 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
3971 static void gen_inlined_structure_type_die (tree, dw_die_ref);
3972 static void gen_inlined_union_type_die (tree, dw_die_ref);
3973 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
3974 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
3975 static void gen_unspecified_parameters_die (tree, dw_die_ref);
3976 static void gen_formal_types_die (tree, dw_die_ref);
3977 static void gen_subprogram_die (tree, dw_die_ref);
3978 static void gen_variable_die (tree, dw_die_ref);
3979 static void gen_label_die (tree, dw_die_ref);
3980 static void gen_lexical_block_die (tree, dw_die_ref, int);
3981 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
3982 static void gen_field_die (tree, dw_die_ref);
3983 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3984 static dw_die_ref gen_compile_unit_die (const char *);
3985 static void gen_string_type_die (tree, dw_die_ref);
3986 static void gen_inheritance_die (tree, tree, dw_die_ref);
3987 static void gen_member_die (tree, dw_die_ref);
3988 static void gen_struct_or_union_type_die (tree, dw_die_ref);
3989 static void gen_subroutine_type_die (tree, dw_die_ref);
3990 static void gen_typedef_die (tree, dw_die_ref);
3991 static void gen_type_die (tree, dw_die_ref);
3992 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
3993 static void gen_block_die (tree, dw_die_ref, int);
3994 static void decls_for_scope (tree, dw_die_ref, int);
3995 static int is_redundant_typedef (tree);
3996 static void gen_namespace_die (tree);
3997 static void gen_decl_die (tree, dw_die_ref);
3998 static dw_die_ref force_decl_die (tree);
3999 static dw_die_ref force_type_die (tree);
4000 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
4001 static void declare_in_namespace (tree, dw_die_ref);
4002 static unsigned lookup_filename (const char *);
4003 static void init_file_table (void);
4004 static void retry_incomplete_types (void);
4005 static void gen_type_die_for_member (tree, tree, dw_die_ref);
4006 static void splice_child_die (dw_die_ref, dw_die_ref);
4007 static int file_info_cmp (const void *, const void *);
4008 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
4009 const char *, const char *, unsigned);
4010 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
4011 const char *, const char *,
4013 static void output_loc_list (dw_loc_list_ref);
4014 static char *gen_internal_sym (const char *);
4016 static void prune_unmark_dies (dw_die_ref);
4017 static void prune_unused_types_mark (dw_die_ref, int);
4018 static void prune_unused_types_walk (dw_die_ref);
4019 static void prune_unused_types_walk_attribs (dw_die_ref);
4020 static void prune_unused_types_prune (dw_die_ref);
4021 static void prune_unused_types (void);
4022 static int maybe_emit_file (int);
4024 /* Section names used to hold DWARF debugging information. */
4025 #ifndef DEBUG_INFO_SECTION
4026 #define DEBUG_INFO_SECTION ".debug_info"
4028 #ifndef DEBUG_ABBREV_SECTION
4029 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4031 #ifndef DEBUG_ARANGES_SECTION
4032 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4034 #ifndef DEBUG_MACINFO_SECTION
4035 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4037 #ifndef DEBUG_LINE_SECTION
4038 #define DEBUG_LINE_SECTION ".debug_line"
4040 #ifndef DEBUG_LOC_SECTION
4041 #define DEBUG_LOC_SECTION ".debug_loc"
4043 #ifndef DEBUG_PUBNAMES_SECTION
4044 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4046 #ifndef DEBUG_STR_SECTION
4047 #define DEBUG_STR_SECTION ".debug_str"
4049 #ifndef DEBUG_RANGES_SECTION
4050 #define DEBUG_RANGES_SECTION ".debug_ranges"
4053 /* Standard ELF section names for compiled code and data. */
4054 #ifndef TEXT_SECTION_NAME
4055 #define TEXT_SECTION_NAME ".text"
4058 /* Section flags for .debug_str section. */
4059 #define DEBUG_STR_SECTION_FLAGS \
4060 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
4061 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4064 /* Labels we insert at beginning sections we can reference instead of
4065 the section names themselves. */
4067 #ifndef TEXT_SECTION_LABEL
4068 #define TEXT_SECTION_LABEL "Ltext"
4070 #ifndef DEBUG_LINE_SECTION_LABEL
4071 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4073 #ifndef DEBUG_INFO_SECTION_LABEL
4074 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4076 #ifndef DEBUG_ABBREV_SECTION_LABEL
4077 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4079 #ifndef DEBUG_LOC_SECTION_LABEL
4080 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4082 #ifndef DEBUG_RANGES_SECTION_LABEL
4083 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4085 #ifndef DEBUG_MACINFO_SECTION_LABEL
4086 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4089 /* Definitions of defaults for formats and names of various special
4090 (artificial) labels which may be generated within this file (when the -g
4091 options is used and DWARF2_DEBUGGING_INFO is in effect.
4092 If necessary, these may be overridden from within the tm.h file, but
4093 typically, overriding these defaults is unnecessary. */
4095 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4096 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4097 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4098 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4099 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4100 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4101 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4102 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4104 #ifndef TEXT_END_LABEL
4105 #define TEXT_END_LABEL "Letext"
4107 #ifndef BLOCK_BEGIN_LABEL
4108 #define BLOCK_BEGIN_LABEL "LBB"
4110 #ifndef BLOCK_END_LABEL
4111 #define BLOCK_END_LABEL "LBE"
4113 #ifndef LINE_CODE_LABEL
4114 #define LINE_CODE_LABEL "LM"
4116 #ifndef SEPARATE_LINE_CODE_LABEL
4117 #define SEPARATE_LINE_CODE_LABEL "LSM"
4120 /* We allow a language front-end to designate a function that is to be
4121 called to "demangle" any name before it it put into a DIE. */
4123 static const char *(*demangle_name_func) (const char *);
4126 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4128 demangle_name_func = func;
4131 /* Test if rtl node points to a pseudo register. */
4134 is_pseudo_reg (rtx rtl)
4136 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4137 || (GET_CODE (rtl) == SUBREG
4138 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4141 /* Return a reference to a type, with its const and volatile qualifiers
4145 type_main_variant (tree type)
4147 type = TYPE_MAIN_VARIANT (type);
4149 /* ??? There really should be only one main variant among any group of
4150 variants of a given type (and all of the MAIN_VARIANT values for all
4151 members of the group should point to that one type) but sometimes the C
4152 front-end messes this up for array types, so we work around that bug
4154 if (TREE_CODE (type) == ARRAY_TYPE)
4155 while (type != TYPE_MAIN_VARIANT (type))
4156 type = TYPE_MAIN_VARIANT (type);
4161 /* Return nonzero if the given type node represents a tagged type. */
4164 is_tagged_type (tree type)
4166 enum tree_code code = TREE_CODE (type);
4168 return (code == RECORD_TYPE || code == UNION_TYPE
4169 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4172 /* Convert a DIE tag into its string name. */
4175 dwarf_tag_name (unsigned int tag)
4179 case DW_TAG_padding:
4180 return "DW_TAG_padding";
4181 case DW_TAG_array_type:
4182 return "DW_TAG_array_type";
4183 case DW_TAG_class_type:
4184 return "DW_TAG_class_type";
4185 case DW_TAG_entry_point:
4186 return "DW_TAG_entry_point";
4187 case DW_TAG_enumeration_type:
4188 return "DW_TAG_enumeration_type";
4189 case DW_TAG_formal_parameter:
4190 return "DW_TAG_formal_parameter";
4191 case DW_TAG_imported_declaration:
4192 return "DW_TAG_imported_declaration";
4194 return "DW_TAG_label";
4195 case DW_TAG_lexical_block:
4196 return "DW_TAG_lexical_block";
4198 return "DW_TAG_member";
4199 case DW_TAG_pointer_type:
4200 return "DW_TAG_pointer_type";
4201 case DW_TAG_reference_type:
4202 return "DW_TAG_reference_type";
4203 case DW_TAG_compile_unit:
4204 return "DW_TAG_compile_unit";
4205 case DW_TAG_string_type:
4206 return "DW_TAG_string_type";
4207 case DW_TAG_structure_type:
4208 return "DW_TAG_structure_type";
4209 case DW_TAG_subroutine_type:
4210 return "DW_TAG_subroutine_type";
4211 case DW_TAG_typedef:
4212 return "DW_TAG_typedef";
4213 case DW_TAG_union_type:
4214 return "DW_TAG_union_type";
4215 case DW_TAG_unspecified_parameters:
4216 return "DW_TAG_unspecified_parameters";
4217 case DW_TAG_variant:
4218 return "DW_TAG_variant";
4219 case DW_TAG_common_block:
4220 return "DW_TAG_common_block";
4221 case DW_TAG_common_inclusion:
4222 return "DW_TAG_common_inclusion";
4223 case DW_TAG_inheritance:
4224 return "DW_TAG_inheritance";
4225 case DW_TAG_inlined_subroutine:
4226 return "DW_TAG_inlined_subroutine";
4228 return "DW_TAG_module";
4229 case DW_TAG_ptr_to_member_type:
4230 return "DW_TAG_ptr_to_member_type";
4231 case DW_TAG_set_type:
4232 return "DW_TAG_set_type";
4233 case DW_TAG_subrange_type:
4234 return "DW_TAG_subrange_type";
4235 case DW_TAG_with_stmt:
4236 return "DW_TAG_with_stmt";
4237 case DW_TAG_access_declaration:
4238 return "DW_TAG_access_declaration";
4239 case DW_TAG_base_type:
4240 return "DW_TAG_base_type";
4241 case DW_TAG_catch_block:
4242 return "DW_TAG_catch_block";
4243 case DW_TAG_const_type:
4244 return "DW_TAG_const_type";
4245 case DW_TAG_constant:
4246 return "DW_TAG_constant";
4247 case DW_TAG_enumerator:
4248 return "DW_TAG_enumerator";
4249 case DW_TAG_file_type:
4250 return "DW_TAG_file_type";
4252 return "DW_TAG_friend";
4253 case DW_TAG_namelist:
4254 return "DW_TAG_namelist";
4255 case DW_TAG_namelist_item:
4256 return "DW_TAG_namelist_item";
4257 case DW_TAG_namespace:
4258 return "DW_TAG_namespace";
4259 case DW_TAG_packed_type:
4260 return "DW_TAG_packed_type";
4261 case DW_TAG_subprogram:
4262 return "DW_TAG_subprogram";
4263 case DW_TAG_template_type_param:
4264 return "DW_TAG_template_type_param";
4265 case DW_TAG_template_value_param:
4266 return "DW_TAG_template_value_param";
4267 case DW_TAG_thrown_type:
4268 return "DW_TAG_thrown_type";
4269 case DW_TAG_try_block:
4270 return "DW_TAG_try_block";
4271 case DW_TAG_variant_part:
4272 return "DW_TAG_variant_part";
4273 case DW_TAG_variable:
4274 return "DW_TAG_variable";
4275 case DW_TAG_volatile_type:
4276 return "DW_TAG_volatile_type";
4277 case DW_TAG_imported_module:
4278 return "DW_TAG_imported_module";
4279 case DW_TAG_MIPS_loop:
4280 return "DW_TAG_MIPS_loop";
4281 case DW_TAG_format_label:
4282 return "DW_TAG_format_label";
4283 case DW_TAG_function_template:
4284 return "DW_TAG_function_template";
4285 case DW_TAG_class_template:
4286 return "DW_TAG_class_template";
4287 case DW_TAG_GNU_BINCL:
4288 return "DW_TAG_GNU_BINCL";
4289 case DW_TAG_GNU_EINCL:
4290 return "DW_TAG_GNU_EINCL";
4292 return "DW_TAG_<unknown>";
4296 /* Convert a DWARF attribute code into its string name. */
4299 dwarf_attr_name (unsigned int attr)
4304 return "DW_AT_sibling";
4305 case DW_AT_location:
4306 return "DW_AT_location";
4308 return "DW_AT_name";
4309 case DW_AT_ordering:
4310 return "DW_AT_ordering";
4311 case DW_AT_subscr_data:
4312 return "DW_AT_subscr_data";
4313 case DW_AT_byte_size:
4314 return "DW_AT_byte_size";
4315 case DW_AT_bit_offset:
4316 return "DW_AT_bit_offset";
4317 case DW_AT_bit_size:
4318 return "DW_AT_bit_size";
4319 case DW_AT_element_list:
4320 return "DW_AT_element_list";
4321 case DW_AT_stmt_list:
4322 return "DW_AT_stmt_list";
4324 return "DW_AT_low_pc";
4326 return "DW_AT_high_pc";
4327 case DW_AT_language:
4328 return "DW_AT_language";
4330 return "DW_AT_member";
4332 return "DW_AT_discr";
4333 case DW_AT_discr_value:
4334 return "DW_AT_discr_value";
4335 case DW_AT_visibility:
4336 return "DW_AT_visibility";
4338 return "DW_AT_import";
4339 case DW_AT_string_length:
4340 return "DW_AT_string_length";
4341 case DW_AT_common_reference:
4342 return "DW_AT_common_reference";
4343 case DW_AT_comp_dir:
4344 return "DW_AT_comp_dir";
4345 case DW_AT_const_value:
4346 return "DW_AT_const_value";
4347 case DW_AT_containing_type:
4348 return "DW_AT_containing_type";
4349 case DW_AT_default_value:
4350 return "DW_AT_default_value";
4352 return "DW_AT_inline";
4353 case DW_AT_is_optional:
4354 return "DW_AT_is_optional";
4355 case DW_AT_lower_bound:
4356 return "DW_AT_lower_bound";
4357 case DW_AT_producer:
4358 return "DW_AT_producer";
4359 case DW_AT_prototyped:
4360 return "DW_AT_prototyped";
4361 case DW_AT_return_addr:
4362 return "DW_AT_return_addr";
4363 case DW_AT_start_scope:
4364 return "DW_AT_start_scope";
4365 case DW_AT_stride_size:
4366 return "DW_AT_stride_size";
4367 case DW_AT_upper_bound:
4368 return "DW_AT_upper_bound";
4369 case DW_AT_abstract_origin:
4370 return "DW_AT_abstract_origin";
4371 case DW_AT_accessibility:
4372 return "DW_AT_accessibility";
4373 case DW_AT_address_class:
4374 return "DW_AT_address_class";
4375 case DW_AT_artificial:
4376 return "DW_AT_artificial";
4377 case DW_AT_base_types:
4378 return "DW_AT_base_types";
4379 case DW_AT_calling_convention:
4380 return "DW_AT_calling_convention";
4382 return "DW_AT_count";
4383 case DW_AT_data_member_location:
4384 return "DW_AT_data_member_location";
4385 case DW_AT_decl_column:
4386 return "DW_AT_decl_column";
4387 case DW_AT_decl_file:
4388 return "DW_AT_decl_file";
4389 case DW_AT_decl_line:
4390 return "DW_AT_decl_line";
4391 case DW_AT_declaration:
4392 return "DW_AT_declaration";
4393 case DW_AT_discr_list:
4394 return "DW_AT_discr_list";
4395 case DW_AT_encoding:
4396 return "DW_AT_encoding";
4397 case DW_AT_external:
4398 return "DW_AT_external";
4399 case DW_AT_frame_base:
4400 return "DW_AT_frame_base";
4402 return "DW_AT_friend";
4403 case DW_AT_identifier_case:
4404 return "DW_AT_identifier_case";
4405 case DW_AT_macro_info:
4406 return "DW_AT_macro_info";
4407 case DW_AT_namelist_items:
4408 return "DW_AT_namelist_items";
4409 case DW_AT_priority:
4410 return "DW_AT_priority";
4412 return "DW_AT_segment";
4413 case DW_AT_specification:
4414 return "DW_AT_specification";
4415 case DW_AT_static_link:
4416 return "DW_AT_static_link";
4418 return "DW_AT_type";
4419 case DW_AT_use_location:
4420 return "DW_AT_use_location";
4421 case DW_AT_variable_parameter:
4422 return "DW_AT_variable_parameter";
4423 case DW_AT_virtuality:
4424 return "DW_AT_virtuality";
4425 case DW_AT_vtable_elem_location:
4426 return "DW_AT_vtable_elem_location";
4428 case DW_AT_allocated:
4429 return "DW_AT_allocated";
4430 case DW_AT_associated:
4431 return "DW_AT_associated";
4432 case DW_AT_data_location:
4433 return "DW_AT_data_location";
4435 return "DW_AT_stride";
4436 case DW_AT_entry_pc:
4437 return "DW_AT_entry_pc";
4438 case DW_AT_use_UTF8:
4439 return "DW_AT_use_UTF8";
4440 case DW_AT_extension:
4441 return "DW_AT_extension";
4443 return "DW_AT_ranges";
4444 case DW_AT_trampoline:
4445 return "DW_AT_trampoline";
4446 case DW_AT_call_column:
4447 return "DW_AT_call_column";
4448 case DW_AT_call_file:
4449 return "DW_AT_call_file";
4450 case DW_AT_call_line:
4451 return "DW_AT_call_line";
4453 case DW_AT_MIPS_fde:
4454 return "DW_AT_MIPS_fde";
4455 case DW_AT_MIPS_loop_begin:
4456 return "DW_AT_MIPS_loop_begin";
4457 case DW_AT_MIPS_tail_loop_begin:
4458 return "DW_AT_MIPS_tail_loop_begin";
4459 case DW_AT_MIPS_epilog_begin:
4460 return "DW_AT_MIPS_epilog_begin";
4461 case DW_AT_MIPS_loop_unroll_factor:
4462 return "DW_AT_MIPS_loop_unroll_factor";
4463 case DW_AT_MIPS_software_pipeline_depth:
4464 return "DW_AT_MIPS_software_pipeline_depth";
4465 case DW_AT_MIPS_linkage_name:
4466 return "DW_AT_MIPS_linkage_name";
4467 case DW_AT_MIPS_stride:
4468 return "DW_AT_MIPS_stride";
4469 case DW_AT_MIPS_abstract_name:
4470 return "DW_AT_MIPS_abstract_name";
4471 case DW_AT_MIPS_clone_origin:
4472 return "DW_AT_MIPS_clone_origin";
4473 case DW_AT_MIPS_has_inlines:
4474 return "DW_AT_MIPS_has_inlines";
4476 case DW_AT_sf_names:
4477 return "DW_AT_sf_names";
4478 case DW_AT_src_info:
4479 return "DW_AT_src_info";
4480 case DW_AT_mac_info:
4481 return "DW_AT_mac_info";
4482 case DW_AT_src_coords:
4483 return "DW_AT_src_coords";
4484 case DW_AT_body_begin:
4485 return "DW_AT_body_begin";
4486 case DW_AT_body_end:
4487 return "DW_AT_body_end";
4488 case DW_AT_GNU_vector:
4489 return "DW_AT_GNU_vector";
4491 case DW_AT_VMS_rtnbeg_pd_address:
4492 return "DW_AT_VMS_rtnbeg_pd_address";
4495 return "DW_AT_<unknown>";
4499 /* Convert a DWARF value form code into its string name. */
4502 dwarf_form_name (unsigned int form)
4507 return "DW_FORM_addr";
4508 case DW_FORM_block2:
4509 return "DW_FORM_block2";
4510 case DW_FORM_block4:
4511 return "DW_FORM_block4";
4513 return "DW_FORM_data2";
4515 return "DW_FORM_data4";
4517 return "DW_FORM_data8";
4518 case DW_FORM_string:
4519 return "DW_FORM_string";
4521 return "DW_FORM_block";
4522 case DW_FORM_block1:
4523 return "DW_FORM_block1";
4525 return "DW_FORM_data1";
4527 return "DW_FORM_flag";
4529 return "DW_FORM_sdata";
4531 return "DW_FORM_strp";
4533 return "DW_FORM_udata";
4534 case DW_FORM_ref_addr:
4535 return "DW_FORM_ref_addr";
4537 return "DW_FORM_ref1";
4539 return "DW_FORM_ref2";
4541 return "DW_FORM_ref4";
4543 return "DW_FORM_ref8";
4544 case DW_FORM_ref_udata:
4545 return "DW_FORM_ref_udata";
4546 case DW_FORM_indirect:
4547 return "DW_FORM_indirect";
4549 return "DW_FORM_<unknown>";
4553 /* Convert a DWARF type code into its string name. */
4557 dwarf_type_encoding_name (unsigned enc)
4561 case DW_ATE_address:
4562 return "DW_ATE_address";
4563 case DW_ATE_boolean:
4564 return "DW_ATE_boolean";
4565 case DW_ATE_complex_float:
4566 return "DW_ATE_complex_float";
4568 return "DW_ATE_float";
4570 return "DW_ATE_signed";
4571 case DW_ATE_signed_char:
4572 return "DW_ATE_signed_char";
4573 case DW_ATE_unsigned:
4574 return "DW_ATE_unsigned";
4575 case DW_ATE_unsigned_char:
4576 return "DW_ATE_unsigned_char";
4578 return "DW_ATE_<unknown>";
4583 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4584 instance of an inlined instance of a decl which is local to an inline
4585 function, so we have to trace all of the way back through the origin chain
4586 to find out what sort of node actually served as the original seed for the
4590 decl_ultimate_origin (tree decl)
4592 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4593 nodes in the function to point to themselves; ignore that if
4594 we're trying to output the abstract instance of this function. */
4595 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4598 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4599 most distant ancestor, this should never happen. */
4600 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4602 return DECL_ABSTRACT_ORIGIN (decl);
4605 /* Determine the "ultimate origin" of a block. The block may be an inlined
4606 instance of an inlined instance of a block which is local to an inline
4607 function, so we have to trace all of the way back through the origin chain
4608 to find out what sort of node actually served as the original seed for the
4612 block_ultimate_origin (tree block)
4614 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4616 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4617 nodes in the function to point to themselves; ignore that if
4618 we're trying to output the abstract instance of this function. */
4619 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4622 if (immediate_origin == NULL_TREE)
4627 tree lookahead = immediate_origin;
4631 ret_val = lookahead;
4632 lookahead = (TREE_CODE (ret_val) == BLOCK
4633 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4635 while (lookahead != NULL && lookahead != ret_val);
4641 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4642 of a virtual function may refer to a base class, so we check the 'this'
4646 decl_class_context (tree decl)
4648 tree context = NULL_TREE;
4650 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4651 context = DECL_CONTEXT (decl);
4653 context = TYPE_MAIN_VARIANT
4654 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4656 if (context && !TYPE_P (context))
4657 context = NULL_TREE;
4662 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4663 addition order, and correct that in reverse_all_dies. */
4666 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4668 if (die != NULL && attr != NULL)
4670 attr->dw_attr_next = die->die_attr;
4671 die->die_attr = attr;
4675 static inline enum dw_val_class
4676 AT_class (dw_attr_ref a)
4678 return a->dw_attr_val.val_class;
4681 /* Add a flag value attribute to a DIE. */
4684 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4686 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4688 attr->dw_attr_next = NULL;
4689 attr->dw_attr = attr_kind;
4690 attr->dw_attr_val.val_class = dw_val_class_flag;
4691 attr->dw_attr_val.v.val_flag = flag;
4692 add_dwarf_attr (die, attr);
4695 static inline unsigned
4696 AT_flag (dw_attr_ref a)
4698 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4699 return a->dw_attr_val.v.val_flag;
4702 /* Add a signed integer attribute value to a DIE. */
4705 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4707 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4709 attr->dw_attr_next = NULL;
4710 attr->dw_attr = attr_kind;
4711 attr->dw_attr_val.val_class = dw_val_class_const;
4712 attr->dw_attr_val.v.val_int = int_val;
4713 add_dwarf_attr (die, attr);
4716 static inline HOST_WIDE_INT
4717 AT_int (dw_attr_ref a)
4719 gcc_assert (a && AT_class (a) == dw_val_class_const);
4720 return a->dw_attr_val.v.val_int;
4723 /* Add an unsigned integer attribute value to a DIE. */
4726 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4727 unsigned HOST_WIDE_INT unsigned_val)
4729 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4731 attr->dw_attr_next = NULL;
4732 attr->dw_attr = attr_kind;
4733 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4734 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4735 add_dwarf_attr (die, attr);
4738 static inline unsigned HOST_WIDE_INT
4739 AT_unsigned (dw_attr_ref a)
4741 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
4742 return a->dw_attr_val.v.val_unsigned;
4745 /* Add an unsigned double integer attribute value to a DIE. */
4748 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
4749 long unsigned int val_hi, long unsigned int val_low)
4751 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4753 attr->dw_attr_next = NULL;
4754 attr->dw_attr = attr_kind;
4755 attr->dw_attr_val.val_class = dw_val_class_long_long;
4756 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4757 attr->dw_attr_val.v.val_long_long.low = val_low;
4758 add_dwarf_attr (die, attr);
4761 /* Add a floating point attribute value to a DIE and return it. */
4764 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4765 unsigned int length, unsigned int elt_size, unsigned char *array)
4767 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4769 attr->dw_attr_next = NULL;
4770 attr->dw_attr = attr_kind;
4771 attr->dw_attr_val.val_class = dw_val_class_vec;
4772 attr->dw_attr_val.v.val_vec.length = length;
4773 attr->dw_attr_val.v.val_vec.elt_size = elt_size;
4774 attr->dw_attr_val.v.val_vec.array = array;
4775 add_dwarf_attr (die, attr);
4778 /* Hash and equality functions for debug_str_hash. */
4781 debug_str_do_hash (const void *x)
4783 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4787 debug_str_eq (const void *x1, const void *x2)
4789 return strcmp ((((const struct indirect_string_node *)x1)->str),
4790 (const char *)x2) == 0;
4793 /* Add a string attribute value to a DIE. */
4796 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4798 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4799 struct indirect_string_node *node;
4802 if (! debug_str_hash)
4803 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4804 debug_str_eq, NULL);
4806 slot = htab_find_slot_with_hash (debug_str_hash, str,
4807 htab_hash_string (str), INSERT);
4809 *slot = ggc_alloc_cleared (sizeof (struct indirect_string_node));
4810 node = (struct indirect_string_node *) *slot;
4811 node->str = ggc_strdup (str);
4814 attr->dw_attr_next = NULL;
4815 attr->dw_attr = attr_kind;
4816 attr->dw_attr_val.val_class = dw_val_class_str;
4817 attr->dw_attr_val.v.val_str = node;
4818 add_dwarf_attr (die, attr);
4821 static inline const char *
4822 AT_string (dw_attr_ref a)
4824 gcc_assert (a && AT_class (a) == dw_val_class_str);
4825 return a->dw_attr_val.v.val_str->str;
4828 /* Find out whether a string should be output inline in DIE
4829 or out-of-line in .debug_str section. */
4832 AT_string_form (dw_attr_ref a)
4834 struct indirect_string_node *node;
4838 gcc_assert (a && AT_class (a) == dw_val_class_str);
4840 node = a->dw_attr_val.v.val_str;
4844 len = strlen (node->str) + 1;
4846 /* If the string is shorter or equal to the size of the reference, it is
4847 always better to put it inline. */
4848 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4849 return node->form = DW_FORM_string;
4851 /* If we cannot expect the linker to merge strings in .debug_str
4852 section, only put it into .debug_str if it is worth even in this
4854 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4855 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4856 return node->form = DW_FORM_string;
4858 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4859 ++dw2_string_counter;
4860 node->label = xstrdup (label);
4862 return node->form = DW_FORM_strp;
4865 /* Add a DIE reference attribute value to a DIE. */
4868 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4870 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4872 attr->dw_attr_next = NULL;
4873 attr->dw_attr = attr_kind;
4874 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4875 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4876 attr->dw_attr_val.v.val_die_ref.external = 0;
4877 add_dwarf_attr (die, attr);
4880 /* Add an AT_specification attribute to a DIE, and also make the back
4881 pointer from the specification to the definition. */
4884 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
4886 add_AT_die_ref (die, DW_AT_specification, targ_die);
4887 gcc_assert (!targ_die->die_definition);
4888 targ_die->die_definition = die;
4891 static inline dw_die_ref
4892 AT_ref (dw_attr_ref a)
4894 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4895 return a->dw_attr_val.v.val_die_ref.die;
4899 AT_ref_external (dw_attr_ref a)
4901 if (a && AT_class (a) == dw_val_class_die_ref)
4902 return a->dw_attr_val.v.val_die_ref.external;
4908 set_AT_ref_external (dw_attr_ref a, int i)
4910 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4911 a->dw_attr_val.v.val_die_ref.external = i;
4914 /* Add an FDE reference attribute value to a DIE. */
4917 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
4919 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4921 attr->dw_attr_next = NULL;
4922 attr->dw_attr = attr_kind;
4923 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4924 attr->dw_attr_val.v.val_fde_index = targ_fde;
4925 add_dwarf_attr (die, attr);
4928 /* Add a location description attribute value to a DIE. */
4931 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4933 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4935 attr->dw_attr_next = NULL;
4936 attr->dw_attr = attr_kind;
4937 attr->dw_attr_val.val_class = dw_val_class_loc;
4938 attr->dw_attr_val.v.val_loc = loc;
4939 add_dwarf_attr (die, attr);
4942 static inline dw_loc_descr_ref
4943 AT_loc (dw_attr_ref a)
4945 gcc_assert (a && AT_class (a) == dw_val_class_loc);
4946 return a->dw_attr_val.v.val_loc;
4950 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
4952 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4954 attr->dw_attr_next = NULL;
4955 attr->dw_attr = attr_kind;
4956 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4957 attr->dw_attr_val.v.val_loc_list = loc_list;
4958 add_dwarf_attr (die, attr);
4959 have_location_lists = 1;
4962 static inline dw_loc_list_ref
4963 AT_loc_list (dw_attr_ref a)
4965 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4966 return a->dw_attr_val.v.val_loc_list;
4969 /* Add an address constant attribute value to a DIE. */
4972 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
4974 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4976 attr->dw_attr_next = NULL;
4977 attr->dw_attr = attr_kind;
4978 attr->dw_attr_val.val_class = dw_val_class_addr;
4979 attr->dw_attr_val.v.val_addr = addr;
4980 add_dwarf_attr (die, attr);
4984 AT_addr (dw_attr_ref a)
4986 gcc_assert (a && AT_class (a) == dw_val_class_addr);
4987 return a->dw_attr_val.v.val_addr;
4990 /* Add a label identifier attribute value to a DIE. */
4993 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
4995 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4997 attr->dw_attr_next = NULL;
4998 attr->dw_attr = attr_kind;
4999 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
5000 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5001 add_dwarf_attr (die, attr);
5004 /* Add a section offset attribute value to a DIE. */
5007 add_AT_lbl_offset (dw_die_ref die, enum dwarf_attribute attr_kind, const char *label)
5009 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5011 attr->dw_attr_next = NULL;
5012 attr->dw_attr = attr_kind;
5013 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
5014 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
5015 add_dwarf_attr (die, attr);
5018 /* Add an offset attribute value to a DIE. */
5021 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
5022 unsigned HOST_WIDE_INT offset)
5024 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5026 attr->dw_attr_next = NULL;
5027 attr->dw_attr = attr_kind;
5028 attr->dw_attr_val.val_class = dw_val_class_offset;
5029 attr->dw_attr_val.v.val_offset = offset;
5030 add_dwarf_attr (die, attr);
5033 /* Add an range_list attribute value to a DIE. */
5036 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5037 long unsigned int offset)
5039 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5041 attr->dw_attr_next = NULL;
5042 attr->dw_attr = attr_kind;
5043 attr->dw_attr_val.val_class = dw_val_class_range_list;
5044 attr->dw_attr_val.v.val_offset = offset;
5045 add_dwarf_attr (die, attr);
5048 static inline const char *
5049 AT_lbl (dw_attr_ref a)
5051 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5052 || AT_class (a) == dw_val_class_lbl_offset));
5053 return a->dw_attr_val.v.val_lbl_id;
5056 /* Get the attribute of type attr_kind. */
5059 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5062 dw_die_ref spec = NULL;
5066 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5067 if (a->dw_attr == attr_kind)
5069 else if (a->dw_attr == DW_AT_specification
5070 || a->dw_attr == DW_AT_abstract_origin)
5074 return get_AT (spec, attr_kind);
5080 /* Return the "low pc" attribute value, typically associated with a subprogram
5081 DIE. Return null if the "low pc" attribute is either not present, or if it
5082 cannot be represented as an assembler label identifier. */
5084 static inline const char *
5085 get_AT_low_pc (dw_die_ref die)
5087 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
5089 return a ? AT_lbl (a) : NULL;
5092 /* Return the "high pc" attribute value, typically associated with a subprogram
5093 DIE. Return null if the "high pc" attribute is either not present, or if it
5094 cannot be represented as an assembler label identifier. */
5096 static inline const char *
5097 get_AT_hi_pc (dw_die_ref die)
5099 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
5101 return a ? AT_lbl (a) : NULL;
5104 /* Return the value of the string attribute designated by ATTR_KIND, or
5105 NULL if it is not present. */
5107 static inline const char *
5108 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5110 dw_attr_ref a = get_AT (die, attr_kind);
5112 return a ? AT_string (a) : NULL;
5115 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5116 if it is not present. */
5119 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5121 dw_attr_ref a = get_AT (die, attr_kind);
5123 return a ? AT_flag (a) : 0;
5126 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5127 if it is not present. */
5129 static inline unsigned
5130 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5132 dw_attr_ref a = get_AT (die, attr_kind);
5134 return a ? AT_unsigned (a) : 0;
5137 static inline dw_die_ref
5138 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5140 dw_attr_ref a = get_AT (die, attr_kind);
5142 return a ? AT_ref (a) : NULL;
5145 /* Return TRUE if the language is C or C++. */
5150 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5152 return (lang == DW_LANG_C || lang == DW_LANG_C89
5153 || lang == DW_LANG_C_plus_plus);
5156 /* Return TRUE if the language is C++. */
5161 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
5162 == DW_LANG_C_plus_plus);
5165 /* Return TRUE if the language is Fortran. */
5170 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5172 return (lang == DW_LANG_Fortran77
5173 || lang == DW_LANG_Fortran90
5174 || lang == DW_LANG_Fortran95);
5177 /* Return TRUE if the language is Java. */
5182 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5184 return lang == DW_LANG_Java;
5187 /* Return TRUE if the language is Ada. */
5192 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5194 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5197 /* Free up the memory used by A. */
5199 static inline void free_AT (dw_attr_ref);
5201 free_AT (dw_attr_ref a)
5203 if (AT_class (a) == dw_val_class_str)
5204 if (a->dw_attr_val.v.val_str->refcount)
5205 a->dw_attr_val.v.val_str->refcount--;
5208 /* Remove the specified attribute if present. */
5211 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5214 dw_attr_ref removed = NULL;
5218 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
5219 if ((*p)->dw_attr == attr_kind)
5222 *p = (*p)->dw_attr_next;
5231 /* Remove child die whose die_tag is specified tag. */
5234 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5236 dw_die_ref current, prev, next;
5237 current = die->die_child;
5239 while (current != NULL)
5241 if (current->die_tag == tag)
5243 next = current->die_sib;
5245 die->die_child = next;
5247 prev->die_sib = next;
5254 current = current->die_sib;
5259 /* Free up the memory used by DIE. */
5262 free_die (dw_die_ref die)
5264 remove_children (die);
5267 /* Discard the children of this DIE. */
5270 remove_children (dw_die_ref die)
5272 dw_die_ref child_die = die->die_child;
5274 die->die_child = NULL;
5276 while (child_die != NULL)
5278 dw_die_ref tmp_die = child_die;
5281 child_die = child_die->die_sib;
5283 for (a = tmp_die->die_attr; a != NULL;)
5285 dw_attr_ref tmp_a = a;
5287 a = a->dw_attr_next;
5295 /* Add a child DIE below its parent. We build the lists up in reverse
5296 addition order, and correct that in reverse_all_dies. */
5299 add_child_die (dw_die_ref die, dw_die_ref child_die)
5301 if (die != NULL && child_die != NULL)
5303 gcc_assert (die != child_die);
5305 child_die->die_parent = die;
5306 child_die->die_sib = die->die_child;
5307 die->die_child = child_die;
5311 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5312 is the specification, to the front of PARENT's list of children. */
5315 splice_child_die (dw_die_ref parent, dw_die_ref child)
5319 /* We want the declaration DIE from inside the class, not the
5320 specification DIE at toplevel. */
5321 if (child->die_parent != parent)
5323 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5329 gcc_assert (child->die_parent == parent
5330 || (child->die_parent
5331 == get_AT_ref (parent, DW_AT_specification)));
5333 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5336 *p = child->die_sib;
5340 child->die_parent = parent;
5341 child->die_sib = parent->die_child;
5342 parent->die_child = child;
5345 /* Return a pointer to a newly created DIE node. */
5347 static inline dw_die_ref
5348 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5350 dw_die_ref die = ggc_alloc_cleared (sizeof (die_node));
5352 die->die_tag = tag_value;
5354 if (parent_die != NULL)
5355 add_child_die (parent_die, die);
5358 limbo_die_node *limbo_node;
5360 limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node));
5361 limbo_node->die = die;
5362 limbo_node->created_for = t;
5363 limbo_node->next = limbo_die_list;
5364 limbo_die_list = limbo_node;
5370 /* Return the DIE associated with the given type specifier. */
5372 static inline dw_die_ref
5373 lookup_type_die (tree type)
5375 return TYPE_SYMTAB_DIE (type);
5378 /* Equate a DIE to a given type specifier. */
5381 equate_type_number_to_die (tree type, dw_die_ref type_die)
5383 TYPE_SYMTAB_DIE (type) = type_die;
5386 /* Returns a hash value for X (which really is a die_struct). */
5389 decl_die_table_hash (const void *x)
5391 return (hashval_t) ((const dw_die_ref) x)->decl_id;
5394 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5397 decl_die_table_eq (const void *x, const void *y)
5399 return (((const dw_die_ref) x)->decl_id == DECL_UID ((const tree) y));
5402 /* Return the DIE associated with a given declaration. */
5404 static inline dw_die_ref
5405 lookup_decl_die (tree decl)
5407 return htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5410 /* Returns a hash value for X (which really is a var_loc_list). */
5413 decl_loc_table_hash (const void *x)
5415 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5418 /* Return nonzero if decl_id of var_loc_list X is the same as
5422 decl_loc_table_eq (const void *x, const void *y)
5424 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const tree) y));
5427 /* Return the var_loc list associated with a given declaration. */
5429 static inline var_loc_list *
5430 lookup_decl_loc (tree decl)
5432 return htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5435 /* Equate a DIE to a particular declaration. */
5438 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5440 unsigned int decl_id = DECL_UID (decl);
5443 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5445 decl_die->decl_id = decl_id;
5448 /* Add a variable location node to the linked list for DECL. */
5451 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
5453 unsigned int decl_id = DECL_UID (decl);
5457 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5460 temp = ggc_alloc_cleared (sizeof (var_loc_list));
5461 temp->decl_id = decl_id;
5469 /* If the current location is the same as the end of the list,
5470 we have nothing to do. */
5471 if (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
5472 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
5474 /* Add LOC to the end of list and update LAST. */
5475 temp->last->next = loc;
5479 /* Do not add empty location to the beginning of the list. */
5480 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
5487 /* Keep track of the number of spaces used to indent the
5488 output of the debugging routines that print the structure of
5489 the DIE internal representation. */
5490 static int print_indent;
5492 /* Indent the line the number of spaces given by print_indent. */
5495 print_spaces (FILE *outfile)
5497 fprintf (outfile, "%*s", print_indent, "");
5500 /* Print the information associated with a given DIE, and its children.
5501 This routine is a debugging aid only. */
5504 print_die (dw_die_ref die, FILE *outfile)
5509 print_spaces (outfile);
5510 fprintf (outfile, "DIE %4lu: %s\n",
5511 die->die_offset, dwarf_tag_name (die->die_tag));
5512 print_spaces (outfile);
5513 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5514 fprintf (outfile, " offset: %lu\n", die->die_offset);
5516 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5518 print_spaces (outfile);
5519 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5521 switch (AT_class (a))
5523 case dw_val_class_addr:
5524 fprintf (outfile, "address");
5526 case dw_val_class_offset:
5527 fprintf (outfile, "offset");
5529 case dw_val_class_loc:
5530 fprintf (outfile, "location descriptor");
5532 case dw_val_class_loc_list:
5533 fprintf (outfile, "location list -> label:%s",
5534 AT_loc_list (a)->ll_symbol);
5536 case dw_val_class_range_list:
5537 fprintf (outfile, "range list");
5539 case dw_val_class_const:
5540 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5542 case dw_val_class_unsigned_const:
5543 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5545 case dw_val_class_long_long:
5546 fprintf (outfile, "constant (%lu,%lu)",
5547 a->dw_attr_val.v.val_long_long.hi,
5548 a->dw_attr_val.v.val_long_long.low);
5550 case dw_val_class_vec:
5551 fprintf (outfile, "floating-point or vector constant");
5553 case dw_val_class_flag:
5554 fprintf (outfile, "%u", AT_flag (a));
5556 case dw_val_class_die_ref:
5557 if (AT_ref (a) != NULL)
5559 if (AT_ref (a)->die_symbol)
5560 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5562 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5565 fprintf (outfile, "die -> <null>");
5567 case dw_val_class_lbl_id:
5568 case dw_val_class_lbl_offset:
5569 fprintf (outfile, "label: %s", AT_lbl (a));
5571 case dw_val_class_str:
5572 if (AT_string (a) != NULL)
5573 fprintf (outfile, "\"%s\"", AT_string (a));
5575 fprintf (outfile, "<null>");
5581 fprintf (outfile, "\n");
5584 if (die->die_child != NULL)
5587 for (c = die->die_child; c != NULL; c = c->die_sib)
5588 print_die (c, outfile);
5592 if (print_indent == 0)
5593 fprintf (outfile, "\n");
5596 /* Print the contents of the source code line number correspondence table.
5597 This routine is a debugging aid only. */
5600 print_dwarf_line_table (FILE *outfile)
5603 dw_line_info_ref line_info;
5605 fprintf (outfile, "\n\nDWARF source line information\n");
5606 for (i = 1; i < line_info_table_in_use; i++)
5608 line_info = &line_info_table[i];
5609 fprintf (outfile, "%5d: ", i);
5610 fprintf (outfile, "%-20s",
5611 VARRAY_CHAR_PTR (file_table, line_info->dw_file_num));
5612 fprintf (outfile, "%6ld", line_info->dw_line_num);
5613 fprintf (outfile, "\n");
5616 fprintf (outfile, "\n\n");
5619 /* Print the information collected for a given DIE. */
5622 debug_dwarf_die (dw_die_ref die)
5624 print_die (die, stderr);
5627 /* Print all DWARF information collected for the compilation unit.
5628 This routine is a debugging aid only. */
5634 print_die (comp_unit_die, stderr);
5635 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5636 print_dwarf_line_table (stderr);
5639 /* We build up the lists of children and attributes by pushing new ones
5640 onto the beginning of the list. Reverse the lists for DIE so that
5641 they are in order of addition. */
5644 reverse_die_lists (dw_die_ref die)
5646 dw_die_ref c, cp, cn;
5647 dw_attr_ref a, ap, an;
5649 for (a = die->die_attr, ap = 0; a; a = an)
5651 an = a->dw_attr_next;
5652 a->dw_attr_next = ap;
5658 for (c = die->die_child, cp = 0; c; c = cn)
5665 die->die_child = cp;
5668 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5669 reverse all dies in add_sibling_attributes, which runs through all the dies,
5670 it would reverse all the dies. Now, however, since we don't call
5671 reverse_die_lists in add_sibling_attributes, we need a routine to
5672 recursively reverse all the dies. This is that routine. */
5675 reverse_all_dies (dw_die_ref die)
5679 reverse_die_lists (die);
5681 for (c = die->die_child; c; c = c->die_sib)
5682 reverse_all_dies (c);
5685 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5686 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5687 DIE that marks the start of the DIEs for this include file. */
5690 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5692 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5693 dw_die_ref new_unit = gen_compile_unit_die (filename);
5695 new_unit->die_sib = old_unit;
5699 /* Close an include-file CU and reopen the enclosing one. */
5702 pop_compile_unit (dw_die_ref old_unit)
5704 dw_die_ref new_unit = old_unit->die_sib;
5706 old_unit->die_sib = NULL;
5710 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5711 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5713 /* Calculate the checksum of a location expression. */
5716 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5718 CHECKSUM (loc->dw_loc_opc);
5719 CHECKSUM (loc->dw_loc_oprnd1);
5720 CHECKSUM (loc->dw_loc_oprnd2);
5723 /* Calculate the checksum of an attribute. */
5726 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5728 dw_loc_descr_ref loc;
5731 CHECKSUM (at->dw_attr);
5733 /* We don't care about differences in file numbering. */
5734 if (at->dw_attr == DW_AT_decl_file
5735 /* Or that this was compiled with a different compiler snapshot; if
5736 the output is the same, that's what matters. */
5737 || at->dw_attr == DW_AT_producer)
5740 switch (AT_class (at))
5742 case dw_val_class_const:
5743 CHECKSUM (at->dw_attr_val.v.val_int);
5745 case dw_val_class_unsigned_const:
5746 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5748 case dw_val_class_long_long:
5749 CHECKSUM (at->dw_attr_val.v.val_long_long);
5751 case dw_val_class_vec:
5752 CHECKSUM (at->dw_attr_val.v.val_vec);
5754 case dw_val_class_flag:
5755 CHECKSUM (at->dw_attr_val.v.val_flag);
5757 case dw_val_class_str:
5758 CHECKSUM_STRING (AT_string (at));
5761 case dw_val_class_addr:
5763 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5764 CHECKSUM_STRING (XSTR (r, 0));
5767 case dw_val_class_offset:
5768 CHECKSUM (at->dw_attr_val.v.val_offset);
5771 case dw_val_class_loc:
5772 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5773 loc_checksum (loc, ctx);
5776 case dw_val_class_die_ref:
5777 die_checksum (AT_ref (at), ctx, mark);
5780 case dw_val_class_fde_ref:
5781 case dw_val_class_lbl_id:
5782 case dw_val_class_lbl_offset:
5790 /* Calculate the checksum of a DIE. */
5793 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5798 /* To avoid infinite recursion. */
5801 CHECKSUM (die->die_mark);
5804 die->die_mark = ++(*mark);
5806 CHECKSUM (die->die_tag);
5808 for (a = die->die_attr; a; a = a->dw_attr_next)
5809 attr_checksum (a, ctx, mark);
5811 for (c = die->die_child; c; c = c->die_sib)
5812 die_checksum (c, ctx, mark);
5816 #undef CHECKSUM_STRING
5818 /* Do the location expressions look same? */
5820 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
5822 return loc1->dw_loc_opc == loc2->dw_loc_opc
5823 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
5824 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
5827 /* Do the values look the same? */
5829 same_dw_val_p (dw_val_node *v1, dw_val_node *v2, int *mark)
5831 dw_loc_descr_ref loc1, loc2;
5834 if (v1->val_class != v2->val_class)
5837 switch (v1->val_class)
5839 case dw_val_class_const:
5840 return v1->v.val_int == v2->v.val_int;
5841 case dw_val_class_unsigned_const:
5842 return v1->v.val_unsigned == v2->v.val_unsigned;
5843 case dw_val_class_long_long:
5844 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
5845 && v1->v.val_long_long.low == v2->v.val_long_long.low;
5846 case dw_val_class_vec:
5847 if (v1->v.val_vec.length != v2->v.val_vec.length
5848 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
5850 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
5851 v1->v.val_vec.length * v1->v.val_vec.elt_size))
5854 case dw_val_class_flag:
5855 return v1->v.val_flag == v2->v.val_flag;
5856 case dw_val_class_str:
5857 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
5859 case dw_val_class_addr:
5860 r1 = v1->v.val_addr;
5861 r2 = v2->v.val_addr;
5862 if (GET_CODE (r1) != GET_CODE (r2))
5864 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
5865 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
5867 case dw_val_class_offset:
5868 return v1->v.val_offset == v2->v.val_offset;
5870 case dw_val_class_loc:
5871 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
5873 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
5874 if (!same_loc_p (loc1, loc2, mark))
5876 return !loc1 && !loc2;
5878 case dw_val_class_die_ref:
5879 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
5881 case dw_val_class_fde_ref:
5882 case dw_val_class_lbl_id:
5883 case dw_val_class_lbl_offset:
5891 /* Do the attributes look the same? */
5894 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
5896 if (at1->dw_attr != at2->dw_attr)
5899 /* We don't care about differences in file numbering. */
5900 if (at1->dw_attr == DW_AT_decl_file
5901 /* Or that this was compiled with a different compiler snapshot; if
5902 the output is the same, that's what matters. */
5903 || at1->dw_attr == DW_AT_producer)
5906 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
5909 /* Do the dies look the same? */
5912 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
5917 /* To avoid infinite recursion. */
5919 return die1->die_mark == die2->die_mark;
5920 die1->die_mark = die2->die_mark = ++(*mark);
5922 if (die1->die_tag != die2->die_tag)
5925 for (a1 = die1->die_attr, a2 = die2->die_attr;
5927 a1 = a1->dw_attr_next, a2 = a2->dw_attr_next)
5928 if (!same_attr_p (a1, a2, mark))
5933 for (c1 = die1->die_child, c2 = die2->die_child;
5935 c1 = c1->die_sib, c2 = c2->die_sib)
5936 if (!same_die_p (c1, c2, mark))
5944 /* Do the dies look the same? Wrapper around same_die_p. */
5947 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
5950 int ret = same_die_p (die1, die2, &mark);
5952 unmark_all_dies (die1);
5953 unmark_all_dies (die2);
5958 /* The prefix to attach to symbols on DIEs in the current comdat debug
5960 static char *comdat_symbol_id;
5962 /* The index of the current symbol within the current comdat CU. */
5963 static unsigned int comdat_symbol_number;
5965 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5966 children, and set comdat_symbol_id accordingly. */
5969 compute_section_prefix (dw_die_ref unit_die)
5971 const char *die_name = get_AT_string (unit_die, DW_AT_name);
5972 const char *base = die_name ? lbasename (die_name) : "anonymous";
5973 char *name = alloca (strlen (base) + 64);
5976 unsigned char checksum[16];
5979 /* Compute the checksum of the DIE, then append part of it as hex digits to
5980 the name filename of the unit. */
5982 md5_init_ctx (&ctx);
5984 die_checksum (unit_die, &ctx, &mark);
5985 unmark_all_dies (unit_die);
5986 md5_finish_ctx (&ctx, checksum);
5988 sprintf (name, "%s.", base);
5989 clean_symbol_name (name);
5991 p = name + strlen (name);
5992 for (i = 0; i < 4; i++)
5994 sprintf (p, "%.2x", checksum[i]);
5998 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5999 comdat_symbol_number = 0;
6002 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6005 is_type_die (dw_die_ref die)
6007 switch (die->die_tag)
6009 case DW_TAG_array_type:
6010 case DW_TAG_class_type:
6011 case DW_TAG_enumeration_type:
6012 case DW_TAG_pointer_type:
6013 case DW_TAG_reference_type:
6014 case DW_TAG_string_type:
6015 case DW_TAG_structure_type:
6016 case DW_TAG_subroutine_type:
6017 case DW_TAG_union_type:
6018 case DW_TAG_ptr_to_member_type:
6019 case DW_TAG_set_type:
6020 case DW_TAG_subrange_type:
6021 case DW_TAG_base_type:
6022 case DW_TAG_const_type:
6023 case DW_TAG_file_type:
6024 case DW_TAG_packed_type:
6025 case DW_TAG_volatile_type:
6026 case DW_TAG_typedef:
6033 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6034 Basically, we want to choose the bits that are likely to be shared between
6035 compilations (types) and leave out the bits that are specific to individual
6036 compilations (functions). */
6039 is_comdat_die (dw_die_ref c)
6041 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6042 we do for stabs. The advantage is a greater likelihood of sharing between
6043 objects that don't include headers in the same order (and therefore would
6044 put the base types in a different comdat). jason 8/28/00 */
6046 if (c->die_tag == DW_TAG_base_type)
6049 if (c->die_tag == DW_TAG_pointer_type
6050 || c->die_tag == DW_TAG_reference_type
6051 || c->die_tag == DW_TAG_const_type
6052 || c->die_tag == DW_TAG_volatile_type)
6054 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6056 return t ? is_comdat_die (t) : 0;
6059 return is_type_die (c);
6062 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6063 compilation unit. */
6066 is_symbol_die (dw_die_ref c)
6068 return (is_type_die (c)
6069 || (get_AT (c, DW_AT_declaration)
6070 && !get_AT (c, DW_AT_specification)));
6074 gen_internal_sym (const char *prefix)
6078 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6079 return xstrdup (buf);
6082 /* Assign symbols to all worthy DIEs under DIE. */
6085 assign_symbol_names (dw_die_ref die)
6089 if (is_symbol_die (die))
6091 if (comdat_symbol_id)
6093 char *p = alloca (strlen (comdat_symbol_id) + 64);
6095 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6096 comdat_symbol_id, comdat_symbol_number++);
6097 die->die_symbol = xstrdup (p);
6100 die->die_symbol = gen_internal_sym ("LDIE");
6103 for (c = die->die_child; c != NULL; c = c->die_sib)
6104 assign_symbol_names (c);
6107 struct cu_hash_table_entry
6110 unsigned min_comdat_num, max_comdat_num;
6111 struct cu_hash_table_entry *next;
6114 /* Routines to manipulate hash table of CUs. */
6116 htab_cu_hash (const void *of)
6118 const struct cu_hash_table_entry *entry = of;
6120 return htab_hash_string (entry->cu->die_symbol);
6124 htab_cu_eq (const void *of1, const void *of2)
6126 const struct cu_hash_table_entry *entry1 = of1;
6127 const struct die_struct *entry2 = of2;
6129 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
6133 htab_cu_del (void *what)
6135 struct cu_hash_table_entry *next, *entry = what;
6145 /* Check whether we have already seen this CU and set up SYM_NUM
6148 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6150 struct cu_hash_table_entry dummy;
6151 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6153 dummy.max_comdat_num = 0;
6155 slot = (struct cu_hash_table_entry **)
6156 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6160 for (; entry; last = entry, entry = entry->next)
6162 if (same_die_p_wrap (cu, entry->cu))
6168 *sym_num = entry->min_comdat_num;
6172 entry = xcalloc (1, sizeof (struct cu_hash_table_entry));
6174 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6175 entry->next = *slot;
6181 /* Record SYM_NUM to record of CU in HTABLE. */
6183 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6185 struct cu_hash_table_entry **slot, *entry;
6187 slot = (struct cu_hash_table_entry **)
6188 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6192 entry->max_comdat_num = sym_num;
6195 /* Traverse the DIE (which is always comp_unit_die), and set up
6196 additional compilation units for each of the include files we see
6197 bracketed by BINCL/EINCL. */
6200 break_out_includes (dw_die_ref die)
6203 dw_die_ref unit = NULL;
6204 limbo_die_node *node, **pnode;
6205 htab_t cu_hash_table;
6207 for (ptr = &(die->die_child); *ptr;)
6209 dw_die_ref c = *ptr;
6211 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6212 || (unit && is_comdat_die (c)))
6214 /* This DIE is for a secondary CU; remove it from the main one. */
6217 if (c->die_tag == DW_TAG_GNU_BINCL)
6219 unit = push_new_compile_unit (unit, c);
6222 else if (c->die_tag == DW_TAG_GNU_EINCL)
6224 unit = pop_compile_unit (unit);
6228 add_child_die (unit, c);
6232 /* Leave this DIE in the main CU. */
6233 ptr = &(c->die_sib);
6239 /* We can only use this in debugging, since the frontend doesn't check
6240 to make sure that we leave every include file we enter. */
6244 assign_symbol_names (die);
6245 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6246 for (node = limbo_die_list, pnode = &limbo_die_list;
6252 compute_section_prefix (node->die);
6253 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6254 &comdat_symbol_number);
6255 assign_symbol_names (node->die);
6257 *pnode = node->next;
6260 pnode = &node->next;
6261 record_comdat_symbol_number (node->die, cu_hash_table,
6262 comdat_symbol_number);
6265 htab_delete (cu_hash_table);
6268 /* Traverse the DIE and add a sibling attribute if it may have the
6269 effect of speeding up access to siblings. To save some space,
6270 avoid generating sibling attributes for DIE's without children. */
6273 add_sibling_attributes (dw_die_ref die)
6277 if (die->die_tag != DW_TAG_compile_unit
6278 && die->die_sib && die->die_child != NULL)
6279 /* Add the sibling link to the front of the attribute list. */
6280 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
6282 for (c = die->die_child; c != NULL; c = c->die_sib)
6283 add_sibling_attributes (c);
6286 /* Output all location lists for the DIE and its children. */
6289 output_location_lists (dw_die_ref die)
6294 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
6295 if (AT_class (d_attr) == dw_val_class_loc_list)
6296 output_loc_list (AT_loc_list (d_attr));
6298 for (c = die->die_child; c != NULL; c = c->die_sib)
6299 output_location_lists (c);
6303 /* The format of each DIE (and its attribute value pairs) is encoded in an
6304 abbreviation table. This routine builds the abbreviation table and assigns
6305 a unique abbreviation id for each abbreviation entry. The children of each
6306 die are visited recursively. */
6309 build_abbrev_table (dw_die_ref die)
6311 unsigned long abbrev_id;
6312 unsigned int n_alloc;
6314 dw_attr_ref d_attr, a_attr;
6316 /* Scan the DIE references, and mark as external any that refer to
6317 DIEs from other CUs (i.e. those which are not marked). */
6318 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
6319 if (AT_class (d_attr) == dw_val_class_die_ref
6320 && AT_ref (d_attr)->die_mark == 0)
6322 gcc_assert (AT_ref (d_attr)->die_symbol);
6324 set_AT_ref_external (d_attr, 1);
6327 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6329 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6331 if (abbrev->die_tag == die->die_tag)
6333 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
6335 a_attr = abbrev->die_attr;
6336 d_attr = die->die_attr;
6338 while (a_attr != NULL && d_attr != NULL)
6340 if ((a_attr->dw_attr != d_attr->dw_attr)
6341 || (value_format (a_attr) != value_format (d_attr)))
6344 a_attr = a_attr->dw_attr_next;
6345 d_attr = d_attr->dw_attr_next;
6348 if (a_attr == NULL && d_attr == NULL)
6354 if (abbrev_id >= abbrev_die_table_in_use)
6356 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
6358 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
6359 abbrev_die_table = ggc_realloc (abbrev_die_table,
6360 sizeof (dw_die_ref) * n_alloc);
6362 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
6363 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
6364 abbrev_die_table_allocated = n_alloc;
6367 ++abbrev_die_table_in_use;
6368 abbrev_die_table[abbrev_id] = die;
6371 die->die_abbrev = abbrev_id;
6372 for (c = die->die_child; c != NULL; c = c->die_sib)
6373 build_abbrev_table (c);
6376 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6379 constant_size (long unsigned int value)
6386 log = floor_log2 (value);
6389 log = 1 << (floor_log2 (log) + 1);
6394 /* Return the size of a DIE as it is represented in the
6395 .debug_info section. */
6397 static unsigned long
6398 size_of_die (dw_die_ref die)
6400 unsigned long size = 0;
6403 size += size_of_uleb128 (die->die_abbrev);
6404 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6406 switch (AT_class (a))
6408 case dw_val_class_addr:
6409 size += DWARF2_ADDR_SIZE;
6411 case dw_val_class_offset:
6412 size += DWARF_OFFSET_SIZE;
6414 case dw_val_class_loc:
6416 unsigned long lsize = size_of_locs (AT_loc (a));
6419 size += constant_size (lsize);
6423 case dw_val_class_loc_list:
6424 size += DWARF_OFFSET_SIZE;
6426 case dw_val_class_range_list:
6427 size += DWARF_OFFSET_SIZE;
6429 case dw_val_class_const:
6430 size += size_of_sleb128 (AT_int (a));
6432 case dw_val_class_unsigned_const:
6433 size += constant_size (AT_unsigned (a));
6435 case dw_val_class_long_long:
6436 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
6438 case dw_val_class_vec:
6439 size += 1 + (a->dw_attr_val.v.val_vec.length
6440 * a->dw_attr_val.v.val_vec.elt_size); /* block */
6442 case dw_val_class_flag:
6445 case dw_val_class_die_ref:
6446 if (AT_ref_external (a))
6447 size += DWARF2_ADDR_SIZE;
6449 size += DWARF_OFFSET_SIZE;
6451 case dw_val_class_fde_ref:
6452 size += DWARF_OFFSET_SIZE;
6454 case dw_val_class_lbl_id:
6455 size += DWARF2_ADDR_SIZE;
6457 case dw_val_class_lbl_offset:
6458 size += DWARF_OFFSET_SIZE;
6460 case dw_val_class_str:
6461 if (AT_string_form (a) == DW_FORM_strp)
6462 size += DWARF_OFFSET_SIZE;
6464 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
6474 /* Size the debugging information associated with a given DIE. Visits the
6475 DIE's children recursively. Updates the global variable next_die_offset, on
6476 each time through. Uses the current value of next_die_offset to update the
6477 die_offset field in each DIE. */
6480 calc_die_sizes (dw_die_ref die)
6484 die->die_offset = next_die_offset;
6485 next_die_offset += size_of_die (die);
6487 for (c = die->die_child; c != NULL; c = c->die_sib)
6490 if (die->die_child != NULL)
6491 /* Count the null byte used to terminate sibling lists. */
6492 next_die_offset += 1;
6495 /* Set the marks for a die and its children. We do this so
6496 that we know whether or not a reference needs to use FORM_ref_addr; only
6497 DIEs in the same CU will be marked. We used to clear out the offset
6498 and use that as the flag, but ran into ordering problems. */
6501 mark_dies (dw_die_ref die)
6505 gcc_assert (!die->die_mark);
6508 for (c = die->die_child; c; c = c->die_sib)
6512 /* Clear the marks for a die and its children. */
6515 unmark_dies (dw_die_ref die)
6519 gcc_assert (die->die_mark);
6522 for (c = die->die_child; c; c = c->die_sib)
6526 /* Clear the marks for a die, its children and referred dies. */
6529 unmark_all_dies (dw_die_ref die)
6538 for (c = die->die_child; c; c = c->die_sib)
6539 unmark_all_dies (c);
6541 for (a = die->die_attr; a; a = a->dw_attr_next)
6542 if (AT_class (a) == dw_val_class_die_ref)
6543 unmark_all_dies (AT_ref (a));
6546 /* Return the size of the .debug_pubnames table generated for the
6547 compilation unit. */
6549 static unsigned long
6550 size_of_pubnames (void)
6555 size = DWARF_PUBNAMES_HEADER_SIZE;
6556 for (i = 0; i < pubname_table_in_use; i++)
6558 pubname_ref p = &pubname_table[i];
6559 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
6562 size += DWARF_OFFSET_SIZE;
6566 /* Return the size of the information in the .debug_aranges section. */
6568 static unsigned long
6569 size_of_aranges (void)
6573 size = DWARF_ARANGES_HEADER_SIZE;
6575 /* Count the address/length pair for this compilation unit. */
6576 size += 2 * DWARF2_ADDR_SIZE;
6577 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6579 /* Count the two zero words used to terminated the address range table. */
6580 size += 2 * DWARF2_ADDR_SIZE;
6584 /* Select the encoding of an attribute value. */
6586 static enum dwarf_form
6587 value_format (dw_attr_ref a)
6589 switch (a->dw_attr_val.val_class)
6591 case dw_val_class_addr:
6592 return DW_FORM_addr;
6593 case dw_val_class_range_list:
6594 case dw_val_class_offset:
6595 switch (DWARF_OFFSET_SIZE)
6598 return DW_FORM_data4;
6600 return DW_FORM_data8;
6604 case dw_val_class_loc_list:
6605 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6606 .debug_loc section */
6607 return DW_FORM_data4;
6608 case dw_val_class_loc:
6609 switch (constant_size (size_of_locs (AT_loc (a))))
6612 return DW_FORM_block1;
6614 return DW_FORM_block2;
6618 case dw_val_class_const:
6619 return DW_FORM_sdata;
6620 case dw_val_class_unsigned_const:
6621 switch (constant_size (AT_unsigned (a)))
6624 return DW_FORM_data1;
6626 return DW_FORM_data2;
6628 return DW_FORM_data4;
6630 return DW_FORM_data8;
6634 case dw_val_class_long_long:
6635 return DW_FORM_block1;
6636 case dw_val_class_vec:
6637 return DW_FORM_block1;
6638 case dw_val_class_flag:
6639 return DW_FORM_flag;
6640 case dw_val_class_die_ref:
6641 if (AT_ref_external (a))
6642 return DW_FORM_ref_addr;
6645 case dw_val_class_fde_ref:
6646 return DW_FORM_data;
6647 case dw_val_class_lbl_id:
6648 return DW_FORM_addr;
6649 case dw_val_class_lbl_offset:
6650 return DW_FORM_data;
6651 case dw_val_class_str:
6652 return AT_string_form (a);
6659 /* Output the encoding of an attribute value. */
6662 output_value_format (dw_attr_ref a)
6664 enum dwarf_form form = value_format (a);
6666 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6669 /* Output the .debug_abbrev section which defines the DIE abbreviation
6673 output_abbrev_section (void)
6675 unsigned long abbrev_id;
6679 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6681 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6683 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6684 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6685 dwarf_tag_name (abbrev->die_tag));
6687 if (abbrev->die_child != NULL)
6688 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6690 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6692 for (a_attr = abbrev->die_attr; a_attr != NULL;
6693 a_attr = a_attr->dw_attr_next)
6695 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6696 dwarf_attr_name (a_attr->dw_attr));
6697 output_value_format (a_attr);
6700 dw2_asm_output_data (1, 0, NULL);
6701 dw2_asm_output_data (1, 0, NULL);
6704 /* Terminate the table. */
6705 dw2_asm_output_data (1, 0, NULL);
6708 /* Output a symbol we can use to refer to this DIE from another CU. */
6711 output_die_symbol (dw_die_ref die)
6713 char *sym = die->die_symbol;
6718 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6719 /* We make these global, not weak; if the target doesn't support
6720 .linkonce, it doesn't support combining the sections, so debugging
6722 targetm.asm_out.globalize_label (asm_out_file, sym);
6724 ASM_OUTPUT_LABEL (asm_out_file, sym);
6727 /* Return a new location list, given the begin and end range, and the
6728 expression. gensym tells us whether to generate a new internal symbol for
6729 this location list node, which is done for the head of the list only. */
6731 static inline dw_loc_list_ref
6732 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
6733 const char *section, unsigned int gensym)
6735 dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node));
6737 retlist->begin = begin;
6739 retlist->expr = expr;
6740 retlist->section = section;
6742 retlist->ll_symbol = gen_internal_sym ("LLST");
6747 /* Add a location description expression to a location list. */
6750 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
6751 const char *begin, const char *end,
6752 const char *section)
6756 /* Find the end of the chain. */
6757 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6760 /* Add a new location list node to the list. */
6761 *d = new_loc_list (descr, begin, end, section, 0);
6764 /* Output the location list given to us. */
6767 output_loc_list (dw_loc_list_ref list_head)
6769 dw_loc_list_ref curr = list_head;
6771 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6773 /* Walk the location list, and output each range + expression. */
6774 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
6777 if (separate_line_info_table_in_use == 0)
6779 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6780 "Location list begin address (%s)",
6781 list_head->ll_symbol);
6782 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6783 "Location list end address (%s)",
6784 list_head->ll_symbol);
6788 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
6789 "Location list begin address (%s)",
6790 list_head->ll_symbol);
6791 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
6792 "Location list end address (%s)",
6793 list_head->ll_symbol);
6795 size = size_of_locs (curr->expr);
6797 /* Output the block length for this list of location operations. */
6798 gcc_assert (size <= 0xffff);
6799 dw2_asm_output_data (2, size, "%s", "Location expression size");
6801 output_loc_sequence (curr->expr);
6804 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
6805 "Location list terminator begin (%s)",
6806 list_head->ll_symbol);
6807 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
6808 "Location list terminator end (%s)",
6809 list_head->ll_symbol);
6812 /* Output the DIE and its attributes. Called recursively to generate
6813 the definitions of each child DIE. */
6816 output_die (dw_die_ref die)
6822 /* If someone in another CU might refer to us, set up a symbol for
6823 them to point to. */
6824 if (die->die_symbol)
6825 output_die_symbol (die);
6827 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6828 die->die_offset, dwarf_tag_name (die->die_tag));
6830 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6832 const char *name = dwarf_attr_name (a->dw_attr);
6834 switch (AT_class (a))
6836 case dw_val_class_addr:
6837 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6840 case dw_val_class_offset:
6841 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6845 case dw_val_class_range_list:
6847 char *p = strchr (ranges_section_label, '\0');
6849 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
6850 a->dw_attr_val.v.val_offset);
6851 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6857 case dw_val_class_loc:
6858 size = size_of_locs (AT_loc (a));
6860 /* Output the block length for this list of location operations. */
6861 dw2_asm_output_data (constant_size (size), size, "%s", name);
6863 output_loc_sequence (AT_loc (a));
6866 case dw_val_class_const:
6867 /* ??? It would be slightly more efficient to use a scheme like is
6868 used for unsigned constants below, but gdb 4.x does not sign
6869 extend. Gdb 5.x does sign extend. */
6870 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6873 case dw_val_class_unsigned_const:
6874 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6875 AT_unsigned (a), "%s", name);
6878 case dw_val_class_long_long:
6880 unsigned HOST_WIDE_INT first, second;
6882 dw2_asm_output_data (1,
6883 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6886 if (WORDS_BIG_ENDIAN)
6888 first = a->dw_attr_val.v.val_long_long.hi;
6889 second = a->dw_attr_val.v.val_long_long.low;
6893 first = a->dw_attr_val.v.val_long_long.low;
6894 second = a->dw_attr_val.v.val_long_long.hi;
6897 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6898 first, "long long constant");
6899 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6904 case dw_val_class_vec:
6906 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
6907 unsigned int len = a->dw_attr_val.v.val_vec.length;
6911 dw2_asm_output_data (1, len * elt_size, "%s", name);
6912 if (elt_size > sizeof (HOST_WIDE_INT))
6917 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
6920 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
6921 "fp or vector constant word %u", i);
6925 case dw_val_class_flag:
6926 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6929 case dw_val_class_loc_list:
6931 char *sym = AT_loc_list (a)->ll_symbol;
6934 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, "%s", name);
6938 case dw_val_class_die_ref:
6939 if (AT_ref_external (a))
6941 char *sym = AT_ref (a)->die_symbol;
6944 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6948 gcc_assert (AT_ref (a)->die_offset);
6949 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6954 case dw_val_class_fde_ref:
6958 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6959 a->dw_attr_val.v.val_fde_index * 2);
6960 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6964 case dw_val_class_lbl_id:
6965 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6968 case dw_val_class_lbl_offset:
6969 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6972 case dw_val_class_str:
6973 if (AT_string_form (a) == DW_FORM_strp)
6974 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6975 a->dw_attr_val.v.val_str->label,
6976 "%s: \"%s\"", name, AT_string (a));
6978 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6986 for (c = die->die_child; c != NULL; c = c->die_sib)
6989 /* Add null byte to terminate sibling list. */
6990 if (die->die_child != NULL)
6991 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6995 /* Output the compilation unit that appears at the beginning of the
6996 .debug_info section, and precedes the DIE descriptions. */
6999 output_compilation_unit_header (void)
7001 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7002 dw2_asm_output_data (4, 0xffffffff,
7003 "Initial length escape value indicating 64-bit DWARF extension");
7004 dw2_asm_output_data (DWARF_OFFSET_SIZE,
7005 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
7006 "Length of Compilation Unit Info");
7007 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
7008 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
7009 "Offset Into Abbrev. Section");
7010 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
7013 /* Output the compilation unit DIE and its children. */
7016 output_comp_unit (dw_die_ref die, int output_if_empty)
7018 const char *secname;
7021 /* Unless we are outputting main CU, we may throw away empty ones. */
7022 if (!output_if_empty && die->die_child == NULL)
7025 /* Even if there are no children of this DIE, we must output the information
7026 about the compilation unit. Otherwise, on an empty translation unit, we
7027 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7028 will then complain when examining the file. First mark all the DIEs in
7029 this CU so we know which get local refs. */
7032 build_abbrev_table (die);
7034 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7035 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7036 calc_die_sizes (die);
7038 oldsym = die->die_symbol;
7041 tmp = alloca (strlen (oldsym) + 24);
7043 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
7045 die->die_symbol = NULL;
7048 secname = (const char *) DEBUG_INFO_SECTION;
7050 /* Output debugging information. */
7051 named_section_flags (secname, SECTION_DEBUG);
7052 output_compilation_unit_header ();
7055 /* Leave the marks on the main CU, so we can check them in
7060 die->die_symbol = oldsym;
7064 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
7065 output of lang_hooks.decl_printable_name for C++ looks like
7066 "A::f(int)". Let's drop the argument list, and maybe the scope. */
7069 dwarf2_name (tree decl, int scope)
7071 return lang_hooks.decl_printable_name (decl, scope ? 1 : 0);
7074 /* Add a new entry to .debug_pubnames if appropriate. */
7077 add_pubname (tree decl, dw_die_ref die)
7081 if (! TREE_PUBLIC (decl))
7084 if (pubname_table_in_use == pubname_table_allocated)
7086 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
7088 = ggc_realloc (pubname_table,
7089 (pubname_table_allocated * sizeof (pubname_entry)));
7090 memset (pubname_table + pubname_table_in_use, 0,
7091 PUBNAME_TABLE_INCREMENT * sizeof (pubname_entry));
7094 p = &pubname_table[pubname_table_in_use++];
7096 p->name = xstrdup (dwarf2_name (decl, 1));
7099 /* Output the public names table used to speed up access to externally
7100 visible names. For now, only generate entries for externally
7101 visible procedures. */
7104 output_pubnames (void)
7107 unsigned long pubnames_length = size_of_pubnames ();
7109 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7110 dw2_asm_output_data (4, 0xffffffff,
7111 "Initial length escape value indicating 64-bit DWARF extension");
7112 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7113 "Length of Public Names Info");
7114 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7115 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7116 "Offset of Compilation Unit Info");
7117 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
7118 "Compilation Unit Length");
7120 for (i = 0; i < pubname_table_in_use; i++)
7122 pubname_ref pub = &pubname_table[i];
7124 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7125 gcc_assert (pub->die->die_mark);
7127 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
7130 dw2_asm_output_nstring (pub->name, -1, "external name");
7133 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
7136 /* Add a new entry to .debug_aranges if appropriate. */
7139 add_arange (tree decl, dw_die_ref die)
7141 if (! DECL_SECTION_NAME (decl))
7144 if (arange_table_in_use == arange_table_allocated)
7146 arange_table_allocated += ARANGE_TABLE_INCREMENT;
7147 arange_table = ggc_realloc (arange_table,
7148 (arange_table_allocated
7149 * sizeof (dw_die_ref)));
7150 memset (arange_table + arange_table_in_use, 0,
7151 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
7154 arange_table[arange_table_in_use++] = die;
7157 /* Output the information that goes into the .debug_aranges table.
7158 Namely, define the beginning and ending address range of the
7159 text section generated for this compilation unit. */
7162 output_aranges (void)
7165 unsigned long aranges_length = size_of_aranges ();
7167 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7168 dw2_asm_output_data (4, 0xffffffff,
7169 "Initial length escape value indicating 64-bit DWARF extension");
7170 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
7171 "Length of Address Ranges Info");
7172 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7173 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7174 "Offset of Compilation Unit Info");
7175 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
7176 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7178 /* We need to align to twice the pointer size here. */
7179 if (DWARF_ARANGES_PAD_SIZE)
7181 /* Pad using a 2 byte words so that padding is correct for any
7183 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7184 2 * DWARF2_ADDR_SIZE);
7185 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
7186 dw2_asm_output_data (2, 0, NULL);
7189 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
7190 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
7191 text_section_label, "Length");
7193 for (i = 0; i < arange_table_in_use; i++)
7195 dw_die_ref die = arange_table[i];
7197 /* We shouldn't see aranges for DIEs outside of the main CU. */
7198 gcc_assert (die->die_mark);
7200 if (die->die_tag == DW_TAG_subprogram)
7202 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
7204 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
7205 get_AT_low_pc (die), "Length");
7209 /* A static variable; extract the symbol from DW_AT_location.
7210 Note that this code isn't currently hit, as we only emit
7211 aranges for functions (jason 9/23/99). */
7212 dw_attr_ref a = get_AT (die, DW_AT_location);
7213 dw_loc_descr_ref loc;
7215 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7218 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
7220 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
7221 loc->dw_loc_oprnd1.v.val_addr, "Address");
7222 dw2_asm_output_data (DWARF2_ADDR_SIZE,
7223 get_AT_unsigned (die, DW_AT_byte_size),
7228 /* Output the terminator words. */
7229 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7230 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7233 /* Add a new entry to .debug_ranges. Return the offset at which it
7237 add_ranges (tree block)
7239 unsigned int in_use = ranges_table_in_use;
7241 if (in_use == ranges_table_allocated)
7243 ranges_table_allocated += RANGES_TABLE_INCREMENT;
7245 = ggc_realloc (ranges_table, (ranges_table_allocated
7246 * sizeof (struct dw_ranges_struct)));
7247 memset (ranges_table + ranges_table_in_use, 0,
7248 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
7251 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
7252 ranges_table_in_use = in_use + 1;
7254 return in_use * 2 * DWARF2_ADDR_SIZE;
7258 output_ranges (void)
7261 static const char *const start_fmt = "Offset 0x%x";
7262 const char *fmt = start_fmt;
7264 for (i = 0; i < ranges_table_in_use; i++)
7266 int block_num = ranges_table[i].block_num;
7270 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
7271 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
7273 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
7274 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
7276 /* If all code is in the text section, then the compilation
7277 unit base address defaults to DW_AT_low_pc, which is the
7278 base of the text section. */
7279 if (separate_line_info_table_in_use == 0)
7281 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
7283 fmt, i * 2 * DWARF2_ADDR_SIZE);
7284 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
7285 text_section_label, NULL);
7288 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
7289 compilation unit base address to zero, which allows us to
7290 use absolute addresses, and not worry about whether the
7291 target supports cross-section arithmetic. */
7294 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
7295 fmt, i * 2 * DWARF2_ADDR_SIZE);
7296 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
7303 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7304 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7310 /* Data structure containing information about input files. */
7313 char *path; /* Complete file name. */
7314 char *fname; /* File name part. */
7315 int length; /* Length of entire string. */
7316 int file_idx; /* Index in input file table. */
7317 int dir_idx; /* Index in directory table. */
7320 /* Data structure containing information about directories with source
7324 char *path; /* Path including directory name. */
7325 int length; /* Path length. */
7326 int prefix; /* Index of directory entry which is a prefix. */
7327 int count; /* Number of files in this directory. */
7328 int dir_idx; /* Index of directory used as base. */
7329 int used; /* Used in the end? */
7332 /* Callback function for file_info comparison. We sort by looking at
7333 the directories in the path. */
7336 file_info_cmp (const void *p1, const void *p2)
7338 const struct file_info *s1 = p1;
7339 const struct file_info *s2 = p2;
7343 /* Take care of file names without directories. We need to make sure that
7344 we return consistent values to qsort since some will get confused if
7345 we return the same value when identical operands are passed in opposite
7346 orders. So if neither has a directory, return 0 and otherwise return
7347 1 or -1 depending on which one has the directory. */
7348 if ((s1->path == s1->fname || s2->path == s2->fname))
7349 return (s2->path == s2->fname) - (s1->path == s1->fname);
7351 cp1 = (unsigned char *) s1->path;
7352 cp2 = (unsigned char *) s2->path;
7358 /* Reached the end of the first path? If so, handle like above. */
7359 if ((cp1 == (unsigned char *) s1->fname)
7360 || (cp2 == (unsigned char *) s2->fname))
7361 return ((cp2 == (unsigned char *) s2->fname)
7362 - (cp1 == (unsigned char *) s1->fname));
7364 /* Character of current path component the same? */
7365 else if (*cp1 != *cp2)
7370 /* Output the directory table and the file name table. We try to minimize
7371 the total amount of memory needed. A heuristic is used to avoid large
7372 slowdowns with many input files. */
7375 output_file_names (void)
7377 struct file_info *files;
7378 struct dir_info *dirs;
7387 /* Handle the case where file_table is empty. */
7388 if (VARRAY_ACTIVE_SIZE (file_table) <= 1)
7390 dw2_asm_output_data (1, 0, "End directory table");
7391 dw2_asm_output_data (1, 0, "End file name table");
7395 /* Allocate the various arrays we need. */
7396 files = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct file_info));
7397 dirs = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct dir_info));
7399 /* Sort the file names. */
7400 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7404 /* Skip all leading "./". */
7405 f = VARRAY_CHAR_PTR (file_table, i);
7406 while (f[0] == '.' && f[1] == '/')
7409 /* Create a new array entry. */
7411 files[i].length = strlen (f);
7412 files[i].file_idx = i;
7414 /* Search for the file name part. */
7415 f = strrchr (f, '/');
7416 files[i].fname = f == NULL ? files[i].path : f + 1;
7419 qsort (files + 1, VARRAY_ACTIVE_SIZE (file_table) - 1,
7420 sizeof (files[0]), file_info_cmp);
7422 /* Find all the different directories used. */
7423 dirs[0].path = files[1].path;
7424 dirs[0].length = files[1].fname - files[1].path;
7425 dirs[0].prefix = -1;
7427 dirs[0].dir_idx = 0;
7429 files[1].dir_idx = 0;
7432 for (i = 2; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7433 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
7434 && memcmp (dirs[ndirs - 1].path, files[i].path,
7435 dirs[ndirs - 1].length) == 0)
7437 /* Same directory as last entry. */
7438 files[i].dir_idx = ndirs - 1;
7439 ++dirs[ndirs - 1].count;
7445 /* This is a new directory. */
7446 dirs[ndirs].path = files[i].path;
7447 dirs[ndirs].length = files[i].fname - files[i].path;
7448 dirs[ndirs].count = 1;
7449 dirs[ndirs].dir_idx = ndirs;
7450 dirs[ndirs].used = 0;
7451 files[i].dir_idx = ndirs;
7453 /* Search for a prefix. */
7454 dirs[ndirs].prefix = -1;
7455 for (j = 0; j < ndirs; j++)
7456 if (dirs[j].length < dirs[ndirs].length
7457 && dirs[j].length > 1
7458 && (dirs[ndirs].prefix == -1
7459 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
7460 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
7461 dirs[ndirs].prefix = j;
7466 /* Now to the actual work. We have to find a subset of the directories which
7467 allow expressing the file name using references to the directory table
7468 with the least amount of characters. We do not do an exhaustive search
7469 where we would have to check out every combination of every single
7470 possible prefix. Instead we use a heuristic which provides nearly optimal
7471 results in most cases and never is much off. */
7472 saved = alloca (ndirs * sizeof (int));
7473 savehere = alloca (ndirs * sizeof (int));
7475 memset (saved, '\0', ndirs * sizeof (saved[0]));
7476 for (i = 0; i < ndirs; i++)
7481 /* We can always save some space for the current directory. But this
7482 does not mean it will be enough to justify adding the directory. */
7483 savehere[i] = dirs[i].length;
7484 total = (savehere[i] - saved[i]) * dirs[i].count;
7486 for (j = i + 1; j < ndirs; j++)
7489 if (saved[j] < dirs[i].length)
7491 /* Determine whether the dirs[i] path is a prefix of the
7496 while (k != -1 && k != (int) i)
7501 /* Yes it is. We can possibly safe some memory but
7502 writing the filenames in dirs[j] relative to
7504 savehere[j] = dirs[i].length;
7505 total += (savehere[j] - saved[j]) * dirs[j].count;
7510 /* Check whether we can safe enough to justify adding the dirs[i]
7512 if (total > dirs[i].length + 1)
7514 /* It's worthwhile adding. */
7515 for (j = i; j < ndirs; j++)
7516 if (savehere[j] > 0)
7518 /* Remember how much we saved for this directory so far. */
7519 saved[j] = savehere[j];
7521 /* Remember the prefix directory. */
7522 dirs[j].dir_idx = i;
7527 /* We have to emit them in the order they appear in the file_table array
7528 since the index is used in the debug info generation. To do this
7529 efficiently we generate a back-mapping of the indices first. */
7530 backmap = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (int));
7531 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7533 backmap[files[i].file_idx] = i;
7535 /* Mark this directory as used. */
7536 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
7539 /* That was it. We are ready to emit the information. First emit the
7540 directory name table. We have to make sure the first actually emitted
7541 directory name has index one; zero is reserved for the current working
7542 directory. Make sure we do not confuse these indices with the one for the
7543 constructed table (even though most of the time they are identical). */
7545 idx_offset = dirs[0].length > 0 ? 1 : 0;
7546 for (i = 1 - idx_offset; i < ndirs; i++)
7547 if (dirs[i].used != 0)
7549 dirs[i].used = idx++;
7550 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
7551 "Directory Entry: 0x%x", dirs[i].used);
7554 dw2_asm_output_data (1, 0, "End directory table");
7556 /* Correct the index for the current working directory entry if it
7558 if (idx_offset == 0)
7561 /* Now write all the file names. */
7562 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7564 int file_idx = backmap[i];
7565 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
7567 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
7568 "File Entry: 0x%lx", (unsigned long) i);
7570 /* Include directory index. */
7571 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
7573 /* Modification time. */
7574 dw2_asm_output_data_uleb128 (0, NULL);
7576 /* File length in bytes. */
7577 dw2_asm_output_data_uleb128 (0, NULL);
7580 dw2_asm_output_data (1, 0, "End file name table");
7584 /* Output the source line number correspondence information. This
7585 information goes into the .debug_line section. */
7588 output_line_info (void)
7590 char l1[20], l2[20], p1[20], p2[20];
7591 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7592 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7595 unsigned long lt_index;
7596 unsigned long current_line;
7599 unsigned long current_file;
7600 unsigned long function;
7602 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7603 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7604 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7605 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7607 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7608 dw2_asm_output_data (4, 0xffffffff,
7609 "Initial length escape value indicating 64-bit DWARF extension");
7610 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7611 "Length of Source Line Info");
7612 ASM_OUTPUT_LABEL (asm_out_file, l1);
7614 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7615 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7616 ASM_OUTPUT_LABEL (asm_out_file, p1);
7618 /* Define the architecture-dependent minimum instruction length (in
7619 bytes). In this implementation of DWARF, this field is used for
7620 information purposes only. Since GCC generates assembly language,
7621 we have no a priori knowledge of how many instruction bytes are
7622 generated for each source line, and therefore can use only the
7623 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7624 commands. Accordingly, we fix this as `1', which is "correct
7625 enough" for all architectures, and don't let the target override. */
7626 dw2_asm_output_data (1, 1,
7627 "Minimum Instruction Length");
7629 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7630 "Default is_stmt_start flag");
7631 dw2_asm_output_data (1, DWARF_LINE_BASE,
7632 "Line Base Value (Special Opcodes)");
7633 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7634 "Line Range Value (Special Opcodes)");
7635 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7636 "Special Opcode Base");
7638 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7642 case DW_LNS_advance_pc:
7643 case DW_LNS_advance_line:
7644 case DW_LNS_set_file:
7645 case DW_LNS_set_column:
7646 case DW_LNS_fixed_advance_pc:
7654 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7658 /* Write out the information about the files we use. */
7659 output_file_names ();
7660 ASM_OUTPUT_LABEL (asm_out_file, p2);
7662 /* We used to set the address register to the first location in the text
7663 section here, but that didn't accomplish anything since we already
7664 have a line note for the opening brace of the first function. */
7666 /* Generate the line number to PC correspondence table, encoded as
7667 a series of state machine operations. */
7670 strcpy (prev_line_label, text_section_label);
7671 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7673 dw_line_info_ref line_info = &line_info_table[lt_index];
7676 /* Disable this optimization for now; GDB wants to see two line notes
7677 at the beginning of a function so it can find the end of the
7680 /* Don't emit anything for redundant notes. Just updating the
7681 address doesn't accomplish anything, because we already assume
7682 that anything after the last address is this line. */
7683 if (line_info->dw_line_num == current_line
7684 && line_info->dw_file_num == current_file)
7688 /* Emit debug info for the address of the current line.
7690 Unfortunately, we have little choice here currently, and must always
7691 use the most general form. GCC does not know the address delta
7692 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7693 attributes which will give an upper bound on the address range. We
7694 could perhaps use length attributes to determine when it is safe to
7695 use DW_LNS_fixed_advance_pc. */
7697 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7700 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7701 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7702 "DW_LNS_fixed_advance_pc");
7703 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7707 /* This can handle any delta. This takes
7708 4+DWARF2_ADDR_SIZE bytes. */
7709 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7710 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7711 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7712 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7715 strcpy (prev_line_label, line_label);
7717 /* Emit debug info for the source file of the current line, if
7718 different from the previous line. */
7719 if (line_info->dw_file_num != current_file)
7721 current_file = line_info->dw_file_num;
7722 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7723 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7724 VARRAY_CHAR_PTR (file_table,
7728 /* Emit debug info for the current line number, choosing the encoding
7729 that uses the least amount of space. */
7730 if (line_info->dw_line_num != current_line)
7732 line_offset = line_info->dw_line_num - current_line;
7733 line_delta = line_offset - DWARF_LINE_BASE;
7734 current_line = line_info->dw_line_num;
7735 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7736 /* This can handle deltas from -10 to 234, using the current
7737 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7739 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7740 "line %lu", current_line);
7743 /* This can handle any delta. This takes at least 4 bytes,
7744 depending on the value being encoded. */
7745 dw2_asm_output_data (1, DW_LNS_advance_line,
7746 "advance to line %lu", current_line);
7747 dw2_asm_output_data_sleb128 (line_offset, NULL);
7748 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7752 /* We still need to start a new row, so output a copy insn. */
7753 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7756 /* Emit debug info for the address of the end of the function. */
7759 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7760 "DW_LNS_fixed_advance_pc");
7761 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7765 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7766 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7767 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7768 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7771 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7772 dw2_asm_output_data_uleb128 (1, NULL);
7773 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7778 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7780 dw_separate_line_info_ref line_info
7781 = &separate_line_info_table[lt_index];
7784 /* Don't emit anything for redundant notes. */
7785 if (line_info->dw_line_num == current_line
7786 && line_info->dw_file_num == current_file
7787 && line_info->function == function)
7791 /* Emit debug info for the address of the current line. If this is
7792 a new function, or the first line of a function, then we need
7793 to handle it differently. */
7794 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7796 if (function != line_info->function)
7798 function = line_info->function;
7800 /* Set the address register to the first line in the function. */
7801 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7802 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7803 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7804 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7808 /* ??? See the DW_LNS_advance_pc comment above. */
7811 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7812 "DW_LNS_fixed_advance_pc");
7813 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7817 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7818 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7819 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7820 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7824 strcpy (prev_line_label, line_label);
7826 /* Emit debug info for the source file of the current line, if
7827 different from the previous line. */
7828 if (line_info->dw_file_num != current_file)
7830 current_file = line_info->dw_file_num;
7831 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7832 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7833 VARRAY_CHAR_PTR (file_table,
7837 /* Emit debug info for the current line number, choosing the encoding
7838 that uses the least amount of space. */
7839 if (line_info->dw_line_num != current_line)
7841 line_offset = line_info->dw_line_num - current_line;
7842 line_delta = line_offset - DWARF_LINE_BASE;
7843 current_line = line_info->dw_line_num;
7844 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7845 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7846 "line %lu", current_line);
7849 dw2_asm_output_data (1, DW_LNS_advance_line,
7850 "advance to line %lu", current_line);
7851 dw2_asm_output_data_sleb128 (line_offset, NULL);
7852 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7856 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7864 /* If we're done with a function, end its sequence. */
7865 if (lt_index == separate_line_info_table_in_use
7866 || separate_line_info_table[lt_index].function != function)
7871 /* Emit debug info for the address of the end of the function. */
7872 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7875 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7876 "DW_LNS_fixed_advance_pc");
7877 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7881 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7882 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7883 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7884 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7887 /* Output the marker for the end of this sequence. */
7888 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7889 dw2_asm_output_data_uleb128 (1, NULL);
7890 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7894 /* Output the marker for the end of the line number info. */
7895 ASM_OUTPUT_LABEL (asm_out_file, l2);
7898 /* Given a pointer to a tree node for some base type, return a pointer to
7899 a DIE that describes the given type.
7901 This routine must only be called for GCC type nodes that correspond to
7902 Dwarf base (fundamental) types. */
7905 base_type_die (tree type)
7907 dw_die_ref base_type_result;
7908 const char *type_name;
7909 enum dwarf_type encoding;
7910 tree name = TYPE_NAME (type);
7912 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7917 if (TREE_CODE (name) == TYPE_DECL)
7918 name = DECL_NAME (name);
7920 type_name = IDENTIFIER_POINTER (name);
7923 type_name = "__unknown__";
7925 switch (TREE_CODE (type))
7928 /* Carefully distinguish the C character types, without messing
7929 up if the language is not C. Note that we check only for the names
7930 that contain spaces; other names might occur by coincidence in other
7932 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7933 && (type == char_type_node
7934 || ! strcmp (type_name, "signed char")
7935 || ! strcmp (type_name, "unsigned char"))))
7937 if (TYPE_UNSIGNED (type))
7938 encoding = DW_ATE_unsigned;
7940 encoding = DW_ATE_signed;
7943 /* else fall through. */
7946 /* GNU Pascal/Ada CHAR type. Not used in C. */
7947 if (TYPE_UNSIGNED (type))
7948 encoding = DW_ATE_unsigned_char;
7950 encoding = DW_ATE_signed_char;
7954 encoding = DW_ATE_float;
7957 /* Dwarf2 doesn't know anything about complex ints, so use
7958 a user defined type for it. */
7960 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7961 encoding = DW_ATE_complex_float;
7963 encoding = DW_ATE_lo_user;
7967 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7968 encoding = DW_ATE_boolean;
7972 /* No other TREE_CODEs are Dwarf fundamental types. */
7976 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
7977 if (demangle_name_func)
7978 type_name = (*demangle_name_func) (type_name);
7980 add_AT_string (base_type_result, DW_AT_name, type_name);
7981 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7982 int_size_in_bytes (type));
7983 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7985 return base_type_result;
7988 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7989 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7990 a given type is generally the same as the given type, except that if the
7991 given type is a pointer or reference type, then the root type of the given
7992 type is the root type of the "basis" type for the pointer or reference
7993 type. (This definition of the "root" type is recursive.) Also, the root
7994 type of a `const' qualified type or a `volatile' qualified type is the
7995 root type of the given type without the qualifiers. */
7998 root_type (tree type)
8000 if (TREE_CODE (type) == ERROR_MARK)
8001 return error_mark_node;
8003 switch (TREE_CODE (type))
8006 return error_mark_node;
8009 case REFERENCE_TYPE:
8010 return type_main_variant (root_type (TREE_TYPE (type)));
8013 return type_main_variant (type);
8017 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8018 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8021 is_base_type (tree type)
8023 switch (TREE_CODE (type))
8038 case QUAL_UNION_TYPE:
8043 case REFERENCE_TYPE:
8057 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8058 node, return the size in bits for the type if it is a constant, or else
8059 return the alignment for the type if the type's size is not constant, or
8060 else return BITS_PER_WORD if the type actually turns out to be an
8063 static inline unsigned HOST_WIDE_INT
8064 simple_type_size_in_bits (tree type)
8066 if (TREE_CODE (type) == ERROR_MARK)
8067 return BITS_PER_WORD;
8068 else if (TYPE_SIZE (type) == NULL_TREE)
8070 else if (host_integerp (TYPE_SIZE (type), 1))
8071 return tree_low_cst (TYPE_SIZE (type), 1);
8073 return TYPE_ALIGN (type);
8076 /* Return true if the debug information for the given type should be
8077 emitted as a subrange type. */
8080 is_subrange_type (tree type)
8082 tree subtype = TREE_TYPE (type);
8084 /* Subrange types are identified by the fact that they are integer
8085 types, and that they have a subtype which is either an integer type
8086 or an enumeral type. */
8088 if (TREE_CODE (type) != INTEGER_TYPE
8089 || subtype == NULL_TREE)
8092 if (TREE_CODE (subtype) != INTEGER_TYPE
8093 && TREE_CODE (subtype) != ENUMERAL_TYPE)
8096 if (TREE_CODE (type) == TREE_CODE (subtype)
8097 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
8098 && TYPE_MIN_VALUE (type) != NULL
8099 && TYPE_MIN_VALUE (subtype) != NULL
8100 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
8101 && TYPE_MAX_VALUE (type) != NULL
8102 && TYPE_MAX_VALUE (subtype) != NULL
8103 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
8105 /* The type and its subtype have the same representation. If in
8106 addition the two types also have the same name, then the given
8107 type is not a subrange type, but rather a plain base type. */
8108 /* FIXME: brobecker/2004-03-22:
8109 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8110 therefore be sufficient to check the TYPE_SIZE node pointers
8111 rather than checking the actual size. Unfortunately, we have
8112 found some cases, such as in the Ada "integer" type, where
8113 this is not the case. Until this problem is solved, we need to
8114 keep checking the actual size. */
8115 tree type_name = TYPE_NAME (type);
8116 tree subtype_name = TYPE_NAME (subtype);
8118 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
8119 type_name = DECL_NAME (type_name);
8121 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
8122 subtype_name = DECL_NAME (subtype_name);
8124 if (type_name == subtype_name)
8131 /* Given a pointer to a tree node for a subrange type, return a pointer
8132 to a DIE that describes the given type. */
8135 subrange_type_die (tree type, dw_die_ref context_die)
8137 dw_die_ref subtype_die;
8138 dw_die_ref subrange_die;
8139 tree name = TYPE_NAME (type);
8140 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
8141 tree subtype = TREE_TYPE (type);
8143 if (context_die == NULL)
8144 context_die = comp_unit_die;
8146 if (TREE_CODE (subtype) == ENUMERAL_TYPE)
8147 subtype_die = gen_enumeration_type_die (subtype, context_die);
8149 subtype_die = base_type_die (subtype);
8151 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
8155 if (TREE_CODE (name) == TYPE_DECL)
8156 name = DECL_NAME (name);
8157 add_name_attribute (subrange_die, IDENTIFIER_POINTER (name));
8160 if (int_size_in_bytes (subtype) != size_in_bytes)
8162 /* The size of the subrange type and its base type do not match,
8163 so we need to generate a size attribute for the subrange type. */
8164 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
8167 if (TYPE_MIN_VALUE (type) != NULL)
8168 add_bound_info (subrange_die, DW_AT_lower_bound,
8169 TYPE_MIN_VALUE (type));
8170 if (TYPE_MAX_VALUE (type) != NULL)
8171 add_bound_info (subrange_die, DW_AT_upper_bound,
8172 TYPE_MAX_VALUE (type));
8173 add_AT_die_ref (subrange_die, DW_AT_type, subtype_die);
8175 return subrange_die;
8178 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8179 entry that chains various modifiers in front of the given type. */
8182 modified_type_die (tree type, int is_const_type, int is_volatile_type,
8183 dw_die_ref context_die)
8185 enum tree_code code = TREE_CODE (type);
8186 dw_die_ref mod_type_die = NULL;
8187 dw_die_ref sub_die = NULL;
8188 tree item_type = NULL;
8190 if (code != ERROR_MARK)
8192 tree qualified_type;
8194 /* See if we already have the appropriately qualified variant of
8197 = get_qualified_type (type,
8198 ((is_const_type ? TYPE_QUAL_CONST : 0)
8200 ? TYPE_QUAL_VOLATILE : 0)));
8202 /* If we do, then we can just use its DIE, if it exists. */
8205 mod_type_die = lookup_type_die (qualified_type);
8207 return mod_type_die;
8210 /* Handle C typedef types. */
8211 if (qualified_type && TYPE_NAME (qualified_type)
8212 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
8213 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
8215 tree type_name = TYPE_NAME (qualified_type);
8216 tree dtype = TREE_TYPE (type_name);
8218 if (qualified_type == dtype)
8220 /* For a named type, use the typedef. */
8221 gen_type_die (qualified_type, context_die);
8222 mod_type_die = lookup_type_die (qualified_type);
8224 else if (is_const_type < TYPE_READONLY (dtype)
8225 || is_volatile_type < TYPE_VOLATILE (dtype))
8226 /* cv-unqualified version of named type. Just use the unnamed
8227 type to which it refers. */
8229 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
8230 is_const_type, is_volatile_type,
8233 /* Else cv-qualified version of named type; fall through. */
8239 else if (is_const_type)
8241 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
8242 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
8244 else if (is_volatile_type)
8246 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
8247 sub_die = modified_type_die (type, 0, 0, context_die);
8249 else if (code == POINTER_TYPE)
8251 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
8252 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8253 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8255 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
8257 item_type = TREE_TYPE (type);
8259 else if (code == REFERENCE_TYPE)
8261 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
8262 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8263 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8265 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
8267 item_type = TREE_TYPE (type);
8269 else if (is_subrange_type (type))
8270 mod_type_die = subrange_type_die (type, context_die);
8271 else if (is_base_type (type))
8272 mod_type_die = base_type_die (type);
8275 gen_type_die (type, context_die);
8277 /* We have to get the type_main_variant here (and pass that to the
8278 `lookup_type_die' routine) because the ..._TYPE node we have
8279 might simply be a *copy* of some original type node (where the
8280 copy was created to help us keep track of typedef names) and
8281 that copy might have a different TYPE_UID from the original
8283 if (TREE_CODE (type) != VECTOR_TYPE)
8284 mod_type_die = lookup_type_die (type_main_variant (type));
8286 /* Vectors have the debugging information in the type,
8287 not the main variant. */
8288 mod_type_die = lookup_type_die (type);
8289 gcc_assert (mod_type_die);
8292 /* We want to equate the qualified type to the die below. */
8293 type = qualified_type;
8297 equate_type_number_to_die (type, mod_type_die);
8299 /* We must do this after the equate_type_number_to_die call, in case
8300 this is a recursive type. This ensures that the modified_type_die
8301 recursion will terminate even if the type is recursive. Recursive
8302 types are possible in Ada. */
8303 sub_die = modified_type_die (item_type,
8304 TYPE_READONLY (item_type),
8305 TYPE_VOLATILE (item_type),
8308 if (sub_die != NULL)
8309 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
8311 return mod_type_die;
8314 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8315 an enumerated type. */
8318 type_is_enum (tree type)
8320 return TREE_CODE (type) == ENUMERAL_TYPE;
8323 /* Return the DBX register number described by a given RTL node. */
8326 dbx_reg_number (rtx rtl)
8328 unsigned regno = REGNO (rtl);
8330 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
8332 return DBX_REGISTER_NUMBER (regno);
8335 /* Return a location descriptor that designates a machine register or
8336 zero if there is none. */
8338 static dw_loc_descr_ref
8339 reg_loc_descriptor (rtx rtl)
8344 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
8347 reg = dbx_reg_number (rtl);
8348 regs = targetm.dwarf_register_span (rtl);
8350 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1
8352 return multiple_reg_loc_descriptor (rtl, regs);
8354 return one_reg_loc_descriptor (reg);
8357 /* Return a location descriptor that designates a machine register for
8358 a given hard register number. */
8360 static dw_loc_descr_ref
8361 one_reg_loc_descriptor (unsigned int regno)
8364 return new_loc_descr (DW_OP_reg0 + regno, 0, 0);
8366 return new_loc_descr (DW_OP_regx, regno, 0);
8369 /* Given an RTL of a register, return a location descriptor that
8370 designates a value that spans more than one register. */
8372 static dw_loc_descr_ref
8373 multiple_reg_loc_descriptor (rtx rtl, rtx regs)
8377 dw_loc_descr_ref loc_result = NULL;
8379 reg = dbx_reg_number (rtl);
8380 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
8382 /* Simple, contiguous registers. */
8383 if (regs == NULL_RTX)
8385 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
8392 t = one_reg_loc_descriptor (reg);
8393 add_loc_descr (&loc_result, t);
8394 add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0));
8400 /* Now onto stupid register sets in non contiguous locations. */
8402 gcc_assert (GET_CODE (regs) == PARALLEL);
8404 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8407 for (i = 0; i < XVECLEN (regs, 0); ++i)
8411 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)));
8412 add_loc_descr (&loc_result, t);
8413 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8414 add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0));
8419 /* Return a location descriptor that designates a constant. */
8421 static dw_loc_descr_ref
8422 int_loc_descriptor (HOST_WIDE_INT i)
8424 enum dwarf_location_atom op;
8426 /* Pick the smallest representation of a constant, rather than just
8427 defaulting to the LEB encoding. */
8431 op = DW_OP_lit0 + i;
8434 else if (i <= 0xffff)
8436 else if (HOST_BITS_PER_WIDE_INT == 32
8446 else if (i >= -0x8000)
8448 else if (HOST_BITS_PER_WIDE_INT == 32
8449 || i >= -0x80000000)
8455 return new_loc_descr (op, i, 0);
8458 /* Return a location descriptor that designates a base+offset location. */
8460 static dw_loc_descr_ref
8461 based_loc_descr (unsigned int reg, HOST_WIDE_INT offset, bool can_use_fbreg)
8463 dw_loc_descr_ref loc_result;
8464 /* For the "frame base", we use the frame pointer or stack pointer
8465 registers, since the RTL for local variables is relative to one of
8467 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
8468 ? HARD_FRAME_POINTER_REGNUM
8469 : STACK_POINTER_REGNUM);
8471 if (reg == fp_reg && can_use_fbreg)
8472 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
8474 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
8476 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
8481 /* Return true if this RTL expression describes a base+offset calculation. */
8484 is_based_loc (rtx rtl)
8486 return (GET_CODE (rtl) == PLUS
8487 && ((REG_P (XEXP (rtl, 0))
8488 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
8489 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
8492 /* The following routine converts the RTL for a variable or parameter
8493 (resident in memory) into an equivalent Dwarf representation of a
8494 mechanism for getting the address of that same variable onto the top of a
8495 hypothetical "address evaluation" stack.
8497 When creating memory location descriptors, we are effectively transforming
8498 the RTL for a memory-resident object into its Dwarf postfix expression
8499 equivalent. This routine recursively descends an RTL tree, turning
8500 it into Dwarf postfix code as it goes.
8502 MODE is the mode of the memory reference, needed to handle some
8503 autoincrement addressing modes.
8505 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the location
8506 list for RTL. We can't use it when we are emitting location list for
8507 virtual variable frame_base_decl (i.e. a location list for DW_AT_frame_base)
8508 which describes how frame base changes when !frame_pointer_needed.
8510 Return 0 if we can't represent the location. */
8512 static dw_loc_descr_ref
8513 mem_loc_descriptor (rtx rtl, enum machine_mode mode, bool can_use_fbreg)
8515 dw_loc_descr_ref mem_loc_result = NULL;
8516 enum dwarf_location_atom op;
8518 /* Note that for a dynamically sized array, the location we will generate a
8519 description of here will be the lowest numbered location which is
8520 actually within the array. That's *not* necessarily the same as the
8521 zeroth element of the array. */
8523 rtl = targetm.delegitimize_address (rtl);
8525 switch (GET_CODE (rtl))
8530 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8531 just fall into the SUBREG code. */
8533 /* ... fall through ... */
8536 /* The case of a subreg may arise when we have a local (register)
8537 variable or a formal (register) parameter which doesn't quite fill
8538 up an entire register. For now, just assume that it is
8539 legitimate to make the Dwarf info refer to the whole register which
8540 contains the given subreg. */
8541 rtl = SUBREG_REG (rtl);
8543 /* ... fall through ... */
8546 /* Whenever a register number forms a part of the description of the
8547 method for calculating the (dynamic) address of a memory resident
8548 object, DWARF rules require the register number be referred to as
8549 a "base register". This distinction is not based in any way upon
8550 what category of register the hardware believes the given register
8551 belongs to. This is strictly DWARF terminology we're dealing with
8552 here. Note that in cases where the location of a memory-resident
8553 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8554 OP_CONST (0)) the actual DWARF location descriptor that we generate
8555 may just be OP_BASEREG (basereg). This may look deceptively like
8556 the object in question was allocated to a register (rather than in
8557 memory) so DWARF consumers need to be aware of the subtle
8558 distinction between OP_REG and OP_BASEREG. */
8559 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
8560 mem_loc_result = based_loc_descr (dbx_reg_number (rtl), 0,
8565 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
8567 if (mem_loc_result != 0)
8568 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
8572 rtl = XEXP (rtl, 1);
8574 /* ... fall through ... */
8577 /* Some ports can transform a symbol ref into a label ref, because
8578 the symbol ref is too far away and has to be dumped into a constant
8582 /* Alternatively, the symbol in the constant pool might be referenced
8583 by a different symbol. */
8584 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
8587 rtx tmp = get_pool_constant_mark (rtl, &marked);
8589 if (GET_CODE (tmp) == SYMBOL_REF)
8592 if (CONSTANT_POOL_ADDRESS_P (tmp))
8593 get_pool_constant_mark (tmp, &marked);
8598 /* If all references to this pool constant were optimized away,
8599 it was not output and thus we can't represent it.
8600 FIXME: might try to use DW_OP_const_value here, though
8601 DW_OP_piece complicates it. */
8606 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
8607 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
8608 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
8609 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
8613 /* Extract the PLUS expression nested inside and fall into
8615 rtl = XEXP (rtl, 1);
8620 /* Turn these into a PLUS expression and fall into the PLUS code
8622 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
8623 GEN_INT (GET_CODE (rtl) == PRE_INC
8624 ? GET_MODE_UNIT_SIZE (mode)
8625 : -GET_MODE_UNIT_SIZE (mode)));
8627 /* ... fall through ... */
8631 if (is_based_loc (rtl))
8632 mem_loc_result = based_loc_descr (dbx_reg_number (XEXP (rtl, 0)),
8633 INTVAL (XEXP (rtl, 1)),
8637 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
8639 if (mem_loc_result == 0)
8642 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
8643 && INTVAL (XEXP (rtl, 1)) >= 0)
8644 add_loc_descr (&mem_loc_result,
8645 new_loc_descr (DW_OP_plus_uconst,
8646 INTVAL (XEXP (rtl, 1)), 0));
8649 add_loc_descr (&mem_loc_result,
8650 mem_loc_descriptor (XEXP (rtl, 1), mode,
8652 add_loc_descr (&mem_loc_result,
8653 new_loc_descr (DW_OP_plus, 0, 0));
8658 /* If a pseudo-reg is optimized away, it is possible for it to
8659 be replaced with a MEM containing a multiply or shift. */
8678 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
8680 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
8683 if (op0 == 0 || op1 == 0)
8686 mem_loc_result = op0;
8687 add_loc_descr (&mem_loc_result, op1);
8688 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
8693 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
8700 return mem_loc_result;
8703 /* Return a descriptor that describes the concatenation of two locations.
8704 This is typically a complex variable. */
8706 static dw_loc_descr_ref
8707 concat_loc_descriptor (rtx x0, rtx x1)
8709 dw_loc_descr_ref cc_loc_result = NULL;
8710 dw_loc_descr_ref x0_ref = loc_descriptor (x0, true);
8711 dw_loc_descr_ref x1_ref = loc_descriptor (x1, true);
8713 if (x0_ref == 0 || x1_ref == 0)
8716 cc_loc_result = x0_ref;
8717 add_loc_descr (&cc_loc_result,
8718 new_loc_descr (DW_OP_piece,
8719 GET_MODE_SIZE (GET_MODE (x0)), 0));
8721 add_loc_descr (&cc_loc_result, x1_ref);
8722 add_loc_descr (&cc_loc_result,
8723 new_loc_descr (DW_OP_piece,
8724 GET_MODE_SIZE (GET_MODE (x1)), 0));
8726 return cc_loc_result;
8729 /* Output a proper Dwarf location descriptor for a variable or parameter
8730 which is either allocated in a register or in a memory location. For a
8731 register, we just generate an OP_REG and the register number. For a
8732 memory location we provide a Dwarf postfix expression describing how to
8733 generate the (dynamic) address of the object onto the address stack.
8735 If we don't know how to describe it, return 0. */
8737 static dw_loc_descr_ref
8738 loc_descriptor (rtx rtl, bool can_use_fbreg)
8740 dw_loc_descr_ref loc_result = NULL;
8742 switch (GET_CODE (rtl))
8745 /* The case of a subreg may arise when we have a local (register)
8746 variable or a formal (register) parameter which doesn't quite fill
8747 up an entire register. For now, just assume that it is
8748 legitimate to make the Dwarf info refer to the whole register which
8749 contains the given subreg. */
8750 rtl = SUBREG_REG (rtl);
8752 /* ... fall through ... */
8755 loc_result = reg_loc_descriptor (rtl);
8759 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
8764 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8769 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
8771 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), can_use_fbreg);
8775 rtl = XEXP (rtl, 1);
8780 rtvec par_elems = XVEC (rtl, 0);
8781 int num_elem = GET_NUM_ELEM (par_elems);
8782 enum machine_mode mode;
8785 /* Create the first one, so we have something to add to. */
8786 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
8788 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
8789 add_loc_descr (&loc_result,
8790 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (mode), 0));
8791 for (i = 1; i < num_elem; i++)
8793 dw_loc_descr_ref temp;
8795 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
8797 add_loc_descr (&loc_result, temp);
8798 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
8799 add_loc_descr (&loc_result,
8800 new_loc_descr (DW_OP_piece,
8801 GET_MODE_SIZE (mode), 0));
8813 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8814 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
8815 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
8816 top-level invocation, and we require the address of LOC; is 0 if we require
8817 the value of LOC. */
8819 static dw_loc_descr_ref
8820 loc_descriptor_from_tree_1 (tree loc, int want_address)
8822 dw_loc_descr_ref ret, ret1;
8823 int have_address = 0;
8824 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
8825 enum dwarf_location_atom op;
8827 /* ??? Most of the time we do not take proper care for sign/zero
8828 extending the values properly. Hopefully this won't be a real
8831 switch (TREE_CODE (loc))
8836 case PLACEHOLDER_EXPR:
8837 /* This case involves extracting fields from an object to determine the
8838 position of other fields. We don't try to encode this here. The
8839 only user of this is Ada, which encodes the needed information using
8840 the names of types. */
8846 case PREINCREMENT_EXPR:
8847 case PREDECREMENT_EXPR:
8848 case POSTINCREMENT_EXPR:
8849 case POSTDECREMENT_EXPR:
8850 /* There are no opcodes for these operations. */
8854 /* If we already want an address, there's nothing we can do. */
8858 /* Otherwise, process the argument and look for the address. */
8859 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
8862 if (DECL_THREAD_LOCAL (loc))
8866 #ifndef ASM_OUTPUT_DWARF_DTPREL
8867 /* If this is not defined, we have no way to emit the data. */
8871 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8872 look up addresses of objects in the current module. */
8873 if (DECL_EXTERNAL (loc))
8876 rtl = rtl_for_decl_location (loc);
8877 if (rtl == NULL_RTX)
8882 rtl = XEXP (rtl, 0);
8883 if (! CONSTANT_P (rtl))
8886 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
8887 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8888 ret->dw_loc_oprnd1.v.val_addr = rtl;
8890 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
8891 add_loc_descr (&ret, ret1);
8899 if (DECL_VALUE_EXPR (loc))
8900 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc), want_address);
8905 rtx rtl = rtl_for_decl_location (loc);
8907 if (rtl == NULL_RTX)
8909 else if (GET_CODE (rtl) == CONST_INT)
8911 HOST_WIDE_INT val = INTVAL (rtl);
8912 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
8913 val &= GET_MODE_MASK (DECL_MODE (loc));
8914 ret = int_loc_descriptor (val);
8916 else if (GET_CODE (rtl) == CONST_STRING)
8918 else if (CONSTANT_P (rtl))
8920 ret = new_loc_descr (DW_OP_addr, 0, 0);
8921 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8922 ret->dw_loc_oprnd1.v.val_addr = rtl;
8926 enum machine_mode mode;
8928 /* Certain constructs can only be represented at top-level. */
8929 if (want_address == 2)
8930 return loc_descriptor (rtl, true);
8932 mode = GET_MODE (rtl);
8935 rtl = XEXP (rtl, 0);
8938 ret = mem_loc_descriptor (rtl, mode, true);
8944 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
8949 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
8953 case NON_LVALUE_EXPR:
8954 case VIEW_CONVERT_EXPR:
8957 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
8962 case ARRAY_RANGE_REF:
8965 HOST_WIDE_INT bitsize, bitpos, bytepos;
8966 enum machine_mode mode;
8969 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8970 &unsignedp, &volatilep);
8975 ret = loc_descriptor_from_tree_1 (obj, 1);
8977 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
8980 if (offset != NULL_TREE)
8982 /* Variable offset. */
8983 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
8984 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8987 bytepos = bitpos / BITS_PER_UNIT;
8989 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8990 else if (bytepos < 0)
8992 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8993 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9001 if (host_integerp (loc, 0))
9002 ret = int_loc_descriptor (tree_low_cst (loc, 0));
9009 /* Get an RTL for this, if something has been emitted. */
9010 rtx rtl = lookup_constant_def (loc);
9011 enum machine_mode mode;
9013 if (!rtl || !MEM_P (rtl))
9015 mode = GET_MODE (rtl);
9016 rtl = XEXP (rtl, 0);
9017 ret = mem_loc_descriptor (rtl, mode, true);
9022 case TRUTH_AND_EXPR:
9023 case TRUTH_ANDIF_EXPR:
9028 case TRUTH_XOR_EXPR:
9034 case TRUTH_ORIF_EXPR:
9039 case FLOOR_DIV_EXPR:
9041 case ROUND_DIV_EXPR:
9042 case TRUNC_DIV_EXPR:
9050 case FLOOR_MOD_EXPR:
9052 case ROUND_MOD_EXPR:
9053 case TRUNC_MOD_EXPR:
9066 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
9070 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
9071 && host_integerp (TREE_OPERAND (loc, 1), 0))
9073 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9077 add_loc_descr (&ret,
9078 new_loc_descr (DW_OP_plus_uconst,
9079 tree_low_cst (TREE_OPERAND (loc, 1),
9089 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9096 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9103 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9110 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9125 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9126 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9127 if (ret == 0 || ret1 == 0)
9130 add_loc_descr (&ret, ret1);
9131 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9134 case TRUTH_NOT_EXPR:
9148 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9152 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9158 const enum tree_code code =
9159 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
9161 loc = build3 (COND_EXPR, TREE_TYPE (loc),
9162 build2 (code, integer_type_node,
9163 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
9164 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
9167 /* ... fall through ... */
9171 dw_loc_descr_ref lhs
9172 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9173 dw_loc_descr_ref rhs
9174 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
9175 dw_loc_descr_ref bra_node, jump_node, tmp;
9177 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9178 if (ret == 0 || lhs == 0 || rhs == 0)
9181 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
9182 add_loc_descr (&ret, bra_node);
9184 add_loc_descr (&ret, rhs);
9185 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
9186 add_loc_descr (&ret, jump_node);
9188 add_loc_descr (&ret, lhs);
9189 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9190 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
9192 /* ??? Need a node to point the skip at. Use a nop. */
9193 tmp = new_loc_descr (DW_OP_nop, 0, 0);
9194 add_loc_descr (&ret, tmp);
9195 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9196 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
9200 case FIX_TRUNC_EXPR:
9202 case FIX_FLOOR_EXPR:
9203 case FIX_ROUND_EXPR:
9207 /* Leave front-end specific codes as simply unknown. This comes
9208 up, for instance, with the C STMT_EXPR. */
9209 if ((unsigned int) TREE_CODE (loc)
9210 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
9213 #ifdef ENABLE_CHECKING
9214 /* Otherwise this is a generic code; we should just lists all of
9215 these explicitly. Aborting means we forgot one. */
9218 /* In a release build, we want to degrade gracefully: better to
9219 generate incomplete debugging information than to crash. */
9224 /* Show if we can't fill the request for an address. */
9225 if (want_address && !have_address)
9228 /* If we've got an address and don't want one, dereference. */
9229 if (!want_address && have_address)
9231 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
9233 if (size > DWARF2_ADDR_SIZE || size == -1)
9235 else if (size == DWARF2_ADDR_SIZE)
9238 op = DW_OP_deref_size;
9240 add_loc_descr (&ret, new_loc_descr (op, size, 0));
9246 static inline dw_loc_descr_ref
9247 loc_descriptor_from_tree (tree loc)
9249 return loc_descriptor_from_tree_1 (loc, 2);
9252 /* Given a value, round it up to the lowest multiple of `boundary'
9253 which is not less than the value itself. */
9255 static inline HOST_WIDE_INT
9256 ceiling (HOST_WIDE_INT value, unsigned int boundary)
9258 return (((value + boundary - 1) / boundary) * boundary);
9261 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9262 pointer to the declared type for the relevant field variable, or return
9263 `integer_type_node' if the given node turns out to be an
9267 field_type (tree decl)
9271 if (TREE_CODE (decl) == ERROR_MARK)
9272 return integer_type_node;
9274 type = DECL_BIT_FIELD_TYPE (decl);
9275 if (type == NULL_TREE)
9276 type = TREE_TYPE (decl);
9281 /* Given a pointer to a tree node, return the alignment in bits for
9282 it, or else return BITS_PER_WORD if the node actually turns out to
9283 be an ERROR_MARK node. */
9285 static inline unsigned
9286 simple_type_align_in_bits (tree type)
9288 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
9291 static inline unsigned
9292 simple_decl_align_in_bits (tree decl)
9294 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
9297 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9298 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9299 or return 0 if we are unable to determine what that offset is, either
9300 because the argument turns out to be a pointer to an ERROR_MARK node, or
9301 because the offset is actually variable. (We can't handle the latter case
9304 static HOST_WIDE_INT
9305 field_byte_offset (tree decl)
9307 unsigned int type_align_in_bits;
9308 unsigned int decl_align_in_bits;
9309 unsigned HOST_WIDE_INT type_size_in_bits;
9310 HOST_WIDE_INT object_offset_in_bits;
9312 tree field_size_tree;
9313 HOST_WIDE_INT bitpos_int;
9314 HOST_WIDE_INT deepest_bitpos;
9315 unsigned HOST_WIDE_INT field_size_in_bits;
9317 if (TREE_CODE (decl) == ERROR_MARK)
9320 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
9322 type = field_type (decl);
9323 field_size_tree = DECL_SIZE (decl);
9325 /* The size could be unspecified if there was an error, or for
9326 a flexible array member. */
9327 if (! field_size_tree)
9328 field_size_tree = bitsize_zero_node;
9330 /* We cannot yet cope with fields whose positions are variable, so
9331 for now, when we see such things, we simply return 0. Someday, we may
9332 be able to handle such cases, but it will be damn difficult. */
9333 if (! host_integerp (bit_position (decl), 0))
9336 bitpos_int = int_bit_position (decl);
9338 /* If we don't know the size of the field, pretend it's a full word. */
9339 if (host_integerp (field_size_tree, 1))
9340 field_size_in_bits = tree_low_cst (field_size_tree, 1);
9342 field_size_in_bits = BITS_PER_WORD;
9344 type_size_in_bits = simple_type_size_in_bits (type);
9345 type_align_in_bits = simple_type_align_in_bits (type);
9346 decl_align_in_bits = simple_decl_align_in_bits (decl);
9348 /* The GCC front-end doesn't make any attempt to keep track of the starting
9349 bit offset (relative to the start of the containing structure type) of the
9350 hypothetical "containing object" for a bit-field. Thus, when computing
9351 the byte offset value for the start of the "containing object" of a
9352 bit-field, we must deduce this information on our own. This can be rather
9353 tricky to do in some cases. For example, handling the following structure
9354 type definition when compiling for an i386/i486 target (which only aligns
9355 long long's to 32-bit boundaries) can be very tricky:
9357 struct S { int field1; long long field2:31; };
9359 Fortunately, there is a simple rule-of-thumb which can be used in such
9360 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
9361 structure shown above. It decides to do this based upon one simple rule
9362 for bit-field allocation. GCC allocates each "containing object" for each
9363 bit-field at the first (i.e. lowest addressed) legitimate alignment
9364 boundary (based upon the required minimum alignment for the declared type
9365 of the field) which it can possibly use, subject to the condition that
9366 there is still enough available space remaining in the containing object
9367 (when allocated at the selected point) to fully accommodate all of the
9368 bits of the bit-field itself.
9370 This simple rule makes it obvious why GCC allocates 8 bytes for each
9371 object of the structure type shown above. When looking for a place to
9372 allocate the "containing object" for `field2', the compiler simply tries
9373 to allocate a 64-bit "containing object" at each successive 32-bit
9374 boundary (starting at zero) until it finds a place to allocate that 64-
9375 bit field such that at least 31 contiguous (and previously unallocated)
9376 bits remain within that selected 64 bit field. (As it turns out, for the
9377 example above, the compiler finds it is OK to allocate the "containing
9378 object" 64-bit field at bit-offset zero within the structure type.)
9380 Here we attempt to work backwards from the limited set of facts we're
9381 given, and we try to deduce from those facts, where GCC must have believed
9382 that the containing object started (within the structure type). The value
9383 we deduce is then used (by the callers of this routine) to generate
9384 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
9385 and, in the case of DW_AT_location, regular fields as well). */
9387 /* Figure out the bit-distance from the start of the structure to the
9388 "deepest" bit of the bit-field. */
9389 deepest_bitpos = bitpos_int + field_size_in_bits;
9391 /* This is the tricky part. Use some fancy footwork to deduce where the
9392 lowest addressed bit of the containing object must be. */
9393 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
9395 /* Round up to type_align by default. This works best for bitfields. */
9396 object_offset_in_bits += type_align_in_bits - 1;
9397 object_offset_in_bits /= type_align_in_bits;
9398 object_offset_in_bits *= type_align_in_bits;
9400 if (object_offset_in_bits > bitpos_int)
9402 /* Sigh, the decl must be packed. */
9403 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
9405 /* Round up to decl_align instead. */
9406 object_offset_in_bits += decl_align_in_bits - 1;
9407 object_offset_in_bits /= decl_align_in_bits;
9408 object_offset_in_bits *= decl_align_in_bits;
9411 return object_offset_in_bits / BITS_PER_UNIT;
9414 /* The following routines define various Dwarf attributes and any data
9415 associated with them. */
9417 /* Add a location description attribute value to a DIE.
9419 This emits location attributes suitable for whole variables and
9420 whole parameters. Note that the location attributes for struct fields are
9421 generated by the routine `data_member_location_attribute' below. */
9424 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
9425 dw_loc_descr_ref descr)
9428 add_AT_loc (die, attr_kind, descr);
9431 /* Attach the specialized form of location attribute used for data members of
9432 struct and union types. In the special case of a FIELD_DECL node which
9433 represents a bit-field, the "offset" part of this special location
9434 descriptor must indicate the distance in bytes from the lowest-addressed
9435 byte of the containing struct or union type to the lowest-addressed byte of
9436 the "containing object" for the bit-field. (See the `field_byte_offset'
9439 For any given bit-field, the "containing object" is a hypothetical object
9440 (of some integral or enum type) within which the given bit-field lives. The
9441 type of this hypothetical "containing object" is always the same as the
9442 declared type of the individual bit-field itself (for GCC anyway... the
9443 DWARF spec doesn't actually mandate this). Note that it is the size (in
9444 bytes) of the hypothetical "containing object" which will be given in the
9445 DW_AT_byte_size attribute for this bit-field. (See the
9446 `byte_size_attribute' function below.) It is also used when calculating the
9447 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
9451 add_data_member_location_attribute (dw_die_ref die, tree decl)
9453 HOST_WIDE_INT offset;
9454 dw_loc_descr_ref loc_descr = 0;
9456 if (TREE_CODE (decl) == TREE_BINFO)
9458 /* We're working on the TAG_inheritance for a base class. */
9459 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
9461 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
9462 aren't at a fixed offset from all (sub)objects of the same
9463 type. We need to extract the appropriate offset from our
9464 vtable. The following dwarf expression means
9466 BaseAddr = ObAddr + *((*ObAddr) - Offset)
9468 This is specific to the V3 ABI, of course. */
9470 dw_loc_descr_ref tmp;
9472 /* Make a copy of the object address. */
9473 tmp = new_loc_descr (DW_OP_dup, 0, 0);
9474 add_loc_descr (&loc_descr, tmp);
9476 /* Extract the vtable address. */
9477 tmp = new_loc_descr (DW_OP_deref, 0, 0);
9478 add_loc_descr (&loc_descr, tmp);
9480 /* Calculate the address of the offset. */
9481 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
9482 gcc_assert (offset < 0);
9484 tmp = int_loc_descriptor (-offset);
9485 add_loc_descr (&loc_descr, tmp);
9486 tmp = new_loc_descr (DW_OP_minus, 0, 0);
9487 add_loc_descr (&loc_descr, tmp);
9489 /* Extract the offset. */
9490 tmp = new_loc_descr (DW_OP_deref, 0, 0);
9491 add_loc_descr (&loc_descr, tmp);
9493 /* Add it to the object address. */
9494 tmp = new_loc_descr (DW_OP_plus, 0, 0);
9495 add_loc_descr (&loc_descr, tmp);
9498 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
9501 offset = field_byte_offset (decl);
9505 enum dwarf_location_atom op;
9507 /* The DWARF2 standard says that we should assume that the structure
9508 address is already on the stack, so we can specify a structure field
9509 address by using DW_OP_plus_uconst. */
9511 #ifdef MIPS_DEBUGGING_INFO
9512 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9513 operator correctly. It works only if we leave the offset on the
9517 op = DW_OP_plus_uconst;
9520 loc_descr = new_loc_descr (op, offset, 0);
9523 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
9526 /* Writes integer values to dw_vec_const array. */
9529 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
9533 *dest++ = val & 0xff;
9539 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
9541 static HOST_WIDE_INT
9542 extract_int (const unsigned char *src, unsigned int size)
9544 HOST_WIDE_INT val = 0;
9550 val |= *--src & 0xff;
9556 /* Writes floating point values to dw_vec_const array. */
9559 insert_float (rtx rtl, unsigned char *array)
9565 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
9566 real_to_target (val, &rv, GET_MODE (rtl));
9568 /* real_to_target puts 32-bit pieces in each long. Pack them. */
9569 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
9571 insert_int (val[i], 4, array);
9576 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9577 does not have a "location" either in memory or in a register. These
9578 things can arise in GNU C when a constant is passed as an actual parameter
9579 to an inlined function. They can also arise in C++ where declared
9580 constants do not necessarily get memory "homes". */
9583 add_const_value_attribute (dw_die_ref die, rtx rtl)
9585 switch (GET_CODE (rtl))
9589 HOST_WIDE_INT val = INTVAL (rtl);
9592 add_AT_int (die, DW_AT_const_value, val);
9594 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
9599 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9600 floating-point constant. A CONST_DOUBLE is used whenever the
9601 constant requires more than one word in order to be adequately
9602 represented. We output CONST_DOUBLEs as blocks. */
9604 enum machine_mode mode = GET_MODE (rtl);
9606 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
9608 unsigned int length = GET_MODE_SIZE (mode);
9609 unsigned char *array = ggc_alloc (length);
9611 insert_float (rtl, array);
9612 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
9616 /* ??? We really should be using HOST_WIDE_INT throughout. */
9617 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
9619 add_AT_long_long (die, DW_AT_const_value,
9620 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
9627 enum machine_mode mode = GET_MODE (rtl);
9628 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
9629 unsigned int length = CONST_VECTOR_NUNITS (rtl);
9630 unsigned char *array = ggc_alloc (length * elt_size);
9634 switch (GET_MODE_CLASS (mode))
9636 case MODE_VECTOR_INT:
9637 for (i = 0, p = array; i < length; i++, p += elt_size)
9639 rtx elt = CONST_VECTOR_ELT (rtl, i);
9640 HOST_WIDE_INT lo, hi;
9642 switch (GET_CODE (elt))
9650 lo = CONST_DOUBLE_LOW (elt);
9651 hi = CONST_DOUBLE_HIGH (elt);
9658 if (elt_size <= sizeof (HOST_WIDE_INT))
9659 insert_int (lo, elt_size, p);
9662 unsigned char *p0 = p;
9663 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
9665 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
9666 if (WORDS_BIG_ENDIAN)
9671 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
9672 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
9677 case MODE_VECTOR_FLOAT:
9678 for (i = 0, p = array; i < length; i++, p += elt_size)
9680 rtx elt = CONST_VECTOR_ELT (rtl, i);
9681 insert_float (elt, p);
9689 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
9694 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
9700 add_AT_addr (die, DW_AT_const_value, rtl);
9701 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
9705 /* In cases where an inlined instance of an inline function is passed
9706 the address of an `auto' variable (which is local to the caller) we
9707 can get a situation where the DECL_RTL of the artificial local
9708 variable (for the inlining) which acts as a stand-in for the
9709 corresponding formal parameter (of the inline function) will look
9710 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9711 exactly a compile-time constant expression, but it isn't the address
9712 of the (artificial) local variable either. Rather, it represents the
9713 *value* which the artificial local variable always has during its
9714 lifetime. We currently have no way to represent such quasi-constant
9715 values in Dwarf, so for now we just punt and generate nothing. */
9719 /* No other kinds of rtx should be possible here. */
9726 rtl_for_decl_location (tree decl)
9730 /* Here we have to decide where we are going to say the parameter "lives"
9731 (as far as the debugger is concerned). We only have a couple of
9732 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9734 DECL_RTL normally indicates where the parameter lives during most of the
9735 activation of the function. If optimization is enabled however, this
9736 could be either NULL or else a pseudo-reg. Both of those cases indicate
9737 that the parameter doesn't really live anywhere (as far as the code
9738 generation parts of GCC are concerned) during most of the function's
9739 activation. That will happen (for example) if the parameter is never
9740 referenced within the function.
9742 We could just generate a location descriptor here for all non-NULL
9743 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
9744 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
9745 where DECL_RTL is NULL or is a pseudo-reg.
9747 Note however that we can only get away with using DECL_INCOMING_RTL as
9748 a backup substitute for DECL_RTL in certain limited cases. In cases
9749 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
9750 we can be sure that the parameter was passed using the same type as it is
9751 declared to have within the function, and that its DECL_INCOMING_RTL
9752 points us to a place where a value of that type is passed.
9754 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
9755 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
9756 because in these cases DECL_INCOMING_RTL points us to a value of some
9757 type which is *different* from the type of the parameter itself. Thus,
9758 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
9759 such cases, the debugger would end up (for example) trying to fetch a
9760 `float' from a place which actually contains the first part of a
9761 `double'. That would lead to really incorrect and confusing
9762 output at debug-time.
9764 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
9765 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
9766 are a couple of exceptions however. On little-endian machines we can
9767 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
9768 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
9769 an integral type that is smaller than TREE_TYPE (decl). These cases arise
9770 when (on a little-endian machine) a non-prototyped function has a
9771 parameter declared to be of type `short' or `char'. In such cases,
9772 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
9773 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
9774 passed `int' value. If the debugger then uses that address to fetch
9775 a `short' or a `char' (on a little-endian machine) the result will be
9776 the correct data, so we allow for such exceptional cases below.
9778 Note that our goal here is to describe the place where the given formal
9779 parameter lives during most of the function's activation (i.e. between the
9780 end of the prologue and the start of the epilogue). We'll do that as best
9781 as we can. Note however that if the given formal parameter is modified
9782 sometime during the execution of the function, then a stack backtrace (at
9783 debug-time) will show the function as having been called with the *new*
9784 value rather than the value which was originally passed in. This happens
9785 rarely enough that it is not a major problem, but it *is* a problem, and
9788 A future version of dwarf2out.c may generate two additional attributes for
9789 any given DW_TAG_formal_parameter DIE which will describe the "passed
9790 type" and the "passed location" for the given formal parameter in addition
9791 to the attributes we now generate to indicate the "declared type" and the
9792 "active location" for each parameter. This additional set of attributes
9793 could be used by debuggers for stack backtraces. Separately, note that
9794 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
9795 This happens (for example) for inlined-instances of inline function formal
9796 parameters which are never referenced. This really shouldn't be
9797 happening. All PARM_DECL nodes should get valid non-NULL
9798 DECL_INCOMING_RTL values. FIXME. */
9800 /* Use DECL_RTL as the "location" unless we find something better. */
9801 rtl = DECL_RTL_IF_SET (decl);
9803 /* When generating abstract instances, ignore everything except
9804 constants, symbols living in memory, and symbols living in
9806 if (! reload_completed)
9809 && (CONSTANT_P (rtl)
9811 && CONSTANT_P (XEXP (rtl, 0)))
9813 && TREE_CODE (decl) == VAR_DECL
9814 && TREE_STATIC (decl))))
9816 rtl = targetm.delegitimize_address (rtl);
9821 else if (TREE_CODE (decl) == PARM_DECL)
9823 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
9825 tree declared_type = TREE_TYPE (decl);
9826 tree passed_type = DECL_ARG_TYPE (decl);
9827 enum machine_mode dmode = TYPE_MODE (declared_type);
9828 enum machine_mode pmode = TYPE_MODE (passed_type);
9830 /* This decl represents a formal parameter which was optimized out.
9831 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
9832 all cases where (rtl == NULL_RTX) just below. */
9834 rtl = DECL_INCOMING_RTL (decl);
9835 else if (SCALAR_INT_MODE_P (dmode)
9836 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
9837 && DECL_INCOMING_RTL (decl))
9839 rtx inc = DECL_INCOMING_RTL (decl);
9842 else if (MEM_P (inc))
9844 if (BYTES_BIG_ENDIAN)
9845 rtl = adjust_address_nv (inc, dmode,
9846 GET_MODE_SIZE (pmode)
9847 - GET_MODE_SIZE (dmode));
9854 /* If the parm was passed in registers, but lives on the stack, then
9855 make a big endian correction if the mode of the type of the
9856 parameter is not the same as the mode of the rtl. */
9857 /* ??? This is the same series of checks that are made in dbxout.c before
9858 we reach the big endian correction code there. It isn't clear if all
9859 of these checks are necessary here, but keeping them all is the safe
9861 else if (MEM_P (rtl)
9862 && XEXP (rtl, 0) != const0_rtx
9863 && ! CONSTANT_P (XEXP (rtl, 0))
9864 /* Not passed in memory. */
9865 && !MEM_P (DECL_INCOMING_RTL (decl))
9866 /* Not passed by invisible reference. */
9867 && (!REG_P (XEXP (rtl, 0))
9868 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
9869 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
9870 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
9871 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
9874 /* Big endian correction check. */
9876 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
9877 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
9880 int offset = (UNITS_PER_WORD
9881 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
9883 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
9884 plus_constant (XEXP (rtl, 0), offset));
9887 else if (TREE_CODE (decl) == VAR_DECL
9890 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
9891 && BYTES_BIG_ENDIAN)
9893 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
9894 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
9896 /* If a variable is declared "register" yet is smaller than
9897 a register, then if we store the variable to memory, it
9898 looks like we're storing a register-sized value, when in
9899 fact we are not. We need to adjust the offset of the
9900 storage location to reflect the actual value's bytes,
9901 else gdb will not be able to display it. */
9903 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
9904 plus_constant (XEXP (rtl, 0), rsize-dsize));
9907 if (rtl != NULL_RTX)
9909 rtl = eliminate_regs (rtl, 0, NULL_RTX);
9910 #ifdef LEAF_REG_REMAP
9911 if (current_function_uses_only_leaf_regs)
9912 leaf_renumber_regs_insn (rtl);
9916 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
9917 and will have been substituted directly into all expressions that use it.
9918 C does not have such a concept, but C++ and other languages do. */
9919 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
9921 /* If a variable is initialized with a string constant without embedded
9922 zeros, build CONST_STRING. */
9923 if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
9924 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
9926 tree arrtype = TREE_TYPE (decl);
9927 tree enttype = TREE_TYPE (arrtype);
9928 tree domain = TYPE_DOMAIN (arrtype);
9929 tree init = DECL_INITIAL (decl);
9930 enum machine_mode mode = TYPE_MODE (enttype);
9932 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
9934 && integer_zerop (TYPE_MIN_VALUE (domain))
9935 && compare_tree_int (TYPE_MAX_VALUE (domain),
9936 TREE_STRING_LENGTH (init) - 1) == 0
9937 && ((size_t) TREE_STRING_LENGTH (init)
9938 == strlen (TREE_STRING_POINTER (init)) + 1))
9939 rtl = gen_rtx_CONST_STRING (VOIDmode,
9940 ggc_strdup (TREE_STRING_POINTER (init)));
9942 /* If the initializer is something that we know will expand into an
9943 immediate RTL constant, expand it now. Expanding anything else
9944 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
9945 else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST
9946 || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST)
9948 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
9949 EXPAND_INITIALIZER);
9950 /* If expand_expr returns a MEM, it wasn't immediate. */
9951 gcc_assert (!rtl || !MEM_P (rtl));
9956 rtl = targetm.delegitimize_address (rtl);
9958 /* If we don't look past the constant pool, we risk emitting a
9959 reference to a constant pool entry that isn't referenced from
9960 code, and thus is not emitted. */
9962 rtl = avoid_constant_pool_reference (rtl);
9967 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
9968 data attribute for a variable or a parameter. We generate the
9969 DW_AT_const_value attribute only in those cases where the given variable
9970 or parameter does not have a true "location" either in memory or in a
9971 register. This can happen (for example) when a constant is passed as an
9972 actual argument in a call to an inline function. (It's possible that
9973 these things can crop up in other ways also.) Note that one type of
9974 constant value which can be passed into an inlined function is a constant
9975 pointer. This can happen for example if an actual argument in an inlined
9976 function call evaluates to a compile-time constant address. */
9979 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
9980 enum dwarf_attribute attr)
9983 dw_loc_descr_ref descr;
9984 var_loc_list *loc_list;
9986 if (TREE_CODE (decl) == ERROR_MARK)
9989 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
9990 || TREE_CODE (decl) == RESULT_DECL);
9992 /* See if we possibly have multiple locations for this variable. */
9993 loc_list = lookup_decl_loc (decl);
9995 /* If it truly has multiple locations, the first and last node will
9997 if (loc_list && loc_list->first != loc_list->last)
9999 const char *secname;
10000 const char *endname;
10001 dw_loc_list_ref list;
10003 struct var_loc_node *node;
10005 /* We need to figure out what section we should use as the base
10006 for the address ranges where a given location is valid.
10007 1. If this particular DECL has a section associated with it,
10009 2. If this function has a section associated with it, use
10011 3. Otherwise, use the text section.
10012 XXX: If you split a variable across multiple sections, this
10015 if (DECL_SECTION_NAME (decl))
10017 tree sectree = DECL_SECTION_NAME (decl);
10018 secname = TREE_STRING_POINTER (sectree);
10020 else if (current_function_decl
10021 && DECL_SECTION_NAME (current_function_decl))
10023 tree sectree = DECL_SECTION_NAME (current_function_decl);
10024 secname = TREE_STRING_POINTER (sectree);
10027 secname = text_section_label;
10029 /* Now that we know what section we are using for a base,
10030 actually construct the list of locations.
10031 The first location information is what is passed to the
10032 function that creates the location list, and the remaining
10033 locations just get added on to that list.
10034 Note that we only know the start address for a location
10035 (IE location changes), so to build the range, we use
10036 the range [current location start, next location start].
10037 This means we have to special case the last node, and generate
10038 a range of [last location start, end of function label]. */
10040 node = loc_list->first;
10041 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10042 list = new_loc_list (loc_descriptor (varloc, attr != DW_AT_frame_base),
10043 node->label, node->next->label, secname, 1);
10046 for (; node->next; node = node->next)
10047 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10049 /* The variable has a location between NODE->LABEL and
10050 NODE->NEXT->LABEL. */
10051 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10052 add_loc_descr_to_loc_list (&list,
10053 loc_descriptor (varloc,
10054 attr != DW_AT_frame_base),
10055 node->label, node->next->label, secname);
10058 /* If the variable has a location at the last label
10059 it keeps its location until the end of function. */
10060 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10062 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10064 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10065 if (!current_function_decl)
10066 endname = text_end_label;
10069 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10070 current_function_funcdef_no);
10071 endname = ggc_strdup (label_id);
10073 add_loc_descr_to_loc_list (&list,
10074 loc_descriptor (varloc,
10075 attr != DW_AT_frame_base),
10076 node->label, endname, secname);
10079 /* Finally, add the location list to the DIE, and we are done. */
10080 add_AT_loc_list (die, attr, list);
10084 rtl = rtl_for_decl_location (decl);
10085 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
10087 add_const_value_attribute (die, rtl);
10091 descr = loc_descriptor_from_tree (decl);
10093 add_AT_location_description (die, attr, descr);
10096 /* If we don't have a copy of this variable in memory for some reason (such
10097 as a C++ member constant that doesn't have an out-of-line definition),
10098 we should tell the debugger about the constant value. */
10101 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
10103 tree init = DECL_INITIAL (decl);
10104 tree type = TREE_TYPE (decl);
10106 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
10107 && initializer_constant_valid_p (init, type) == null_pointer_node)
10112 switch (TREE_CODE (type))
10115 if (host_integerp (init, 0))
10116 add_AT_unsigned (var_die, DW_AT_const_value,
10117 tree_low_cst (init, 0));
10119 add_AT_long_long (var_die, DW_AT_const_value,
10120 TREE_INT_CST_HIGH (init),
10121 TREE_INT_CST_LOW (init));
10128 /* Generate a DW_AT_name attribute given some string value to be included as
10129 the value of the attribute. */
10132 add_name_attribute (dw_die_ref die, const char *name_string)
10134 if (name_string != NULL && *name_string != 0)
10136 if (demangle_name_func)
10137 name_string = (*demangle_name_func) (name_string);
10139 add_AT_string (die, DW_AT_name, name_string);
10143 /* Generate a DW_AT_comp_dir attribute for DIE. */
10146 add_comp_dir_attribute (dw_die_ref die)
10148 const char *wd = get_src_pwd ();
10150 add_AT_string (die, DW_AT_comp_dir, wd);
10153 /* Given a tree node describing an array bound (either lower or upper) output
10154 a representation for that bound. */
10157 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
10159 switch (TREE_CODE (bound))
10164 /* All fixed-bounds are represented by INTEGER_CST nodes. */
10166 if (! host_integerp (bound, 0)
10167 || (bound_attr == DW_AT_lower_bound
10168 && (((is_c_family () || is_java ()) && integer_zerop (bound))
10169 || (is_fortran () && integer_onep (bound)))))
10170 /* Use the default. */
10173 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
10178 case NON_LVALUE_EXPR:
10179 case VIEW_CONVERT_EXPR:
10180 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
10190 dw_die_ref decl_die = lookup_decl_die (bound);
10192 /* ??? Can this happen, or should the variable have been bound
10193 first? Probably it can, since I imagine that we try to create
10194 the types of parameters in the order in which they exist in
10195 the list, and won't have created a forward reference to a
10196 later parameter. */
10197 if (decl_die != NULL)
10198 add_AT_die_ref (subrange_die, bound_attr, decl_die);
10204 /* Otherwise try to create a stack operation procedure to
10205 evaluate the value of the array bound. */
10207 dw_die_ref ctx, decl_die;
10208 dw_loc_descr_ref loc;
10210 loc = loc_descriptor_from_tree (bound);
10214 if (current_function_decl == 0)
10215 ctx = comp_unit_die;
10217 ctx = lookup_decl_die (current_function_decl);
10219 decl_die = new_die (DW_TAG_variable, ctx, bound);
10220 add_AT_flag (decl_die, DW_AT_artificial, 1);
10221 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
10222 add_AT_loc (decl_die, DW_AT_location, loc);
10224 add_AT_die_ref (subrange_die, bound_attr, decl_die);
10230 /* Note that the block of subscript information for an array type also
10231 includes information about the element type of type given array type. */
10234 add_subscript_info (dw_die_ref type_die, tree type)
10236 #ifndef MIPS_DEBUGGING_INFO
10237 unsigned dimension_number;
10240 dw_die_ref subrange_die;
10242 /* The GNU compilers represent multidimensional array types as sequences of
10243 one dimensional array types whose element types are themselves array
10244 types. Here we squish that down, so that each multidimensional array
10245 type gets only one array_type DIE in the Dwarf debugging info. The draft
10246 Dwarf specification say that we are allowed to do this kind of
10247 compression in C (because there is no difference between an array or
10248 arrays and a multidimensional array in C) but for other source languages
10249 (e.g. Ada) we probably shouldn't do this. */
10251 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10252 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10253 We work around this by disabling this feature. See also
10254 gen_array_type_die. */
10255 #ifndef MIPS_DEBUGGING_INFO
10256 for (dimension_number = 0;
10257 TREE_CODE (type) == ARRAY_TYPE;
10258 type = TREE_TYPE (type), dimension_number++)
10261 tree domain = TYPE_DOMAIN (type);
10263 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
10264 and (in GNU C only) variable bounds. Handle all three forms
10266 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
10269 /* We have an array type with specified bounds. */
10270 lower = TYPE_MIN_VALUE (domain);
10271 upper = TYPE_MAX_VALUE (domain);
10273 /* Define the index type. */
10274 if (TREE_TYPE (domain))
10276 /* ??? This is probably an Ada unnamed subrange type. Ignore the
10277 TREE_TYPE field. We can't emit debug info for this
10278 because it is an unnamed integral type. */
10279 if (TREE_CODE (domain) == INTEGER_TYPE
10280 && TYPE_NAME (domain) == NULL_TREE
10281 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
10282 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
10285 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
10289 /* ??? If upper is NULL, the array has unspecified length,
10290 but it does have a lower bound. This happens with Fortran
10292 Since the debugger is definitely going to need to know N
10293 to produce useful results, go ahead and output the lower
10294 bound solo, and hope the debugger can cope. */
10296 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
10298 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
10301 /* Otherwise we have an array type with an unspecified length. The
10302 DWARF-2 spec does not say how to handle this; let's just leave out the
10308 add_byte_size_attribute (dw_die_ref die, tree tree_node)
10312 switch (TREE_CODE (tree_node))
10317 case ENUMERAL_TYPE:
10320 case QUAL_UNION_TYPE:
10321 size = int_size_in_bytes (tree_node);
10324 /* For a data member of a struct or union, the DW_AT_byte_size is
10325 generally given as the number of bytes normally allocated for an
10326 object of the *declared* type of the member itself. This is true
10327 even for bit-fields. */
10328 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
10331 gcc_unreachable ();
10334 /* Note that `size' might be -1 when we get to this point. If it is, that
10335 indicates that the byte size of the entity in question is variable. We
10336 have no good way of expressing this fact in Dwarf at the present time,
10337 so just let the -1 pass on through. */
10338 add_AT_unsigned (die, DW_AT_byte_size, size);
10341 /* For a FIELD_DECL node which represents a bit-field, output an attribute
10342 which specifies the distance in bits from the highest order bit of the
10343 "containing object" for the bit-field to the highest order bit of the
10346 For any given bit-field, the "containing object" is a hypothetical object
10347 (of some integral or enum type) within which the given bit-field lives. The
10348 type of this hypothetical "containing object" is always the same as the
10349 declared type of the individual bit-field itself. The determination of the
10350 exact location of the "containing object" for a bit-field is rather
10351 complicated. It's handled by the `field_byte_offset' function (above).
10353 Note that it is the size (in bytes) of the hypothetical "containing object"
10354 which will be given in the DW_AT_byte_size attribute for this bit-field.
10355 (See `byte_size_attribute' above). */
10358 add_bit_offset_attribute (dw_die_ref die, tree decl)
10360 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
10361 tree type = DECL_BIT_FIELD_TYPE (decl);
10362 HOST_WIDE_INT bitpos_int;
10363 HOST_WIDE_INT highest_order_object_bit_offset;
10364 HOST_WIDE_INT highest_order_field_bit_offset;
10365 HOST_WIDE_INT unsigned bit_offset;
10367 /* Must be a field and a bit field. */
10368 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
10370 /* We can't yet handle bit-fields whose offsets are variable, so if we
10371 encounter such things, just return without generating any attribute
10372 whatsoever. Likewise for variable or too large size. */
10373 if (! host_integerp (bit_position (decl), 0)
10374 || ! host_integerp (DECL_SIZE (decl), 1))
10377 bitpos_int = int_bit_position (decl);
10379 /* Note that the bit offset is always the distance (in bits) from the
10380 highest-order bit of the "containing object" to the highest-order bit of
10381 the bit-field itself. Since the "high-order end" of any object or field
10382 is different on big-endian and little-endian machines, the computation
10383 below must take account of these differences. */
10384 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
10385 highest_order_field_bit_offset = bitpos_int;
10387 if (! BYTES_BIG_ENDIAN)
10389 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
10390 highest_order_object_bit_offset += simple_type_size_in_bits (type);
10394 = (! BYTES_BIG_ENDIAN
10395 ? highest_order_object_bit_offset - highest_order_field_bit_offset
10396 : highest_order_field_bit_offset - highest_order_object_bit_offset);
10398 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
10401 /* For a FIELD_DECL node which represents a bit field, output an attribute
10402 which specifies the length in bits of the given field. */
10405 add_bit_size_attribute (dw_die_ref die, tree decl)
10407 /* Must be a field and a bit field. */
10408 gcc_assert (TREE_CODE (decl) == FIELD_DECL
10409 && DECL_BIT_FIELD_TYPE (decl));
10411 if (host_integerp (DECL_SIZE (decl), 1))
10412 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
10415 /* If the compiled language is ANSI C, then add a 'prototyped'
10416 attribute, if arg types are given for the parameters of a function. */
10419 add_prototyped_attribute (dw_die_ref die, tree func_type)
10421 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
10422 && TYPE_ARG_TYPES (func_type) != NULL)
10423 add_AT_flag (die, DW_AT_prototyped, 1);
10426 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
10427 by looking in either the type declaration or object declaration
10431 add_abstract_origin_attribute (dw_die_ref die, tree origin)
10433 dw_die_ref origin_die = NULL;
10435 if (TREE_CODE (origin) != FUNCTION_DECL)
10437 /* We may have gotten separated from the block for the inlined
10438 function, if we're in an exception handler or some such; make
10439 sure that the abstract function has been written out.
10441 Doing this for nested functions is wrong, however; functions are
10442 distinct units, and our context might not even be inline. */
10446 fn = TYPE_STUB_DECL (fn);
10448 fn = decl_function_context (fn);
10450 dwarf2out_abstract_function (fn);
10453 if (DECL_P (origin))
10454 origin_die = lookup_decl_die (origin);
10455 else if (TYPE_P (origin))
10456 origin_die = lookup_type_die (origin);
10458 gcc_assert (origin_die);
10460 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
10463 /* We do not currently support the pure_virtual attribute. */
10466 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
10468 if (DECL_VINDEX (func_decl))
10470 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10472 if (host_integerp (DECL_VINDEX (func_decl), 0))
10473 add_AT_loc (die, DW_AT_vtable_elem_location,
10474 new_loc_descr (DW_OP_constu,
10475 tree_low_cst (DECL_VINDEX (func_decl), 0),
10478 /* GNU extension: Record what type this method came from originally. */
10479 if (debug_info_level > DINFO_LEVEL_TERSE)
10480 add_AT_die_ref (die, DW_AT_containing_type,
10481 lookup_type_die (DECL_CONTEXT (func_decl)));
10485 /* Add source coordinate attributes for the given decl. */
10488 add_src_coords_attributes (dw_die_ref die, tree decl)
10490 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
10491 unsigned file_index = lookup_filename (s.file);
10493 add_AT_unsigned (die, DW_AT_decl_file, file_index);
10494 add_AT_unsigned (die, DW_AT_decl_line, s.line);
10497 /* Add a DW_AT_name attribute and source coordinate attribute for the
10498 given decl, but only if it actually has a name. */
10501 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
10505 decl_name = DECL_NAME (decl);
10506 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
10508 add_name_attribute (die, dwarf2_name (decl, 0));
10509 if (! DECL_ARTIFICIAL (decl))
10510 add_src_coords_attributes (die, decl);
10512 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
10513 && TREE_PUBLIC (decl)
10514 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
10515 && !DECL_ABSTRACT (decl))
10516 add_AT_string (die, DW_AT_MIPS_linkage_name,
10517 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
10520 #ifdef VMS_DEBUGGING_INFO
10521 /* Get the function's name, as described by its RTL. This may be different
10522 from the DECL_NAME name used in the source file. */
10523 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
10525 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
10526 XEXP (DECL_RTL (decl), 0));
10527 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
10532 /* Push a new declaration scope. */
10535 push_decl_scope (tree scope)
10537 VARRAY_PUSH_TREE (decl_scope_table, scope);
10540 /* Pop a declaration scope. */
10543 pop_decl_scope (void)
10545 gcc_assert (VARRAY_ACTIVE_SIZE (decl_scope_table) > 0);
10547 VARRAY_POP (decl_scope_table);
10550 /* Return the DIE for the scope that immediately contains this type.
10551 Non-named types get global scope. Named types nested in other
10552 types get their containing scope if it's open, or global scope
10553 otherwise. All other types (i.e. function-local named types) get
10554 the current active scope. */
10557 scope_die_for (tree t, dw_die_ref context_die)
10559 dw_die_ref scope_die = NULL;
10560 tree containing_scope;
10563 /* Non-types always go in the current scope. */
10564 gcc_assert (TYPE_P (t));
10566 containing_scope = TYPE_CONTEXT (t);
10568 /* Use the containing namespace if it was passed in (for a declaration). */
10569 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
10571 if (context_die == lookup_decl_die (containing_scope))
10574 containing_scope = NULL_TREE;
10577 /* Ignore function type "scopes" from the C frontend. They mean that
10578 a tagged type is local to a parmlist of a function declarator, but
10579 that isn't useful to DWARF. */
10580 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
10581 containing_scope = NULL_TREE;
10583 if (containing_scope == NULL_TREE)
10584 scope_die = comp_unit_die;
10585 else if (TYPE_P (containing_scope))
10587 /* For types, we can just look up the appropriate DIE. But
10588 first we check to see if we're in the middle of emitting it
10589 so we know where the new DIE should go. */
10590 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
10591 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
10596 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
10597 || TREE_ASM_WRITTEN (containing_scope));
10599 /* If none of the current dies are suitable, we get file scope. */
10600 scope_die = comp_unit_die;
10603 scope_die = lookup_type_die (containing_scope);
10606 scope_die = context_die;
10611 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10614 local_scope_p (dw_die_ref context_die)
10616 for (; context_die; context_die = context_die->die_parent)
10617 if (context_die->die_tag == DW_TAG_inlined_subroutine
10618 || context_die->die_tag == DW_TAG_subprogram)
10624 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
10625 whether or not to treat a DIE in this context as a declaration. */
10628 class_or_namespace_scope_p (dw_die_ref context_die)
10630 return (context_die
10631 && (context_die->die_tag == DW_TAG_structure_type
10632 || context_die->die_tag == DW_TAG_union_type
10633 || context_die->die_tag == DW_TAG_namespace));
10636 /* Many forms of DIEs require a "type description" attribute. This
10637 routine locates the proper "type descriptor" die for the type given
10638 by 'type', and adds a DW_AT_type attribute below the given die. */
10641 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
10642 int decl_volatile, dw_die_ref context_die)
10644 enum tree_code code = TREE_CODE (type);
10645 dw_die_ref type_die = NULL;
10647 /* ??? If this type is an unnamed subrange type of an integral or
10648 floating-point type, use the inner type. This is because we have no
10649 support for unnamed types in base_type_die. This can happen if this is
10650 an Ada subrange type. Correct solution is emit a subrange type die. */
10651 if ((code == INTEGER_TYPE || code == REAL_TYPE)
10652 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
10653 type = TREE_TYPE (type), code = TREE_CODE (type);
10655 if (code == ERROR_MARK
10656 /* Handle a special case. For functions whose return type is void, we
10657 generate *no* type attribute. (Note that no object may have type
10658 `void', so this only applies to function return types). */
10659 || code == VOID_TYPE)
10662 type_die = modified_type_die (type,
10663 decl_const || TYPE_READONLY (type),
10664 decl_volatile || TYPE_VOLATILE (type),
10667 if (type_die != NULL)
10668 add_AT_die_ref (object_die, DW_AT_type, type_die);
10671 /* Given an object die, add the calling convention attribute for the
10672 function call type. */
10674 add_calling_convention_attribute (dw_die_ref subr_die, tree type)
10676 enum dwarf_calling_convention value = DW_CC_normal;
10678 value = targetm.dwarf_calling_convention (type);
10680 /* Only add the attribute if the backend requests it, and
10681 is not DW_CC_normal. */
10682 if (value && (value != DW_CC_normal))
10683 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
10686 /* Given a tree pointer to a struct, class, union, or enum type node, return
10687 a pointer to the (string) tag name for the given type, or zero if the type
10688 was declared without a tag. */
10690 static const char *
10691 type_tag (tree type)
10693 const char *name = 0;
10695 if (TYPE_NAME (type) != 0)
10699 /* Find the IDENTIFIER_NODE for the type name. */
10700 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
10701 t = TYPE_NAME (type);
10703 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
10704 a TYPE_DECL node, regardless of whether or not a `typedef' was
10706 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10707 && ! DECL_IGNORED_P (TYPE_NAME (type)))
10708 t = DECL_NAME (TYPE_NAME (type));
10710 /* Now get the name as a string, or invent one. */
10712 name = IDENTIFIER_POINTER (t);
10715 return (name == 0 || *name == '\0') ? 0 : name;
10718 /* Return the type associated with a data member, make a special check
10719 for bit field types. */
10722 member_declared_type (tree member)
10724 return (DECL_BIT_FIELD_TYPE (member)
10725 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
10728 /* Get the decl's label, as described by its RTL. This may be different
10729 from the DECL_NAME name used in the source file. */
10732 static const char *
10733 decl_start_label (tree decl)
10736 const char *fnname;
10738 x = DECL_RTL (decl);
10739 gcc_assert (MEM_P (x));
10742 gcc_assert (GET_CODE (x) == SYMBOL_REF);
10744 fnname = XSTR (x, 0);
10749 /* These routines generate the internal representation of the DIE's for
10750 the compilation unit. Debugging information is collected by walking
10751 the declaration trees passed in from dwarf2out_decl(). */
10754 gen_array_type_die (tree type, dw_die_ref context_die)
10756 dw_die_ref scope_die = scope_die_for (type, context_die);
10757 dw_die_ref array_die;
10760 /* ??? The SGI dwarf reader fails for array of array of enum types unless
10761 the inner array type comes before the outer array type. Thus we must
10762 call gen_type_die before we call new_die. See below also. */
10763 #ifdef MIPS_DEBUGGING_INFO
10764 gen_type_die (TREE_TYPE (type), context_die);
10767 array_die = new_die (DW_TAG_array_type, scope_die, type);
10768 add_name_attribute (array_die, type_tag (type));
10769 equate_type_number_to_die (type, array_die);
10771 if (TREE_CODE (type) == VECTOR_TYPE)
10773 /* The frontend feeds us a representation for the vector as a struct
10774 containing an array. Pull out the array type. */
10775 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
10776 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
10780 /* We default the array ordering. SDB will probably do
10781 the right things even if DW_AT_ordering is not present. It's not even
10782 an issue until we start to get into multidimensional arrays anyway. If
10783 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
10784 then we'll have to put the DW_AT_ordering attribute back in. (But if
10785 and when we find out that we need to put these in, we will only do so
10786 for multidimensional arrays. */
10787 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
10790 #ifdef MIPS_DEBUGGING_INFO
10791 /* The SGI compilers handle arrays of unknown bound by setting
10792 AT_declaration and not emitting any subrange DIEs. */
10793 if (! TYPE_DOMAIN (type))
10794 add_AT_flag (array_die, DW_AT_declaration, 1);
10797 add_subscript_info (array_die, type);
10799 /* Add representation of the type of the elements of this array type. */
10800 element_type = TREE_TYPE (type);
10802 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10803 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10804 We work around this by disabling this feature. See also
10805 add_subscript_info. */
10806 #ifndef MIPS_DEBUGGING_INFO
10807 while (TREE_CODE (element_type) == ARRAY_TYPE)
10808 element_type = TREE_TYPE (element_type);
10810 gen_type_die (element_type, context_die);
10813 add_type_attribute (array_die, element_type, 0, 0, context_die);
10817 gen_set_type_die (tree type, dw_die_ref context_die)
10819 dw_die_ref type_die
10820 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
10822 equate_type_number_to_die (type, type_die);
10823 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
10828 gen_entry_point_die (tree decl, dw_die_ref context_die)
10830 tree origin = decl_ultimate_origin (decl);
10831 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
10833 if (origin != NULL)
10834 add_abstract_origin_attribute (decl_die, origin);
10837 add_name_and_src_coords_attributes (decl_die, decl);
10838 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
10839 0, 0, context_die);
10842 if (DECL_ABSTRACT (decl))
10843 equate_decl_number_to_die (decl, decl_die);
10845 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
10849 /* Walk through the list of incomplete types again, trying once more to
10850 emit full debugging info for them. */
10853 retry_incomplete_types (void)
10857 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
10858 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
10861 /* Generate a DIE to represent an inlined instance of an enumeration type. */
10864 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
10866 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
10868 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10869 be incomplete and such types are not marked. */
10870 add_abstract_origin_attribute (type_die, type);
10873 /* Generate a DIE to represent an inlined instance of a structure type. */
10876 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
10878 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
10880 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10881 be incomplete and such types are not marked. */
10882 add_abstract_origin_attribute (type_die, type);
10885 /* Generate a DIE to represent an inlined instance of a union type. */
10888 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
10890 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
10892 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10893 be incomplete and such types are not marked. */
10894 add_abstract_origin_attribute (type_die, type);
10897 /* Generate a DIE to represent an enumeration type. Note that these DIEs
10898 include all of the information about the enumeration values also. Each
10899 enumerated type name/value is listed as a child of the enumerated type
10903 gen_enumeration_type_die (tree type, dw_die_ref context_die)
10905 dw_die_ref type_die = lookup_type_die (type);
10907 if (type_die == NULL)
10909 type_die = new_die (DW_TAG_enumeration_type,
10910 scope_die_for (type, context_die), type);
10911 equate_type_number_to_die (type, type_die);
10912 add_name_attribute (type_die, type_tag (type));
10914 else if (! TYPE_SIZE (type))
10917 remove_AT (type_die, DW_AT_declaration);
10919 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
10920 given enum type is incomplete, do not generate the DW_AT_byte_size
10921 attribute or the DW_AT_element_list attribute. */
10922 if (TYPE_SIZE (type))
10926 TREE_ASM_WRITTEN (type) = 1;
10927 add_byte_size_attribute (type_die, type);
10928 if (TYPE_STUB_DECL (type) != NULL_TREE)
10929 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10931 /* If the first reference to this type was as the return type of an
10932 inline function, then it may not have a parent. Fix this now. */
10933 if (type_die->die_parent == NULL)
10934 add_child_die (scope_die_for (type, context_die), type_die);
10936 for (link = TYPE_VALUES (type);
10937 link != NULL; link = TREE_CHAIN (link))
10939 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
10940 tree value = TREE_VALUE (link);
10942 add_name_attribute (enum_die,
10943 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
10945 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
10946 /* DWARF2 does not provide a way of indicating whether or
10947 not enumeration constants are signed or unsigned. GDB
10948 always assumes the values are signed, so we output all
10949 values as if they were signed. That means that
10950 enumeration constants with very large unsigned values
10951 will appear to have negative values in the debugger. */
10952 add_AT_int (enum_die, DW_AT_const_value,
10953 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
10957 add_AT_flag (type_die, DW_AT_declaration, 1);
10962 /* Generate a DIE to represent either a real live formal parameter decl or to
10963 represent just the type of some formal parameter position in some function
10966 Note that this routine is a bit unusual because its argument may be a
10967 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
10968 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
10969 node. If it's the former then this function is being called to output a
10970 DIE to represent a formal parameter object (or some inlining thereof). If
10971 it's the latter, then this function is only being called to output a
10972 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
10973 argument type of some subprogram type. */
10976 gen_formal_parameter_die (tree node, dw_die_ref context_die)
10978 dw_die_ref parm_die
10979 = new_die (DW_TAG_formal_parameter, context_die, node);
10982 switch (TREE_CODE_CLASS (TREE_CODE (node)))
10984 case tcc_declaration:
10985 origin = decl_ultimate_origin (node);
10986 if (origin != NULL)
10987 add_abstract_origin_attribute (parm_die, origin);
10990 add_name_and_src_coords_attributes (parm_die, node);
10991 add_type_attribute (parm_die, TREE_TYPE (node),
10992 TREE_READONLY (node),
10993 TREE_THIS_VOLATILE (node),
10995 if (DECL_ARTIFICIAL (node))
10996 add_AT_flag (parm_die, DW_AT_artificial, 1);
10999 equate_decl_number_to_die (node, parm_die);
11000 if (! DECL_ABSTRACT (node))
11001 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
11006 /* We were called with some kind of a ..._TYPE node. */
11007 add_type_attribute (parm_die, node, 0, 0, context_die);
11011 gcc_unreachable ();
11017 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
11018 at the end of an (ANSI prototyped) formal parameters list. */
11021 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
11023 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
11026 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
11027 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
11028 parameters as specified in some function type specification (except for
11029 those which appear as part of a function *definition*). */
11032 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
11035 tree formal_type = NULL;
11036 tree first_parm_type;
11039 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
11041 arg = DECL_ARGUMENTS (function_or_method_type);
11042 function_or_method_type = TREE_TYPE (function_or_method_type);
11047 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
11049 /* Make our first pass over the list of formal parameter types and output a
11050 DW_TAG_formal_parameter DIE for each one. */
11051 for (link = first_parm_type; link; )
11053 dw_die_ref parm_die;
11055 formal_type = TREE_VALUE (link);
11056 if (formal_type == void_type_node)
11059 /* Output a (nameless) DIE to represent the formal parameter itself. */
11060 parm_die = gen_formal_parameter_die (formal_type, context_die);
11061 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
11062 && link == first_parm_type)
11063 || (arg && DECL_ARTIFICIAL (arg)))
11064 add_AT_flag (parm_die, DW_AT_artificial, 1);
11066 link = TREE_CHAIN (link);
11068 arg = TREE_CHAIN (arg);
11071 /* If this function type has an ellipsis, add a
11072 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
11073 if (formal_type != void_type_node)
11074 gen_unspecified_parameters_die (function_or_method_type, context_die);
11076 /* Make our second (and final) pass over the list of formal parameter types
11077 and output DIEs to represent those types (as necessary). */
11078 for (link = TYPE_ARG_TYPES (function_or_method_type);
11079 link && TREE_VALUE (link);
11080 link = TREE_CHAIN (link))
11081 gen_type_die (TREE_VALUE (link), context_die);
11084 /* We want to generate the DIE for TYPE so that we can generate the
11085 die for MEMBER, which has been defined; we will need to refer back
11086 to the member declaration nested within TYPE. If we're trying to
11087 generate minimal debug info for TYPE, processing TYPE won't do the
11088 trick; we need to attach the member declaration by hand. */
11091 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
11093 gen_type_die (type, context_die);
11095 /* If we're trying to avoid duplicate debug info, we may not have
11096 emitted the member decl for this function. Emit it now. */
11097 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
11098 && ! lookup_decl_die (member))
11100 gcc_assert (!decl_ultimate_origin (member));
11102 push_decl_scope (type);
11103 if (TREE_CODE (member) == FUNCTION_DECL)
11104 gen_subprogram_die (member, lookup_type_die (type));
11106 gen_variable_die (member, lookup_type_die (type));
11112 /* Generate the DWARF2 info for the "abstract" instance of a function which we
11113 may later generate inlined and/or out-of-line instances of. */
11116 dwarf2out_abstract_function (tree decl)
11118 dw_die_ref old_die;
11121 int was_abstract = DECL_ABSTRACT (decl);
11123 /* Make sure we have the actual abstract inline, not a clone. */
11124 decl = DECL_ORIGIN (decl);
11126 old_die = lookup_decl_die (decl);
11127 if (old_die && get_AT (old_die, DW_AT_inline))
11128 /* We've already generated the abstract instance. */
11131 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
11132 we don't get confused by DECL_ABSTRACT. */
11133 if (debug_info_level > DINFO_LEVEL_TERSE)
11135 context = decl_class_context (decl);
11137 gen_type_die_for_member
11138 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
11141 /* Pretend we've just finished compiling this function. */
11142 save_fn = current_function_decl;
11143 current_function_decl = decl;
11145 set_decl_abstract_flags (decl, 1);
11146 dwarf2out_decl (decl);
11147 if (! was_abstract)
11148 set_decl_abstract_flags (decl, 0);
11150 current_function_decl = save_fn;
11153 /* Generate a DIE to represent a declared function (either file-scope or
11157 gen_subprogram_die (tree decl, dw_die_ref context_die)
11159 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
11160 tree origin = decl_ultimate_origin (decl);
11161 dw_die_ref subr_die;
11165 dw_die_ref old_die = lookup_decl_die (decl);
11166 int declaration = (current_function_decl != decl
11167 || class_or_namespace_scope_p (context_die));
11169 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
11170 started to generate the abstract instance of an inline, decided to output
11171 its containing class, and proceeded to emit the declaration of the inline
11172 from the member list for the class. If so, DECLARATION takes priority;
11173 we'll get back to the abstract instance when done with the class. */
11175 /* The class-scope declaration DIE must be the primary DIE. */
11176 if (origin && declaration && class_or_namespace_scope_p (context_die))
11179 gcc_assert (!old_die);
11182 if (origin != NULL)
11184 gcc_assert (!declaration || local_scope_p (context_die));
11186 /* Fixup die_parent for the abstract instance of a nested
11187 inline function. */
11188 if (old_die && old_die->die_parent == NULL)
11189 add_child_die (context_die, old_die);
11191 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11192 add_abstract_origin_attribute (subr_die, origin);
11196 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11197 unsigned file_index = lookup_filename (s.file);
11199 if (!get_AT_flag (old_die, DW_AT_declaration)
11200 /* We can have a normal definition following an inline one in the
11201 case of redefinition of GNU C extern inlines.
11202 It seems reasonable to use AT_specification in this case. */
11203 && !get_AT (old_die, DW_AT_inline))
11205 /* ??? This can happen if there is a bug in the program, for
11206 instance, if it has duplicate function definitions. Ideally,
11207 we should detect this case and ignore it. For now, if we have
11208 already reported an error, any error at all, then assume that
11209 we got here because of an input error, not a dwarf2 bug. */
11210 gcc_assert (errorcount);
11214 /* If the definition comes from the same place as the declaration,
11215 maybe use the old DIE. We always want the DIE for this function
11216 that has the *_pc attributes to be under comp_unit_die so the
11217 debugger can find it. We also need to do this for abstract
11218 instances of inlines, since the spec requires the out-of-line copy
11219 to have the same parent. For local class methods, this doesn't
11220 apply; we just use the old DIE. */
11221 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
11222 && (DECL_ARTIFICIAL (decl)
11223 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
11224 && (get_AT_unsigned (old_die, DW_AT_decl_line)
11225 == (unsigned) s.line))))
11227 subr_die = old_die;
11229 /* Clear out the declaration attribute and the formal parameters.
11230 Do not remove all children, because it is possible that this
11231 declaration die was forced using force_decl_die(). In such
11232 cases die that forced declaration die (e.g. TAG_imported_module)
11233 is one of the children that we do not want to remove. */
11234 remove_AT (subr_die, DW_AT_declaration);
11235 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
11239 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11240 add_AT_specification (subr_die, old_die);
11241 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
11242 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
11243 if (get_AT_unsigned (old_die, DW_AT_decl_line)
11244 != (unsigned) s.line)
11246 (subr_die, DW_AT_decl_line, s.line);
11251 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11253 if (TREE_PUBLIC (decl))
11254 add_AT_flag (subr_die, DW_AT_external, 1);
11256 add_name_and_src_coords_attributes (subr_die, decl);
11257 if (debug_info_level > DINFO_LEVEL_TERSE)
11259 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
11260 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
11261 0, 0, context_die);
11264 add_pure_or_virtual_attribute (subr_die, decl);
11265 if (DECL_ARTIFICIAL (decl))
11266 add_AT_flag (subr_die, DW_AT_artificial, 1);
11268 if (TREE_PROTECTED (decl))
11269 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
11270 else if (TREE_PRIVATE (decl))
11271 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
11276 if (!old_die || !get_AT (old_die, DW_AT_inline))
11278 add_AT_flag (subr_die, DW_AT_declaration, 1);
11280 /* The first time we see a member function, it is in the context of
11281 the class to which it belongs. We make sure of this by emitting
11282 the class first. The next time is the definition, which is
11283 handled above. The two may come from the same source text.
11285 Note that force_decl_die() forces function declaration die. It is
11286 later reused to represent definition. */
11287 equate_decl_number_to_die (decl, subr_die);
11290 else if (DECL_ABSTRACT (decl))
11292 if (DECL_DECLARED_INLINE_P (decl))
11294 if (cgraph_function_possibly_inlined_p (decl))
11295 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
11297 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
11301 if (cgraph_function_possibly_inlined_p (decl))
11302 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
11304 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
11307 equate_decl_number_to_die (decl, subr_die);
11309 else if (!DECL_EXTERNAL (decl))
11311 if (!old_die || !get_AT (old_die, DW_AT_inline))
11312 equate_decl_number_to_die (decl, subr_die);
11314 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
11315 current_function_funcdef_no);
11316 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
11317 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
11318 current_function_funcdef_no);
11319 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
11321 add_pubname (decl, subr_die);
11322 add_arange (decl, subr_die);
11324 #ifdef MIPS_DEBUGGING_INFO
11325 /* Add a reference to the FDE for this routine. */
11326 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
11329 /* Define the "frame base" location for this routine. We use the
11330 frame pointer or stack pointer registers, since the RTL for local
11331 variables is relative to one of them. */
11332 if (frame_base_decl && lookup_decl_loc (frame_base_decl) != NULL)
11334 add_location_or_const_value_attribute (subr_die, frame_base_decl,
11340 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
11341 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
11344 if (cfun->static_chain_decl)
11345 add_AT_location_description (subr_die, DW_AT_static_link,
11346 loc_descriptor_from_tree (cfun->static_chain_decl));
11349 /* Now output descriptions of the arguments for this function. This gets
11350 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
11351 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
11352 `...' at the end of the formal parameter list. In order to find out if
11353 there was a trailing ellipsis or not, we must instead look at the type
11354 associated with the FUNCTION_DECL. This will be a node of type
11355 FUNCTION_TYPE. If the chain of type nodes hanging off of this
11356 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
11357 an ellipsis at the end. */
11359 /* In the case where we are describing a mere function declaration, all we
11360 need to do here (and all we *can* do here) is to describe the *types* of
11361 its formal parameters. */
11362 if (debug_info_level <= DINFO_LEVEL_TERSE)
11364 else if (declaration)
11365 gen_formal_types_die (decl, subr_die);
11368 /* Generate DIEs to represent all known formal parameters. */
11369 tree arg_decls = DECL_ARGUMENTS (decl);
11372 /* When generating DIEs, generate the unspecified_parameters DIE
11373 instead if we come across the arg "__builtin_va_alist" */
11374 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
11375 if (TREE_CODE (parm) == PARM_DECL)
11377 if (DECL_NAME (parm)
11378 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
11379 "__builtin_va_alist"))
11380 gen_unspecified_parameters_die (parm, subr_die);
11382 gen_decl_die (parm, subr_die);
11385 /* Decide whether we need an unspecified_parameters DIE at the end.
11386 There are 2 more cases to do this for: 1) the ansi ... declaration -
11387 this is detectable when the end of the arg list is not a
11388 void_type_node 2) an unprototyped function declaration (not a
11389 definition). This just means that we have no info about the
11390 parameters at all. */
11391 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
11392 if (fn_arg_types != NULL)
11394 /* This is the prototyped case, check for.... */
11395 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
11396 gen_unspecified_parameters_die (decl, subr_die);
11398 else if (DECL_INITIAL (decl) == NULL_TREE)
11399 gen_unspecified_parameters_die (decl, subr_die);
11402 /* Output Dwarf info for all of the stuff within the body of the function
11403 (if it has one - it may be just a declaration). */
11404 outer_scope = DECL_INITIAL (decl);
11406 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
11407 a function. This BLOCK actually represents the outermost binding contour
11408 for the function, i.e. the contour in which the function's formal
11409 parameters and labels get declared. Curiously, it appears that the front
11410 end doesn't actually put the PARM_DECL nodes for the current function onto
11411 the BLOCK_VARS list for this outer scope, but are strung off of the
11412 DECL_ARGUMENTS list for the function instead.
11414 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
11415 the LABEL_DECL nodes for the function however, and we output DWARF info
11416 for those in decls_for_scope. Just within the `outer_scope' there will be
11417 a BLOCK node representing the function's outermost pair of curly braces,
11418 and any blocks used for the base and member initializers of a C++
11419 constructor function. */
11420 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
11422 /* Emit a DW_TAG_variable DIE for a named return value. */
11423 if (DECL_NAME (DECL_RESULT (decl)))
11424 gen_decl_die (DECL_RESULT (decl), subr_die);
11426 current_function_has_inlines = 0;
11427 decls_for_scope (outer_scope, subr_die, 0);
11429 #if 0 && defined (MIPS_DEBUGGING_INFO)
11430 if (current_function_has_inlines)
11432 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
11433 if (! comp_unit_has_inlines)
11435 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
11436 comp_unit_has_inlines = 1;
11441 /* Add the calling convention attribute if requested. */
11442 add_calling_convention_attribute (subr_die, TREE_TYPE (decl));
11446 /* Generate a DIE to represent a declared data object. */
11449 gen_variable_die (tree decl, dw_die_ref context_die)
11451 tree origin = decl_ultimate_origin (decl);
11452 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
11454 dw_die_ref old_die = lookup_decl_die (decl);
11455 int declaration = (DECL_EXTERNAL (decl)
11456 || class_or_namespace_scope_p (context_die));
11458 if (origin != NULL)
11459 add_abstract_origin_attribute (var_die, origin);
11461 /* Loop unrolling can create multiple blocks that refer to the same
11462 static variable, so we must test for the DW_AT_declaration flag.
11464 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
11465 copy decls and set the DECL_ABSTRACT flag on them instead of
11468 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
11469 else if (old_die && TREE_STATIC (decl)
11470 && get_AT_flag (old_die, DW_AT_declaration) == 1)
11472 /* This is a definition of a C++ class level static. */
11473 add_AT_specification (var_die, old_die);
11474 if (DECL_NAME (decl))
11476 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11477 unsigned file_index = lookup_filename (s.file);
11479 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
11480 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
11482 if (get_AT_unsigned (old_die, DW_AT_decl_line)
11483 != (unsigned) s.line)
11485 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
11490 add_name_and_src_coords_attributes (var_die, decl);
11491 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
11492 TREE_THIS_VOLATILE (decl), context_die);
11494 if (TREE_PUBLIC (decl))
11495 add_AT_flag (var_die, DW_AT_external, 1);
11497 if (DECL_ARTIFICIAL (decl))
11498 add_AT_flag (var_die, DW_AT_artificial, 1);
11500 if (TREE_PROTECTED (decl))
11501 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
11502 else if (TREE_PRIVATE (decl))
11503 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
11507 add_AT_flag (var_die, DW_AT_declaration, 1);
11509 if (DECL_ABSTRACT (decl) || declaration)
11510 equate_decl_number_to_die (decl, var_die);
11512 if (! declaration && ! DECL_ABSTRACT (decl))
11514 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
11515 add_pubname (decl, var_die);
11518 tree_add_const_value_attribute (var_die, decl);
11521 /* Generate a DIE to represent a label identifier. */
11524 gen_label_die (tree decl, dw_die_ref context_die)
11526 tree origin = decl_ultimate_origin (decl);
11527 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
11529 char label[MAX_ARTIFICIAL_LABEL_BYTES];
11531 if (origin != NULL)
11532 add_abstract_origin_attribute (lbl_die, origin);
11534 add_name_and_src_coords_attributes (lbl_die, decl);
11536 if (DECL_ABSTRACT (decl))
11537 equate_decl_number_to_die (decl, lbl_die);
11540 insn = DECL_RTL_IF_SET (decl);
11542 /* Deleted labels are programmer specified labels which have been
11543 eliminated because of various optimizations. We still emit them
11544 here so that it is possible to put breakpoints on them. */
11548 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))))
11550 /* When optimization is enabled (via -O) some parts of the compiler
11551 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
11552 represent source-level labels which were explicitly declared by
11553 the user. This really shouldn't be happening though, so catch
11554 it if it ever does happen. */
11555 gcc_assert (!INSN_DELETED_P (insn));
11557 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
11558 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
11563 /* Generate a DIE for a lexical block. */
11566 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
11568 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
11569 char label[MAX_ARTIFICIAL_LABEL_BYTES];
11571 if (! BLOCK_ABSTRACT (stmt))
11573 if (BLOCK_FRAGMENT_CHAIN (stmt))
11577 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
11579 chain = BLOCK_FRAGMENT_CHAIN (stmt);
11582 add_ranges (chain);
11583 chain = BLOCK_FRAGMENT_CHAIN (chain);
11590 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
11591 BLOCK_NUMBER (stmt));
11592 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
11593 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
11594 BLOCK_NUMBER (stmt));
11595 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
11599 decls_for_scope (stmt, stmt_die, depth);
11602 /* Generate a DIE for an inlined subprogram. */
11605 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
11607 tree decl = block_ultimate_origin (stmt);
11609 /* Emit info for the abstract instance first, if we haven't yet. We
11610 must emit this even if the block is abstract, otherwise when we
11611 emit the block below (or elsewhere), we may end up trying to emit
11612 a die whose origin die hasn't been emitted, and crashing. */
11613 dwarf2out_abstract_function (decl);
11615 if (! BLOCK_ABSTRACT (stmt))
11617 dw_die_ref subr_die
11618 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
11619 char label[MAX_ARTIFICIAL_LABEL_BYTES];
11621 add_abstract_origin_attribute (subr_die, decl);
11622 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
11623 BLOCK_NUMBER (stmt));
11624 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
11625 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
11626 BLOCK_NUMBER (stmt));
11627 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
11628 decls_for_scope (stmt, subr_die, depth);
11629 current_function_has_inlines = 1;
11632 /* We may get here if we're the outer block of function A that was
11633 inlined into function B that was inlined into function C. When
11634 generating debugging info for C, dwarf2out_abstract_function(B)
11635 would mark all inlined blocks as abstract, including this one.
11636 So, we wouldn't (and shouldn't) expect labels to be generated
11637 for this one. Instead, just emit debugging info for
11638 declarations within the block. This is particularly important
11639 in the case of initializers of arguments passed from B to us:
11640 if they're statement expressions containing declarations, we
11641 wouldn't generate dies for their abstract variables, and then,
11642 when generating dies for the real variables, we'd die (pun
11644 gen_lexical_block_die (stmt, context_die, depth);
11647 /* Generate a DIE for a field in a record, or structure. */
11650 gen_field_die (tree decl, dw_die_ref context_die)
11652 dw_die_ref decl_die;
11654 if (TREE_TYPE (decl) == error_mark_node)
11657 decl_die = new_die (DW_TAG_member, context_die, decl);
11658 add_name_and_src_coords_attributes (decl_die, decl);
11659 add_type_attribute (decl_die, member_declared_type (decl),
11660 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
11663 if (DECL_BIT_FIELD_TYPE (decl))
11665 add_byte_size_attribute (decl_die, decl);
11666 add_bit_size_attribute (decl_die, decl);
11667 add_bit_offset_attribute (decl_die, decl);
11670 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
11671 add_data_member_location_attribute (decl_die, decl);
11673 if (DECL_ARTIFICIAL (decl))
11674 add_AT_flag (decl_die, DW_AT_artificial, 1);
11676 if (TREE_PROTECTED (decl))
11677 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
11678 else if (TREE_PRIVATE (decl))
11679 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
11681 /* Equate decl number to die, so that we can look up this decl later on. */
11682 equate_decl_number_to_die (decl, decl_die);
11686 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11687 Use modified_type_die instead.
11688 We keep this code here just in case these types of DIEs may be needed to
11689 represent certain things in other languages (e.g. Pascal) someday. */
11692 gen_pointer_type_die (tree type, dw_die_ref context_die)
11695 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
11697 equate_type_number_to_die (type, ptr_die);
11698 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
11699 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
11702 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11703 Use modified_type_die instead.
11704 We keep this code here just in case these types of DIEs may be needed to
11705 represent certain things in other languages (e.g. Pascal) someday. */
11708 gen_reference_type_die (tree type, dw_die_ref context_die)
11711 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
11713 equate_type_number_to_die (type, ref_die);
11714 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
11715 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
11719 /* Generate a DIE for a pointer to a member type. */
11722 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
11725 = new_die (DW_TAG_ptr_to_member_type,
11726 scope_die_for (type, context_die), type);
11728 equate_type_number_to_die (type, ptr_die);
11729 add_AT_die_ref (ptr_die, DW_AT_containing_type,
11730 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
11731 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
11734 /* Generate the DIE for the compilation unit. */
11737 gen_compile_unit_die (const char *filename)
11740 char producer[250];
11741 const char *language_string = lang_hooks.name;
11744 die = new_die (DW_TAG_compile_unit, NULL, NULL);
11748 add_name_attribute (die, filename);
11749 /* Don't add cwd for <built-in>. */
11750 if (filename[0] != DIR_SEPARATOR && filename[0] != '<')
11751 add_comp_dir_attribute (die);
11754 sprintf (producer, "%s %s", language_string, version_string);
11756 #ifdef MIPS_DEBUGGING_INFO
11757 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
11758 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
11759 not appear in the producer string, the debugger reaches the conclusion
11760 that the object file is stripped and has no debugging information.
11761 To get the MIPS/SGI debugger to believe that there is debugging
11762 information in the object file, we add a -g to the producer string. */
11763 if (debug_info_level > DINFO_LEVEL_TERSE)
11764 strcat (producer, " -g");
11767 add_AT_string (die, DW_AT_producer, producer);
11769 if (strcmp (language_string, "GNU C++") == 0)
11770 language = DW_LANG_C_plus_plus;
11771 else if (strcmp (language_string, "GNU Ada") == 0)
11772 language = DW_LANG_Ada95;
11773 else if (strcmp (language_string, "GNU F77") == 0)
11774 language = DW_LANG_Fortran77;
11775 else if (strcmp (language_string, "GNU F95") == 0)
11776 language = DW_LANG_Fortran95;
11777 else if (strcmp (language_string, "GNU Pascal") == 0)
11778 language = DW_LANG_Pascal83;
11779 else if (strcmp (language_string, "GNU Java") == 0)
11780 language = DW_LANG_Java;
11782 language = DW_LANG_C89;
11784 add_AT_unsigned (die, DW_AT_language, language);
11788 /* Generate a DIE for a string type. */
11791 gen_string_type_die (tree type, dw_die_ref context_die)
11793 dw_die_ref type_die
11794 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
11796 equate_type_number_to_die (type, type_die);
11798 /* ??? Fudge the string length attribute for now.
11799 TODO: add string length info. */
11801 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
11802 bound_representation (upper_bound, 0, 'u');
11806 /* Generate the DIE for a base class. */
11809 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
11811 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
11813 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
11814 add_data_member_location_attribute (die, binfo);
11816 if (BINFO_VIRTUAL_P (binfo))
11817 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
11819 if (access == access_public_node)
11820 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
11821 else if (access == access_protected_node)
11822 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
11825 /* Generate a DIE for a class member. */
11828 gen_member_die (tree type, dw_die_ref context_die)
11831 tree binfo = TYPE_BINFO (type);
11834 /* If this is not an incomplete type, output descriptions of each of its
11835 members. Note that as we output the DIEs necessary to represent the
11836 members of this record or union type, we will also be trying to output
11837 DIEs to represent the *types* of those members. However the `type'
11838 function (above) will specifically avoid generating type DIEs for member
11839 types *within* the list of member DIEs for this (containing) type except
11840 for those types (of members) which are explicitly marked as also being
11841 members of this (containing) type themselves. The g++ front- end can
11842 force any given type to be treated as a member of some other (containing)
11843 type by setting the TYPE_CONTEXT of the given (member) type to point to
11844 the TREE node representing the appropriate (containing) type. */
11846 /* First output info about the base classes. */
11849 VEC (tree) *accesses = BINFO_BASE_ACCESSES (binfo);
11853 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
11854 gen_inheritance_die (base,
11855 (accesses ? VEC_index (tree, accesses, i)
11856 : access_public_node), context_die);
11859 /* Now output info about the data members and type members. */
11860 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
11862 /* If we thought we were generating minimal debug info for TYPE
11863 and then changed our minds, some of the member declarations
11864 may have already been defined. Don't define them again, but
11865 do put them in the right order. */
11867 child = lookup_decl_die (member);
11869 splice_child_die (context_die, child);
11871 gen_decl_die (member, context_die);
11874 /* Now output info about the function members (if any). */
11875 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
11877 /* Don't include clones in the member list. */
11878 if (DECL_ABSTRACT_ORIGIN (member))
11881 child = lookup_decl_die (member);
11883 splice_child_die (context_die, child);
11885 gen_decl_die (member, context_die);
11889 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
11890 is set, we pretend that the type was never defined, so we only get the
11891 member DIEs needed by later specification DIEs. */
11894 gen_struct_or_union_type_die (tree type, dw_die_ref context_die)
11896 dw_die_ref type_die = lookup_type_die (type);
11897 dw_die_ref scope_die = 0;
11899 int complete = (TYPE_SIZE (type)
11900 && (! TYPE_STUB_DECL (type)
11901 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
11902 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
11904 if (type_die && ! complete)
11907 if (TYPE_CONTEXT (type) != NULL_TREE
11908 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
11909 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
11912 scope_die = scope_die_for (type, context_die);
11914 if (! type_die || (nested && scope_die == comp_unit_die))
11915 /* First occurrence of type or toplevel definition of nested class. */
11917 dw_die_ref old_die = type_die;
11919 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
11920 ? DW_TAG_structure_type : DW_TAG_union_type,
11922 equate_type_number_to_die (type, type_die);
11924 add_AT_specification (type_die, old_die);
11926 add_name_attribute (type_die, type_tag (type));
11929 remove_AT (type_die, DW_AT_declaration);
11931 /* If this type has been completed, then give it a byte_size attribute and
11932 then give a list of members. */
11933 if (complete && !ns_decl)
11935 /* Prevent infinite recursion in cases where the type of some member of
11936 this type is expressed in terms of this type itself. */
11937 TREE_ASM_WRITTEN (type) = 1;
11938 add_byte_size_attribute (type_die, type);
11939 if (TYPE_STUB_DECL (type) != NULL_TREE)
11940 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
11942 /* If the first reference to this type was as the return type of an
11943 inline function, then it may not have a parent. Fix this now. */
11944 if (type_die->die_parent == NULL)
11945 add_child_die (scope_die, type_die);
11947 push_decl_scope (type);
11948 gen_member_die (type, type_die);
11951 /* GNU extension: Record what type our vtable lives in. */
11952 if (TYPE_VFIELD (type))
11954 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
11956 gen_type_die (vtype, context_die);
11957 add_AT_die_ref (type_die, DW_AT_containing_type,
11958 lookup_type_die (vtype));
11963 add_AT_flag (type_die, DW_AT_declaration, 1);
11965 /* We don't need to do this for function-local types. */
11966 if (TYPE_STUB_DECL (type)
11967 && ! decl_function_context (TYPE_STUB_DECL (type)))
11968 VARRAY_PUSH_TREE (incomplete_types, type);
11972 /* Generate a DIE for a subroutine _type_. */
11975 gen_subroutine_type_die (tree type, dw_die_ref context_die)
11977 tree return_type = TREE_TYPE (type);
11978 dw_die_ref subr_die
11979 = new_die (DW_TAG_subroutine_type,
11980 scope_die_for (type, context_die), type);
11982 equate_type_number_to_die (type, subr_die);
11983 add_prototyped_attribute (subr_die, type);
11984 add_type_attribute (subr_die, return_type, 0, 0, context_die);
11985 gen_formal_types_die (type, subr_die);
11988 /* Generate a DIE for a type definition. */
11991 gen_typedef_die (tree decl, dw_die_ref context_die)
11993 dw_die_ref type_die;
11996 if (TREE_ASM_WRITTEN (decl))
11999 TREE_ASM_WRITTEN (decl) = 1;
12000 type_die = new_die (DW_TAG_typedef, context_die, decl);
12001 origin = decl_ultimate_origin (decl);
12002 if (origin != NULL)
12003 add_abstract_origin_attribute (type_die, origin);
12008 add_name_and_src_coords_attributes (type_die, decl);
12009 if (DECL_ORIGINAL_TYPE (decl))
12011 type = DECL_ORIGINAL_TYPE (decl);
12013 gcc_assert (type != TREE_TYPE (decl));
12014 equate_type_number_to_die (TREE_TYPE (decl), type_die);
12017 type = TREE_TYPE (decl);
12019 add_type_attribute (type_die, type, TREE_READONLY (decl),
12020 TREE_THIS_VOLATILE (decl), context_die);
12023 if (DECL_ABSTRACT (decl))
12024 equate_decl_number_to_die (decl, type_die);
12027 /* Generate a type description DIE. */
12030 gen_type_die (tree type, dw_die_ref context_die)
12034 if (type == NULL_TREE || type == error_mark_node)
12037 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12038 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
12040 if (TREE_ASM_WRITTEN (type))
12043 /* Prevent broken recursion; we can't hand off to the same type. */
12044 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
12046 TREE_ASM_WRITTEN (type) = 1;
12047 gen_decl_die (TYPE_NAME (type), context_die);
12051 /* We are going to output a DIE to represent the unqualified version
12052 of this type (i.e. without any const or volatile qualifiers) so
12053 get the main variant (i.e. the unqualified version) of this type
12054 now. (Vectors are special because the debugging info is in the
12055 cloned type itself). */
12056 if (TREE_CODE (type) != VECTOR_TYPE)
12057 type = type_main_variant (type);
12059 if (TREE_ASM_WRITTEN (type))
12062 switch (TREE_CODE (type))
12068 case REFERENCE_TYPE:
12069 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
12070 ensures that the gen_type_die recursion will terminate even if the
12071 type is recursive. Recursive types are possible in Ada. */
12072 /* ??? We could perhaps do this for all types before the switch
12074 TREE_ASM_WRITTEN (type) = 1;
12076 /* For these types, all that is required is that we output a DIE (or a
12077 set of DIEs) to represent the "basis" type. */
12078 gen_type_die (TREE_TYPE (type), context_die);
12082 /* This code is used for C++ pointer-to-data-member types.
12083 Output a description of the relevant class type. */
12084 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
12086 /* Output a description of the type of the object pointed to. */
12087 gen_type_die (TREE_TYPE (type), context_die);
12089 /* Now output a DIE to represent this pointer-to-data-member type
12091 gen_ptr_to_mbr_type_die (type, context_die);
12095 gen_type_die (TYPE_DOMAIN (type), context_die);
12096 gen_set_type_die (type, context_die);
12100 gen_type_die (TREE_TYPE (type), context_die);
12101 /* No way to represent these in Dwarf yet! */
12102 gcc_unreachable ();
12105 case FUNCTION_TYPE:
12106 /* Force out return type (in case it wasn't forced out already). */
12107 gen_type_die (TREE_TYPE (type), context_die);
12108 gen_subroutine_type_die (type, context_die);
12112 /* Force out return type (in case it wasn't forced out already). */
12113 gen_type_die (TREE_TYPE (type), context_die);
12114 gen_subroutine_type_die (type, context_die);
12118 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
12120 gen_type_die (TREE_TYPE (type), context_die);
12121 gen_string_type_die (type, context_die);
12124 gen_array_type_die (type, context_die);
12128 gen_array_type_die (type, context_die);
12131 case ENUMERAL_TYPE:
12134 case QUAL_UNION_TYPE:
12135 /* If this is a nested type whose containing class hasn't been written
12136 out yet, writing it out will cover this one, too. This does not apply
12137 to instantiations of member class templates; they need to be added to
12138 the containing class as they are generated. FIXME: This hurts the
12139 idea of combining type decls from multiple TUs, since we can't predict
12140 what set of template instantiations we'll get. */
12141 if (TYPE_CONTEXT (type)
12142 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
12143 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
12145 gen_type_die (TYPE_CONTEXT (type), context_die);
12147 if (TREE_ASM_WRITTEN (type))
12150 /* If that failed, attach ourselves to the stub. */
12151 push_decl_scope (TYPE_CONTEXT (type));
12152 context_die = lookup_type_die (TYPE_CONTEXT (type));
12157 declare_in_namespace (type, context_die);
12161 if (TREE_CODE (type) == ENUMERAL_TYPE)
12162 gen_enumeration_type_die (type, context_die);
12164 gen_struct_or_union_type_die (type, context_die);
12169 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
12170 it up if it is ever completed. gen_*_type_die will set it for us
12171 when appropriate. */
12180 /* No DIEs needed for fundamental types. */
12184 /* No Dwarf representation currently defined. */
12188 gcc_unreachable ();
12191 TREE_ASM_WRITTEN (type) = 1;
12194 /* Generate a DIE for a tagged type instantiation. */
12197 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
12199 if (type == NULL_TREE || type == error_mark_node)
12202 /* We are going to output a DIE to represent the unqualified version of
12203 this type (i.e. without any const or volatile qualifiers) so make sure
12204 that we have the main variant (i.e. the unqualified version) of this
12206 gcc_assert (type == type_main_variant (type));
12208 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
12209 an instance of an unresolved type. */
12211 switch (TREE_CODE (type))
12216 case ENUMERAL_TYPE:
12217 gen_inlined_enumeration_type_die (type, context_die);
12221 gen_inlined_structure_type_die (type, context_die);
12225 case QUAL_UNION_TYPE:
12226 gen_inlined_union_type_die (type, context_die);
12230 gcc_unreachable ();
12234 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
12235 things which are local to the given block. */
12238 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
12240 int must_output_die = 0;
12243 enum tree_code origin_code;
12245 /* Ignore blocks never really used to make RTL. */
12246 if (stmt == NULL_TREE || !TREE_USED (stmt)
12247 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
12250 /* If the block is one fragment of a non-contiguous block, do not
12251 process the variables, since they will have been done by the
12252 origin block. Do process subblocks. */
12253 if (BLOCK_FRAGMENT_ORIGIN (stmt))
12257 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
12258 gen_block_die (sub, context_die, depth + 1);
12263 /* Determine the "ultimate origin" of this block. This block may be an
12264 inlined instance of an inlined instance of inline function, so we have
12265 to trace all of the way back through the origin chain to find out what
12266 sort of node actually served as the original seed for the creation of
12267 the current block. */
12268 origin = block_ultimate_origin (stmt);
12269 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
12271 /* Determine if we need to output any Dwarf DIEs at all to represent this
12273 if (origin_code == FUNCTION_DECL)
12274 /* The outer scopes for inlinings *must* always be represented. We
12275 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
12276 must_output_die = 1;
12279 /* In the case where the current block represents an inlining of the
12280 "body block" of an inline function, we must *NOT* output any DIE for
12281 this block because we have already output a DIE to represent the whole
12282 inlined function scope and the "body block" of any function doesn't
12283 really represent a different scope according to ANSI C rules. So we
12284 check here to make sure that this block does not represent a "body
12285 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
12286 if (! is_body_block (origin ? origin : stmt))
12288 /* Determine if this block directly contains any "significant"
12289 local declarations which we will need to output DIEs for. */
12290 if (debug_info_level > DINFO_LEVEL_TERSE)
12291 /* We are not in terse mode so *any* local declaration counts
12292 as being a "significant" one. */
12293 must_output_die = (BLOCK_VARS (stmt) != NULL);
12295 /* We are in terse mode, so only local (nested) function
12296 definitions count as "significant" local declarations. */
12297 for (decl = BLOCK_VARS (stmt);
12298 decl != NULL; decl = TREE_CHAIN (decl))
12299 if (TREE_CODE (decl) == FUNCTION_DECL
12300 && DECL_INITIAL (decl))
12302 must_output_die = 1;
12308 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
12309 DIE for any block which contains no significant local declarations at
12310 all. Rather, in such cases we just call `decls_for_scope' so that any
12311 needed Dwarf info for any sub-blocks will get properly generated. Note
12312 that in terse mode, our definition of what constitutes a "significant"
12313 local declaration gets restricted to include only inlined function
12314 instances and local (nested) function definitions. */
12315 if (must_output_die)
12317 if (origin_code == FUNCTION_DECL)
12318 gen_inlined_subroutine_die (stmt, context_die, depth);
12320 gen_lexical_block_die (stmt, context_die, depth);
12323 decls_for_scope (stmt, context_die, depth);
12326 /* Generate all of the decls declared within a given scope and (recursively)
12327 all of its sub-blocks. */
12330 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
12335 /* Ignore blocks never really used to make RTL. */
12336 if (stmt == NULL_TREE || ! TREE_USED (stmt))
12339 /* Output the DIEs to represent all of the data objects and typedefs
12340 declared directly within this block but not within any nested
12341 sub-blocks. Also, nested function and tag DIEs have been
12342 generated with a parent of NULL; fix that up now. */
12343 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
12347 if (TREE_CODE (decl) == FUNCTION_DECL)
12348 die = lookup_decl_die (decl);
12349 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
12350 die = lookup_type_die (TREE_TYPE (decl));
12354 if (die != NULL && die->die_parent == NULL)
12355 add_child_die (context_die, die);
12357 gen_decl_die (decl, context_die);
12360 /* If we're at -g1, we're not interested in subblocks. */
12361 if (debug_info_level <= DINFO_LEVEL_TERSE)
12364 /* Output the DIEs to represent all sub-blocks (and the items declared
12365 therein) of this block. */
12366 for (subblocks = BLOCK_SUBBLOCKS (stmt);
12368 subblocks = BLOCK_CHAIN (subblocks))
12369 gen_block_die (subblocks, context_die, depth + 1);
12372 /* Is this a typedef we can avoid emitting? */
12375 is_redundant_typedef (tree decl)
12377 if (TYPE_DECL_IS_STUB (decl))
12380 if (DECL_ARTIFICIAL (decl)
12381 && DECL_CONTEXT (decl)
12382 && is_tagged_type (DECL_CONTEXT (decl))
12383 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
12384 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
12385 /* Also ignore the artificial member typedef for the class name. */
12391 /* Returns the DIE for decl or aborts. */
12394 force_decl_die (tree decl)
12396 dw_die_ref decl_die;
12397 unsigned saved_external_flag;
12398 tree save_fn = NULL_TREE;
12399 decl_die = lookup_decl_die (decl);
12402 dw_die_ref context_die;
12403 tree decl_context = DECL_CONTEXT (decl);
12406 /* Find die that represents this context. */
12407 if (TYPE_P (decl_context))
12408 context_die = force_type_die (decl_context);
12410 context_die = force_decl_die (decl_context);
12413 context_die = comp_unit_die;
12415 switch (TREE_CODE (decl))
12417 case FUNCTION_DECL:
12418 /* Clear current_function_decl, so that gen_subprogram_die thinks
12419 that this is a declaration. At this point, we just want to force
12420 declaration die. */
12421 save_fn = current_function_decl;
12422 current_function_decl = NULL_TREE;
12423 gen_subprogram_die (decl, context_die);
12424 current_function_decl = save_fn;
12428 /* Set external flag to force declaration die. Restore it after
12429 gen_decl_die() call. */
12430 saved_external_flag = DECL_EXTERNAL (decl);
12431 DECL_EXTERNAL (decl) = 1;
12432 gen_decl_die (decl, context_die);
12433 DECL_EXTERNAL (decl) = saved_external_flag;
12436 case NAMESPACE_DECL:
12437 dwarf2out_decl (decl);
12441 gcc_unreachable ();
12444 /* See if we can find the die for this deci now.
12445 If not then abort. */
12447 decl_die = lookup_decl_die (decl);
12448 gcc_assert (decl_die);
12454 /* Returns the DIE for decl or aborts. */
12457 force_type_die (tree type)
12459 dw_die_ref type_die;
12461 type_die = lookup_type_die (type);
12464 dw_die_ref context_die;
12465 if (TYPE_CONTEXT (type))
12466 if (TYPE_P (TYPE_CONTEXT (type)))
12467 context_die = force_type_die (TYPE_CONTEXT (type));
12469 context_die = force_decl_die (TYPE_CONTEXT (type));
12471 context_die = comp_unit_die;
12473 gen_type_die (type, context_die);
12474 type_die = lookup_type_die (type);
12475 gcc_assert (type_die);
12480 /* Force out any required namespaces to be able to output DECL,
12481 and return the new context_die for it, if it's changed. */
12484 setup_namespace_context (tree thing, dw_die_ref context_die)
12486 tree context = (DECL_P (thing)
12487 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
12488 if (context && TREE_CODE (context) == NAMESPACE_DECL)
12489 /* Force out the namespace. */
12490 context_die = force_decl_die (context);
12492 return context_die;
12495 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
12496 type) within its namespace, if appropriate.
12498 For compatibility with older debuggers, namespace DIEs only contain
12499 declarations; all definitions are emitted at CU scope. */
12502 declare_in_namespace (tree thing, dw_die_ref context_die)
12504 dw_die_ref ns_context;
12506 if (debug_info_level <= DINFO_LEVEL_TERSE)
12509 ns_context = setup_namespace_context (thing, context_die);
12511 if (ns_context != context_die)
12513 if (DECL_P (thing))
12514 gen_decl_die (thing, ns_context);
12516 gen_type_die (thing, ns_context);
12520 /* Generate a DIE for a namespace or namespace alias. */
12523 gen_namespace_die (tree decl)
12525 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
12527 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
12528 they are an alias of. */
12529 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
12531 /* Output a real namespace. */
12532 dw_die_ref namespace_die
12533 = new_die (DW_TAG_namespace, context_die, decl);
12534 add_name_and_src_coords_attributes (namespace_die, decl);
12535 equate_decl_number_to_die (decl, namespace_die);
12539 /* Output a namespace alias. */
12541 /* Force out the namespace we are an alias of, if necessary. */
12542 dw_die_ref origin_die
12543 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
12545 /* Now create the namespace alias DIE. */
12546 dw_die_ref namespace_die
12547 = new_die (DW_TAG_imported_declaration, context_die, decl);
12548 add_name_and_src_coords_attributes (namespace_die, decl);
12549 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
12550 equate_decl_number_to_die (decl, namespace_die);
12554 /* Generate Dwarf debug information for a decl described by DECL. */
12557 gen_decl_die (tree decl, dw_die_ref context_die)
12561 if (DECL_P (decl) && DECL_IGNORED_P (decl))
12564 switch (TREE_CODE (decl))
12570 /* The individual enumerators of an enum type get output when we output
12571 the Dwarf representation of the relevant enum type itself. */
12574 case FUNCTION_DECL:
12575 /* Don't output any DIEs to represent mere function declarations,
12576 unless they are class members or explicit block externs. */
12577 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
12578 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
12583 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
12584 on local redeclarations of global functions. That seems broken. */
12585 if (current_function_decl != decl)
12586 /* This is only a declaration. */;
12589 /* If we're emitting a clone, emit info for the abstract instance. */
12590 if (DECL_ORIGIN (decl) != decl)
12591 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
12593 /* If we're emitting an out-of-line copy of an inline function,
12594 emit info for the abstract instance and set up to refer to it. */
12595 else if (cgraph_function_possibly_inlined_p (decl)
12596 && ! DECL_ABSTRACT (decl)
12597 && ! class_or_namespace_scope_p (context_die)
12598 /* dwarf2out_abstract_function won't emit a die if this is just
12599 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
12600 that case, because that works only if we have a die. */
12601 && DECL_INITIAL (decl) != NULL_TREE)
12603 dwarf2out_abstract_function (decl);
12604 set_decl_origin_self (decl);
12607 /* Otherwise we're emitting the primary DIE for this decl. */
12608 else if (debug_info_level > DINFO_LEVEL_TERSE)
12610 /* Before we describe the FUNCTION_DECL itself, make sure that we
12611 have described its return type. */
12612 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
12614 /* And its virtual context. */
12615 if (DECL_VINDEX (decl) != NULL_TREE)
12616 gen_type_die (DECL_CONTEXT (decl), context_die);
12618 /* And its containing type. */
12619 origin = decl_class_context (decl);
12620 if (origin != NULL_TREE)
12621 gen_type_die_for_member (origin, decl, context_die);
12623 /* And its containing namespace. */
12624 declare_in_namespace (decl, context_die);
12627 /* Now output a DIE to represent the function itself. */
12628 gen_subprogram_die (decl, context_die);
12632 /* If we are in terse mode, don't generate any DIEs to represent any
12633 actual typedefs. */
12634 if (debug_info_level <= DINFO_LEVEL_TERSE)
12637 /* In the special case of a TYPE_DECL node representing the declaration
12638 of some type tag, if the given TYPE_DECL is marked as having been
12639 instantiated from some other (original) TYPE_DECL node (e.g. one which
12640 was generated within the original definition of an inline function) we
12641 have to generate a special (abbreviated) DW_TAG_structure_type,
12642 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
12643 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
12645 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
12649 if (is_redundant_typedef (decl))
12650 gen_type_die (TREE_TYPE (decl), context_die);
12652 /* Output a DIE to represent the typedef itself. */
12653 gen_typedef_die (decl, context_die);
12657 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12658 gen_label_die (decl, context_die);
12663 /* If we are in terse mode, don't generate any DIEs to represent any
12664 variable declarations or definitions. */
12665 if (debug_info_level <= DINFO_LEVEL_TERSE)
12668 /* Output any DIEs that are needed to specify the type of this data
12670 gen_type_die (TREE_TYPE (decl), context_die);
12672 /* And its containing type. */
12673 origin = decl_class_context (decl);
12674 if (origin != NULL_TREE)
12675 gen_type_die_for_member (origin, decl, context_die);
12677 /* And its containing namespace. */
12678 declare_in_namespace (decl, context_die);
12680 /* Now output the DIE to represent the data object itself. This gets
12681 complicated because of the possibility that the VAR_DECL really
12682 represents an inlined instance of a formal parameter for an inline
12684 origin = decl_ultimate_origin (decl);
12685 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
12686 gen_formal_parameter_die (decl, context_die);
12688 gen_variable_die (decl, context_die);
12692 /* Ignore the nameless fields that are used to skip bits but handle C++
12693 anonymous unions and structs. */
12694 if (DECL_NAME (decl) != NULL_TREE
12695 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
12696 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
12698 gen_type_die (member_declared_type (decl), context_die);
12699 gen_field_die (decl, context_die);
12704 gen_type_die (TREE_TYPE (decl), context_die);
12705 gen_formal_parameter_die (decl, context_die);
12708 case NAMESPACE_DECL:
12709 gen_namespace_die (decl);
12713 /* Probably some frontend-internal decl. Assume we don't care. */
12714 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
12719 /* Add Ada "use" clause information for SGI Workshop debugger. */
12722 dwarf2out_add_library_unit_info (const char *filename, const char *context_list)
12724 unsigned int file_index;
12726 if (filename != NULL)
12728 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
12729 tree context_list_decl
12730 = build_decl (LABEL_DECL, get_identifier (context_list),
12733 TREE_PUBLIC (context_list_decl) = TRUE;
12734 add_name_attribute (unit_die, context_list);
12735 file_index = lookup_filename (filename);
12736 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
12737 add_pubname (context_list_decl, unit_die);
12741 /* Output debug information for global decl DECL. Called from toplev.c after
12742 compilation proper has finished. */
12745 dwarf2out_global_decl (tree decl)
12747 /* Output DWARF2 information for file-scope tentative data object
12748 declarations, file-scope (extern) function declarations (which had no
12749 corresponding body) and file-scope tagged type declarations and
12750 definitions which have not yet been forced out. */
12751 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
12752 dwarf2out_decl (decl);
12755 /* Output debug information for type decl DECL. Called from toplev.c
12756 and from language front ends (to record built-in types). */
12758 dwarf2out_type_decl (tree decl, int local)
12761 dwarf2out_decl (decl);
12764 /* Output debug information for imported module or decl. */
12767 dwarf2out_imported_module_or_decl (tree decl, tree context)
12769 dw_die_ref imported_die, at_import_die;
12770 dw_die_ref scope_die;
12771 unsigned file_index;
12772 expanded_location xloc;
12774 if (debug_info_level <= DINFO_LEVEL_TERSE)
12779 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
12780 We need decl DIE for reference and scope die. First, get DIE for the decl
12783 /* Get the scope die for decl context. Use comp_unit_die for global module
12784 or decl. If die is not found for non globals, force new die. */
12786 scope_die = comp_unit_die;
12787 else if (TYPE_P (context))
12788 scope_die = force_type_die (context);
12790 scope_die = force_decl_die (context);
12792 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
12793 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
12794 at_import_die = force_type_die (TREE_TYPE (decl));
12796 at_import_die = force_decl_die (decl);
12798 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
12799 if (TREE_CODE (decl) == NAMESPACE_DECL)
12800 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
12802 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
12804 xloc = expand_location (input_location);
12805 file_index = lookup_filename (xloc.file);
12806 add_AT_unsigned (imported_die, DW_AT_decl_file, file_index);
12807 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
12808 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
12811 /* Write the debugging output for DECL. */
12814 dwarf2out_decl (tree decl)
12816 dw_die_ref context_die = comp_unit_die;
12818 switch (TREE_CODE (decl))
12823 case FUNCTION_DECL:
12824 /* What we would really like to do here is to filter out all mere
12825 file-scope declarations of file-scope functions which are never
12826 referenced later within this translation unit (and keep all of ones
12827 that *are* referenced later on) but we aren't clairvoyant, so we have
12828 no idea which functions will be referenced in the future (i.e. later
12829 on within the current translation unit). So here we just ignore all
12830 file-scope function declarations which are not also definitions. If
12831 and when the debugger needs to know something about these functions,
12832 it will have to hunt around and find the DWARF information associated
12833 with the definition of the function.
12835 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
12836 nodes represent definitions and which ones represent mere
12837 declarations. We have to check DECL_INITIAL instead. That's because
12838 the C front-end supports some weird semantics for "extern inline"
12839 function definitions. These can get inlined within the current
12840 translation unit (an thus, we need to generate Dwarf info for their
12841 abstract instances so that the Dwarf info for the concrete inlined
12842 instances can have something to refer to) but the compiler never
12843 generates any out-of-lines instances of such things (despite the fact
12844 that they *are* definitions).
12846 The important point is that the C front-end marks these "extern
12847 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
12848 them anyway. Note that the C++ front-end also plays some similar games
12849 for inline function definitions appearing within include files which
12850 also contain `#pragma interface' pragmas. */
12851 if (DECL_INITIAL (decl) == NULL_TREE)
12854 /* If we're a nested function, initially use a parent of NULL; if we're
12855 a plain function, this will be fixed up in decls_for_scope. If
12856 we're a method, it will be ignored, since we already have a DIE. */
12857 if (decl_function_context (decl)
12858 /* But if we're in terse mode, we don't care about scope. */
12859 && debug_info_level > DINFO_LEVEL_TERSE)
12860 context_die = NULL;
12864 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
12865 declaration and if the declaration was never even referenced from
12866 within this entire compilation unit. We suppress these DIEs in
12867 order to save space in the .debug section (by eliminating entries
12868 which are probably useless). Note that we must not suppress
12869 block-local extern declarations (whether used or not) because that
12870 would screw-up the debugger's name lookup mechanism and cause it to
12871 miss things which really ought to be in scope at a given point. */
12872 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
12875 /* If we are in terse mode, don't generate any DIEs to represent any
12876 variable declarations or definitions. */
12877 if (debug_info_level <= DINFO_LEVEL_TERSE)
12881 case NAMESPACE_DECL:
12882 if (debug_info_level <= DINFO_LEVEL_TERSE)
12884 if (lookup_decl_die (decl) != NULL)
12889 /* Don't emit stubs for types unless they are needed by other DIEs. */
12890 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
12893 /* Don't bother trying to generate any DIEs to represent any of the
12894 normal built-in types for the language we are compiling. */
12895 if (DECL_IS_BUILTIN (decl))
12897 /* OK, we need to generate one for `bool' so GDB knows what type
12898 comparisons have. */
12899 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
12900 == DW_LANG_C_plus_plus)
12901 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
12902 && ! DECL_IGNORED_P (decl))
12903 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
12908 /* If we are in terse mode, don't generate any DIEs for types. */
12909 if (debug_info_level <= DINFO_LEVEL_TERSE)
12912 /* If we're a function-scope tag, initially use a parent of NULL;
12913 this will be fixed up in decls_for_scope. */
12914 if (decl_function_context (decl))
12915 context_die = NULL;
12923 gen_decl_die (decl, context_die);
12926 /* Output a marker (i.e. a label) for the beginning of the generated code for
12927 a lexical block. */
12930 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
12931 unsigned int blocknum)
12933 function_section (current_function_decl);
12934 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
12937 /* Output a marker (i.e. a label) for the end of the generated code for a
12941 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
12943 function_section (current_function_decl);
12944 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
12947 /* Returns nonzero if it is appropriate not to emit any debugging
12948 information for BLOCK, because it doesn't contain any instructions.
12950 Don't allow this for blocks with nested functions or local classes
12951 as we would end up with orphans, and in the presence of scheduling
12952 we may end up calling them anyway. */
12955 dwarf2out_ignore_block (tree block)
12959 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
12960 if (TREE_CODE (decl) == FUNCTION_DECL
12961 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
12967 /* Lookup FILE_NAME (in the list of filenames that we know about here in
12968 dwarf2out.c) and return its "index". The index of each (known) filename is
12969 just a unique number which is associated with only that one filename. We
12970 need such numbers for the sake of generating labels (in the .debug_sfnames
12971 section) and references to those files numbers (in the .debug_srcinfo
12972 and.debug_macinfo sections). If the filename given as an argument is not
12973 found in our current list, add it to the list and assign it the next
12974 available unique index number. In order to speed up searches, we remember
12975 the index of the filename was looked up last. This handles the majority of
12979 lookup_filename (const char *file_name)
12982 char *save_file_name;
12984 /* Check to see if the file name that was searched on the previous
12985 call matches this file name. If so, return the index. */
12986 if (file_table_last_lookup_index != 0)
12989 = VARRAY_CHAR_PTR (file_table, file_table_last_lookup_index);
12990 if (strcmp (file_name, last) == 0)
12991 return file_table_last_lookup_index;
12994 /* Didn't match the previous lookup, search the table. */
12995 n = VARRAY_ACTIVE_SIZE (file_table);
12996 for (i = 1; i < n; i++)
12997 if (strcmp (file_name, VARRAY_CHAR_PTR (file_table, i)) == 0)
12999 file_table_last_lookup_index = i;
13003 /* Add the new entry to the end of the filename table. */
13004 file_table_last_lookup_index = n;
13005 save_file_name = (char *) ggc_strdup (file_name);
13006 VARRAY_PUSH_CHAR_PTR (file_table, save_file_name);
13007 VARRAY_PUSH_UINT (file_table_emitted, 0);
13013 maybe_emit_file (int fileno)
13015 if (DWARF2_ASM_LINE_DEBUG_INFO && fileno > 0)
13017 if (!VARRAY_UINT (file_table_emitted, fileno))
13019 VARRAY_UINT (file_table_emitted, fileno) = ++emitcount;
13020 fprintf (asm_out_file, "\t.file %u ",
13021 VARRAY_UINT (file_table_emitted, fileno));
13022 output_quoted_string (asm_out_file,
13023 VARRAY_CHAR_PTR (file_table, fileno));
13024 fputc ('\n', asm_out_file);
13026 return VARRAY_UINT (file_table_emitted, fileno);
13033 init_file_table (void)
13035 /* Allocate the initial hunk of the file_table. */
13036 VARRAY_CHAR_PTR_INIT (file_table, 64, "file_table");
13037 VARRAY_UINT_INIT (file_table_emitted, 64, "file_table_emitted");
13039 /* Skip the first entry - file numbers begin at 1. */
13040 VARRAY_PUSH_CHAR_PTR (file_table, NULL);
13041 VARRAY_PUSH_UINT (file_table_emitted, 0);
13042 file_table_last_lookup_index = 0;
13045 /* Called by the final INSN scan whenever we see a var location. We
13046 use it to drop labels in the right places, and throw the location in
13047 our lookup table. */
13050 dwarf2out_var_location (rtx loc_note)
13052 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
13053 struct var_loc_node *newloc;
13055 static rtx last_insn;
13056 static const char *last_label;
13058 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
13060 prev_insn = PREV_INSN (loc_note);
13062 newloc = ggc_alloc_cleared (sizeof (struct var_loc_node));
13063 /* If the insn we processed last time is the previous insn
13064 and it is also a var location note, use the label we emitted
13066 if (last_insn != NULL_RTX
13067 && last_insn == prev_insn
13068 && NOTE_P (prev_insn)
13069 && NOTE_LINE_NUMBER (prev_insn) == NOTE_INSN_VAR_LOCATION)
13071 newloc->label = last_label;
13075 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
13076 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
13078 newloc->label = ggc_strdup (loclabel);
13080 newloc->var_loc_note = loc_note;
13081 newloc->next = NULL;
13083 last_insn = loc_note;
13084 last_label = newloc->label;
13086 add_var_loc_to_decl (NOTE_VAR_LOCATION_DECL (loc_note), newloc);
13089 /* We need to reset the locations at the beginning of each
13090 function. We can't do this in the end_function hook, because the
13091 declarations that use the locations won't have been outputted when
13092 that hook is called. */
13095 dwarf2out_begin_function (tree unused ATTRIBUTE_UNUSED)
13097 htab_empty (decl_loc_table);
13100 /* Output a label to mark the beginning of a source code line entry
13101 and record information relating to this source line, in
13102 'line_info_table' for later output of the .debug_line section. */
13105 dwarf2out_source_line (unsigned int line, const char *filename)
13107 if (debug_info_level >= DINFO_LEVEL_NORMAL
13110 function_section (current_function_decl);
13112 /* If requested, emit something human-readable. */
13113 if (flag_debug_asm)
13114 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
13117 if (DWARF2_ASM_LINE_DEBUG_INFO)
13119 unsigned file_num = lookup_filename (filename);
13121 file_num = maybe_emit_file (file_num);
13123 /* Emit the .loc directive understood by GNU as. */
13124 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
13126 /* Indicate that line number info exists. */
13127 line_info_table_in_use++;
13129 /* Indicate that multiple line number tables exist. */
13130 if (DECL_SECTION_NAME (current_function_decl))
13131 separate_line_info_table_in_use++;
13133 else if (DECL_SECTION_NAME (current_function_decl))
13135 dw_separate_line_info_ref line_info;
13136 targetm.asm_out.internal_label (asm_out_file, SEPARATE_LINE_CODE_LABEL,
13137 separate_line_info_table_in_use);
13139 /* Expand the line info table if necessary. */
13140 if (separate_line_info_table_in_use
13141 == separate_line_info_table_allocated)
13143 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
13144 separate_line_info_table
13145 = ggc_realloc (separate_line_info_table,
13146 separate_line_info_table_allocated
13147 * sizeof (dw_separate_line_info_entry));
13148 memset (separate_line_info_table
13149 + separate_line_info_table_in_use,
13151 (LINE_INFO_TABLE_INCREMENT
13152 * sizeof (dw_separate_line_info_entry)));
13155 /* Add the new entry at the end of the line_info_table. */
13157 = &separate_line_info_table[separate_line_info_table_in_use++];
13158 line_info->dw_file_num = lookup_filename (filename);
13159 line_info->dw_line_num = line;
13160 line_info->function = current_function_funcdef_no;
13164 dw_line_info_ref line_info;
13166 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
13167 line_info_table_in_use);
13169 /* Expand the line info table if necessary. */
13170 if (line_info_table_in_use == line_info_table_allocated)
13172 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
13174 = ggc_realloc (line_info_table,
13175 (line_info_table_allocated
13176 * sizeof (dw_line_info_entry)));
13177 memset (line_info_table + line_info_table_in_use, 0,
13178 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
13181 /* Add the new entry at the end of the line_info_table. */
13182 line_info = &line_info_table[line_info_table_in_use++];
13183 line_info->dw_file_num = lookup_filename (filename);
13184 line_info->dw_line_num = line;
13189 /* Record the beginning of a new source file. */
13192 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
13194 if (flag_eliminate_dwarf2_dups)
13196 /* Record the beginning of the file for break_out_includes. */
13197 dw_die_ref bincl_die;
13199 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
13200 add_AT_string (bincl_die, DW_AT_name, filename);
13203 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13205 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13206 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
13207 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
13209 maybe_emit_file (lookup_filename (filename));
13210 dw2_asm_output_data_uleb128 (lookup_filename (filename),
13211 "Filename we just started");
13215 /* Record the end of a source file. */
13218 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
13220 if (flag_eliminate_dwarf2_dups)
13221 /* Record the end of the file for break_out_includes. */
13222 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
13224 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13226 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13227 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
13231 /* Called from debug_define in toplev.c. The `buffer' parameter contains
13232 the tail part of the directive line, i.e. the part which is past the
13233 initial whitespace, #, whitespace, directive-name, whitespace part. */
13236 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
13237 const char *buffer ATTRIBUTE_UNUSED)
13239 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13241 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13242 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
13243 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
13244 dw2_asm_output_nstring (buffer, -1, "The macro");
13248 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
13249 the tail part of the directive line, i.e. the part which is past the
13250 initial whitespace, #, whitespace, directive-name, whitespace part. */
13253 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
13254 const char *buffer ATTRIBUTE_UNUSED)
13256 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13258 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13259 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
13260 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
13261 dw2_asm_output_nstring (buffer, -1, "The macro");
13265 /* Set up for Dwarf output at the start of compilation. */
13268 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
13270 init_file_table ();
13272 /* Allocate the decl_die_table. */
13273 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
13274 decl_die_table_eq, NULL);
13276 /* Allocate the decl_loc_table. */
13277 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
13278 decl_loc_table_eq, NULL);
13280 /* Allocate the initial hunk of the decl_scope_table. */
13281 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
13283 /* Allocate the initial hunk of the abbrev_die_table. */
13284 abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
13285 * sizeof (dw_die_ref));
13286 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
13287 /* Zero-th entry is allocated, but unused. */
13288 abbrev_die_table_in_use = 1;
13290 /* Allocate the initial hunk of the line_info_table. */
13291 line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
13292 * sizeof (dw_line_info_entry));
13293 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
13295 /* Zero-th entry is allocated, but unused. */
13296 line_info_table_in_use = 1;
13298 /* Generate the initial DIE for the .debug section. Note that the (string)
13299 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
13300 will (typically) be a relative pathname and that this pathname should be
13301 taken as being relative to the directory from which the compiler was
13302 invoked when the given (base) source file was compiled. We will fill
13303 in this value in dwarf2out_finish. */
13304 comp_unit_die = gen_compile_unit_die (NULL);
13306 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
13308 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
13310 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
13311 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
13312 DEBUG_ABBREV_SECTION_LABEL, 0);
13313 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
13315 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
13316 DEBUG_INFO_SECTION_LABEL, 0);
13317 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
13318 DEBUG_LINE_SECTION_LABEL, 0);
13319 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
13320 DEBUG_RANGES_SECTION_LABEL, 0);
13321 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
13322 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
13323 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
13324 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
13325 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
13326 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
13328 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13330 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13331 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
13332 DEBUG_MACINFO_SECTION_LABEL, 0);
13333 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
13337 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
13340 /* A helper function for dwarf2out_finish called through
13341 ht_forall. Emit one queued .debug_str string. */
13344 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
13346 struct indirect_string_node *node = (struct indirect_string_node *) *h;
13348 if (node->form == DW_FORM_strp)
13350 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
13351 ASM_OUTPUT_LABEL (asm_out_file, node->label);
13352 assemble_string (node->str, strlen (node->str) + 1);
13360 /* Clear the marks for a die and its children.
13361 Be cool if the mark isn't set. */
13364 prune_unmark_dies (dw_die_ref die)
13368 for (c = die->die_child; c; c = c->die_sib)
13369 prune_unmark_dies (c);
13373 /* Given DIE that we're marking as used, find any other dies
13374 it references as attributes and mark them as used. */
13377 prune_unused_types_walk_attribs (dw_die_ref die)
13381 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
13383 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
13385 /* A reference to another DIE.
13386 Make sure that it will get emitted. */
13387 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
13389 else if (a->dw_attr == DW_AT_decl_file)
13391 /* A reference to a file. Make sure the file name is emitted. */
13392 a->dw_attr_val.v.val_unsigned =
13393 maybe_emit_file (a->dw_attr_val.v.val_unsigned);
13399 /* Mark DIE as being used. If DOKIDS is true, then walk down
13400 to DIE's children. */
13403 prune_unused_types_mark (dw_die_ref die, int dokids)
13407 if (die->die_mark == 0)
13409 /* We haven't done this node yet. Mark it as used. */
13412 /* We also have to mark its parents as used.
13413 (But we don't want to mark our parents' kids due to this.) */
13414 if (die->die_parent)
13415 prune_unused_types_mark (die->die_parent, 0);
13417 /* Mark any referenced nodes. */
13418 prune_unused_types_walk_attribs (die);
13420 /* If this node is a specification,
13421 also mark the definition, if it exists. */
13422 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
13423 prune_unused_types_mark (die->die_definition, 1);
13426 if (dokids && die->die_mark != 2)
13428 /* We need to walk the children, but haven't done so yet.
13429 Remember that we've walked the kids. */
13433 for (c = die->die_child; c; c = c->die_sib)
13435 /* If this is an array type, we need to make sure our
13436 kids get marked, even if they're types. */
13437 if (die->die_tag == DW_TAG_array_type)
13438 prune_unused_types_mark (c, 1);
13440 prune_unused_types_walk (c);
13446 /* Walk the tree DIE and mark types that we actually use. */
13449 prune_unused_types_walk (dw_die_ref die)
13453 /* Don't do anything if this node is already marked. */
13457 switch (die->die_tag) {
13458 case DW_TAG_const_type:
13459 case DW_TAG_packed_type:
13460 case DW_TAG_pointer_type:
13461 case DW_TAG_reference_type:
13462 case DW_TAG_volatile_type:
13463 case DW_TAG_typedef:
13464 case DW_TAG_array_type:
13465 case DW_TAG_structure_type:
13466 case DW_TAG_union_type:
13467 case DW_TAG_class_type:
13468 case DW_TAG_friend:
13469 case DW_TAG_variant_part:
13470 case DW_TAG_enumeration_type:
13471 case DW_TAG_subroutine_type:
13472 case DW_TAG_string_type:
13473 case DW_TAG_set_type:
13474 case DW_TAG_subrange_type:
13475 case DW_TAG_ptr_to_member_type:
13476 case DW_TAG_file_type:
13477 /* It's a type node --- don't mark it. */
13481 /* Mark everything else. */
13487 /* Now, mark any dies referenced from here. */
13488 prune_unused_types_walk_attribs (die);
13490 /* Mark children. */
13491 for (c = die->die_child; c; c = c->die_sib)
13492 prune_unused_types_walk (c);
13496 /* Remove from the tree DIE any dies that aren't marked. */
13499 prune_unused_types_prune (dw_die_ref die)
13501 dw_die_ref c, p, n;
13503 gcc_assert (die->die_mark);
13506 for (c = die->die_child; c; c = n)
13511 prune_unused_types_prune (c);
13519 die->die_child = n;
13526 /* Remove dies representing declarations that we never use. */
13529 prune_unused_types (void)
13532 limbo_die_node *node;
13534 /* Clear all the marks. */
13535 prune_unmark_dies (comp_unit_die);
13536 for (node = limbo_die_list; node; node = node->next)
13537 prune_unmark_dies (node->die);
13539 /* Set the mark on nodes that are actually used. */
13540 prune_unused_types_walk (comp_unit_die);
13541 for (node = limbo_die_list; node; node = node->next)
13542 prune_unused_types_walk (node->die);
13544 /* Also set the mark on nodes referenced from the
13545 pubname_table or arange_table. */
13546 for (i = 0; i < pubname_table_in_use; i++)
13547 prune_unused_types_mark (pubname_table[i].die, 1);
13548 for (i = 0; i < arange_table_in_use; i++)
13549 prune_unused_types_mark (arange_table[i], 1);
13551 /* Get rid of nodes that aren't marked. */
13552 prune_unused_types_prune (comp_unit_die);
13553 for (node = limbo_die_list; node; node = node->next)
13554 prune_unused_types_prune (node->die);
13556 /* Leave the marks clear. */
13557 prune_unmark_dies (comp_unit_die);
13558 for (node = limbo_die_list; node; node = node->next)
13559 prune_unmark_dies (node->die);
13562 /* Output stuff that dwarf requires at the end of every file,
13563 and generate the DWARF-2 debugging info. */
13566 dwarf2out_finish (const char *filename)
13568 limbo_die_node *node, *next_node;
13569 dw_die_ref die = 0;
13571 /* Add the name for the main input file now. We delayed this from
13572 dwarf2out_init to avoid complications with PCH. */
13573 add_name_attribute (comp_unit_die, filename);
13574 if (filename[0] != DIR_SEPARATOR)
13575 add_comp_dir_attribute (comp_unit_die);
13576 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
13579 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
13580 if (VARRAY_CHAR_PTR (file_table, i)[0] != DIR_SEPARATOR
13581 /* Don't add cwd for <built-in>. */
13582 && VARRAY_CHAR_PTR (file_table, i)[0] != '<')
13584 add_comp_dir_attribute (comp_unit_die);
13589 /* Traverse the limbo die list, and add parent/child links. The only
13590 dies without parents that should be here are concrete instances of
13591 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
13592 For concrete instances, we can get the parent die from the abstract
13594 for (node = limbo_die_list; node; node = next_node)
13596 next_node = node->next;
13599 if (die->die_parent == NULL)
13601 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
13604 add_child_die (origin->die_parent, die);
13605 else if (die == comp_unit_die)
13607 else if (errorcount > 0 || sorrycount > 0)
13608 /* It's OK to be confused by errors in the input. */
13609 add_child_die (comp_unit_die, die);
13612 /* In certain situations, the lexical block containing a
13613 nested function can be optimized away, which results
13614 in the nested function die being orphaned. Likewise
13615 with the return type of that nested function. Force
13616 this to be a child of the containing function.
13618 It may happen that even the containing function got fully
13619 inlined and optimized out. In that case we are lost and
13620 assign the empty child. This should not be big issue as
13621 the function is likely unreachable too. */
13622 tree context = NULL_TREE;
13624 gcc_assert (node->created_for);
13626 if (DECL_P (node->created_for))
13627 context = DECL_CONTEXT (node->created_for);
13628 else if (TYPE_P (node->created_for))
13629 context = TYPE_CONTEXT (node->created_for);
13631 gcc_assert (context && TREE_CODE (context) == FUNCTION_DECL);
13633 origin = lookup_decl_die (context);
13635 add_child_die (origin, die);
13637 add_child_die (comp_unit_die, die);
13642 limbo_die_list = NULL;
13644 /* Walk through the list of incomplete types again, trying once more to
13645 emit full debugging info for them. */
13646 retry_incomplete_types ();
13648 /* We need to reverse all the dies before break_out_includes, or
13649 we'll see the end of an include file before the beginning. */
13650 reverse_all_dies (comp_unit_die);
13652 if (flag_eliminate_unused_debug_types)
13653 prune_unused_types ();
13655 /* Generate separate CUs for each of the include files we've seen.
13656 They will go into limbo_die_list. */
13657 if (flag_eliminate_dwarf2_dups)
13658 break_out_includes (comp_unit_die);
13660 /* Traverse the DIE's and add add sibling attributes to those DIE's
13661 that have children. */
13662 add_sibling_attributes (comp_unit_die);
13663 for (node = limbo_die_list; node; node = node->next)
13664 add_sibling_attributes (node->die);
13666 /* Output a terminator label for the .text section. */
13668 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
13670 /* Output the source line correspondence table. We must do this
13671 even if there is no line information. Otherwise, on an empty
13672 translation unit, we will generate a present, but empty,
13673 .debug_info section. IRIX 6.5 `nm' will then complain when
13674 examining the file. */
13675 if (! DWARF2_ASM_LINE_DEBUG_INFO)
13677 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
13678 output_line_info ();
13681 /* Output location list section if necessary. */
13682 if (have_location_lists)
13684 /* Output the location lists info. */
13685 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
13686 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
13687 DEBUG_LOC_SECTION_LABEL, 0);
13688 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
13689 output_location_lists (die);
13690 have_location_lists = 0;
13693 /* We can only use the low/high_pc attributes if all of the code was
13695 if (separate_line_info_table_in_use == 0)
13697 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
13698 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
13701 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
13702 "base address". Use zero so that these addresses become absolute. */
13703 else if (have_location_lists || ranges_table_in_use)
13704 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
13706 if (debug_info_level >= DINFO_LEVEL_NORMAL)
13707 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
13708 debug_line_section_label);
13710 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13711 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
13713 /* Output all of the compilation units. We put the main one last so that
13714 the offsets are available to output_pubnames. */
13715 for (node = limbo_die_list; node; node = node->next)
13716 output_comp_unit (node->die, 0);
13718 output_comp_unit (comp_unit_die, 0);
13720 /* Output the abbreviation table. */
13721 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
13722 output_abbrev_section ();
13724 /* Output public names table if necessary. */
13725 if (pubname_table_in_use)
13727 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
13728 output_pubnames ();
13731 /* Output the address range information. We only put functions in the arange
13732 table, so don't write it out if we don't have any. */
13733 if (fde_table_in_use)
13735 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
13739 /* Output ranges section if necessary. */
13740 if (ranges_table_in_use)
13742 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
13743 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
13747 /* Have to end the primary source file. */
13748 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13750 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13751 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
13752 dw2_asm_output_data (1, 0, "End compilation unit");
13755 /* If we emitted any DW_FORM_strp form attribute, output the string
13757 if (debug_str_hash)
13758 htab_traverse (debug_str_hash, output_indirect_string, NULL);
13762 /* This should never be used, but its address is needed for comparisons. */
13763 const struct gcc_debug_hooks dwarf2_debug_hooks;
13765 #endif /* DWARF2_DEBUGGING_INFO */
13767 #include "gt-dwarf2out.h"