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 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1450 HOST_WIDE_INT offset;
1452 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1453 the PARALLEL independently. The first element is always processed if
1454 it is a SET. This is for backward compatibility. Other elements
1455 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1456 flag is set in them. */
1457 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1460 int limit = XVECLEN (expr, 0);
1462 for (par_index = 0; par_index < limit; par_index++)
1463 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1464 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1466 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1471 gcc_assert (GET_CODE (expr) == SET);
1473 src = SET_SRC (expr);
1474 dest = SET_DEST (expr);
1476 if (GET_CODE (src) == REG)
1478 rtx rsi = reg_saved_in (src);
1483 switch (GET_CODE (dest))
1486 switch (GET_CODE (src))
1488 /* Setting FP from SP. */
1490 if (cfa.reg == (unsigned) REGNO (src))
1493 /* Update the CFA rule wrt SP or FP. Make sure src is
1494 relative to the current CFA register.
1496 We used to require that dest be either SP or FP, but the
1497 ARM copies SP to a temporary register, and from there to
1498 FP. So we just rely on the backends to only set
1499 RTX_FRAME_RELATED_P on appropriate insns. */
1500 cfa.reg = REGNO (dest);
1501 cfa_temp.reg = cfa.reg;
1502 cfa_temp.offset = cfa.offset;
1506 /* Saving a register in a register. */
1507 gcc_assert (call_used_regs [REGNO (dest)]
1508 && !fixed_regs [REGNO (dest)]);
1509 queue_reg_save (label, src, dest, 0);
1516 if (dest == stack_pointer_rtx)
1520 switch (GET_CODE (XEXP (src, 1)))
1523 offset = INTVAL (XEXP (src, 1));
1526 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1528 offset = cfa_temp.offset;
1534 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1536 /* Restoring SP from FP in the epilogue. */
1537 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1538 cfa.reg = STACK_POINTER_REGNUM;
1540 else if (GET_CODE (src) == LO_SUM)
1541 /* Assume we've set the source reg of the LO_SUM from sp. */
1544 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1546 if (GET_CODE (src) != MINUS)
1548 if (cfa.reg == STACK_POINTER_REGNUM)
1549 cfa.offset += offset;
1550 if (cfa_store.reg == STACK_POINTER_REGNUM)
1551 cfa_store.offset += offset;
1553 else if (dest == hard_frame_pointer_rtx)
1556 /* Either setting the FP from an offset of the SP,
1557 or adjusting the FP */
1558 gcc_assert (frame_pointer_needed);
1560 gcc_assert (REG_P (XEXP (src, 0))
1561 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1562 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1563 offset = INTVAL (XEXP (src, 1));
1564 if (GET_CODE (src) != MINUS)
1566 cfa.offset += offset;
1567 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1571 gcc_assert (GET_CODE (src) != MINUS);
1574 if (REG_P (XEXP (src, 0))
1575 && REGNO (XEXP (src, 0)) == cfa.reg
1576 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1578 /* Setting a temporary CFA register that will be copied
1579 into the FP later on. */
1580 offset = - INTVAL (XEXP (src, 1));
1581 cfa.offset += offset;
1582 cfa.reg = REGNO (dest);
1583 /* Or used to save regs to the stack. */
1584 cfa_temp.reg = cfa.reg;
1585 cfa_temp.offset = cfa.offset;
1589 else if (REG_P (XEXP (src, 0))
1590 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1591 && XEXP (src, 1) == stack_pointer_rtx)
1593 /* Setting a scratch register that we will use instead
1594 of SP for saving registers to the stack. */
1595 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1596 cfa_store.reg = REGNO (dest);
1597 cfa_store.offset = cfa.offset - cfa_temp.offset;
1601 else if (GET_CODE (src) == LO_SUM
1602 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1604 cfa_temp.reg = REGNO (dest);
1605 cfa_temp.offset = INTVAL (XEXP (src, 1));
1614 cfa_temp.reg = REGNO (dest);
1615 cfa_temp.offset = INTVAL (src);
1620 gcc_assert (REG_P (XEXP (src, 0))
1621 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1622 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1624 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1625 cfa_temp.reg = REGNO (dest);
1626 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1629 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1630 which will fill in all of the bits. */
1639 def_cfa_1 (label, &cfa);
1643 gcc_assert (REG_P (src));
1645 /* Saving a register to the stack. Make sure dest is relative to the
1647 switch (GET_CODE (XEXP (dest, 0)))
1652 /* We can't handle variable size modifications. */
1653 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1655 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1657 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1658 && cfa_store.reg == STACK_POINTER_REGNUM);
1660 cfa_store.offset += offset;
1661 if (cfa.reg == STACK_POINTER_REGNUM)
1662 cfa.offset = cfa_store.offset;
1664 offset = -cfa_store.offset;
1670 offset = GET_MODE_SIZE (GET_MODE (dest));
1671 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1674 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1675 && cfa_store.reg == STACK_POINTER_REGNUM);
1677 cfa_store.offset += offset;
1678 if (cfa.reg == STACK_POINTER_REGNUM)
1679 cfa.offset = cfa_store.offset;
1681 offset = -cfa_store.offset;
1685 /* With an offset. */
1692 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT);
1693 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1694 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1697 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1699 if (cfa_store.reg == (unsigned) regno)
1700 offset -= cfa_store.offset;
1703 gcc_assert (cfa_temp.reg == (unsigned) regno);
1704 offset -= cfa_temp.offset;
1710 /* Without an offset. */
1713 int regno = REGNO (XEXP (dest, 0));
1715 if (cfa_store.reg == (unsigned) regno)
1716 offset = -cfa_store.offset;
1719 gcc_assert (cfa_temp.reg == (unsigned) regno);
1720 offset = -cfa_temp.offset;
1727 gcc_assert (cfa_temp.reg
1728 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1729 offset = -cfa_temp.offset;
1730 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1737 if (REGNO (src) != STACK_POINTER_REGNUM
1738 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1739 && (unsigned) REGNO (src) == cfa.reg)
1741 /* We're storing the current CFA reg into the stack. */
1743 if (cfa.offset == 0)
1745 /* If the source register is exactly the CFA, assume
1746 we're saving SP like any other register; this happens
1748 def_cfa_1 (label, &cfa);
1749 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1754 /* Otherwise, we'll need to look in the stack to
1755 calculate the CFA. */
1756 rtx x = XEXP (dest, 0);
1760 gcc_assert (REG_P (x));
1762 cfa.reg = REGNO (x);
1763 cfa.base_offset = offset;
1765 def_cfa_1 (label, &cfa);
1770 def_cfa_1 (label, &cfa);
1771 queue_reg_save (label, src, NULL_RTX, offset);
1779 /* Record call frame debugging information for INSN, which either
1780 sets SP or FP (adjusting how we calculate the frame address) or saves a
1781 register to the stack. If INSN is NULL_RTX, initialize our state.
1783 If AFTER_P is false, we're being called before the insn is emitted,
1784 otherwise after. Call instructions get invoked twice. */
1787 dwarf2out_frame_debug (rtx insn, bool after_p)
1792 if (insn == NULL_RTX)
1796 /* Flush any queued register saves. */
1797 flush_queued_reg_saves ();
1799 /* Set up state for generating call frame debug info. */
1802 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1804 cfa.reg = STACK_POINTER_REGNUM;
1807 cfa_temp.offset = 0;
1809 for (i = 0; i < num_regs_saved_in_regs; i++)
1811 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1812 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1814 num_regs_saved_in_regs = 0;
1818 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1819 flush_queued_reg_saves ();
1821 if (! RTX_FRAME_RELATED_P (insn))
1823 if (!ACCUMULATE_OUTGOING_ARGS)
1824 dwarf2out_stack_adjust (insn, after_p);
1828 label = dwarf2out_cfi_label ();
1829 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1831 insn = XEXP (src, 0);
1833 insn = PATTERN (insn);
1835 dwarf2out_frame_debug_expr (insn, label);
1840 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1841 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1842 (enum dwarf_call_frame_info cfi);
1844 static enum dw_cfi_oprnd_type
1845 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1850 case DW_CFA_GNU_window_save:
1851 return dw_cfi_oprnd_unused;
1853 case DW_CFA_set_loc:
1854 case DW_CFA_advance_loc1:
1855 case DW_CFA_advance_loc2:
1856 case DW_CFA_advance_loc4:
1857 case DW_CFA_MIPS_advance_loc8:
1858 return dw_cfi_oprnd_addr;
1861 case DW_CFA_offset_extended:
1862 case DW_CFA_def_cfa:
1863 case DW_CFA_offset_extended_sf:
1864 case DW_CFA_def_cfa_sf:
1865 case DW_CFA_restore_extended:
1866 case DW_CFA_undefined:
1867 case DW_CFA_same_value:
1868 case DW_CFA_def_cfa_register:
1869 case DW_CFA_register:
1870 return dw_cfi_oprnd_reg_num;
1872 case DW_CFA_def_cfa_offset:
1873 case DW_CFA_GNU_args_size:
1874 case DW_CFA_def_cfa_offset_sf:
1875 return dw_cfi_oprnd_offset;
1877 case DW_CFA_def_cfa_expression:
1878 case DW_CFA_expression:
1879 return dw_cfi_oprnd_loc;
1886 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1887 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1888 (enum dwarf_call_frame_info cfi);
1890 static enum dw_cfi_oprnd_type
1891 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1895 case DW_CFA_def_cfa:
1896 case DW_CFA_def_cfa_sf:
1898 case DW_CFA_offset_extended_sf:
1899 case DW_CFA_offset_extended:
1900 return dw_cfi_oprnd_offset;
1902 case DW_CFA_register:
1903 return dw_cfi_oprnd_reg_num;
1906 return dw_cfi_oprnd_unused;
1910 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1912 /* Map register numbers held in the call frame info that gcc has
1913 collected using DWARF_FRAME_REGNUM to those that should be output in
1914 .debug_frame and .eh_frame. */
1915 #ifndef DWARF2_FRAME_REG_OUT
1916 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
1919 /* Output a Call Frame Information opcode and its operand(s). */
1922 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
1925 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1926 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1927 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1928 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
1929 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1930 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1932 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1933 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
1934 "DW_CFA_offset, column 0x%lx", r);
1935 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1937 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1939 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1940 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
1941 "DW_CFA_restore, column 0x%lx", r);
1945 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1946 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1948 switch (cfi->dw_cfi_opc)
1950 case DW_CFA_set_loc:
1952 dw2_asm_output_encoded_addr_rtx (
1953 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1954 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1957 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1958 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1961 case DW_CFA_advance_loc1:
1962 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1963 fde->dw_fde_current_label, NULL);
1964 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1967 case DW_CFA_advance_loc2:
1968 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1969 fde->dw_fde_current_label, NULL);
1970 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1973 case DW_CFA_advance_loc4:
1974 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1975 fde->dw_fde_current_label, NULL);
1976 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1979 case DW_CFA_MIPS_advance_loc8:
1980 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1981 fde->dw_fde_current_label, NULL);
1982 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1985 case DW_CFA_offset_extended:
1986 case DW_CFA_def_cfa:
1987 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1988 dw2_asm_output_data_uleb128 (r, NULL);
1989 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1992 case DW_CFA_offset_extended_sf:
1993 case DW_CFA_def_cfa_sf:
1994 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1995 dw2_asm_output_data_uleb128 (r, NULL);
1996 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1999 case DW_CFA_restore_extended:
2000 case DW_CFA_undefined:
2001 case DW_CFA_same_value:
2002 case DW_CFA_def_cfa_register:
2003 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2004 dw2_asm_output_data_uleb128 (r, NULL);
2007 case DW_CFA_register:
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 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2011 dw2_asm_output_data_uleb128 (r, NULL);
2014 case DW_CFA_def_cfa_offset:
2015 case DW_CFA_GNU_args_size:
2016 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2019 case DW_CFA_def_cfa_offset_sf:
2020 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2023 case DW_CFA_GNU_window_save:
2026 case DW_CFA_def_cfa_expression:
2027 case DW_CFA_expression:
2028 output_cfa_loc (cfi);
2031 case DW_CFA_GNU_negative_offset_extended:
2032 /* Obsoleted by DW_CFA_offset_extended_sf. */
2041 /* Output the call frame information used to record information
2042 that relates to calculating the frame pointer, and records the
2043 location of saved registers. */
2046 output_call_frame_info (int for_eh)
2051 char l1[20], l2[20], section_start_label[20];
2052 bool any_lsda_needed = false;
2053 char augmentation[6];
2054 int augmentation_size;
2055 int fde_encoding = DW_EH_PE_absptr;
2056 int per_encoding = DW_EH_PE_absptr;
2057 int lsda_encoding = DW_EH_PE_absptr;
2059 /* Don't emit a CIE if there won't be any FDEs. */
2060 if (fde_table_in_use == 0)
2063 /* If we make FDEs linkonce, we may have to emit an empty label for
2064 an FDE that wouldn't otherwise be emitted. We want to avoid
2065 having an FDE kept around when the function it refers to is
2066 discarded. Example where this matters: a primary function
2067 template in C++ requires EH information, but an explicit
2068 specialization doesn't. */
2069 if (TARGET_USES_WEAK_UNWIND_INFO
2070 && ! flag_asynchronous_unwind_tables
2072 for (i = 0; i < fde_table_in_use; i++)
2073 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2074 && !fde_table[i].uses_eh_lsda
2075 && ! DECL_WEAK (fde_table[i].decl))
2076 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2077 for_eh, /* empty */ 1);
2079 /* If we don't have any functions we'll want to unwind out of, don't
2080 emit any EH unwind information. Note that if exceptions aren't
2081 enabled, we won't have collected nothrow information, and if we
2082 asked for asynchronous tables, we always want this info. */
2085 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2087 for (i = 0; i < fde_table_in_use; i++)
2088 if (fde_table[i].uses_eh_lsda)
2089 any_eh_needed = any_lsda_needed = true;
2090 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2091 any_eh_needed = true;
2092 else if (! fde_table[i].nothrow
2093 && ! fde_table[i].all_throwers_are_sibcalls)
2094 any_eh_needed = true;
2096 if (! any_eh_needed)
2100 /* We're going to be generating comments, so turn on app. */
2105 targetm.asm_out.eh_frame_section ();
2107 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
2109 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2110 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2112 /* Output the CIE. */
2113 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2114 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2115 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2116 "Length of Common Information Entry");
2117 ASM_OUTPUT_LABEL (asm_out_file, l1);
2119 /* Now that the CIE pointer is PC-relative for EH,
2120 use 0 to identify the CIE. */
2121 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2122 (for_eh ? 0 : DW_CIE_ID),
2123 "CIE Identifier Tag");
2125 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2127 augmentation[0] = 0;
2128 augmentation_size = 0;
2134 z Indicates that a uleb128 is present to size the
2135 augmentation section.
2136 L Indicates the encoding (and thus presence) of
2137 an LSDA pointer in the FDE augmentation.
2138 R Indicates a non-default pointer encoding for
2140 P Indicates the presence of an encoding + language
2141 personality routine in the CIE augmentation. */
2143 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2144 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2145 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2147 p = augmentation + 1;
2148 if (eh_personality_libfunc)
2151 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2153 if (any_lsda_needed)
2156 augmentation_size += 1;
2158 if (fde_encoding != DW_EH_PE_absptr)
2161 augmentation_size += 1;
2163 if (p > augmentation + 1)
2165 augmentation[0] = 'z';
2169 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2170 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2172 int offset = ( 4 /* Length */
2174 + 1 /* CIE version */
2175 + strlen (augmentation) + 1 /* Augmentation */
2176 + size_of_uleb128 (1) /* Code alignment */
2177 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2179 + 1 /* Augmentation size */
2180 + 1 /* Personality encoding */ );
2181 int pad = -offset & (PTR_SIZE - 1);
2183 augmentation_size += pad;
2185 /* Augmentations should be small, so there's scarce need to
2186 iterate for a solution. Die if we exceed one uleb128 byte. */
2187 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2191 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2192 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2193 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2194 "CIE Data Alignment Factor");
2196 if (DW_CIE_VERSION == 1)
2197 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
2199 dw2_asm_output_data_uleb128 (DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
2201 if (augmentation[0])
2203 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2204 if (eh_personality_libfunc)
2206 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2207 eh_data_format_name (per_encoding));
2208 dw2_asm_output_encoded_addr_rtx (per_encoding,
2209 eh_personality_libfunc, NULL);
2212 if (any_lsda_needed)
2213 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2214 eh_data_format_name (lsda_encoding));
2216 if (fde_encoding != DW_EH_PE_absptr)
2217 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2218 eh_data_format_name (fde_encoding));
2221 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2222 output_cfi (cfi, NULL, for_eh);
2224 /* Pad the CIE out to an address sized boundary. */
2225 ASM_OUTPUT_ALIGN (asm_out_file,
2226 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2227 ASM_OUTPUT_LABEL (asm_out_file, l2);
2229 /* Loop through all of the FDE's. */
2230 for (i = 0; i < fde_table_in_use; i++)
2232 fde = &fde_table[i];
2234 /* Don't emit EH unwind info for leaf functions that don't need it. */
2235 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2236 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2237 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2238 && !fde->uses_eh_lsda)
2241 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2242 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2243 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2244 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2245 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2247 ASM_OUTPUT_LABEL (asm_out_file, l1);
2250 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2252 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2257 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2258 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2259 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2261 "FDE initial location");
2262 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2263 fde->dw_fde_end, fde->dw_fde_begin,
2264 "FDE address range");
2268 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2269 "FDE initial location");
2270 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2271 fde->dw_fde_end, fde->dw_fde_begin,
2272 "FDE address range");
2275 if (augmentation[0])
2277 if (any_lsda_needed)
2279 int size = size_of_encoded_value (lsda_encoding);
2281 if (lsda_encoding == DW_EH_PE_aligned)
2283 int offset = ( 4 /* Length */
2284 + 4 /* CIE offset */
2285 + 2 * size_of_encoded_value (fde_encoding)
2286 + 1 /* Augmentation size */ );
2287 int pad = -offset & (PTR_SIZE - 1);
2290 gcc_assert (size_of_uleb128 (size) == 1);
2293 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2295 if (fde->uses_eh_lsda)
2297 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2298 fde->funcdef_number);
2299 dw2_asm_output_encoded_addr_rtx (
2300 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2301 "Language Specific Data Area");
2305 if (lsda_encoding == DW_EH_PE_aligned)
2306 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2308 (size_of_encoded_value (lsda_encoding), 0,
2309 "Language Specific Data Area (none)");
2313 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2316 /* Loop through the Call Frame Instructions associated with
2318 fde->dw_fde_current_label = fde->dw_fde_begin;
2319 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2320 output_cfi (cfi, fde, for_eh);
2322 /* Pad the FDE out to an address sized boundary. */
2323 ASM_OUTPUT_ALIGN (asm_out_file,
2324 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2325 ASM_OUTPUT_LABEL (asm_out_file, l2);
2328 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2329 dw2_asm_output_data (4, 0, "End of Table");
2330 #ifdef MIPS_DEBUGGING_INFO
2331 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2332 get a value of 0. Putting .align 0 after the label fixes it. */
2333 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2336 /* Turn off app to make assembly quicker. */
2341 /* Output a marker (i.e. a label) for the beginning of a function, before
2345 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2346 const char *file ATTRIBUTE_UNUSED)
2348 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2352 current_function_func_begin_label = NULL;
2354 #ifdef TARGET_UNWIND_INFO
2355 /* ??? current_function_func_begin_label is also used by except.c
2356 for call-site information. We must emit this label if it might
2358 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2359 && ! dwarf2out_do_frame ())
2362 if (! dwarf2out_do_frame ())
2366 function_section (current_function_decl);
2367 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2368 current_function_funcdef_no);
2369 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2370 current_function_funcdef_no);
2371 dup_label = xstrdup (label);
2372 current_function_func_begin_label = dup_label;
2374 #ifdef TARGET_UNWIND_INFO
2375 /* We can elide the fde allocation if we're not emitting debug info. */
2376 if (! dwarf2out_do_frame ())
2380 /* Expand the fde table if necessary. */
2381 if (fde_table_in_use == fde_table_allocated)
2383 fde_table_allocated += FDE_TABLE_INCREMENT;
2384 fde_table = ggc_realloc (fde_table,
2385 fde_table_allocated * sizeof (dw_fde_node));
2386 memset (fde_table + fde_table_in_use, 0,
2387 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2390 /* Record the FDE associated with this function. */
2391 current_funcdef_fde = fde_table_in_use;
2393 /* Add the new FDE at the end of the fde_table. */
2394 fde = &fde_table[fde_table_in_use++];
2395 fde->decl = current_function_decl;
2396 fde->dw_fde_begin = dup_label;
2397 fde->dw_fde_current_label = NULL;
2398 fde->dw_fde_end = NULL;
2399 fde->dw_fde_cfi = NULL;
2400 fde->funcdef_number = current_function_funcdef_no;
2401 fde->nothrow = TREE_NOTHROW (current_function_decl);
2402 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2403 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2405 args_size = old_args_size = 0;
2407 /* We only want to output line number information for the genuine dwarf2
2408 prologue case, not the eh frame case. */
2409 #ifdef DWARF2_DEBUGGING_INFO
2411 dwarf2out_source_line (line, file);
2415 /* Output a marker (i.e. a label) for the absolute end of the generated code
2416 for a function definition. This gets called *after* the epilogue code has
2420 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2421 const char *file ATTRIBUTE_UNUSED)
2424 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2426 /* Output a label to mark the endpoint of the code generated for this
2428 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2429 current_function_funcdef_no);
2430 ASM_OUTPUT_LABEL (asm_out_file, label);
2431 fde = &fde_table[fde_table_in_use - 1];
2432 fde->dw_fde_end = xstrdup (label);
2436 dwarf2out_frame_init (void)
2438 /* Allocate the initial hunk of the fde_table. */
2439 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2440 fde_table_allocated = FDE_TABLE_INCREMENT;
2441 fde_table_in_use = 0;
2443 /* Generate the CFA instructions common to all FDE's. Do it now for the
2444 sake of lookup_cfa. */
2446 #ifdef DWARF2_UNWIND_INFO
2447 /* On entry, the Canonical Frame Address is at SP. */
2448 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2449 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2454 dwarf2out_frame_finish (void)
2456 /* Output call frame information. */
2457 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2458 output_call_frame_info (0);
2460 #ifndef TARGET_UNWIND_INFO
2461 /* Output another copy for the unwinder. */
2462 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2463 output_call_frame_info (1);
2468 /* And now, the subset of the debugging information support code necessary
2469 for emitting location expressions. */
2471 /* We need some way to distinguish DW_OP_addr with a direct symbol
2472 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2473 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2476 typedef struct dw_val_struct *dw_val_ref;
2477 typedef struct die_struct *dw_die_ref;
2478 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2479 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2481 /* Each DIE may have a series of attribute/value pairs. Values
2482 can take on several forms. The forms that are used in this
2483 implementation are listed below. */
2488 dw_val_class_offset,
2490 dw_val_class_loc_list,
2491 dw_val_class_range_list,
2493 dw_val_class_unsigned_const,
2494 dw_val_class_long_long,
2497 dw_val_class_die_ref,
2498 dw_val_class_fde_ref,
2499 dw_val_class_lbl_id,
2500 dw_val_class_lbl_offset,
2504 /* Describe a double word constant value. */
2505 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2507 typedef struct dw_long_long_struct GTY(())
2514 /* Describe a floating point constant value, or a vector constant value. */
2516 typedef struct dw_vec_struct GTY(())
2518 unsigned char * GTY((length ("%h.length"))) array;
2524 /* The dw_val_node describes an attribute's value, as it is
2525 represented internally. */
2527 typedef struct dw_val_struct GTY(())
2529 enum dw_val_class val_class;
2530 union dw_val_struct_union
2532 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2533 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2534 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2535 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2536 HOST_WIDE_INT GTY ((default)) val_int;
2537 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2538 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2539 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2540 struct dw_val_die_union
2544 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2545 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2546 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2547 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2548 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2550 GTY ((desc ("%1.val_class"))) v;
2554 /* Locations in memory are described using a sequence of stack machine
2557 typedef struct dw_loc_descr_struct GTY(())
2559 dw_loc_descr_ref dw_loc_next;
2560 enum dwarf_location_atom dw_loc_opc;
2561 dw_val_node dw_loc_oprnd1;
2562 dw_val_node dw_loc_oprnd2;
2567 /* Location lists are ranges + location descriptions for that range,
2568 so you can track variables that are in different places over
2569 their entire life. */
2570 typedef struct dw_loc_list_struct GTY(())
2572 dw_loc_list_ref dw_loc_next;
2573 const char *begin; /* Label for begin address of range */
2574 const char *end; /* Label for end address of range */
2575 char *ll_symbol; /* Label for beginning of location list.
2576 Only on head of list */
2577 const char *section; /* Section this loclist is relative to */
2578 dw_loc_descr_ref expr;
2581 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2583 static const char *dwarf_stack_op_name (unsigned);
2584 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2585 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2586 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2587 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2588 static unsigned long size_of_locs (dw_loc_descr_ref);
2589 static void output_loc_operands (dw_loc_descr_ref);
2590 static void output_loc_sequence (dw_loc_descr_ref);
2592 /* Convert a DWARF stack opcode into its string name. */
2595 dwarf_stack_op_name (unsigned int op)
2600 case INTERNAL_DW_OP_tls_addr:
2601 return "DW_OP_addr";
2603 return "DW_OP_deref";
2605 return "DW_OP_const1u";
2607 return "DW_OP_const1s";
2609 return "DW_OP_const2u";
2611 return "DW_OP_const2s";
2613 return "DW_OP_const4u";
2615 return "DW_OP_const4s";
2617 return "DW_OP_const8u";
2619 return "DW_OP_const8s";
2621 return "DW_OP_constu";
2623 return "DW_OP_consts";
2627 return "DW_OP_drop";
2629 return "DW_OP_over";
2631 return "DW_OP_pick";
2633 return "DW_OP_swap";
2637 return "DW_OP_xderef";
2645 return "DW_OP_minus";
2657 return "DW_OP_plus";
2658 case DW_OP_plus_uconst:
2659 return "DW_OP_plus_uconst";
2665 return "DW_OP_shra";
2683 return "DW_OP_skip";
2685 return "DW_OP_lit0";
2687 return "DW_OP_lit1";
2689 return "DW_OP_lit2";
2691 return "DW_OP_lit3";
2693 return "DW_OP_lit4";
2695 return "DW_OP_lit5";
2697 return "DW_OP_lit6";
2699 return "DW_OP_lit7";
2701 return "DW_OP_lit8";
2703 return "DW_OP_lit9";
2705 return "DW_OP_lit10";
2707 return "DW_OP_lit11";
2709 return "DW_OP_lit12";
2711 return "DW_OP_lit13";
2713 return "DW_OP_lit14";
2715 return "DW_OP_lit15";
2717 return "DW_OP_lit16";
2719 return "DW_OP_lit17";
2721 return "DW_OP_lit18";
2723 return "DW_OP_lit19";
2725 return "DW_OP_lit20";
2727 return "DW_OP_lit21";
2729 return "DW_OP_lit22";
2731 return "DW_OP_lit23";
2733 return "DW_OP_lit24";
2735 return "DW_OP_lit25";
2737 return "DW_OP_lit26";
2739 return "DW_OP_lit27";
2741 return "DW_OP_lit28";
2743 return "DW_OP_lit29";
2745 return "DW_OP_lit30";
2747 return "DW_OP_lit31";
2749 return "DW_OP_reg0";
2751 return "DW_OP_reg1";
2753 return "DW_OP_reg2";
2755 return "DW_OP_reg3";
2757 return "DW_OP_reg4";
2759 return "DW_OP_reg5";
2761 return "DW_OP_reg6";
2763 return "DW_OP_reg7";
2765 return "DW_OP_reg8";
2767 return "DW_OP_reg9";
2769 return "DW_OP_reg10";
2771 return "DW_OP_reg11";
2773 return "DW_OP_reg12";
2775 return "DW_OP_reg13";
2777 return "DW_OP_reg14";
2779 return "DW_OP_reg15";
2781 return "DW_OP_reg16";
2783 return "DW_OP_reg17";
2785 return "DW_OP_reg18";
2787 return "DW_OP_reg19";
2789 return "DW_OP_reg20";
2791 return "DW_OP_reg21";
2793 return "DW_OP_reg22";
2795 return "DW_OP_reg23";
2797 return "DW_OP_reg24";
2799 return "DW_OP_reg25";
2801 return "DW_OP_reg26";
2803 return "DW_OP_reg27";
2805 return "DW_OP_reg28";
2807 return "DW_OP_reg29";
2809 return "DW_OP_reg30";
2811 return "DW_OP_reg31";
2813 return "DW_OP_breg0";
2815 return "DW_OP_breg1";
2817 return "DW_OP_breg2";
2819 return "DW_OP_breg3";
2821 return "DW_OP_breg4";
2823 return "DW_OP_breg5";
2825 return "DW_OP_breg6";
2827 return "DW_OP_breg7";
2829 return "DW_OP_breg8";
2831 return "DW_OP_breg9";
2833 return "DW_OP_breg10";
2835 return "DW_OP_breg11";
2837 return "DW_OP_breg12";
2839 return "DW_OP_breg13";
2841 return "DW_OP_breg14";
2843 return "DW_OP_breg15";
2845 return "DW_OP_breg16";
2847 return "DW_OP_breg17";
2849 return "DW_OP_breg18";
2851 return "DW_OP_breg19";
2853 return "DW_OP_breg20";
2855 return "DW_OP_breg21";
2857 return "DW_OP_breg22";
2859 return "DW_OP_breg23";
2861 return "DW_OP_breg24";
2863 return "DW_OP_breg25";
2865 return "DW_OP_breg26";
2867 return "DW_OP_breg27";
2869 return "DW_OP_breg28";
2871 return "DW_OP_breg29";
2873 return "DW_OP_breg30";
2875 return "DW_OP_breg31";
2877 return "DW_OP_regx";
2879 return "DW_OP_fbreg";
2881 return "DW_OP_bregx";
2883 return "DW_OP_piece";
2884 case DW_OP_deref_size:
2885 return "DW_OP_deref_size";
2886 case DW_OP_xderef_size:
2887 return "DW_OP_xderef_size";
2890 case DW_OP_push_object_address:
2891 return "DW_OP_push_object_address";
2893 return "DW_OP_call2";
2895 return "DW_OP_call4";
2896 case DW_OP_call_ref:
2897 return "DW_OP_call_ref";
2898 case DW_OP_GNU_push_tls_address:
2899 return "DW_OP_GNU_push_tls_address";
2901 return "OP_<unknown>";
2905 /* Return a pointer to a newly allocated location description. Location
2906 descriptions are simple expression terms that can be strung
2907 together to form more complicated location (address) descriptions. */
2909 static inline dw_loc_descr_ref
2910 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
2911 unsigned HOST_WIDE_INT oprnd2)
2913 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
2915 descr->dw_loc_opc = op;
2916 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2917 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2918 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2919 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2925 /* Add a location description term to a location description expression. */
2928 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
2930 dw_loc_descr_ref *d;
2932 /* Find the end of the chain. */
2933 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2939 /* Return the size of a location descriptor. */
2941 static unsigned long
2942 size_of_loc_descr (dw_loc_descr_ref loc)
2944 unsigned long size = 1;
2946 switch (loc->dw_loc_opc)
2949 case INTERNAL_DW_OP_tls_addr:
2950 size += DWARF2_ADDR_SIZE;
2969 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2972 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2977 case DW_OP_plus_uconst:
2978 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3016 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3019 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3022 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3025 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3026 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3029 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3031 case DW_OP_deref_size:
3032 case DW_OP_xderef_size:
3041 case DW_OP_call_ref:
3042 size += DWARF2_ADDR_SIZE;
3051 /* Return the size of a series of location descriptors. */
3053 static unsigned long
3054 size_of_locs (dw_loc_descr_ref loc)
3058 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
3060 loc->dw_loc_addr = size;
3061 size += size_of_loc_descr (loc);
3067 /* Output location description stack opcode's operands (if any). */
3070 output_loc_operands (dw_loc_descr_ref loc)
3072 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3073 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3075 switch (loc->dw_loc_opc)
3077 #ifdef DWARF2_DEBUGGING_INFO
3079 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3083 dw2_asm_output_data (2, val1->v.val_int, NULL);
3087 dw2_asm_output_data (4, val1->v.val_int, NULL);
3091 gcc_assert (HOST_BITS_PER_LONG >= 64);
3092 dw2_asm_output_data (8, val1->v.val_int, NULL);
3099 gcc_assert (val1->val_class == dw_val_class_loc);
3100 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3102 dw2_asm_output_data (2, offset, NULL);
3115 /* We currently don't make any attempt to make sure these are
3116 aligned properly like we do for the main unwind info, so
3117 don't support emitting things larger than a byte if we're
3118 only doing unwinding. */
3123 dw2_asm_output_data (1, val1->v.val_int, NULL);
3126 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3129 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3132 dw2_asm_output_data (1, val1->v.val_int, NULL);
3134 case DW_OP_plus_uconst:
3135 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3169 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3172 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3175 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3178 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3179 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3182 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3184 case DW_OP_deref_size:
3185 case DW_OP_xderef_size:
3186 dw2_asm_output_data (1, val1->v.val_int, NULL);
3189 case INTERNAL_DW_OP_tls_addr:
3190 #ifdef ASM_OUTPUT_DWARF_DTPREL
3191 ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE,
3193 fputc ('\n', asm_out_file);
3200 /* Other codes have no operands. */
3205 /* Output a sequence of location operations. */
3208 output_loc_sequence (dw_loc_descr_ref loc)
3210 for (; loc != NULL; loc = loc->dw_loc_next)
3212 /* Output the opcode. */
3213 dw2_asm_output_data (1, loc->dw_loc_opc,
3214 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3216 /* Output the operand(s) (if any). */
3217 output_loc_operands (loc);
3221 /* This routine will generate the correct assembly data for a location
3222 description based on a cfi entry with a complex address. */
3225 output_cfa_loc (dw_cfi_ref cfi)
3227 dw_loc_descr_ref loc;
3230 /* Output the size of the block. */
3231 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3232 size = size_of_locs (loc);
3233 dw2_asm_output_data_uleb128 (size, NULL);
3235 /* Now output the operations themselves. */
3236 output_loc_sequence (loc);
3239 /* This function builds a dwarf location descriptor sequence from
3240 a dw_cfa_location. */
3242 static struct dw_loc_descr_struct *
3243 build_cfa_loc (dw_cfa_location *cfa)
3245 struct dw_loc_descr_struct *head, *tmp;
3247 gcc_assert (cfa->indirect);
3249 if (cfa->base_offset)
3252 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3254 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3256 else if (cfa->reg <= 31)
3257 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3259 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3261 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3262 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3263 add_loc_descr (&head, tmp);
3264 if (cfa->offset != 0)
3266 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3267 add_loc_descr (&head, tmp);
3273 /* This function fills in aa dw_cfa_location structure from a dwarf location
3274 descriptor sequence. */
3277 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3279 struct dw_loc_descr_struct *ptr;
3281 cfa->base_offset = 0;
3285 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3287 enum dwarf_location_atom op = ptr->dw_loc_opc;
3323 cfa->reg = op - DW_OP_reg0;
3326 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3360 cfa->reg = op - DW_OP_breg0;
3361 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3364 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3365 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3370 case DW_OP_plus_uconst:
3371 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3374 internal_error ("DW_LOC_OP %s not implemented\n",
3375 dwarf_stack_op_name (ptr->dw_loc_opc));
3379 #endif /* .debug_frame support */
3381 /* And now, the support for symbolic debugging information. */
3382 #ifdef DWARF2_DEBUGGING_INFO
3384 /* .debug_str support. */
3385 static int output_indirect_string (void **, void *);
3387 static void dwarf2out_init (const char *);
3388 static void dwarf2out_finish (const char *);
3389 static void dwarf2out_define (unsigned int, const char *);
3390 static void dwarf2out_undef (unsigned int, const char *);
3391 static void dwarf2out_start_source_file (unsigned, const char *);
3392 static void dwarf2out_end_source_file (unsigned);
3393 static void dwarf2out_begin_block (unsigned, unsigned);
3394 static void dwarf2out_end_block (unsigned, unsigned);
3395 static bool dwarf2out_ignore_block (tree);
3396 static void dwarf2out_global_decl (tree);
3397 static void dwarf2out_type_decl (tree, int);
3398 static void dwarf2out_imported_module_or_decl (tree, tree);
3399 static void dwarf2out_abstract_function (tree);
3400 static void dwarf2out_var_location (rtx);
3401 static void dwarf2out_begin_function (tree);
3403 /* The debug hooks structure. */
3405 const struct gcc_debug_hooks dwarf2_debug_hooks =
3411 dwarf2out_start_source_file,
3412 dwarf2out_end_source_file,
3413 dwarf2out_begin_block,
3414 dwarf2out_end_block,
3415 dwarf2out_ignore_block,
3416 dwarf2out_source_line,
3417 dwarf2out_begin_prologue,
3418 debug_nothing_int_charstar, /* end_prologue */
3419 dwarf2out_end_epilogue,
3420 dwarf2out_begin_function,
3421 debug_nothing_int, /* end_function */
3422 dwarf2out_decl, /* function_decl */
3423 dwarf2out_global_decl,
3424 dwarf2out_type_decl, /* type_decl */
3425 dwarf2out_imported_module_or_decl,
3426 debug_nothing_tree, /* deferred_inline_function */
3427 /* The DWARF 2 backend tries to reduce debugging bloat by not
3428 emitting the abstract description of inline functions until
3429 something tries to reference them. */
3430 dwarf2out_abstract_function, /* outlining_inline_function */
3431 debug_nothing_rtx, /* label */
3432 debug_nothing_int, /* handle_pch */
3433 dwarf2out_var_location
3437 /* NOTE: In the comments in this file, many references are made to
3438 "Debugging Information Entries". This term is abbreviated as `DIE'
3439 throughout the remainder of this file. */
3441 /* An internal representation of the DWARF output is built, and then
3442 walked to generate the DWARF debugging info. The walk of the internal
3443 representation is done after the entire program has been compiled.
3444 The types below are used to describe the internal representation. */
3446 /* Various DIE's use offsets relative to the beginning of the
3447 .debug_info section to refer to each other. */
3449 typedef long int dw_offset;
3451 /* Define typedefs here to avoid circular dependencies. */
3453 typedef struct dw_attr_struct *dw_attr_ref;
3454 typedef struct dw_line_info_struct *dw_line_info_ref;
3455 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3456 typedef struct pubname_struct *pubname_ref;
3457 typedef struct dw_ranges_struct *dw_ranges_ref;
3459 /* Each entry in the line_info_table maintains the file and
3460 line number associated with the label generated for that
3461 entry. The label gives the PC value associated with
3462 the line number entry. */
3464 typedef struct dw_line_info_struct GTY(())
3466 unsigned long dw_file_num;
3467 unsigned long dw_line_num;
3471 /* Line information for functions in separate sections; each one gets its
3473 typedef struct dw_separate_line_info_struct GTY(())
3475 unsigned long dw_file_num;
3476 unsigned long dw_line_num;
3477 unsigned long function;
3479 dw_separate_line_info_entry;
3481 /* Each DIE attribute has a field specifying the attribute kind,
3482 a link to the next attribute in the chain, and an attribute value.
3483 Attributes are typically linked below the DIE they modify. */
3485 typedef struct dw_attr_struct GTY(())
3487 enum dwarf_attribute dw_attr;
3488 dw_attr_ref dw_attr_next;
3489 dw_val_node dw_attr_val;
3493 /* The Debugging Information Entry (DIE) structure */
3495 typedef struct die_struct GTY(())
3497 enum dwarf_tag die_tag;
3499 dw_attr_ref die_attr;
3500 dw_die_ref die_parent;
3501 dw_die_ref die_child;
3503 dw_die_ref die_definition; /* ref from a specification to its definition */
3504 dw_offset die_offset;
3505 unsigned long die_abbrev;
3507 unsigned int decl_id;
3511 /* The pubname structure */
3513 typedef struct pubname_struct GTY(())
3520 struct dw_ranges_struct GTY(())
3525 /* The limbo die list structure. */
3526 typedef struct limbo_die_struct GTY(())
3530 struct limbo_die_struct *next;
3534 /* How to start an assembler comment. */
3535 #ifndef ASM_COMMENT_START
3536 #define ASM_COMMENT_START ";#"
3539 /* Define a macro which returns nonzero for a TYPE_DECL which was
3540 implicitly generated for a tagged type.
3542 Note that unlike the gcc front end (which generates a NULL named
3543 TYPE_DECL node for each complete tagged type, each array type, and
3544 each function type node created) the g++ front end generates a
3545 _named_ TYPE_DECL node for each tagged type node created.
3546 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3547 generate a DW_TAG_typedef DIE for them. */
3549 #define TYPE_DECL_IS_STUB(decl) \
3550 (DECL_NAME (decl) == NULL_TREE \
3551 || (DECL_ARTIFICIAL (decl) \
3552 && is_tagged_type (TREE_TYPE (decl)) \
3553 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3554 /* This is necessary for stub decls that \
3555 appear in nested inline functions. */ \
3556 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3557 && (decl_ultimate_origin (decl) \
3558 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3560 /* Information concerning the compilation unit's programming
3561 language, and compiler version. */
3563 /* Fixed size portion of the DWARF compilation unit header. */
3564 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3565 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3567 /* Fixed size portion of public names info. */
3568 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3570 /* Fixed size portion of the address range info. */
3571 #define DWARF_ARANGES_HEADER_SIZE \
3572 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3573 DWARF2_ADDR_SIZE * 2) \
3574 - DWARF_INITIAL_LENGTH_SIZE)
3576 /* Size of padding portion in the address range info. It must be
3577 aligned to twice the pointer size. */
3578 #define DWARF_ARANGES_PAD_SIZE \
3579 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3580 DWARF2_ADDR_SIZE * 2) \
3581 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3583 /* Use assembler line directives if available. */
3584 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3585 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3586 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3588 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3592 /* Minimum line offset in a special line info. opcode.
3593 This value was chosen to give a reasonable range of values. */
3594 #define DWARF_LINE_BASE -10
3596 /* First special line opcode - leave room for the standard opcodes. */
3597 #define DWARF_LINE_OPCODE_BASE 10
3599 /* Range of line offsets in a special line info. opcode. */
3600 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3602 /* Flag that indicates the initial value of the is_stmt_start flag.
3603 In the present implementation, we do not mark any lines as
3604 the beginning of a source statement, because that information
3605 is not made available by the GCC front-end. */
3606 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3608 #ifdef DWARF2_DEBUGGING_INFO
3609 /* This location is used by calc_die_sizes() to keep track
3610 the offset of each DIE within the .debug_info section. */
3611 static unsigned long next_die_offset;
3614 /* Record the root of the DIE's built for the current compilation unit. */
3615 static GTY(()) dw_die_ref comp_unit_die;
3617 /* A list of DIEs with a NULL parent waiting to be relocated. */
3618 static GTY(()) limbo_die_node *limbo_die_list;
3620 /* Filenames referenced by this compilation unit. */
3621 static GTY(()) varray_type file_table;
3622 static GTY(()) varray_type file_table_emitted;
3623 static GTY(()) size_t file_table_last_lookup_index;
3625 /* A hash table of references to DIE's that describe declarations.
3626 The key is a DECL_UID() which is a unique number identifying each decl. */
3627 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3629 /* Node of the variable location list. */
3630 struct var_loc_node GTY ((chain_next ("%h.next")))
3632 rtx GTY (()) var_loc_note;
3633 const char * GTY (()) label;
3634 struct var_loc_node * GTY (()) next;
3637 /* Variable location list. */
3638 struct var_loc_list_def GTY (())
3640 struct var_loc_node * GTY (()) first;
3642 /* Do not mark the last element of the chained list because
3643 it is marked through the chain. */
3644 struct var_loc_node * GTY ((skip ("%h"))) last;
3646 /* DECL_UID of the variable decl. */
3647 unsigned int decl_id;
3649 typedef struct var_loc_list_def var_loc_list;
3652 /* Table of decl location linked lists. */
3653 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3655 /* A pointer to the base of a list of references to DIE's that
3656 are uniquely identified by their tag, presence/absence of
3657 children DIE's, and list of attribute/value pairs. */
3658 static GTY((length ("abbrev_die_table_allocated")))
3659 dw_die_ref *abbrev_die_table;
3661 /* Number of elements currently allocated for abbrev_die_table. */
3662 static GTY(()) unsigned abbrev_die_table_allocated;
3664 /* Number of elements in type_die_table currently in use. */
3665 static GTY(()) unsigned abbrev_die_table_in_use;
3667 /* Size (in elements) of increments by which we may expand the
3668 abbrev_die_table. */
3669 #define ABBREV_DIE_TABLE_INCREMENT 256
3671 /* A pointer to the base of a table that contains line information
3672 for each source code line in .text in the compilation unit. */
3673 static GTY((length ("line_info_table_allocated")))
3674 dw_line_info_ref line_info_table;
3676 /* Number of elements currently allocated for line_info_table. */
3677 static GTY(()) unsigned line_info_table_allocated;
3679 /* Number of elements in line_info_table currently in use. */
3680 static GTY(()) unsigned line_info_table_in_use;
3682 /* A pointer to the base of a table that contains line information
3683 for each source code line outside of .text in the compilation unit. */
3684 static GTY ((length ("separate_line_info_table_allocated")))
3685 dw_separate_line_info_ref separate_line_info_table;
3687 /* Number of elements currently allocated for separate_line_info_table. */
3688 static GTY(()) unsigned separate_line_info_table_allocated;
3690 /* Number of elements in separate_line_info_table currently in use. */
3691 static GTY(()) unsigned separate_line_info_table_in_use;
3693 /* Size (in elements) of increments by which we may expand the
3695 #define LINE_INFO_TABLE_INCREMENT 1024
3697 /* A pointer to the base of a table that contains a list of publicly
3698 accessible names. */
3699 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table;
3701 /* Number of elements currently allocated for pubname_table. */
3702 static GTY(()) unsigned pubname_table_allocated;
3704 /* Number of elements in pubname_table currently in use. */
3705 static GTY(()) unsigned pubname_table_in_use;
3707 /* Size (in elements) of increments by which we may expand the
3709 #define PUBNAME_TABLE_INCREMENT 64
3711 /* Array of dies for which we should generate .debug_arange info. */
3712 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
3714 /* Number of elements currently allocated for arange_table. */
3715 static GTY(()) unsigned arange_table_allocated;
3717 /* Number of elements in arange_table currently in use. */
3718 static GTY(()) unsigned arange_table_in_use;
3720 /* Size (in elements) of increments by which we may expand the
3722 #define ARANGE_TABLE_INCREMENT 64
3724 /* Array of dies for which we should generate .debug_ranges info. */
3725 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3727 /* Number of elements currently allocated for ranges_table. */
3728 static GTY(()) unsigned ranges_table_allocated;
3730 /* Number of elements in ranges_table currently in use. */
3731 static GTY(()) unsigned ranges_table_in_use;
3733 /* Size (in elements) of increments by which we may expand the
3735 #define RANGES_TABLE_INCREMENT 64
3737 /* Whether we have location lists that need outputting */
3738 static GTY(()) unsigned have_location_lists;
3740 /* Unique label counter. */
3741 static GTY(()) unsigned int loclabel_num;
3743 #ifdef DWARF2_DEBUGGING_INFO
3744 /* Record whether the function being analyzed contains inlined functions. */
3745 static int current_function_has_inlines;
3747 #if 0 && defined (MIPS_DEBUGGING_INFO)
3748 static int comp_unit_has_inlines;
3751 /* Number of file tables emitted in maybe_emit_file(). */
3752 static GTY(()) int emitcount = 0;
3754 /* Number of internal labels generated by gen_internal_sym(). */
3755 static GTY(()) int label_num;
3757 #ifdef DWARF2_DEBUGGING_INFO
3759 /* Forward declarations for functions defined in this file. */
3761 static int is_pseudo_reg (rtx);
3762 static tree type_main_variant (tree);
3763 static int is_tagged_type (tree);
3764 static const char *dwarf_tag_name (unsigned);
3765 static const char *dwarf_attr_name (unsigned);
3766 static const char *dwarf_form_name (unsigned);
3768 static const char *dwarf_type_encoding_name (unsigned);
3770 static tree decl_ultimate_origin (tree);
3771 static tree block_ultimate_origin (tree);
3772 static tree decl_class_context (tree);
3773 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3774 static inline enum dw_val_class AT_class (dw_attr_ref);
3775 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3776 static inline unsigned AT_flag (dw_attr_ref);
3777 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3778 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
3779 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3780 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
3781 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
3783 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3784 unsigned int, unsigned char *);
3785 static hashval_t debug_str_do_hash (const void *);
3786 static int debug_str_eq (const void *, const void *);
3787 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3788 static inline const char *AT_string (dw_attr_ref);
3789 static int AT_string_form (dw_attr_ref);
3790 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3791 static void add_AT_specification (dw_die_ref, dw_die_ref);
3792 static inline dw_die_ref AT_ref (dw_attr_ref);
3793 static inline int AT_ref_external (dw_attr_ref);
3794 static inline void set_AT_ref_external (dw_attr_ref, int);
3795 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3796 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3797 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3798 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3800 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3801 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3802 static inline rtx AT_addr (dw_attr_ref);
3803 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3804 static void add_AT_lbl_offset (dw_die_ref, enum dwarf_attribute, const char *);
3805 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3806 unsigned HOST_WIDE_INT);
3807 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3809 static inline const char *AT_lbl (dw_attr_ref);
3810 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3811 static const char *get_AT_low_pc (dw_die_ref);
3812 static const char *get_AT_hi_pc (dw_die_ref);
3813 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3814 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3815 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3816 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3817 static bool is_c_family (void);
3818 static bool is_cxx (void);
3819 static bool is_java (void);
3820 static bool is_fortran (void);
3821 static bool is_ada (void);
3822 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3823 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3824 static inline void free_die (dw_die_ref);
3825 static void remove_children (dw_die_ref);
3826 static void add_child_die (dw_die_ref, dw_die_ref);
3827 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3828 static dw_die_ref lookup_type_die (tree);
3829 static void equate_type_number_to_die (tree, dw_die_ref);
3830 static hashval_t decl_die_table_hash (const void *);
3831 static int decl_die_table_eq (const void *, const void *);
3832 static dw_die_ref lookup_decl_die (tree);
3833 static hashval_t decl_loc_table_hash (const void *);
3834 static int decl_loc_table_eq (const void *, const void *);
3835 static var_loc_list *lookup_decl_loc (tree);
3836 static void equate_decl_number_to_die (tree, dw_die_ref);
3837 static void add_var_loc_to_decl (tree, struct var_loc_node *);
3838 static void print_spaces (FILE *);
3839 static void print_die (dw_die_ref, FILE *);
3840 static void print_dwarf_line_table (FILE *);
3841 static void reverse_die_lists (dw_die_ref);
3842 static void reverse_all_dies (dw_die_ref);
3843 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3844 static dw_die_ref pop_compile_unit (dw_die_ref);
3845 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3846 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3847 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3848 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3849 static int same_dw_val_p (dw_val_node *, dw_val_node *, int *);
3850 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3851 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3852 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3853 static void compute_section_prefix (dw_die_ref);
3854 static int is_type_die (dw_die_ref);
3855 static int is_comdat_die (dw_die_ref);
3856 static int is_symbol_die (dw_die_ref);
3857 static void assign_symbol_names (dw_die_ref);
3858 static void break_out_includes (dw_die_ref);
3859 static hashval_t htab_cu_hash (const void *);
3860 static int htab_cu_eq (const void *, const void *);
3861 static void htab_cu_del (void *);
3862 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3863 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3864 static void add_sibling_attributes (dw_die_ref);
3865 static void build_abbrev_table (dw_die_ref);
3866 static void output_location_lists (dw_die_ref);
3867 static int constant_size (long unsigned);
3868 static unsigned long size_of_die (dw_die_ref);
3869 static void calc_die_sizes (dw_die_ref);
3870 static void mark_dies (dw_die_ref);
3871 static void unmark_dies (dw_die_ref);
3872 static void unmark_all_dies (dw_die_ref);
3873 static unsigned long size_of_pubnames (void);
3874 static unsigned long size_of_aranges (void);
3875 static enum dwarf_form value_format (dw_attr_ref);
3876 static void output_value_format (dw_attr_ref);
3877 static void output_abbrev_section (void);
3878 static void output_die_symbol (dw_die_ref);
3879 static void output_die (dw_die_ref);
3880 static void output_compilation_unit_header (void);
3881 static void output_comp_unit (dw_die_ref, int);
3882 static const char *dwarf2_name (tree, int);
3883 static void add_pubname (tree, dw_die_ref);
3884 static void output_pubnames (void);
3885 static void add_arange (tree, dw_die_ref);
3886 static void output_aranges (void);
3887 static unsigned int add_ranges (tree);
3888 static void output_ranges (void);
3889 static void output_line_info (void);
3890 static void output_file_names (void);
3891 static dw_die_ref base_type_die (tree);
3892 static tree root_type (tree);
3893 static int is_base_type (tree);
3894 static bool is_subrange_type (tree);
3895 static dw_die_ref subrange_type_die (tree, dw_die_ref);
3896 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
3897 static int type_is_enum (tree);
3898 static unsigned int dbx_reg_number (rtx);
3899 static dw_loc_descr_ref reg_loc_descriptor (rtx);
3900 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int);
3901 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx);
3902 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3903 static dw_loc_descr_ref based_loc_descr (unsigned, HOST_WIDE_INT, bool);
3904 static int is_based_loc (rtx);
3905 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode, bool);
3906 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx);
3907 static dw_loc_descr_ref loc_descriptor (rtx, bool);
3908 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
3909 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
3910 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3911 static tree field_type (tree);
3912 static unsigned int simple_type_align_in_bits (tree);
3913 static unsigned int simple_decl_align_in_bits (tree);
3914 static unsigned HOST_WIDE_INT simple_type_size_in_bits (tree);
3915 static HOST_WIDE_INT field_byte_offset (tree);
3916 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3918 static void add_data_member_location_attribute (dw_die_ref, tree);
3919 static void add_const_value_attribute (dw_die_ref, rtx);
3920 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3921 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
3922 static void insert_float (rtx, unsigned char *);
3923 static rtx rtl_for_decl_location (tree);
3924 static void add_location_or_const_value_attribute (dw_die_ref, tree,
3925 enum dwarf_attribute);
3926 static void tree_add_const_value_attribute (dw_die_ref, tree);
3927 static void add_name_attribute (dw_die_ref, const char *);
3928 static void add_comp_dir_attribute (dw_die_ref);
3929 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
3930 static void add_subscript_info (dw_die_ref, tree);
3931 static void add_byte_size_attribute (dw_die_ref, tree);
3932 static void add_bit_offset_attribute (dw_die_ref, tree);
3933 static void add_bit_size_attribute (dw_die_ref, tree);
3934 static void add_prototyped_attribute (dw_die_ref, tree);
3935 static void add_abstract_origin_attribute (dw_die_ref, tree);
3936 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3937 static void add_src_coords_attributes (dw_die_ref, tree);
3938 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3939 static void push_decl_scope (tree);
3940 static void pop_decl_scope (void);
3941 static dw_die_ref scope_die_for (tree, dw_die_ref);
3942 static inline int local_scope_p (dw_die_ref);
3943 static inline int class_or_namespace_scope_p (dw_die_ref);
3944 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
3945 static void add_calling_convention_attribute (dw_die_ref, tree);
3946 static const char *type_tag (tree);
3947 static tree member_declared_type (tree);
3949 static const char *decl_start_label (tree);
3951 static void gen_array_type_die (tree, dw_die_ref);
3952 static void gen_set_type_die (tree, dw_die_ref);
3954 static void gen_entry_point_die (tree, dw_die_ref);
3956 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
3957 static void gen_inlined_structure_type_die (tree, dw_die_ref);
3958 static void gen_inlined_union_type_die (tree, dw_die_ref);
3959 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
3960 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
3961 static void gen_unspecified_parameters_die (tree, dw_die_ref);
3962 static void gen_formal_types_die (tree, dw_die_ref);
3963 static void gen_subprogram_die (tree, dw_die_ref);
3964 static void gen_variable_die (tree, dw_die_ref);
3965 static void gen_label_die (tree, dw_die_ref);
3966 static void gen_lexical_block_die (tree, dw_die_ref, int);
3967 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
3968 static void gen_field_die (tree, dw_die_ref);
3969 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3970 static dw_die_ref gen_compile_unit_die (const char *);
3971 static void gen_string_type_die (tree, dw_die_ref);
3972 static void gen_inheritance_die (tree, tree, dw_die_ref);
3973 static void gen_member_die (tree, dw_die_ref);
3974 static void gen_struct_or_union_type_die (tree, dw_die_ref);
3975 static void gen_subroutine_type_die (tree, dw_die_ref);
3976 static void gen_typedef_die (tree, dw_die_ref);
3977 static void gen_type_die (tree, dw_die_ref);
3978 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
3979 static void gen_block_die (tree, dw_die_ref, int);
3980 static void decls_for_scope (tree, dw_die_ref, int);
3981 static int is_redundant_typedef (tree);
3982 static void gen_namespace_die (tree);
3983 static void gen_decl_die (tree, dw_die_ref);
3984 static dw_die_ref force_decl_die (tree);
3985 static dw_die_ref force_type_die (tree);
3986 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
3987 static void declare_in_namespace (tree, dw_die_ref);
3988 static unsigned lookup_filename (const char *);
3989 static void init_file_table (void);
3990 static void retry_incomplete_types (void);
3991 static void gen_type_die_for_member (tree, tree, dw_die_ref);
3992 static void splice_child_die (dw_die_ref, dw_die_ref);
3993 static int file_info_cmp (const void *, const void *);
3994 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
3995 const char *, const char *, unsigned);
3996 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
3997 const char *, const char *,
3999 static void output_loc_list (dw_loc_list_ref);
4000 static char *gen_internal_sym (const char *);
4002 static void prune_unmark_dies (dw_die_ref);
4003 static void prune_unused_types_mark (dw_die_ref, int);
4004 static void prune_unused_types_walk (dw_die_ref);
4005 static void prune_unused_types_walk_attribs (dw_die_ref);
4006 static void prune_unused_types_prune (dw_die_ref);
4007 static void prune_unused_types (void);
4008 static int maybe_emit_file (int);
4010 /* Section names used to hold DWARF debugging information. */
4011 #ifndef DEBUG_INFO_SECTION
4012 #define DEBUG_INFO_SECTION ".debug_info"
4014 #ifndef DEBUG_ABBREV_SECTION
4015 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4017 #ifndef DEBUG_ARANGES_SECTION
4018 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4020 #ifndef DEBUG_MACINFO_SECTION
4021 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4023 #ifndef DEBUG_LINE_SECTION
4024 #define DEBUG_LINE_SECTION ".debug_line"
4026 #ifndef DEBUG_LOC_SECTION
4027 #define DEBUG_LOC_SECTION ".debug_loc"
4029 #ifndef DEBUG_PUBNAMES_SECTION
4030 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4032 #ifndef DEBUG_STR_SECTION
4033 #define DEBUG_STR_SECTION ".debug_str"
4035 #ifndef DEBUG_RANGES_SECTION
4036 #define DEBUG_RANGES_SECTION ".debug_ranges"
4039 /* Standard ELF section names for compiled code and data. */
4040 #ifndef TEXT_SECTION_NAME
4041 #define TEXT_SECTION_NAME ".text"
4044 /* Section flags for .debug_str section. */
4045 #define DEBUG_STR_SECTION_FLAGS \
4046 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
4047 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4050 /* Labels we insert at beginning sections we can reference instead of
4051 the section names themselves. */
4053 #ifndef TEXT_SECTION_LABEL
4054 #define TEXT_SECTION_LABEL "Ltext"
4056 #ifndef DEBUG_LINE_SECTION_LABEL
4057 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4059 #ifndef DEBUG_INFO_SECTION_LABEL
4060 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4062 #ifndef DEBUG_ABBREV_SECTION_LABEL
4063 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4065 #ifndef DEBUG_LOC_SECTION_LABEL
4066 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4068 #ifndef DEBUG_RANGES_SECTION_LABEL
4069 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4071 #ifndef DEBUG_MACINFO_SECTION_LABEL
4072 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4075 /* Definitions of defaults for formats and names of various special
4076 (artificial) labels which may be generated within this file (when the -g
4077 options is used and DWARF2_DEBUGGING_INFO is in effect.
4078 If necessary, these may be overridden from within the tm.h file, but
4079 typically, overriding these defaults is unnecessary. */
4081 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4082 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4083 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4084 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4085 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4086 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4087 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4088 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4090 #ifndef TEXT_END_LABEL
4091 #define TEXT_END_LABEL "Letext"
4093 #ifndef BLOCK_BEGIN_LABEL
4094 #define BLOCK_BEGIN_LABEL "LBB"
4096 #ifndef BLOCK_END_LABEL
4097 #define BLOCK_END_LABEL "LBE"
4099 #ifndef LINE_CODE_LABEL
4100 #define LINE_CODE_LABEL "LM"
4102 #ifndef SEPARATE_LINE_CODE_LABEL
4103 #define SEPARATE_LINE_CODE_LABEL "LSM"
4106 /* We allow a language front-end to designate a function that is to be
4107 called to "demangle" any name before it it put into a DIE. */
4109 static const char *(*demangle_name_func) (const char *);
4112 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4114 demangle_name_func = func;
4117 /* Test if rtl node points to a pseudo register. */
4120 is_pseudo_reg (rtx rtl)
4122 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4123 || (GET_CODE (rtl) == SUBREG
4124 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4127 /* Return a reference to a type, with its const and volatile qualifiers
4131 type_main_variant (tree type)
4133 type = TYPE_MAIN_VARIANT (type);
4135 /* ??? There really should be only one main variant among any group of
4136 variants of a given type (and all of the MAIN_VARIANT values for all
4137 members of the group should point to that one type) but sometimes the C
4138 front-end messes this up for array types, so we work around that bug
4140 if (TREE_CODE (type) == ARRAY_TYPE)
4141 while (type != TYPE_MAIN_VARIANT (type))
4142 type = TYPE_MAIN_VARIANT (type);
4147 /* Return nonzero if the given type node represents a tagged type. */
4150 is_tagged_type (tree type)
4152 enum tree_code code = TREE_CODE (type);
4154 return (code == RECORD_TYPE || code == UNION_TYPE
4155 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4158 /* Convert a DIE tag into its string name. */
4161 dwarf_tag_name (unsigned int tag)
4165 case DW_TAG_padding:
4166 return "DW_TAG_padding";
4167 case DW_TAG_array_type:
4168 return "DW_TAG_array_type";
4169 case DW_TAG_class_type:
4170 return "DW_TAG_class_type";
4171 case DW_TAG_entry_point:
4172 return "DW_TAG_entry_point";
4173 case DW_TAG_enumeration_type:
4174 return "DW_TAG_enumeration_type";
4175 case DW_TAG_formal_parameter:
4176 return "DW_TAG_formal_parameter";
4177 case DW_TAG_imported_declaration:
4178 return "DW_TAG_imported_declaration";
4180 return "DW_TAG_label";
4181 case DW_TAG_lexical_block:
4182 return "DW_TAG_lexical_block";
4184 return "DW_TAG_member";
4185 case DW_TAG_pointer_type:
4186 return "DW_TAG_pointer_type";
4187 case DW_TAG_reference_type:
4188 return "DW_TAG_reference_type";
4189 case DW_TAG_compile_unit:
4190 return "DW_TAG_compile_unit";
4191 case DW_TAG_string_type:
4192 return "DW_TAG_string_type";
4193 case DW_TAG_structure_type:
4194 return "DW_TAG_structure_type";
4195 case DW_TAG_subroutine_type:
4196 return "DW_TAG_subroutine_type";
4197 case DW_TAG_typedef:
4198 return "DW_TAG_typedef";
4199 case DW_TAG_union_type:
4200 return "DW_TAG_union_type";
4201 case DW_TAG_unspecified_parameters:
4202 return "DW_TAG_unspecified_parameters";
4203 case DW_TAG_variant:
4204 return "DW_TAG_variant";
4205 case DW_TAG_common_block:
4206 return "DW_TAG_common_block";
4207 case DW_TAG_common_inclusion:
4208 return "DW_TAG_common_inclusion";
4209 case DW_TAG_inheritance:
4210 return "DW_TAG_inheritance";
4211 case DW_TAG_inlined_subroutine:
4212 return "DW_TAG_inlined_subroutine";
4214 return "DW_TAG_module";
4215 case DW_TAG_ptr_to_member_type:
4216 return "DW_TAG_ptr_to_member_type";
4217 case DW_TAG_set_type:
4218 return "DW_TAG_set_type";
4219 case DW_TAG_subrange_type:
4220 return "DW_TAG_subrange_type";
4221 case DW_TAG_with_stmt:
4222 return "DW_TAG_with_stmt";
4223 case DW_TAG_access_declaration:
4224 return "DW_TAG_access_declaration";
4225 case DW_TAG_base_type:
4226 return "DW_TAG_base_type";
4227 case DW_TAG_catch_block:
4228 return "DW_TAG_catch_block";
4229 case DW_TAG_const_type:
4230 return "DW_TAG_const_type";
4231 case DW_TAG_constant:
4232 return "DW_TAG_constant";
4233 case DW_TAG_enumerator:
4234 return "DW_TAG_enumerator";
4235 case DW_TAG_file_type:
4236 return "DW_TAG_file_type";
4238 return "DW_TAG_friend";
4239 case DW_TAG_namelist:
4240 return "DW_TAG_namelist";
4241 case DW_TAG_namelist_item:
4242 return "DW_TAG_namelist_item";
4243 case DW_TAG_namespace:
4244 return "DW_TAG_namespace";
4245 case DW_TAG_packed_type:
4246 return "DW_TAG_packed_type";
4247 case DW_TAG_subprogram:
4248 return "DW_TAG_subprogram";
4249 case DW_TAG_template_type_param:
4250 return "DW_TAG_template_type_param";
4251 case DW_TAG_template_value_param:
4252 return "DW_TAG_template_value_param";
4253 case DW_TAG_thrown_type:
4254 return "DW_TAG_thrown_type";
4255 case DW_TAG_try_block:
4256 return "DW_TAG_try_block";
4257 case DW_TAG_variant_part:
4258 return "DW_TAG_variant_part";
4259 case DW_TAG_variable:
4260 return "DW_TAG_variable";
4261 case DW_TAG_volatile_type:
4262 return "DW_TAG_volatile_type";
4263 case DW_TAG_imported_module:
4264 return "DW_TAG_imported_module";
4265 case DW_TAG_MIPS_loop:
4266 return "DW_TAG_MIPS_loop";
4267 case DW_TAG_format_label:
4268 return "DW_TAG_format_label";
4269 case DW_TAG_function_template:
4270 return "DW_TAG_function_template";
4271 case DW_TAG_class_template:
4272 return "DW_TAG_class_template";
4273 case DW_TAG_GNU_BINCL:
4274 return "DW_TAG_GNU_BINCL";
4275 case DW_TAG_GNU_EINCL:
4276 return "DW_TAG_GNU_EINCL";
4278 return "DW_TAG_<unknown>";
4282 /* Convert a DWARF attribute code into its string name. */
4285 dwarf_attr_name (unsigned int attr)
4290 return "DW_AT_sibling";
4291 case DW_AT_location:
4292 return "DW_AT_location";
4294 return "DW_AT_name";
4295 case DW_AT_ordering:
4296 return "DW_AT_ordering";
4297 case DW_AT_subscr_data:
4298 return "DW_AT_subscr_data";
4299 case DW_AT_byte_size:
4300 return "DW_AT_byte_size";
4301 case DW_AT_bit_offset:
4302 return "DW_AT_bit_offset";
4303 case DW_AT_bit_size:
4304 return "DW_AT_bit_size";
4305 case DW_AT_element_list:
4306 return "DW_AT_element_list";
4307 case DW_AT_stmt_list:
4308 return "DW_AT_stmt_list";
4310 return "DW_AT_low_pc";
4312 return "DW_AT_high_pc";
4313 case DW_AT_language:
4314 return "DW_AT_language";
4316 return "DW_AT_member";
4318 return "DW_AT_discr";
4319 case DW_AT_discr_value:
4320 return "DW_AT_discr_value";
4321 case DW_AT_visibility:
4322 return "DW_AT_visibility";
4324 return "DW_AT_import";
4325 case DW_AT_string_length:
4326 return "DW_AT_string_length";
4327 case DW_AT_common_reference:
4328 return "DW_AT_common_reference";
4329 case DW_AT_comp_dir:
4330 return "DW_AT_comp_dir";
4331 case DW_AT_const_value:
4332 return "DW_AT_const_value";
4333 case DW_AT_containing_type:
4334 return "DW_AT_containing_type";
4335 case DW_AT_default_value:
4336 return "DW_AT_default_value";
4338 return "DW_AT_inline";
4339 case DW_AT_is_optional:
4340 return "DW_AT_is_optional";
4341 case DW_AT_lower_bound:
4342 return "DW_AT_lower_bound";
4343 case DW_AT_producer:
4344 return "DW_AT_producer";
4345 case DW_AT_prototyped:
4346 return "DW_AT_prototyped";
4347 case DW_AT_return_addr:
4348 return "DW_AT_return_addr";
4349 case DW_AT_start_scope:
4350 return "DW_AT_start_scope";
4351 case DW_AT_stride_size:
4352 return "DW_AT_stride_size";
4353 case DW_AT_upper_bound:
4354 return "DW_AT_upper_bound";
4355 case DW_AT_abstract_origin:
4356 return "DW_AT_abstract_origin";
4357 case DW_AT_accessibility:
4358 return "DW_AT_accessibility";
4359 case DW_AT_address_class:
4360 return "DW_AT_address_class";
4361 case DW_AT_artificial:
4362 return "DW_AT_artificial";
4363 case DW_AT_base_types:
4364 return "DW_AT_base_types";
4365 case DW_AT_calling_convention:
4366 return "DW_AT_calling_convention";
4368 return "DW_AT_count";
4369 case DW_AT_data_member_location:
4370 return "DW_AT_data_member_location";
4371 case DW_AT_decl_column:
4372 return "DW_AT_decl_column";
4373 case DW_AT_decl_file:
4374 return "DW_AT_decl_file";
4375 case DW_AT_decl_line:
4376 return "DW_AT_decl_line";
4377 case DW_AT_declaration:
4378 return "DW_AT_declaration";
4379 case DW_AT_discr_list:
4380 return "DW_AT_discr_list";
4381 case DW_AT_encoding:
4382 return "DW_AT_encoding";
4383 case DW_AT_external:
4384 return "DW_AT_external";
4385 case DW_AT_frame_base:
4386 return "DW_AT_frame_base";
4388 return "DW_AT_friend";
4389 case DW_AT_identifier_case:
4390 return "DW_AT_identifier_case";
4391 case DW_AT_macro_info:
4392 return "DW_AT_macro_info";
4393 case DW_AT_namelist_items:
4394 return "DW_AT_namelist_items";
4395 case DW_AT_priority:
4396 return "DW_AT_priority";
4398 return "DW_AT_segment";
4399 case DW_AT_specification:
4400 return "DW_AT_specification";
4401 case DW_AT_static_link:
4402 return "DW_AT_static_link";
4404 return "DW_AT_type";
4405 case DW_AT_use_location:
4406 return "DW_AT_use_location";
4407 case DW_AT_variable_parameter:
4408 return "DW_AT_variable_parameter";
4409 case DW_AT_virtuality:
4410 return "DW_AT_virtuality";
4411 case DW_AT_vtable_elem_location:
4412 return "DW_AT_vtable_elem_location";
4414 case DW_AT_allocated:
4415 return "DW_AT_allocated";
4416 case DW_AT_associated:
4417 return "DW_AT_associated";
4418 case DW_AT_data_location:
4419 return "DW_AT_data_location";
4421 return "DW_AT_stride";
4422 case DW_AT_entry_pc:
4423 return "DW_AT_entry_pc";
4424 case DW_AT_use_UTF8:
4425 return "DW_AT_use_UTF8";
4426 case DW_AT_extension:
4427 return "DW_AT_extension";
4429 return "DW_AT_ranges";
4430 case DW_AT_trampoline:
4431 return "DW_AT_trampoline";
4432 case DW_AT_call_column:
4433 return "DW_AT_call_column";
4434 case DW_AT_call_file:
4435 return "DW_AT_call_file";
4436 case DW_AT_call_line:
4437 return "DW_AT_call_line";
4439 case DW_AT_MIPS_fde:
4440 return "DW_AT_MIPS_fde";
4441 case DW_AT_MIPS_loop_begin:
4442 return "DW_AT_MIPS_loop_begin";
4443 case DW_AT_MIPS_tail_loop_begin:
4444 return "DW_AT_MIPS_tail_loop_begin";
4445 case DW_AT_MIPS_epilog_begin:
4446 return "DW_AT_MIPS_epilog_begin";
4447 case DW_AT_MIPS_loop_unroll_factor:
4448 return "DW_AT_MIPS_loop_unroll_factor";
4449 case DW_AT_MIPS_software_pipeline_depth:
4450 return "DW_AT_MIPS_software_pipeline_depth";
4451 case DW_AT_MIPS_linkage_name:
4452 return "DW_AT_MIPS_linkage_name";
4453 case DW_AT_MIPS_stride:
4454 return "DW_AT_MIPS_stride";
4455 case DW_AT_MIPS_abstract_name:
4456 return "DW_AT_MIPS_abstract_name";
4457 case DW_AT_MIPS_clone_origin:
4458 return "DW_AT_MIPS_clone_origin";
4459 case DW_AT_MIPS_has_inlines:
4460 return "DW_AT_MIPS_has_inlines";
4462 case DW_AT_sf_names:
4463 return "DW_AT_sf_names";
4464 case DW_AT_src_info:
4465 return "DW_AT_src_info";
4466 case DW_AT_mac_info:
4467 return "DW_AT_mac_info";
4468 case DW_AT_src_coords:
4469 return "DW_AT_src_coords";
4470 case DW_AT_body_begin:
4471 return "DW_AT_body_begin";
4472 case DW_AT_body_end:
4473 return "DW_AT_body_end";
4474 case DW_AT_GNU_vector:
4475 return "DW_AT_GNU_vector";
4477 case DW_AT_VMS_rtnbeg_pd_address:
4478 return "DW_AT_VMS_rtnbeg_pd_address";
4481 return "DW_AT_<unknown>";
4485 /* Convert a DWARF value form code into its string name. */
4488 dwarf_form_name (unsigned int form)
4493 return "DW_FORM_addr";
4494 case DW_FORM_block2:
4495 return "DW_FORM_block2";
4496 case DW_FORM_block4:
4497 return "DW_FORM_block4";
4499 return "DW_FORM_data2";
4501 return "DW_FORM_data4";
4503 return "DW_FORM_data8";
4504 case DW_FORM_string:
4505 return "DW_FORM_string";
4507 return "DW_FORM_block";
4508 case DW_FORM_block1:
4509 return "DW_FORM_block1";
4511 return "DW_FORM_data1";
4513 return "DW_FORM_flag";
4515 return "DW_FORM_sdata";
4517 return "DW_FORM_strp";
4519 return "DW_FORM_udata";
4520 case DW_FORM_ref_addr:
4521 return "DW_FORM_ref_addr";
4523 return "DW_FORM_ref1";
4525 return "DW_FORM_ref2";
4527 return "DW_FORM_ref4";
4529 return "DW_FORM_ref8";
4530 case DW_FORM_ref_udata:
4531 return "DW_FORM_ref_udata";
4532 case DW_FORM_indirect:
4533 return "DW_FORM_indirect";
4535 return "DW_FORM_<unknown>";
4539 /* Convert a DWARF type code into its string name. */
4543 dwarf_type_encoding_name (unsigned enc)
4547 case DW_ATE_address:
4548 return "DW_ATE_address";
4549 case DW_ATE_boolean:
4550 return "DW_ATE_boolean";
4551 case DW_ATE_complex_float:
4552 return "DW_ATE_complex_float";
4554 return "DW_ATE_float";
4556 return "DW_ATE_signed";
4557 case DW_ATE_signed_char:
4558 return "DW_ATE_signed_char";
4559 case DW_ATE_unsigned:
4560 return "DW_ATE_unsigned";
4561 case DW_ATE_unsigned_char:
4562 return "DW_ATE_unsigned_char";
4564 return "DW_ATE_<unknown>";
4569 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4570 instance of an inlined instance of a decl which is local to an inline
4571 function, so we have to trace all of the way back through the origin chain
4572 to find out what sort of node actually served as the original seed for the
4576 decl_ultimate_origin (tree decl)
4578 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4579 nodes in the function to point to themselves; ignore that if
4580 we're trying to output the abstract instance of this function. */
4581 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4584 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4585 most distant ancestor, this should never happen. */
4586 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4588 return DECL_ABSTRACT_ORIGIN (decl);
4591 /* Determine the "ultimate origin" of a block. The block may be an inlined
4592 instance of an inlined instance of a block which is local to an inline
4593 function, so we have to trace all of the way back through the origin chain
4594 to find out what sort of node actually served as the original seed for the
4598 block_ultimate_origin (tree block)
4600 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4602 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4603 nodes in the function to point to themselves; ignore that if
4604 we're trying to output the abstract instance of this function. */
4605 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4608 if (immediate_origin == NULL_TREE)
4613 tree lookahead = immediate_origin;
4617 ret_val = lookahead;
4618 lookahead = (TREE_CODE (ret_val) == BLOCK
4619 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4621 while (lookahead != NULL && lookahead != ret_val);
4627 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4628 of a virtual function may refer to a base class, so we check the 'this'
4632 decl_class_context (tree decl)
4634 tree context = NULL_TREE;
4636 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4637 context = DECL_CONTEXT (decl);
4639 context = TYPE_MAIN_VARIANT
4640 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4642 if (context && !TYPE_P (context))
4643 context = NULL_TREE;
4648 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4649 addition order, and correct that in reverse_all_dies. */
4652 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4654 if (die != NULL && attr != NULL)
4656 attr->dw_attr_next = die->die_attr;
4657 die->die_attr = attr;
4661 static inline enum dw_val_class
4662 AT_class (dw_attr_ref a)
4664 return a->dw_attr_val.val_class;
4667 /* Add a flag value attribute to a DIE. */
4670 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4672 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4674 attr->dw_attr_next = NULL;
4675 attr->dw_attr = attr_kind;
4676 attr->dw_attr_val.val_class = dw_val_class_flag;
4677 attr->dw_attr_val.v.val_flag = flag;
4678 add_dwarf_attr (die, attr);
4681 static inline unsigned
4682 AT_flag (dw_attr_ref a)
4684 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4685 return a->dw_attr_val.v.val_flag;
4688 /* Add a signed integer attribute value to a DIE. */
4691 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4693 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4695 attr->dw_attr_next = NULL;
4696 attr->dw_attr = attr_kind;
4697 attr->dw_attr_val.val_class = dw_val_class_const;
4698 attr->dw_attr_val.v.val_int = int_val;
4699 add_dwarf_attr (die, attr);
4702 static inline HOST_WIDE_INT
4703 AT_int (dw_attr_ref a)
4705 gcc_assert (a && AT_class (a) == dw_val_class_const);
4706 return a->dw_attr_val.v.val_int;
4709 /* Add an unsigned integer attribute value to a DIE. */
4712 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4713 unsigned HOST_WIDE_INT unsigned_val)
4715 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4717 attr->dw_attr_next = NULL;
4718 attr->dw_attr = attr_kind;
4719 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4720 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4721 add_dwarf_attr (die, attr);
4724 static inline unsigned HOST_WIDE_INT
4725 AT_unsigned (dw_attr_ref a)
4727 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
4728 return a->dw_attr_val.v.val_unsigned;
4731 /* Add an unsigned double integer attribute value to a DIE. */
4734 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
4735 long unsigned int val_hi, long unsigned int val_low)
4737 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4739 attr->dw_attr_next = NULL;
4740 attr->dw_attr = attr_kind;
4741 attr->dw_attr_val.val_class = dw_val_class_long_long;
4742 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4743 attr->dw_attr_val.v.val_long_long.low = val_low;
4744 add_dwarf_attr (die, attr);
4747 /* Add a floating point attribute value to a DIE and return it. */
4750 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4751 unsigned int length, unsigned int elt_size, unsigned char *array)
4753 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4755 attr->dw_attr_next = NULL;
4756 attr->dw_attr = attr_kind;
4757 attr->dw_attr_val.val_class = dw_val_class_vec;
4758 attr->dw_attr_val.v.val_vec.length = length;
4759 attr->dw_attr_val.v.val_vec.elt_size = elt_size;
4760 attr->dw_attr_val.v.val_vec.array = array;
4761 add_dwarf_attr (die, attr);
4764 /* Hash and equality functions for debug_str_hash. */
4767 debug_str_do_hash (const void *x)
4769 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4773 debug_str_eq (const void *x1, const void *x2)
4775 return strcmp ((((const struct indirect_string_node *)x1)->str),
4776 (const char *)x2) == 0;
4779 /* Add a string attribute value to a DIE. */
4782 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4784 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4785 struct indirect_string_node *node;
4788 if (! debug_str_hash)
4789 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4790 debug_str_eq, NULL);
4792 slot = htab_find_slot_with_hash (debug_str_hash, str,
4793 htab_hash_string (str), INSERT);
4795 *slot = ggc_alloc_cleared (sizeof (struct indirect_string_node));
4796 node = (struct indirect_string_node *) *slot;
4797 node->str = ggc_strdup (str);
4800 attr->dw_attr_next = NULL;
4801 attr->dw_attr = attr_kind;
4802 attr->dw_attr_val.val_class = dw_val_class_str;
4803 attr->dw_attr_val.v.val_str = node;
4804 add_dwarf_attr (die, attr);
4807 static inline const char *
4808 AT_string (dw_attr_ref a)
4810 gcc_assert (a && AT_class (a) == dw_val_class_str);
4811 return a->dw_attr_val.v.val_str->str;
4814 /* Find out whether a string should be output inline in DIE
4815 or out-of-line in .debug_str section. */
4818 AT_string_form (dw_attr_ref a)
4820 struct indirect_string_node *node;
4824 gcc_assert (a && AT_class (a) == dw_val_class_str);
4826 node = a->dw_attr_val.v.val_str;
4830 len = strlen (node->str) + 1;
4832 /* If the string is shorter or equal to the size of the reference, it is
4833 always better to put it inline. */
4834 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4835 return node->form = DW_FORM_string;
4837 /* If we cannot expect the linker to merge strings in .debug_str
4838 section, only put it into .debug_str if it is worth even in this
4840 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4841 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4842 return node->form = DW_FORM_string;
4844 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4845 ++dw2_string_counter;
4846 node->label = xstrdup (label);
4848 return node->form = DW_FORM_strp;
4851 /* Add a DIE reference attribute value to a DIE. */
4854 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4856 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4858 attr->dw_attr_next = NULL;
4859 attr->dw_attr = attr_kind;
4860 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4861 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4862 attr->dw_attr_val.v.val_die_ref.external = 0;
4863 add_dwarf_attr (die, attr);
4866 /* Add an AT_specification attribute to a DIE, and also make the back
4867 pointer from the specification to the definition. */
4870 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
4872 add_AT_die_ref (die, DW_AT_specification, targ_die);
4873 gcc_assert (!targ_die->die_definition);
4874 targ_die->die_definition = die;
4877 static inline dw_die_ref
4878 AT_ref (dw_attr_ref a)
4880 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4881 return a->dw_attr_val.v.val_die_ref.die;
4885 AT_ref_external (dw_attr_ref a)
4887 if (a && AT_class (a) == dw_val_class_die_ref)
4888 return a->dw_attr_val.v.val_die_ref.external;
4894 set_AT_ref_external (dw_attr_ref a, int i)
4896 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4897 a->dw_attr_val.v.val_die_ref.external = i;
4900 /* Add an FDE reference attribute value to a DIE. */
4903 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
4905 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4907 attr->dw_attr_next = NULL;
4908 attr->dw_attr = attr_kind;
4909 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4910 attr->dw_attr_val.v.val_fde_index = targ_fde;
4911 add_dwarf_attr (die, attr);
4914 /* Add a location description attribute value to a DIE. */
4917 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
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_loc;
4924 attr->dw_attr_val.v.val_loc = loc;
4925 add_dwarf_attr (die, attr);
4928 static inline dw_loc_descr_ref
4929 AT_loc (dw_attr_ref a)
4931 gcc_assert (a && AT_class (a) == dw_val_class_loc);
4932 return a->dw_attr_val.v.val_loc;
4936 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
4938 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4940 attr->dw_attr_next = NULL;
4941 attr->dw_attr = attr_kind;
4942 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4943 attr->dw_attr_val.v.val_loc_list = loc_list;
4944 add_dwarf_attr (die, attr);
4945 have_location_lists = 1;
4948 static inline dw_loc_list_ref
4949 AT_loc_list (dw_attr_ref a)
4951 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4952 return a->dw_attr_val.v.val_loc_list;
4955 /* Add an address constant attribute value to a DIE. */
4958 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
4960 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4962 attr->dw_attr_next = NULL;
4963 attr->dw_attr = attr_kind;
4964 attr->dw_attr_val.val_class = dw_val_class_addr;
4965 attr->dw_attr_val.v.val_addr = addr;
4966 add_dwarf_attr (die, attr);
4970 AT_addr (dw_attr_ref a)
4972 gcc_assert (a && AT_class (a) == dw_val_class_addr);
4973 return a->dw_attr_val.v.val_addr;
4976 /* Add a label identifier attribute value to a DIE. */
4979 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
4981 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4983 attr->dw_attr_next = NULL;
4984 attr->dw_attr = attr_kind;
4985 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4986 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4987 add_dwarf_attr (die, attr);
4990 /* Add a section offset attribute value to a DIE. */
4993 add_AT_lbl_offset (dw_die_ref die, enum dwarf_attribute attr_kind, const char *label)
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_offset;
5000 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
5001 add_dwarf_attr (die, attr);
5004 /* Add an offset attribute value to a DIE. */
5007 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
5008 unsigned HOST_WIDE_INT offset)
5010 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5012 attr->dw_attr_next = NULL;
5013 attr->dw_attr = attr_kind;
5014 attr->dw_attr_val.val_class = dw_val_class_offset;
5015 attr->dw_attr_val.v.val_offset = offset;
5016 add_dwarf_attr (die, attr);
5019 /* Add an range_list attribute value to a DIE. */
5022 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5023 long unsigned int offset)
5025 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5027 attr->dw_attr_next = NULL;
5028 attr->dw_attr = attr_kind;
5029 attr->dw_attr_val.val_class = dw_val_class_range_list;
5030 attr->dw_attr_val.v.val_offset = offset;
5031 add_dwarf_attr (die, attr);
5034 static inline const char *
5035 AT_lbl (dw_attr_ref a)
5037 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5038 || AT_class (a) == dw_val_class_lbl_offset));
5039 return a->dw_attr_val.v.val_lbl_id;
5042 /* Get the attribute of type attr_kind. */
5045 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5048 dw_die_ref spec = NULL;
5052 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5053 if (a->dw_attr == attr_kind)
5055 else if (a->dw_attr == DW_AT_specification
5056 || a->dw_attr == DW_AT_abstract_origin)
5060 return get_AT (spec, attr_kind);
5066 /* Return the "low pc" attribute value, typically associated with a subprogram
5067 DIE. Return null if the "low pc" attribute is either not present, or if it
5068 cannot be represented as an assembler label identifier. */
5070 static inline const char *
5071 get_AT_low_pc (dw_die_ref die)
5073 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
5075 return a ? AT_lbl (a) : NULL;
5078 /* Return the "high pc" attribute value, typically associated with a subprogram
5079 DIE. Return null if the "high pc" attribute is either not present, or if it
5080 cannot be represented as an assembler label identifier. */
5082 static inline const char *
5083 get_AT_hi_pc (dw_die_ref die)
5085 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
5087 return a ? AT_lbl (a) : NULL;
5090 /* Return the value of the string attribute designated by ATTR_KIND, or
5091 NULL if it is not present. */
5093 static inline const char *
5094 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5096 dw_attr_ref a = get_AT (die, attr_kind);
5098 return a ? AT_string (a) : NULL;
5101 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5102 if it is not present. */
5105 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5107 dw_attr_ref a = get_AT (die, attr_kind);
5109 return a ? AT_flag (a) : 0;
5112 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5113 if it is not present. */
5115 static inline unsigned
5116 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5118 dw_attr_ref a = get_AT (die, attr_kind);
5120 return a ? AT_unsigned (a) : 0;
5123 static inline dw_die_ref
5124 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5126 dw_attr_ref a = get_AT (die, attr_kind);
5128 return a ? AT_ref (a) : NULL;
5131 /* Return TRUE if the language is C or C++. */
5136 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5138 return (lang == DW_LANG_C || lang == DW_LANG_C89
5139 || lang == DW_LANG_C_plus_plus);
5142 /* Return TRUE if the language is C++. */
5147 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
5148 == DW_LANG_C_plus_plus);
5151 /* Return TRUE if the language is Fortran. */
5156 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5158 return (lang == DW_LANG_Fortran77
5159 || lang == DW_LANG_Fortran90
5160 || lang == DW_LANG_Fortran95);
5163 /* Return TRUE if the language is Java. */
5168 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5170 return lang == DW_LANG_Java;
5173 /* Return TRUE if the language is Ada. */
5178 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5180 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5183 /* Free up the memory used by A. */
5185 static inline void free_AT (dw_attr_ref);
5187 free_AT (dw_attr_ref a)
5189 if (AT_class (a) == dw_val_class_str)
5190 if (a->dw_attr_val.v.val_str->refcount)
5191 a->dw_attr_val.v.val_str->refcount--;
5194 /* Remove the specified attribute if present. */
5197 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5200 dw_attr_ref removed = NULL;
5204 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
5205 if ((*p)->dw_attr == attr_kind)
5208 *p = (*p)->dw_attr_next;
5217 /* Remove child die whose die_tag is specified tag. */
5220 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5222 dw_die_ref current, prev, next;
5223 current = die->die_child;
5225 while (current != NULL)
5227 if (current->die_tag == tag)
5229 next = current->die_sib;
5231 die->die_child = next;
5233 prev->die_sib = next;
5240 current = current->die_sib;
5245 /* Free up the memory used by DIE. */
5248 free_die (dw_die_ref die)
5250 remove_children (die);
5253 /* Discard the children of this DIE. */
5256 remove_children (dw_die_ref die)
5258 dw_die_ref child_die = die->die_child;
5260 die->die_child = NULL;
5262 while (child_die != NULL)
5264 dw_die_ref tmp_die = child_die;
5267 child_die = child_die->die_sib;
5269 for (a = tmp_die->die_attr; a != NULL;)
5271 dw_attr_ref tmp_a = a;
5273 a = a->dw_attr_next;
5281 /* Add a child DIE below its parent. We build the lists up in reverse
5282 addition order, and correct that in reverse_all_dies. */
5285 add_child_die (dw_die_ref die, dw_die_ref child_die)
5287 if (die != NULL && child_die != NULL)
5289 gcc_assert (die != child_die);
5291 child_die->die_parent = die;
5292 child_die->die_sib = die->die_child;
5293 die->die_child = child_die;
5297 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5298 is the specification, to the front of PARENT's list of children. */
5301 splice_child_die (dw_die_ref parent, dw_die_ref child)
5305 /* We want the declaration DIE from inside the class, not the
5306 specification DIE at toplevel. */
5307 if (child->die_parent != parent)
5309 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5315 gcc_assert (child->die_parent == parent
5316 || (child->die_parent
5317 == get_AT_ref (parent, DW_AT_specification)));
5319 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5322 *p = child->die_sib;
5326 child->die_parent = parent;
5327 child->die_sib = parent->die_child;
5328 parent->die_child = child;
5331 /* Return a pointer to a newly created DIE node. */
5333 static inline dw_die_ref
5334 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5336 dw_die_ref die = ggc_alloc_cleared (sizeof (die_node));
5338 die->die_tag = tag_value;
5340 if (parent_die != NULL)
5341 add_child_die (parent_die, die);
5344 limbo_die_node *limbo_node;
5346 limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node));
5347 limbo_node->die = die;
5348 limbo_node->created_for = t;
5349 limbo_node->next = limbo_die_list;
5350 limbo_die_list = limbo_node;
5356 /* Return the DIE associated with the given type specifier. */
5358 static inline dw_die_ref
5359 lookup_type_die (tree type)
5361 return TYPE_SYMTAB_DIE (type);
5364 /* Equate a DIE to a given type specifier. */
5367 equate_type_number_to_die (tree type, dw_die_ref type_die)
5369 TYPE_SYMTAB_DIE (type) = type_die;
5372 /* Returns a hash value for X (which really is a die_struct). */
5375 decl_die_table_hash (const void *x)
5377 return (hashval_t) ((const dw_die_ref) x)->decl_id;
5380 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5383 decl_die_table_eq (const void *x, const void *y)
5385 return (((const dw_die_ref) x)->decl_id == DECL_UID ((const tree) y));
5388 /* Return the DIE associated with a given declaration. */
5390 static inline dw_die_ref
5391 lookup_decl_die (tree decl)
5393 return htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5396 /* Returns a hash value for X (which really is a var_loc_list). */
5399 decl_loc_table_hash (const void *x)
5401 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5404 /* Return nonzero if decl_id of var_loc_list X is the same as
5408 decl_loc_table_eq (const void *x, const void *y)
5410 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const tree) y));
5413 /* Return the var_loc list associated with a given declaration. */
5415 static inline var_loc_list *
5416 lookup_decl_loc (tree decl)
5418 return htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5421 /* Equate a DIE to a particular declaration. */
5424 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5426 unsigned int decl_id = DECL_UID (decl);
5429 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5431 decl_die->decl_id = decl_id;
5434 /* Add a variable location node to the linked list for DECL. */
5437 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
5439 unsigned int decl_id = DECL_UID (decl);
5443 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5446 temp = ggc_alloc_cleared (sizeof (var_loc_list));
5447 temp->decl_id = decl_id;
5455 /* If the current location is the same as the end of the list,
5456 we have nothing to do. */
5457 if (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
5458 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
5460 /* Add LOC to the end of list and update LAST. */
5461 temp->last->next = loc;
5465 /* Do not add empty location to the beginning of the list. */
5466 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
5473 /* Keep track of the number of spaces used to indent the
5474 output of the debugging routines that print the structure of
5475 the DIE internal representation. */
5476 static int print_indent;
5478 /* Indent the line the number of spaces given by print_indent. */
5481 print_spaces (FILE *outfile)
5483 fprintf (outfile, "%*s", print_indent, "");
5486 /* Print the information associated with a given DIE, and its children.
5487 This routine is a debugging aid only. */
5490 print_die (dw_die_ref die, FILE *outfile)
5495 print_spaces (outfile);
5496 fprintf (outfile, "DIE %4lu: %s\n",
5497 die->die_offset, dwarf_tag_name (die->die_tag));
5498 print_spaces (outfile);
5499 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5500 fprintf (outfile, " offset: %lu\n", die->die_offset);
5502 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5504 print_spaces (outfile);
5505 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5507 switch (AT_class (a))
5509 case dw_val_class_addr:
5510 fprintf (outfile, "address");
5512 case dw_val_class_offset:
5513 fprintf (outfile, "offset");
5515 case dw_val_class_loc:
5516 fprintf (outfile, "location descriptor");
5518 case dw_val_class_loc_list:
5519 fprintf (outfile, "location list -> label:%s",
5520 AT_loc_list (a)->ll_symbol);
5522 case dw_val_class_range_list:
5523 fprintf (outfile, "range list");
5525 case dw_val_class_const:
5526 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5528 case dw_val_class_unsigned_const:
5529 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5531 case dw_val_class_long_long:
5532 fprintf (outfile, "constant (%lu,%lu)",
5533 a->dw_attr_val.v.val_long_long.hi,
5534 a->dw_attr_val.v.val_long_long.low);
5536 case dw_val_class_vec:
5537 fprintf (outfile, "floating-point or vector constant");
5539 case dw_val_class_flag:
5540 fprintf (outfile, "%u", AT_flag (a));
5542 case dw_val_class_die_ref:
5543 if (AT_ref (a) != NULL)
5545 if (AT_ref (a)->die_symbol)
5546 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5548 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5551 fprintf (outfile, "die -> <null>");
5553 case dw_val_class_lbl_id:
5554 case dw_val_class_lbl_offset:
5555 fprintf (outfile, "label: %s", AT_lbl (a));
5557 case dw_val_class_str:
5558 if (AT_string (a) != NULL)
5559 fprintf (outfile, "\"%s\"", AT_string (a));
5561 fprintf (outfile, "<null>");
5567 fprintf (outfile, "\n");
5570 if (die->die_child != NULL)
5573 for (c = die->die_child; c != NULL; c = c->die_sib)
5574 print_die (c, outfile);
5578 if (print_indent == 0)
5579 fprintf (outfile, "\n");
5582 /* Print the contents of the source code line number correspondence table.
5583 This routine is a debugging aid only. */
5586 print_dwarf_line_table (FILE *outfile)
5589 dw_line_info_ref line_info;
5591 fprintf (outfile, "\n\nDWARF source line information\n");
5592 for (i = 1; i < line_info_table_in_use; i++)
5594 line_info = &line_info_table[i];
5595 fprintf (outfile, "%5d: ", i);
5596 fprintf (outfile, "%-20s",
5597 VARRAY_CHAR_PTR (file_table, line_info->dw_file_num));
5598 fprintf (outfile, "%6ld", line_info->dw_line_num);
5599 fprintf (outfile, "\n");
5602 fprintf (outfile, "\n\n");
5605 /* Print the information collected for a given DIE. */
5608 debug_dwarf_die (dw_die_ref die)
5610 print_die (die, stderr);
5613 /* Print all DWARF information collected for the compilation unit.
5614 This routine is a debugging aid only. */
5620 print_die (comp_unit_die, stderr);
5621 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5622 print_dwarf_line_table (stderr);
5625 /* We build up the lists of children and attributes by pushing new ones
5626 onto the beginning of the list. Reverse the lists for DIE so that
5627 they are in order of addition. */
5630 reverse_die_lists (dw_die_ref die)
5632 dw_die_ref c, cp, cn;
5633 dw_attr_ref a, ap, an;
5635 for (a = die->die_attr, ap = 0; a; a = an)
5637 an = a->dw_attr_next;
5638 a->dw_attr_next = ap;
5644 for (c = die->die_child, cp = 0; c; c = cn)
5651 die->die_child = cp;
5654 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5655 reverse all dies in add_sibling_attributes, which runs through all the dies,
5656 it would reverse all the dies. Now, however, since we don't call
5657 reverse_die_lists in add_sibling_attributes, we need a routine to
5658 recursively reverse all the dies. This is that routine. */
5661 reverse_all_dies (dw_die_ref die)
5665 reverse_die_lists (die);
5667 for (c = die->die_child; c; c = c->die_sib)
5668 reverse_all_dies (c);
5671 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5672 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5673 DIE that marks the start of the DIEs for this include file. */
5676 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5678 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5679 dw_die_ref new_unit = gen_compile_unit_die (filename);
5681 new_unit->die_sib = old_unit;
5685 /* Close an include-file CU and reopen the enclosing one. */
5688 pop_compile_unit (dw_die_ref old_unit)
5690 dw_die_ref new_unit = old_unit->die_sib;
5692 old_unit->die_sib = NULL;
5696 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5697 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5699 /* Calculate the checksum of a location expression. */
5702 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5704 CHECKSUM (loc->dw_loc_opc);
5705 CHECKSUM (loc->dw_loc_oprnd1);
5706 CHECKSUM (loc->dw_loc_oprnd2);
5709 /* Calculate the checksum of an attribute. */
5712 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5714 dw_loc_descr_ref loc;
5717 CHECKSUM (at->dw_attr);
5719 /* We don't care about differences in file numbering. */
5720 if (at->dw_attr == DW_AT_decl_file
5721 /* Or that this was compiled with a different compiler snapshot; if
5722 the output is the same, that's what matters. */
5723 || at->dw_attr == DW_AT_producer)
5726 switch (AT_class (at))
5728 case dw_val_class_const:
5729 CHECKSUM (at->dw_attr_val.v.val_int);
5731 case dw_val_class_unsigned_const:
5732 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5734 case dw_val_class_long_long:
5735 CHECKSUM (at->dw_attr_val.v.val_long_long);
5737 case dw_val_class_vec:
5738 CHECKSUM (at->dw_attr_val.v.val_vec);
5740 case dw_val_class_flag:
5741 CHECKSUM (at->dw_attr_val.v.val_flag);
5743 case dw_val_class_str:
5744 CHECKSUM_STRING (AT_string (at));
5747 case dw_val_class_addr:
5749 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5750 CHECKSUM_STRING (XSTR (r, 0));
5753 case dw_val_class_offset:
5754 CHECKSUM (at->dw_attr_val.v.val_offset);
5757 case dw_val_class_loc:
5758 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5759 loc_checksum (loc, ctx);
5762 case dw_val_class_die_ref:
5763 die_checksum (AT_ref (at), ctx, mark);
5766 case dw_val_class_fde_ref:
5767 case dw_val_class_lbl_id:
5768 case dw_val_class_lbl_offset:
5776 /* Calculate the checksum of a DIE. */
5779 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5784 /* To avoid infinite recursion. */
5787 CHECKSUM (die->die_mark);
5790 die->die_mark = ++(*mark);
5792 CHECKSUM (die->die_tag);
5794 for (a = die->die_attr; a; a = a->dw_attr_next)
5795 attr_checksum (a, ctx, mark);
5797 for (c = die->die_child; c; c = c->die_sib)
5798 die_checksum (c, ctx, mark);
5802 #undef CHECKSUM_STRING
5804 /* Do the location expressions look same? */
5806 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
5808 return loc1->dw_loc_opc == loc2->dw_loc_opc
5809 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
5810 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
5813 /* Do the values look the same? */
5815 same_dw_val_p (dw_val_node *v1, dw_val_node *v2, int *mark)
5817 dw_loc_descr_ref loc1, loc2;
5820 if (v1->val_class != v2->val_class)
5823 switch (v1->val_class)
5825 case dw_val_class_const:
5826 return v1->v.val_int == v2->v.val_int;
5827 case dw_val_class_unsigned_const:
5828 return v1->v.val_unsigned == v2->v.val_unsigned;
5829 case dw_val_class_long_long:
5830 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
5831 && v1->v.val_long_long.low == v2->v.val_long_long.low;
5832 case dw_val_class_vec:
5833 if (v1->v.val_vec.length != v2->v.val_vec.length
5834 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
5836 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
5837 v1->v.val_vec.length * v1->v.val_vec.elt_size))
5840 case dw_val_class_flag:
5841 return v1->v.val_flag == v2->v.val_flag;
5842 case dw_val_class_str:
5843 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
5845 case dw_val_class_addr:
5846 r1 = v1->v.val_addr;
5847 r2 = v2->v.val_addr;
5848 if (GET_CODE (r1) != GET_CODE (r2))
5850 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
5851 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
5853 case dw_val_class_offset:
5854 return v1->v.val_offset == v2->v.val_offset;
5856 case dw_val_class_loc:
5857 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
5859 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
5860 if (!same_loc_p (loc1, loc2, mark))
5862 return !loc1 && !loc2;
5864 case dw_val_class_die_ref:
5865 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
5867 case dw_val_class_fde_ref:
5868 case dw_val_class_lbl_id:
5869 case dw_val_class_lbl_offset:
5877 /* Do the attributes look the same? */
5880 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
5882 if (at1->dw_attr != at2->dw_attr)
5885 /* We don't care about differences in file numbering. */
5886 if (at1->dw_attr == DW_AT_decl_file
5887 /* Or that this was compiled with a different compiler snapshot; if
5888 the output is the same, that's what matters. */
5889 || at1->dw_attr == DW_AT_producer)
5892 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
5895 /* Do the dies look the same? */
5898 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
5903 /* To avoid infinite recursion. */
5905 return die1->die_mark == die2->die_mark;
5906 die1->die_mark = die2->die_mark = ++(*mark);
5908 if (die1->die_tag != die2->die_tag)
5911 for (a1 = die1->die_attr, a2 = die2->die_attr;
5913 a1 = a1->dw_attr_next, a2 = a2->dw_attr_next)
5914 if (!same_attr_p (a1, a2, mark))
5919 for (c1 = die1->die_child, c2 = die2->die_child;
5921 c1 = c1->die_sib, c2 = c2->die_sib)
5922 if (!same_die_p (c1, c2, mark))
5930 /* Do the dies look the same? Wrapper around same_die_p. */
5933 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
5936 int ret = same_die_p (die1, die2, &mark);
5938 unmark_all_dies (die1);
5939 unmark_all_dies (die2);
5944 /* The prefix to attach to symbols on DIEs in the current comdat debug
5946 static char *comdat_symbol_id;
5948 /* The index of the current symbol within the current comdat CU. */
5949 static unsigned int comdat_symbol_number;
5951 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5952 children, and set comdat_symbol_id accordingly. */
5955 compute_section_prefix (dw_die_ref unit_die)
5957 const char *die_name = get_AT_string (unit_die, DW_AT_name);
5958 const char *base = die_name ? lbasename (die_name) : "anonymous";
5959 char *name = alloca (strlen (base) + 64);
5962 unsigned char checksum[16];
5965 /* Compute the checksum of the DIE, then append part of it as hex digits to
5966 the name filename of the unit. */
5968 md5_init_ctx (&ctx);
5970 die_checksum (unit_die, &ctx, &mark);
5971 unmark_all_dies (unit_die);
5972 md5_finish_ctx (&ctx, checksum);
5974 sprintf (name, "%s.", base);
5975 clean_symbol_name (name);
5977 p = name + strlen (name);
5978 for (i = 0; i < 4; i++)
5980 sprintf (p, "%.2x", checksum[i]);
5984 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5985 comdat_symbol_number = 0;
5988 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5991 is_type_die (dw_die_ref die)
5993 switch (die->die_tag)
5995 case DW_TAG_array_type:
5996 case DW_TAG_class_type:
5997 case DW_TAG_enumeration_type:
5998 case DW_TAG_pointer_type:
5999 case DW_TAG_reference_type:
6000 case DW_TAG_string_type:
6001 case DW_TAG_structure_type:
6002 case DW_TAG_subroutine_type:
6003 case DW_TAG_union_type:
6004 case DW_TAG_ptr_to_member_type:
6005 case DW_TAG_set_type:
6006 case DW_TAG_subrange_type:
6007 case DW_TAG_base_type:
6008 case DW_TAG_const_type:
6009 case DW_TAG_file_type:
6010 case DW_TAG_packed_type:
6011 case DW_TAG_volatile_type:
6012 case DW_TAG_typedef:
6019 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6020 Basically, we want to choose the bits that are likely to be shared between
6021 compilations (types) and leave out the bits that are specific to individual
6022 compilations (functions). */
6025 is_comdat_die (dw_die_ref c)
6027 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6028 we do for stabs. The advantage is a greater likelihood of sharing between
6029 objects that don't include headers in the same order (and therefore would
6030 put the base types in a different comdat). jason 8/28/00 */
6032 if (c->die_tag == DW_TAG_base_type)
6035 if (c->die_tag == DW_TAG_pointer_type
6036 || c->die_tag == DW_TAG_reference_type
6037 || c->die_tag == DW_TAG_const_type
6038 || c->die_tag == DW_TAG_volatile_type)
6040 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6042 return t ? is_comdat_die (t) : 0;
6045 return is_type_die (c);
6048 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6049 compilation unit. */
6052 is_symbol_die (dw_die_ref c)
6054 return (is_type_die (c)
6055 || (get_AT (c, DW_AT_declaration)
6056 && !get_AT (c, DW_AT_specification)));
6060 gen_internal_sym (const char *prefix)
6064 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6065 return xstrdup (buf);
6068 /* Assign symbols to all worthy DIEs under DIE. */
6071 assign_symbol_names (dw_die_ref die)
6075 if (is_symbol_die (die))
6077 if (comdat_symbol_id)
6079 char *p = alloca (strlen (comdat_symbol_id) + 64);
6081 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6082 comdat_symbol_id, comdat_symbol_number++);
6083 die->die_symbol = xstrdup (p);
6086 die->die_symbol = gen_internal_sym ("LDIE");
6089 for (c = die->die_child; c != NULL; c = c->die_sib)
6090 assign_symbol_names (c);
6093 struct cu_hash_table_entry
6096 unsigned min_comdat_num, max_comdat_num;
6097 struct cu_hash_table_entry *next;
6100 /* Routines to manipulate hash table of CUs. */
6102 htab_cu_hash (const void *of)
6104 const struct cu_hash_table_entry *entry = of;
6106 return htab_hash_string (entry->cu->die_symbol);
6110 htab_cu_eq (const void *of1, const void *of2)
6112 const struct cu_hash_table_entry *entry1 = of1;
6113 const struct die_struct *entry2 = of2;
6115 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
6119 htab_cu_del (void *what)
6121 struct cu_hash_table_entry *next, *entry = what;
6131 /* Check whether we have already seen this CU and set up SYM_NUM
6134 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6136 struct cu_hash_table_entry dummy;
6137 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6139 dummy.max_comdat_num = 0;
6141 slot = (struct cu_hash_table_entry **)
6142 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6146 for (; entry; last = entry, entry = entry->next)
6148 if (same_die_p_wrap (cu, entry->cu))
6154 *sym_num = entry->min_comdat_num;
6158 entry = xcalloc (1, sizeof (struct cu_hash_table_entry));
6160 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6161 entry->next = *slot;
6167 /* Record SYM_NUM to record of CU in HTABLE. */
6169 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6171 struct cu_hash_table_entry **slot, *entry;
6173 slot = (struct cu_hash_table_entry **)
6174 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6178 entry->max_comdat_num = sym_num;
6181 /* Traverse the DIE (which is always comp_unit_die), and set up
6182 additional compilation units for each of the include files we see
6183 bracketed by BINCL/EINCL. */
6186 break_out_includes (dw_die_ref die)
6189 dw_die_ref unit = NULL;
6190 limbo_die_node *node, **pnode;
6191 htab_t cu_hash_table;
6193 for (ptr = &(die->die_child); *ptr;)
6195 dw_die_ref c = *ptr;
6197 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6198 || (unit && is_comdat_die (c)))
6200 /* This DIE is for a secondary CU; remove it from the main one. */
6203 if (c->die_tag == DW_TAG_GNU_BINCL)
6205 unit = push_new_compile_unit (unit, c);
6208 else if (c->die_tag == DW_TAG_GNU_EINCL)
6210 unit = pop_compile_unit (unit);
6214 add_child_die (unit, c);
6218 /* Leave this DIE in the main CU. */
6219 ptr = &(c->die_sib);
6225 /* We can only use this in debugging, since the frontend doesn't check
6226 to make sure that we leave every include file we enter. */
6230 assign_symbol_names (die);
6231 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6232 for (node = limbo_die_list, pnode = &limbo_die_list;
6238 compute_section_prefix (node->die);
6239 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6240 &comdat_symbol_number);
6241 assign_symbol_names (node->die);
6243 *pnode = node->next;
6246 pnode = &node->next;
6247 record_comdat_symbol_number (node->die, cu_hash_table,
6248 comdat_symbol_number);
6251 htab_delete (cu_hash_table);
6254 /* Traverse the DIE and add a sibling attribute if it may have the
6255 effect of speeding up access to siblings. To save some space,
6256 avoid generating sibling attributes for DIE's without children. */
6259 add_sibling_attributes (dw_die_ref die)
6263 if (die->die_tag != DW_TAG_compile_unit
6264 && die->die_sib && die->die_child != NULL)
6265 /* Add the sibling link to the front of the attribute list. */
6266 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
6268 for (c = die->die_child; c != NULL; c = c->die_sib)
6269 add_sibling_attributes (c);
6272 /* Output all location lists for the DIE and its children. */
6275 output_location_lists (dw_die_ref die)
6280 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
6281 if (AT_class (d_attr) == dw_val_class_loc_list)
6282 output_loc_list (AT_loc_list (d_attr));
6284 for (c = die->die_child; c != NULL; c = c->die_sib)
6285 output_location_lists (c);
6289 /* The format of each DIE (and its attribute value pairs) is encoded in an
6290 abbreviation table. This routine builds the abbreviation table and assigns
6291 a unique abbreviation id for each abbreviation entry. The children of each
6292 die are visited recursively. */
6295 build_abbrev_table (dw_die_ref die)
6297 unsigned long abbrev_id;
6298 unsigned int n_alloc;
6300 dw_attr_ref d_attr, a_attr;
6302 /* Scan the DIE references, and mark as external any that refer to
6303 DIEs from other CUs (i.e. those which are not marked). */
6304 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
6305 if (AT_class (d_attr) == dw_val_class_die_ref
6306 && AT_ref (d_attr)->die_mark == 0)
6308 gcc_assert (AT_ref (d_attr)->die_symbol);
6310 set_AT_ref_external (d_attr, 1);
6313 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6315 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6317 if (abbrev->die_tag == die->die_tag)
6319 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
6321 a_attr = abbrev->die_attr;
6322 d_attr = die->die_attr;
6324 while (a_attr != NULL && d_attr != NULL)
6326 if ((a_attr->dw_attr != d_attr->dw_attr)
6327 || (value_format (a_attr) != value_format (d_attr)))
6330 a_attr = a_attr->dw_attr_next;
6331 d_attr = d_attr->dw_attr_next;
6334 if (a_attr == NULL && d_attr == NULL)
6340 if (abbrev_id >= abbrev_die_table_in_use)
6342 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
6344 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
6345 abbrev_die_table = ggc_realloc (abbrev_die_table,
6346 sizeof (dw_die_ref) * n_alloc);
6348 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
6349 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
6350 abbrev_die_table_allocated = n_alloc;
6353 ++abbrev_die_table_in_use;
6354 abbrev_die_table[abbrev_id] = die;
6357 die->die_abbrev = abbrev_id;
6358 for (c = die->die_child; c != NULL; c = c->die_sib)
6359 build_abbrev_table (c);
6362 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6365 constant_size (long unsigned int value)
6372 log = floor_log2 (value);
6375 log = 1 << (floor_log2 (log) + 1);
6380 /* Return the size of a DIE as it is represented in the
6381 .debug_info section. */
6383 static unsigned long
6384 size_of_die (dw_die_ref die)
6386 unsigned long size = 0;
6389 size += size_of_uleb128 (die->die_abbrev);
6390 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6392 switch (AT_class (a))
6394 case dw_val_class_addr:
6395 size += DWARF2_ADDR_SIZE;
6397 case dw_val_class_offset:
6398 size += DWARF_OFFSET_SIZE;
6400 case dw_val_class_loc:
6402 unsigned long lsize = size_of_locs (AT_loc (a));
6405 size += constant_size (lsize);
6409 case dw_val_class_loc_list:
6410 size += DWARF_OFFSET_SIZE;
6412 case dw_val_class_range_list:
6413 size += DWARF_OFFSET_SIZE;
6415 case dw_val_class_const:
6416 size += size_of_sleb128 (AT_int (a));
6418 case dw_val_class_unsigned_const:
6419 size += constant_size (AT_unsigned (a));
6421 case dw_val_class_long_long:
6422 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
6424 case dw_val_class_vec:
6425 size += 1 + (a->dw_attr_val.v.val_vec.length
6426 * a->dw_attr_val.v.val_vec.elt_size); /* block */
6428 case dw_val_class_flag:
6431 case dw_val_class_die_ref:
6432 if (AT_ref_external (a))
6433 size += DWARF2_ADDR_SIZE;
6435 size += DWARF_OFFSET_SIZE;
6437 case dw_val_class_fde_ref:
6438 size += DWARF_OFFSET_SIZE;
6440 case dw_val_class_lbl_id:
6441 size += DWARF2_ADDR_SIZE;
6443 case dw_val_class_lbl_offset:
6444 size += DWARF_OFFSET_SIZE;
6446 case dw_val_class_str:
6447 if (AT_string_form (a) == DW_FORM_strp)
6448 size += DWARF_OFFSET_SIZE;
6450 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
6460 /* Size the debugging information associated with a given DIE. Visits the
6461 DIE's children recursively. Updates the global variable next_die_offset, on
6462 each time through. Uses the current value of next_die_offset to update the
6463 die_offset field in each DIE. */
6466 calc_die_sizes (dw_die_ref die)
6470 die->die_offset = next_die_offset;
6471 next_die_offset += size_of_die (die);
6473 for (c = die->die_child; c != NULL; c = c->die_sib)
6476 if (die->die_child != NULL)
6477 /* Count the null byte used to terminate sibling lists. */
6478 next_die_offset += 1;
6481 /* Set the marks for a die and its children. We do this so
6482 that we know whether or not a reference needs to use FORM_ref_addr; only
6483 DIEs in the same CU will be marked. We used to clear out the offset
6484 and use that as the flag, but ran into ordering problems. */
6487 mark_dies (dw_die_ref die)
6491 gcc_assert (!die->die_mark);
6494 for (c = die->die_child; c; c = c->die_sib)
6498 /* Clear the marks for a die and its children. */
6501 unmark_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, its children and referred dies. */
6515 unmark_all_dies (dw_die_ref die)
6524 for (c = die->die_child; c; c = c->die_sib)
6525 unmark_all_dies (c);
6527 for (a = die->die_attr; a; a = a->dw_attr_next)
6528 if (AT_class (a) == dw_val_class_die_ref)
6529 unmark_all_dies (AT_ref (a));
6532 /* Return the size of the .debug_pubnames table generated for the
6533 compilation unit. */
6535 static unsigned long
6536 size_of_pubnames (void)
6541 size = DWARF_PUBNAMES_HEADER_SIZE;
6542 for (i = 0; i < pubname_table_in_use; i++)
6544 pubname_ref p = &pubname_table[i];
6545 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
6548 size += DWARF_OFFSET_SIZE;
6552 /* Return the size of the information in the .debug_aranges section. */
6554 static unsigned long
6555 size_of_aranges (void)
6559 size = DWARF_ARANGES_HEADER_SIZE;
6561 /* Count the address/length pair for this compilation unit. */
6562 size += 2 * DWARF2_ADDR_SIZE;
6563 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6565 /* Count the two zero words used to terminated the address range table. */
6566 size += 2 * DWARF2_ADDR_SIZE;
6570 /* Select the encoding of an attribute value. */
6572 static enum dwarf_form
6573 value_format (dw_attr_ref a)
6575 switch (a->dw_attr_val.val_class)
6577 case dw_val_class_addr:
6578 return DW_FORM_addr;
6579 case dw_val_class_range_list:
6580 case dw_val_class_offset:
6581 switch (DWARF_OFFSET_SIZE)
6584 return DW_FORM_data4;
6586 return DW_FORM_data8;
6590 case dw_val_class_loc_list:
6591 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6592 .debug_loc section */
6593 return DW_FORM_data4;
6594 case dw_val_class_loc:
6595 switch (constant_size (size_of_locs (AT_loc (a))))
6598 return DW_FORM_block1;
6600 return DW_FORM_block2;
6604 case dw_val_class_const:
6605 return DW_FORM_sdata;
6606 case dw_val_class_unsigned_const:
6607 switch (constant_size (AT_unsigned (a)))
6610 return DW_FORM_data1;
6612 return DW_FORM_data2;
6614 return DW_FORM_data4;
6616 return DW_FORM_data8;
6620 case dw_val_class_long_long:
6621 return DW_FORM_block1;
6622 case dw_val_class_vec:
6623 return DW_FORM_block1;
6624 case dw_val_class_flag:
6625 return DW_FORM_flag;
6626 case dw_val_class_die_ref:
6627 if (AT_ref_external (a))
6628 return DW_FORM_ref_addr;
6631 case dw_val_class_fde_ref:
6632 return DW_FORM_data;
6633 case dw_val_class_lbl_id:
6634 return DW_FORM_addr;
6635 case dw_val_class_lbl_offset:
6636 return DW_FORM_data;
6637 case dw_val_class_str:
6638 return AT_string_form (a);
6645 /* Output the encoding of an attribute value. */
6648 output_value_format (dw_attr_ref a)
6650 enum dwarf_form form = value_format (a);
6652 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6655 /* Output the .debug_abbrev section which defines the DIE abbreviation
6659 output_abbrev_section (void)
6661 unsigned long abbrev_id;
6665 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6667 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6669 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6670 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6671 dwarf_tag_name (abbrev->die_tag));
6673 if (abbrev->die_child != NULL)
6674 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6676 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6678 for (a_attr = abbrev->die_attr; a_attr != NULL;
6679 a_attr = a_attr->dw_attr_next)
6681 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6682 dwarf_attr_name (a_attr->dw_attr));
6683 output_value_format (a_attr);
6686 dw2_asm_output_data (1, 0, NULL);
6687 dw2_asm_output_data (1, 0, NULL);
6690 /* Terminate the table. */
6691 dw2_asm_output_data (1, 0, NULL);
6694 /* Output a symbol we can use to refer to this DIE from another CU. */
6697 output_die_symbol (dw_die_ref die)
6699 char *sym = die->die_symbol;
6704 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6705 /* We make these global, not weak; if the target doesn't support
6706 .linkonce, it doesn't support combining the sections, so debugging
6708 targetm.asm_out.globalize_label (asm_out_file, sym);
6710 ASM_OUTPUT_LABEL (asm_out_file, sym);
6713 /* Return a new location list, given the begin and end range, and the
6714 expression. gensym tells us whether to generate a new internal symbol for
6715 this location list node, which is done for the head of the list only. */
6717 static inline dw_loc_list_ref
6718 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
6719 const char *section, unsigned int gensym)
6721 dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node));
6723 retlist->begin = begin;
6725 retlist->expr = expr;
6726 retlist->section = section;
6728 retlist->ll_symbol = gen_internal_sym ("LLST");
6733 /* Add a location description expression to a location list. */
6736 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
6737 const char *begin, const char *end,
6738 const char *section)
6742 /* Find the end of the chain. */
6743 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6746 /* Add a new location list node to the list. */
6747 *d = new_loc_list (descr, begin, end, section, 0);
6750 /* Output the location list given to us. */
6753 output_loc_list (dw_loc_list_ref list_head)
6755 dw_loc_list_ref curr = list_head;
6757 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6759 /* Walk the location list, and output each range + expression. */
6760 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
6763 if (separate_line_info_table_in_use == 0)
6765 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6766 "Location list begin address (%s)",
6767 list_head->ll_symbol);
6768 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6769 "Location list end address (%s)",
6770 list_head->ll_symbol);
6774 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
6775 "Location list begin address (%s)",
6776 list_head->ll_symbol);
6777 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
6778 "Location list end address (%s)",
6779 list_head->ll_symbol);
6781 size = size_of_locs (curr->expr);
6783 /* Output the block length for this list of location operations. */
6784 gcc_assert (size <= 0xffff);
6785 dw2_asm_output_data (2, size, "%s", "Location expression size");
6787 output_loc_sequence (curr->expr);
6790 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
6791 "Location list terminator begin (%s)",
6792 list_head->ll_symbol);
6793 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
6794 "Location list terminator end (%s)",
6795 list_head->ll_symbol);
6798 /* Output the DIE and its attributes. Called recursively to generate
6799 the definitions of each child DIE. */
6802 output_die (dw_die_ref die)
6808 /* If someone in another CU might refer to us, set up a symbol for
6809 them to point to. */
6810 if (die->die_symbol)
6811 output_die_symbol (die);
6813 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6814 die->die_offset, dwarf_tag_name (die->die_tag));
6816 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6818 const char *name = dwarf_attr_name (a->dw_attr);
6820 switch (AT_class (a))
6822 case dw_val_class_addr:
6823 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6826 case dw_val_class_offset:
6827 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6831 case dw_val_class_range_list:
6833 char *p = strchr (ranges_section_label, '\0');
6835 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
6836 a->dw_attr_val.v.val_offset);
6837 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6843 case dw_val_class_loc:
6844 size = size_of_locs (AT_loc (a));
6846 /* Output the block length for this list of location operations. */
6847 dw2_asm_output_data (constant_size (size), size, "%s", name);
6849 output_loc_sequence (AT_loc (a));
6852 case dw_val_class_const:
6853 /* ??? It would be slightly more efficient to use a scheme like is
6854 used for unsigned constants below, but gdb 4.x does not sign
6855 extend. Gdb 5.x does sign extend. */
6856 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6859 case dw_val_class_unsigned_const:
6860 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6861 AT_unsigned (a), "%s", name);
6864 case dw_val_class_long_long:
6866 unsigned HOST_WIDE_INT first, second;
6868 dw2_asm_output_data (1,
6869 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6872 if (WORDS_BIG_ENDIAN)
6874 first = a->dw_attr_val.v.val_long_long.hi;
6875 second = a->dw_attr_val.v.val_long_long.low;
6879 first = a->dw_attr_val.v.val_long_long.low;
6880 second = a->dw_attr_val.v.val_long_long.hi;
6883 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6884 first, "long long constant");
6885 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6890 case dw_val_class_vec:
6892 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
6893 unsigned int len = a->dw_attr_val.v.val_vec.length;
6897 dw2_asm_output_data (1, len * elt_size, "%s", name);
6898 if (elt_size > sizeof (HOST_WIDE_INT))
6903 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
6906 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
6907 "fp or vector constant word %u", i);
6911 case dw_val_class_flag:
6912 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6915 case dw_val_class_loc_list:
6917 char *sym = AT_loc_list (a)->ll_symbol;
6920 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, "%s", name);
6924 case dw_val_class_die_ref:
6925 if (AT_ref_external (a))
6927 char *sym = AT_ref (a)->die_symbol;
6930 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6934 gcc_assert (AT_ref (a)->die_offset);
6935 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6940 case dw_val_class_fde_ref:
6944 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6945 a->dw_attr_val.v.val_fde_index * 2);
6946 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6950 case dw_val_class_lbl_id:
6951 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6954 case dw_val_class_lbl_offset:
6955 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6958 case dw_val_class_str:
6959 if (AT_string_form (a) == DW_FORM_strp)
6960 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6961 a->dw_attr_val.v.val_str->label,
6962 "%s: \"%s\"", name, AT_string (a));
6964 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6972 for (c = die->die_child; c != NULL; c = c->die_sib)
6975 /* Add null byte to terminate sibling list. */
6976 if (die->die_child != NULL)
6977 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6981 /* Output the compilation unit that appears at the beginning of the
6982 .debug_info section, and precedes the DIE descriptions. */
6985 output_compilation_unit_header (void)
6987 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
6988 dw2_asm_output_data (4, 0xffffffff,
6989 "Initial length escape value indicating 64-bit DWARF extension");
6990 dw2_asm_output_data (DWARF_OFFSET_SIZE,
6991 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
6992 "Length of Compilation Unit Info");
6993 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6994 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6995 "Offset Into Abbrev. Section");
6996 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6999 /* Output the compilation unit DIE and its children. */
7002 output_comp_unit (dw_die_ref die, int output_if_empty)
7004 const char *secname;
7007 /* Unless we are outputting main CU, we may throw away empty ones. */
7008 if (!output_if_empty && die->die_child == NULL)
7011 /* Even if there are no children of this DIE, we must output the information
7012 about the compilation unit. Otherwise, on an empty translation unit, we
7013 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7014 will then complain when examining the file. First mark all the DIEs in
7015 this CU so we know which get local refs. */
7018 build_abbrev_table (die);
7020 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7021 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7022 calc_die_sizes (die);
7024 oldsym = die->die_symbol;
7027 tmp = alloca (strlen (oldsym) + 24);
7029 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
7031 die->die_symbol = NULL;
7034 secname = (const char *) DEBUG_INFO_SECTION;
7036 /* Output debugging information. */
7037 named_section_flags (secname, SECTION_DEBUG);
7038 output_compilation_unit_header ();
7041 /* Leave the marks on the main CU, so we can check them in
7046 die->die_symbol = oldsym;
7050 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
7051 output of lang_hooks.decl_printable_name for C++ looks like
7052 "A::f(int)". Let's drop the argument list, and maybe the scope. */
7055 dwarf2_name (tree decl, int scope)
7057 return lang_hooks.decl_printable_name (decl, scope ? 1 : 0);
7060 /* Add a new entry to .debug_pubnames if appropriate. */
7063 add_pubname (tree decl, dw_die_ref die)
7067 if (! TREE_PUBLIC (decl))
7070 if (pubname_table_in_use == pubname_table_allocated)
7072 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
7074 = ggc_realloc (pubname_table,
7075 (pubname_table_allocated * sizeof (pubname_entry)));
7076 memset (pubname_table + pubname_table_in_use, 0,
7077 PUBNAME_TABLE_INCREMENT * sizeof (pubname_entry));
7080 p = &pubname_table[pubname_table_in_use++];
7082 p->name = xstrdup (dwarf2_name (decl, 1));
7085 /* Output the public names table used to speed up access to externally
7086 visible names. For now, only generate entries for externally
7087 visible procedures. */
7090 output_pubnames (void)
7093 unsigned long pubnames_length = size_of_pubnames ();
7095 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7096 dw2_asm_output_data (4, 0xffffffff,
7097 "Initial length escape value indicating 64-bit DWARF extension");
7098 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7099 "Length of Public Names Info");
7100 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7101 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7102 "Offset of Compilation Unit Info");
7103 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
7104 "Compilation Unit Length");
7106 for (i = 0; i < pubname_table_in_use; i++)
7108 pubname_ref pub = &pubname_table[i];
7110 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7111 gcc_assert (pub->die->die_mark);
7113 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
7116 dw2_asm_output_nstring (pub->name, -1, "external name");
7119 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
7122 /* Add a new entry to .debug_aranges if appropriate. */
7125 add_arange (tree decl, dw_die_ref die)
7127 if (! DECL_SECTION_NAME (decl))
7130 if (arange_table_in_use == arange_table_allocated)
7132 arange_table_allocated += ARANGE_TABLE_INCREMENT;
7133 arange_table = ggc_realloc (arange_table,
7134 (arange_table_allocated
7135 * sizeof (dw_die_ref)));
7136 memset (arange_table + arange_table_in_use, 0,
7137 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
7140 arange_table[arange_table_in_use++] = die;
7143 /* Output the information that goes into the .debug_aranges table.
7144 Namely, define the beginning and ending address range of the
7145 text section generated for this compilation unit. */
7148 output_aranges (void)
7151 unsigned long aranges_length = size_of_aranges ();
7153 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7154 dw2_asm_output_data (4, 0xffffffff,
7155 "Initial length escape value indicating 64-bit DWARF extension");
7156 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
7157 "Length of Address Ranges Info");
7158 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7159 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7160 "Offset of Compilation Unit Info");
7161 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
7162 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7164 /* We need to align to twice the pointer size here. */
7165 if (DWARF_ARANGES_PAD_SIZE)
7167 /* Pad using a 2 byte words so that padding is correct for any
7169 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7170 2 * DWARF2_ADDR_SIZE);
7171 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
7172 dw2_asm_output_data (2, 0, NULL);
7175 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
7176 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
7177 text_section_label, "Length");
7179 for (i = 0; i < arange_table_in_use; i++)
7181 dw_die_ref die = arange_table[i];
7183 /* We shouldn't see aranges for DIEs outside of the main CU. */
7184 gcc_assert (die->die_mark);
7186 if (die->die_tag == DW_TAG_subprogram)
7188 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
7190 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
7191 get_AT_low_pc (die), "Length");
7195 /* A static variable; extract the symbol from DW_AT_location.
7196 Note that this code isn't currently hit, as we only emit
7197 aranges for functions (jason 9/23/99). */
7198 dw_attr_ref a = get_AT (die, DW_AT_location);
7199 dw_loc_descr_ref loc;
7201 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7204 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
7206 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
7207 loc->dw_loc_oprnd1.v.val_addr, "Address");
7208 dw2_asm_output_data (DWARF2_ADDR_SIZE,
7209 get_AT_unsigned (die, DW_AT_byte_size),
7214 /* Output the terminator words. */
7215 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7216 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7219 /* Add a new entry to .debug_ranges. Return the offset at which it
7223 add_ranges (tree block)
7225 unsigned int in_use = ranges_table_in_use;
7227 if (in_use == ranges_table_allocated)
7229 ranges_table_allocated += RANGES_TABLE_INCREMENT;
7231 = ggc_realloc (ranges_table, (ranges_table_allocated
7232 * sizeof (struct dw_ranges_struct)));
7233 memset (ranges_table + ranges_table_in_use, 0,
7234 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
7237 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
7238 ranges_table_in_use = in_use + 1;
7240 return in_use * 2 * DWARF2_ADDR_SIZE;
7244 output_ranges (void)
7247 static const char *const start_fmt = "Offset 0x%x";
7248 const char *fmt = start_fmt;
7250 for (i = 0; i < ranges_table_in_use; i++)
7252 int block_num = ranges_table[i].block_num;
7256 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
7257 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
7259 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
7260 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
7262 /* If all code is in the text section, then the compilation
7263 unit base address defaults to DW_AT_low_pc, which is the
7264 base of the text section. */
7265 if (separate_line_info_table_in_use == 0)
7267 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
7269 fmt, i * 2 * DWARF2_ADDR_SIZE);
7270 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
7271 text_section_label, NULL);
7274 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
7275 compilation unit base address to zero, which allows us to
7276 use absolute addresses, and not worry about whether the
7277 target supports cross-section arithmetic. */
7280 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
7281 fmt, i * 2 * DWARF2_ADDR_SIZE);
7282 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
7289 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7290 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7296 /* Data structure containing information about input files. */
7299 char *path; /* Complete file name. */
7300 char *fname; /* File name part. */
7301 int length; /* Length of entire string. */
7302 int file_idx; /* Index in input file table. */
7303 int dir_idx; /* Index in directory table. */
7306 /* Data structure containing information about directories with source
7310 char *path; /* Path including directory name. */
7311 int length; /* Path length. */
7312 int prefix; /* Index of directory entry which is a prefix. */
7313 int count; /* Number of files in this directory. */
7314 int dir_idx; /* Index of directory used as base. */
7315 int used; /* Used in the end? */
7318 /* Callback function for file_info comparison. We sort by looking at
7319 the directories in the path. */
7322 file_info_cmp (const void *p1, const void *p2)
7324 const struct file_info *s1 = p1;
7325 const struct file_info *s2 = p2;
7329 /* Take care of file names without directories. We need to make sure that
7330 we return consistent values to qsort since some will get confused if
7331 we return the same value when identical operands are passed in opposite
7332 orders. So if neither has a directory, return 0 and otherwise return
7333 1 or -1 depending on which one has the directory. */
7334 if ((s1->path == s1->fname || s2->path == s2->fname))
7335 return (s2->path == s2->fname) - (s1->path == s1->fname);
7337 cp1 = (unsigned char *) s1->path;
7338 cp2 = (unsigned char *) s2->path;
7344 /* Reached the end of the first path? If so, handle like above. */
7345 if ((cp1 == (unsigned char *) s1->fname)
7346 || (cp2 == (unsigned char *) s2->fname))
7347 return ((cp2 == (unsigned char *) s2->fname)
7348 - (cp1 == (unsigned char *) s1->fname));
7350 /* Character of current path component the same? */
7351 else if (*cp1 != *cp2)
7356 /* Output the directory table and the file name table. We try to minimize
7357 the total amount of memory needed. A heuristic is used to avoid large
7358 slowdowns with many input files. */
7361 output_file_names (void)
7363 struct file_info *files;
7364 struct dir_info *dirs;
7373 /* Handle the case where file_table is empty. */
7374 if (VARRAY_ACTIVE_SIZE (file_table) <= 1)
7376 dw2_asm_output_data (1, 0, "End directory table");
7377 dw2_asm_output_data (1, 0, "End file name table");
7381 /* Allocate the various arrays we need. */
7382 files = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct file_info));
7383 dirs = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct dir_info));
7385 /* Sort the file names. */
7386 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7390 /* Skip all leading "./". */
7391 f = VARRAY_CHAR_PTR (file_table, i);
7392 while (f[0] == '.' && f[1] == '/')
7395 /* Create a new array entry. */
7397 files[i].length = strlen (f);
7398 files[i].file_idx = i;
7400 /* Search for the file name part. */
7401 f = strrchr (f, '/');
7402 files[i].fname = f == NULL ? files[i].path : f + 1;
7405 qsort (files + 1, VARRAY_ACTIVE_SIZE (file_table) - 1,
7406 sizeof (files[0]), file_info_cmp);
7408 /* Find all the different directories used. */
7409 dirs[0].path = files[1].path;
7410 dirs[0].length = files[1].fname - files[1].path;
7411 dirs[0].prefix = -1;
7413 dirs[0].dir_idx = 0;
7415 files[1].dir_idx = 0;
7418 for (i = 2; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7419 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
7420 && memcmp (dirs[ndirs - 1].path, files[i].path,
7421 dirs[ndirs - 1].length) == 0)
7423 /* Same directory as last entry. */
7424 files[i].dir_idx = ndirs - 1;
7425 ++dirs[ndirs - 1].count;
7431 /* This is a new directory. */
7432 dirs[ndirs].path = files[i].path;
7433 dirs[ndirs].length = files[i].fname - files[i].path;
7434 dirs[ndirs].count = 1;
7435 dirs[ndirs].dir_idx = ndirs;
7436 dirs[ndirs].used = 0;
7437 files[i].dir_idx = ndirs;
7439 /* Search for a prefix. */
7440 dirs[ndirs].prefix = -1;
7441 for (j = 0; j < ndirs; j++)
7442 if (dirs[j].length < dirs[ndirs].length
7443 && dirs[j].length > 1
7444 && (dirs[ndirs].prefix == -1
7445 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
7446 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
7447 dirs[ndirs].prefix = j;
7452 /* Now to the actual work. We have to find a subset of the directories which
7453 allow expressing the file name using references to the directory table
7454 with the least amount of characters. We do not do an exhaustive search
7455 where we would have to check out every combination of every single
7456 possible prefix. Instead we use a heuristic which provides nearly optimal
7457 results in most cases and never is much off. */
7458 saved = alloca (ndirs * sizeof (int));
7459 savehere = alloca (ndirs * sizeof (int));
7461 memset (saved, '\0', ndirs * sizeof (saved[0]));
7462 for (i = 0; i < ndirs; i++)
7467 /* We can always save some space for the current directory. But this
7468 does not mean it will be enough to justify adding the directory. */
7469 savehere[i] = dirs[i].length;
7470 total = (savehere[i] - saved[i]) * dirs[i].count;
7472 for (j = i + 1; j < ndirs; j++)
7475 if (saved[j] < dirs[i].length)
7477 /* Determine whether the dirs[i] path is a prefix of the
7482 while (k != -1 && k != (int) i)
7487 /* Yes it is. We can possibly safe some memory but
7488 writing the filenames in dirs[j] relative to
7490 savehere[j] = dirs[i].length;
7491 total += (savehere[j] - saved[j]) * dirs[j].count;
7496 /* Check whether we can safe enough to justify adding the dirs[i]
7498 if (total > dirs[i].length + 1)
7500 /* It's worthwhile adding. */
7501 for (j = i; j < ndirs; j++)
7502 if (savehere[j] > 0)
7504 /* Remember how much we saved for this directory so far. */
7505 saved[j] = savehere[j];
7507 /* Remember the prefix directory. */
7508 dirs[j].dir_idx = i;
7513 /* We have to emit them in the order they appear in the file_table array
7514 since the index is used in the debug info generation. To do this
7515 efficiently we generate a back-mapping of the indices first. */
7516 backmap = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (int));
7517 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7519 backmap[files[i].file_idx] = i;
7521 /* Mark this directory as used. */
7522 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
7525 /* That was it. We are ready to emit the information. First emit the
7526 directory name table. We have to make sure the first actually emitted
7527 directory name has index one; zero is reserved for the current working
7528 directory. Make sure we do not confuse these indices with the one for the
7529 constructed table (even though most of the time they are identical). */
7531 idx_offset = dirs[0].length > 0 ? 1 : 0;
7532 for (i = 1 - idx_offset; i < ndirs; i++)
7533 if (dirs[i].used != 0)
7535 dirs[i].used = idx++;
7536 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
7537 "Directory Entry: 0x%x", dirs[i].used);
7540 dw2_asm_output_data (1, 0, "End directory table");
7542 /* Correct the index for the current working directory entry if it
7544 if (idx_offset == 0)
7547 /* Now write all the file names. */
7548 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7550 int file_idx = backmap[i];
7551 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
7553 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
7554 "File Entry: 0x%lx", (unsigned long) i);
7556 /* Include directory index. */
7557 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
7559 /* Modification time. */
7560 dw2_asm_output_data_uleb128 (0, NULL);
7562 /* File length in bytes. */
7563 dw2_asm_output_data_uleb128 (0, NULL);
7566 dw2_asm_output_data (1, 0, "End file name table");
7570 /* Output the source line number correspondence information. This
7571 information goes into the .debug_line section. */
7574 output_line_info (void)
7576 char l1[20], l2[20], p1[20], p2[20];
7577 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7578 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7581 unsigned long lt_index;
7582 unsigned long current_line;
7585 unsigned long current_file;
7586 unsigned long function;
7588 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7589 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7590 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7591 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7593 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7594 dw2_asm_output_data (4, 0xffffffff,
7595 "Initial length escape value indicating 64-bit DWARF extension");
7596 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7597 "Length of Source Line Info");
7598 ASM_OUTPUT_LABEL (asm_out_file, l1);
7600 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7601 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7602 ASM_OUTPUT_LABEL (asm_out_file, p1);
7604 /* Define the architecture-dependent minimum instruction length (in
7605 bytes). In this implementation of DWARF, this field is used for
7606 information purposes only. Since GCC generates assembly language,
7607 we have no a priori knowledge of how many instruction bytes are
7608 generated for each source line, and therefore can use only the
7609 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7610 commands. Accordingly, we fix this as `1', which is "correct
7611 enough" for all architectures, and don't let the target override. */
7612 dw2_asm_output_data (1, 1,
7613 "Minimum Instruction Length");
7615 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7616 "Default is_stmt_start flag");
7617 dw2_asm_output_data (1, DWARF_LINE_BASE,
7618 "Line Base Value (Special Opcodes)");
7619 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7620 "Line Range Value (Special Opcodes)");
7621 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7622 "Special Opcode Base");
7624 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7628 case DW_LNS_advance_pc:
7629 case DW_LNS_advance_line:
7630 case DW_LNS_set_file:
7631 case DW_LNS_set_column:
7632 case DW_LNS_fixed_advance_pc:
7640 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7644 /* Write out the information about the files we use. */
7645 output_file_names ();
7646 ASM_OUTPUT_LABEL (asm_out_file, p2);
7648 /* We used to set the address register to the first location in the text
7649 section here, but that didn't accomplish anything since we already
7650 have a line note for the opening brace of the first function. */
7652 /* Generate the line number to PC correspondence table, encoded as
7653 a series of state machine operations. */
7656 strcpy (prev_line_label, text_section_label);
7657 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7659 dw_line_info_ref line_info = &line_info_table[lt_index];
7662 /* Disable this optimization for now; GDB wants to see two line notes
7663 at the beginning of a function so it can find the end of the
7666 /* Don't emit anything for redundant notes. Just updating the
7667 address doesn't accomplish anything, because we already assume
7668 that anything after the last address is this line. */
7669 if (line_info->dw_line_num == current_line
7670 && line_info->dw_file_num == current_file)
7674 /* Emit debug info for the address of the current line.
7676 Unfortunately, we have little choice here currently, and must always
7677 use the most general form. GCC does not know the address delta
7678 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7679 attributes which will give an upper bound on the address range. We
7680 could perhaps use length attributes to determine when it is safe to
7681 use DW_LNS_fixed_advance_pc. */
7683 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7686 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7687 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7688 "DW_LNS_fixed_advance_pc");
7689 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7693 /* This can handle any delta. This takes
7694 4+DWARF2_ADDR_SIZE bytes. */
7695 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7696 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7697 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7698 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7701 strcpy (prev_line_label, line_label);
7703 /* Emit debug info for the source file of the current line, if
7704 different from the previous line. */
7705 if (line_info->dw_file_num != current_file)
7707 current_file = line_info->dw_file_num;
7708 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7709 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7710 VARRAY_CHAR_PTR (file_table,
7714 /* Emit debug info for the current line number, choosing the encoding
7715 that uses the least amount of space. */
7716 if (line_info->dw_line_num != current_line)
7718 line_offset = line_info->dw_line_num - current_line;
7719 line_delta = line_offset - DWARF_LINE_BASE;
7720 current_line = line_info->dw_line_num;
7721 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7722 /* This can handle deltas from -10 to 234, using the current
7723 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7725 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7726 "line %lu", current_line);
7729 /* This can handle any delta. This takes at least 4 bytes,
7730 depending on the value being encoded. */
7731 dw2_asm_output_data (1, DW_LNS_advance_line,
7732 "advance to line %lu", current_line);
7733 dw2_asm_output_data_sleb128 (line_offset, NULL);
7734 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7738 /* We still need to start a new row, so output a copy insn. */
7739 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7742 /* Emit debug info for the address of the end of the function. */
7745 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7746 "DW_LNS_fixed_advance_pc");
7747 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7751 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7752 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7753 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7754 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7757 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7758 dw2_asm_output_data_uleb128 (1, NULL);
7759 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7764 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7766 dw_separate_line_info_ref line_info
7767 = &separate_line_info_table[lt_index];
7770 /* Don't emit anything for redundant notes. */
7771 if (line_info->dw_line_num == current_line
7772 && line_info->dw_file_num == current_file
7773 && line_info->function == function)
7777 /* Emit debug info for the address of the current line. If this is
7778 a new function, or the first line of a function, then we need
7779 to handle it differently. */
7780 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7782 if (function != line_info->function)
7784 function = line_info->function;
7786 /* Set the address register to the first line in the function. */
7787 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7788 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7789 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7790 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7794 /* ??? See the DW_LNS_advance_pc comment above. */
7797 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7798 "DW_LNS_fixed_advance_pc");
7799 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7803 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7804 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7805 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7806 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7810 strcpy (prev_line_label, line_label);
7812 /* Emit debug info for the source file of the current line, if
7813 different from the previous line. */
7814 if (line_info->dw_file_num != current_file)
7816 current_file = line_info->dw_file_num;
7817 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7818 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7819 VARRAY_CHAR_PTR (file_table,
7823 /* Emit debug info for the current line number, choosing the encoding
7824 that uses the least amount of space. */
7825 if (line_info->dw_line_num != current_line)
7827 line_offset = line_info->dw_line_num - current_line;
7828 line_delta = line_offset - DWARF_LINE_BASE;
7829 current_line = line_info->dw_line_num;
7830 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7831 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7832 "line %lu", current_line);
7835 dw2_asm_output_data (1, DW_LNS_advance_line,
7836 "advance to line %lu", current_line);
7837 dw2_asm_output_data_sleb128 (line_offset, NULL);
7838 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7842 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7850 /* If we're done with a function, end its sequence. */
7851 if (lt_index == separate_line_info_table_in_use
7852 || separate_line_info_table[lt_index].function != function)
7857 /* Emit debug info for the address of the end of the function. */
7858 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7861 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7862 "DW_LNS_fixed_advance_pc");
7863 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7867 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7868 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7869 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7870 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7873 /* Output the marker for the end of this sequence. */
7874 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7875 dw2_asm_output_data_uleb128 (1, NULL);
7876 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7880 /* Output the marker for the end of the line number info. */
7881 ASM_OUTPUT_LABEL (asm_out_file, l2);
7884 /* Given a pointer to a tree node for some base type, return a pointer to
7885 a DIE that describes the given type.
7887 This routine must only be called for GCC type nodes that correspond to
7888 Dwarf base (fundamental) types. */
7891 base_type_die (tree type)
7893 dw_die_ref base_type_result;
7894 const char *type_name;
7895 enum dwarf_type encoding;
7896 tree name = TYPE_NAME (type);
7898 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7903 if (TREE_CODE (name) == TYPE_DECL)
7904 name = DECL_NAME (name);
7906 type_name = IDENTIFIER_POINTER (name);
7909 type_name = "__unknown__";
7911 switch (TREE_CODE (type))
7914 /* Carefully distinguish the C character types, without messing
7915 up if the language is not C. Note that we check only for the names
7916 that contain spaces; other names might occur by coincidence in other
7918 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7919 && (type == char_type_node
7920 || ! strcmp (type_name, "signed char")
7921 || ! strcmp (type_name, "unsigned char"))))
7923 if (TYPE_UNSIGNED (type))
7924 encoding = DW_ATE_unsigned;
7926 encoding = DW_ATE_signed;
7929 /* else fall through. */
7932 /* GNU Pascal/Ada CHAR type. Not used in C. */
7933 if (TYPE_UNSIGNED (type))
7934 encoding = DW_ATE_unsigned_char;
7936 encoding = DW_ATE_signed_char;
7940 encoding = DW_ATE_float;
7943 /* Dwarf2 doesn't know anything about complex ints, so use
7944 a user defined type for it. */
7946 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7947 encoding = DW_ATE_complex_float;
7949 encoding = DW_ATE_lo_user;
7953 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7954 encoding = DW_ATE_boolean;
7958 /* No other TREE_CODEs are Dwarf fundamental types. */
7962 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
7963 if (demangle_name_func)
7964 type_name = (*demangle_name_func) (type_name);
7966 add_AT_string (base_type_result, DW_AT_name, type_name);
7967 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7968 int_size_in_bytes (type));
7969 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7971 return base_type_result;
7974 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7975 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7976 a given type is generally the same as the given type, except that if the
7977 given type is a pointer or reference type, then the root type of the given
7978 type is the root type of the "basis" type for the pointer or reference
7979 type. (This definition of the "root" type is recursive.) Also, the root
7980 type of a `const' qualified type or a `volatile' qualified type is the
7981 root type of the given type without the qualifiers. */
7984 root_type (tree type)
7986 if (TREE_CODE (type) == ERROR_MARK)
7987 return error_mark_node;
7989 switch (TREE_CODE (type))
7992 return error_mark_node;
7995 case REFERENCE_TYPE:
7996 return type_main_variant (root_type (TREE_TYPE (type)));
7999 return type_main_variant (type);
8003 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8004 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8007 is_base_type (tree type)
8009 switch (TREE_CODE (type))
8024 case QUAL_UNION_TYPE:
8029 case REFERENCE_TYPE:
8043 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8044 node, return the size in bits for the type if it is a constant, or else
8045 return the alignment for the type if the type's size is not constant, or
8046 else return BITS_PER_WORD if the type actually turns out to be an
8049 static inline unsigned HOST_WIDE_INT
8050 simple_type_size_in_bits (tree type)
8052 if (TREE_CODE (type) == ERROR_MARK)
8053 return BITS_PER_WORD;
8054 else if (TYPE_SIZE (type) == NULL_TREE)
8056 else if (host_integerp (TYPE_SIZE (type), 1))
8057 return tree_low_cst (TYPE_SIZE (type), 1);
8059 return TYPE_ALIGN (type);
8062 /* Return true if the debug information for the given type should be
8063 emitted as a subrange type. */
8066 is_subrange_type (tree type)
8068 tree subtype = TREE_TYPE (type);
8070 /* Subrange types are identified by the fact that they are integer
8071 types, and that they have a subtype which is either an integer type
8072 or an enumeral type. */
8074 if (TREE_CODE (type) != INTEGER_TYPE
8075 || subtype == NULL_TREE)
8078 if (TREE_CODE (subtype) != INTEGER_TYPE
8079 && TREE_CODE (subtype) != ENUMERAL_TYPE)
8082 if (TREE_CODE (type) == TREE_CODE (subtype)
8083 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
8084 && TYPE_MIN_VALUE (type) != NULL
8085 && TYPE_MIN_VALUE (subtype) != NULL
8086 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
8087 && TYPE_MAX_VALUE (type) != NULL
8088 && TYPE_MAX_VALUE (subtype) != NULL
8089 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
8091 /* The type and its subtype have the same representation. If in
8092 addition the two types also have the same name, then the given
8093 type is not a subrange type, but rather a plain base type. */
8094 /* FIXME: brobecker/2004-03-22:
8095 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8096 therefore be sufficient to check the TYPE_SIZE node pointers
8097 rather than checking the actual size. Unfortunately, we have
8098 found some cases, such as in the Ada "integer" type, where
8099 this is not the case. Until this problem is solved, we need to
8100 keep checking the actual size. */
8101 tree type_name = TYPE_NAME (type);
8102 tree subtype_name = TYPE_NAME (subtype);
8104 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
8105 type_name = DECL_NAME (type_name);
8107 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
8108 subtype_name = DECL_NAME (subtype_name);
8110 if (type_name == subtype_name)
8117 /* Given a pointer to a tree node for a subrange type, return a pointer
8118 to a DIE that describes the given type. */
8121 subrange_type_die (tree type, dw_die_ref context_die)
8123 dw_die_ref subtype_die;
8124 dw_die_ref subrange_die;
8125 tree name = TYPE_NAME (type);
8126 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
8127 tree subtype = TREE_TYPE (type);
8129 if (context_die == NULL)
8130 context_die = comp_unit_die;
8132 if (TREE_CODE (subtype) == ENUMERAL_TYPE)
8133 subtype_die = gen_enumeration_type_die (subtype, context_die);
8135 subtype_die = base_type_die (subtype);
8137 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
8141 if (TREE_CODE (name) == TYPE_DECL)
8142 name = DECL_NAME (name);
8143 add_name_attribute (subrange_die, IDENTIFIER_POINTER (name));
8146 if (int_size_in_bytes (subtype) != size_in_bytes)
8148 /* The size of the subrange type and its base type do not match,
8149 so we need to generate a size attribute for the subrange type. */
8150 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
8153 if (TYPE_MIN_VALUE (type) != NULL)
8154 add_bound_info (subrange_die, DW_AT_lower_bound,
8155 TYPE_MIN_VALUE (type));
8156 if (TYPE_MAX_VALUE (type) != NULL)
8157 add_bound_info (subrange_die, DW_AT_upper_bound,
8158 TYPE_MAX_VALUE (type));
8159 add_AT_die_ref (subrange_die, DW_AT_type, subtype_die);
8161 return subrange_die;
8164 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8165 entry that chains various modifiers in front of the given type. */
8168 modified_type_die (tree type, int is_const_type, int is_volatile_type,
8169 dw_die_ref context_die)
8171 enum tree_code code = TREE_CODE (type);
8172 dw_die_ref mod_type_die = NULL;
8173 dw_die_ref sub_die = NULL;
8174 tree item_type = NULL;
8176 if (code != ERROR_MARK)
8178 tree qualified_type;
8180 /* See if we already have the appropriately qualified variant of
8183 = get_qualified_type (type,
8184 ((is_const_type ? TYPE_QUAL_CONST : 0)
8186 ? TYPE_QUAL_VOLATILE : 0)));
8188 /* If we do, then we can just use its DIE, if it exists. */
8191 mod_type_die = lookup_type_die (qualified_type);
8193 return mod_type_die;
8196 /* Handle C typedef types. */
8197 if (qualified_type && TYPE_NAME (qualified_type)
8198 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
8199 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
8201 tree type_name = TYPE_NAME (qualified_type);
8202 tree dtype = TREE_TYPE (type_name);
8204 if (qualified_type == dtype)
8206 /* For a named type, use the typedef. */
8207 gen_type_die (qualified_type, context_die);
8208 mod_type_die = lookup_type_die (qualified_type);
8210 else if (is_const_type < TYPE_READONLY (dtype)
8211 || is_volatile_type < TYPE_VOLATILE (dtype))
8212 /* cv-unqualified version of named type. Just use the unnamed
8213 type to which it refers. */
8215 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
8216 is_const_type, is_volatile_type,
8219 /* Else cv-qualified version of named type; fall through. */
8225 else if (is_const_type)
8227 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
8228 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
8230 else if (is_volatile_type)
8232 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
8233 sub_die = modified_type_die (type, 0, 0, context_die);
8235 else if (code == POINTER_TYPE)
8237 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
8238 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8239 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8241 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
8243 item_type = TREE_TYPE (type);
8245 else if (code == REFERENCE_TYPE)
8247 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
8248 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8249 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8251 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
8253 item_type = TREE_TYPE (type);
8255 else if (is_subrange_type (type))
8256 mod_type_die = subrange_type_die (type, context_die);
8257 else if (is_base_type (type))
8258 mod_type_die = base_type_die (type);
8261 gen_type_die (type, context_die);
8263 /* We have to get the type_main_variant here (and pass that to the
8264 `lookup_type_die' routine) because the ..._TYPE node we have
8265 might simply be a *copy* of some original type node (where the
8266 copy was created to help us keep track of typedef names) and
8267 that copy might have a different TYPE_UID from the original
8269 if (TREE_CODE (type) != VECTOR_TYPE)
8270 mod_type_die = lookup_type_die (type_main_variant (type));
8272 /* Vectors have the debugging information in the type,
8273 not the main variant. */
8274 mod_type_die = lookup_type_die (type);
8275 gcc_assert (mod_type_die);
8278 /* We want to equate the qualified type to the die below. */
8279 type = qualified_type;
8283 equate_type_number_to_die (type, mod_type_die);
8285 /* We must do this after the equate_type_number_to_die call, in case
8286 this is a recursive type. This ensures that the modified_type_die
8287 recursion will terminate even if the type is recursive. Recursive
8288 types are possible in Ada. */
8289 sub_die = modified_type_die (item_type,
8290 TYPE_READONLY (item_type),
8291 TYPE_VOLATILE (item_type),
8294 if (sub_die != NULL)
8295 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
8297 return mod_type_die;
8300 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8301 an enumerated type. */
8304 type_is_enum (tree type)
8306 return TREE_CODE (type) == ENUMERAL_TYPE;
8309 /* Return the DBX register number described by a given RTL node. */
8312 dbx_reg_number (rtx rtl)
8314 unsigned regno = REGNO (rtl);
8316 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
8318 return DBX_REGISTER_NUMBER (regno);
8321 /* Return a location descriptor that designates a machine register or
8322 zero if there is none. */
8324 static dw_loc_descr_ref
8325 reg_loc_descriptor (rtx rtl)
8330 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
8333 reg = dbx_reg_number (rtl);
8334 regs = targetm.dwarf_register_span (rtl);
8336 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1
8338 return multiple_reg_loc_descriptor (rtl, regs);
8340 return one_reg_loc_descriptor (reg);
8343 /* Return a location descriptor that designates a machine register for
8344 a given hard register number. */
8346 static dw_loc_descr_ref
8347 one_reg_loc_descriptor (unsigned int regno)
8350 return new_loc_descr (DW_OP_reg0 + regno, 0, 0);
8352 return new_loc_descr (DW_OP_regx, regno, 0);
8355 /* Given an RTL of a register, return a location descriptor that
8356 designates a value that spans more than one register. */
8358 static dw_loc_descr_ref
8359 multiple_reg_loc_descriptor (rtx rtl, rtx regs)
8363 dw_loc_descr_ref loc_result = NULL;
8365 reg = dbx_reg_number (rtl);
8366 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
8368 /* Simple, contiguous registers. */
8369 if (regs == NULL_RTX)
8371 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
8378 t = one_reg_loc_descriptor (reg);
8379 add_loc_descr (&loc_result, t);
8380 add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0));
8386 /* Now onto stupid register sets in non contiguous locations. */
8388 gcc_assert (GET_CODE (regs) == PARALLEL);
8390 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8393 for (i = 0; i < XVECLEN (regs, 0); ++i)
8397 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)));
8398 add_loc_descr (&loc_result, t);
8399 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8400 add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0));
8405 /* Return a location descriptor that designates a constant. */
8407 static dw_loc_descr_ref
8408 int_loc_descriptor (HOST_WIDE_INT i)
8410 enum dwarf_location_atom op;
8412 /* Pick the smallest representation of a constant, rather than just
8413 defaulting to the LEB encoding. */
8417 op = DW_OP_lit0 + i;
8420 else if (i <= 0xffff)
8422 else if (HOST_BITS_PER_WIDE_INT == 32
8432 else if (i >= -0x8000)
8434 else if (HOST_BITS_PER_WIDE_INT == 32
8435 || i >= -0x80000000)
8441 return new_loc_descr (op, i, 0);
8444 /* Return a location descriptor that designates a base+offset location. */
8446 static dw_loc_descr_ref
8447 based_loc_descr (unsigned int reg, HOST_WIDE_INT offset, bool can_use_fbreg)
8449 dw_loc_descr_ref loc_result;
8450 /* For the "frame base", we use the frame pointer or stack pointer
8451 registers, since the RTL for local variables is relative to one of
8453 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
8454 ? HARD_FRAME_POINTER_REGNUM
8455 : STACK_POINTER_REGNUM);
8457 if (reg == fp_reg && can_use_fbreg)
8458 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
8460 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
8462 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
8467 /* Return true if this RTL expression describes a base+offset calculation. */
8470 is_based_loc (rtx rtl)
8472 return (GET_CODE (rtl) == PLUS
8473 && ((REG_P (XEXP (rtl, 0))
8474 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
8475 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
8478 /* The following routine converts the RTL for a variable or parameter
8479 (resident in memory) into an equivalent Dwarf representation of a
8480 mechanism for getting the address of that same variable onto the top of a
8481 hypothetical "address evaluation" stack.
8483 When creating memory location descriptors, we are effectively transforming
8484 the RTL for a memory-resident object into its Dwarf postfix expression
8485 equivalent. This routine recursively descends an RTL tree, turning
8486 it into Dwarf postfix code as it goes.
8488 MODE is the mode of the memory reference, needed to handle some
8489 autoincrement addressing modes.
8491 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the location
8492 list for RTL. We can't use it when we are emitting location list for
8493 virtual variable frame_base_decl (i.e. a location list for DW_AT_frame_base)
8494 which describes how frame base changes when !frame_pointer_needed.
8496 Return 0 if we can't represent the location. */
8498 static dw_loc_descr_ref
8499 mem_loc_descriptor (rtx rtl, enum machine_mode mode, bool can_use_fbreg)
8501 dw_loc_descr_ref mem_loc_result = NULL;
8502 enum dwarf_location_atom op;
8504 /* Note that for a dynamically sized array, the location we will generate a
8505 description of here will be the lowest numbered location which is
8506 actually within the array. That's *not* necessarily the same as the
8507 zeroth element of the array. */
8509 rtl = targetm.delegitimize_address (rtl);
8511 switch (GET_CODE (rtl))
8516 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8517 just fall into the SUBREG code. */
8519 /* ... fall through ... */
8522 /* The case of a subreg may arise when we have a local (register)
8523 variable or a formal (register) parameter which doesn't quite fill
8524 up an entire register. For now, just assume that it is
8525 legitimate to make the Dwarf info refer to the whole register which
8526 contains the given subreg. */
8527 rtl = SUBREG_REG (rtl);
8529 /* ... fall through ... */
8532 /* Whenever a register number forms a part of the description of the
8533 method for calculating the (dynamic) address of a memory resident
8534 object, DWARF rules require the register number be referred to as
8535 a "base register". This distinction is not based in any way upon
8536 what category of register the hardware believes the given register
8537 belongs to. This is strictly DWARF terminology we're dealing with
8538 here. Note that in cases where the location of a memory-resident
8539 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8540 OP_CONST (0)) the actual DWARF location descriptor that we generate
8541 may just be OP_BASEREG (basereg). This may look deceptively like
8542 the object in question was allocated to a register (rather than in
8543 memory) so DWARF consumers need to be aware of the subtle
8544 distinction between OP_REG and OP_BASEREG. */
8545 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
8546 mem_loc_result = based_loc_descr (dbx_reg_number (rtl), 0,
8551 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
8553 if (mem_loc_result != 0)
8554 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
8558 rtl = XEXP (rtl, 1);
8560 /* ... fall through ... */
8563 /* Some ports can transform a symbol ref into a label ref, because
8564 the symbol ref is too far away and has to be dumped into a constant
8568 /* Alternatively, the symbol in the constant pool might be referenced
8569 by a different symbol. */
8570 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
8573 rtx tmp = get_pool_constant_mark (rtl, &marked);
8575 if (GET_CODE (tmp) == SYMBOL_REF)
8578 if (CONSTANT_POOL_ADDRESS_P (tmp))
8579 get_pool_constant_mark (tmp, &marked);
8584 /* If all references to this pool constant were optimized away,
8585 it was not output and thus we can't represent it.
8586 FIXME: might try to use DW_OP_const_value here, though
8587 DW_OP_piece complicates it. */
8592 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
8593 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
8594 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
8595 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
8599 /* Extract the PLUS expression nested inside and fall into
8601 rtl = XEXP (rtl, 1);
8606 /* Turn these into a PLUS expression and fall into the PLUS code
8608 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
8609 GEN_INT (GET_CODE (rtl) == PRE_INC
8610 ? GET_MODE_UNIT_SIZE (mode)
8611 : -GET_MODE_UNIT_SIZE (mode)));
8613 /* ... fall through ... */
8617 if (is_based_loc (rtl))
8618 mem_loc_result = based_loc_descr (dbx_reg_number (XEXP (rtl, 0)),
8619 INTVAL (XEXP (rtl, 1)),
8623 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
8625 if (mem_loc_result == 0)
8628 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
8629 && INTVAL (XEXP (rtl, 1)) >= 0)
8630 add_loc_descr (&mem_loc_result,
8631 new_loc_descr (DW_OP_plus_uconst,
8632 INTVAL (XEXP (rtl, 1)), 0));
8635 add_loc_descr (&mem_loc_result,
8636 mem_loc_descriptor (XEXP (rtl, 1), mode,
8638 add_loc_descr (&mem_loc_result,
8639 new_loc_descr (DW_OP_plus, 0, 0));
8644 /* If a pseudo-reg is optimized away, it is possible for it to
8645 be replaced with a MEM containing a multiply or shift. */
8664 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
8666 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
8669 if (op0 == 0 || op1 == 0)
8672 mem_loc_result = op0;
8673 add_loc_descr (&mem_loc_result, op1);
8674 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
8679 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
8686 return mem_loc_result;
8689 /* Return a descriptor that describes the concatenation of two locations.
8690 This is typically a complex variable. */
8692 static dw_loc_descr_ref
8693 concat_loc_descriptor (rtx x0, rtx x1)
8695 dw_loc_descr_ref cc_loc_result = NULL;
8696 dw_loc_descr_ref x0_ref = loc_descriptor (x0, true);
8697 dw_loc_descr_ref x1_ref = loc_descriptor (x1, true);
8699 if (x0_ref == 0 || x1_ref == 0)
8702 cc_loc_result = x0_ref;
8703 add_loc_descr (&cc_loc_result,
8704 new_loc_descr (DW_OP_piece,
8705 GET_MODE_SIZE (GET_MODE (x0)), 0));
8707 add_loc_descr (&cc_loc_result, x1_ref);
8708 add_loc_descr (&cc_loc_result,
8709 new_loc_descr (DW_OP_piece,
8710 GET_MODE_SIZE (GET_MODE (x1)), 0));
8712 return cc_loc_result;
8715 /* Output a proper Dwarf location descriptor for a variable or parameter
8716 which is either allocated in a register or in a memory location. For a
8717 register, we just generate an OP_REG and the register number. For a
8718 memory location we provide a Dwarf postfix expression describing how to
8719 generate the (dynamic) address of the object onto the address stack.
8721 If we don't know how to describe it, return 0. */
8723 static dw_loc_descr_ref
8724 loc_descriptor (rtx rtl, bool can_use_fbreg)
8726 dw_loc_descr_ref loc_result = NULL;
8728 switch (GET_CODE (rtl))
8731 /* The case of a subreg may arise when we have a local (register)
8732 variable or a formal (register) parameter which doesn't quite fill
8733 up an entire register. For now, just assume that it is
8734 legitimate to make the Dwarf info refer to the whole register which
8735 contains the given subreg. */
8736 rtl = SUBREG_REG (rtl);
8738 /* ... fall through ... */
8741 loc_result = reg_loc_descriptor (rtl);
8745 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
8750 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8755 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
8757 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), can_use_fbreg);
8761 rtl = XEXP (rtl, 1);
8766 rtvec par_elems = XVEC (rtl, 0);
8767 int num_elem = GET_NUM_ELEM (par_elems);
8768 enum machine_mode mode;
8771 /* Create the first one, so we have something to add to. */
8772 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
8774 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
8775 add_loc_descr (&loc_result,
8776 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (mode), 0));
8777 for (i = 1; i < num_elem; i++)
8779 dw_loc_descr_ref temp;
8781 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
8783 add_loc_descr (&loc_result, temp);
8784 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
8785 add_loc_descr (&loc_result,
8786 new_loc_descr (DW_OP_piece,
8787 GET_MODE_SIZE (mode), 0));
8799 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8800 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
8801 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
8802 top-level invocation, and we require the address of LOC; is 0 if we require
8803 the value of LOC. */
8805 static dw_loc_descr_ref
8806 loc_descriptor_from_tree_1 (tree loc, int want_address)
8808 dw_loc_descr_ref ret, ret1;
8809 int have_address = 0;
8810 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
8811 enum dwarf_location_atom op;
8813 /* ??? Most of the time we do not take proper care for sign/zero
8814 extending the values properly. Hopefully this won't be a real
8817 switch (TREE_CODE (loc))
8822 case PLACEHOLDER_EXPR:
8823 /* This case involves extracting fields from an object to determine the
8824 position of other fields. We don't try to encode this here. The
8825 only user of this is Ada, which encodes the needed information using
8826 the names of types. */
8832 case PREINCREMENT_EXPR:
8833 case PREDECREMENT_EXPR:
8834 case POSTINCREMENT_EXPR:
8835 case POSTDECREMENT_EXPR:
8836 /* There are no opcodes for these operations. */
8840 /* If we already want an address, there's nothing we can do. */
8844 /* Otherwise, process the argument and look for the address. */
8845 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
8848 if (DECL_THREAD_LOCAL (loc))
8852 #ifndef ASM_OUTPUT_DWARF_DTPREL
8853 /* If this is not defined, we have no way to emit the data. */
8857 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8858 look up addresses of objects in the current module. */
8859 if (DECL_EXTERNAL (loc))
8862 rtl = rtl_for_decl_location (loc);
8863 if (rtl == NULL_RTX)
8868 rtl = XEXP (rtl, 0);
8869 if (! CONSTANT_P (rtl))
8872 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
8873 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8874 ret->dw_loc_oprnd1.v.val_addr = rtl;
8876 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
8877 add_loc_descr (&ret, ret1);
8885 if (DECL_VALUE_EXPR (loc))
8886 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc), want_address);
8891 rtx rtl = rtl_for_decl_location (loc);
8893 if (rtl == NULL_RTX)
8895 else if (GET_CODE (rtl) == CONST_INT)
8897 HOST_WIDE_INT val = INTVAL (rtl);
8898 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
8899 val &= GET_MODE_MASK (DECL_MODE (loc));
8900 ret = int_loc_descriptor (val);
8902 else if (GET_CODE (rtl) == CONST_STRING)
8904 else if (CONSTANT_P (rtl))
8906 ret = new_loc_descr (DW_OP_addr, 0, 0);
8907 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8908 ret->dw_loc_oprnd1.v.val_addr = rtl;
8912 enum machine_mode mode;
8914 /* Certain constructs can only be represented at top-level. */
8915 if (want_address == 2)
8916 return loc_descriptor (rtl, true);
8918 mode = GET_MODE (rtl);
8921 rtl = XEXP (rtl, 0);
8924 ret = mem_loc_descriptor (rtl, mode, true);
8930 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
8935 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
8939 case NON_LVALUE_EXPR:
8940 case VIEW_CONVERT_EXPR:
8943 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
8948 case ARRAY_RANGE_REF:
8951 HOST_WIDE_INT bitsize, bitpos, bytepos;
8952 enum machine_mode mode;
8955 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8956 &unsignedp, &volatilep);
8961 ret = loc_descriptor_from_tree_1 (obj, 1);
8963 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
8966 if (offset != NULL_TREE)
8968 /* Variable offset. */
8969 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
8970 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8973 bytepos = bitpos / BITS_PER_UNIT;
8975 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8976 else if (bytepos < 0)
8978 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8979 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8987 if (host_integerp (loc, 0))
8988 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8995 /* Get an RTL for this, if something has been emitted. */
8996 rtx rtl = lookup_constant_def (loc);
8997 enum machine_mode mode;
8999 if (!rtl || !MEM_P (rtl))
9001 mode = GET_MODE (rtl);
9002 rtl = XEXP (rtl, 0);
9003 ret = mem_loc_descriptor (rtl, mode, true);
9008 case TRUTH_AND_EXPR:
9009 case TRUTH_ANDIF_EXPR:
9014 case TRUTH_XOR_EXPR:
9020 case TRUTH_ORIF_EXPR:
9025 case FLOOR_DIV_EXPR:
9027 case ROUND_DIV_EXPR:
9028 case TRUNC_DIV_EXPR:
9036 case FLOOR_MOD_EXPR:
9038 case ROUND_MOD_EXPR:
9039 case TRUNC_MOD_EXPR:
9052 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
9056 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
9057 && host_integerp (TREE_OPERAND (loc, 1), 0))
9059 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9063 add_loc_descr (&ret,
9064 new_loc_descr (DW_OP_plus_uconst,
9065 tree_low_cst (TREE_OPERAND (loc, 1),
9075 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9082 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9089 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9096 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9111 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9112 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9113 if (ret == 0 || ret1 == 0)
9116 add_loc_descr (&ret, ret1);
9117 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9120 case TRUTH_NOT_EXPR:
9134 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9138 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9144 const enum tree_code code =
9145 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
9147 loc = build3 (COND_EXPR, TREE_TYPE (loc),
9148 build2 (code, integer_type_node,
9149 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
9150 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
9153 /* ... fall through ... */
9157 dw_loc_descr_ref lhs
9158 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9159 dw_loc_descr_ref rhs
9160 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
9161 dw_loc_descr_ref bra_node, jump_node, tmp;
9163 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9164 if (ret == 0 || lhs == 0 || rhs == 0)
9167 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
9168 add_loc_descr (&ret, bra_node);
9170 add_loc_descr (&ret, rhs);
9171 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
9172 add_loc_descr (&ret, jump_node);
9174 add_loc_descr (&ret, lhs);
9175 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9176 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
9178 /* ??? Need a node to point the skip at. Use a nop. */
9179 tmp = new_loc_descr (DW_OP_nop, 0, 0);
9180 add_loc_descr (&ret, tmp);
9181 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9182 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
9186 case FIX_TRUNC_EXPR:
9188 case FIX_FLOOR_EXPR:
9189 case FIX_ROUND_EXPR:
9193 /* Leave front-end specific codes as simply unknown. This comes
9194 up, for instance, with the C STMT_EXPR. */
9195 if ((unsigned int) TREE_CODE (loc)
9196 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
9199 #ifdef ENABLE_CHECKING
9200 /* Otherwise this is a generic code; we should just lists all of
9201 these explicitly. Aborting means we forgot one. */
9204 /* In a release build, we want to degrade gracefully: better to
9205 generate incomplete debugging information than to crash. */
9210 /* Show if we can't fill the request for an address. */
9211 if (want_address && !have_address)
9214 /* If we've got an address and don't want one, dereference. */
9215 if (!want_address && have_address)
9217 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
9219 if (size > DWARF2_ADDR_SIZE || size == -1)
9221 else if (size == DWARF2_ADDR_SIZE)
9224 op = DW_OP_deref_size;
9226 add_loc_descr (&ret, new_loc_descr (op, size, 0));
9232 static inline dw_loc_descr_ref
9233 loc_descriptor_from_tree (tree loc)
9235 return loc_descriptor_from_tree_1 (loc, 2);
9238 /* Given a value, round it up to the lowest multiple of `boundary'
9239 which is not less than the value itself. */
9241 static inline HOST_WIDE_INT
9242 ceiling (HOST_WIDE_INT value, unsigned int boundary)
9244 return (((value + boundary - 1) / boundary) * boundary);
9247 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9248 pointer to the declared type for the relevant field variable, or return
9249 `integer_type_node' if the given node turns out to be an
9253 field_type (tree decl)
9257 if (TREE_CODE (decl) == ERROR_MARK)
9258 return integer_type_node;
9260 type = DECL_BIT_FIELD_TYPE (decl);
9261 if (type == NULL_TREE)
9262 type = TREE_TYPE (decl);
9267 /* Given a pointer to a tree node, return the alignment in bits for
9268 it, or else return BITS_PER_WORD if the node actually turns out to
9269 be an ERROR_MARK node. */
9271 static inline unsigned
9272 simple_type_align_in_bits (tree type)
9274 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
9277 static inline unsigned
9278 simple_decl_align_in_bits (tree decl)
9280 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
9283 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9284 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9285 or return 0 if we are unable to determine what that offset is, either
9286 because the argument turns out to be a pointer to an ERROR_MARK node, or
9287 because the offset is actually variable. (We can't handle the latter case
9290 static HOST_WIDE_INT
9291 field_byte_offset (tree decl)
9293 unsigned int type_align_in_bits;
9294 unsigned int decl_align_in_bits;
9295 unsigned HOST_WIDE_INT type_size_in_bits;
9296 HOST_WIDE_INT object_offset_in_bits;
9298 tree field_size_tree;
9299 HOST_WIDE_INT bitpos_int;
9300 HOST_WIDE_INT deepest_bitpos;
9301 unsigned HOST_WIDE_INT field_size_in_bits;
9303 if (TREE_CODE (decl) == ERROR_MARK)
9306 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
9308 type = field_type (decl);
9309 field_size_tree = DECL_SIZE (decl);
9311 /* The size could be unspecified if there was an error, or for
9312 a flexible array member. */
9313 if (! field_size_tree)
9314 field_size_tree = bitsize_zero_node;
9316 /* We cannot yet cope with fields whose positions are variable, so
9317 for now, when we see such things, we simply return 0. Someday, we may
9318 be able to handle such cases, but it will be damn difficult. */
9319 if (! host_integerp (bit_position (decl), 0))
9322 bitpos_int = int_bit_position (decl);
9324 /* If we don't know the size of the field, pretend it's a full word. */
9325 if (host_integerp (field_size_tree, 1))
9326 field_size_in_bits = tree_low_cst (field_size_tree, 1);
9328 field_size_in_bits = BITS_PER_WORD;
9330 type_size_in_bits = simple_type_size_in_bits (type);
9331 type_align_in_bits = simple_type_align_in_bits (type);
9332 decl_align_in_bits = simple_decl_align_in_bits (decl);
9334 /* The GCC front-end doesn't make any attempt to keep track of the starting
9335 bit offset (relative to the start of the containing structure type) of the
9336 hypothetical "containing object" for a bit-field. Thus, when computing
9337 the byte offset value for the start of the "containing object" of a
9338 bit-field, we must deduce this information on our own. This can be rather
9339 tricky to do in some cases. For example, handling the following structure
9340 type definition when compiling for an i386/i486 target (which only aligns
9341 long long's to 32-bit boundaries) can be very tricky:
9343 struct S { int field1; long long field2:31; };
9345 Fortunately, there is a simple rule-of-thumb which can be used in such
9346 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
9347 structure shown above. It decides to do this based upon one simple rule
9348 for bit-field allocation. GCC allocates each "containing object" for each
9349 bit-field at the first (i.e. lowest addressed) legitimate alignment
9350 boundary (based upon the required minimum alignment for the declared type
9351 of the field) which it can possibly use, subject to the condition that
9352 there is still enough available space remaining in the containing object
9353 (when allocated at the selected point) to fully accommodate all of the
9354 bits of the bit-field itself.
9356 This simple rule makes it obvious why GCC allocates 8 bytes for each
9357 object of the structure type shown above. When looking for a place to
9358 allocate the "containing object" for `field2', the compiler simply tries
9359 to allocate a 64-bit "containing object" at each successive 32-bit
9360 boundary (starting at zero) until it finds a place to allocate that 64-
9361 bit field such that at least 31 contiguous (and previously unallocated)
9362 bits remain within that selected 64 bit field. (As it turns out, for the
9363 example above, the compiler finds it is OK to allocate the "containing
9364 object" 64-bit field at bit-offset zero within the structure type.)
9366 Here we attempt to work backwards from the limited set of facts we're
9367 given, and we try to deduce from those facts, where GCC must have believed
9368 that the containing object started (within the structure type). The value
9369 we deduce is then used (by the callers of this routine) to generate
9370 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
9371 and, in the case of DW_AT_location, regular fields as well). */
9373 /* Figure out the bit-distance from the start of the structure to the
9374 "deepest" bit of the bit-field. */
9375 deepest_bitpos = bitpos_int + field_size_in_bits;
9377 /* This is the tricky part. Use some fancy footwork to deduce where the
9378 lowest addressed bit of the containing object must be. */
9379 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
9381 /* Round up to type_align by default. This works best for bitfields. */
9382 object_offset_in_bits += type_align_in_bits - 1;
9383 object_offset_in_bits /= type_align_in_bits;
9384 object_offset_in_bits *= type_align_in_bits;
9386 if (object_offset_in_bits > bitpos_int)
9388 /* Sigh, the decl must be packed. */
9389 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
9391 /* Round up to decl_align instead. */
9392 object_offset_in_bits += decl_align_in_bits - 1;
9393 object_offset_in_bits /= decl_align_in_bits;
9394 object_offset_in_bits *= decl_align_in_bits;
9397 return object_offset_in_bits / BITS_PER_UNIT;
9400 /* The following routines define various Dwarf attributes and any data
9401 associated with them. */
9403 /* Add a location description attribute value to a DIE.
9405 This emits location attributes suitable for whole variables and
9406 whole parameters. Note that the location attributes for struct fields are
9407 generated by the routine `data_member_location_attribute' below. */
9410 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
9411 dw_loc_descr_ref descr)
9414 add_AT_loc (die, attr_kind, descr);
9417 /* Attach the specialized form of location attribute used for data members of
9418 struct and union types. In the special case of a FIELD_DECL node which
9419 represents a bit-field, the "offset" part of this special location
9420 descriptor must indicate the distance in bytes from the lowest-addressed
9421 byte of the containing struct or union type to the lowest-addressed byte of
9422 the "containing object" for the bit-field. (See the `field_byte_offset'
9425 For any given bit-field, the "containing object" is a hypothetical object
9426 (of some integral or enum type) within which the given bit-field lives. The
9427 type of this hypothetical "containing object" is always the same as the
9428 declared type of the individual bit-field itself (for GCC anyway... the
9429 DWARF spec doesn't actually mandate this). Note that it is the size (in
9430 bytes) of the hypothetical "containing object" which will be given in the
9431 DW_AT_byte_size attribute for this bit-field. (See the
9432 `byte_size_attribute' function below.) It is also used when calculating the
9433 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
9437 add_data_member_location_attribute (dw_die_ref die, tree decl)
9439 HOST_WIDE_INT offset;
9440 dw_loc_descr_ref loc_descr = 0;
9442 if (TREE_CODE (decl) == TREE_BINFO)
9444 /* We're working on the TAG_inheritance for a base class. */
9445 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
9447 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
9448 aren't at a fixed offset from all (sub)objects of the same
9449 type. We need to extract the appropriate offset from our
9450 vtable. The following dwarf expression means
9452 BaseAddr = ObAddr + *((*ObAddr) - Offset)
9454 This is specific to the V3 ABI, of course. */
9456 dw_loc_descr_ref tmp;
9458 /* Make a copy of the object address. */
9459 tmp = new_loc_descr (DW_OP_dup, 0, 0);
9460 add_loc_descr (&loc_descr, tmp);
9462 /* Extract the vtable address. */
9463 tmp = new_loc_descr (DW_OP_deref, 0, 0);
9464 add_loc_descr (&loc_descr, tmp);
9466 /* Calculate the address of the offset. */
9467 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
9468 gcc_assert (offset < 0);
9470 tmp = int_loc_descriptor (-offset);
9471 add_loc_descr (&loc_descr, tmp);
9472 tmp = new_loc_descr (DW_OP_minus, 0, 0);
9473 add_loc_descr (&loc_descr, tmp);
9475 /* Extract the offset. */
9476 tmp = new_loc_descr (DW_OP_deref, 0, 0);
9477 add_loc_descr (&loc_descr, tmp);
9479 /* Add it to the object address. */
9480 tmp = new_loc_descr (DW_OP_plus, 0, 0);
9481 add_loc_descr (&loc_descr, tmp);
9484 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
9487 offset = field_byte_offset (decl);
9491 enum dwarf_location_atom op;
9493 /* The DWARF2 standard says that we should assume that the structure
9494 address is already on the stack, so we can specify a structure field
9495 address by using DW_OP_plus_uconst. */
9497 #ifdef MIPS_DEBUGGING_INFO
9498 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9499 operator correctly. It works only if we leave the offset on the
9503 op = DW_OP_plus_uconst;
9506 loc_descr = new_loc_descr (op, offset, 0);
9509 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
9512 /* Writes integer values to dw_vec_const array. */
9515 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
9519 *dest++ = val & 0xff;
9525 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
9527 static HOST_WIDE_INT
9528 extract_int (const unsigned char *src, unsigned int size)
9530 HOST_WIDE_INT val = 0;
9536 val |= *--src & 0xff;
9542 /* Writes floating point values to dw_vec_const array. */
9545 insert_float (rtx rtl, unsigned char *array)
9551 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
9552 real_to_target (val, &rv, GET_MODE (rtl));
9554 /* real_to_target puts 32-bit pieces in each long. Pack them. */
9555 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
9557 insert_int (val[i], 4, array);
9562 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9563 does not have a "location" either in memory or in a register. These
9564 things can arise in GNU C when a constant is passed as an actual parameter
9565 to an inlined function. They can also arise in C++ where declared
9566 constants do not necessarily get memory "homes". */
9569 add_const_value_attribute (dw_die_ref die, rtx rtl)
9571 switch (GET_CODE (rtl))
9575 HOST_WIDE_INT val = INTVAL (rtl);
9578 add_AT_int (die, DW_AT_const_value, val);
9580 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
9585 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9586 floating-point constant. A CONST_DOUBLE is used whenever the
9587 constant requires more than one word in order to be adequately
9588 represented. We output CONST_DOUBLEs as blocks. */
9590 enum machine_mode mode = GET_MODE (rtl);
9592 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
9594 unsigned int length = GET_MODE_SIZE (mode);
9595 unsigned char *array = ggc_alloc (length);
9597 insert_float (rtl, array);
9598 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
9602 /* ??? We really should be using HOST_WIDE_INT throughout. */
9603 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
9605 add_AT_long_long (die, DW_AT_const_value,
9606 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
9613 enum machine_mode mode = GET_MODE (rtl);
9614 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
9615 unsigned int length = CONST_VECTOR_NUNITS (rtl);
9616 unsigned char *array = ggc_alloc (length * elt_size);
9620 switch (GET_MODE_CLASS (mode))
9622 case MODE_VECTOR_INT:
9623 for (i = 0, p = array; i < length; i++, p += elt_size)
9625 rtx elt = CONST_VECTOR_ELT (rtl, i);
9626 HOST_WIDE_INT lo, hi;
9628 switch (GET_CODE (elt))
9636 lo = CONST_DOUBLE_LOW (elt);
9637 hi = CONST_DOUBLE_HIGH (elt);
9644 if (elt_size <= sizeof (HOST_WIDE_INT))
9645 insert_int (lo, elt_size, p);
9648 unsigned char *p0 = p;
9649 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
9651 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
9652 if (WORDS_BIG_ENDIAN)
9657 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
9658 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
9663 case MODE_VECTOR_FLOAT:
9664 for (i = 0, p = array; i < length; i++, p += elt_size)
9666 rtx elt = CONST_VECTOR_ELT (rtl, i);
9667 insert_float (elt, p);
9675 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
9680 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
9686 add_AT_addr (die, DW_AT_const_value, rtl);
9687 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
9691 /* In cases where an inlined instance of an inline function is passed
9692 the address of an `auto' variable (which is local to the caller) we
9693 can get a situation where the DECL_RTL of the artificial local
9694 variable (for the inlining) which acts as a stand-in for the
9695 corresponding formal parameter (of the inline function) will look
9696 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9697 exactly a compile-time constant expression, but it isn't the address
9698 of the (artificial) local variable either. Rather, it represents the
9699 *value* which the artificial local variable always has during its
9700 lifetime. We currently have no way to represent such quasi-constant
9701 values in Dwarf, so for now we just punt and generate nothing. */
9705 /* No other kinds of rtx should be possible here. */
9712 rtl_for_decl_location (tree decl)
9716 /* Here we have to decide where we are going to say the parameter "lives"
9717 (as far as the debugger is concerned). We only have a couple of
9718 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9720 DECL_RTL normally indicates where the parameter lives during most of the
9721 activation of the function. If optimization is enabled however, this
9722 could be either NULL or else a pseudo-reg. Both of those cases indicate
9723 that the parameter doesn't really live anywhere (as far as the code
9724 generation parts of GCC are concerned) during most of the function's
9725 activation. That will happen (for example) if the parameter is never
9726 referenced within the function.
9728 We could just generate a location descriptor here for all non-NULL
9729 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
9730 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
9731 where DECL_RTL is NULL or is a pseudo-reg.
9733 Note however that we can only get away with using DECL_INCOMING_RTL as
9734 a backup substitute for DECL_RTL in certain limited cases. In cases
9735 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
9736 we can be sure that the parameter was passed using the same type as it is
9737 declared to have within the function, and that its DECL_INCOMING_RTL
9738 points us to a place where a value of that type is passed.
9740 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
9741 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
9742 because in these cases DECL_INCOMING_RTL points us to a value of some
9743 type which is *different* from the type of the parameter itself. Thus,
9744 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
9745 such cases, the debugger would end up (for example) trying to fetch a
9746 `float' from a place which actually contains the first part of a
9747 `double'. That would lead to really incorrect and confusing
9748 output at debug-time.
9750 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
9751 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
9752 are a couple of exceptions however. On little-endian machines we can
9753 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
9754 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
9755 an integral type that is smaller than TREE_TYPE (decl). These cases arise
9756 when (on a little-endian machine) a non-prototyped function has a
9757 parameter declared to be of type `short' or `char'. In such cases,
9758 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
9759 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
9760 passed `int' value. If the debugger then uses that address to fetch
9761 a `short' or a `char' (on a little-endian machine) the result will be
9762 the correct data, so we allow for such exceptional cases below.
9764 Note that our goal here is to describe the place where the given formal
9765 parameter lives during most of the function's activation (i.e. between the
9766 end of the prologue and the start of the epilogue). We'll do that as best
9767 as we can. Note however that if the given formal parameter is modified
9768 sometime during the execution of the function, then a stack backtrace (at
9769 debug-time) will show the function as having been called with the *new*
9770 value rather than the value which was originally passed in. This happens
9771 rarely enough that it is not a major problem, but it *is* a problem, and
9774 A future version of dwarf2out.c may generate two additional attributes for
9775 any given DW_TAG_formal_parameter DIE which will describe the "passed
9776 type" and the "passed location" for the given formal parameter in addition
9777 to the attributes we now generate to indicate the "declared type" and the
9778 "active location" for each parameter. This additional set of attributes
9779 could be used by debuggers for stack backtraces. Separately, note that
9780 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
9781 This happens (for example) for inlined-instances of inline function formal
9782 parameters which are never referenced. This really shouldn't be
9783 happening. All PARM_DECL nodes should get valid non-NULL
9784 DECL_INCOMING_RTL values. FIXME. */
9786 /* Use DECL_RTL as the "location" unless we find something better. */
9787 rtl = DECL_RTL_IF_SET (decl);
9789 /* When generating abstract instances, ignore everything except
9790 constants, symbols living in memory, and symbols living in
9792 if (! reload_completed)
9795 && (CONSTANT_P (rtl)
9797 && CONSTANT_P (XEXP (rtl, 0)))
9799 && TREE_CODE (decl) == VAR_DECL
9800 && TREE_STATIC (decl))))
9802 rtl = targetm.delegitimize_address (rtl);
9807 else if (TREE_CODE (decl) == PARM_DECL)
9809 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
9811 tree declared_type = TREE_TYPE (decl);
9812 tree passed_type = DECL_ARG_TYPE (decl);
9813 enum machine_mode dmode = TYPE_MODE (declared_type);
9814 enum machine_mode pmode = TYPE_MODE (passed_type);
9816 /* This decl represents a formal parameter which was optimized out.
9817 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
9818 all cases where (rtl == NULL_RTX) just below. */
9820 rtl = DECL_INCOMING_RTL (decl);
9821 else if (SCALAR_INT_MODE_P (dmode)
9822 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
9823 && DECL_INCOMING_RTL (decl))
9825 rtx inc = DECL_INCOMING_RTL (decl);
9828 else if (MEM_P (inc))
9830 if (BYTES_BIG_ENDIAN)
9831 rtl = adjust_address_nv (inc, dmode,
9832 GET_MODE_SIZE (pmode)
9833 - GET_MODE_SIZE (dmode));
9840 /* If the parm was passed in registers, but lives on the stack, then
9841 make a big endian correction if the mode of the type of the
9842 parameter is not the same as the mode of the rtl. */
9843 /* ??? This is the same series of checks that are made in dbxout.c before
9844 we reach the big endian correction code there. It isn't clear if all
9845 of these checks are necessary here, but keeping them all is the safe
9847 else if (MEM_P (rtl)
9848 && XEXP (rtl, 0) != const0_rtx
9849 && ! CONSTANT_P (XEXP (rtl, 0))
9850 /* Not passed in memory. */
9851 && !MEM_P (DECL_INCOMING_RTL (decl))
9852 /* Not passed by invisible reference. */
9853 && (!REG_P (XEXP (rtl, 0))
9854 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
9855 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
9856 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
9857 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
9860 /* Big endian correction check. */
9862 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
9863 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
9866 int offset = (UNITS_PER_WORD
9867 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
9869 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
9870 plus_constant (XEXP (rtl, 0), offset));
9873 else if (TREE_CODE (decl) == VAR_DECL
9876 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
9877 && BYTES_BIG_ENDIAN)
9879 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
9880 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
9882 /* If a variable is declared "register" yet is smaller than
9883 a register, then if we store the variable to memory, it
9884 looks like we're storing a register-sized value, when in
9885 fact we are not. We need to adjust the offset of the
9886 storage location to reflect the actual value's bytes,
9887 else gdb will not be able to display it. */
9889 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
9890 plus_constant (XEXP (rtl, 0), rsize-dsize));
9893 if (rtl != NULL_RTX)
9895 rtl = eliminate_regs (rtl, 0, NULL_RTX);
9896 #ifdef LEAF_REG_REMAP
9897 if (current_function_uses_only_leaf_regs)
9898 leaf_renumber_regs_insn (rtl);
9902 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
9903 and will have been substituted directly into all expressions that use it.
9904 C does not have such a concept, but C++ and other languages do. */
9905 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
9907 /* If a variable is initialized with a string constant without embedded
9908 zeros, build CONST_STRING. */
9909 if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
9910 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
9912 tree arrtype = TREE_TYPE (decl);
9913 tree enttype = TREE_TYPE (arrtype);
9914 tree domain = TYPE_DOMAIN (arrtype);
9915 tree init = DECL_INITIAL (decl);
9916 enum machine_mode mode = TYPE_MODE (enttype);
9918 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
9920 && integer_zerop (TYPE_MIN_VALUE (domain))
9921 && compare_tree_int (TYPE_MAX_VALUE (domain),
9922 TREE_STRING_LENGTH (init) - 1) == 0
9923 && ((size_t) TREE_STRING_LENGTH (init)
9924 == strlen (TREE_STRING_POINTER (init)) + 1))
9925 rtl = gen_rtx_CONST_STRING (VOIDmode,
9926 ggc_strdup (TREE_STRING_POINTER (init)));
9928 /* If the initializer is something that we know will expand into an
9929 immediate RTL constant, expand it now. Expanding anything else
9930 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
9931 else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST
9932 || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST)
9934 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
9935 EXPAND_INITIALIZER);
9936 /* If expand_expr returns a MEM, it wasn't immediate. */
9937 gcc_assert (!rtl || !MEM_P (rtl));
9942 rtl = targetm.delegitimize_address (rtl);
9944 /* If we don't look past the constant pool, we risk emitting a
9945 reference to a constant pool entry that isn't referenced from
9946 code, and thus is not emitted. */
9948 rtl = avoid_constant_pool_reference (rtl);
9953 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
9954 data attribute for a variable or a parameter. We generate the
9955 DW_AT_const_value attribute only in those cases where the given variable
9956 or parameter does not have a true "location" either in memory or in a
9957 register. This can happen (for example) when a constant is passed as an
9958 actual argument in a call to an inline function. (It's possible that
9959 these things can crop up in other ways also.) Note that one type of
9960 constant value which can be passed into an inlined function is a constant
9961 pointer. This can happen for example if an actual argument in an inlined
9962 function call evaluates to a compile-time constant address. */
9965 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
9966 enum dwarf_attribute attr)
9969 dw_loc_descr_ref descr;
9970 var_loc_list *loc_list;
9972 if (TREE_CODE (decl) == ERROR_MARK)
9975 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
9976 || TREE_CODE (decl) == RESULT_DECL);
9978 /* See if we possibly have multiple locations for this variable. */
9979 loc_list = lookup_decl_loc (decl);
9981 /* If it truly has multiple locations, the first and last node will
9983 if (loc_list && loc_list->first != loc_list->last)
9985 const char *secname;
9986 const char *endname;
9987 dw_loc_list_ref list;
9989 struct var_loc_node *node;
9991 /* We need to figure out what section we should use as the base
9992 for the address ranges where a given location is valid.
9993 1. If this particular DECL has a section associated with it,
9995 2. If this function has a section associated with it, use
9997 3. Otherwise, use the text section.
9998 XXX: If you split a variable across multiple sections, this
10001 if (DECL_SECTION_NAME (decl))
10003 tree sectree = DECL_SECTION_NAME (decl);
10004 secname = TREE_STRING_POINTER (sectree);
10006 else if (current_function_decl
10007 && DECL_SECTION_NAME (current_function_decl))
10009 tree sectree = DECL_SECTION_NAME (current_function_decl);
10010 secname = TREE_STRING_POINTER (sectree);
10013 secname = text_section_label;
10015 /* Now that we know what section we are using for a base,
10016 actually construct the list of locations.
10017 The first location information is what is passed to the
10018 function that creates the location list, and the remaining
10019 locations just get added on to that list.
10020 Note that we only know the start address for a location
10021 (IE location changes), so to build the range, we use
10022 the range [current location start, next location start].
10023 This means we have to special case the last node, and generate
10024 a range of [last location start, end of function label]. */
10026 node = loc_list->first;
10027 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10028 list = new_loc_list (loc_descriptor (varloc, attr != DW_AT_frame_base),
10029 node->label, node->next->label, secname, 1);
10032 for (; node->next; node = node->next)
10033 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10035 /* The variable has a location between NODE->LABEL and
10036 NODE->NEXT->LABEL. */
10037 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10038 add_loc_descr_to_loc_list (&list,
10039 loc_descriptor (varloc,
10040 attr != DW_AT_frame_base),
10041 node->label, node->next->label, secname);
10044 /* If the variable has a location at the last label
10045 it keeps its location until the end of function. */
10046 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10048 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10050 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10051 if (!current_function_decl)
10052 endname = text_end_label;
10055 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10056 current_function_funcdef_no);
10057 endname = ggc_strdup (label_id);
10059 add_loc_descr_to_loc_list (&list,
10060 loc_descriptor (varloc,
10061 attr != DW_AT_frame_base),
10062 node->label, endname, secname);
10065 /* Finally, add the location list to the DIE, and we are done. */
10066 add_AT_loc_list (die, attr, list);
10070 rtl = rtl_for_decl_location (decl);
10071 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
10073 add_const_value_attribute (die, rtl);
10077 descr = loc_descriptor_from_tree (decl);
10079 add_AT_location_description (die, attr, descr);
10082 /* If we don't have a copy of this variable in memory for some reason (such
10083 as a C++ member constant that doesn't have an out-of-line definition),
10084 we should tell the debugger about the constant value. */
10087 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
10089 tree init = DECL_INITIAL (decl);
10090 tree type = TREE_TYPE (decl);
10092 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
10093 && initializer_constant_valid_p (init, type) == null_pointer_node)
10098 switch (TREE_CODE (type))
10101 if (host_integerp (init, 0))
10102 add_AT_unsigned (var_die, DW_AT_const_value,
10103 tree_low_cst (init, 0));
10105 add_AT_long_long (var_die, DW_AT_const_value,
10106 TREE_INT_CST_HIGH (init),
10107 TREE_INT_CST_LOW (init));
10114 /* Generate a DW_AT_name attribute given some string value to be included as
10115 the value of the attribute. */
10118 add_name_attribute (dw_die_ref die, const char *name_string)
10120 if (name_string != NULL && *name_string != 0)
10122 if (demangle_name_func)
10123 name_string = (*demangle_name_func) (name_string);
10125 add_AT_string (die, DW_AT_name, name_string);
10129 /* Generate a DW_AT_comp_dir attribute for DIE. */
10132 add_comp_dir_attribute (dw_die_ref die)
10134 const char *wd = get_src_pwd ();
10136 add_AT_string (die, DW_AT_comp_dir, wd);
10139 /* Given a tree node describing an array bound (either lower or upper) output
10140 a representation for that bound. */
10143 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
10145 switch (TREE_CODE (bound))
10150 /* All fixed-bounds are represented by INTEGER_CST nodes. */
10152 if (! host_integerp (bound, 0)
10153 || (bound_attr == DW_AT_lower_bound
10154 && (((is_c_family () || is_java ()) && integer_zerop (bound))
10155 || (is_fortran () && integer_onep (bound)))))
10156 /* Use the default. */
10159 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
10164 case NON_LVALUE_EXPR:
10165 case VIEW_CONVERT_EXPR:
10166 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
10176 dw_die_ref decl_die = lookup_decl_die (bound);
10178 /* ??? Can this happen, or should the variable have been bound
10179 first? Probably it can, since I imagine that we try to create
10180 the types of parameters in the order in which they exist in
10181 the list, and won't have created a forward reference to a
10182 later parameter. */
10183 if (decl_die != NULL)
10184 add_AT_die_ref (subrange_die, bound_attr, decl_die);
10190 /* Otherwise try to create a stack operation procedure to
10191 evaluate the value of the array bound. */
10193 dw_die_ref ctx, decl_die;
10194 dw_loc_descr_ref loc;
10196 loc = loc_descriptor_from_tree (bound);
10200 if (current_function_decl == 0)
10201 ctx = comp_unit_die;
10203 ctx = lookup_decl_die (current_function_decl);
10205 decl_die = new_die (DW_TAG_variable, ctx, bound);
10206 add_AT_flag (decl_die, DW_AT_artificial, 1);
10207 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
10208 add_AT_loc (decl_die, DW_AT_location, loc);
10210 add_AT_die_ref (subrange_die, bound_attr, decl_die);
10216 /* Note that the block of subscript information for an array type also
10217 includes information about the element type of type given array type. */
10220 add_subscript_info (dw_die_ref type_die, tree type)
10222 #ifndef MIPS_DEBUGGING_INFO
10223 unsigned dimension_number;
10226 dw_die_ref subrange_die;
10228 /* The GNU compilers represent multidimensional array types as sequences of
10229 one dimensional array types whose element types are themselves array
10230 types. Here we squish that down, so that each multidimensional array
10231 type gets only one array_type DIE in the Dwarf debugging info. The draft
10232 Dwarf specification say that we are allowed to do this kind of
10233 compression in C (because there is no difference between an array or
10234 arrays and a multidimensional array in C) but for other source languages
10235 (e.g. Ada) we probably shouldn't do this. */
10237 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10238 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10239 We work around this by disabling this feature. See also
10240 gen_array_type_die. */
10241 #ifndef MIPS_DEBUGGING_INFO
10242 for (dimension_number = 0;
10243 TREE_CODE (type) == ARRAY_TYPE;
10244 type = TREE_TYPE (type), dimension_number++)
10247 tree domain = TYPE_DOMAIN (type);
10249 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
10250 and (in GNU C only) variable bounds. Handle all three forms
10252 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
10255 /* We have an array type with specified bounds. */
10256 lower = TYPE_MIN_VALUE (domain);
10257 upper = TYPE_MAX_VALUE (domain);
10259 /* Define the index type. */
10260 if (TREE_TYPE (domain))
10262 /* ??? This is probably an Ada unnamed subrange type. Ignore the
10263 TREE_TYPE field. We can't emit debug info for this
10264 because it is an unnamed integral type. */
10265 if (TREE_CODE (domain) == INTEGER_TYPE
10266 && TYPE_NAME (domain) == NULL_TREE
10267 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
10268 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
10271 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
10275 /* ??? If upper is NULL, the array has unspecified length,
10276 but it does have a lower bound. This happens with Fortran
10278 Since the debugger is definitely going to need to know N
10279 to produce useful results, go ahead and output the lower
10280 bound solo, and hope the debugger can cope. */
10282 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
10284 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
10287 /* Otherwise we have an array type with an unspecified length. The
10288 DWARF-2 spec does not say how to handle this; let's just leave out the
10294 add_byte_size_attribute (dw_die_ref die, tree tree_node)
10298 switch (TREE_CODE (tree_node))
10303 case ENUMERAL_TYPE:
10306 case QUAL_UNION_TYPE:
10307 size = int_size_in_bytes (tree_node);
10310 /* For a data member of a struct or union, the DW_AT_byte_size is
10311 generally given as the number of bytes normally allocated for an
10312 object of the *declared* type of the member itself. This is true
10313 even for bit-fields. */
10314 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
10317 gcc_unreachable ();
10320 /* Note that `size' might be -1 when we get to this point. If it is, that
10321 indicates that the byte size of the entity in question is variable. We
10322 have no good way of expressing this fact in Dwarf at the present time,
10323 so just let the -1 pass on through. */
10324 add_AT_unsigned (die, DW_AT_byte_size, size);
10327 /* For a FIELD_DECL node which represents a bit-field, output an attribute
10328 which specifies the distance in bits from the highest order bit of the
10329 "containing object" for the bit-field to the highest order bit of the
10332 For any given bit-field, the "containing object" is a hypothetical object
10333 (of some integral or enum type) within which the given bit-field lives. The
10334 type of this hypothetical "containing object" is always the same as the
10335 declared type of the individual bit-field itself. The determination of the
10336 exact location of the "containing object" for a bit-field is rather
10337 complicated. It's handled by the `field_byte_offset' function (above).
10339 Note that it is the size (in bytes) of the hypothetical "containing object"
10340 which will be given in the DW_AT_byte_size attribute for this bit-field.
10341 (See `byte_size_attribute' above). */
10344 add_bit_offset_attribute (dw_die_ref die, tree decl)
10346 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
10347 tree type = DECL_BIT_FIELD_TYPE (decl);
10348 HOST_WIDE_INT bitpos_int;
10349 HOST_WIDE_INT highest_order_object_bit_offset;
10350 HOST_WIDE_INT highest_order_field_bit_offset;
10351 HOST_WIDE_INT unsigned bit_offset;
10353 /* Must be a field and a bit field. */
10354 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
10356 /* We can't yet handle bit-fields whose offsets are variable, so if we
10357 encounter such things, just return without generating any attribute
10358 whatsoever. Likewise for variable or too large size. */
10359 if (! host_integerp (bit_position (decl), 0)
10360 || ! host_integerp (DECL_SIZE (decl), 1))
10363 bitpos_int = int_bit_position (decl);
10365 /* Note that the bit offset is always the distance (in bits) from the
10366 highest-order bit of the "containing object" to the highest-order bit of
10367 the bit-field itself. Since the "high-order end" of any object or field
10368 is different on big-endian and little-endian machines, the computation
10369 below must take account of these differences. */
10370 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
10371 highest_order_field_bit_offset = bitpos_int;
10373 if (! BYTES_BIG_ENDIAN)
10375 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
10376 highest_order_object_bit_offset += simple_type_size_in_bits (type);
10380 = (! BYTES_BIG_ENDIAN
10381 ? highest_order_object_bit_offset - highest_order_field_bit_offset
10382 : highest_order_field_bit_offset - highest_order_object_bit_offset);
10384 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
10387 /* For a FIELD_DECL node which represents a bit field, output an attribute
10388 which specifies the length in bits of the given field. */
10391 add_bit_size_attribute (dw_die_ref die, tree decl)
10393 /* Must be a field and a bit field. */
10394 gcc_assert (TREE_CODE (decl) == FIELD_DECL
10395 && DECL_BIT_FIELD_TYPE (decl));
10397 if (host_integerp (DECL_SIZE (decl), 1))
10398 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
10401 /* If the compiled language is ANSI C, then add a 'prototyped'
10402 attribute, if arg types are given for the parameters of a function. */
10405 add_prototyped_attribute (dw_die_ref die, tree func_type)
10407 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
10408 && TYPE_ARG_TYPES (func_type) != NULL)
10409 add_AT_flag (die, DW_AT_prototyped, 1);
10412 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
10413 by looking in either the type declaration or object declaration
10417 add_abstract_origin_attribute (dw_die_ref die, tree origin)
10419 dw_die_ref origin_die = NULL;
10421 if (TREE_CODE (origin) != FUNCTION_DECL)
10423 /* We may have gotten separated from the block for the inlined
10424 function, if we're in an exception handler or some such; make
10425 sure that the abstract function has been written out.
10427 Doing this for nested functions is wrong, however; functions are
10428 distinct units, and our context might not even be inline. */
10432 fn = TYPE_STUB_DECL (fn);
10434 fn = decl_function_context (fn);
10436 dwarf2out_abstract_function (fn);
10439 if (DECL_P (origin))
10440 origin_die = lookup_decl_die (origin);
10441 else if (TYPE_P (origin))
10442 origin_die = lookup_type_die (origin);
10444 gcc_assert (origin_die);
10446 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
10449 /* We do not currently support the pure_virtual attribute. */
10452 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
10454 if (DECL_VINDEX (func_decl))
10456 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10458 if (host_integerp (DECL_VINDEX (func_decl), 0))
10459 add_AT_loc (die, DW_AT_vtable_elem_location,
10460 new_loc_descr (DW_OP_constu,
10461 tree_low_cst (DECL_VINDEX (func_decl), 0),
10464 /* GNU extension: Record what type this method came from originally. */
10465 if (debug_info_level > DINFO_LEVEL_TERSE)
10466 add_AT_die_ref (die, DW_AT_containing_type,
10467 lookup_type_die (DECL_CONTEXT (func_decl)));
10471 /* Add source coordinate attributes for the given decl. */
10474 add_src_coords_attributes (dw_die_ref die, tree decl)
10476 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
10477 unsigned file_index = lookup_filename (s.file);
10479 add_AT_unsigned (die, DW_AT_decl_file, file_index);
10480 add_AT_unsigned (die, DW_AT_decl_line, s.line);
10483 /* Add a DW_AT_name attribute and source coordinate attribute for the
10484 given decl, but only if it actually has a name. */
10487 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
10491 decl_name = DECL_NAME (decl);
10492 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
10494 add_name_attribute (die, dwarf2_name (decl, 0));
10495 if (! DECL_ARTIFICIAL (decl))
10496 add_src_coords_attributes (die, decl);
10498 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
10499 && TREE_PUBLIC (decl)
10500 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
10501 && !DECL_ABSTRACT (decl))
10502 add_AT_string (die, DW_AT_MIPS_linkage_name,
10503 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
10506 #ifdef VMS_DEBUGGING_INFO
10507 /* Get the function's name, as described by its RTL. This may be different
10508 from the DECL_NAME name used in the source file. */
10509 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
10511 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
10512 XEXP (DECL_RTL (decl), 0));
10513 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
10518 /* Push a new declaration scope. */
10521 push_decl_scope (tree scope)
10523 VARRAY_PUSH_TREE (decl_scope_table, scope);
10526 /* Pop a declaration scope. */
10529 pop_decl_scope (void)
10531 gcc_assert (VARRAY_ACTIVE_SIZE (decl_scope_table) > 0);
10533 VARRAY_POP (decl_scope_table);
10536 /* Return the DIE for the scope that immediately contains this type.
10537 Non-named types get global scope. Named types nested in other
10538 types get their containing scope if it's open, or global scope
10539 otherwise. All other types (i.e. function-local named types) get
10540 the current active scope. */
10543 scope_die_for (tree t, dw_die_ref context_die)
10545 dw_die_ref scope_die = NULL;
10546 tree containing_scope;
10549 /* Non-types always go in the current scope. */
10550 gcc_assert (TYPE_P (t));
10552 containing_scope = TYPE_CONTEXT (t);
10554 /* Use the containing namespace if it was passed in (for a declaration). */
10555 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
10557 if (context_die == lookup_decl_die (containing_scope))
10560 containing_scope = NULL_TREE;
10563 /* Ignore function type "scopes" from the C frontend. They mean that
10564 a tagged type is local to a parmlist of a function declarator, but
10565 that isn't useful to DWARF. */
10566 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
10567 containing_scope = NULL_TREE;
10569 if (containing_scope == NULL_TREE)
10570 scope_die = comp_unit_die;
10571 else if (TYPE_P (containing_scope))
10573 /* For types, we can just look up the appropriate DIE. But
10574 first we check to see if we're in the middle of emitting it
10575 so we know where the new DIE should go. */
10576 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
10577 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
10582 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
10583 || TREE_ASM_WRITTEN (containing_scope));
10585 /* If none of the current dies are suitable, we get file scope. */
10586 scope_die = comp_unit_die;
10589 scope_die = lookup_type_die (containing_scope);
10592 scope_die = context_die;
10597 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10600 local_scope_p (dw_die_ref context_die)
10602 for (; context_die; context_die = context_die->die_parent)
10603 if (context_die->die_tag == DW_TAG_inlined_subroutine
10604 || context_die->die_tag == DW_TAG_subprogram)
10610 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
10611 whether or not to treat a DIE in this context as a declaration. */
10614 class_or_namespace_scope_p (dw_die_ref context_die)
10616 return (context_die
10617 && (context_die->die_tag == DW_TAG_structure_type
10618 || context_die->die_tag == DW_TAG_union_type
10619 || context_die->die_tag == DW_TAG_namespace));
10622 /* Many forms of DIEs require a "type description" attribute. This
10623 routine locates the proper "type descriptor" die for the type given
10624 by 'type', and adds a DW_AT_type attribute below the given die. */
10627 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
10628 int decl_volatile, dw_die_ref context_die)
10630 enum tree_code code = TREE_CODE (type);
10631 dw_die_ref type_die = NULL;
10633 /* ??? If this type is an unnamed subrange type of an integral or
10634 floating-point type, use the inner type. This is because we have no
10635 support for unnamed types in base_type_die. This can happen if this is
10636 an Ada subrange type. Correct solution is emit a subrange type die. */
10637 if ((code == INTEGER_TYPE || code == REAL_TYPE)
10638 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
10639 type = TREE_TYPE (type), code = TREE_CODE (type);
10641 if (code == ERROR_MARK
10642 /* Handle a special case. For functions whose return type is void, we
10643 generate *no* type attribute. (Note that no object may have type
10644 `void', so this only applies to function return types). */
10645 || code == VOID_TYPE)
10648 type_die = modified_type_die (type,
10649 decl_const || TYPE_READONLY (type),
10650 decl_volatile || TYPE_VOLATILE (type),
10653 if (type_die != NULL)
10654 add_AT_die_ref (object_die, DW_AT_type, type_die);
10657 /* Given an object die, add the calling convention attribute for the
10658 function call type. */
10660 add_calling_convention_attribute (dw_die_ref subr_die, tree type)
10662 enum dwarf_calling_convention value = DW_CC_normal;
10664 value = targetm.dwarf_calling_convention (type);
10666 /* Only add the attribute if the backend requests it, and
10667 is not DW_CC_normal. */
10668 if (value && (value != DW_CC_normal))
10669 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
10672 /* Given a tree pointer to a struct, class, union, or enum type node, return
10673 a pointer to the (string) tag name for the given type, or zero if the type
10674 was declared without a tag. */
10676 static const char *
10677 type_tag (tree type)
10679 const char *name = 0;
10681 if (TYPE_NAME (type) != 0)
10685 /* Find the IDENTIFIER_NODE for the type name. */
10686 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
10687 t = TYPE_NAME (type);
10689 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
10690 a TYPE_DECL node, regardless of whether or not a `typedef' was
10692 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10693 && ! DECL_IGNORED_P (TYPE_NAME (type)))
10694 t = DECL_NAME (TYPE_NAME (type));
10696 /* Now get the name as a string, or invent one. */
10698 name = IDENTIFIER_POINTER (t);
10701 return (name == 0 || *name == '\0') ? 0 : name;
10704 /* Return the type associated with a data member, make a special check
10705 for bit field types. */
10708 member_declared_type (tree member)
10710 return (DECL_BIT_FIELD_TYPE (member)
10711 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
10714 /* Get the decl's label, as described by its RTL. This may be different
10715 from the DECL_NAME name used in the source file. */
10718 static const char *
10719 decl_start_label (tree decl)
10722 const char *fnname;
10724 x = DECL_RTL (decl);
10725 gcc_assert (MEM_P (x));
10728 gcc_assert (GET_CODE (x) == SYMBOL_REF);
10730 fnname = XSTR (x, 0);
10735 /* These routines generate the internal representation of the DIE's for
10736 the compilation unit. Debugging information is collected by walking
10737 the declaration trees passed in from dwarf2out_decl(). */
10740 gen_array_type_die (tree type, dw_die_ref context_die)
10742 dw_die_ref scope_die = scope_die_for (type, context_die);
10743 dw_die_ref array_die;
10746 /* ??? The SGI dwarf reader fails for array of array of enum types unless
10747 the inner array type comes before the outer array type. Thus we must
10748 call gen_type_die before we call new_die. See below also. */
10749 #ifdef MIPS_DEBUGGING_INFO
10750 gen_type_die (TREE_TYPE (type), context_die);
10753 array_die = new_die (DW_TAG_array_type, scope_die, type);
10754 add_name_attribute (array_die, type_tag (type));
10755 equate_type_number_to_die (type, array_die);
10757 if (TREE_CODE (type) == VECTOR_TYPE)
10759 /* The frontend feeds us a representation for the vector as a struct
10760 containing an array. Pull out the array type. */
10761 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
10762 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
10766 /* We default the array ordering. SDB will probably do
10767 the right things even if DW_AT_ordering is not present. It's not even
10768 an issue until we start to get into multidimensional arrays anyway. If
10769 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
10770 then we'll have to put the DW_AT_ordering attribute back in. (But if
10771 and when we find out that we need to put these in, we will only do so
10772 for multidimensional arrays. */
10773 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
10776 #ifdef MIPS_DEBUGGING_INFO
10777 /* The SGI compilers handle arrays of unknown bound by setting
10778 AT_declaration and not emitting any subrange DIEs. */
10779 if (! TYPE_DOMAIN (type))
10780 add_AT_flag (array_die, DW_AT_declaration, 1);
10783 add_subscript_info (array_die, type);
10785 /* Add representation of the type of the elements of this array type. */
10786 element_type = TREE_TYPE (type);
10788 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10789 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10790 We work around this by disabling this feature. See also
10791 add_subscript_info. */
10792 #ifndef MIPS_DEBUGGING_INFO
10793 while (TREE_CODE (element_type) == ARRAY_TYPE)
10794 element_type = TREE_TYPE (element_type);
10796 gen_type_die (element_type, context_die);
10799 add_type_attribute (array_die, element_type, 0, 0, context_die);
10803 gen_set_type_die (tree type, dw_die_ref context_die)
10805 dw_die_ref type_die
10806 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
10808 equate_type_number_to_die (type, type_die);
10809 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
10814 gen_entry_point_die (tree decl, dw_die_ref context_die)
10816 tree origin = decl_ultimate_origin (decl);
10817 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
10819 if (origin != NULL)
10820 add_abstract_origin_attribute (decl_die, origin);
10823 add_name_and_src_coords_attributes (decl_die, decl);
10824 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
10825 0, 0, context_die);
10828 if (DECL_ABSTRACT (decl))
10829 equate_decl_number_to_die (decl, decl_die);
10831 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
10835 /* Walk through the list of incomplete types again, trying once more to
10836 emit full debugging info for them. */
10839 retry_incomplete_types (void)
10843 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
10844 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
10847 /* Generate a DIE to represent an inlined instance of an enumeration type. */
10850 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
10852 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
10854 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10855 be incomplete and such types are not marked. */
10856 add_abstract_origin_attribute (type_die, type);
10859 /* Generate a DIE to represent an inlined instance of a structure type. */
10862 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
10864 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
10866 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10867 be incomplete and such types are not marked. */
10868 add_abstract_origin_attribute (type_die, type);
10871 /* Generate a DIE to represent an inlined instance of a union type. */
10874 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
10876 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
10878 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10879 be incomplete and such types are not marked. */
10880 add_abstract_origin_attribute (type_die, type);
10883 /* Generate a DIE to represent an enumeration type. Note that these DIEs
10884 include all of the information about the enumeration values also. Each
10885 enumerated type name/value is listed as a child of the enumerated type
10889 gen_enumeration_type_die (tree type, dw_die_ref context_die)
10891 dw_die_ref type_die = lookup_type_die (type);
10893 if (type_die == NULL)
10895 type_die = new_die (DW_TAG_enumeration_type,
10896 scope_die_for (type, context_die), type);
10897 equate_type_number_to_die (type, type_die);
10898 add_name_attribute (type_die, type_tag (type));
10900 else if (! TYPE_SIZE (type))
10903 remove_AT (type_die, DW_AT_declaration);
10905 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
10906 given enum type is incomplete, do not generate the DW_AT_byte_size
10907 attribute or the DW_AT_element_list attribute. */
10908 if (TYPE_SIZE (type))
10912 TREE_ASM_WRITTEN (type) = 1;
10913 add_byte_size_attribute (type_die, type);
10914 if (TYPE_STUB_DECL (type) != NULL_TREE)
10915 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10917 /* If the first reference to this type was as the return type of an
10918 inline function, then it may not have a parent. Fix this now. */
10919 if (type_die->die_parent == NULL)
10920 add_child_die (scope_die_for (type, context_die), type_die);
10922 for (link = TYPE_VALUES (type);
10923 link != NULL; link = TREE_CHAIN (link))
10925 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
10926 tree value = TREE_VALUE (link);
10928 add_name_attribute (enum_die,
10929 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
10931 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
10932 /* DWARF2 does not provide a way of indicating whether or
10933 not enumeration constants are signed or unsigned. GDB
10934 always assumes the values are signed, so we output all
10935 values as if they were signed. That means that
10936 enumeration constants with very large unsigned values
10937 will appear to have negative values in the debugger. */
10938 add_AT_int (enum_die, DW_AT_const_value,
10939 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
10943 add_AT_flag (type_die, DW_AT_declaration, 1);
10948 /* Generate a DIE to represent either a real live formal parameter decl or to
10949 represent just the type of some formal parameter position in some function
10952 Note that this routine is a bit unusual because its argument may be a
10953 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
10954 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
10955 node. If it's the former then this function is being called to output a
10956 DIE to represent a formal parameter object (or some inlining thereof). If
10957 it's the latter, then this function is only being called to output a
10958 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
10959 argument type of some subprogram type. */
10962 gen_formal_parameter_die (tree node, dw_die_ref context_die)
10964 dw_die_ref parm_die
10965 = new_die (DW_TAG_formal_parameter, context_die, node);
10968 switch (TREE_CODE_CLASS (TREE_CODE (node)))
10970 case tcc_declaration:
10971 origin = decl_ultimate_origin (node);
10972 if (origin != NULL)
10973 add_abstract_origin_attribute (parm_die, origin);
10976 add_name_and_src_coords_attributes (parm_die, node);
10977 add_type_attribute (parm_die, TREE_TYPE (node),
10978 TREE_READONLY (node),
10979 TREE_THIS_VOLATILE (node),
10981 if (DECL_ARTIFICIAL (node))
10982 add_AT_flag (parm_die, DW_AT_artificial, 1);
10985 equate_decl_number_to_die (node, parm_die);
10986 if (! DECL_ABSTRACT (node))
10987 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
10992 /* We were called with some kind of a ..._TYPE node. */
10993 add_type_attribute (parm_die, node, 0, 0, context_die);
10997 gcc_unreachable ();
11003 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
11004 at the end of an (ANSI prototyped) formal parameters list. */
11007 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
11009 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
11012 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
11013 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
11014 parameters as specified in some function type specification (except for
11015 those which appear as part of a function *definition*). */
11018 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
11021 tree formal_type = NULL;
11022 tree first_parm_type;
11025 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
11027 arg = DECL_ARGUMENTS (function_or_method_type);
11028 function_or_method_type = TREE_TYPE (function_or_method_type);
11033 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
11035 /* Make our first pass over the list of formal parameter types and output a
11036 DW_TAG_formal_parameter DIE for each one. */
11037 for (link = first_parm_type; link; )
11039 dw_die_ref parm_die;
11041 formal_type = TREE_VALUE (link);
11042 if (formal_type == void_type_node)
11045 /* Output a (nameless) DIE to represent the formal parameter itself. */
11046 parm_die = gen_formal_parameter_die (formal_type, context_die);
11047 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
11048 && link == first_parm_type)
11049 || (arg && DECL_ARTIFICIAL (arg)))
11050 add_AT_flag (parm_die, DW_AT_artificial, 1);
11052 link = TREE_CHAIN (link);
11054 arg = TREE_CHAIN (arg);
11057 /* If this function type has an ellipsis, add a
11058 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
11059 if (formal_type != void_type_node)
11060 gen_unspecified_parameters_die (function_or_method_type, context_die);
11062 /* Make our second (and final) pass over the list of formal parameter types
11063 and output DIEs to represent those types (as necessary). */
11064 for (link = TYPE_ARG_TYPES (function_or_method_type);
11065 link && TREE_VALUE (link);
11066 link = TREE_CHAIN (link))
11067 gen_type_die (TREE_VALUE (link), context_die);
11070 /* We want to generate the DIE for TYPE so that we can generate the
11071 die for MEMBER, which has been defined; we will need to refer back
11072 to the member declaration nested within TYPE. If we're trying to
11073 generate minimal debug info for TYPE, processing TYPE won't do the
11074 trick; we need to attach the member declaration by hand. */
11077 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
11079 gen_type_die (type, context_die);
11081 /* If we're trying to avoid duplicate debug info, we may not have
11082 emitted the member decl for this function. Emit it now. */
11083 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
11084 && ! lookup_decl_die (member))
11086 gcc_assert (!decl_ultimate_origin (member));
11088 push_decl_scope (type);
11089 if (TREE_CODE (member) == FUNCTION_DECL)
11090 gen_subprogram_die (member, lookup_type_die (type));
11092 gen_variable_die (member, lookup_type_die (type));
11098 /* Generate the DWARF2 info for the "abstract" instance of a function which we
11099 may later generate inlined and/or out-of-line instances of. */
11102 dwarf2out_abstract_function (tree decl)
11104 dw_die_ref old_die;
11107 int was_abstract = DECL_ABSTRACT (decl);
11109 /* Make sure we have the actual abstract inline, not a clone. */
11110 decl = DECL_ORIGIN (decl);
11112 old_die = lookup_decl_die (decl);
11113 if (old_die && get_AT (old_die, DW_AT_inline))
11114 /* We've already generated the abstract instance. */
11117 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
11118 we don't get confused by DECL_ABSTRACT. */
11119 if (debug_info_level > DINFO_LEVEL_TERSE)
11121 context = decl_class_context (decl);
11123 gen_type_die_for_member
11124 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
11127 /* Pretend we've just finished compiling this function. */
11128 save_fn = current_function_decl;
11129 current_function_decl = decl;
11131 set_decl_abstract_flags (decl, 1);
11132 dwarf2out_decl (decl);
11133 if (! was_abstract)
11134 set_decl_abstract_flags (decl, 0);
11136 current_function_decl = save_fn;
11139 /* Generate a DIE to represent a declared function (either file-scope or
11143 gen_subprogram_die (tree decl, dw_die_ref context_die)
11145 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
11146 tree origin = decl_ultimate_origin (decl);
11147 dw_die_ref subr_die;
11151 dw_die_ref old_die = lookup_decl_die (decl);
11152 int declaration = (current_function_decl != decl
11153 || class_or_namespace_scope_p (context_die));
11155 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
11156 started to generate the abstract instance of an inline, decided to output
11157 its containing class, and proceeded to emit the declaration of the inline
11158 from the member list for the class. If so, DECLARATION takes priority;
11159 we'll get back to the abstract instance when done with the class. */
11161 /* The class-scope declaration DIE must be the primary DIE. */
11162 if (origin && declaration && class_or_namespace_scope_p (context_die))
11165 gcc_assert (!old_die);
11168 if (origin != NULL)
11170 gcc_assert (!declaration || local_scope_p (context_die));
11172 /* Fixup die_parent for the abstract instance of a nested
11173 inline function. */
11174 if (old_die && old_die->die_parent == NULL)
11175 add_child_die (context_die, old_die);
11177 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11178 add_abstract_origin_attribute (subr_die, origin);
11182 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11183 unsigned file_index = lookup_filename (s.file);
11185 if (!get_AT_flag (old_die, DW_AT_declaration)
11186 /* We can have a normal definition following an inline one in the
11187 case of redefinition of GNU C extern inlines.
11188 It seems reasonable to use AT_specification in this case. */
11189 && !get_AT (old_die, DW_AT_inline))
11191 /* ??? This can happen if there is a bug in the program, for
11192 instance, if it has duplicate function definitions. Ideally,
11193 we should detect this case and ignore it. For now, if we have
11194 already reported an error, any error at all, then assume that
11195 we got here because of an input error, not a dwarf2 bug. */
11196 gcc_assert (errorcount);
11200 /* If the definition comes from the same place as the declaration,
11201 maybe use the old DIE. We always want the DIE for this function
11202 that has the *_pc attributes to be under comp_unit_die so the
11203 debugger can find it. We also need to do this for abstract
11204 instances of inlines, since the spec requires the out-of-line copy
11205 to have the same parent. For local class methods, this doesn't
11206 apply; we just use the old DIE. */
11207 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
11208 && (DECL_ARTIFICIAL (decl)
11209 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
11210 && (get_AT_unsigned (old_die, DW_AT_decl_line)
11211 == (unsigned) s.line))))
11213 subr_die = old_die;
11215 /* Clear out the declaration attribute and the formal parameters.
11216 Do not remove all children, because it is possible that this
11217 declaration die was forced using force_decl_die(). In such
11218 cases die that forced declaration die (e.g. TAG_imported_module)
11219 is one of the children that we do not want to remove. */
11220 remove_AT (subr_die, DW_AT_declaration);
11221 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
11225 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11226 add_AT_specification (subr_die, old_die);
11227 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
11228 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
11229 if (get_AT_unsigned (old_die, DW_AT_decl_line)
11230 != (unsigned) s.line)
11232 (subr_die, DW_AT_decl_line, s.line);
11237 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11239 if (TREE_PUBLIC (decl))
11240 add_AT_flag (subr_die, DW_AT_external, 1);
11242 add_name_and_src_coords_attributes (subr_die, decl);
11243 if (debug_info_level > DINFO_LEVEL_TERSE)
11245 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
11246 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
11247 0, 0, context_die);
11250 add_pure_or_virtual_attribute (subr_die, decl);
11251 if (DECL_ARTIFICIAL (decl))
11252 add_AT_flag (subr_die, DW_AT_artificial, 1);
11254 if (TREE_PROTECTED (decl))
11255 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
11256 else if (TREE_PRIVATE (decl))
11257 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
11262 if (!old_die || !get_AT (old_die, DW_AT_inline))
11264 add_AT_flag (subr_die, DW_AT_declaration, 1);
11266 /* The first time we see a member function, it is in the context of
11267 the class to which it belongs. We make sure of this by emitting
11268 the class first. The next time is the definition, which is
11269 handled above. The two may come from the same source text.
11271 Note that force_decl_die() forces function declaration die. It is
11272 later reused to represent definition. */
11273 equate_decl_number_to_die (decl, subr_die);
11276 else if (DECL_ABSTRACT (decl))
11278 if (DECL_DECLARED_INLINE_P (decl))
11280 if (cgraph_function_possibly_inlined_p (decl))
11281 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
11283 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
11287 if (cgraph_function_possibly_inlined_p (decl))
11288 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
11290 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
11293 equate_decl_number_to_die (decl, subr_die);
11295 else if (!DECL_EXTERNAL (decl))
11297 if (!old_die || !get_AT (old_die, DW_AT_inline))
11298 equate_decl_number_to_die (decl, subr_die);
11300 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
11301 current_function_funcdef_no);
11302 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
11303 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
11304 current_function_funcdef_no);
11305 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
11307 add_pubname (decl, subr_die);
11308 add_arange (decl, subr_die);
11310 #ifdef MIPS_DEBUGGING_INFO
11311 /* Add a reference to the FDE for this routine. */
11312 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
11315 /* Define the "frame base" location for this routine. We use the
11316 frame pointer or stack pointer registers, since the RTL for local
11317 variables is relative to one of them. */
11318 if (frame_base_decl && lookup_decl_loc (frame_base_decl) != NULL)
11320 add_location_or_const_value_attribute (subr_die, frame_base_decl,
11326 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
11327 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
11330 if (cfun->static_chain_decl)
11331 add_AT_location_description (subr_die, DW_AT_static_link,
11332 loc_descriptor_from_tree (cfun->static_chain_decl));
11335 /* Now output descriptions of the arguments for this function. This gets
11336 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
11337 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
11338 `...' at the end of the formal parameter list. In order to find out if
11339 there was a trailing ellipsis or not, we must instead look at the type
11340 associated with the FUNCTION_DECL. This will be a node of type
11341 FUNCTION_TYPE. If the chain of type nodes hanging off of this
11342 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
11343 an ellipsis at the end. */
11345 /* In the case where we are describing a mere function declaration, all we
11346 need to do here (and all we *can* do here) is to describe the *types* of
11347 its formal parameters. */
11348 if (debug_info_level <= DINFO_LEVEL_TERSE)
11350 else if (declaration)
11351 gen_formal_types_die (decl, subr_die);
11354 /* Generate DIEs to represent all known formal parameters. */
11355 tree arg_decls = DECL_ARGUMENTS (decl);
11358 /* When generating DIEs, generate the unspecified_parameters DIE
11359 instead if we come across the arg "__builtin_va_alist" */
11360 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
11361 if (TREE_CODE (parm) == PARM_DECL)
11363 if (DECL_NAME (parm)
11364 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
11365 "__builtin_va_alist"))
11366 gen_unspecified_parameters_die (parm, subr_die);
11368 gen_decl_die (parm, subr_die);
11371 /* Decide whether we need an unspecified_parameters DIE at the end.
11372 There are 2 more cases to do this for: 1) the ansi ... declaration -
11373 this is detectable when the end of the arg list is not a
11374 void_type_node 2) an unprototyped function declaration (not a
11375 definition). This just means that we have no info about the
11376 parameters at all. */
11377 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
11378 if (fn_arg_types != NULL)
11380 /* This is the prototyped case, check for.... */
11381 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
11382 gen_unspecified_parameters_die (decl, subr_die);
11384 else if (DECL_INITIAL (decl) == NULL_TREE)
11385 gen_unspecified_parameters_die (decl, subr_die);
11388 /* Output Dwarf info for all of the stuff within the body of the function
11389 (if it has one - it may be just a declaration). */
11390 outer_scope = DECL_INITIAL (decl);
11392 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
11393 a function. This BLOCK actually represents the outermost binding contour
11394 for the function, i.e. the contour in which the function's formal
11395 parameters and labels get declared. Curiously, it appears that the front
11396 end doesn't actually put the PARM_DECL nodes for the current function onto
11397 the BLOCK_VARS list for this outer scope, but are strung off of the
11398 DECL_ARGUMENTS list for the function instead.
11400 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
11401 the LABEL_DECL nodes for the function however, and we output DWARF info
11402 for those in decls_for_scope. Just within the `outer_scope' there will be
11403 a BLOCK node representing the function's outermost pair of curly braces,
11404 and any blocks used for the base and member initializers of a C++
11405 constructor function. */
11406 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
11408 /* Emit a DW_TAG_variable DIE for a named return value. */
11409 if (DECL_NAME (DECL_RESULT (decl)))
11410 gen_decl_die (DECL_RESULT (decl), subr_die);
11412 current_function_has_inlines = 0;
11413 decls_for_scope (outer_scope, subr_die, 0);
11415 #if 0 && defined (MIPS_DEBUGGING_INFO)
11416 if (current_function_has_inlines)
11418 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
11419 if (! comp_unit_has_inlines)
11421 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
11422 comp_unit_has_inlines = 1;
11427 /* Add the calling convention attribute if requested. */
11428 add_calling_convention_attribute (subr_die, TREE_TYPE (decl));
11432 /* Generate a DIE to represent a declared data object. */
11435 gen_variable_die (tree decl, dw_die_ref context_die)
11437 tree origin = decl_ultimate_origin (decl);
11438 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
11440 dw_die_ref old_die = lookup_decl_die (decl);
11441 int declaration = (DECL_EXTERNAL (decl)
11442 || class_or_namespace_scope_p (context_die));
11444 if (origin != NULL)
11445 add_abstract_origin_attribute (var_die, origin);
11447 /* Loop unrolling can create multiple blocks that refer to the same
11448 static variable, so we must test for the DW_AT_declaration flag.
11450 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
11451 copy decls and set the DECL_ABSTRACT flag on them instead of
11454 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
11455 else if (old_die && TREE_STATIC (decl)
11456 && get_AT_flag (old_die, DW_AT_declaration) == 1)
11458 /* This is a definition of a C++ class level static. */
11459 add_AT_specification (var_die, old_die);
11460 if (DECL_NAME (decl))
11462 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11463 unsigned file_index = lookup_filename (s.file);
11465 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
11466 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
11468 if (get_AT_unsigned (old_die, DW_AT_decl_line)
11469 != (unsigned) s.line)
11471 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
11476 add_name_and_src_coords_attributes (var_die, decl);
11477 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
11478 TREE_THIS_VOLATILE (decl), context_die);
11480 if (TREE_PUBLIC (decl))
11481 add_AT_flag (var_die, DW_AT_external, 1);
11483 if (DECL_ARTIFICIAL (decl))
11484 add_AT_flag (var_die, DW_AT_artificial, 1);
11486 if (TREE_PROTECTED (decl))
11487 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
11488 else if (TREE_PRIVATE (decl))
11489 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
11493 add_AT_flag (var_die, DW_AT_declaration, 1);
11495 if (DECL_ABSTRACT (decl) || declaration)
11496 equate_decl_number_to_die (decl, var_die);
11498 if (! declaration && ! DECL_ABSTRACT (decl))
11500 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
11501 add_pubname (decl, var_die);
11504 tree_add_const_value_attribute (var_die, decl);
11507 /* Generate a DIE to represent a label identifier. */
11510 gen_label_die (tree decl, dw_die_ref context_die)
11512 tree origin = decl_ultimate_origin (decl);
11513 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
11515 char label[MAX_ARTIFICIAL_LABEL_BYTES];
11517 if (origin != NULL)
11518 add_abstract_origin_attribute (lbl_die, origin);
11520 add_name_and_src_coords_attributes (lbl_die, decl);
11522 if (DECL_ABSTRACT (decl))
11523 equate_decl_number_to_die (decl, lbl_die);
11526 insn = DECL_RTL_IF_SET (decl);
11528 /* Deleted labels are programmer specified labels which have been
11529 eliminated because of various optimizations. We still emit them
11530 here so that it is possible to put breakpoints on them. */
11534 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))))
11536 /* When optimization is enabled (via -O) some parts of the compiler
11537 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
11538 represent source-level labels which were explicitly declared by
11539 the user. This really shouldn't be happening though, so catch
11540 it if it ever does happen. */
11541 gcc_assert (!INSN_DELETED_P (insn));
11543 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
11544 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
11549 /* Generate a DIE for a lexical block. */
11552 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
11554 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
11555 char label[MAX_ARTIFICIAL_LABEL_BYTES];
11557 if (! BLOCK_ABSTRACT (stmt))
11559 if (BLOCK_FRAGMENT_CHAIN (stmt))
11563 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
11565 chain = BLOCK_FRAGMENT_CHAIN (stmt);
11568 add_ranges (chain);
11569 chain = BLOCK_FRAGMENT_CHAIN (chain);
11576 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
11577 BLOCK_NUMBER (stmt));
11578 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
11579 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
11580 BLOCK_NUMBER (stmt));
11581 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
11585 decls_for_scope (stmt, stmt_die, depth);
11588 /* Generate a DIE for an inlined subprogram. */
11591 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
11593 tree decl = block_ultimate_origin (stmt);
11595 /* Emit info for the abstract instance first, if we haven't yet. We
11596 must emit this even if the block is abstract, otherwise when we
11597 emit the block below (or elsewhere), we may end up trying to emit
11598 a die whose origin die hasn't been emitted, and crashing. */
11599 dwarf2out_abstract_function (decl);
11601 if (! BLOCK_ABSTRACT (stmt))
11603 dw_die_ref subr_die
11604 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
11605 char label[MAX_ARTIFICIAL_LABEL_BYTES];
11607 add_abstract_origin_attribute (subr_die, decl);
11608 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
11609 BLOCK_NUMBER (stmt));
11610 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
11611 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
11612 BLOCK_NUMBER (stmt));
11613 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
11614 decls_for_scope (stmt, subr_die, depth);
11615 current_function_has_inlines = 1;
11618 /* We may get here if we're the outer block of function A that was
11619 inlined into function B that was inlined into function C. When
11620 generating debugging info for C, dwarf2out_abstract_function(B)
11621 would mark all inlined blocks as abstract, including this one.
11622 So, we wouldn't (and shouldn't) expect labels to be generated
11623 for this one. Instead, just emit debugging info for
11624 declarations within the block. This is particularly important
11625 in the case of initializers of arguments passed from B to us:
11626 if they're statement expressions containing declarations, we
11627 wouldn't generate dies for their abstract variables, and then,
11628 when generating dies for the real variables, we'd die (pun
11630 gen_lexical_block_die (stmt, context_die, depth);
11633 /* Generate a DIE for a field in a record, or structure. */
11636 gen_field_die (tree decl, dw_die_ref context_die)
11638 dw_die_ref decl_die;
11640 if (TREE_TYPE (decl) == error_mark_node)
11643 decl_die = new_die (DW_TAG_member, context_die, decl);
11644 add_name_and_src_coords_attributes (decl_die, decl);
11645 add_type_attribute (decl_die, member_declared_type (decl),
11646 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
11649 if (DECL_BIT_FIELD_TYPE (decl))
11651 add_byte_size_attribute (decl_die, decl);
11652 add_bit_size_attribute (decl_die, decl);
11653 add_bit_offset_attribute (decl_die, decl);
11656 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
11657 add_data_member_location_attribute (decl_die, decl);
11659 if (DECL_ARTIFICIAL (decl))
11660 add_AT_flag (decl_die, DW_AT_artificial, 1);
11662 if (TREE_PROTECTED (decl))
11663 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
11664 else if (TREE_PRIVATE (decl))
11665 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
11667 /* Equate decl number to die, so that we can look up this decl later on. */
11668 equate_decl_number_to_die (decl, decl_die);
11672 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11673 Use modified_type_die instead.
11674 We keep this code here just in case these types of DIEs may be needed to
11675 represent certain things in other languages (e.g. Pascal) someday. */
11678 gen_pointer_type_die (tree type, dw_die_ref context_die)
11681 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
11683 equate_type_number_to_die (type, ptr_die);
11684 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
11685 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
11688 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11689 Use modified_type_die instead.
11690 We keep this code here just in case these types of DIEs may be needed to
11691 represent certain things in other languages (e.g. Pascal) someday. */
11694 gen_reference_type_die (tree type, dw_die_ref context_die)
11697 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
11699 equate_type_number_to_die (type, ref_die);
11700 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
11701 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
11705 /* Generate a DIE for a pointer to a member type. */
11708 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
11711 = new_die (DW_TAG_ptr_to_member_type,
11712 scope_die_for (type, context_die), type);
11714 equate_type_number_to_die (type, ptr_die);
11715 add_AT_die_ref (ptr_die, DW_AT_containing_type,
11716 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
11717 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
11720 /* Generate the DIE for the compilation unit. */
11723 gen_compile_unit_die (const char *filename)
11726 char producer[250];
11727 const char *language_string = lang_hooks.name;
11730 die = new_die (DW_TAG_compile_unit, NULL, NULL);
11734 add_name_attribute (die, filename);
11735 /* Don't add cwd for <built-in>. */
11736 if (filename[0] != DIR_SEPARATOR && filename[0] != '<')
11737 add_comp_dir_attribute (die);
11740 sprintf (producer, "%s %s", language_string, version_string);
11742 #ifdef MIPS_DEBUGGING_INFO
11743 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
11744 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
11745 not appear in the producer string, the debugger reaches the conclusion
11746 that the object file is stripped and has no debugging information.
11747 To get the MIPS/SGI debugger to believe that there is debugging
11748 information in the object file, we add a -g to the producer string. */
11749 if (debug_info_level > DINFO_LEVEL_TERSE)
11750 strcat (producer, " -g");
11753 add_AT_string (die, DW_AT_producer, producer);
11755 if (strcmp (language_string, "GNU C++") == 0)
11756 language = DW_LANG_C_plus_plus;
11757 else if (strcmp (language_string, "GNU Ada") == 0)
11758 language = DW_LANG_Ada95;
11759 else if (strcmp (language_string, "GNU F77") == 0)
11760 language = DW_LANG_Fortran77;
11761 else if (strcmp (language_string, "GNU F95") == 0)
11762 language = DW_LANG_Fortran95;
11763 else if (strcmp (language_string, "GNU Pascal") == 0)
11764 language = DW_LANG_Pascal83;
11765 else if (strcmp (language_string, "GNU Java") == 0)
11766 language = DW_LANG_Java;
11768 language = DW_LANG_C89;
11770 add_AT_unsigned (die, DW_AT_language, language);
11774 /* Generate a DIE for a string type. */
11777 gen_string_type_die (tree type, dw_die_ref context_die)
11779 dw_die_ref type_die
11780 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
11782 equate_type_number_to_die (type, type_die);
11784 /* ??? Fudge the string length attribute for now.
11785 TODO: add string length info. */
11787 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
11788 bound_representation (upper_bound, 0, 'u');
11792 /* Generate the DIE for a base class. */
11795 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
11797 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
11799 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
11800 add_data_member_location_attribute (die, binfo);
11802 if (BINFO_VIRTUAL_P (binfo))
11803 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
11805 if (access == access_public_node)
11806 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
11807 else if (access == access_protected_node)
11808 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
11811 /* Generate a DIE for a class member. */
11814 gen_member_die (tree type, dw_die_ref context_die)
11817 tree binfo = TYPE_BINFO (type);
11820 /* If this is not an incomplete type, output descriptions of each of its
11821 members. Note that as we output the DIEs necessary to represent the
11822 members of this record or union type, we will also be trying to output
11823 DIEs to represent the *types* of those members. However the `type'
11824 function (above) will specifically avoid generating type DIEs for member
11825 types *within* the list of member DIEs for this (containing) type except
11826 for those types (of members) which are explicitly marked as also being
11827 members of this (containing) type themselves. The g++ front- end can
11828 force any given type to be treated as a member of some other (containing)
11829 type by setting the TYPE_CONTEXT of the given (member) type to point to
11830 the TREE node representing the appropriate (containing) type. */
11832 /* First output info about the base classes. */
11835 VEC (tree) *accesses = BINFO_BASE_ACCESSES (binfo);
11839 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
11840 gen_inheritance_die (base,
11841 (accesses ? VEC_index (tree, accesses, i)
11842 : access_public_node), context_die);
11845 /* Now output info about the data members and type members. */
11846 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
11848 /* If we thought we were generating minimal debug info for TYPE
11849 and then changed our minds, some of the member declarations
11850 may have already been defined. Don't define them again, but
11851 do put them in the right order. */
11853 child = lookup_decl_die (member);
11855 splice_child_die (context_die, child);
11857 gen_decl_die (member, context_die);
11860 /* Now output info about the function members (if any). */
11861 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
11863 /* Don't include clones in the member list. */
11864 if (DECL_ABSTRACT_ORIGIN (member))
11867 child = lookup_decl_die (member);
11869 splice_child_die (context_die, child);
11871 gen_decl_die (member, context_die);
11875 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
11876 is set, we pretend that the type was never defined, so we only get the
11877 member DIEs needed by later specification DIEs. */
11880 gen_struct_or_union_type_die (tree type, dw_die_ref context_die)
11882 dw_die_ref type_die = lookup_type_die (type);
11883 dw_die_ref scope_die = 0;
11885 int complete = (TYPE_SIZE (type)
11886 && (! TYPE_STUB_DECL (type)
11887 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
11888 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
11890 if (type_die && ! complete)
11893 if (TYPE_CONTEXT (type) != NULL_TREE
11894 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
11895 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
11898 scope_die = scope_die_for (type, context_die);
11900 if (! type_die || (nested && scope_die == comp_unit_die))
11901 /* First occurrence of type or toplevel definition of nested class. */
11903 dw_die_ref old_die = type_die;
11905 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
11906 ? DW_TAG_structure_type : DW_TAG_union_type,
11908 equate_type_number_to_die (type, type_die);
11910 add_AT_specification (type_die, old_die);
11912 add_name_attribute (type_die, type_tag (type));
11915 remove_AT (type_die, DW_AT_declaration);
11917 /* If this type has been completed, then give it a byte_size attribute and
11918 then give a list of members. */
11919 if (complete && !ns_decl)
11921 /* Prevent infinite recursion in cases where the type of some member of
11922 this type is expressed in terms of this type itself. */
11923 TREE_ASM_WRITTEN (type) = 1;
11924 add_byte_size_attribute (type_die, type);
11925 if (TYPE_STUB_DECL (type) != NULL_TREE)
11926 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
11928 /* If the first reference to this type was as the return type of an
11929 inline function, then it may not have a parent. Fix this now. */
11930 if (type_die->die_parent == NULL)
11931 add_child_die (scope_die, type_die);
11933 push_decl_scope (type);
11934 gen_member_die (type, type_die);
11937 /* GNU extension: Record what type our vtable lives in. */
11938 if (TYPE_VFIELD (type))
11940 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
11942 gen_type_die (vtype, context_die);
11943 add_AT_die_ref (type_die, DW_AT_containing_type,
11944 lookup_type_die (vtype));
11949 add_AT_flag (type_die, DW_AT_declaration, 1);
11951 /* We don't need to do this for function-local types. */
11952 if (TYPE_STUB_DECL (type)
11953 && ! decl_function_context (TYPE_STUB_DECL (type)))
11954 VARRAY_PUSH_TREE (incomplete_types, type);
11958 /* Generate a DIE for a subroutine _type_. */
11961 gen_subroutine_type_die (tree type, dw_die_ref context_die)
11963 tree return_type = TREE_TYPE (type);
11964 dw_die_ref subr_die
11965 = new_die (DW_TAG_subroutine_type,
11966 scope_die_for (type, context_die), type);
11968 equate_type_number_to_die (type, subr_die);
11969 add_prototyped_attribute (subr_die, type);
11970 add_type_attribute (subr_die, return_type, 0, 0, context_die);
11971 gen_formal_types_die (type, subr_die);
11974 /* Generate a DIE for a type definition. */
11977 gen_typedef_die (tree decl, dw_die_ref context_die)
11979 dw_die_ref type_die;
11982 if (TREE_ASM_WRITTEN (decl))
11985 TREE_ASM_WRITTEN (decl) = 1;
11986 type_die = new_die (DW_TAG_typedef, context_die, decl);
11987 origin = decl_ultimate_origin (decl);
11988 if (origin != NULL)
11989 add_abstract_origin_attribute (type_die, origin);
11994 add_name_and_src_coords_attributes (type_die, decl);
11995 if (DECL_ORIGINAL_TYPE (decl))
11997 type = DECL_ORIGINAL_TYPE (decl);
11999 gcc_assert (type != TREE_TYPE (decl));
12000 equate_type_number_to_die (TREE_TYPE (decl), type_die);
12003 type = TREE_TYPE (decl);
12005 add_type_attribute (type_die, type, TREE_READONLY (decl),
12006 TREE_THIS_VOLATILE (decl), context_die);
12009 if (DECL_ABSTRACT (decl))
12010 equate_decl_number_to_die (decl, type_die);
12013 /* Generate a type description DIE. */
12016 gen_type_die (tree type, dw_die_ref context_die)
12020 if (type == NULL_TREE || type == error_mark_node)
12023 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12024 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
12026 if (TREE_ASM_WRITTEN (type))
12029 /* Prevent broken recursion; we can't hand off to the same type. */
12030 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
12032 TREE_ASM_WRITTEN (type) = 1;
12033 gen_decl_die (TYPE_NAME (type), context_die);
12037 /* We are going to output a DIE to represent the unqualified version
12038 of this type (i.e. without any const or volatile qualifiers) so
12039 get the main variant (i.e. the unqualified version) of this type
12040 now. (Vectors are special because the debugging info is in the
12041 cloned type itself). */
12042 if (TREE_CODE (type) != VECTOR_TYPE)
12043 type = type_main_variant (type);
12045 if (TREE_ASM_WRITTEN (type))
12048 switch (TREE_CODE (type))
12054 case REFERENCE_TYPE:
12055 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
12056 ensures that the gen_type_die recursion will terminate even if the
12057 type is recursive. Recursive types are possible in Ada. */
12058 /* ??? We could perhaps do this for all types before the switch
12060 TREE_ASM_WRITTEN (type) = 1;
12062 /* For these types, all that is required is that we output a DIE (or a
12063 set of DIEs) to represent the "basis" type. */
12064 gen_type_die (TREE_TYPE (type), context_die);
12068 /* This code is used for C++ pointer-to-data-member types.
12069 Output a description of the relevant class type. */
12070 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
12072 /* Output a description of the type of the object pointed to. */
12073 gen_type_die (TREE_TYPE (type), context_die);
12075 /* Now output a DIE to represent this pointer-to-data-member type
12077 gen_ptr_to_mbr_type_die (type, context_die);
12081 gen_type_die (TYPE_DOMAIN (type), context_die);
12082 gen_set_type_die (type, context_die);
12086 gen_type_die (TREE_TYPE (type), context_die);
12087 /* No way to represent these in Dwarf yet! */
12088 gcc_unreachable ();
12091 case FUNCTION_TYPE:
12092 /* Force out return type (in case it wasn't forced out already). */
12093 gen_type_die (TREE_TYPE (type), context_die);
12094 gen_subroutine_type_die (type, context_die);
12098 /* Force out return type (in case it wasn't forced out already). */
12099 gen_type_die (TREE_TYPE (type), context_die);
12100 gen_subroutine_type_die (type, context_die);
12104 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
12106 gen_type_die (TREE_TYPE (type), context_die);
12107 gen_string_type_die (type, context_die);
12110 gen_array_type_die (type, context_die);
12114 gen_array_type_die (type, context_die);
12117 case ENUMERAL_TYPE:
12120 case QUAL_UNION_TYPE:
12121 /* If this is a nested type whose containing class hasn't been written
12122 out yet, writing it out will cover this one, too. This does not apply
12123 to instantiations of member class templates; they need to be added to
12124 the containing class as they are generated. FIXME: This hurts the
12125 idea of combining type decls from multiple TUs, since we can't predict
12126 what set of template instantiations we'll get. */
12127 if (TYPE_CONTEXT (type)
12128 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
12129 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
12131 gen_type_die (TYPE_CONTEXT (type), context_die);
12133 if (TREE_ASM_WRITTEN (type))
12136 /* If that failed, attach ourselves to the stub. */
12137 push_decl_scope (TYPE_CONTEXT (type));
12138 context_die = lookup_type_die (TYPE_CONTEXT (type));
12143 declare_in_namespace (type, context_die);
12147 if (TREE_CODE (type) == ENUMERAL_TYPE)
12148 gen_enumeration_type_die (type, context_die);
12150 gen_struct_or_union_type_die (type, context_die);
12155 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
12156 it up if it is ever completed. gen_*_type_die will set it for us
12157 when appropriate. */
12166 /* No DIEs needed for fundamental types. */
12170 /* No Dwarf representation currently defined. */
12174 gcc_unreachable ();
12177 TREE_ASM_WRITTEN (type) = 1;
12180 /* Generate a DIE for a tagged type instantiation. */
12183 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
12185 if (type == NULL_TREE || type == error_mark_node)
12188 /* We are going to output a DIE to represent the unqualified version of
12189 this type (i.e. without any const or volatile qualifiers) so make sure
12190 that we have the main variant (i.e. the unqualified version) of this
12192 gcc_assert (type == type_main_variant (type));
12194 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
12195 an instance of an unresolved type. */
12197 switch (TREE_CODE (type))
12202 case ENUMERAL_TYPE:
12203 gen_inlined_enumeration_type_die (type, context_die);
12207 gen_inlined_structure_type_die (type, context_die);
12211 case QUAL_UNION_TYPE:
12212 gen_inlined_union_type_die (type, context_die);
12216 gcc_unreachable ();
12220 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
12221 things which are local to the given block. */
12224 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
12226 int must_output_die = 0;
12229 enum tree_code origin_code;
12231 /* Ignore blocks never really used to make RTL. */
12232 if (stmt == NULL_TREE || !TREE_USED (stmt)
12233 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
12236 /* If the block is one fragment of a non-contiguous block, do not
12237 process the variables, since they will have been done by the
12238 origin block. Do process subblocks. */
12239 if (BLOCK_FRAGMENT_ORIGIN (stmt))
12243 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
12244 gen_block_die (sub, context_die, depth + 1);
12249 /* Determine the "ultimate origin" of this block. This block may be an
12250 inlined instance of an inlined instance of inline function, so we have
12251 to trace all of the way back through the origin chain to find out what
12252 sort of node actually served as the original seed for the creation of
12253 the current block. */
12254 origin = block_ultimate_origin (stmt);
12255 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
12257 /* Determine if we need to output any Dwarf DIEs at all to represent this
12259 if (origin_code == FUNCTION_DECL)
12260 /* The outer scopes for inlinings *must* always be represented. We
12261 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
12262 must_output_die = 1;
12265 /* In the case where the current block represents an inlining of the
12266 "body block" of an inline function, we must *NOT* output any DIE for
12267 this block because we have already output a DIE to represent the whole
12268 inlined function scope and the "body block" of any function doesn't
12269 really represent a different scope according to ANSI C rules. So we
12270 check here to make sure that this block does not represent a "body
12271 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
12272 if (! is_body_block (origin ? origin : stmt))
12274 /* Determine if this block directly contains any "significant"
12275 local declarations which we will need to output DIEs for. */
12276 if (debug_info_level > DINFO_LEVEL_TERSE)
12277 /* We are not in terse mode so *any* local declaration counts
12278 as being a "significant" one. */
12279 must_output_die = (BLOCK_VARS (stmt) != NULL);
12281 /* We are in terse mode, so only local (nested) function
12282 definitions count as "significant" local declarations. */
12283 for (decl = BLOCK_VARS (stmt);
12284 decl != NULL; decl = TREE_CHAIN (decl))
12285 if (TREE_CODE (decl) == FUNCTION_DECL
12286 && DECL_INITIAL (decl))
12288 must_output_die = 1;
12294 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
12295 DIE for any block which contains no significant local declarations at
12296 all. Rather, in such cases we just call `decls_for_scope' so that any
12297 needed Dwarf info for any sub-blocks will get properly generated. Note
12298 that in terse mode, our definition of what constitutes a "significant"
12299 local declaration gets restricted to include only inlined function
12300 instances and local (nested) function definitions. */
12301 if (must_output_die)
12303 if (origin_code == FUNCTION_DECL)
12304 gen_inlined_subroutine_die (stmt, context_die, depth);
12306 gen_lexical_block_die (stmt, context_die, depth);
12309 decls_for_scope (stmt, context_die, depth);
12312 /* Generate all of the decls declared within a given scope and (recursively)
12313 all of its sub-blocks. */
12316 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
12321 /* Ignore blocks never really used to make RTL. */
12322 if (stmt == NULL_TREE || ! TREE_USED (stmt))
12325 /* Output the DIEs to represent all of the data objects and typedefs
12326 declared directly within this block but not within any nested
12327 sub-blocks. Also, nested function and tag DIEs have been
12328 generated with a parent of NULL; fix that up now. */
12329 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
12333 if (TREE_CODE (decl) == FUNCTION_DECL)
12334 die = lookup_decl_die (decl);
12335 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
12336 die = lookup_type_die (TREE_TYPE (decl));
12340 if (die != NULL && die->die_parent == NULL)
12341 add_child_die (context_die, die);
12343 gen_decl_die (decl, context_die);
12346 /* If we're at -g1, we're not interested in subblocks. */
12347 if (debug_info_level <= DINFO_LEVEL_TERSE)
12350 /* Output the DIEs to represent all sub-blocks (and the items declared
12351 therein) of this block. */
12352 for (subblocks = BLOCK_SUBBLOCKS (stmt);
12354 subblocks = BLOCK_CHAIN (subblocks))
12355 gen_block_die (subblocks, context_die, depth + 1);
12358 /* Is this a typedef we can avoid emitting? */
12361 is_redundant_typedef (tree decl)
12363 if (TYPE_DECL_IS_STUB (decl))
12366 if (DECL_ARTIFICIAL (decl)
12367 && DECL_CONTEXT (decl)
12368 && is_tagged_type (DECL_CONTEXT (decl))
12369 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
12370 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
12371 /* Also ignore the artificial member typedef for the class name. */
12377 /* Returns the DIE for decl or aborts. */
12380 force_decl_die (tree decl)
12382 dw_die_ref decl_die;
12383 unsigned saved_external_flag;
12384 tree save_fn = NULL_TREE;
12385 decl_die = lookup_decl_die (decl);
12388 dw_die_ref context_die;
12389 tree decl_context = DECL_CONTEXT (decl);
12392 /* Find die that represents this context. */
12393 if (TYPE_P (decl_context))
12394 context_die = force_type_die (decl_context);
12396 context_die = force_decl_die (decl_context);
12399 context_die = comp_unit_die;
12401 switch (TREE_CODE (decl))
12403 case FUNCTION_DECL:
12404 /* Clear current_function_decl, so that gen_subprogram_die thinks
12405 that this is a declaration. At this point, we just want to force
12406 declaration die. */
12407 save_fn = current_function_decl;
12408 current_function_decl = NULL_TREE;
12409 gen_subprogram_die (decl, context_die);
12410 current_function_decl = save_fn;
12414 /* Set external flag to force declaration die. Restore it after
12415 gen_decl_die() call. */
12416 saved_external_flag = DECL_EXTERNAL (decl);
12417 DECL_EXTERNAL (decl) = 1;
12418 gen_decl_die (decl, context_die);
12419 DECL_EXTERNAL (decl) = saved_external_flag;
12422 case NAMESPACE_DECL:
12423 dwarf2out_decl (decl);
12427 gcc_unreachable ();
12430 /* See if we can find the die for this deci now.
12431 If not then abort. */
12433 decl_die = lookup_decl_die (decl);
12434 gcc_assert (decl_die);
12440 /* Returns the DIE for decl or aborts. */
12443 force_type_die (tree type)
12445 dw_die_ref type_die;
12447 type_die = lookup_type_die (type);
12450 dw_die_ref context_die;
12451 if (TYPE_CONTEXT (type))
12452 if (TYPE_P (TYPE_CONTEXT (type)))
12453 context_die = force_type_die (TYPE_CONTEXT (type));
12455 context_die = force_decl_die (TYPE_CONTEXT (type));
12457 context_die = comp_unit_die;
12459 gen_type_die (type, context_die);
12460 type_die = lookup_type_die (type);
12461 gcc_assert (type_die);
12466 /* Force out any required namespaces to be able to output DECL,
12467 and return the new context_die for it, if it's changed. */
12470 setup_namespace_context (tree thing, dw_die_ref context_die)
12472 tree context = (DECL_P (thing)
12473 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
12474 if (context && TREE_CODE (context) == NAMESPACE_DECL)
12475 /* Force out the namespace. */
12476 context_die = force_decl_die (context);
12478 return context_die;
12481 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
12482 type) within its namespace, if appropriate.
12484 For compatibility with older debuggers, namespace DIEs only contain
12485 declarations; all definitions are emitted at CU scope. */
12488 declare_in_namespace (tree thing, dw_die_ref context_die)
12490 dw_die_ref ns_context;
12492 if (debug_info_level <= DINFO_LEVEL_TERSE)
12495 ns_context = setup_namespace_context (thing, context_die);
12497 if (ns_context != context_die)
12499 if (DECL_P (thing))
12500 gen_decl_die (thing, ns_context);
12502 gen_type_die (thing, ns_context);
12506 /* Generate a DIE for a namespace or namespace alias. */
12509 gen_namespace_die (tree decl)
12511 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
12513 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
12514 they are an alias of. */
12515 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
12517 /* Output a real namespace. */
12518 dw_die_ref namespace_die
12519 = new_die (DW_TAG_namespace, context_die, decl);
12520 add_name_and_src_coords_attributes (namespace_die, decl);
12521 equate_decl_number_to_die (decl, namespace_die);
12525 /* Output a namespace alias. */
12527 /* Force out the namespace we are an alias of, if necessary. */
12528 dw_die_ref origin_die
12529 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
12531 /* Now create the namespace alias DIE. */
12532 dw_die_ref namespace_die
12533 = new_die (DW_TAG_imported_declaration, context_die, decl);
12534 add_name_and_src_coords_attributes (namespace_die, decl);
12535 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
12536 equate_decl_number_to_die (decl, namespace_die);
12540 /* Generate Dwarf debug information for a decl described by DECL. */
12543 gen_decl_die (tree decl, dw_die_ref context_die)
12547 if (DECL_P (decl) && DECL_IGNORED_P (decl))
12550 switch (TREE_CODE (decl))
12556 /* The individual enumerators of an enum type get output when we output
12557 the Dwarf representation of the relevant enum type itself. */
12560 case FUNCTION_DECL:
12561 /* Don't output any DIEs to represent mere function declarations,
12562 unless they are class members or explicit block externs. */
12563 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
12564 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
12569 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
12570 on local redeclarations of global functions. That seems broken. */
12571 if (current_function_decl != decl)
12572 /* This is only a declaration. */;
12575 /* If we're emitting a clone, emit info for the abstract instance. */
12576 if (DECL_ORIGIN (decl) != decl)
12577 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
12579 /* If we're emitting an out-of-line copy of an inline function,
12580 emit info for the abstract instance and set up to refer to it. */
12581 else if (cgraph_function_possibly_inlined_p (decl)
12582 && ! DECL_ABSTRACT (decl)
12583 && ! class_or_namespace_scope_p (context_die)
12584 /* dwarf2out_abstract_function won't emit a die if this is just
12585 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
12586 that case, because that works only if we have a die. */
12587 && DECL_INITIAL (decl) != NULL_TREE)
12589 dwarf2out_abstract_function (decl);
12590 set_decl_origin_self (decl);
12593 /* Otherwise we're emitting the primary DIE for this decl. */
12594 else if (debug_info_level > DINFO_LEVEL_TERSE)
12596 /* Before we describe the FUNCTION_DECL itself, make sure that we
12597 have described its return type. */
12598 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
12600 /* And its virtual context. */
12601 if (DECL_VINDEX (decl) != NULL_TREE)
12602 gen_type_die (DECL_CONTEXT (decl), context_die);
12604 /* And its containing type. */
12605 origin = decl_class_context (decl);
12606 if (origin != NULL_TREE)
12607 gen_type_die_for_member (origin, decl, context_die);
12609 /* And its containing namespace. */
12610 declare_in_namespace (decl, context_die);
12613 /* Now output a DIE to represent the function itself. */
12614 gen_subprogram_die (decl, context_die);
12618 /* If we are in terse mode, don't generate any DIEs to represent any
12619 actual typedefs. */
12620 if (debug_info_level <= DINFO_LEVEL_TERSE)
12623 /* In the special case of a TYPE_DECL node representing the declaration
12624 of some type tag, if the given TYPE_DECL is marked as having been
12625 instantiated from some other (original) TYPE_DECL node (e.g. one which
12626 was generated within the original definition of an inline function) we
12627 have to generate a special (abbreviated) DW_TAG_structure_type,
12628 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
12629 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
12631 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
12635 if (is_redundant_typedef (decl))
12636 gen_type_die (TREE_TYPE (decl), context_die);
12638 /* Output a DIE to represent the typedef itself. */
12639 gen_typedef_die (decl, context_die);
12643 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12644 gen_label_die (decl, context_die);
12649 /* If we are in terse mode, don't generate any DIEs to represent any
12650 variable declarations or definitions. */
12651 if (debug_info_level <= DINFO_LEVEL_TERSE)
12654 /* Output any DIEs that are needed to specify the type of this data
12656 gen_type_die (TREE_TYPE (decl), context_die);
12658 /* And its containing type. */
12659 origin = decl_class_context (decl);
12660 if (origin != NULL_TREE)
12661 gen_type_die_for_member (origin, decl, context_die);
12663 /* And its containing namespace. */
12664 declare_in_namespace (decl, context_die);
12666 /* Now output the DIE to represent the data object itself. This gets
12667 complicated because of the possibility that the VAR_DECL really
12668 represents an inlined instance of a formal parameter for an inline
12670 origin = decl_ultimate_origin (decl);
12671 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
12672 gen_formal_parameter_die (decl, context_die);
12674 gen_variable_die (decl, context_die);
12678 /* Ignore the nameless fields that are used to skip bits but handle C++
12679 anonymous unions and structs. */
12680 if (DECL_NAME (decl) != NULL_TREE
12681 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
12682 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
12684 gen_type_die (member_declared_type (decl), context_die);
12685 gen_field_die (decl, context_die);
12690 gen_type_die (TREE_TYPE (decl), context_die);
12691 gen_formal_parameter_die (decl, context_die);
12694 case NAMESPACE_DECL:
12695 gen_namespace_die (decl);
12699 /* Probably some frontend-internal decl. Assume we don't care. */
12700 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
12705 /* Add Ada "use" clause information for SGI Workshop debugger. */
12708 dwarf2out_add_library_unit_info (const char *filename, const char *context_list)
12710 unsigned int file_index;
12712 if (filename != NULL)
12714 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
12715 tree context_list_decl
12716 = build_decl (LABEL_DECL, get_identifier (context_list),
12719 TREE_PUBLIC (context_list_decl) = TRUE;
12720 add_name_attribute (unit_die, context_list);
12721 file_index = lookup_filename (filename);
12722 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
12723 add_pubname (context_list_decl, unit_die);
12727 /* Output debug information for global decl DECL. Called from toplev.c after
12728 compilation proper has finished. */
12731 dwarf2out_global_decl (tree decl)
12733 /* Output DWARF2 information for file-scope tentative data object
12734 declarations, file-scope (extern) function declarations (which had no
12735 corresponding body) and file-scope tagged type declarations and
12736 definitions which have not yet been forced out. */
12737 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
12738 dwarf2out_decl (decl);
12741 /* Output debug information for type decl DECL. Called from toplev.c
12742 and from language front ends (to record built-in types). */
12744 dwarf2out_type_decl (tree decl, int local)
12747 dwarf2out_decl (decl);
12750 /* Output debug information for imported module or decl. */
12753 dwarf2out_imported_module_or_decl (tree decl, tree context)
12755 dw_die_ref imported_die, at_import_die;
12756 dw_die_ref scope_die;
12757 unsigned file_index;
12758 expanded_location xloc;
12760 if (debug_info_level <= DINFO_LEVEL_TERSE)
12765 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
12766 We need decl DIE for reference and scope die. First, get DIE for the decl
12769 /* Get the scope die for decl context. Use comp_unit_die for global module
12770 or decl. If die is not found for non globals, force new die. */
12772 scope_die = comp_unit_die;
12773 else if (TYPE_P (context))
12774 scope_die = force_type_die (context);
12776 scope_die = force_decl_die (context);
12778 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
12779 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
12780 at_import_die = force_type_die (TREE_TYPE (decl));
12782 at_import_die = force_decl_die (decl);
12784 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
12785 if (TREE_CODE (decl) == NAMESPACE_DECL)
12786 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
12788 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
12790 xloc = expand_location (input_location);
12791 file_index = lookup_filename (xloc.file);
12792 add_AT_unsigned (imported_die, DW_AT_decl_file, file_index);
12793 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
12794 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
12797 /* Write the debugging output for DECL. */
12800 dwarf2out_decl (tree decl)
12802 dw_die_ref context_die = comp_unit_die;
12804 switch (TREE_CODE (decl))
12809 case FUNCTION_DECL:
12810 /* What we would really like to do here is to filter out all mere
12811 file-scope declarations of file-scope functions which are never
12812 referenced later within this translation unit (and keep all of ones
12813 that *are* referenced later on) but we aren't clairvoyant, so we have
12814 no idea which functions will be referenced in the future (i.e. later
12815 on within the current translation unit). So here we just ignore all
12816 file-scope function declarations which are not also definitions. If
12817 and when the debugger needs to know something about these functions,
12818 it will have to hunt around and find the DWARF information associated
12819 with the definition of the function.
12821 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
12822 nodes represent definitions and which ones represent mere
12823 declarations. We have to check DECL_INITIAL instead. That's because
12824 the C front-end supports some weird semantics for "extern inline"
12825 function definitions. These can get inlined within the current
12826 translation unit (an thus, we need to generate Dwarf info for their
12827 abstract instances so that the Dwarf info for the concrete inlined
12828 instances can have something to refer to) but the compiler never
12829 generates any out-of-lines instances of such things (despite the fact
12830 that they *are* definitions).
12832 The important point is that the C front-end marks these "extern
12833 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
12834 them anyway. Note that the C++ front-end also plays some similar games
12835 for inline function definitions appearing within include files which
12836 also contain `#pragma interface' pragmas. */
12837 if (DECL_INITIAL (decl) == NULL_TREE)
12840 /* If we're a nested function, initially use a parent of NULL; if we're
12841 a plain function, this will be fixed up in decls_for_scope. If
12842 we're a method, it will be ignored, since we already have a DIE. */
12843 if (decl_function_context (decl)
12844 /* But if we're in terse mode, we don't care about scope. */
12845 && debug_info_level > DINFO_LEVEL_TERSE)
12846 context_die = NULL;
12850 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
12851 declaration and if the declaration was never even referenced from
12852 within this entire compilation unit. We suppress these DIEs in
12853 order to save space in the .debug section (by eliminating entries
12854 which are probably useless). Note that we must not suppress
12855 block-local extern declarations (whether used or not) because that
12856 would screw-up the debugger's name lookup mechanism and cause it to
12857 miss things which really ought to be in scope at a given point. */
12858 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
12861 /* If we are in terse mode, don't generate any DIEs to represent any
12862 variable declarations or definitions. */
12863 if (debug_info_level <= DINFO_LEVEL_TERSE)
12867 case NAMESPACE_DECL:
12868 if (debug_info_level <= DINFO_LEVEL_TERSE)
12870 if (lookup_decl_die (decl) != NULL)
12875 /* Don't emit stubs for types unless they are needed by other DIEs. */
12876 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
12879 /* Don't bother trying to generate any DIEs to represent any of the
12880 normal built-in types for the language we are compiling. */
12881 if (DECL_IS_BUILTIN (decl))
12883 /* OK, we need to generate one for `bool' so GDB knows what type
12884 comparisons have. */
12885 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
12886 == DW_LANG_C_plus_plus)
12887 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
12888 && ! DECL_IGNORED_P (decl))
12889 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
12894 /* If we are in terse mode, don't generate any DIEs for types. */
12895 if (debug_info_level <= DINFO_LEVEL_TERSE)
12898 /* If we're a function-scope tag, initially use a parent of NULL;
12899 this will be fixed up in decls_for_scope. */
12900 if (decl_function_context (decl))
12901 context_die = NULL;
12909 gen_decl_die (decl, context_die);
12912 /* Output a marker (i.e. a label) for the beginning of the generated code for
12913 a lexical block. */
12916 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
12917 unsigned int blocknum)
12919 function_section (current_function_decl);
12920 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
12923 /* Output a marker (i.e. a label) for the end of the generated code for a
12927 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
12929 function_section (current_function_decl);
12930 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
12933 /* Returns nonzero if it is appropriate not to emit any debugging
12934 information for BLOCK, because it doesn't contain any instructions.
12936 Don't allow this for blocks with nested functions or local classes
12937 as we would end up with orphans, and in the presence of scheduling
12938 we may end up calling them anyway. */
12941 dwarf2out_ignore_block (tree block)
12945 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
12946 if (TREE_CODE (decl) == FUNCTION_DECL
12947 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
12953 /* Lookup FILE_NAME (in the list of filenames that we know about here in
12954 dwarf2out.c) and return its "index". The index of each (known) filename is
12955 just a unique number which is associated with only that one filename. We
12956 need such numbers for the sake of generating labels (in the .debug_sfnames
12957 section) and references to those files numbers (in the .debug_srcinfo
12958 and.debug_macinfo sections). If the filename given as an argument is not
12959 found in our current list, add it to the list and assign it the next
12960 available unique index number. In order to speed up searches, we remember
12961 the index of the filename was looked up last. This handles the majority of
12965 lookup_filename (const char *file_name)
12968 char *save_file_name;
12970 /* Check to see if the file name that was searched on the previous
12971 call matches this file name. If so, return the index. */
12972 if (file_table_last_lookup_index != 0)
12975 = VARRAY_CHAR_PTR (file_table, file_table_last_lookup_index);
12976 if (strcmp (file_name, last) == 0)
12977 return file_table_last_lookup_index;
12980 /* Didn't match the previous lookup, search the table. */
12981 n = VARRAY_ACTIVE_SIZE (file_table);
12982 for (i = 1; i < n; i++)
12983 if (strcmp (file_name, VARRAY_CHAR_PTR (file_table, i)) == 0)
12985 file_table_last_lookup_index = i;
12989 /* Add the new entry to the end of the filename table. */
12990 file_table_last_lookup_index = n;
12991 save_file_name = (char *) ggc_strdup (file_name);
12992 VARRAY_PUSH_CHAR_PTR (file_table, save_file_name);
12993 VARRAY_PUSH_UINT (file_table_emitted, 0);
12999 maybe_emit_file (int fileno)
13001 if (DWARF2_ASM_LINE_DEBUG_INFO && fileno > 0)
13003 if (!VARRAY_UINT (file_table_emitted, fileno))
13005 VARRAY_UINT (file_table_emitted, fileno) = ++emitcount;
13006 fprintf (asm_out_file, "\t.file %u ",
13007 VARRAY_UINT (file_table_emitted, fileno));
13008 output_quoted_string (asm_out_file,
13009 VARRAY_CHAR_PTR (file_table, fileno));
13010 fputc ('\n', asm_out_file);
13012 return VARRAY_UINT (file_table_emitted, fileno);
13019 init_file_table (void)
13021 /* Allocate the initial hunk of the file_table. */
13022 VARRAY_CHAR_PTR_INIT (file_table, 64, "file_table");
13023 VARRAY_UINT_INIT (file_table_emitted, 64, "file_table_emitted");
13025 /* Skip the first entry - file numbers begin at 1. */
13026 VARRAY_PUSH_CHAR_PTR (file_table, NULL);
13027 VARRAY_PUSH_UINT (file_table_emitted, 0);
13028 file_table_last_lookup_index = 0;
13031 /* Called by the final INSN scan whenever we see a var location. We
13032 use it to drop labels in the right places, and throw the location in
13033 our lookup table. */
13036 dwarf2out_var_location (rtx loc_note)
13038 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
13039 struct var_loc_node *newloc;
13041 static rtx last_insn;
13042 static const char *last_label;
13044 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
13046 prev_insn = PREV_INSN (loc_note);
13048 newloc = ggc_alloc_cleared (sizeof (struct var_loc_node));
13049 /* If the insn we processed last time is the previous insn
13050 and it is also a var location note, use the label we emitted
13052 if (last_insn != NULL_RTX
13053 && last_insn == prev_insn
13054 && NOTE_P (prev_insn)
13055 && NOTE_LINE_NUMBER (prev_insn) == NOTE_INSN_VAR_LOCATION)
13057 newloc->label = last_label;
13061 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
13062 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
13064 newloc->label = ggc_strdup (loclabel);
13066 newloc->var_loc_note = loc_note;
13067 newloc->next = NULL;
13069 last_insn = loc_note;
13070 last_label = newloc->label;
13072 add_var_loc_to_decl (NOTE_VAR_LOCATION_DECL (loc_note), newloc);
13075 /* We need to reset the locations at the beginning of each
13076 function. We can't do this in the end_function hook, because the
13077 declarations that use the locations won't have been outputted when
13078 that hook is called. */
13081 dwarf2out_begin_function (tree unused ATTRIBUTE_UNUSED)
13083 htab_empty (decl_loc_table);
13086 /* Output a label to mark the beginning of a source code line entry
13087 and record information relating to this source line, in
13088 'line_info_table' for later output of the .debug_line section. */
13091 dwarf2out_source_line (unsigned int line, const char *filename)
13093 if (debug_info_level >= DINFO_LEVEL_NORMAL
13096 function_section (current_function_decl);
13098 /* If requested, emit something human-readable. */
13099 if (flag_debug_asm)
13100 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
13103 if (DWARF2_ASM_LINE_DEBUG_INFO)
13105 unsigned file_num = lookup_filename (filename);
13107 file_num = maybe_emit_file (file_num);
13109 /* Emit the .loc directive understood by GNU as. */
13110 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
13112 /* Indicate that line number info exists. */
13113 line_info_table_in_use++;
13115 /* Indicate that multiple line number tables exist. */
13116 if (DECL_SECTION_NAME (current_function_decl))
13117 separate_line_info_table_in_use++;
13119 else if (DECL_SECTION_NAME (current_function_decl))
13121 dw_separate_line_info_ref line_info;
13122 targetm.asm_out.internal_label (asm_out_file, SEPARATE_LINE_CODE_LABEL,
13123 separate_line_info_table_in_use);
13125 /* Expand the line info table if necessary. */
13126 if (separate_line_info_table_in_use
13127 == separate_line_info_table_allocated)
13129 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
13130 separate_line_info_table
13131 = ggc_realloc (separate_line_info_table,
13132 separate_line_info_table_allocated
13133 * sizeof (dw_separate_line_info_entry));
13134 memset (separate_line_info_table
13135 + separate_line_info_table_in_use,
13137 (LINE_INFO_TABLE_INCREMENT
13138 * sizeof (dw_separate_line_info_entry)));
13141 /* Add the new entry at the end of the line_info_table. */
13143 = &separate_line_info_table[separate_line_info_table_in_use++];
13144 line_info->dw_file_num = lookup_filename (filename);
13145 line_info->dw_line_num = line;
13146 line_info->function = current_function_funcdef_no;
13150 dw_line_info_ref line_info;
13152 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
13153 line_info_table_in_use);
13155 /* Expand the line info table if necessary. */
13156 if (line_info_table_in_use == line_info_table_allocated)
13158 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
13160 = ggc_realloc (line_info_table,
13161 (line_info_table_allocated
13162 * sizeof (dw_line_info_entry)));
13163 memset (line_info_table + line_info_table_in_use, 0,
13164 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
13167 /* Add the new entry at the end of the line_info_table. */
13168 line_info = &line_info_table[line_info_table_in_use++];
13169 line_info->dw_file_num = lookup_filename (filename);
13170 line_info->dw_line_num = line;
13175 /* Record the beginning of a new source file. */
13178 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
13180 if (flag_eliminate_dwarf2_dups)
13182 /* Record the beginning of the file for break_out_includes. */
13183 dw_die_ref bincl_die;
13185 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
13186 add_AT_string (bincl_die, DW_AT_name, filename);
13189 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13191 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13192 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
13193 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
13195 maybe_emit_file (lookup_filename (filename));
13196 dw2_asm_output_data_uleb128 (lookup_filename (filename),
13197 "Filename we just started");
13201 /* Record the end of a source file. */
13204 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
13206 if (flag_eliminate_dwarf2_dups)
13207 /* Record the end of the file for break_out_includes. */
13208 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
13210 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13212 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13213 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
13217 /* Called from debug_define in toplev.c. The `buffer' parameter contains
13218 the tail part of the directive line, i.e. the part which is past the
13219 initial whitespace, #, whitespace, directive-name, whitespace part. */
13222 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
13223 const char *buffer ATTRIBUTE_UNUSED)
13225 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13227 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13228 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
13229 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
13230 dw2_asm_output_nstring (buffer, -1, "The macro");
13234 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
13235 the tail part of the directive line, i.e. the part which is past the
13236 initial whitespace, #, whitespace, directive-name, whitespace part. */
13239 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
13240 const char *buffer ATTRIBUTE_UNUSED)
13242 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13244 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13245 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
13246 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
13247 dw2_asm_output_nstring (buffer, -1, "The macro");
13251 /* Set up for Dwarf output at the start of compilation. */
13254 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
13256 init_file_table ();
13258 /* Allocate the decl_die_table. */
13259 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
13260 decl_die_table_eq, NULL);
13262 /* Allocate the decl_loc_table. */
13263 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
13264 decl_loc_table_eq, NULL);
13266 /* Allocate the initial hunk of the decl_scope_table. */
13267 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
13269 /* Allocate the initial hunk of the abbrev_die_table. */
13270 abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
13271 * sizeof (dw_die_ref));
13272 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
13273 /* Zero-th entry is allocated, but unused. */
13274 abbrev_die_table_in_use = 1;
13276 /* Allocate the initial hunk of the line_info_table. */
13277 line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
13278 * sizeof (dw_line_info_entry));
13279 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
13281 /* Zero-th entry is allocated, but unused. */
13282 line_info_table_in_use = 1;
13284 /* Generate the initial DIE for the .debug section. Note that the (string)
13285 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
13286 will (typically) be a relative pathname and that this pathname should be
13287 taken as being relative to the directory from which the compiler was
13288 invoked when the given (base) source file was compiled. We will fill
13289 in this value in dwarf2out_finish. */
13290 comp_unit_die = gen_compile_unit_die (NULL);
13292 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
13294 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
13296 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
13297 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
13298 DEBUG_ABBREV_SECTION_LABEL, 0);
13299 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
13301 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
13302 DEBUG_INFO_SECTION_LABEL, 0);
13303 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
13304 DEBUG_LINE_SECTION_LABEL, 0);
13305 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
13306 DEBUG_RANGES_SECTION_LABEL, 0);
13307 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
13308 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
13309 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
13310 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
13311 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
13312 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
13314 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13316 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13317 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
13318 DEBUG_MACINFO_SECTION_LABEL, 0);
13319 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
13323 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
13326 /* A helper function for dwarf2out_finish called through
13327 ht_forall. Emit one queued .debug_str string. */
13330 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
13332 struct indirect_string_node *node = (struct indirect_string_node *) *h;
13334 if (node->form == DW_FORM_strp)
13336 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
13337 ASM_OUTPUT_LABEL (asm_out_file, node->label);
13338 assemble_string (node->str, strlen (node->str) + 1);
13346 /* Clear the marks for a die and its children.
13347 Be cool if the mark isn't set. */
13350 prune_unmark_dies (dw_die_ref die)
13354 for (c = die->die_child; c; c = c->die_sib)
13355 prune_unmark_dies (c);
13359 /* Given DIE that we're marking as used, find any other dies
13360 it references as attributes and mark them as used. */
13363 prune_unused_types_walk_attribs (dw_die_ref die)
13367 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
13369 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
13371 /* A reference to another DIE.
13372 Make sure that it will get emitted. */
13373 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
13375 else if (a->dw_attr == DW_AT_decl_file)
13377 /* A reference to a file. Make sure the file name is emitted. */
13378 a->dw_attr_val.v.val_unsigned =
13379 maybe_emit_file (a->dw_attr_val.v.val_unsigned);
13385 /* Mark DIE as being used. If DOKIDS is true, then walk down
13386 to DIE's children. */
13389 prune_unused_types_mark (dw_die_ref die, int dokids)
13393 if (die->die_mark == 0)
13395 /* We haven't done this node yet. Mark it as used. */
13398 /* We also have to mark its parents as used.
13399 (But we don't want to mark our parents' kids due to this.) */
13400 if (die->die_parent)
13401 prune_unused_types_mark (die->die_parent, 0);
13403 /* Mark any referenced nodes. */
13404 prune_unused_types_walk_attribs (die);
13406 /* If this node is a specification,
13407 also mark the definition, if it exists. */
13408 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
13409 prune_unused_types_mark (die->die_definition, 1);
13412 if (dokids && die->die_mark != 2)
13414 /* We need to walk the children, but haven't done so yet.
13415 Remember that we've walked the kids. */
13419 for (c = die->die_child; c; c = c->die_sib)
13421 /* If this is an array type, we need to make sure our
13422 kids get marked, even if they're types. */
13423 if (die->die_tag == DW_TAG_array_type)
13424 prune_unused_types_mark (c, 1);
13426 prune_unused_types_walk (c);
13432 /* Walk the tree DIE and mark types that we actually use. */
13435 prune_unused_types_walk (dw_die_ref die)
13439 /* Don't do anything if this node is already marked. */
13443 switch (die->die_tag) {
13444 case DW_TAG_const_type:
13445 case DW_TAG_packed_type:
13446 case DW_TAG_pointer_type:
13447 case DW_TAG_reference_type:
13448 case DW_TAG_volatile_type:
13449 case DW_TAG_typedef:
13450 case DW_TAG_array_type:
13451 case DW_TAG_structure_type:
13452 case DW_TAG_union_type:
13453 case DW_TAG_class_type:
13454 case DW_TAG_friend:
13455 case DW_TAG_variant_part:
13456 case DW_TAG_enumeration_type:
13457 case DW_TAG_subroutine_type:
13458 case DW_TAG_string_type:
13459 case DW_TAG_set_type:
13460 case DW_TAG_subrange_type:
13461 case DW_TAG_ptr_to_member_type:
13462 case DW_TAG_file_type:
13463 /* It's a type node --- don't mark it. */
13467 /* Mark everything else. */
13473 /* Now, mark any dies referenced from here. */
13474 prune_unused_types_walk_attribs (die);
13476 /* Mark children. */
13477 for (c = die->die_child; c; c = c->die_sib)
13478 prune_unused_types_walk (c);
13482 /* Remove from the tree DIE any dies that aren't marked. */
13485 prune_unused_types_prune (dw_die_ref die)
13487 dw_die_ref c, p, n;
13489 gcc_assert (die->die_mark);
13492 for (c = die->die_child; c; c = n)
13497 prune_unused_types_prune (c);
13505 die->die_child = n;
13512 /* Remove dies representing declarations that we never use. */
13515 prune_unused_types (void)
13518 limbo_die_node *node;
13520 /* Clear all the marks. */
13521 prune_unmark_dies (comp_unit_die);
13522 for (node = limbo_die_list; node; node = node->next)
13523 prune_unmark_dies (node->die);
13525 /* Set the mark on nodes that are actually used. */
13526 prune_unused_types_walk (comp_unit_die);
13527 for (node = limbo_die_list; node; node = node->next)
13528 prune_unused_types_walk (node->die);
13530 /* Also set the mark on nodes referenced from the
13531 pubname_table or arange_table. */
13532 for (i = 0; i < pubname_table_in_use; i++)
13533 prune_unused_types_mark (pubname_table[i].die, 1);
13534 for (i = 0; i < arange_table_in_use; i++)
13535 prune_unused_types_mark (arange_table[i], 1);
13537 /* Get rid of nodes that aren't marked. */
13538 prune_unused_types_prune (comp_unit_die);
13539 for (node = limbo_die_list; node; node = node->next)
13540 prune_unused_types_prune (node->die);
13542 /* Leave the marks clear. */
13543 prune_unmark_dies (comp_unit_die);
13544 for (node = limbo_die_list; node; node = node->next)
13545 prune_unmark_dies (node->die);
13548 /* Output stuff that dwarf requires at the end of every file,
13549 and generate the DWARF-2 debugging info. */
13552 dwarf2out_finish (const char *filename)
13554 limbo_die_node *node, *next_node;
13555 dw_die_ref die = 0;
13557 /* Add the name for the main input file now. We delayed this from
13558 dwarf2out_init to avoid complications with PCH. */
13559 add_name_attribute (comp_unit_die, filename);
13560 if (filename[0] != DIR_SEPARATOR)
13561 add_comp_dir_attribute (comp_unit_die);
13562 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
13565 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
13566 if (VARRAY_CHAR_PTR (file_table, i)[0] != DIR_SEPARATOR
13567 /* Don't add cwd for <built-in>. */
13568 && VARRAY_CHAR_PTR (file_table, i)[0] != '<')
13570 add_comp_dir_attribute (comp_unit_die);
13575 /* Traverse the limbo die list, and add parent/child links. The only
13576 dies without parents that should be here are concrete instances of
13577 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
13578 For concrete instances, we can get the parent die from the abstract
13580 for (node = limbo_die_list; node; node = next_node)
13582 next_node = node->next;
13585 if (die->die_parent == NULL)
13587 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
13590 add_child_die (origin->die_parent, die);
13591 else if (die == comp_unit_die)
13593 else if (errorcount > 0 || sorrycount > 0)
13594 /* It's OK to be confused by errors in the input. */
13595 add_child_die (comp_unit_die, die);
13598 /* In certain situations, the lexical block containing a
13599 nested function can be optimized away, which results
13600 in the nested function die being orphaned. Likewise
13601 with the return type of that nested function. Force
13602 this to be a child of the containing function.
13604 It may happen that even the containing function got fully
13605 inlined and optimized out. In that case we are lost and
13606 assign the empty child. This should not be big issue as
13607 the function is likely unreachable too. */
13608 tree context = NULL_TREE;
13610 gcc_assert (node->created_for);
13612 if (DECL_P (node->created_for))
13613 context = DECL_CONTEXT (node->created_for);
13614 else if (TYPE_P (node->created_for))
13615 context = TYPE_CONTEXT (node->created_for);
13617 gcc_assert (context && TREE_CODE (context) == FUNCTION_DECL);
13619 origin = lookup_decl_die (context);
13621 add_child_die (origin, die);
13623 add_child_die (comp_unit_die, die);
13628 limbo_die_list = NULL;
13630 /* Walk through the list of incomplete types again, trying once more to
13631 emit full debugging info for them. */
13632 retry_incomplete_types ();
13634 /* We need to reverse all the dies before break_out_includes, or
13635 we'll see the end of an include file before the beginning. */
13636 reverse_all_dies (comp_unit_die);
13638 if (flag_eliminate_unused_debug_types)
13639 prune_unused_types ();
13641 /* Generate separate CUs for each of the include files we've seen.
13642 They will go into limbo_die_list. */
13643 if (flag_eliminate_dwarf2_dups)
13644 break_out_includes (comp_unit_die);
13646 /* Traverse the DIE's and add add sibling attributes to those DIE's
13647 that have children. */
13648 add_sibling_attributes (comp_unit_die);
13649 for (node = limbo_die_list; node; node = node->next)
13650 add_sibling_attributes (node->die);
13652 /* Output a terminator label for the .text section. */
13654 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
13656 /* Output the source line correspondence table. We must do this
13657 even if there is no line information. Otherwise, on an empty
13658 translation unit, we will generate a present, but empty,
13659 .debug_info section. IRIX 6.5 `nm' will then complain when
13660 examining the file. */
13661 if (! DWARF2_ASM_LINE_DEBUG_INFO)
13663 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
13664 output_line_info ();
13667 /* Output location list section if necessary. */
13668 if (have_location_lists)
13670 /* Output the location lists info. */
13671 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
13672 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
13673 DEBUG_LOC_SECTION_LABEL, 0);
13674 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
13675 output_location_lists (die);
13676 have_location_lists = 0;
13679 /* We can only use the low/high_pc attributes if all of the code was
13681 if (separate_line_info_table_in_use == 0)
13683 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
13684 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
13687 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
13688 "base address". Use zero so that these addresses become absolute. */
13689 else if (have_location_lists || ranges_table_in_use)
13690 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
13692 if (debug_info_level >= DINFO_LEVEL_NORMAL)
13693 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
13694 debug_line_section_label);
13696 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13697 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
13699 /* Output all of the compilation units. We put the main one last so that
13700 the offsets are available to output_pubnames. */
13701 for (node = limbo_die_list; node; node = node->next)
13702 output_comp_unit (node->die, 0);
13704 output_comp_unit (comp_unit_die, 0);
13706 /* Output the abbreviation table. */
13707 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
13708 output_abbrev_section ();
13710 /* Output public names table if necessary. */
13711 if (pubname_table_in_use)
13713 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
13714 output_pubnames ();
13717 /* Output the address range information. We only put functions in the arange
13718 table, so don't write it out if we don't have any. */
13719 if (fde_table_in_use)
13721 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
13725 /* Output ranges section if necessary. */
13726 if (ranges_table_in_use)
13728 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
13729 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
13733 /* Have to end the primary source file. */
13734 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13736 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13737 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
13738 dw2_asm_output_data (1, 0, "End compilation unit");
13741 /* If we emitted any DW_FORM_strp form attribute, output the string
13743 if (debug_str_hash)
13744 htab_traverse (debug_str_hash, output_indirect_string, NULL);
13748 /* This should never be used, but its address is needed for comparisons. */
13749 const struct gcc_debug_hooks dwarf2_debug_hooks;
13751 #endif /* DWARF2_DEBUGGING_INFO */
13753 #include "gt-dwarf2out.h"