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, 2005 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, 51 Franklin Street, Fifth Floor, 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 ();
174 DEF_VEC_ALLOC_P(rtx,gc);
176 /* Array of RTXes referenced by the debugging information, which therefore
177 must be kept around forever. */
178 static GTY(()) VEC(rtx,gc) *used_rtx_array;
180 /* A pointer to the base of a list of incomplete types which might be
181 completed at some later time. incomplete_types_list needs to be a
182 VEC(tree,gc) because we want to tell the garbage collector about
184 static GTY(()) VEC(tree,gc) *incomplete_types;
186 /* A pointer to the base of a table of references to declaration
187 scopes. This table is a display which tracks the nesting
188 of declaration scopes at the current scope and containing
189 scopes. This table is used to find the proper place to
190 define type declaration DIE's. */
191 static GTY(()) VEC(tree,gc) *decl_scope_table;
193 /* How to start an assembler comment. */
194 #ifndef ASM_COMMENT_START
195 #define ASM_COMMENT_START ";#"
198 typedef struct dw_cfi_struct *dw_cfi_ref;
199 typedef struct dw_fde_struct *dw_fde_ref;
200 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
202 /* Call frames are described using a sequence of Call Frame
203 Information instructions. The register number, offset
204 and address fields are provided as possible operands;
205 their use is selected by the opcode field. */
207 enum dw_cfi_oprnd_type {
209 dw_cfi_oprnd_reg_num,
215 typedef union dw_cfi_oprnd_struct GTY(())
217 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
218 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
219 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
220 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
224 typedef struct dw_cfi_struct GTY(())
226 dw_cfi_ref dw_cfi_next;
227 enum dwarf_call_frame_info dw_cfi_opc;
228 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
230 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
235 /* This is how we define the location of the CFA. We use to handle it
236 as REG + OFFSET all the time, but now it can be more complex.
237 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
238 Instead of passing around REG and OFFSET, we pass a copy
239 of this structure. */
240 typedef struct cfa_loc GTY(())
242 HOST_WIDE_INT offset;
243 HOST_WIDE_INT base_offset;
245 int indirect; /* 1 if CFA is accessed via a dereference. */
248 /* All call frame descriptions (FDE's) in the GCC generated DWARF
249 refer to a single Common Information Entry (CIE), defined at
250 the beginning of the .debug_frame section. This use of a single
251 CIE obviates the need to keep track of multiple CIE's
252 in the DWARF generation routines below. */
254 typedef struct dw_fde_struct GTY(())
257 const char *dw_fde_begin;
258 const char *dw_fde_current_label;
259 const char *dw_fde_end;
260 const char *dw_fde_hot_section_label;
261 const char *dw_fde_hot_section_end_label;
262 const char *dw_fde_unlikely_section_label;
263 const char *dw_fde_unlikely_section_end_label;
264 bool dw_fde_switched_sections;
265 dw_cfi_ref dw_fde_cfi;
266 unsigned funcdef_number;
267 unsigned all_throwers_are_sibcalls : 1;
268 unsigned nothrow : 1;
269 unsigned uses_eh_lsda : 1;
273 /* Maximum size (in bytes) of an artificially generated label. */
274 #define MAX_ARTIFICIAL_LABEL_BYTES 30
276 /* The size of addresses as they appear in the Dwarf 2 data.
277 Some architectures use word addresses to refer to code locations,
278 but Dwarf 2 info always uses byte addresses. On such machines,
279 Dwarf 2 addresses need to be larger than the architecture's
281 #ifndef DWARF2_ADDR_SIZE
282 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
285 /* The size in bytes of a DWARF field indicating an offset or length
286 relative to a debug info section, specified to be 4 bytes in the
287 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
290 #ifndef DWARF_OFFSET_SIZE
291 #define DWARF_OFFSET_SIZE 4
294 /* According to the (draft) DWARF 3 specification, the initial length
295 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
296 bytes are 0xffffffff, followed by the length stored in the next 8
299 However, the SGI/MIPS ABI uses an initial length which is equal to
300 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
302 #ifndef DWARF_INITIAL_LENGTH_SIZE
303 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
306 #define DWARF_VERSION 2
308 /* Round SIZE up to the nearest BOUNDARY. */
309 #define DWARF_ROUND(SIZE,BOUNDARY) \
310 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
312 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
313 #ifndef DWARF_CIE_DATA_ALIGNMENT
314 #ifdef STACK_GROWS_DOWNWARD
315 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
317 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
321 /* A pointer to the base of a table that contains frame description
322 information for each routine. */
323 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
325 /* Number of elements currently allocated for fde_table. */
326 static GTY(()) unsigned fde_table_allocated;
328 /* Number of elements in fde_table currently in use. */
329 static GTY(()) unsigned fde_table_in_use;
331 /* Size (in elements) of increments by which we may expand the
333 #define FDE_TABLE_INCREMENT 256
335 /* A list of call frame insns for the CIE. */
336 static GTY(()) dw_cfi_ref cie_cfi_head;
338 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
339 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
340 attribute that accelerates the lookup of the FDE associated
341 with the subprogram. This variable holds the table index of the FDE
342 associated with the current function (body) definition. */
343 static unsigned current_funcdef_fde;
346 struct indirect_string_node GTY(())
349 unsigned int refcount;
354 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
356 static GTY(()) int dw2_string_counter;
357 static GTY(()) unsigned long dwarf2out_cfi_label_num;
359 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
361 /* Forward declarations for functions defined in this file. */
363 static char *stripattributes (const char *);
364 static const char *dwarf_cfi_name (unsigned);
365 static dw_cfi_ref new_cfi (void);
366 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
367 static void add_fde_cfi (const char *, dw_cfi_ref);
368 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
369 static void lookup_cfa (dw_cfa_location *);
370 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
371 static void initial_return_save (rtx);
372 static HOST_WIDE_INT stack_adjust_offset (rtx);
373 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
374 static void output_call_frame_info (int);
375 static void dwarf2out_stack_adjust (rtx, bool);
376 static void flush_queued_reg_saves (void);
377 static bool clobbers_queued_reg_save (rtx);
378 static void dwarf2out_frame_debug_expr (rtx, const char *);
380 /* Support for complex CFA locations. */
381 static void output_cfa_loc (dw_cfi_ref);
382 static void get_cfa_from_loc_descr (dw_cfa_location *,
383 struct dw_loc_descr_struct *);
384 static struct dw_loc_descr_struct *build_cfa_loc
386 static void def_cfa_1 (const char *, dw_cfa_location *);
388 /* How to start an assembler comment. */
389 #ifndef ASM_COMMENT_START
390 #define ASM_COMMENT_START ";#"
393 /* Data and reference forms for relocatable data. */
394 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
395 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
397 #ifndef DEBUG_FRAME_SECTION
398 #define DEBUG_FRAME_SECTION ".debug_frame"
401 #ifndef FUNC_BEGIN_LABEL
402 #define FUNC_BEGIN_LABEL "LFB"
405 #ifndef FUNC_END_LABEL
406 #define FUNC_END_LABEL "LFE"
409 #ifndef FRAME_BEGIN_LABEL
410 #define FRAME_BEGIN_LABEL "Lframe"
412 #define CIE_AFTER_SIZE_LABEL "LSCIE"
413 #define CIE_END_LABEL "LECIE"
414 #define FDE_LABEL "LSFDE"
415 #define FDE_AFTER_SIZE_LABEL "LASFDE"
416 #define FDE_END_LABEL "LEFDE"
417 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
418 #define LINE_NUMBER_END_LABEL "LELT"
419 #define LN_PROLOG_AS_LABEL "LASLTP"
420 #define LN_PROLOG_END_LABEL "LELTP"
421 #define DIE_LABEL_PREFIX "DW"
423 /* The DWARF 2 CFA column which tracks the return address. Normally this
424 is the column for PC, or the first column after all of the hard
426 #ifndef DWARF_FRAME_RETURN_COLUMN
428 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
430 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
434 /* The mapping from gcc register number to DWARF 2 CFA column number. By
435 default, we just provide columns for all registers. */
436 #ifndef DWARF_FRAME_REGNUM
437 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
440 /* Hook used by __throw. */
443 expand_builtin_dwarf_sp_column (void)
445 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
448 /* Return a pointer to a copy of the section string name S with all
449 attributes stripped off, and an asterisk prepended (for assemble_name). */
452 stripattributes (const char *s)
454 char *stripped = xmalloc (strlen (s) + 2);
459 while (*s && *s != ',')
466 /* Generate code to initialize the register size table. */
469 expand_builtin_init_dwarf_reg_sizes (tree address)
472 enum machine_mode mode = TYPE_MODE (char_type_node);
473 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
474 rtx mem = gen_rtx_MEM (BLKmode, addr);
475 bool wrote_return_column = false;
477 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
478 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
480 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
481 enum machine_mode save_mode = reg_raw_mode[i];
484 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
485 save_mode = choose_hard_reg_mode (i, 1, true);
486 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
488 if (save_mode == VOIDmode)
490 wrote_return_column = true;
492 size = GET_MODE_SIZE (save_mode);
496 emit_move_insn (adjust_address (mem, mode, offset),
497 gen_int_mode (size, mode));
500 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
501 gcc_assert (wrote_return_column);
502 i = DWARF_ALT_FRAME_RETURN_COLUMN;
503 wrote_return_column = false;
505 i = DWARF_FRAME_RETURN_COLUMN;
508 if (! wrote_return_column)
510 enum machine_mode save_mode = Pmode;
511 HOST_WIDE_INT offset = i * GET_MODE_SIZE (mode);
512 HOST_WIDE_INT size = GET_MODE_SIZE (save_mode);
513 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
517 /* Convert a DWARF call frame info. operation to its string name */
520 dwarf_cfi_name (unsigned int cfi_opc)
524 case DW_CFA_advance_loc:
525 return "DW_CFA_advance_loc";
527 return "DW_CFA_offset";
529 return "DW_CFA_restore";
533 return "DW_CFA_set_loc";
534 case DW_CFA_advance_loc1:
535 return "DW_CFA_advance_loc1";
536 case DW_CFA_advance_loc2:
537 return "DW_CFA_advance_loc2";
538 case DW_CFA_advance_loc4:
539 return "DW_CFA_advance_loc4";
540 case DW_CFA_offset_extended:
541 return "DW_CFA_offset_extended";
542 case DW_CFA_restore_extended:
543 return "DW_CFA_restore_extended";
544 case DW_CFA_undefined:
545 return "DW_CFA_undefined";
546 case DW_CFA_same_value:
547 return "DW_CFA_same_value";
548 case DW_CFA_register:
549 return "DW_CFA_register";
550 case DW_CFA_remember_state:
551 return "DW_CFA_remember_state";
552 case DW_CFA_restore_state:
553 return "DW_CFA_restore_state";
555 return "DW_CFA_def_cfa";
556 case DW_CFA_def_cfa_register:
557 return "DW_CFA_def_cfa_register";
558 case DW_CFA_def_cfa_offset:
559 return "DW_CFA_def_cfa_offset";
562 case DW_CFA_def_cfa_expression:
563 return "DW_CFA_def_cfa_expression";
564 case DW_CFA_expression:
565 return "DW_CFA_expression";
566 case DW_CFA_offset_extended_sf:
567 return "DW_CFA_offset_extended_sf";
568 case DW_CFA_def_cfa_sf:
569 return "DW_CFA_def_cfa_sf";
570 case DW_CFA_def_cfa_offset_sf:
571 return "DW_CFA_def_cfa_offset_sf";
573 /* SGI/MIPS specific */
574 case DW_CFA_MIPS_advance_loc8:
575 return "DW_CFA_MIPS_advance_loc8";
578 case DW_CFA_GNU_window_save:
579 return "DW_CFA_GNU_window_save";
580 case DW_CFA_GNU_args_size:
581 return "DW_CFA_GNU_args_size";
582 case DW_CFA_GNU_negative_offset_extended:
583 return "DW_CFA_GNU_negative_offset_extended";
586 return "DW_CFA_<unknown>";
590 /* Return a pointer to a newly allocated Call Frame Instruction. */
592 static inline dw_cfi_ref
595 dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node));
597 cfi->dw_cfi_next = NULL;
598 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
599 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
604 /* Add a Call Frame Instruction to list of instructions. */
607 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
611 /* Find the end of the chain. */
612 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
618 /* Generate a new label for the CFI info to refer to. */
621 dwarf2out_cfi_label (void)
623 static char label[20];
625 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
626 ASM_OUTPUT_LABEL (asm_out_file, label);
630 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
631 or to the CIE if LABEL is NULL. */
634 add_fde_cfi (const char *label, dw_cfi_ref cfi)
638 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
641 label = dwarf2out_cfi_label ();
643 if (fde->dw_fde_current_label == NULL
644 || strcmp (label, fde->dw_fde_current_label) != 0)
648 fde->dw_fde_current_label = label = xstrdup (label);
650 /* Set the location counter to the new label. */
652 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
653 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
654 add_cfi (&fde->dw_fde_cfi, xcfi);
657 add_cfi (&fde->dw_fde_cfi, cfi);
661 add_cfi (&cie_cfi_head, cfi);
664 /* Subroutine of lookup_cfa. */
667 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
669 switch (cfi->dw_cfi_opc)
671 case DW_CFA_def_cfa_offset:
672 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
674 case DW_CFA_def_cfa_offset_sf:
676 = cfi->dw_cfi_oprnd1.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
678 case DW_CFA_def_cfa_register:
679 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
682 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
683 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
685 case DW_CFA_def_cfa_sf:
686 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
688 = cfi->dw_cfi_oprnd2.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
690 case DW_CFA_def_cfa_expression:
691 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
698 /* Find the previous value for the CFA. */
701 lookup_cfa (dw_cfa_location *loc)
705 loc->reg = INVALID_REGNUM;
708 loc->base_offset = 0;
710 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
711 lookup_cfa_1 (cfi, loc);
713 if (fde_table_in_use)
715 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
716 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
717 lookup_cfa_1 (cfi, loc);
721 /* The current rule for calculating the DWARF2 canonical frame address. */
722 static dw_cfa_location cfa;
724 /* The register used for saving registers to the stack, and its offset
726 static dw_cfa_location cfa_store;
728 /* The running total of the size of arguments pushed onto the stack. */
729 static HOST_WIDE_INT args_size;
731 /* The last args_size we actually output. */
732 static HOST_WIDE_INT old_args_size;
734 /* Entry point to update the canonical frame address (CFA).
735 LABEL is passed to add_fde_cfi. The value of CFA is now to be
736 calculated from REG+OFFSET. */
739 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
746 def_cfa_1 (label, &loc);
749 /* Determine if two dw_cfa_location structures define the same data. */
752 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
754 return (loc1->reg == loc2->reg
755 && loc1->offset == loc2->offset
756 && loc1->indirect == loc2->indirect
757 && (loc1->indirect == 0
758 || loc1->base_offset == loc2->base_offset));
761 /* This routine does the actual work. The CFA is now calculated from
762 the dw_cfa_location structure. */
765 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
768 dw_cfa_location old_cfa, loc;
773 if (cfa_store.reg == loc.reg && loc.indirect == 0)
774 cfa_store.offset = loc.offset;
776 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
777 lookup_cfa (&old_cfa);
779 /* If nothing changed, no need to issue any call frame instructions. */
780 if (cfa_equal_p (&loc, &old_cfa))
785 if (loc.reg == old_cfa.reg && !loc.indirect)
787 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
788 the CFA register did not change but the offset did. */
791 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
792 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
794 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
795 cfi->dw_cfi_oprnd1.dw_cfi_offset = f_offset;
799 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
800 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
804 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
805 else if (loc.offset == old_cfa.offset
806 && old_cfa.reg != INVALID_REGNUM
809 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
810 indicating the CFA register has changed to <register> but the
811 offset has not changed. */
812 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
813 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
817 else if (loc.indirect == 0)
819 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
820 indicating the CFA register has changed to <register> with
821 the specified offset. */
824 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
825 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
827 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
828 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
829 cfi->dw_cfi_oprnd2.dw_cfi_offset = f_offset;
833 cfi->dw_cfi_opc = DW_CFA_def_cfa;
834 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
835 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
840 /* Construct a DW_CFA_def_cfa_expression instruction to
841 calculate the CFA using a full location expression since no
842 register-offset pair is available. */
843 struct dw_loc_descr_struct *loc_list;
845 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
846 loc_list = build_cfa_loc (&loc);
847 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
850 add_fde_cfi (label, cfi);
853 /* Add the CFI for saving a register. REG is the CFA column number.
854 LABEL is passed to add_fde_cfi.
855 If SREG is -1, the register is saved at OFFSET from the CFA;
856 otherwise it is saved in SREG. */
859 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
861 dw_cfi_ref cfi = new_cfi ();
863 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
865 if (sreg == INVALID_REGNUM)
868 /* The register number won't fit in 6 bits, so we have to use
870 cfi->dw_cfi_opc = DW_CFA_offset_extended;
872 cfi->dw_cfi_opc = DW_CFA_offset;
874 #ifdef ENABLE_CHECKING
876 /* If we get an offset that is not a multiple of
877 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
878 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
880 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
882 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
885 offset /= DWARF_CIE_DATA_ALIGNMENT;
887 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
889 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
891 else if (sreg == reg)
892 cfi->dw_cfi_opc = DW_CFA_same_value;
895 cfi->dw_cfi_opc = DW_CFA_register;
896 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
899 add_fde_cfi (label, cfi);
902 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
903 This CFI tells the unwinder that it needs to restore the window registers
904 from the previous frame's window save area.
906 ??? Perhaps we should note in the CIE where windows are saved (instead of
907 assuming 0(cfa)) and what registers are in the window. */
910 dwarf2out_window_save (const char *label)
912 dw_cfi_ref cfi = new_cfi ();
914 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
915 add_fde_cfi (label, cfi);
918 /* Add a CFI to update the running total of the size of arguments
919 pushed onto the stack. */
922 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
926 if (size == old_args_size)
929 old_args_size = size;
932 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
933 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
934 add_fde_cfi (label, cfi);
937 /* Entry point for saving a register to the stack. REG is the GCC register
938 number. LABEL and OFFSET are passed to reg_save. */
941 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
943 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
946 /* Entry point for saving the return address in the stack.
947 LABEL and OFFSET are passed to reg_save. */
950 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
952 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
955 /* Entry point for saving the return address in a register.
956 LABEL and SREG are passed to reg_save. */
959 dwarf2out_return_reg (const char *label, unsigned int sreg)
961 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
964 /* Record the initial position of the return address. RTL is
965 INCOMING_RETURN_ADDR_RTX. */
968 initial_return_save (rtx rtl)
970 unsigned int reg = INVALID_REGNUM;
971 HOST_WIDE_INT offset = 0;
973 switch (GET_CODE (rtl))
976 /* RA is in a register. */
977 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
981 /* RA is on the stack. */
983 switch (GET_CODE (rtl))
986 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
991 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
992 offset = INTVAL (XEXP (rtl, 1));
996 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
997 offset = -INTVAL (XEXP (rtl, 1));
1007 /* The return address is at some offset from any value we can
1008 actually load. For instance, on the SPARC it is in %i7+8. Just
1009 ignore the offset for now; it doesn't matter for unwinding frames. */
1010 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1011 initial_return_save (XEXP (rtl, 0));
1018 if (reg != DWARF_FRAME_RETURN_COLUMN)
1019 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1022 /* Given a SET, calculate the amount of stack adjustment it
1025 static HOST_WIDE_INT
1026 stack_adjust_offset (rtx pattern)
1028 rtx src = SET_SRC (pattern);
1029 rtx dest = SET_DEST (pattern);
1030 HOST_WIDE_INT offset = 0;
1033 if (dest == stack_pointer_rtx)
1035 /* (set (reg sp) (plus (reg sp) (const_int))) */
1036 code = GET_CODE (src);
1037 if (! (code == PLUS || code == MINUS)
1038 || XEXP (src, 0) != stack_pointer_rtx
1039 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1042 offset = INTVAL (XEXP (src, 1));
1046 else if (MEM_P (dest))
1048 /* (set (mem (pre_dec (reg sp))) (foo)) */
1049 src = XEXP (dest, 0);
1050 code = GET_CODE (src);
1056 if (XEXP (src, 0) == stack_pointer_rtx)
1058 rtx val = XEXP (XEXP (src, 1), 1);
1059 /* We handle only adjustments by constant amount. */
1060 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1061 && GET_CODE (val) == CONST_INT);
1062 offset = -INTVAL (val);
1069 if (XEXP (src, 0) == stack_pointer_rtx)
1071 offset = GET_MODE_SIZE (GET_MODE (dest));
1078 if (XEXP (src, 0) == stack_pointer_rtx)
1080 offset = -GET_MODE_SIZE (GET_MODE (dest));
1095 /* Check INSN to see if it looks like a push or a stack adjustment, and
1096 make a note of it if it does. EH uses this information to find out how
1097 much extra space it needs to pop off the stack. */
1100 dwarf2out_stack_adjust (rtx insn, bool after_p)
1102 HOST_WIDE_INT offset;
1106 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1107 with this function. Proper support would require all frame-related
1108 insns to be marked, and to be able to handle saving state around
1109 epilogues textually in the middle of the function. */
1110 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1113 /* If only calls can throw, and we have a frame pointer,
1114 save up adjustments until we see the CALL_INSN. */
1115 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1117 if (CALL_P (insn) && !after_p)
1119 /* Extract the size of the args from the CALL rtx itself. */
1120 insn = PATTERN (insn);
1121 if (GET_CODE (insn) == PARALLEL)
1122 insn = XVECEXP (insn, 0, 0);
1123 if (GET_CODE (insn) == SET)
1124 insn = SET_SRC (insn);
1125 gcc_assert (GET_CODE (insn) == CALL);
1126 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1131 if (CALL_P (insn) && !after_p)
1133 if (!flag_asynchronous_unwind_tables)
1134 dwarf2out_args_size ("", args_size);
1137 else if (BARRIER_P (insn))
1139 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1140 the compiler will have already emitted a stack adjustment, but
1141 doesn't bother for calls to noreturn functions. */
1142 #ifdef STACK_GROWS_DOWNWARD
1143 offset = -args_size;
1148 else if (GET_CODE (PATTERN (insn)) == SET)
1149 offset = stack_adjust_offset (PATTERN (insn));
1150 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1151 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1153 /* There may be stack adjustments inside compound insns. Search
1155 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1156 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1157 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1165 if (cfa.reg == STACK_POINTER_REGNUM)
1166 cfa.offset += offset;
1168 #ifndef STACK_GROWS_DOWNWARD
1172 args_size += offset;
1176 label = dwarf2out_cfi_label ();
1177 def_cfa_1 (label, &cfa);
1178 if (flag_asynchronous_unwind_tables)
1179 dwarf2out_args_size (label, args_size);
1184 /* We delay emitting a register save until either (a) we reach the end
1185 of the prologue or (b) the register is clobbered. This clusters
1186 register saves so that there are fewer pc advances. */
1188 struct queued_reg_save GTY(())
1190 struct queued_reg_save *next;
1192 HOST_WIDE_INT cfa_offset;
1196 static GTY(()) struct queued_reg_save *queued_reg_saves;
1198 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1199 struct reg_saved_in_data GTY(()) {
1204 /* A list of registers saved in other registers.
1205 The list intentionally has a small maximum capacity of 4; if your
1206 port needs more than that, you might consider implementing a
1207 more efficient data structure. */
1208 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1209 static GTY(()) size_t num_regs_saved_in_regs;
1211 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1212 static const char *last_reg_save_label;
1214 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1215 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1218 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1220 struct queued_reg_save *q;
1222 /* Duplicates waste space, but it's also necessary to remove them
1223 for correctness, since the queue gets output in reverse
1225 for (q = queued_reg_saves; q != NULL; q = q->next)
1226 if (REGNO (q->reg) == REGNO (reg))
1231 q = ggc_alloc (sizeof (*q));
1232 q->next = queued_reg_saves;
1233 queued_reg_saves = q;
1237 q->cfa_offset = offset;
1238 q->saved_reg = sreg;
1240 last_reg_save_label = label;
1243 /* Output all the entries in QUEUED_REG_SAVES. */
1246 flush_queued_reg_saves (void)
1248 struct queued_reg_save *q;
1250 for (q = queued_reg_saves; q; q = q->next)
1253 unsigned int reg, sreg;
1255 for (i = 0; i < num_regs_saved_in_regs; i++)
1256 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1258 if (q->saved_reg && i == num_regs_saved_in_regs)
1260 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1261 num_regs_saved_in_regs++;
1263 if (i != num_regs_saved_in_regs)
1265 regs_saved_in_regs[i].orig_reg = q->reg;
1266 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1269 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1271 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1273 sreg = INVALID_REGNUM;
1274 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1277 queued_reg_saves = NULL;
1278 last_reg_save_label = NULL;
1281 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1282 location for? Or, does it clobber a register which we've previously
1283 said that some other register is saved in, and for which we now
1284 have a new location for? */
1287 clobbers_queued_reg_save (rtx insn)
1289 struct queued_reg_save *q;
1291 for (q = queued_reg_saves; q; q = q->next)
1294 if (modified_in_p (q->reg, insn))
1296 for (i = 0; i < num_regs_saved_in_regs; i++)
1297 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1298 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1305 /* Entry point for saving the first register into the second. */
1308 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1311 unsigned int regno, sregno;
1313 for (i = 0; i < num_regs_saved_in_regs; i++)
1314 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1316 if (i == num_regs_saved_in_regs)
1318 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1319 num_regs_saved_in_regs++;
1321 regs_saved_in_regs[i].orig_reg = reg;
1322 regs_saved_in_regs[i].saved_in_reg = sreg;
1324 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1325 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1326 reg_save (label, regno, sregno, 0);
1329 /* What register, if any, is currently saved in REG? */
1332 reg_saved_in (rtx reg)
1334 unsigned int regn = REGNO (reg);
1336 struct queued_reg_save *q;
1338 for (q = queued_reg_saves; q; q = q->next)
1339 if (q->saved_reg && regn == REGNO (q->saved_reg))
1342 for (i = 0; i < num_regs_saved_in_regs; i++)
1343 if (regs_saved_in_regs[i].saved_in_reg
1344 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1345 return regs_saved_in_regs[i].orig_reg;
1351 /* A temporary register holding an integral value used in adjusting SP
1352 or setting up the store_reg. The "offset" field holds the integer
1353 value, not an offset. */
1354 static dw_cfa_location cfa_temp;
1356 /* Record call frame debugging information for an expression EXPR,
1357 which either sets SP or FP (adjusting how we calculate the frame
1358 address) or saves a register to the stack or another register.
1359 LABEL indicates the address of EXPR.
1361 This function encodes a state machine mapping rtxes to actions on
1362 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1363 users need not read the source code.
1365 The High-Level Picture
1367 Changes in the register we use to calculate the CFA: Currently we
1368 assume that if you copy the CFA register into another register, we
1369 should take the other one as the new CFA register; this seems to
1370 work pretty well. If it's wrong for some target, it's simple
1371 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1373 Changes in the register we use for saving registers to the stack:
1374 This is usually SP, but not always. Again, we deduce that if you
1375 copy SP into another register (and SP is not the CFA register),
1376 then the new register is the one we will be using for register
1377 saves. This also seems to work.
1379 Register saves: There's not much guesswork about this one; if
1380 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1381 register save, and the register used to calculate the destination
1382 had better be the one we think we're using for this purpose.
1383 It's also assumed that a copy from a call-saved register to another
1384 register is saving that register if RTX_FRAME_RELATED_P is set on
1385 that instruction. If the copy is from a call-saved register to
1386 the *same* register, that means that the register is now the same
1387 value as in the caller.
1389 Except: If the register being saved is the CFA register, and the
1390 offset is nonzero, we are saving the CFA, so we assume we have to
1391 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1392 the intent is to save the value of SP from the previous frame.
1394 In addition, if a register has previously been saved to a different
1397 Invariants / Summaries of Rules
1399 cfa current rule for calculating the CFA. It usually
1400 consists of a register and an offset.
1401 cfa_store register used by prologue code to save things to the stack
1402 cfa_store.offset is the offset from the value of
1403 cfa_store.reg to the actual CFA
1404 cfa_temp register holding an integral value. cfa_temp.offset
1405 stores the value, which will be used to adjust the
1406 stack pointer. cfa_temp is also used like cfa_store,
1407 to track stores to the stack via fp or a temp reg.
1409 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1410 with cfa.reg as the first operand changes the cfa.reg and its
1411 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1414 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1415 expression yielding a constant. This sets cfa_temp.reg
1416 and cfa_temp.offset.
1418 Rule 5: Create a new register cfa_store used to save items to the
1421 Rules 10-14: Save a register to the stack. Define offset as the
1422 difference of the original location and cfa_store's
1423 location (or cfa_temp's location if cfa_temp is used).
1427 "{a,b}" indicates a choice of a xor b.
1428 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1431 (set <reg1> <reg2>:cfa.reg)
1432 effects: cfa.reg = <reg1>
1433 cfa.offset unchanged
1434 cfa_temp.reg = <reg1>
1435 cfa_temp.offset = cfa.offset
1438 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1439 {<const_int>,<reg>:cfa_temp.reg}))
1440 effects: cfa.reg = sp if fp used
1441 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1442 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1443 if cfa_store.reg==sp
1446 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1447 effects: cfa.reg = fp
1448 cfa_offset += +/- <const_int>
1451 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1452 constraints: <reg1> != fp
1454 effects: cfa.reg = <reg1>
1455 cfa_temp.reg = <reg1>
1456 cfa_temp.offset = cfa.offset
1459 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1460 constraints: <reg1> != fp
1462 effects: cfa_store.reg = <reg1>
1463 cfa_store.offset = cfa.offset - cfa_temp.offset
1466 (set <reg> <const_int>)
1467 effects: cfa_temp.reg = <reg>
1468 cfa_temp.offset = <const_int>
1471 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1472 effects: cfa_temp.reg = <reg1>
1473 cfa_temp.offset |= <const_int>
1476 (set <reg> (high <exp>))
1480 (set <reg> (lo_sum <exp> <const_int>))
1481 effects: cfa_temp.reg = <reg>
1482 cfa_temp.offset = <const_int>
1485 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1486 effects: cfa_store.offset -= <const_int>
1487 cfa.offset = cfa_store.offset if cfa.reg == sp
1489 cfa.base_offset = -cfa_store.offset
1492 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1493 effects: cfa_store.offset += -/+ mode_size(mem)
1494 cfa.offset = cfa_store.offset if cfa.reg == sp
1496 cfa.base_offset = -cfa_store.offset
1499 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1502 effects: cfa.reg = <reg1>
1503 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1506 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1507 effects: cfa.reg = <reg1>
1508 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1511 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1512 effects: cfa.reg = <reg1>
1513 cfa.base_offset = -cfa_temp.offset
1514 cfa_temp.offset -= mode_size(mem)
1517 Â (set <reg> {unspec, unspec_volatile})
1518 Â effects: target-dependent */
1521 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1524 HOST_WIDE_INT offset;
1526 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1527 the PARALLEL independently. The first element is always processed if
1528 it is a SET. This is for backward compatibility. Other elements
1529 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1530 flag is set in them. */
1531 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1534 int limit = XVECLEN (expr, 0);
1536 for (par_index = 0; par_index < limit; par_index++)
1537 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1538 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1540 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1545 gcc_assert (GET_CODE (expr) == SET);
1547 src = SET_SRC (expr);
1548 dest = SET_DEST (expr);
1552 rtx rsi = reg_saved_in (src);
1557 switch (GET_CODE (dest))
1560 switch (GET_CODE (src))
1562 /* Setting FP from SP. */
1564 if (cfa.reg == (unsigned) REGNO (src))
1567 /* Update the CFA rule wrt SP or FP. Make sure src is
1568 relative to the current CFA register.
1570 We used to require that dest be either SP or FP, but the
1571 ARM copies SP to a temporary register, and from there to
1572 FP. So we just rely on the backends to only set
1573 RTX_FRAME_RELATED_P on appropriate insns. */
1574 cfa.reg = REGNO (dest);
1575 cfa_temp.reg = cfa.reg;
1576 cfa_temp.offset = cfa.offset;
1580 /* Saving a register in a register. */
1581 gcc_assert (call_used_regs [REGNO (dest)]
1582 && (!fixed_regs [REGNO (dest)]
1583 /* For the SPARC and its register window. */
1584 || DWARF_FRAME_REGNUM (REGNO (src))
1585 == DWARF_FRAME_RETURN_COLUMN));
1586 queue_reg_save (label, src, dest, 0);
1593 if (dest == stack_pointer_rtx)
1597 switch (GET_CODE (XEXP (src, 1)))
1600 offset = INTVAL (XEXP (src, 1));
1603 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1605 offset = cfa_temp.offset;
1611 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1613 /* Restoring SP from FP in the epilogue. */
1614 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1615 cfa.reg = STACK_POINTER_REGNUM;
1617 else if (GET_CODE (src) == LO_SUM)
1618 /* Assume we've set the source reg of the LO_SUM from sp. */
1621 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1623 if (GET_CODE (src) != MINUS)
1625 if (cfa.reg == STACK_POINTER_REGNUM)
1626 cfa.offset += offset;
1627 if (cfa_store.reg == STACK_POINTER_REGNUM)
1628 cfa_store.offset += offset;
1630 else if (dest == hard_frame_pointer_rtx)
1633 /* Either setting the FP from an offset of the SP,
1634 or adjusting the FP */
1635 gcc_assert (frame_pointer_needed);
1637 gcc_assert (REG_P (XEXP (src, 0))
1638 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1639 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1640 offset = INTVAL (XEXP (src, 1));
1641 if (GET_CODE (src) != MINUS)
1643 cfa.offset += offset;
1644 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1648 gcc_assert (GET_CODE (src) != MINUS);
1651 if (REG_P (XEXP (src, 0))
1652 && REGNO (XEXP (src, 0)) == cfa.reg
1653 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1655 /* Setting a temporary CFA register that will be copied
1656 into the FP later on. */
1657 offset = - INTVAL (XEXP (src, 1));
1658 cfa.offset += offset;
1659 cfa.reg = REGNO (dest);
1660 /* Or used to save regs to the stack. */
1661 cfa_temp.reg = cfa.reg;
1662 cfa_temp.offset = cfa.offset;
1666 else if (REG_P (XEXP (src, 0))
1667 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1668 && XEXP (src, 1) == stack_pointer_rtx)
1670 /* Setting a scratch register that we will use instead
1671 of SP for saving registers to the stack. */
1672 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1673 cfa_store.reg = REGNO (dest);
1674 cfa_store.offset = cfa.offset - cfa_temp.offset;
1678 else if (GET_CODE (src) == LO_SUM
1679 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1681 cfa_temp.reg = REGNO (dest);
1682 cfa_temp.offset = INTVAL (XEXP (src, 1));
1691 cfa_temp.reg = REGNO (dest);
1692 cfa_temp.offset = INTVAL (src);
1697 gcc_assert (REG_P (XEXP (src, 0))
1698 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1699 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1701 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1702 cfa_temp.reg = REGNO (dest);
1703 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1706 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1707 which will fill in all of the bits. */
1714 case UNSPEC_VOLATILE:
1715 gcc_assert (targetm.dwarf_handle_frame_unspec);
1716 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
1723 def_cfa_1 (label, &cfa);
1727 gcc_assert (REG_P (src));
1729 /* Saving a register to the stack. Make sure dest is relative to the
1731 switch (GET_CODE (XEXP (dest, 0)))
1736 /* We can't handle variable size modifications. */
1737 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1739 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1741 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1742 && cfa_store.reg == STACK_POINTER_REGNUM);
1744 cfa_store.offset += offset;
1745 if (cfa.reg == STACK_POINTER_REGNUM)
1746 cfa.offset = cfa_store.offset;
1748 offset = -cfa_store.offset;
1754 offset = GET_MODE_SIZE (GET_MODE (dest));
1755 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1758 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1759 && cfa_store.reg == STACK_POINTER_REGNUM);
1761 cfa_store.offset += offset;
1762 if (cfa.reg == STACK_POINTER_REGNUM)
1763 cfa.offset = cfa_store.offset;
1765 offset = -cfa_store.offset;
1769 /* With an offset. */
1776 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
1777 && REG_P (XEXP (XEXP (dest, 0), 0)));
1778 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1779 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1782 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1784 if (cfa_store.reg == (unsigned) regno)
1785 offset -= cfa_store.offset;
1788 gcc_assert (cfa_temp.reg == (unsigned) regno);
1789 offset -= cfa_temp.offset;
1795 /* Without an offset. */
1798 int regno = REGNO (XEXP (dest, 0));
1800 if (cfa_store.reg == (unsigned) regno)
1801 offset = -cfa_store.offset;
1804 gcc_assert (cfa_temp.reg == (unsigned) regno);
1805 offset = -cfa_temp.offset;
1812 gcc_assert (cfa_temp.reg
1813 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1814 offset = -cfa_temp.offset;
1815 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1822 if (REGNO (src) != STACK_POINTER_REGNUM
1823 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1824 && (unsigned) REGNO (src) == cfa.reg)
1826 /* We're storing the current CFA reg into the stack. */
1828 if (cfa.offset == 0)
1830 /* If the source register is exactly the CFA, assume
1831 we're saving SP like any other register; this happens
1833 def_cfa_1 (label, &cfa);
1834 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1839 /* Otherwise, we'll need to look in the stack to
1840 calculate the CFA. */
1841 rtx x = XEXP (dest, 0);
1845 gcc_assert (REG_P (x));
1847 cfa.reg = REGNO (x);
1848 cfa.base_offset = offset;
1850 def_cfa_1 (label, &cfa);
1855 def_cfa_1 (label, &cfa);
1856 queue_reg_save (label, src, NULL_RTX, offset);
1864 /* Record call frame debugging information for INSN, which either
1865 sets SP or FP (adjusting how we calculate the frame address) or saves a
1866 register to the stack. If INSN is NULL_RTX, initialize our state.
1868 If AFTER_P is false, we're being called before the insn is emitted,
1869 otherwise after. Call instructions get invoked twice. */
1872 dwarf2out_frame_debug (rtx insn, bool after_p)
1877 if (insn == NULL_RTX)
1881 /* Flush any queued register saves. */
1882 flush_queued_reg_saves ();
1884 /* Set up state for generating call frame debug info. */
1887 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1889 cfa.reg = STACK_POINTER_REGNUM;
1892 cfa_temp.offset = 0;
1894 for (i = 0; i < num_regs_saved_in_regs; i++)
1896 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1897 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1899 num_regs_saved_in_regs = 0;
1903 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1904 flush_queued_reg_saves ();
1906 if (! RTX_FRAME_RELATED_P (insn))
1908 if (!ACCUMULATE_OUTGOING_ARGS)
1909 dwarf2out_stack_adjust (insn, after_p);
1913 label = dwarf2out_cfi_label ();
1914 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1916 insn = XEXP (src, 0);
1918 insn = PATTERN (insn);
1920 dwarf2out_frame_debug_expr (insn, label);
1925 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1926 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1927 (enum dwarf_call_frame_info cfi);
1929 static enum dw_cfi_oprnd_type
1930 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1935 case DW_CFA_GNU_window_save:
1936 return dw_cfi_oprnd_unused;
1938 case DW_CFA_set_loc:
1939 case DW_CFA_advance_loc1:
1940 case DW_CFA_advance_loc2:
1941 case DW_CFA_advance_loc4:
1942 case DW_CFA_MIPS_advance_loc8:
1943 return dw_cfi_oprnd_addr;
1946 case DW_CFA_offset_extended:
1947 case DW_CFA_def_cfa:
1948 case DW_CFA_offset_extended_sf:
1949 case DW_CFA_def_cfa_sf:
1950 case DW_CFA_restore_extended:
1951 case DW_CFA_undefined:
1952 case DW_CFA_same_value:
1953 case DW_CFA_def_cfa_register:
1954 case DW_CFA_register:
1955 return dw_cfi_oprnd_reg_num;
1957 case DW_CFA_def_cfa_offset:
1958 case DW_CFA_GNU_args_size:
1959 case DW_CFA_def_cfa_offset_sf:
1960 return dw_cfi_oprnd_offset;
1962 case DW_CFA_def_cfa_expression:
1963 case DW_CFA_expression:
1964 return dw_cfi_oprnd_loc;
1971 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1972 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1973 (enum dwarf_call_frame_info cfi);
1975 static enum dw_cfi_oprnd_type
1976 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1980 case DW_CFA_def_cfa:
1981 case DW_CFA_def_cfa_sf:
1983 case DW_CFA_offset_extended_sf:
1984 case DW_CFA_offset_extended:
1985 return dw_cfi_oprnd_offset;
1987 case DW_CFA_register:
1988 return dw_cfi_oprnd_reg_num;
1991 return dw_cfi_oprnd_unused;
1995 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1997 /* Map register numbers held in the call frame info that gcc has
1998 collected using DWARF_FRAME_REGNUM to those that should be output in
1999 .debug_frame and .eh_frame. */
2000 #ifndef DWARF2_FRAME_REG_OUT
2001 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
2004 /* Output a Call Frame Information opcode and its operand(s). */
2007 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2010 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2011 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2012 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2013 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2014 cfi->dw_cfi_oprnd1.dw_cfi_offset);
2015 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2017 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2018 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2019 "DW_CFA_offset, column 0x%lx", r);
2020 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2022 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2024 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2025 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2026 "DW_CFA_restore, column 0x%lx", r);
2030 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2031 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2033 switch (cfi->dw_cfi_opc)
2035 case DW_CFA_set_loc:
2037 dw2_asm_output_encoded_addr_rtx (
2038 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2039 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2042 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2043 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2046 case DW_CFA_advance_loc1:
2047 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2048 fde->dw_fde_current_label, NULL);
2049 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2052 case DW_CFA_advance_loc2:
2053 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2054 fde->dw_fde_current_label, NULL);
2055 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2058 case DW_CFA_advance_loc4:
2059 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2060 fde->dw_fde_current_label, NULL);
2061 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2064 case DW_CFA_MIPS_advance_loc8:
2065 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2066 fde->dw_fde_current_label, NULL);
2067 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2070 case DW_CFA_offset_extended:
2071 case DW_CFA_def_cfa:
2072 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2073 dw2_asm_output_data_uleb128 (r, NULL);
2074 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2077 case DW_CFA_offset_extended_sf:
2078 case DW_CFA_def_cfa_sf:
2079 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2080 dw2_asm_output_data_uleb128 (r, NULL);
2081 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2084 case DW_CFA_restore_extended:
2085 case DW_CFA_undefined:
2086 case DW_CFA_same_value:
2087 case DW_CFA_def_cfa_register:
2088 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2089 dw2_asm_output_data_uleb128 (r, NULL);
2092 case DW_CFA_register:
2093 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2094 dw2_asm_output_data_uleb128 (r, NULL);
2095 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2096 dw2_asm_output_data_uleb128 (r, NULL);
2099 case DW_CFA_def_cfa_offset:
2100 case DW_CFA_GNU_args_size:
2101 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2104 case DW_CFA_def_cfa_offset_sf:
2105 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2108 case DW_CFA_GNU_window_save:
2111 case DW_CFA_def_cfa_expression:
2112 case DW_CFA_expression:
2113 output_cfa_loc (cfi);
2116 case DW_CFA_GNU_negative_offset_extended:
2117 /* Obsoleted by DW_CFA_offset_extended_sf. */
2126 /* Output the call frame information used to record information
2127 that relates to calculating the frame pointer, and records the
2128 location of saved registers. */
2131 output_call_frame_info (int for_eh)
2136 char l1[20], l2[20], section_start_label[20];
2137 bool any_lsda_needed = false;
2138 char augmentation[6];
2139 int augmentation_size;
2140 int fde_encoding = DW_EH_PE_absptr;
2141 int per_encoding = DW_EH_PE_absptr;
2142 int lsda_encoding = DW_EH_PE_absptr;
2145 /* Don't emit a CIE if there won't be any FDEs. */
2146 if (fde_table_in_use == 0)
2149 /* If we make FDEs linkonce, we may have to emit an empty label for
2150 an FDE that wouldn't otherwise be emitted. We want to avoid
2151 having an FDE kept around when the function it refers to is
2152 discarded. Example where this matters: a primary function
2153 template in C++ requires EH information, but an explicit
2154 specialization doesn't. */
2155 if (TARGET_USES_WEAK_UNWIND_INFO
2156 && ! flag_asynchronous_unwind_tables
2158 for (i = 0; i < fde_table_in_use; i++)
2159 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2160 && !fde_table[i].uses_eh_lsda
2161 && ! DECL_WEAK (fde_table[i].decl))
2162 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2163 for_eh, /* empty */ 1);
2165 /* If we don't have any functions we'll want to unwind out of, don't
2166 emit any EH unwind information. Note that if exceptions aren't
2167 enabled, we won't have collected nothrow information, and if we
2168 asked for asynchronous tables, we always want this info. */
2171 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2173 for (i = 0; i < fde_table_in_use; i++)
2174 if (fde_table[i].uses_eh_lsda)
2175 any_eh_needed = any_lsda_needed = true;
2176 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2177 any_eh_needed = true;
2178 else if (! fde_table[i].nothrow
2179 && ! fde_table[i].all_throwers_are_sibcalls)
2180 any_eh_needed = true;
2182 if (! any_eh_needed)
2186 /* We're going to be generating comments, so turn on app. */
2191 targetm.asm_out.eh_frame_section ();
2193 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
2195 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2196 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2198 /* Output the CIE. */
2199 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2200 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2201 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2202 "Length of Common Information Entry");
2203 ASM_OUTPUT_LABEL (asm_out_file, l1);
2205 /* Now that the CIE pointer is PC-relative for EH,
2206 use 0 to identify the CIE. */
2207 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2208 (for_eh ? 0 : DW_CIE_ID),
2209 "CIE Identifier Tag");
2211 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2213 augmentation[0] = 0;
2214 augmentation_size = 0;
2220 z Indicates that a uleb128 is present to size the
2221 augmentation section.
2222 L Indicates the encoding (and thus presence) of
2223 an LSDA pointer in the FDE augmentation.
2224 R Indicates a non-default pointer encoding for
2226 P Indicates the presence of an encoding + language
2227 personality routine in the CIE augmentation. */
2229 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2230 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2231 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2233 p = augmentation + 1;
2234 if (eh_personality_libfunc)
2237 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2239 if (any_lsda_needed)
2242 augmentation_size += 1;
2244 if (fde_encoding != DW_EH_PE_absptr)
2247 augmentation_size += 1;
2249 if (p > augmentation + 1)
2251 augmentation[0] = 'z';
2255 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2256 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2258 int offset = ( 4 /* Length */
2260 + 1 /* CIE version */
2261 + strlen (augmentation) + 1 /* Augmentation */
2262 + size_of_uleb128 (1) /* Code alignment */
2263 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2265 + 1 /* Augmentation size */
2266 + 1 /* Personality encoding */ );
2267 int pad = -offset & (PTR_SIZE - 1);
2269 augmentation_size += pad;
2271 /* Augmentations should be small, so there's scarce need to
2272 iterate for a solution. Die if we exceed one uleb128 byte. */
2273 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2277 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2278 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2279 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2280 "CIE Data Alignment Factor");
2282 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2283 if (DW_CIE_VERSION == 1)
2284 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2286 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2288 if (augmentation[0])
2290 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2291 if (eh_personality_libfunc)
2293 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2294 eh_data_format_name (per_encoding));
2295 dw2_asm_output_encoded_addr_rtx (per_encoding,
2296 eh_personality_libfunc,
2300 if (any_lsda_needed)
2301 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2302 eh_data_format_name (lsda_encoding));
2304 if (fde_encoding != DW_EH_PE_absptr)
2305 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2306 eh_data_format_name (fde_encoding));
2309 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2310 output_cfi (cfi, NULL, for_eh);
2312 /* Pad the CIE out to an address sized boundary. */
2313 ASM_OUTPUT_ALIGN (asm_out_file,
2314 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2315 ASM_OUTPUT_LABEL (asm_out_file, l2);
2317 /* Loop through all of the FDE's. */
2318 for (i = 0; i < fde_table_in_use; i++)
2320 fde = &fde_table[i];
2322 /* Don't emit EH unwind info for leaf functions that don't need it. */
2323 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2324 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2325 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2326 && !fde->uses_eh_lsda)
2329 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2330 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2331 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2332 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2333 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2335 ASM_OUTPUT_LABEL (asm_out_file, l1);
2338 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2340 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2345 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2346 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2347 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2350 "FDE initial location");
2351 if (fde->dw_fde_switched_sections)
2353 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2354 fde->dw_fde_unlikely_section_label);
2355 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2356 fde->dw_fde_hot_section_label);
2357 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2358 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2359 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
2360 "FDE initial location");
2361 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2362 fde->dw_fde_hot_section_end_label,
2363 fde->dw_fde_hot_section_label,
2364 "FDE address range");
2365 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
2366 "FDE initial location");
2367 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2368 fde->dw_fde_unlikely_section_end_label,
2369 fde->dw_fde_unlikely_section_label,
2370 "FDE address range");
2373 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2374 fde->dw_fde_end, fde->dw_fde_begin,
2375 "FDE address range");
2379 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2380 "FDE initial location");
2381 if (fde->dw_fde_switched_sections)
2383 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2384 fde->dw_fde_hot_section_label,
2385 "FDE initial location");
2386 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2387 fde->dw_fde_hot_section_end_label,
2388 fde->dw_fde_hot_section_label,
2389 "FDE address range");
2390 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2391 fde->dw_fde_unlikely_section_label,
2392 "FDE initial location");
2393 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2394 fde->dw_fde_unlikely_section_end_label,
2395 fde->dw_fde_unlikely_section_label,
2396 "FDE address range");
2399 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2400 fde->dw_fde_end, fde->dw_fde_begin,
2401 "FDE address range");
2404 if (augmentation[0])
2406 if (any_lsda_needed)
2408 int size = size_of_encoded_value (lsda_encoding);
2410 if (lsda_encoding == DW_EH_PE_aligned)
2412 int offset = ( 4 /* Length */
2413 + 4 /* CIE offset */
2414 + 2 * size_of_encoded_value (fde_encoding)
2415 + 1 /* Augmentation size */ );
2416 int pad = -offset & (PTR_SIZE - 1);
2419 gcc_assert (size_of_uleb128 (size) == 1);
2422 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2424 if (fde->uses_eh_lsda)
2426 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2427 fde->funcdef_number);
2428 dw2_asm_output_encoded_addr_rtx (
2429 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2430 false, "Language Specific Data Area");
2434 if (lsda_encoding == DW_EH_PE_aligned)
2435 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2437 (size_of_encoded_value (lsda_encoding), 0,
2438 "Language Specific Data Area (none)");
2442 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2445 /* Loop through the Call Frame Instructions associated with
2447 fde->dw_fde_current_label = fde->dw_fde_begin;
2448 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2449 output_cfi (cfi, fde, for_eh);
2451 /* Pad the FDE out to an address sized boundary. */
2452 ASM_OUTPUT_ALIGN (asm_out_file,
2453 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2454 ASM_OUTPUT_LABEL (asm_out_file, l2);
2457 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2458 dw2_asm_output_data (4, 0, "End of Table");
2459 #ifdef MIPS_DEBUGGING_INFO
2460 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2461 get a value of 0. Putting .align 0 after the label fixes it. */
2462 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2465 /* Turn off app to make assembly quicker. */
2470 /* Output a marker (i.e. a label) for the beginning of a function, before
2474 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2475 const char *file ATTRIBUTE_UNUSED)
2477 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2481 current_function_func_begin_label = NULL;
2483 #ifdef TARGET_UNWIND_INFO
2484 /* ??? current_function_func_begin_label is also used by except.c
2485 for call-site information. We must emit this label if it might
2487 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2488 && ! dwarf2out_do_frame ())
2491 if (! dwarf2out_do_frame ())
2495 function_section (current_function_decl);
2496 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2497 current_function_funcdef_no);
2498 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2499 current_function_funcdef_no);
2500 dup_label = xstrdup (label);
2501 current_function_func_begin_label = dup_label;
2503 #ifdef TARGET_UNWIND_INFO
2504 /* We can elide the fde allocation if we're not emitting debug info. */
2505 if (! dwarf2out_do_frame ())
2509 /* Expand the fde table if necessary. */
2510 if (fde_table_in_use == fde_table_allocated)
2512 fde_table_allocated += FDE_TABLE_INCREMENT;
2513 fde_table = ggc_realloc (fde_table,
2514 fde_table_allocated * sizeof (dw_fde_node));
2515 memset (fde_table + fde_table_in_use, 0,
2516 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2519 /* Record the FDE associated with this function. */
2520 current_funcdef_fde = fde_table_in_use;
2522 /* Add the new FDE at the end of the fde_table. */
2523 fde = &fde_table[fde_table_in_use++];
2524 fde->decl = current_function_decl;
2525 fde->dw_fde_begin = dup_label;
2526 fde->dw_fde_current_label = NULL;
2527 fde->dw_fde_hot_section_label = NULL;
2528 fde->dw_fde_hot_section_end_label = NULL;
2529 fde->dw_fde_unlikely_section_label = NULL;
2530 fde->dw_fde_unlikely_section_end_label = NULL;
2531 fde->dw_fde_switched_sections = false;
2532 fde->dw_fde_end = NULL;
2533 fde->dw_fde_cfi = NULL;
2534 fde->funcdef_number = current_function_funcdef_no;
2535 fde->nothrow = TREE_NOTHROW (current_function_decl);
2536 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2537 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2539 args_size = old_args_size = 0;
2541 /* We only want to output line number information for the genuine dwarf2
2542 prologue case, not the eh frame case. */
2543 #ifdef DWARF2_DEBUGGING_INFO
2545 dwarf2out_source_line (line, file);
2549 /* Output a marker (i.e. a label) for the absolute end of the generated code
2550 for a function definition. This gets called *after* the epilogue code has
2554 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2555 const char *file ATTRIBUTE_UNUSED)
2558 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2560 /* Output a label to mark the endpoint of the code generated for this
2562 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2563 current_function_funcdef_no);
2564 ASM_OUTPUT_LABEL (asm_out_file, label);
2565 fde = &fde_table[fde_table_in_use - 1];
2566 fde->dw_fde_end = xstrdup (label);
2570 dwarf2out_frame_init (void)
2572 /* Allocate the initial hunk of the fde_table. */
2573 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2574 fde_table_allocated = FDE_TABLE_INCREMENT;
2575 fde_table_in_use = 0;
2577 /* Generate the CFA instructions common to all FDE's. Do it now for the
2578 sake of lookup_cfa. */
2580 #ifdef DWARF2_UNWIND_INFO
2581 /* On entry, the Canonical Frame Address is at SP. */
2582 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2583 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2588 dwarf2out_frame_finish (void)
2590 /* Output call frame information. */
2591 if (write_symbols == DWARF2_DEBUG
2592 || write_symbols == VMS_AND_DWARF2_DEBUG
2593 #ifdef DWARF2_FRAME_INFO
2594 || DWARF2_FRAME_INFO
2597 output_call_frame_info (0);
2599 #ifndef TARGET_UNWIND_INFO
2600 /* Output another copy for the unwinder. */
2601 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2602 output_call_frame_info (1);
2607 /* And now, the subset of the debugging information support code necessary
2608 for emitting location expressions. */
2610 /* We need some way to distinguish DW_OP_addr with a direct symbol
2611 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2612 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2615 typedef struct dw_val_struct *dw_val_ref;
2616 typedef struct die_struct *dw_die_ref;
2617 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2618 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2620 /* Each DIE may have a series of attribute/value pairs. Values
2621 can take on several forms. The forms that are used in this
2622 implementation are listed below. */
2627 dw_val_class_offset,
2629 dw_val_class_loc_list,
2630 dw_val_class_range_list,
2632 dw_val_class_unsigned_const,
2633 dw_val_class_long_long,
2636 dw_val_class_die_ref,
2637 dw_val_class_fde_ref,
2638 dw_val_class_lbl_id,
2639 dw_val_class_lbl_offset,
2643 /* Describe a double word constant value. */
2644 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2646 typedef struct dw_long_long_struct GTY(())
2653 /* Describe a floating point constant value, or a vector constant value. */
2655 typedef struct dw_vec_struct GTY(())
2657 unsigned char * GTY((length ("%h.length"))) array;
2663 /* The dw_val_node describes an attribute's value, as it is
2664 represented internally. */
2666 typedef struct dw_val_struct GTY(())
2668 enum dw_val_class val_class;
2669 union dw_val_struct_union
2671 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2672 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2673 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2674 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2675 HOST_WIDE_INT GTY ((default)) val_int;
2676 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2677 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2678 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2679 struct dw_val_die_union
2683 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2684 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2685 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2686 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2687 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2689 GTY ((desc ("%1.val_class"))) v;
2693 /* Locations in memory are described using a sequence of stack machine
2696 typedef struct dw_loc_descr_struct GTY(())
2698 dw_loc_descr_ref dw_loc_next;
2699 enum dwarf_location_atom dw_loc_opc;
2700 dw_val_node dw_loc_oprnd1;
2701 dw_val_node dw_loc_oprnd2;
2706 /* Location lists are ranges + location descriptions for that range,
2707 so you can track variables that are in different places over
2708 their entire life. */
2709 typedef struct dw_loc_list_struct GTY(())
2711 dw_loc_list_ref dw_loc_next;
2712 const char *begin; /* Label for begin address of range */
2713 const char *end; /* Label for end address of range */
2714 char *ll_symbol; /* Label for beginning of location list.
2715 Only on head of list */
2716 const char *section; /* Section this loclist is relative to */
2717 dw_loc_descr_ref expr;
2720 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2722 static const char *dwarf_stack_op_name (unsigned);
2723 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2724 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2725 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2726 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2727 static unsigned long size_of_locs (dw_loc_descr_ref);
2728 static void output_loc_operands (dw_loc_descr_ref);
2729 static void output_loc_sequence (dw_loc_descr_ref);
2731 /* Convert a DWARF stack opcode into its string name. */
2734 dwarf_stack_op_name (unsigned int op)
2739 case INTERNAL_DW_OP_tls_addr:
2740 return "DW_OP_addr";
2742 return "DW_OP_deref";
2744 return "DW_OP_const1u";
2746 return "DW_OP_const1s";
2748 return "DW_OP_const2u";
2750 return "DW_OP_const2s";
2752 return "DW_OP_const4u";
2754 return "DW_OP_const4s";
2756 return "DW_OP_const8u";
2758 return "DW_OP_const8s";
2760 return "DW_OP_constu";
2762 return "DW_OP_consts";
2766 return "DW_OP_drop";
2768 return "DW_OP_over";
2770 return "DW_OP_pick";
2772 return "DW_OP_swap";
2776 return "DW_OP_xderef";
2784 return "DW_OP_minus";
2796 return "DW_OP_plus";
2797 case DW_OP_plus_uconst:
2798 return "DW_OP_plus_uconst";
2804 return "DW_OP_shra";
2822 return "DW_OP_skip";
2824 return "DW_OP_lit0";
2826 return "DW_OP_lit1";
2828 return "DW_OP_lit2";
2830 return "DW_OP_lit3";
2832 return "DW_OP_lit4";
2834 return "DW_OP_lit5";
2836 return "DW_OP_lit6";
2838 return "DW_OP_lit7";
2840 return "DW_OP_lit8";
2842 return "DW_OP_lit9";
2844 return "DW_OP_lit10";
2846 return "DW_OP_lit11";
2848 return "DW_OP_lit12";
2850 return "DW_OP_lit13";
2852 return "DW_OP_lit14";
2854 return "DW_OP_lit15";
2856 return "DW_OP_lit16";
2858 return "DW_OP_lit17";
2860 return "DW_OP_lit18";
2862 return "DW_OP_lit19";
2864 return "DW_OP_lit20";
2866 return "DW_OP_lit21";
2868 return "DW_OP_lit22";
2870 return "DW_OP_lit23";
2872 return "DW_OP_lit24";
2874 return "DW_OP_lit25";
2876 return "DW_OP_lit26";
2878 return "DW_OP_lit27";
2880 return "DW_OP_lit28";
2882 return "DW_OP_lit29";
2884 return "DW_OP_lit30";
2886 return "DW_OP_lit31";
2888 return "DW_OP_reg0";
2890 return "DW_OP_reg1";
2892 return "DW_OP_reg2";
2894 return "DW_OP_reg3";
2896 return "DW_OP_reg4";
2898 return "DW_OP_reg5";
2900 return "DW_OP_reg6";
2902 return "DW_OP_reg7";
2904 return "DW_OP_reg8";
2906 return "DW_OP_reg9";
2908 return "DW_OP_reg10";
2910 return "DW_OP_reg11";
2912 return "DW_OP_reg12";
2914 return "DW_OP_reg13";
2916 return "DW_OP_reg14";
2918 return "DW_OP_reg15";
2920 return "DW_OP_reg16";
2922 return "DW_OP_reg17";
2924 return "DW_OP_reg18";
2926 return "DW_OP_reg19";
2928 return "DW_OP_reg20";
2930 return "DW_OP_reg21";
2932 return "DW_OP_reg22";
2934 return "DW_OP_reg23";
2936 return "DW_OP_reg24";
2938 return "DW_OP_reg25";
2940 return "DW_OP_reg26";
2942 return "DW_OP_reg27";
2944 return "DW_OP_reg28";
2946 return "DW_OP_reg29";
2948 return "DW_OP_reg30";
2950 return "DW_OP_reg31";
2952 return "DW_OP_breg0";
2954 return "DW_OP_breg1";
2956 return "DW_OP_breg2";
2958 return "DW_OP_breg3";
2960 return "DW_OP_breg4";
2962 return "DW_OP_breg5";
2964 return "DW_OP_breg6";
2966 return "DW_OP_breg7";
2968 return "DW_OP_breg8";
2970 return "DW_OP_breg9";
2972 return "DW_OP_breg10";
2974 return "DW_OP_breg11";
2976 return "DW_OP_breg12";
2978 return "DW_OP_breg13";
2980 return "DW_OP_breg14";
2982 return "DW_OP_breg15";
2984 return "DW_OP_breg16";
2986 return "DW_OP_breg17";
2988 return "DW_OP_breg18";
2990 return "DW_OP_breg19";
2992 return "DW_OP_breg20";
2994 return "DW_OP_breg21";
2996 return "DW_OP_breg22";
2998 return "DW_OP_breg23";
3000 return "DW_OP_breg24";
3002 return "DW_OP_breg25";
3004 return "DW_OP_breg26";
3006 return "DW_OP_breg27";
3008 return "DW_OP_breg28";
3010 return "DW_OP_breg29";
3012 return "DW_OP_breg30";
3014 return "DW_OP_breg31";
3016 return "DW_OP_regx";
3018 return "DW_OP_fbreg";
3020 return "DW_OP_bregx";
3022 return "DW_OP_piece";
3023 case DW_OP_deref_size:
3024 return "DW_OP_deref_size";
3025 case DW_OP_xderef_size:
3026 return "DW_OP_xderef_size";
3029 case DW_OP_push_object_address:
3030 return "DW_OP_push_object_address";
3032 return "DW_OP_call2";
3034 return "DW_OP_call4";
3035 case DW_OP_call_ref:
3036 return "DW_OP_call_ref";
3037 case DW_OP_GNU_push_tls_address:
3038 return "DW_OP_GNU_push_tls_address";
3040 return "OP_<unknown>";
3044 /* Return a pointer to a newly allocated location description. Location
3045 descriptions are simple expression terms that can be strung
3046 together to form more complicated location (address) descriptions. */
3048 static inline dw_loc_descr_ref
3049 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3050 unsigned HOST_WIDE_INT oprnd2)
3052 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
3054 descr->dw_loc_opc = op;
3055 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3056 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3057 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3058 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3063 /* Add a location description term to a location description expression. */
3066 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3068 dw_loc_descr_ref *d;
3070 /* Find the end of the chain. */
3071 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3077 /* Return the size of a location descriptor. */
3079 static unsigned long
3080 size_of_loc_descr (dw_loc_descr_ref loc)
3082 unsigned long size = 1;
3084 switch (loc->dw_loc_opc)
3087 case INTERNAL_DW_OP_tls_addr:
3088 size += DWARF2_ADDR_SIZE;
3107 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3110 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3115 case DW_OP_plus_uconst:
3116 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3154 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3157 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3160 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3163 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3164 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3167 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3169 case DW_OP_deref_size:
3170 case DW_OP_xderef_size:
3179 case DW_OP_call_ref:
3180 size += DWARF2_ADDR_SIZE;
3189 /* Return the size of a series of location descriptors. */
3191 static unsigned long
3192 size_of_locs (dw_loc_descr_ref loc)
3196 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
3198 loc->dw_loc_addr = size;
3199 size += size_of_loc_descr (loc);
3205 /* Output location description stack opcode's operands (if any). */
3208 output_loc_operands (dw_loc_descr_ref loc)
3210 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3211 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3213 switch (loc->dw_loc_opc)
3215 #ifdef DWARF2_DEBUGGING_INFO
3217 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3221 dw2_asm_output_data (2, val1->v.val_int, NULL);
3225 dw2_asm_output_data (4, val1->v.val_int, NULL);
3229 gcc_assert (HOST_BITS_PER_LONG >= 64);
3230 dw2_asm_output_data (8, val1->v.val_int, NULL);
3237 gcc_assert (val1->val_class == dw_val_class_loc);
3238 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3240 dw2_asm_output_data (2, offset, NULL);
3253 /* We currently don't make any attempt to make sure these are
3254 aligned properly like we do for the main unwind info, so
3255 don't support emitting things larger than a byte if we're
3256 only doing unwinding. */
3261 dw2_asm_output_data (1, val1->v.val_int, NULL);
3264 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3267 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3270 dw2_asm_output_data (1, val1->v.val_int, NULL);
3272 case DW_OP_plus_uconst:
3273 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3307 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3310 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3313 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3316 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3317 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3320 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3322 case DW_OP_deref_size:
3323 case DW_OP_xderef_size:
3324 dw2_asm_output_data (1, val1->v.val_int, NULL);
3327 case INTERNAL_DW_OP_tls_addr:
3328 if (targetm.asm_out.output_dwarf_dtprel)
3330 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3333 fputc ('\n', asm_out_file);
3340 /* Other codes have no operands. */
3345 /* Output a sequence of location operations. */
3348 output_loc_sequence (dw_loc_descr_ref loc)
3350 for (; loc != NULL; loc = loc->dw_loc_next)
3352 /* Output the opcode. */
3353 dw2_asm_output_data (1, loc->dw_loc_opc,
3354 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3356 /* Output the operand(s) (if any). */
3357 output_loc_operands (loc);
3361 /* This routine will generate the correct assembly data for a location
3362 description based on a cfi entry with a complex address. */
3365 output_cfa_loc (dw_cfi_ref cfi)
3367 dw_loc_descr_ref loc;
3370 /* Output the size of the block. */
3371 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3372 size = size_of_locs (loc);
3373 dw2_asm_output_data_uleb128 (size, NULL);
3375 /* Now output the operations themselves. */
3376 output_loc_sequence (loc);
3379 /* This function builds a dwarf location descriptor sequence from
3380 a dw_cfa_location. */
3382 static struct dw_loc_descr_struct *
3383 build_cfa_loc (dw_cfa_location *cfa)
3385 struct dw_loc_descr_struct *head, *tmp;
3389 if (cfa->base_offset)
3392 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3394 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3396 else if (cfa->reg <= 31)
3397 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3399 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3401 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3402 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3403 add_loc_descr (&head, tmp);
3404 if (cfa->offset != 0)
3406 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3407 add_loc_descr (&head, tmp);
3412 if (cfa->offset == 0)
3414 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3416 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3417 else if (cfa->reg <= 31)
3418 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->offset, 0);
3420 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->offset);
3426 /* This function fills in aa dw_cfa_location structure from a dwarf location
3427 descriptor sequence. */
3430 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3432 struct dw_loc_descr_struct *ptr;
3434 cfa->base_offset = 0;
3438 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3440 enum dwarf_location_atom op = ptr->dw_loc_opc;
3476 cfa->reg = op - DW_OP_reg0;
3479 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3513 cfa->reg = op - DW_OP_breg0;
3514 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3517 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3518 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3523 case DW_OP_plus_uconst:
3524 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3527 internal_error ("DW_LOC_OP %s not implemented",
3528 dwarf_stack_op_name (ptr->dw_loc_opc));
3532 #endif /* .debug_frame support */
3534 /* And now, the support for symbolic debugging information. */
3535 #ifdef DWARF2_DEBUGGING_INFO
3537 /* .debug_str support. */
3538 static int output_indirect_string (void **, void *);
3540 static void dwarf2out_init (const char *);
3541 static void dwarf2out_finish (const char *);
3542 static void dwarf2out_define (unsigned int, const char *);
3543 static void dwarf2out_undef (unsigned int, const char *);
3544 static void dwarf2out_start_source_file (unsigned, const char *);
3545 static void dwarf2out_end_source_file (unsigned);
3546 static void dwarf2out_begin_block (unsigned, unsigned);
3547 static void dwarf2out_end_block (unsigned, unsigned);
3548 static bool dwarf2out_ignore_block (tree);
3549 static void dwarf2out_global_decl (tree);
3550 static void dwarf2out_type_decl (tree, int);
3551 static void dwarf2out_imported_module_or_decl (tree, tree);
3552 static void dwarf2out_abstract_function (tree);
3553 static void dwarf2out_var_location (rtx);
3554 static void dwarf2out_begin_function (tree);
3555 static void dwarf2out_switch_text_section (void);
3557 /* The debug hooks structure. */
3559 const struct gcc_debug_hooks dwarf2_debug_hooks =
3565 dwarf2out_start_source_file,
3566 dwarf2out_end_source_file,
3567 dwarf2out_begin_block,
3568 dwarf2out_end_block,
3569 dwarf2out_ignore_block,
3570 dwarf2out_source_line,
3571 dwarf2out_begin_prologue,
3572 debug_nothing_int_charstar, /* end_prologue */
3573 dwarf2out_end_epilogue,
3574 dwarf2out_begin_function,
3575 debug_nothing_int, /* end_function */
3576 dwarf2out_decl, /* function_decl */
3577 dwarf2out_global_decl,
3578 dwarf2out_type_decl, /* type_decl */
3579 dwarf2out_imported_module_or_decl,
3580 debug_nothing_tree, /* deferred_inline_function */
3581 /* The DWARF 2 backend tries to reduce debugging bloat by not
3582 emitting the abstract description of inline functions until
3583 something tries to reference them. */
3584 dwarf2out_abstract_function, /* outlining_inline_function */
3585 debug_nothing_rtx, /* label */
3586 debug_nothing_int, /* handle_pch */
3587 dwarf2out_var_location,
3588 dwarf2out_switch_text_section,
3589 1 /* start_end_main_source_file */
3593 /* NOTE: In the comments in this file, many references are made to
3594 "Debugging Information Entries". This term is abbreviated as `DIE'
3595 throughout the remainder of this file. */
3597 /* An internal representation of the DWARF output is built, and then
3598 walked to generate the DWARF debugging info. The walk of the internal
3599 representation is done after the entire program has been compiled.
3600 The types below are used to describe the internal representation. */
3602 /* Various DIE's use offsets relative to the beginning of the
3603 .debug_info section to refer to each other. */
3605 typedef long int dw_offset;
3607 /* Define typedefs here to avoid circular dependencies. */
3609 typedef struct dw_attr_struct *dw_attr_ref;
3610 typedef struct dw_line_info_struct *dw_line_info_ref;
3611 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3612 typedef struct pubname_struct *pubname_ref;
3613 typedef struct dw_ranges_struct *dw_ranges_ref;
3615 /* Each entry in the line_info_table maintains the file and
3616 line number associated with the label generated for that
3617 entry. The label gives the PC value associated with
3618 the line number entry. */
3620 typedef struct dw_line_info_struct GTY(())
3622 unsigned long dw_file_num;
3623 unsigned long dw_line_num;
3627 /* Line information for functions in separate sections; each one gets its
3629 typedef struct dw_separate_line_info_struct GTY(())
3631 unsigned long dw_file_num;
3632 unsigned long dw_line_num;
3633 unsigned long function;
3635 dw_separate_line_info_entry;
3637 /* Each DIE attribute has a field specifying the attribute kind,
3638 a link to the next attribute in the chain, and an attribute value.
3639 Attributes are typically linked below the DIE they modify. */
3641 typedef struct dw_attr_struct GTY(())
3643 enum dwarf_attribute dw_attr;
3644 dw_attr_ref dw_attr_next;
3645 dw_val_node dw_attr_val;
3649 /* The Debugging Information Entry (DIE) structure */
3651 typedef struct die_struct GTY(())
3653 enum dwarf_tag die_tag;
3655 dw_attr_ref die_attr;
3656 dw_die_ref die_parent;
3657 dw_die_ref die_child;
3659 dw_die_ref die_definition; /* ref from a specification to its definition */
3660 dw_offset die_offset;
3661 unsigned long die_abbrev;
3663 unsigned int decl_id;
3667 /* The pubname structure */
3669 typedef struct pubname_struct GTY(())
3676 struct dw_ranges_struct GTY(())
3681 /* The limbo die list structure. */
3682 typedef struct limbo_die_struct GTY(())
3686 struct limbo_die_struct *next;
3690 /* How to start an assembler comment. */
3691 #ifndef ASM_COMMENT_START
3692 #define ASM_COMMENT_START ";#"
3695 /* Define a macro which returns nonzero for a TYPE_DECL which was
3696 implicitly generated for a tagged type.
3698 Note that unlike the gcc front end (which generates a NULL named
3699 TYPE_DECL node for each complete tagged type, each array type, and
3700 each function type node created) the g++ front end generates a
3701 _named_ TYPE_DECL node for each tagged type node created.
3702 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3703 generate a DW_TAG_typedef DIE for them. */
3705 #define TYPE_DECL_IS_STUB(decl) \
3706 (DECL_NAME (decl) == NULL_TREE \
3707 || (DECL_ARTIFICIAL (decl) \
3708 && is_tagged_type (TREE_TYPE (decl)) \
3709 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3710 /* This is necessary for stub decls that \
3711 appear in nested inline functions. */ \
3712 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3713 && (decl_ultimate_origin (decl) \
3714 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3716 /* Information concerning the compilation unit's programming
3717 language, and compiler version. */
3719 /* Fixed size portion of the DWARF compilation unit header. */
3720 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3721 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3723 /* Fixed size portion of public names info. */
3724 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3726 /* Fixed size portion of the address range info. */
3727 #define DWARF_ARANGES_HEADER_SIZE \
3728 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3729 DWARF2_ADDR_SIZE * 2) \
3730 - DWARF_INITIAL_LENGTH_SIZE)
3732 /* Size of padding portion in the address range info. It must be
3733 aligned to twice the pointer size. */
3734 #define DWARF_ARANGES_PAD_SIZE \
3735 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3736 DWARF2_ADDR_SIZE * 2) \
3737 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3739 /* Use assembler line directives if available. */
3740 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3741 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3742 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3744 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3748 /* Minimum line offset in a special line info. opcode.
3749 This value was chosen to give a reasonable range of values. */
3750 #define DWARF_LINE_BASE -10
3752 /* First special line opcode - leave room for the standard opcodes. */
3753 #define DWARF_LINE_OPCODE_BASE 10
3755 /* Range of line offsets in a special line info. opcode. */
3756 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3758 /* Flag that indicates the initial value of the is_stmt_start flag.
3759 In the present implementation, we do not mark any lines as
3760 the beginning of a source statement, because that information
3761 is not made available by the GCC front-end. */
3762 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3764 #ifdef DWARF2_DEBUGGING_INFO
3765 /* This location is used by calc_die_sizes() to keep track
3766 the offset of each DIE within the .debug_info section. */
3767 static unsigned long next_die_offset;
3770 /* Record the root of the DIE's built for the current compilation unit. */
3771 static GTY(()) dw_die_ref comp_unit_die;
3773 /* A list of DIEs with a NULL parent waiting to be relocated. */
3774 static GTY(()) limbo_die_node *limbo_die_list;
3776 /* Filenames referenced by this compilation unit. */
3777 static GTY(()) varray_type file_table;
3778 static GTY(()) varray_type file_table_emitted;
3779 static GTY(()) size_t file_table_last_lookup_index;
3781 /* A hash table of references to DIE's that describe declarations.
3782 The key is a DECL_UID() which is a unique number identifying each decl. */
3783 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3785 /* Node of the variable location list. */
3786 struct var_loc_node GTY ((chain_next ("%h.next")))
3788 rtx GTY (()) var_loc_note;
3789 const char * GTY (()) label;
3790 const char * GTY (()) section_label;
3791 struct var_loc_node * GTY (()) next;
3794 /* Variable location list. */
3795 struct var_loc_list_def GTY (())
3797 struct var_loc_node * GTY (()) first;
3799 /* Do not mark the last element of the chained list because
3800 it is marked through the chain. */
3801 struct var_loc_node * GTY ((skip ("%h"))) last;
3803 /* DECL_UID of the variable decl. */
3804 unsigned int decl_id;
3806 typedef struct var_loc_list_def var_loc_list;
3809 /* Table of decl location linked lists. */
3810 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3812 /* A pointer to the base of a list of references to DIE's that
3813 are uniquely identified by their tag, presence/absence of
3814 children DIE's, and list of attribute/value pairs. */
3815 static GTY((length ("abbrev_die_table_allocated")))
3816 dw_die_ref *abbrev_die_table;
3818 /* Number of elements currently allocated for abbrev_die_table. */
3819 static GTY(()) unsigned abbrev_die_table_allocated;
3821 /* Number of elements in type_die_table currently in use. */
3822 static GTY(()) unsigned abbrev_die_table_in_use;
3824 /* Size (in elements) of increments by which we may expand the
3825 abbrev_die_table. */
3826 #define ABBREV_DIE_TABLE_INCREMENT 256
3828 /* A pointer to the base of a table that contains line information
3829 for each source code line in .text in the compilation unit. */
3830 static GTY((length ("line_info_table_allocated")))
3831 dw_line_info_ref line_info_table;
3833 /* Number of elements currently allocated for line_info_table. */
3834 static GTY(()) unsigned line_info_table_allocated;
3836 /* Number of elements in line_info_table currently in use. */
3837 static GTY(()) unsigned line_info_table_in_use;
3839 /* True if the compilation unit contains more than one .text section. */
3840 static GTY(()) bool have_switched_text_section = false;
3842 /* A pointer to the base of a table that contains line information
3843 for each source code line outside of .text in the compilation unit. */
3844 static GTY ((length ("separate_line_info_table_allocated")))
3845 dw_separate_line_info_ref separate_line_info_table;
3847 /* Number of elements currently allocated for separate_line_info_table. */
3848 static GTY(()) unsigned separate_line_info_table_allocated;
3850 /* Number of elements in separate_line_info_table currently in use. */
3851 static GTY(()) unsigned separate_line_info_table_in_use;
3853 /* Size (in elements) of increments by which we may expand the
3855 #define LINE_INFO_TABLE_INCREMENT 1024
3857 /* A pointer to the base of a table that contains a list of publicly
3858 accessible names. */
3859 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table;
3861 /* Number of elements currently allocated for pubname_table. */
3862 static GTY(()) unsigned pubname_table_allocated;
3864 /* Number of elements in pubname_table currently in use. */
3865 static GTY(()) unsigned pubname_table_in_use;
3867 /* Size (in elements) of increments by which we may expand the
3869 #define PUBNAME_TABLE_INCREMENT 64
3871 /* Array of dies for which we should generate .debug_arange info. */
3872 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
3874 /* Number of elements currently allocated for arange_table. */
3875 static GTY(()) unsigned arange_table_allocated;
3877 /* Number of elements in arange_table currently in use. */
3878 static GTY(()) unsigned arange_table_in_use;
3880 /* Size (in elements) of increments by which we may expand the
3882 #define ARANGE_TABLE_INCREMENT 64
3884 /* Array of dies for which we should generate .debug_ranges info. */
3885 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3887 /* Number of elements currently allocated for ranges_table. */
3888 static GTY(()) unsigned ranges_table_allocated;
3890 /* Number of elements in ranges_table currently in use. */
3891 static GTY(()) unsigned ranges_table_in_use;
3893 /* Size (in elements) of increments by which we may expand the
3895 #define RANGES_TABLE_INCREMENT 64
3897 /* Whether we have location lists that need outputting */
3898 static GTY(()) unsigned have_location_lists;
3900 /* Unique label counter. */
3901 static GTY(()) unsigned int loclabel_num;
3903 #ifdef DWARF2_DEBUGGING_INFO
3904 /* Record whether the function being analyzed contains inlined functions. */
3905 static int current_function_has_inlines;
3907 #if 0 && defined (MIPS_DEBUGGING_INFO)
3908 static int comp_unit_has_inlines;
3911 /* Number of file tables emitted in maybe_emit_file(). */
3912 static GTY(()) int emitcount = 0;
3914 /* Number of internal labels generated by gen_internal_sym(). */
3915 static GTY(()) int label_num;
3917 #ifdef DWARF2_DEBUGGING_INFO
3919 /* Offset from the "steady-state frame pointer" to the CFA,
3920 within the current function. */
3921 static HOST_WIDE_INT frame_pointer_cfa_offset;
3923 /* Forward declarations for functions defined in this file. */
3925 static int is_pseudo_reg (rtx);
3926 static tree type_main_variant (tree);
3927 static int is_tagged_type (tree);
3928 static const char *dwarf_tag_name (unsigned);
3929 static const char *dwarf_attr_name (unsigned);
3930 static const char *dwarf_form_name (unsigned);
3931 static tree decl_ultimate_origin (tree);
3932 static tree block_ultimate_origin (tree);
3933 static tree decl_class_context (tree);
3934 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3935 static inline enum dw_val_class AT_class (dw_attr_ref);
3936 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3937 static inline unsigned AT_flag (dw_attr_ref);
3938 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3939 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
3940 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3941 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
3942 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
3944 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3945 unsigned int, unsigned char *);
3946 static hashval_t debug_str_do_hash (const void *);
3947 static int debug_str_eq (const void *, const void *);
3948 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3949 static inline const char *AT_string (dw_attr_ref);
3950 static int AT_string_form (dw_attr_ref);
3951 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3952 static void add_AT_specification (dw_die_ref, dw_die_ref);
3953 static inline dw_die_ref AT_ref (dw_attr_ref);
3954 static inline int AT_ref_external (dw_attr_ref);
3955 static inline void set_AT_ref_external (dw_attr_ref, int);
3956 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3957 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3958 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3959 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3961 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3962 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3963 static inline rtx AT_addr (dw_attr_ref);
3964 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3965 static void add_AT_lbl_offset (dw_die_ref, enum dwarf_attribute, const char *);
3966 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3967 unsigned HOST_WIDE_INT);
3968 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3970 static inline const char *AT_lbl (dw_attr_ref);
3971 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3972 static const char *get_AT_low_pc (dw_die_ref);
3973 static const char *get_AT_hi_pc (dw_die_ref);
3974 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3975 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3976 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3977 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3978 static bool is_c_family (void);
3979 static bool is_cxx (void);
3980 static bool is_java (void);
3981 static bool is_fortran (void);
3982 static bool is_ada (void);
3983 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3984 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3985 static inline void free_die (dw_die_ref);
3986 static void remove_children (dw_die_ref);
3987 static void add_child_die (dw_die_ref, dw_die_ref);
3988 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3989 static dw_die_ref lookup_type_die (tree);
3990 static void equate_type_number_to_die (tree, dw_die_ref);
3991 static hashval_t decl_die_table_hash (const void *);
3992 static int decl_die_table_eq (const void *, const void *);
3993 static dw_die_ref lookup_decl_die (tree);
3994 static hashval_t decl_loc_table_hash (const void *);
3995 static int decl_loc_table_eq (const void *, const void *);
3996 static var_loc_list *lookup_decl_loc (tree);
3997 static void equate_decl_number_to_die (tree, dw_die_ref);
3998 static void add_var_loc_to_decl (tree, struct var_loc_node *);
3999 static void print_spaces (FILE *);
4000 static void print_die (dw_die_ref, FILE *);
4001 static void print_dwarf_line_table (FILE *);
4002 static void reverse_die_lists (dw_die_ref);
4003 static void reverse_all_dies (dw_die_ref);
4004 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
4005 static dw_die_ref pop_compile_unit (dw_die_ref);
4006 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
4007 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
4008 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
4009 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
4010 static int same_dw_val_p (dw_val_node *, dw_val_node *, int *);
4011 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
4012 static int same_die_p (dw_die_ref, dw_die_ref, int *);
4013 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
4014 static void compute_section_prefix (dw_die_ref);
4015 static int is_type_die (dw_die_ref);
4016 static int is_comdat_die (dw_die_ref);
4017 static int is_symbol_die (dw_die_ref);
4018 static void assign_symbol_names (dw_die_ref);
4019 static void break_out_includes (dw_die_ref);
4020 static hashval_t htab_cu_hash (const void *);
4021 static int htab_cu_eq (const void *, const void *);
4022 static void htab_cu_del (void *);
4023 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
4024 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
4025 static void add_sibling_attributes (dw_die_ref);
4026 static void build_abbrev_table (dw_die_ref);
4027 static void output_location_lists (dw_die_ref);
4028 static int constant_size (long unsigned);
4029 static unsigned long size_of_die (dw_die_ref);
4030 static void calc_die_sizes (dw_die_ref);
4031 static void mark_dies (dw_die_ref);
4032 static void unmark_dies (dw_die_ref);
4033 static void unmark_all_dies (dw_die_ref);
4034 static unsigned long size_of_pubnames (void);
4035 static unsigned long size_of_aranges (void);
4036 static enum dwarf_form value_format (dw_attr_ref);
4037 static void output_value_format (dw_attr_ref);
4038 static void output_abbrev_section (void);
4039 static void output_die_symbol (dw_die_ref);
4040 static void output_die (dw_die_ref);
4041 static void output_compilation_unit_header (void);
4042 static void output_comp_unit (dw_die_ref, int);
4043 static const char *dwarf2_name (tree, int);
4044 static void add_pubname (tree, dw_die_ref);
4045 static void output_pubnames (void);
4046 static void add_arange (tree, dw_die_ref);
4047 static void output_aranges (void);
4048 static unsigned int add_ranges (tree);
4049 static void output_ranges (void);
4050 static void output_line_info (void);
4051 static void output_file_names (void);
4052 static dw_die_ref base_type_die (tree);
4053 static tree root_type (tree);
4054 static int is_base_type (tree);
4055 static bool is_subrange_type (tree);
4056 static dw_die_ref subrange_type_die (tree, dw_die_ref);
4057 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
4058 static int type_is_enum (tree);
4059 static unsigned int dbx_reg_number (rtx);
4060 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
4061 static dw_loc_descr_ref reg_loc_descriptor (rtx);
4062 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int);
4063 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx);
4064 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4065 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT);
4066 static int is_based_loc (rtx);
4067 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode);
4068 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx);
4069 static dw_loc_descr_ref loc_descriptor (rtx);
4070 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
4071 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
4072 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
4073 static tree field_type (tree);
4074 static unsigned int simple_type_align_in_bits (tree);
4075 static unsigned int simple_decl_align_in_bits (tree);
4076 static unsigned HOST_WIDE_INT simple_type_size_in_bits (tree);
4077 static HOST_WIDE_INT field_byte_offset (tree);
4078 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
4080 static void add_data_member_location_attribute (dw_die_ref, tree);
4081 static void add_const_value_attribute (dw_die_ref, rtx);
4082 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
4083 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4084 static void insert_float (rtx, unsigned char *);
4085 static rtx rtl_for_decl_location (tree);
4086 static void add_location_or_const_value_attribute (dw_die_ref, tree,
4087 enum dwarf_attribute);
4088 static void tree_add_const_value_attribute (dw_die_ref, tree);
4089 static void add_name_attribute (dw_die_ref, const char *);
4090 static void add_comp_dir_attribute (dw_die_ref);
4091 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
4092 static void add_subscript_info (dw_die_ref, tree);
4093 static void add_byte_size_attribute (dw_die_ref, tree);
4094 static void add_bit_offset_attribute (dw_die_ref, tree);
4095 static void add_bit_size_attribute (dw_die_ref, tree);
4096 static void add_prototyped_attribute (dw_die_ref, tree);
4097 static void add_abstract_origin_attribute (dw_die_ref, tree);
4098 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
4099 static void add_src_coords_attributes (dw_die_ref, tree);
4100 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
4101 static void push_decl_scope (tree);
4102 static void pop_decl_scope (void);
4103 static dw_die_ref scope_die_for (tree, dw_die_ref);
4104 static inline int local_scope_p (dw_die_ref);
4105 static inline int class_or_namespace_scope_p (dw_die_ref);
4106 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
4107 static void add_calling_convention_attribute (dw_die_ref, tree);
4108 static const char *type_tag (tree);
4109 static tree member_declared_type (tree);
4111 static const char *decl_start_label (tree);
4113 static void gen_array_type_die (tree, dw_die_ref);
4115 static void gen_entry_point_die (tree, dw_die_ref);
4117 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
4118 static void gen_inlined_structure_type_die (tree, dw_die_ref);
4119 static void gen_inlined_union_type_die (tree, dw_die_ref);
4120 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
4121 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
4122 static void gen_unspecified_parameters_die (tree, dw_die_ref);
4123 static void gen_formal_types_die (tree, dw_die_ref);
4124 static void gen_subprogram_die (tree, dw_die_ref);
4125 static void gen_variable_die (tree, dw_die_ref);
4126 static void gen_label_die (tree, dw_die_ref);
4127 static void gen_lexical_block_die (tree, dw_die_ref, int);
4128 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
4129 static void gen_field_die (tree, dw_die_ref);
4130 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
4131 static dw_die_ref gen_compile_unit_die (const char *);
4132 static void gen_string_type_die (tree, dw_die_ref);
4133 static void gen_inheritance_die (tree, tree, dw_die_ref);
4134 static void gen_member_die (tree, dw_die_ref);
4135 static void gen_struct_or_union_type_die (tree, dw_die_ref);
4136 static void gen_subroutine_type_die (tree, dw_die_ref);
4137 static void gen_typedef_die (tree, dw_die_ref);
4138 static void gen_type_die (tree, dw_die_ref);
4139 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
4140 static void gen_block_die (tree, dw_die_ref, int);
4141 static void decls_for_scope (tree, dw_die_ref, int);
4142 static int is_redundant_typedef (tree);
4143 static void gen_namespace_die (tree);
4144 static void gen_decl_die (tree, dw_die_ref);
4145 static dw_die_ref force_decl_die (tree);
4146 static dw_die_ref force_type_die (tree);
4147 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
4148 static void declare_in_namespace (tree, dw_die_ref);
4149 static unsigned lookup_filename (const char *);
4150 static void init_file_table (void);
4151 static void retry_incomplete_types (void);
4152 static void gen_type_die_for_member (tree, tree, dw_die_ref);
4153 static void splice_child_die (dw_die_ref, dw_die_ref);
4154 static int file_info_cmp (const void *, const void *);
4155 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
4156 const char *, const char *, unsigned);
4157 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
4158 const char *, const char *,
4160 static void output_loc_list (dw_loc_list_ref);
4161 static char *gen_internal_sym (const char *);
4163 static void prune_unmark_dies (dw_die_ref);
4164 static void prune_unused_types_mark (dw_die_ref, int);
4165 static void prune_unused_types_walk (dw_die_ref);
4166 static void prune_unused_types_walk_attribs (dw_die_ref);
4167 static void prune_unused_types_prune (dw_die_ref);
4168 static void prune_unused_types (void);
4169 static int maybe_emit_file (int);
4171 /* Section names used to hold DWARF debugging information. */
4172 #ifndef DEBUG_INFO_SECTION
4173 #define DEBUG_INFO_SECTION ".debug_info"
4175 #ifndef DEBUG_ABBREV_SECTION
4176 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4178 #ifndef DEBUG_ARANGES_SECTION
4179 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4181 #ifndef DEBUG_MACINFO_SECTION
4182 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4184 #ifndef DEBUG_LINE_SECTION
4185 #define DEBUG_LINE_SECTION ".debug_line"
4187 #ifndef DEBUG_LOC_SECTION
4188 #define DEBUG_LOC_SECTION ".debug_loc"
4190 #ifndef DEBUG_PUBNAMES_SECTION
4191 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4193 #ifndef DEBUG_STR_SECTION
4194 #define DEBUG_STR_SECTION ".debug_str"
4196 #ifndef DEBUG_RANGES_SECTION
4197 #define DEBUG_RANGES_SECTION ".debug_ranges"
4200 /* Standard ELF section names for compiled code and data. */
4201 #ifndef TEXT_SECTION_NAME
4202 #define TEXT_SECTION_NAME ".text"
4205 /* Section flags for .debug_str section. */
4206 #define DEBUG_STR_SECTION_FLAGS \
4207 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
4208 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4211 /* Labels we insert at beginning sections we can reference instead of
4212 the section names themselves. */
4214 #ifndef TEXT_SECTION_LABEL
4215 #define TEXT_SECTION_LABEL "Ltext"
4217 #ifndef COLD_TEXT_SECTION_LABEL
4218 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4220 #ifndef DEBUG_LINE_SECTION_LABEL
4221 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4223 #ifndef DEBUG_INFO_SECTION_LABEL
4224 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4226 #ifndef DEBUG_ABBREV_SECTION_LABEL
4227 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4229 #ifndef DEBUG_LOC_SECTION_LABEL
4230 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4232 #ifndef DEBUG_RANGES_SECTION_LABEL
4233 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4235 #ifndef DEBUG_MACINFO_SECTION_LABEL
4236 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4239 /* Definitions of defaults for formats and names of various special
4240 (artificial) labels which may be generated within this file (when the -g
4241 options is used and DWARF2_DEBUGGING_INFO is in effect.
4242 If necessary, these may be overridden from within the tm.h file, but
4243 typically, overriding these defaults is unnecessary. */
4245 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4246 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4247 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4248 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4249 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4250 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4251 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4252 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4253 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4254 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4256 #ifndef TEXT_END_LABEL
4257 #define TEXT_END_LABEL "Letext"
4259 #ifndef COLD_END_LABEL
4260 #define COLD_END_LABEL "Letext_cold"
4262 #ifndef BLOCK_BEGIN_LABEL
4263 #define BLOCK_BEGIN_LABEL "LBB"
4265 #ifndef BLOCK_END_LABEL
4266 #define BLOCK_END_LABEL "LBE"
4268 #ifndef LINE_CODE_LABEL
4269 #define LINE_CODE_LABEL "LM"
4271 #ifndef SEPARATE_LINE_CODE_LABEL
4272 #define SEPARATE_LINE_CODE_LABEL "LSM"
4275 /* We allow a language front-end to designate a function that is to be
4276 called to "demangle" any name before it is put into a DIE. */
4278 static const char *(*demangle_name_func) (const char *);
4281 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4283 demangle_name_func = func;
4286 /* Test if rtl node points to a pseudo register. */
4289 is_pseudo_reg (rtx rtl)
4291 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4292 || (GET_CODE (rtl) == SUBREG
4293 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4296 /* Return a reference to a type, with its const and volatile qualifiers
4300 type_main_variant (tree type)
4302 type = TYPE_MAIN_VARIANT (type);
4304 /* ??? There really should be only one main variant among any group of
4305 variants of a given type (and all of the MAIN_VARIANT values for all
4306 members of the group should point to that one type) but sometimes the C
4307 front-end messes this up for array types, so we work around that bug
4309 if (TREE_CODE (type) == ARRAY_TYPE)
4310 while (type != TYPE_MAIN_VARIANT (type))
4311 type = TYPE_MAIN_VARIANT (type);
4316 /* Return nonzero if the given type node represents a tagged type. */
4319 is_tagged_type (tree type)
4321 enum tree_code code = TREE_CODE (type);
4323 return (code == RECORD_TYPE || code == UNION_TYPE
4324 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4327 /* Convert a DIE tag into its string name. */
4330 dwarf_tag_name (unsigned int tag)
4334 case DW_TAG_padding:
4335 return "DW_TAG_padding";
4336 case DW_TAG_array_type:
4337 return "DW_TAG_array_type";
4338 case DW_TAG_class_type:
4339 return "DW_TAG_class_type";
4340 case DW_TAG_entry_point:
4341 return "DW_TAG_entry_point";
4342 case DW_TAG_enumeration_type:
4343 return "DW_TAG_enumeration_type";
4344 case DW_TAG_formal_parameter:
4345 return "DW_TAG_formal_parameter";
4346 case DW_TAG_imported_declaration:
4347 return "DW_TAG_imported_declaration";
4349 return "DW_TAG_label";
4350 case DW_TAG_lexical_block:
4351 return "DW_TAG_lexical_block";
4353 return "DW_TAG_member";
4354 case DW_TAG_pointer_type:
4355 return "DW_TAG_pointer_type";
4356 case DW_TAG_reference_type:
4357 return "DW_TAG_reference_type";
4358 case DW_TAG_compile_unit:
4359 return "DW_TAG_compile_unit";
4360 case DW_TAG_string_type:
4361 return "DW_TAG_string_type";
4362 case DW_TAG_structure_type:
4363 return "DW_TAG_structure_type";
4364 case DW_TAG_subroutine_type:
4365 return "DW_TAG_subroutine_type";
4366 case DW_TAG_typedef:
4367 return "DW_TAG_typedef";
4368 case DW_TAG_union_type:
4369 return "DW_TAG_union_type";
4370 case DW_TAG_unspecified_parameters:
4371 return "DW_TAG_unspecified_parameters";
4372 case DW_TAG_variant:
4373 return "DW_TAG_variant";
4374 case DW_TAG_common_block:
4375 return "DW_TAG_common_block";
4376 case DW_TAG_common_inclusion:
4377 return "DW_TAG_common_inclusion";
4378 case DW_TAG_inheritance:
4379 return "DW_TAG_inheritance";
4380 case DW_TAG_inlined_subroutine:
4381 return "DW_TAG_inlined_subroutine";
4383 return "DW_TAG_module";
4384 case DW_TAG_ptr_to_member_type:
4385 return "DW_TAG_ptr_to_member_type";
4386 case DW_TAG_set_type:
4387 return "DW_TAG_set_type";
4388 case DW_TAG_subrange_type:
4389 return "DW_TAG_subrange_type";
4390 case DW_TAG_with_stmt:
4391 return "DW_TAG_with_stmt";
4392 case DW_TAG_access_declaration:
4393 return "DW_TAG_access_declaration";
4394 case DW_TAG_base_type:
4395 return "DW_TAG_base_type";
4396 case DW_TAG_catch_block:
4397 return "DW_TAG_catch_block";
4398 case DW_TAG_const_type:
4399 return "DW_TAG_const_type";
4400 case DW_TAG_constant:
4401 return "DW_TAG_constant";
4402 case DW_TAG_enumerator:
4403 return "DW_TAG_enumerator";
4404 case DW_TAG_file_type:
4405 return "DW_TAG_file_type";
4407 return "DW_TAG_friend";
4408 case DW_TAG_namelist:
4409 return "DW_TAG_namelist";
4410 case DW_TAG_namelist_item:
4411 return "DW_TAG_namelist_item";
4412 case DW_TAG_namespace:
4413 return "DW_TAG_namespace";
4414 case DW_TAG_packed_type:
4415 return "DW_TAG_packed_type";
4416 case DW_TAG_subprogram:
4417 return "DW_TAG_subprogram";
4418 case DW_TAG_template_type_param:
4419 return "DW_TAG_template_type_param";
4420 case DW_TAG_template_value_param:
4421 return "DW_TAG_template_value_param";
4422 case DW_TAG_thrown_type:
4423 return "DW_TAG_thrown_type";
4424 case DW_TAG_try_block:
4425 return "DW_TAG_try_block";
4426 case DW_TAG_variant_part:
4427 return "DW_TAG_variant_part";
4428 case DW_TAG_variable:
4429 return "DW_TAG_variable";
4430 case DW_TAG_volatile_type:
4431 return "DW_TAG_volatile_type";
4432 case DW_TAG_imported_module:
4433 return "DW_TAG_imported_module";
4434 case DW_TAG_MIPS_loop:
4435 return "DW_TAG_MIPS_loop";
4436 case DW_TAG_format_label:
4437 return "DW_TAG_format_label";
4438 case DW_TAG_function_template:
4439 return "DW_TAG_function_template";
4440 case DW_TAG_class_template:
4441 return "DW_TAG_class_template";
4442 case DW_TAG_GNU_BINCL:
4443 return "DW_TAG_GNU_BINCL";
4444 case DW_TAG_GNU_EINCL:
4445 return "DW_TAG_GNU_EINCL";
4447 return "DW_TAG_<unknown>";
4451 /* Convert a DWARF attribute code into its string name. */
4454 dwarf_attr_name (unsigned int attr)
4459 return "DW_AT_sibling";
4460 case DW_AT_location:
4461 return "DW_AT_location";
4463 return "DW_AT_name";
4464 case DW_AT_ordering:
4465 return "DW_AT_ordering";
4466 case DW_AT_subscr_data:
4467 return "DW_AT_subscr_data";
4468 case DW_AT_byte_size:
4469 return "DW_AT_byte_size";
4470 case DW_AT_bit_offset:
4471 return "DW_AT_bit_offset";
4472 case DW_AT_bit_size:
4473 return "DW_AT_bit_size";
4474 case DW_AT_element_list:
4475 return "DW_AT_element_list";
4476 case DW_AT_stmt_list:
4477 return "DW_AT_stmt_list";
4479 return "DW_AT_low_pc";
4481 return "DW_AT_high_pc";
4482 case DW_AT_language:
4483 return "DW_AT_language";
4485 return "DW_AT_member";
4487 return "DW_AT_discr";
4488 case DW_AT_discr_value:
4489 return "DW_AT_discr_value";
4490 case DW_AT_visibility:
4491 return "DW_AT_visibility";
4493 return "DW_AT_import";
4494 case DW_AT_string_length:
4495 return "DW_AT_string_length";
4496 case DW_AT_common_reference:
4497 return "DW_AT_common_reference";
4498 case DW_AT_comp_dir:
4499 return "DW_AT_comp_dir";
4500 case DW_AT_const_value:
4501 return "DW_AT_const_value";
4502 case DW_AT_containing_type:
4503 return "DW_AT_containing_type";
4504 case DW_AT_default_value:
4505 return "DW_AT_default_value";
4507 return "DW_AT_inline";
4508 case DW_AT_is_optional:
4509 return "DW_AT_is_optional";
4510 case DW_AT_lower_bound:
4511 return "DW_AT_lower_bound";
4512 case DW_AT_producer:
4513 return "DW_AT_producer";
4514 case DW_AT_prototyped:
4515 return "DW_AT_prototyped";
4516 case DW_AT_return_addr:
4517 return "DW_AT_return_addr";
4518 case DW_AT_start_scope:
4519 return "DW_AT_start_scope";
4520 case DW_AT_stride_size:
4521 return "DW_AT_stride_size";
4522 case DW_AT_upper_bound:
4523 return "DW_AT_upper_bound";
4524 case DW_AT_abstract_origin:
4525 return "DW_AT_abstract_origin";
4526 case DW_AT_accessibility:
4527 return "DW_AT_accessibility";
4528 case DW_AT_address_class:
4529 return "DW_AT_address_class";
4530 case DW_AT_artificial:
4531 return "DW_AT_artificial";
4532 case DW_AT_base_types:
4533 return "DW_AT_base_types";
4534 case DW_AT_calling_convention:
4535 return "DW_AT_calling_convention";
4537 return "DW_AT_count";
4538 case DW_AT_data_member_location:
4539 return "DW_AT_data_member_location";
4540 case DW_AT_decl_column:
4541 return "DW_AT_decl_column";
4542 case DW_AT_decl_file:
4543 return "DW_AT_decl_file";
4544 case DW_AT_decl_line:
4545 return "DW_AT_decl_line";
4546 case DW_AT_declaration:
4547 return "DW_AT_declaration";
4548 case DW_AT_discr_list:
4549 return "DW_AT_discr_list";
4550 case DW_AT_encoding:
4551 return "DW_AT_encoding";
4552 case DW_AT_external:
4553 return "DW_AT_external";
4554 case DW_AT_frame_base:
4555 return "DW_AT_frame_base";
4557 return "DW_AT_friend";
4558 case DW_AT_identifier_case:
4559 return "DW_AT_identifier_case";
4560 case DW_AT_macro_info:
4561 return "DW_AT_macro_info";
4562 case DW_AT_namelist_items:
4563 return "DW_AT_namelist_items";
4564 case DW_AT_priority:
4565 return "DW_AT_priority";
4567 return "DW_AT_segment";
4568 case DW_AT_specification:
4569 return "DW_AT_specification";
4570 case DW_AT_static_link:
4571 return "DW_AT_static_link";
4573 return "DW_AT_type";
4574 case DW_AT_use_location:
4575 return "DW_AT_use_location";
4576 case DW_AT_variable_parameter:
4577 return "DW_AT_variable_parameter";
4578 case DW_AT_virtuality:
4579 return "DW_AT_virtuality";
4580 case DW_AT_vtable_elem_location:
4581 return "DW_AT_vtable_elem_location";
4583 case DW_AT_allocated:
4584 return "DW_AT_allocated";
4585 case DW_AT_associated:
4586 return "DW_AT_associated";
4587 case DW_AT_data_location:
4588 return "DW_AT_data_location";
4590 return "DW_AT_stride";
4591 case DW_AT_entry_pc:
4592 return "DW_AT_entry_pc";
4593 case DW_AT_use_UTF8:
4594 return "DW_AT_use_UTF8";
4595 case DW_AT_extension:
4596 return "DW_AT_extension";
4598 return "DW_AT_ranges";
4599 case DW_AT_trampoline:
4600 return "DW_AT_trampoline";
4601 case DW_AT_call_column:
4602 return "DW_AT_call_column";
4603 case DW_AT_call_file:
4604 return "DW_AT_call_file";
4605 case DW_AT_call_line:
4606 return "DW_AT_call_line";
4608 case DW_AT_MIPS_fde:
4609 return "DW_AT_MIPS_fde";
4610 case DW_AT_MIPS_loop_begin:
4611 return "DW_AT_MIPS_loop_begin";
4612 case DW_AT_MIPS_tail_loop_begin:
4613 return "DW_AT_MIPS_tail_loop_begin";
4614 case DW_AT_MIPS_epilog_begin:
4615 return "DW_AT_MIPS_epilog_begin";
4616 case DW_AT_MIPS_loop_unroll_factor:
4617 return "DW_AT_MIPS_loop_unroll_factor";
4618 case DW_AT_MIPS_software_pipeline_depth:
4619 return "DW_AT_MIPS_software_pipeline_depth";
4620 case DW_AT_MIPS_linkage_name:
4621 return "DW_AT_MIPS_linkage_name";
4622 case DW_AT_MIPS_stride:
4623 return "DW_AT_MIPS_stride";
4624 case DW_AT_MIPS_abstract_name:
4625 return "DW_AT_MIPS_abstract_name";
4626 case DW_AT_MIPS_clone_origin:
4627 return "DW_AT_MIPS_clone_origin";
4628 case DW_AT_MIPS_has_inlines:
4629 return "DW_AT_MIPS_has_inlines";
4631 case DW_AT_sf_names:
4632 return "DW_AT_sf_names";
4633 case DW_AT_src_info:
4634 return "DW_AT_src_info";
4635 case DW_AT_mac_info:
4636 return "DW_AT_mac_info";
4637 case DW_AT_src_coords:
4638 return "DW_AT_src_coords";
4639 case DW_AT_body_begin:
4640 return "DW_AT_body_begin";
4641 case DW_AT_body_end:
4642 return "DW_AT_body_end";
4643 case DW_AT_GNU_vector:
4644 return "DW_AT_GNU_vector";
4646 case DW_AT_VMS_rtnbeg_pd_address:
4647 return "DW_AT_VMS_rtnbeg_pd_address";
4650 return "DW_AT_<unknown>";
4654 /* Convert a DWARF value form code into its string name. */
4657 dwarf_form_name (unsigned int form)
4662 return "DW_FORM_addr";
4663 case DW_FORM_block2:
4664 return "DW_FORM_block2";
4665 case DW_FORM_block4:
4666 return "DW_FORM_block4";
4668 return "DW_FORM_data2";
4670 return "DW_FORM_data4";
4672 return "DW_FORM_data8";
4673 case DW_FORM_string:
4674 return "DW_FORM_string";
4676 return "DW_FORM_block";
4677 case DW_FORM_block1:
4678 return "DW_FORM_block1";
4680 return "DW_FORM_data1";
4682 return "DW_FORM_flag";
4684 return "DW_FORM_sdata";
4686 return "DW_FORM_strp";
4688 return "DW_FORM_udata";
4689 case DW_FORM_ref_addr:
4690 return "DW_FORM_ref_addr";
4692 return "DW_FORM_ref1";
4694 return "DW_FORM_ref2";
4696 return "DW_FORM_ref4";
4698 return "DW_FORM_ref8";
4699 case DW_FORM_ref_udata:
4700 return "DW_FORM_ref_udata";
4701 case DW_FORM_indirect:
4702 return "DW_FORM_indirect";
4704 return "DW_FORM_<unknown>";
4708 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4709 instance of an inlined instance of a decl which is local to an inline
4710 function, so we have to trace all of the way back through the origin chain
4711 to find out what sort of node actually served as the original seed for the
4715 decl_ultimate_origin (tree decl)
4717 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4720 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4721 nodes in the function to point to themselves; ignore that if
4722 we're trying to output the abstract instance of this function. */
4723 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4726 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4727 most distant ancestor, this should never happen. */
4728 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4730 return DECL_ABSTRACT_ORIGIN (decl);
4733 /* Determine the "ultimate origin" of a block. The block may be an inlined
4734 instance of an inlined instance of a block which is local to an inline
4735 function, so we have to trace all of the way back through the origin chain
4736 to find out what sort of node actually served as the original seed for the
4740 block_ultimate_origin (tree block)
4742 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4744 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4745 nodes in the function to point to themselves; ignore that if
4746 we're trying to output the abstract instance of this function. */
4747 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4750 if (immediate_origin == NULL_TREE)
4755 tree lookahead = immediate_origin;
4759 ret_val = lookahead;
4760 lookahead = (TREE_CODE (ret_val) == BLOCK
4761 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4763 while (lookahead != NULL && lookahead != ret_val);
4765 /* The block's abstract origin chain may not be the *ultimate* origin of
4766 the block. It could lead to a DECL that has an abstract origin set.
4767 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
4768 will give us if it has one). Note that DECL's abstract origins are
4769 supposed to be the most distant ancestor (or so decl_ultimate_origin
4770 claims), so we don't need to loop following the DECL origins. */
4771 if (DECL_P (ret_val))
4772 return DECL_ORIGIN (ret_val);
4778 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4779 of a virtual function may refer to a base class, so we check the 'this'
4783 decl_class_context (tree decl)
4785 tree context = NULL_TREE;
4787 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4788 context = DECL_CONTEXT (decl);
4790 context = TYPE_MAIN_VARIANT
4791 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4793 if (context && !TYPE_P (context))
4794 context = NULL_TREE;
4799 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4800 addition order, and correct that in reverse_all_dies. */
4803 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4805 if (die != NULL && attr != NULL)
4807 attr->dw_attr_next = die->die_attr;
4808 die->die_attr = attr;
4812 static inline enum dw_val_class
4813 AT_class (dw_attr_ref a)
4815 return a->dw_attr_val.val_class;
4818 /* Add a flag value attribute to a DIE. */
4821 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4823 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4825 attr->dw_attr_next = NULL;
4826 attr->dw_attr = attr_kind;
4827 attr->dw_attr_val.val_class = dw_val_class_flag;
4828 attr->dw_attr_val.v.val_flag = flag;
4829 add_dwarf_attr (die, attr);
4832 static inline unsigned
4833 AT_flag (dw_attr_ref a)
4835 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4836 return a->dw_attr_val.v.val_flag;
4839 /* Add a signed integer attribute value to a DIE. */
4842 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4844 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4846 attr->dw_attr_next = NULL;
4847 attr->dw_attr = attr_kind;
4848 attr->dw_attr_val.val_class = dw_val_class_const;
4849 attr->dw_attr_val.v.val_int = int_val;
4850 add_dwarf_attr (die, attr);
4853 static inline HOST_WIDE_INT
4854 AT_int (dw_attr_ref a)
4856 gcc_assert (a && AT_class (a) == dw_val_class_const);
4857 return a->dw_attr_val.v.val_int;
4860 /* Add an unsigned integer attribute value to a DIE. */
4863 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4864 unsigned HOST_WIDE_INT unsigned_val)
4866 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4868 attr->dw_attr_next = NULL;
4869 attr->dw_attr = attr_kind;
4870 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4871 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4872 add_dwarf_attr (die, attr);
4875 static inline unsigned HOST_WIDE_INT
4876 AT_unsigned (dw_attr_ref a)
4878 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
4879 return a->dw_attr_val.v.val_unsigned;
4882 /* Add an unsigned double integer attribute value to a DIE. */
4885 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
4886 long unsigned int val_hi, long unsigned int val_low)
4888 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4890 attr->dw_attr_next = NULL;
4891 attr->dw_attr = attr_kind;
4892 attr->dw_attr_val.val_class = dw_val_class_long_long;
4893 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4894 attr->dw_attr_val.v.val_long_long.low = val_low;
4895 add_dwarf_attr (die, attr);
4898 /* Add a floating point attribute value to a DIE and return it. */
4901 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4902 unsigned int length, unsigned int elt_size, unsigned char *array)
4904 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4906 attr->dw_attr_next = NULL;
4907 attr->dw_attr = attr_kind;
4908 attr->dw_attr_val.val_class = dw_val_class_vec;
4909 attr->dw_attr_val.v.val_vec.length = length;
4910 attr->dw_attr_val.v.val_vec.elt_size = elt_size;
4911 attr->dw_attr_val.v.val_vec.array = array;
4912 add_dwarf_attr (die, attr);
4915 /* Hash and equality functions for debug_str_hash. */
4918 debug_str_do_hash (const void *x)
4920 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4924 debug_str_eq (const void *x1, const void *x2)
4926 return strcmp ((((const struct indirect_string_node *)x1)->str),
4927 (const char *)x2) == 0;
4930 /* Add a string attribute value to a DIE. */
4933 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4935 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4936 struct indirect_string_node *node;
4939 if (! debug_str_hash)
4940 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4941 debug_str_eq, NULL);
4943 slot = htab_find_slot_with_hash (debug_str_hash, str,
4944 htab_hash_string (str), INSERT);
4946 *slot = ggc_alloc_cleared (sizeof (struct indirect_string_node));
4947 node = (struct indirect_string_node *) *slot;
4948 node->str = ggc_strdup (str);
4951 attr->dw_attr_next = NULL;
4952 attr->dw_attr = attr_kind;
4953 attr->dw_attr_val.val_class = dw_val_class_str;
4954 attr->dw_attr_val.v.val_str = node;
4955 add_dwarf_attr (die, attr);
4958 static inline const char *
4959 AT_string (dw_attr_ref a)
4961 gcc_assert (a && AT_class (a) == dw_val_class_str);
4962 return a->dw_attr_val.v.val_str->str;
4965 /* Find out whether a string should be output inline in DIE
4966 or out-of-line in .debug_str section. */
4969 AT_string_form (dw_attr_ref a)
4971 struct indirect_string_node *node;
4975 gcc_assert (a && AT_class (a) == dw_val_class_str);
4977 node = a->dw_attr_val.v.val_str;
4981 len = strlen (node->str) + 1;
4983 /* If the string is shorter or equal to the size of the reference, it is
4984 always better to put it inline. */
4985 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4986 return node->form = DW_FORM_string;
4988 /* If we cannot expect the linker to merge strings in .debug_str
4989 section, only put it into .debug_str if it is worth even in this
4991 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4992 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4993 return node->form = DW_FORM_string;
4995 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4996 ++dw2_string_counter;
4997 node->label = xstrdup (label);
4999 return node->form = DW_FORM_strp;
5002 /* Add a DIE reference attribute value to a DIE. */
5005 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
5007 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5009 attr->dw_attr_next = NULL;
5010 attr->dw_attr = attr_kind;
5011 attr->dw_attr_val.val_class = dw_val_class_die_ref;
5012 attr->dw_attr_val.v.val_die_ref.die = targ_die;
5013 attr->dw_attr_val.v.val_die_ref.external = 0;
5014 add_dwarf_attr (die, attr);
5017 /* Add an AT_specification attribute to a DIE, and also make the back
5018 pointer from the specification to the definition. */
5021 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
5023 add_AT_die_ref (die, DW_AT_specification, targ_die);
5024 gcc_assert (!targ_die->die_definition);
5025 targ_die->die_definition = die;
5028 static inline dw_die_ref
5029 AT_ref (dw_attr_ref a)
5031 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5032 return a->dw_attr_val.v.val_die_ref.die;
5036 AT_ref_external (dw_attr_ref a)
5038 if (a && AT_class (a) == dw_val_class_die_ref)
5039 return a->dw_attr_val.v.val_die_ref.external;
5045 set_AT_ref_external (dw_attr_ref a, int i)
5047 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5048 a->dw_attr_val.v.val_die_ref.external = i;
5051 /* Add an FDE reference attribute value to a DIE. */
5054 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
5056 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5058 attr->dw_attr_next = NULL;
5059 attr->dw_attr = attr_kind;
5060 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
5061 attr->dw_attr_val.v.val_fde_index = targ_fde;
5062 add_dwarf_attr (die, attr);
5065 /* Add a location description attribute value to a DIE. */
5068 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
5070 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5072 attr->dw_attr_next = NULL;
5073 attr->dw_attr = attr_kind;
5074 attr->dw_attr_val.val_class = dw_val_class_loc;
5075 attr->dw_attr_val.v.val_loc = loc;
5076 add_dwarf_attr (die, attr);
5079 static inline dw_loc_descr_ref
5080 AT_loc (dw_attr_ref a)
5082 gcc_assert (a && AT_class (a) == dw_val_class_loc);
5083 return a->dw_attr_val.v.val_loc;
5087 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
5089 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5091 attr->dw_attr_next = NULL;
5092 attr->dw_attr = attr_kind;
5093 attr->dw_attr_val.val_class = dw_val_class_loc_list;
5094 attr->dw_attr_val.v.val_loc_list = loc_list;
5095 add_dwarf_attr (die, attr);
5096 have_location_lists = 1;
5099 static inline dw_loc_list_ref
5100 AT_loc_list (dw_attr_ref a)
5102 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5103 return a->dw_attr_val.v.val_loc_list;
5106 /* Add an address constant attribute value to a DIE. */
5109 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
5111 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5113 attr->dw_attr_next = NULL;
5114 attr->dw_attr = attr_kind;
5115 attr->dw_attr_val.val_class = dw_val_class_addr;
5116 attr->dw_attr_val.v.val_addr = addr;
5117 add_dwarf_attr (die, attr);
5121 AT_addr (dw_attr_ref a)
5123 gcc_assert (a && AT_class (a) == dw_val_class_addr);
5124 return a->dw_attr_val.v.val_addr;
5127 /* Add a label identifier attribute value to a DIE. */
5130 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
5132 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5134 attr->dw_attr_next = NULL;
5135 attr->dw_attr = attr_kind;
5136 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
5137 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5138 add_dwarf_attr (die, attr);
5141 /* Add a section offset attribute value to a DIE. */
5144 add_AT_lbl_offset (dw_die_ref die, enum dwarf_attribute attr_kind, const char *label)
5146 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5148 attr->dw_attr_next = NULL;
5149 attr->dw_attr = attr_kind;
5150 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
5151 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
5152 add_dwarf_attr (die, attr);
5155 /* Add an offset attribute value to a DIE. */
5158 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
5159 unsigned HOST_WIDE_INT offset)
5161 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5163 attr->dw_attr_next = NULL;
5164 attr->dw_attr = attr_kind;
5165 attr->dw_attr_val.val_class = dw_val_class_offset;
5166 attr->dw_attr_val.v.val_offset = offset;
5167 add_dwarf_attr (die, attr);
5170 /* Add an range_list attribute value to a DIE. */
5173 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5174 long unsigned int offset)
5176 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5178 attr->dw_attr_next = NULL;
5179 attr->dw_attr = attr_kind;
5180 attr->dw_attr_val.val_class = dw_val_class_range_list;
5181 attr->dw_attr_val.v.val_offset = offset;
5182 add_dwarf_attr (die, attr);
5185 static inline const char *
5186 AT_lbl (dw_attr_ref a)
5188 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5189 || AT_class (a) == dw_val_class_lbl_offset));
5190 return a->dw_attr_val.v.val_lbl_id;
5193 /* Get the attribute of type attr_kind. */
5196 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5199 dw_die_ref spec = NULL;
5203 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5204 if (a->dw_attr == attr_kind)
5206 else if (a->dw_attr == DW_AT_specification
5207 || a->dw_attr == DW_AT_abstract_origin)
5211 return get_AT (spec, attr_kind);
5217 /* Return the "low pc" attribute value, typically associated with a subprogram
5218 DIE. Return null if the "low pc" attribute is either not present, or if it
5219 cannot be represented as an assembler label identifier. */
5221 static inline const char *
5222 get_AT_low_pc (dw_die_ref die)
5224 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
5226 return a ? AT_lbl (a) : NULL;
5229 /* Return the "high pc" attribute value, typically associated with a subprogram
5230 DIE. Return null if the "high pc" attribute is either not present, or if it
5231 cannot be represented as an assembler label identifier. */
5233 static inline const char *
5234 get_AT_hi_pc (dw_die_ref die)
5236 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
5238 return a ? AT_lbl (a) : NULL;
5241 /* Return the value of the string attribute designated by ATTR_KIND, or
5242 NULL if it is not present. */
5244 static inline const char *
5245 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5247 dw_attr_ref a = get_AT (die, attr_kind);
5249 return a ? AT_string (a) : NULL;
5252 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5253 if it is not present. */
5256 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5258 dw_attr_ref a = get_AT (die, attr_kind);
5260 return a ? AT_flag (a) : 0;
5263 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5264 if it is not present. */
5266 static inline unsigned
5267 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5269 dw_attr_ref a = get_AT (die, attr_kind);
5271 return a ? AT_unsigned (a) : 0;
5274 static inline dw_die_ref
5275 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5277 dw_attr_ref a = get_AT (die, attr_kind);
5279 return a ? AT_ref (a) : NULL;
5282 /* Return TRUE if the language is C or C++. */
5287 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5289 return (lang == DW_LANG_C || lang == DW_LANG_C89
5290 || lang == DW_LANG_C_plus_plus);
5293 /* Return TRUE if the language is C++. */
5298 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
5299 == DW_LANG_C_plus_plus);
5302 /* Return TRUE if the language is Fortran. */
5307 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5309 return (lang == DW_LANG_Fortran77
5310 || lang == DW_LANG_Fortran90
5311 || lang == DW_LANG_Fortran95);
5314 /* Return TRUE if the language is Java. */
5319 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5321 return lang == DW_LANG_Java;
5324 /* Return TRUE if the language is Ada. */
5329 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5331 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5334 /* Free up the memory used by A. */
5336 static inline void free_AT (dw_attr_ref);
5338 free_AT (dw_attr_ref a)
5340 if (AT_class (a) == dw_val_class_str)
5341 if (a->dw_attr_val.v.val_str->refcount)
5342 a->dw_attr_val.v.val_str->refcount--;
5345 /* Remove the specified attribute if present. */
5348 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5351 dw_attr_ref removed = NULL;
5355 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
5356 if ((*p)->dw_attr == attr_kind)
5359 *p = (*p)->dw_attr_next;
5368 /* Remove child die whose die_tag is specified tag. */
5371 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5373 dw_die_ref current, prev, next;
5374 current = die->die_child;
5376 while (current != NULL)
5378 if (current->die_tag == tag)
5380 next = current->die_sib;
5382 die->die_child = next;
5384 prev->die_sib = next;
5391 current = current->die_sib;
5396 /* Free up the memory used by DIE. */
5399 free_die (dw_die_ref die)
5401 remove_children (die);
5404 /* Discard the children of this DIE. */
5407 remove_children (dw_die_ref die)
5409 dw_die_ref child_die = die->die_child;
5411 die->die_child = NULL;
5413 while (child_die != NULL)
5415 dw_die_ref tmp_die = child_die;
5418 child_die = child_die->die_sib;
5420 for (a = tmp_die->die_attr; a != NULL;)
5422 dw_attr_ref tmp_a = a;
5424 a = a->dw_attr_next;
5432 /* Add a child DIE below its parent. We build the lists up in reverse
5433 addition order, and correct that in reverse_all_dies. */
5436 add_child_die (dw_die_ref die, dw_die_ref child_die)
5438 if (die != NULL && child_die != NULL)
5440 gcc_assert (die != child_die);
5442 child_die->die_parent = die;
5443 child_die->die_sib = die->die_child;
5444 die->die_child = child_die;
5448 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5449 is the specification, to the front of PARENT's list of children. */
5452 splice_child_die (dw_die_ref parent, dw_die_ref child)
5456 /* We want the declaration DIE from inside the class, not the
5457 specification DIE at toplevel. */
5458 if (child->die_parent != parent)
5460 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5466 gcc_assert (child->die_parent == parent
5467 || (child->die_parent
5468 == get_AT_ref (parent, DW_AT_specification)));
5470 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5473 *p = child->die_sib;
5477 child->die_parent = parent;
5478 child->die_sib = parent->die_child;
5479 parent->die_child = child;
5482 /* Return a pointer to a newly created DIE node. */
5484 static inline dw_die_ref
5485 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5487 dw_die_ref die = ggc_alloc_cleared (sizeof (die_node));
5489 die->die_tag = tag_value;
5491 if (parent_die != NULL)
5492 add_child_die (parent_die, die);
5495 limbo_die_node *limbo_node;
5497 limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node));
5498 limbo_node->die = die;
5499 limbo_node->created_for = t;
5500 limbo_node->next = limbo_die_list;
5501 limbo_die_list = limbo_node;
5507 /* Return the DIE associated with the given type specifier. */
5509 static inline dw_die_ref
5510 lookup_type_die (tree type)
5512 return TYPE_SYMTAB_DIE (type);
5515 /* Equate a DIE to a given type specifier. */
5518 equate_type_number_to_die (tree type, dw_die_ref type_die)
5520 TYPE_SYMTAB_DIE (type) = type_die;
5523 /* Returns a hash value for X (which really is a die_struct). */
5526 decl_die_table_hash (const void *x)
5528 return (hashval_t) ((const dw_die_ref) x)->decl_id;
5531 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5534 decl_die_table_eq (const void *x, const void *y)
5536 return (((const dw_die_ref) x)->decl_id == DECL_UID ((const tree) y));
5539 /* Return the DIE associated with a given declaration. */
5541 static inline dw_die_ref
5542 lookup_decl_die (tree decl)
5544 return htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5547 /* Returns a hash value for X (which really is a var_loc_list). */
5550 decl_loc_table_hash (const void *x)
5552 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5555 /* Return nonzero if decl_id of var_loc_list X is the same as
5559 decl_loc_table_eq (const void *x, const void *y)
5561 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const tree) y));
5564 /* Return the var_loc list associated with a given declaration. */
5566 static inline var_loc_list *
5567 lookup_decl_loc (tree decl)
5569 return htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5572 /* Equate a DIE to a particular declaration. */
5575 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5577 unsigned int decl_id = DECL_UID (decl);
5580 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5582 decl_die->decl_id = decl_id;
5585 /* Add a variable location node to the linked list for DECL. */
5588 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
5590 unsigned int decl_id = DECL_UID (decl);
5594 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5597 temp = ggc_alloc_cleared (sizeof (var_loc_list));
5598 temp->decl_id = decl_id;
5606 /* If the current location is the same as the end of the list,
5607 we have nothing to do. */
5608 if (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
5609 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
5611 /* Add LOC to the end of list and update LAST. */
5612 temp->last->next = loc;
5616 /* Do not add empty location to the beginning of the list. */
5617 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
5624 /* Keep track of the number of spaces used to indent the
5625 output of the debugging routines that print the structure of
5626 the DIE internal representation. */
5627 static int print_indent;
5629 /* Indent the line the number of spaces given by print_indent. */
5632 print_spaces (FILE *outfile)
5634 fprintf (outfile, "%*s", print_indent, "");
5637 /* Print the information associated with a given DIE, and its children.
5638 This routine is a debugging aid only. */
5641 print_die (dw_die_ref die, FILE *outfile)
5646 print_spaces (outfile);
5647 fprintf (outfile, "DIE %4lu: %s\n",
5648 die->die_offset, dwarf_tag_name (die->die_tag));
5649 print_spaces (outfile);
5650 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5651 fprintf (outfile, " offset: %lu\n", die->die_offset);
5653 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5655 print_spaces (outfile);
5656 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5658 switch (AT_class (a))
5660 case dw_val_class_addr:
5661 fprintf (outfile, "address");
5663 case dw_val_class_offset:
5664 fprintf (outfile, "offset");
5666 case dw_val_class_loc:
5667 fprintf (outfile, "location descriptor");
5669 case dw_val_class_loc_list:
5670 fprintf (outfile, "location list -> label:%s",
5671 AT_loc_list (a)->ll_symbol);
5673 case dw_val_class_range_list:
5674 fprintf (outfile, "range list");
5676 case dw_val_class_const:
5677 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5679 case dw_val_class_unsigned_const:
5680 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5682 case dw_val_class_long_long:
5683 fprintf (outfile, "constant (%lu,%lu)",
5684 a->dw_attr_val.v.val_long_long.hi,
5685 a->dw_attr_val.v.val_long_long.low);
5687 case dw_val_class_vec:
5688 fprintf (outfile, "floating-point or vector constant");
5690 case dw_val_class_flag:
5691 fprintf (outfile, "%u", AT_flag (a));
5693 case dw_val_class_die_ref:
5694 if (AT_ref (a) != NULL)
5696 if (AT_ref (a)->die_symbol)
5697 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5699 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5702 fprintf (outfile, "die -> <null>");
5704 case dw_val_class_lbl_id:
5705 case dw_val_class_lbl_offset:
5706 fprintf (outfile, "label: %s", AT_lbl (a));
5708 case dw_val_class_str:
5709 if (AT_string (a) != NULL)
5710 fprintf (outfile, "\"%s\"", AT_string (a));
5712 fprintf (outfile, "<null>");
5718 fprintf (outfile, "\n");
5721 if (die->die_child != NULL)
5724 for (c = die->die_child; c != NULL; c = c->die_sib)
5725 print_die (c, outfile);
5729 if (print_indent == 0)
5730 fprintf (outfile, "\n");
5733 /* Print the contents of the source code line number correspondence table.
5734 This routine is a debugging aid only. */
5737 print_dwarf_line_table (FILE *outfile)
5740 dw_line_info_ref line_info;
5742 fprintf (outfile, "\n\nDWARF source line information\n");
5743 for (i = 1; i < line_info_table_in_use; i++)
5745 line_info = &line_info_table[i];
5746 fprintf (outfile, "%5d: ", i);
5747 fprintf (outfile, "%-20s",
5748 VARRAY_CHAR_PTR (file_table, line_info->dw_file_num));
5749 fprintf (outfile, "%6ld", line_info->dw_line_num);
5750 fprintf (outfile, "\n");
5753 fprintf (outfile, "\n\n");
5756 /* Print the information collected for a given DIE. */
5759 debug_dwarf_die (dw_die_ref die)
5761 print_die (die, stderr);
5764 /* Print all DWARF information collected for the compilation unit.
5765 This routine is a debugging aid only. */
5771 print_die (comp_unit_die, stderr);
5772 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5773 print_dwarf_line_table (stderr);
5776 /* We build up the lists of children and attributes by pushing new ones
5777 onto the beginning of the list. Reverse the lists for DIE so that
5778 they are in order of addition. */
5781 reverse_die_lists (dw_die_ref die)
5783 dw_die_ref c, cp, cn;
5784 dw_attr_ref a, ap, an;
5786 for (a = die->die_attr, ap = 0; a; a = an)
5788 an = a->dw_attr_next;
5789 a->dw_attr_next = ap;
5795 for (c = die->die_child, cp = 0; c; c = cn)
5802 die->die_child = cp;
5805 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5806 reverse all dies in add_sibling_attributes, which runs through all the dies,
5807 it would reverse all the dies. Now, however, since we don't call
5808 reverse_die_lists in add_sibling_attributes, we need a routine to
5809 recursively reverse all the dies. This is that routine. */
5812 reverse_all_dies (dw_die_ref die)
5816 reverse_die_lists (die);
5818 for (c = die->die_child; c; c = c->die_sib)
5819 reverse_all_dies (c);
5822 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5823 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5824 DIE that marks the start of the DIEs for this include file. */
5827 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5829 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5830 dw_die_ref new_unit = gen_compile_unit_die (filename);
5832 new_unit->die_sib = old_unit;
5836 /* Close an include-file CU and reopen the enclosing one. */
5839 pop_compile_unit (dw_die_ref old_unit)
5841 dw_die_ref new_unit = old_unit->die_sib;
5843 old_unit->die_sib = NULL;
5847 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5848 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5850 /* Calculate the checksum of a location expression. */
5853 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5855 CHECKSUM (loc->dw_loc_opc);
5856 CHECKSUM (loc->dw_loc_oprnd1);
5857 CHECKSUM (loc->dw_loc_oprnd2);
5860 /* Calculate the checksum of an attribute. */
5863 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5865 dw_loc_descr_ref loc;
5868 CHECKSUM (at->dw_attr);
5870 /* We don't care about differences in file numbering. */
5871 if (at->dw_attr == DW_AT_decl_file
5872 /* Or that this was compiled with a different compiler snapshot; if
5873 the output is the same, that's what matters. */
5874 || at->dw_attr == DW_AT_producer)
5877 switch (AT_class (at))
5879 case dw_val_class_const:
5880 CHECKSUM (at->dw_attr_val.v.val_int);
5882 case dw_val_class_unsigned_const:
5883 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5885 case dw_val_class_long_long:
5886 CHECKSUM (at->dw_attr_val.v.val_long_long);
5888 case dw_val_class_vec:
5889 CHECKSUM (at->dw_attr_val.v.val_vec);
5891 case dw_val_class_flag:
5892 CHECKSUM (at->dw_attr_val.v.val_flag);
5894 case dw_val_class_str:
5895 CHECKSUM_STRING (AT_string (at));
5898 case dw_val_class_addr:
5900 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5901 CHECKSUM_STRING (XSTR (r, 0));
5904 case dw_val_class_offset:
5905 CHECKSUM (at->dw_attr_val.v.val_offset);
5908 case dw_val_class_loc:
5909 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5910 loc_checksum (loc, ctx);
5913 case dw_val_class_die_ref:
5914 die_checksum (AT_ref (at), ctx, mark);
5917 case dw_val_class_fde_ref:
5918 case dw_val_class_lbl_id:
5919 case dw_val_class_lbl_offset:
5927 /* Calculate the checksum of a DIE. */
5930 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5935 /* To avoid infinite recursion. */
5938 CHECKSUM (die->die_mark);
5941 die->die_mark = ++(*mark);
5943 CHECKSUM (die->die_tag);
5945 for (a = die->die_attr; a; a = a->dw_attr_next)
5946 attr_checksum (a, ctx, mark);
5948 for (c = die->die_child; c; c = c->die_sib)
5949 die_checksum (c, ctx, mark);
5953 #undef CHECKSUM_STRING
5955 /* Do the location expressions look same? */
5957 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
5959 return loc1->dw_loc_opc == loc2->dw_loc_opc
5960 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
5961 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
5964 /* Do the values look the same? */
5966 same_dw_val_p (dw_val_node *v1, dw_val_node *v2, int *mark)
5968 dw_loc_descr_ref loc1, loc2;
5971 if (v1->val_class != v2->val_class)
5974 switch (v1->val_class)
5976 case dw_val_class_const:
5977 return v1->v.val_int == v2->v.val_int;
5978 case dw_val_class_unsigned_const:
5979 return v1->v.val_unsigned == v2->v.val_unsigned;
5980 case dw_val_class_long_long:
5981 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
5982 && v1->v.val_long_long.low == v2->v.val_long_long.low;
5983 case dw_val_class_vec:
5984 if (v1->v.val_vec.length != v2->v.val_vec.length
5985 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
5987 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
5988 v1->v.val_vec.length * v1->v.val_vec.elt_size))
5991 case dw_val_class_flag:
5992 return v1->v.val_flag == v2->v.val_flag;
5993 case dw_val_class_str:
5994 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
5996 case dw_val_class_addr:
5997 r1 = v1->v.val_addr;
5998 r2 = v2->v.val_addr;
5999 if (GET_CODE (r1) != GET_CODE (r2))
6001 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
6002 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
6004 case dw_val_class_offset:
6005 return v1->v.val_offset == v2->v.val_offset;
6007 case dw_val_class_loc:
6008 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6010 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6011 if (!same_loc_p (loc1, loc2, mark))
6013 return !loc1 && !loc2;
6015 case dw_val_class_die_ref:
6016 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6018 case dw_val_class_fde_ref:
6019 case dw_val_class_lbl_id:
6020 case dw_val_class_lbl_offset:
6028 /* Do the attributes look the same? */
6031 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
6033 if (at1->dw_attr != at2->dw_attr)
6036 /* We don't care about differences in file numbering. */
6037 if (at1->dw_attr == DW_AT_decl_file
6038 /* Or that this was compiled with a different compiler snapshot; if
6039 the output is the same, that's what matters. */
6040 || at1->dw_attr == DW_AT_producer)
6043 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6046 /* Do the dies look the same? */
6049 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6054 /* To avoid infinite recursion. */
6056 return die1->die_mark == die2->die_mark;
6057 die1->die_mark = die2->die_mark = ++(*mark);
6059 if (die1->die_tag != die2->die_tag)
6062 for (a1 = die1->die_attr, a2 = die2->die_attr;
6064 a1 = a1->dw_attr_next, a2 = a2->dw_attr_next)
6065 if (!same_attr_p (a1, a2, mark))
6070 for (c1 = die1->die_child, c2 = die2->die_child;
6072 c1 = c1->die_sib, c2 = c2->die_sib)
6073 if (!same_die_p (c1, c2, mark))
6081 /* Do the dies look the same? Wrapper around same_die_p. */
6084 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6087 int ret = same_die_p (die1, die2, &mark);
6089 unmark_all_dies (die1);
6090 unmark_all_dies (die2);
6095 /* The prefix to attach to symbols on DIEs in the current comdat debug
6097 static char *comdat_symbol_id;
6099 /* The index of the current symbol within the current comdat CU. */
6100 static unsigned int comdat_symbol_number;
6102 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6103 children, and set comdat_symbol_id accordingly. */
6106 compute_section_prefix (dw_die_ref unit_die)
6108 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6109 const char *base = die_name ? lbasename (die_name) : "anonymous";
6110 char *name = alloca (strlen (base) + 64);
6113 unsigned char checksum[16];
6116 /* Compute the checksum of the DIE, then append part of it as hex digits to
6117 the name filename of the unit. */
6119 md5_init_ctx (&ctx);
6121 die_checksum (unit_die, &ctx, &mark);
6122 unmark_all_dies (unit_die);
6123 md5_finish_ctx (&ctx, checksum);
6125 sprintf (name, "%s.", base);
6126 clean_symbol_name (name);
6128 p = name + strlen (name);
6129 for (i = 0; i < 4; i++)
6131 sprintf (p, "%.2x", checksum[i]);
6135 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
6136 comdat_symbol_number = 0;
6139 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6142 is_type_die (dw_die_ref die)
6144 switch (die->die_tag)
6146 case DW_TAG_array_type:
6147 case DW_TAG_class_type:
6148 case DW_TAG_enumeration_type:
6149 case DW_TAG_pointer_type:
6150 case DW_TAG_reference_type:
6151 case DW_TAG_string_type:
6152 case DW_TAG_structure_type:
6153 case DW_TAG_subroutine_type:
6154 case DW_TAG_union_type:
6155 case DW_TAG_ptr_to_member_type:
6156 case DW_TAG_set_type:
6157 case DW_TAG_subrange_type:
6158 case DW_TAG_base_type:
6159 case DW_TAG_const_type:
6160 case DW_TAG_file_type:
6161 case DW_TAG_packed_type:
6162 case DW_TAG_volatile_type:
6163 case DW_TAG_typedef:
6170 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6171 Basically, we want to choose the bits that are likely to be shared between
6172 compilations (types) and leave out the bits that are specific to individual
6173 compilations (functions). */
6176 is_comdat_die (dw_die_ref c)
6178 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6179 we do for stabs. The advantage is a greater likelihood of sharing between
6180 objects that don't include headers in the same order (and therefore would
6181 put the base types in a different comdat). jason 8/28/00 */
6183 if (c->die_tag == DW_TAG_base_type)
6186 if (c->die_tag == DW_TAG_pointer_type
6187 || c->die_tag == DW_TAG_reference_type
6188 || c->die_tag == DW_TAG_const_type
6189 || c->die_tag == DW_TAG_volatile_type)
6191 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6193 return t ? is_comdat_die (t) : 0;
6196 return is_type_die (c);
6199 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6200 compilation unit. */
6203 is_symbol_die (dw_die_ref c)
6205 return (is_type_die (c)
6206 || (get_AT (c, DW_AT_declaration)
6207 && !get_AT (c, DW_AT_specification)));
6211 gen_internal_sym (const char *prefix)
6215 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6216 return xstrdup (buf);
6219 /* Assign symbols to all worthy DIEs under DIE. */
6222 assign_symbol_names (dw_die_ref die)
6226 if (is_symbol_die (die))
6228 if (comdat_symbol_id)
6230 char *p = alloca (strlen (comdat_symbol_id) + 64);
6232 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6233 comdat_symbol_id, comdat_symbol_number++);
6234 die->die_symbol = xstrdup (p);
6237 die->die_symbol = gen_internal_sym ("LDIE");
6240 for (c = die->die_child; c != NULL; c = c->die_sib)
6241 assign_symbol_names (c);
6244 struct cu_hash_table_entry
6247 unsigned min_comdat_num, max_comdat_num;
6248 struct cu_hash_table_entry *next;
6251 /* Routines to manipulate hash table of CUs. */
6253 htab_cu_hash (const void *of)
6255 const struct cu_hash_table_entry *entry = of;
6257 return htab_hash_string (entry->cu->die_symbol);
6261 htab_cu_eq (const void *of1, const void *of2)
6263 const struct cu_hash_table_entry *entry1 = of1;
6264 const struct die_struct *entry2 = of2;
6266 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
6270 htab_cu_del (void *what)
6272 struct cu_hash_table_entry *next, *entry = what;
6282 /* Check whether we have already seen this CU and set up SYM_NUM
6285 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6287 struct cu_hash_table_entry dummy;
6288 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6290 dummy.max_comdat_num = 0;
6292 slot = (struct cu_hash_table_entry **)
6293 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6297 for (; entry; last = entry, entry = entry->next)
6299 if (same_die_p_wrap (cu, entry->cu))
6305 *sym_num = entry->min_comdat_num;
6309 entry = xcalloc (1, sizeof (struct cu_hash_table_entry));
6311 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6312 entry->next = *slot;
6318 /* Record SYM_NUM to record of CU in HTABLE. */
6320 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6322 struct cu_hash_table_entry **slot, *entry;
6324 slot = (struct cu_hash_table_entry **)
6325 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6329 entry->max_comdat_num = sym_num;
6332 /* Traverse the DIE (which is always comp_unit_die), and set up
6333 additional compilation units for each of the include files we see
6334 bracketed by BINCL/EINCL. */
6337 break_out_includes (dw_die_ref die)
6340 dw_die_ref unit = NULL;
6341 limbo_die_node *node, **pnode;
6342 htab_t cu_hash_table;
6344 for (ptr = &(die->die_child); *ptr;)
6346 dw_die_ref c = *ptr;
6348 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6349 || (unit && is_comdat_die (c)))
6351 /* This DIE is for a secondary CU; remove it from the main one. */
6354 if (c->die_tag == DW_TAG_GNU_BINCL)
6356 unit = push_new_compile_unit (unit, c);
6359 else if (c->die_tag == DW_TAG_GNU_EINCL)
6361 unit = pop_compile_unit (unit);
6365 add_child_die (unit, c);
6369 /* Leave this DIE in the main CU. */
6370 ptr = &(c->die_sib);
6376 /* We can only use this in debugging, since the frontend doesn't check
6377 to make sure that we leave every include file we enter. */
6381 assign_symbol_names (die);
6382 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6383 for (node = limbo_die_list, pnode = &limbo_die_list;
6389 compute_section_prefix (node->die);
6390 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6391 &comdat_symbol_number);
6392 assign_symbol_names (node->die);
6394 *pnode = node->next;
6397 pnode = &node->next;
6398 record_comdat_symbol_number (node->die, cu_hash_table,
6399 comdat_symbol_number);
6402 htab_delete (cu_hash_table);
6405 /* Traverse the DIE and add a sibling attribute if it may have the
6406 effect of speeding up access to siblings. To save some space,
6407 avoid generating sibling attributes for DIE's without children. */
6410 add_sibling_attributes (dw_die_ref die)
6414 if (die->die_tag != DW_TAG_compile_unit
6415 && die->die_sib && die->die_child != NULL)
6416 /* Add the sibling link to the front of the attribute list. */
6417 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
6419 for (c = die->die_child; c != NULL; c = c->die_sib)
6420 add_sibling_attributes (c);
6423 /* Output all location lists for the DIE and its children. */
6426 output_location_lists (dw_die_ref die)
6431 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
6432 if (AT_class (d_attr) == dw_val_class_loc_list)
6433 output_loc_list (AT_loc_list (d_attr));
6435 for (c = die->die_child; c != NULL; c = c->die_sib)
6436 output_location_lists (c);
6440 /* The format of each DIE (and its attribute value pairs) is encoded in an
6441 abbreviation table. This routine builds the abbreviation table and assigns
6442 a unique abbreviation id for each abbreviation entry. The children of each
6443 die are visited recursively. */
6446 build_abbrev_table (dw_die_ref die)
6448 unsigned long abbrev_id;
6449 unsigned int n_alloc;
6451 dw_attr_ref d_attr, a_attr;
6453 /* Scan the DIE references, and mark as external any that refer to
6454 DIEs from other CUs (i.e. those which are not marked). */
6455 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
6456 if (AT_class (d_attr) == dw_val_class_die_ref
6457 && AT_ref (d_attr)->die_mark == 0)
6459 gcc_assert (AT_ref (d_attr)->die_symbol);
6461 set_AT_ref_external (d_attr, 1);
6464 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6466 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6468 if (abbrev->die_tag == die->die_tag)
6470 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
6472 a_attr = abbrev->die_attr;
6473 d_attr = die->die_attr;
6475 while (a_attr != NULL && d_attr != NULL)
6477 if ((a_attr->dw_attr != d_attr->dw_attr)
6478 || (value_format (a_attr) != value_format (d_attr)))
6481 a_attr = a_attr->dw_attr_next;
6482 d_attr = d_attr->dw_attr_next;
6485 if (a_attr == NULL && d_attr == NULL)
6491 if (abbrev_id >= abbrev_die_table_in_use)
6493 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
6495 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
6496 abbrev_die_table = ggc_realloc (abbrev_die_table,
6497 sizeof (dw_die_ref) * n_alloc);
6499 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
6500 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
6501 abbrev_die_table_allocated = n_alloc;
6504 ++abbrev_die_table_in_use;
6505 abbrev_die_table[abbrev_id] = die;
6508 die->die_abbrev = abbrev_id;
6509 for (c = die->die_child; c != NULL; c = c->die_sib)
6510 build_abbrev_table (c);
6513 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6516 constant_size (long unsigned int value)
6523 log = floor_log2 (value);
6526 log = 1 << (floor_log2 (log) + 1);
6531 /* Return the size of a DIE as it is represented in the
6532 .debug_info section. */
6534 static unsigned long
6535 size_of_die (dw_die_ref die)
6537 unsigned long size = 0;
6540 size += size_of_uleb128 (die->die_abbrev);
6541 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6543 switch (AT_class (a))
6545 case dw_val_class_addr:
6546 size += DWARF2_ADDR_SIZE;
6548 case dw_val_class_offset:
6549 size += DWARF_OFFSET_SIZE;
6551 case dw_val_class_loc:
6553 unsigned long lsize = size_of_locs (AT_loc (a));
6556 size += constant_size (lsize);
6560 case dw_val_class_loc_list:
6561 size += DWARF_OFFSET_SIZE;
6563 case dw_val_class_range_list:
6564 size += DWARF_OFFSET_SIZE;
6566 case dw_val_class_const:
6567 size += size_of_sleb128 (AT_int (a));
6569 case dw_val_class_unsigned_const:
6570 size += constant_size (AT_unsigned (a));
6572 case dw_val_class_long_long:
6573 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
6575 case dw_val_class_vec:
6576 size += 1 + (a->dw_attr_val.v.val_vec.length
6577 * a->dw_attr_val.v.val_vec.elt_size); /* block */
6579 case dw_val_class_flag:
6582 case dw_val_class_die_ref:
6583 if (AT_ref_external (a))
6584 size += DWARF2_ADDR_SIZE;
6586 size += DWARF_OFFSET_SIZE;
6588 case dw_val_class_fde_ref:
6589 size += DWARF_OFFSET_SIZE;
6591 case dw_val_class_lbl_id:
6592 size += DWARF2_ADDR_SIZE;
6594 case dw_val_class_lbl_offset:
6595 size += DWARF_OFFSET_SIZE;
6597 case dw_val_class_str:
6598 if (AT_string_form (a) == DW_FORM_strp)
6599 size += DWARF_OFFSET_SIZE;
6601 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
6611 /* Size the debugging information associated with a given DIE. Visits the
6612 DIE's children recursively. Updates the global variable next_die_offset, on
6613 each time through. Uses the current value of next_die_offset to update the
6614 die_offset field in each DIE. */
6617 calc_die_sizes (dw_die_ref die)
6621 die->die_offset = next_die_offset;
6622 next_die_offset += size_of_die (die);
6624 for (c = die->die_child; c != NULL; c = c->die_sib)
6627 if (die->die_child != NULL)
6628 /* Count the null byte used to terminate sibling lists. */
6629 next_die_offset += 1;
6632 /* Set the marks for a die and its children. We do this so
6633 that we know whether or not a reference needs to use FORM_ref_addr; only
6634 DIEs in the same CU will be marked. We used to clear out the offset
6635 and use that as the flag, but ran into ordering problems. */
6638 mark_dies (dw_die_ref die)
6642 gcc_assert (!die->die_mark);
6645 for (c = die->die_child; c; c = c->die_sib)
6649 /* Clear the marks for a die and its children. */
6652 unmark_dies (dw_die_ref die)
6656 gcc_assert (die->die_mark);
6659 for (c = die->die_child; c; c = c->die_sib)
6663 /* Clear the marks for a die, its children and referred dies. */
6666 unmark_all_dies (dw_die_ref die)
6675 for (c = die->die_child; c; c = c->die_sib)
6676 unmark_all_dies (c);
6678 for (a = die->die_attr; a; a = a->dw_attr_next)
6679 if (AT_class (a) == dw_val_class_die_ref)
6680 unmark_all_dies (AT_ref (a));
6683 /* Return the size of the .debug_pubnames table generated for the
6684 compilation unit. */
6686 static unsigned long
6687 size_of_pubnames (void)
6692 size = DWARF_PUBNAMES_HEADER_SIZE;
6693 for (i = 0; i < pubname_table_in_use; i++)
6695 pubname_ref p = &pubname_table[i];
6696 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
6699 size += DWARF_OFFSET_SIZE;
6703 /* Return the size of the information in the .debug_aranges section. */
6705 static unsigned long
6706 size_of_aranges (void)
6710 size = DWARF_ARANGES_HEADER_SIZE;
6712 /* Count the address/length pair for this compilation unit. */
6713 size += 2 * DWARF2_ADDR_SIZE;
6714 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6716 /* Count the two zero words used to terminated the address range table. */
6717 size += 2 * DWARF2_ADDR_SIZE;
6721 /* Select the encoding of an attribute value. */
6723 static enum dwarf_form
6724 value_format (dw_attr_ref a)
6726 switch (a->dw_attr_val.val_class)
6728 case dw_val_class_addr:
6729 return DW_FORM_addr;
6730 case dw_val_class_range_list:
6731 case dw_val_class_offset:
6732 switch (DWARF_OFFSET_SIZE)
6735 return DW_FORM_data4;
6737 return DW_FORM_data8;
6741 case dw_val_class_loc_list:
6742 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6743 .debug_loc section */
6744 return DW_FORM_data4;
6745 case dw_val_class_loc:
6746 switch (constant_size (size_of_locs (AT_loc (a))))
6749 return DW_FORM_block1;
6751 return DW_FORM_block2;
6755 case dw_val_class_const:
6756 return DW_FORM_sdata;
6757 case dw_val_class_unsigned_const:
6758 switch (constant_size (AT_unsigned (a)))
6761 return DW_FORM_data1;
6763 return DW_FORM_data2;
6765 return DW_FORM_data4;
6767 return DW_FORM_data8;
6771 case dw_val_class_long_long:
6772 return DW_FORM_block1;
6773 case dw_val_class_vec:
6774 return DW_FORM_block1;
6775 case dw_val_class_flag:
6776 return DW_FORM_flag;
6777 case dw_val_class_die_ref:
6778 if (AT_ref_external (a))
6779 return DW_FORM_ref_addr;
6782 case dw_val_class_fde_ref:
6783 return DW_FORM_data;
6784 case dw_val_class_lbl_id:
6785 return DW_FORM_addr;
6786 case dw_val_class_lbl_offset:
6787 return DW_FORM_data;
6788 case dw_val_class_str:
6789 return AT_string_form (a);
6796 /* Output the encoding of an attribute value. */
6799 output_value_format (dw_attr_ref a)
6801 enum dwarf_form form = value_format (a);
6803 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6806 /* Output the .debug_abbrev section which defines the DIE abbreviation
6810 output_abbrev_section (void)
6812 unsigned long abbrev_id;
6816 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6818 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6820 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6821 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6822 dwarf_tag_name (abbrev->die_tag));
6824 if (abbrev->die_child != NULL)
6825 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6827 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6829 for (a_attr = abbrev->die_attr; a_attr != NULL;
6830 a_attr = a_attr->dw_attr_next)
6832 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6833 dwarf_attr_name (a_attr->dw_attr));
6834 output_value_format (a_attr);
6837 dw2_asm_output_data (1, 0, NULL);
6838 dw2_asm_output_data (1, 0, NULL);
6841 /* Terminate the table. */
6842 dw2_asm_output_data (1, 0, NULL);
6845 /* Output a symbol we can use to refer to this DIE from another CU. */
6848 output_die_symbol (dw_die_ref die)
6850 char *sym = die->die_symbol;
6855 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6856 /* We make these global, not weak; if the target doesn't support
6857 .linkonce, it doesn't support combining the sections, so debugging
6859 targetm.asm_out.globalize_label (asm_out_file, sym);
6861 ASM_OUTPUT_LABEL (asm_out_file, sym);
6864 /* Return a new location list, given the begin and end range, and the
6865 expression. gensym tells us whether to generate a new internal symbol for
6866 this location list node, which is done for the head of the list only. */
6868 static inline dw_loc_list_ref
6869 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
6870 const char *section, unsigned int gensym)
6872 dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node));
6874 retlist->begin = begin;
6876 retlist->expr = expr;
6877 retlist->section = section;
6879 retlist->ll_symbol = gen_internal_sym ("LLST");
6884 /* Add a location description expression to a location list. */
6887 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
6888 const char *begin, const char *end,
6889 const char *section)
6893 /* Find the end of the chain. */
6894 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6897 /* Add a new location list node to the list. */
6898 *d = new_loc_list (descr, begin, end, section, 0);
6902 dwarf2out_switch_text_section (void)
6908 fde = &fde_table[fde_table_in_use - 1];
6909 fde->dw_fde_switched_sections = true;
6910 fde->dw_fde_hot_section_label = cfun->hot_section_label;
6911 fde->dw_fde_hot_section_end_label = cfun->hot_section_end_label;
6912 fde->dw_fde_unlikely_section_label = cfun->cold_section_label;
6913 fde->dw_fde_unlikely_section_end_label = cfun->cold_section_end_label;
6914 have_switched_text_section = true;
6917 /* Output the location list given to us. */
6920 output_loc_list (dw_loc_list_ref list_head)
6922 dw_loc_list_ref curr = list_head;
6924 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6926 /* Walk the location list, and output each range + expression. */
6927 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
6930 if (!separate_line_info_table_in_use && !have_switched_text_section)
6932 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6933 "Location list begin address (%s)",
6934 list_head->ll_symbol);
6935 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6936 "Location list end address (%s)",
6937 list_head->ll_symbol);
6941 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
6942 "Location list begin address (%s)",
6943 list_head->ll_symbol);
6944 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
6945 "Location list end address (%s)",
6946 list_head->ll_symbol);
6948 size = size_of_locs (curr->expr);
6950 /* Output the block length for this list of location operations. */
6951 gcc_assert (size <= 0xffff);
6952 dw2_asm_output_data (2, size, "%s", "Location expression size");
6954 output_loc_sequence (curr->expr);
6957 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
6958 "Location list terminator begin (%s)",
6959 list_head->ll_symbol);
6960 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
6961 "Location list terminator end (%s)",
6962 list_head->ll_symbol);
6965 /* Output the DIE and its attributes. Called recursively to generate
6966 the definitions of each child DIE. */
6969 output_die (dw_die_ref die)
6975 /* If someone in another CU might refer to us, set up a symbol for
6976 them to point to. */
6977 if (die->die_symbol)
6978 output_die_symbol (die);
6980 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6981 die->die_offset, dwarf_tag_name (die->die_tag));
6983 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6985 const char *name = dwarf_attr_name (a->dw_attr);
6987 switch (AT_class (a))
6989 case dw_val_class_addr:
6990 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6993 case dw_val_class_offset:
6994 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6998 case dw_val_class_range_list:
7000 char *p = strchr (ranges_section_label, '\0');
7002 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
7003 a->dw_attr_val.v.val_offset);
7004 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
7010 case dw_val_class_loc:
7011 size = size_of_locs (AT_loc (a));
7013 /* Output the block length for this list of location operations. */
7014 dw2_asm_output_data (constant_size (size), size, "%s", name);
7016 output_loc_sequence (AT_loc (a));
7019 case dw_val_class_const:
7020 /* ??? It would be slightly more efficient to use a scheme like is
7021 used for unsigned constants below, but gdb 4.x does not sign
7022 extend. Gdb 5.x does sign extend. */
7023 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
7026 case dw_val_class_unsigned_const:
7027 dw2_asm_output_data (constant_size (AT_unsigned (a)),
7028 AT_unsigned (a), "%s", name);
7031 case dw_val_class_long_long:
7033 unsigned HOST_WIDE_INT first, second;
7035 dw2_asm_output_data (1,
7036 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7039 if (WORDS_BIG_ENDIAN)
7041 first = a->dw_attr_val.v.val_long_long.hi;
7042 second = a->dw_attr_val.v.val_long_long.low;
7046 first = a->dw_attr_val.v.val_long_long.low;
7047 second = a->dw_attr_val.v.val_long_long.hi;
7050 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7051 first, "long long constant");
7052 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7057 case dw_val_class_vec:
7059 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
7060 unsigned int len = a->dw_attr_val.v.val_vec.length;
7064 dw2_asm_output_data (1, len * elt_size, "%s", name);
7065 if (elt_size > sizeof (HOST_WIDE_INT))
7070 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
7073 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
7074 "fp or vector constant word %u", i);
7078 case dw_val_class_flag:
7079 dw2_asm_output_data (1, AT_flag (a), "%s", name);
7082 case dw_val_class_loc_list:
7084 char *sym = AT_loc_list (a)->ll_symbol;
7087 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, "%s", name);
7091 case dw_val_class_die_ref:
7092 if (AT_ref_external (a))
7094 char *sym = AT_ref (a)->die_symbol;
7097 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
7101 gcc_assert (AT_ref (a)->die_offset);
7102 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
7107 case dw_val_class_fde_ref:
7111 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
7112 a->dw_attr_val.v.val_fde_index * 2);
7113 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
7117 case dw_val_class_lbl_id:
7118 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
7121 case dw_val_class_lbl_offset:
7122 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
7125 case dw_val_class_str:
7126 if (AT_string_form (a) == DW_FORM_strp)
7127 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
7128 a->dw_attr_val.v.val_str->label,
7129 "%s: \"%s\"", name, AT_string (a));
7131 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
7139 for (c = die->die_child; c != NULL; c = c->die_sib)
7142 /* Add null byte to terminate sibling list. */
7143 if (die->die_child != NULL)
7144 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7148 /* Output the compilation unit that appears at the beginning of the
7149 .debug_info section, and precedes the DIE descriptions. */
7152 output_compilation_unit_header (void)
7154 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7155 dw2_asm_output_data (4, 0xffffffff,
7156 "Initial length escape value indicating 64-bit DWARF extension");
7157 dw2_asm_output_data (DWARF_OFFSET_SIZE,
7158 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
7159 "Length of Compilation Unit Info");
7160 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
7161 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
7162 "Offset Into Abbrev. Section");
7163 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
7166 /* Output the compilation unit DIE and its children. */
7169 output_comp_unit (dw_die_ref die, int output_if_empty)
7171 const char *secname;
7174 /* Unless we are outputting main CU, we may throw away empty ones. */
7175 if (!output_if_empty && die->die_child == NULL)
7178 /* Even if there are no children of this DIE, we must output the information
7179 about the compilation unit. Otherwise, on an empty translation unit, we
7180 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7181 will then complain when examining the file. First mark all the DIEs in
7182 this CU so we know which get local refs. */
7185 build_abbrev_table (die);
7187 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7188 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7189 calc_die_sizes (die);
7191 oldsym = die->die_symbol;
7194 tmp = alloca (strlen (oldsym) + 24);
7196 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
7198 die->die_symbol = NULL;
7201 secname = (const char *) DEBUG_INFO_SECTION;
7203 /* Output debugging information. */
7204 named_section_flags (secname, SECTION_DEBUG);
7205 output_compilation_unit_header ();
7208 /* Leave the marks on the main CU, so we can check them in
7213 die->die_symbol = oldsym;
7217 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
7218 output of lang_hooks.decl_printable_name for C++ looks like
7219 "A::f(int)". Let's drop the argument list, and maybe the scope. */
7222 dwarf2_name (tree decl, int scope)
7224 return lang_hooks.decl_printable_name (decl, scope ? 1 : 0);
7227 /* Add a new entry to .debug_pubnames if appropriate. */
7230 add_pubname (tree decl, dw_die_ref die)
7234 if (! TREE_PUBLIC (decl))
7237 if (pubname_table_in_use == pubname_table_allocated)
7239 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
7241 = ggc_realloc (pubname_table,
7242 (pubname_table_allocated * sizeof (pubname_entry)));
7243 memset (pubname_table + pubname_table_in_use, 0,
7244 PUBNAME_TABLE_INCREMENT * sizeof (pubname_entry));
7247 p = &pubname_table[pubname_table_in_use++];
7249 p->name = xstrdup (dwarf2_name (decl, 1));
7252 /* Output the public names table used to speed up access to externally
7253 visible names. For now, only generate entries for externally
7254 visible procedures. */
7257 output_pubnames (void)
7260 unsigned long pubnames_length = size_of_pubnames ();
7262 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7263 dw2_asm_output_data (4, 0xffffffff,
7264 "Initial length escape value indicating 64-bit DWARF extension");
7265 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7266 "Length of Public Names Info");
7267 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7268 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7269 "Offset of Compilation Unit Info");
7270 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
7271 "Compilation Unit Length");
7273 for (i = 0; i < pubname_table_in_use; i++)
7275 pubname_ref pub = &pubname_table[i];
7277 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7278 gcc_assert (pub->die->die_mark);
7280 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
7283 dw2_asm_output_nstring (pub->name, -1, "external name");
7286 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
7289 /* Add a new entry to .debug_aranges if appropriate. */
7292 add_arange (tree decl, dw_die_ref die)
7294 if (! DECL_SECTION_NAME (decl))
7297 if (arange_table_in_use == arange_table_allocated)
7299 arange_table_allocated += ARANGE_TABLE_INCREMENT;
7300 arange_table = ggc_realloc (arange_table,
7301 (arange_table_allocated
7302 * sizeof (dw_die_ref)));
7303 memset (arange_table + arange_table_in_use, 0,
7304 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
7307 arange_table[arange_table_in_use++] = die;
7310 /* Output the information that goes into the .debug_aranges table.
7311 Namely, define the beginning and ending address range of the
7312 text section generated for this compilation unit. */
7315 output_aranges (void)
7318 unsigned long aranges_length = size_of_aranges ();
7320 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7321 dw2_asm_output_data (4, 0xffffffff,
7322 "Initial length escape value indicating 64-bit DWARF extension");
7323 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
7324 "Length of Address Ranges Info");
7325 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7326 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7327 "Offset of Compilation Unit Info");
7328 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
7329 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7331 /* We need to align to twice the pointer size here. */
7332 if (DWARF_ARANGES_PAD_SIZE)
7334 /* Pad using a 2 byte words so that padding is correct for any
7336 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7337 2 * DWARF2_ADDR_SIZE);
7338 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
7339 dw2_asm_output_data (2, 0, NULL);
7342 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
7343 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
7344 text_section_label, "Length");
7345 if (flag_reorder_blocks_and_partition)
7347 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
7349 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
7350 cold_text_section_label, "Length");
7353 for (i = 0; i < arange_table_in_use; i++)
7355 dw_die_ref die = arange_table[i];
7357 /* We shouldn't see aranges for DIEs outside of the main CU. */
7358 gcc_assert (die->die_mark);
7360 if (die->die_tag == DW_TAG_subprogram)
7362 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
7364 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
7365 get_AT_low_pc (die), "Length");
7369 /* A static variable; extract the symbol from DW_AT_location.
7370 Note that this code isn't currently hit, as we only emit
7371 aranges for functions (jason 9/23/99). */
7372 dw_attr_ref a = get_AT (die, DW_AT_location);
7373 dw_loc_descr_ref loc;
7375 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7378 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
7380 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
7381 loc->dw_loc_oprnd1.v.val_addr, "Address");
7382 dw2_asm_output_data (DWARF2_ADDR_SIZE,
7383 get_AT_unsigned (die, DW_AT_byte_size),
7388 /* Output the terminator words. */
7389 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7390 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7393 /* Add a new entry to .debug_ranges. Return the offset at which it
7397 add_ranges (tree block)
7399 unsigned int in_use = ranges_table_in_use;
7401 if (in_use == ranges_table_allocated)
7403 ranges_table_allocated += RANGES_TABLE_INCREMENT;
7405 = ggc_realloc (ranges_table, (ranges_table_allocated
7406 * sizeof (struct dw_ranges_struct)));
7407 memset (ranges_table + ranges_table_in_use, 0,
7408 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
7411 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
7412 ranges_table_in_use = in_use + 1;
7414 return in_use * 2 * DWARF2_ADDR_SIZE;
7418 output_ranges (void)
7421 static const char *const start_fmt = "Offset 0x%x";
7422 const char *fmt = start_fmt;
7424 for (i = 0; i < ranges_table_in_use; i++)
7426 int block_num = ranges_table[i].block_num;
7430 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
7431 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
7433 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
7434 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
7436 /* If all code is in the text section, then the compilation
7437 unit base address defaults to DW_AT_low_pc, which is the
7438 base of the text section. */
7439 if (!separate_line_info_table_in_use && !have_switched_text_section)
7441 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
7443 fmt, i * 2 * DWARF2_ADDR_SIZE);
7444 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
7445 text_section_label, NULL);
7448 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
7449 compilation unit base address to zero, which allows us to
7450 use absolute addresses, and not worry about whether the
7451 target supports cross-section arithmetic. */
7454 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
7455 fmt, i * 2 * DWARF2_ADDR_SIZE);
7456 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
7463 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7464 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7470 /* Data structure containing information about input files. */
7473 char *path; /* Complete file name. */
7474 char *fname; /* File name part. */
7475 int length; /* Length of entire string. */
7476 int file_idx; /* Index in input file table. */
7477 int dir_idx; /* Index in directory table. */
7480 /* Data structure containing information about directories with source
7484 char *path; /* Path including directory name. */
7485 int length; /* Path length. */
7486 int prefix; /* Index of directory entry which is a prefix. */
7487 int count; /* Number of files in this directory. */
7488 int dir_idx; /* Index of directory used as base. */
7489 int used; /* Used in the end? */
7492 /* Callback function for file_info comparison. We sort by looking at
7493 the directories in the path. */
7496 file_info_cmp (const void *p1, const void *p2)
7498 const struct file_info *s1 = p1;
7499 const struct file_info *s2 = p2;
7503 /* Take care of file names without directories. We need to make sure that
7504 we return consistent values to qsort since some will get confused if
7505 we return the same value when identical operands are passed in opposite
7506 orders. So if neither has a directory, return 0 and otherwise return
7507 1 or -1 depending on which one has the directory. */
7508 if ((s1->path == s1->fname || s2->path == s2->fname))
7509 return (s2->path == s2->fname) - (s1->path == s1->fname);
7511 cp1 = (unsigned char *) s1->path;
7512 cp2 = (unsigned char *) s2->path;
7518 /* Reached the end of the first path? If so, handle like above. */
7519 if ((cp1 == (unsigned char *) s1->fname)
7520 || (cp2 == (unsigned char *) s2->fname))
7521 return ((cp2 == (unsigned char *) s2->fname)
7522 - (cp1 == (unsigned char *) s1->fname));
7524 /* Character of current path component the same? */
7525 else if (*cp1 != *cp2)
7530 /* Output the directory table and the file name table. We try to minimize
7531 the total amount of memory needed. A heuristic is used to avoid large
7532 slowdowns with many input files. */
7535 output_file_names (void)
7537 struct file_info *files;
7538 struct dir_info *dirs;
7547 /* Handle the case where file_table is empty. */
7548 if (VARRAY_ACTIVE_SIZE (file_table) <= 1)
7550 dw2_asm_output_data (1, 0, "End directory table");
7551 dw2_asm_output_data (1, 0, "End file name table");
7555 /* Allocate the various arrays we need. */
7556 files = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct file_info));
7557 dirs = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct dir_info));
7559 /* Sort the file names. */
7560 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7564 /* Skip all leading "./". */
7565 f = VARRAY_CHAR_PTR (file_table, i);
7566 while (f[0] == '.' && f[1] == '/')
7569 /* Create a new array entry. */
7571 files[i].length = strlen (f);
7572 files[i].file_idx = i;
7574 /* Search for the file name part. */
7575 f = strrchr (f, '/');
7576 files[i].fname = f == NULL ? files[i].path : f + 1;
7579 qsort (files + 1, VARRAY_ACTIVE_SIZE (file_table) - 1,
7580 sizeof (files[0]), file_info_cmp);
7582 /* Find all the different directories used. */
7583 dirs[0].path = files[1].path;
7584 dirs[0].length = files[1].fname - files[1].path;
7585 dirs[0].prefix = -1;
7587 dirs[0].dir_idx = 0;
7589 files[1].dir_idx = 0;
7592 for (i = 2; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7593 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
7594 && memcmp (dirs[ndirs - 1].path, files[i].path,
7595 dirs[ndirs - 1].length) == 0)
7597 /* Same directory as last entry. */
7598 files[i].dir_idx = ndirs - 1;
7599 ++dirs[ndirs - 1].count;
7605 /* This is a new directory. */
7606 dirs[ndirs].path = files[i].path;
7607 dirs[ndirs].length = files[i].fname - files[i].path;
7608 dirs[ndirs].count = 1;
7609 dirs[ndirs].dir_idx = ndirs;
7610 dirs[ndirs].used = 0;
7611 files[i].dir_idx = ndirs;
7613 /* Search for a prefix. */
7614 dirs[ndirs].prefix = -1;
7615 for (j = 0; j < ndirs; j++)
7616 if (dirs[j].length < dirs[ndirs].length
7617 && dirs[j].length > 1
7618 && (dirs[ndirs].prefix == -1
7619 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
7620 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
7621 dirs[ndirs].prefix = j;
7626 /* Now to the actual work. We have to find a subset of the directories which
7627 allow expressing the file name using references to the directory table
7628 with the least amount of characters. We do not do an exhaustive search
7629 where we would have to check out every combination of every single
7630 possible prefix. Instead we use a heuristic which provides nearly optimal
7631 results in most cases and never is much off. */
7632 saved = alloca (ndirs * sizeof (int));
7633 savehere = alloca (ndirs * sizeof (int));
7635 memset (saved, '\0', ndirs * sizeof (saved[0]));
7636 for (i = 0; i < ndirs; i++)
7641 /* We can always save some space for the current directory. But this
7642 does not mean it will be enough to justify adding the directory. */
7643 savehere[i] = dirs[i].length;
7644 total = (savehere[i] - saved[i]) * dirs[i].count;
7646 for (j = i + 1; j < ndirs; j++)
7649 if (saved[j] < dirs[i].length)
7651 /* Determine whether the dirs[i] path is a prefix of the
7656 while (k != -1 && k != (int) i)
7661 /* Yes it is. We can possibly safe some memory but
7662 writing the filenames in dirs[j] relative to
7664 savehere[j] = dirs[i].length;
7665 total += (savehere[j] - saved[j]) * dirs[j].count;
7670 /* Check whether we can safe enough to justify adding the dirs[i]
7672 if (total > dirs[i].length + 1)
7674 /* It's worthwhile adding. */
7675 for (j = i; j < ndirs; j++)
7676 if (savehere[j] > 0)
7678 /* Remember how much we saved for this directory so far. */
7679 saved[j] = savehere[j];
7681 /* Remember the prefix directory. */
7682 dirs[j].dir_idx = i;
7687 /* We have to emit them in the order they appear in the file_table array
7688 since the index is used in the debug info generation. To do this
7689 efficiently we generate a back-mapping of the indices first. */
7690 backmap = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (int));
7691 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7693 backmap[files[i].file_idx] = i;
7695 /* Mark this directory as used. */
7696 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
7699 /* That was it. We are ready to emit the information. First emit the
7700 directory name table. We have to make sure the first actually emitted
7701 directory name has index one; zero is reserved for the current working
7702 directory. Make sure we do not confuse these indices with the one for the
7703 constructed table (even though most of the time they are identical). */
7705 idx_offset = dirs[0].length > 0 ? 1 : 0;
7706 for (i = 1 - idx_offset; i < ndirs; i++)
7707 if (dirs[i].used != 0)
7709 dirs[i].used = idx++;
7710 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
7711 "Directory Entry: 0x%x", dirs[i].used);
7714 dw2_asm_output_data (1, 0, "End directory table");
7716 /* Correct the index for the current working directory entry if it
7718 if (idx_offset == 0)
7721 /* Now write all the file names. */
7722 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7724 int file_idx = backmap[i];
7725 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
7727 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
7728 "File Entry: 0x%lx", (unsigned long) i);
7730 /* Include directory index. */
7731 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
7733 /* Modification time. */
7734 dw2_asm_output_data_uleb128 (0, NULL);
7736 /* File length in bytes. */
7737 dw2_asm_output_data_uleb128 (0, NULL);
7740 dw2_asm_output_data (1, 0, "End file name table");
7744 /* Output the source line number correspondence information. This
7745 information goes into the .debug_line section. */
7748 output_line_info (void)
7750 char l1[20], l2[20], p1[20], p2[20];
7751 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7752 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7755 unsigned long lt_index;
7756 unsigned long current_line;
7759 unsigned long current_file;
7760 unsigned long function;
7762 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7763 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7764 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7765 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7767 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7768 dw2_asm_output_data (4, 0xffffffff,
7769 "Initial length escape value indicating 64-bit DWARF extension");
7770 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7771 "Length of Source Line Info");
7772 ASM_OUTPUT_LABEL (asm_out_file, l1);
7774 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7775 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7776 ASM_OUTPUT_LABEL (asm_out_file, p1);
7778 /* Define the architecture-dependent minimum instruction length (in
7779 bytes). In this implementation of DWARF, this field is used for
7780 information purposes only. Since GCC generates assembly language,
7781 we have no a priori knowledge of how many instruction bytes are
7782 generated for each source line, and therefore can use only the
7783 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7784 commands. Accordingly, we fix this as `1', which is "correct
7785 enough" for all architectures, and don't let the target override. */
7786 dw2_asm_output_data (1, 1,
7787 "Minimum Instruction Length");
7789 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7790 "Default is_stmt_start flag");
7791 dw2_asm_output_data (1, DWARF_LINE_BASE,
7792 "Line Base Value (Special Opcodes)");
7793 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7794 "Line Range Value (Special Opcodes)");
7795 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7796 "Special Opcode Base");
7798 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7802 case DW_LNS_advance_pc:
7803 case DW_LNS_advance_line:
7804 case DW_LNS_set_file:
7805 case DW_LNS_set_column:
7806 case DW_LNS_fixed_advance_pc:
7814 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7818 /* Write out the information about the files we use. */
7819 output_file_names ();
7820 ASM_OUTPUT_LABEL (asm_out_file, p2);
7822 /* We used to set the address register to the first location in the text
7823 section here, but that didn't accomplish anything since we already
7824 have a line note for the opening brace of the first function. */
7826 /* Generate the line number to PC correspondence table, encoded as
7827 a series of state machine operations. */
7832 && (last_text_section == in_unlikely_executed_text
7833 || (last_text_section == in_named
7834 && last_text_section_name == cfun->unlikely_text_section_name)))
7835 strcpy (prev_line_label, cfun->cold_section_label);
7837 strcpy (prev_line_label, text_section_label);
7838 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7840 dw_line_info_ref line_info = &line_info_table[lt_index];
7843 /* Disable this optimization for now; GDB wants to see two line notes
7844 at the beginning of a function so it can find the end of the
7847 /* Don't emit anything for redundant notes. Just updating the
7848 address doesn't accomplish anything, because we already assume
7849 that anything after the last address is this line. */
7850 if (line_info->dw_line_num == current_line
7851 && line_info->dw_file_num == current_file)
7855 /* Emit debug info for the address of the current line.
7857 Unfortunately, we have little choice here currently, and must always
7858 use the most general form. GCC does not know the address delta
7859 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7860 attributes which will give an upper bound on the address range. We
7861 could perhaps use length attributes to determine when it is safe to
7862 use DW_LNS_fixed_advance_pc. */
7864 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7867 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7868 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7869 "DW_LNS_fixed_advance_pc");
7870 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7874 /* This can handle any delta. This takes
7875 4+DWARF2_ADDR_SIZE bytes. */
7876 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7877 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7878 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7879 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7882 strcpy (prev_line_label, line_label);
7884 /* Emit debug info for the source file of the current line, if
7885 different from the previous line. */
7886 if (line_info->dw_file_num != current_file)
7888 current_file = line_info->dw_file_num;
7889 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7890 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7891 VARRAY_CHAR_PTR (file_table,
7895 /* Emit debug info for the current line number, choosing the encoding
7896 that uses the least amount of space. */
7897 if (line_info->dw_line_num != current_line)
7899 line_offset = line_info->dw_line_num - current_line;
7900 line_delta = line_offset - DWARF_LINE_BASE;
7901 current_line = line_info->dw_line_num;
7902 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7903 /* This can handle deltas from -10 to 234, using the current
7904 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7906 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7907 "line %lu", current_line);
7910 /* This can handle any delta. This takes at least 4 bytes,
7911 depending on the value being encoded. */
7912 dw2_asm_output_data (1, DW_LNS_advance_line,
7913 "advance to line %lu", current_line);
7914 dw2_asm_output_data_sleb128 (line_offset, NULL);
7915 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7919 /* We still need to start a new row, so output a copy insn. */
7920 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7923 /* Emit debug info for the address of the end of the function. */
7926 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7927 "DW_LNS_fixed_advance_pc");
7928 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7932 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7933 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7934 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7935 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7938 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7939 dw2_asm_output_data_uleb128 (1, NULL);
7940 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7945 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7947 dw_separate_line_info_ref line_info
7948 = &separate_line_info_table[lt_index];
7951 /* Don't emit anything for redundant notes. */
7952 if (line_info->dw_line_num == current_line
7953 && line_info->dw_file_num == current_file
7954 && line_info->function == function)
7958 /* Emit debug info for the address of the current line. If this is
7959 a new function, or the first line of a function, then we need
7960 to handle it differently. */
7961 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7963 if (function != line_info->function)
7965 function = line_info->function;
7967 /* Set the address register to the first line in the function. */
7968 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7969 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7970 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7971 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7975 /* ??? See the DW_LNS_advance_pc comment above. */
7978 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7979 "DW_LNS_fixed_advance_pc");
7980 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7984 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7985 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7986 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7987 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7991 strcpy (prev_line_label, line_label);
7993 /* Emit debug info for the source file of the current line, if
7994 different from the previous line. */
7995 if (line_info->dw_file_num != current_file)
7997 current_file = line_info->dw_file_num;
7998 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7999 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
8000 VARRAY_CHAR_PTR (file_table,
8004 /* Emit debug info for the current line number, choosing the encoding
8005 that uses the least amount of space. */
8006 if (line_info->dw_line_num != current_line)
8008 line_offset = line_info->dw_line_num - current_line;
8009 line_delta = line_offset - DWARF_LINE_BASE;
8010 current_line = line_info->dw_line_num;
8011 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8012 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8013 "line %lu", current_line);
8016 dw2_asm_output_data (1, DW_LNS_advance_line,
8017 "advance to line %lu", current_line);
8018 dw2_asm_output_data_sleb128 (line_offset, NULL);
8019 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8023 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8031 /* If we're done with a function, end its sequence. */
8032 if (lt_index == separate_line_info_table_in_use
8033 || separate_line_info_table[lt_index].function != function)
8038 /* Emit debug info for the address of the end of the function. */
8039 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
8042 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8043 "DW_LNS_fixed_advance_pc");
8044 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8048 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8049 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8050 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8051 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8054 /* Output the marker for the end of this sequence. */
8055 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8056 dw2_asm_output_data_uleb128 (1, NULL);
8057 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8061 /* Output the marker for the end of the line number info. */
8062 ASM_OUTPUT_LABEL (asm_out_file, l2);
8065 /* Given a pointer to a tree node for some base type, return a pointer to
8066 a DIE that describes the given type.
8068 This routine must only be called for GCC type nodes that correspond to
8069 Dwarf base (fundamental) types. */
8072 base_type_die (tree type)
8074 dw_die_ref base_type_result;
8075 const char *type_name;
8076 enum dwarf_type encoding;
8077 tree name = TYPE_NAME (type);
8079 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
8084 if (TREE_CODE (name) == TYPE_DECL)
8085 name = DECL_NAME (name);
8087 type_name = IDENTIFIER_POINTER (name);
8090 type_name = "__unknown__";
8092 switch (TREE_CODE (type))
8095 /* Carefully distinguish the C character types, without messing
8096 up if the language is not C. Note that we check only for the names
8097 that contain spaces; other names might occur by coincidence in other
8099 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
8100 && (TYPE_MAIN_VARIANT (type) == char_type_node
8101 || ! strcmp (type_name, "signed char")
8102 || ! strcmp (type_name, "unsigned char"))))
8104 if (TYPE_UNSIGNED (type))
8105 encoding = DW_ATE_unsigned;
8107 encoding = DW_ATE_signed;
8110 /* else fall through. */
8113 /* GNU Pascal/Ada CHAR type. Not used in C. */
8114 if (TYPE_UNSIGNED (type))
8115 encoding = DW_ATE_unsigned_char;
8117 encoding = DW_ATE_signed_char;
8121 encoding = DW_ATE_float;
8124 /* Dwarf2 doesn't know anything about complex ints, so use
8125 a user defined type for it. */
8127 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
8128 encoding = DW_ATE_complex_float;
8130 encoding = DW_ATE_lo_user;
8134 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8135 encoding = DW_ATE_boolean;
8139 /* No other TREE_CODEs are Dwarf fundamental types. */
8143 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
8144 if (demangle_name_func)
8145 type_name = (*demangle_name_func) (type_name);
8147 add_AT_string (base_type_result, DW_AT_name, type_name);
8148 add_AT_unsigned (base_type_result, DW_AT_byte_size,
8149 int_size_in_bytes (type));
8150 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
8152 return base_type_result;
8155 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
8156 the Dwarf "root" type for the given input type. The Dwarf "root" type of
8157 a given type is generally the same as the given type, except that if the
8158 given type is a pointer or reference type, then the root type of the given
8159 type is the root type of the "basis" type for the pointer or reference
8160 type. (This definition of the "root" type is recursive.) Also, the root
8161 type of a `const' qualified type or a `volatile' qualified type is the
8162 root type of the given type without the qualifiers. */
8165 root_type (tree type)
8167 if (TREE_CODE (type) == ERROR_MARK)
8168 return error_mark_node;
8170 switch (TREE_CODE (type))
8173 return error_mark_node;
8176 case REFERENCE_TYPE:
8177 return type_main_variant (root_type (TREE_TYPE (type)));
8180 return type_main_variant (type);
8184 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8185 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8188 is_base_type (tree type)
8190 switch (TREE_CODE (type))
8204 case QUAL_UNION_TYPE:
8209 case REFERENCE_TYPE:
8222 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8223 node, return the size in bits for the type if it is a constant, or else
8224 return the alignment for the type if the type's size is not constant, or
8225 else return BITS_PER_WORD if the type actually turns out to be an
8228 static inline unsigned HOST_WIDE_INT
8229 simple_type_size_in_bits (tree type)
8231 if (TREE_CODE (type) == ERROR_MARK)
8232 return BITS_PER_WORD;
8233 else if (TYPE_SIZE (type) == NULL_TREE)
8235 else if (host_integerp (TYPE_SIZE (type), 1))
8236 return tree_low_cst (TYPE_SIZE (type), 1);
8238 return TYPE_ALIGN (type);
8241 /* Return true if the debug information for the given type should be
8242 emitted as a subrange type. */
8245 is_subrange_type (tree type)
8247 tree subtype = TREE_TYPE (type);
8249 /* Subrange types are identified by the fact that they are integer
8250 types, and that they have a subtype which is either an integer type
8251 or an enumeral type. */
8253 if (TREE_CODE (type) != INTEGER_TYPE
8254 || subtype == NULL_TREE)
8257 if (TREE_CODE (subtype) != INTEGER_TYPE
8258 && TREE_CODE (subtype) != ENUMERAL_TYPE)
8261 if (TREE_CODE (type) == TREE_CODE (subtype)
8262 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
8263 && TYPE_MIN_VALUE (type) != NULL
8264 && TYPE_MIN_VALUE (subtype) != NULL
8265 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
8266 && TYPE_MAX_VALUE (type) != NULL
8267 && TYPE_MAX_VALUE (subtype) != NULL
8268 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
8270 /* The type and its subtype have the same representation. If in
8271 addition the two types also have the same name, then the given
8272 type is not a subrange type, but rather a plain base type. */
8273 /* FIXME: brobecker/2004-03-22:
8274 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8275 therefore be sufficient to check the TYPE_SIZE node pointers
8276 rather than checking the actual size. Unfortunately, we have
8277 found some cases, such as in the Ada "integer" type, where
8278 this is not the case. Until this problem is solved, we need to
8279 keep checking the actual size. */
8280 tree type_name = TYPE_NAME (type);
8281 tree subtype_name = TYPE_NAME (subtype);
8283 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
8284 type_name = DECL_NAME (type_name);
8286 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
8287 subtype_name = DECL_NAME (subtype_name);
8289 if (type_name == subtype_name)
8296 /* Given a pointer to a tree node for a subrange type, return a pointer
8297 to a DIE that describes the given type. */
8300 subrange_type_die (tree type, dw_die_ref context_die)
8302 dw_die_ref subtype_die;
8303 dw_die_ref subrange_die;
8304 tree name = TYPE_NAME (type);
8305 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
8306 tree subtype = TREE_TYPE (type);
8308 if (context_die == NULL)
8309 context_die = comp_unit_die;
8311 if (TREE_CODE (subtype) == ENUMERAL_TYPE)
8312 subtype_die = gen_enumeration_type_die (subtype, context_die);
8314 subtype_die = base_type_die (subtype);
8316 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
8320 if (TREE_CODE (name) == TYPE_DECL)
8321 name = DECL_NAME (name);
8322 add_name_attribute (subrange_die, IDENTIFIER_POINTER (name));
8325 if (int_size_in_bytes (subtype) != size_in_bytes)
8327 /* The size of the subrange type and its base type do not match,
8328 so we need to generate a size attribute for the subrange type. */
8329 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
8332 if (TYPE_MIN_VALUE (type) != NULL)
8333 add_bound_info (subrange_die, DW_AT_lower_bound,
8334 TYPE_MIN_VALUE (type));
8335 if (TYPE_MAX_VALUE (type) != NULL)
8336 add_bound_info (subrange_die, DW_AT_upper_bound,
8337 TYPE_MAX_VALUE (type));
8338 add_AT_die_ref (subrange_die, DW_AT_type, subtype_die);
8340 return subrange_die;
8343 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8344 entry that chains various modifiers in front of the given type. */
8347 modified_type_die (tree type, int is_const_type, int is_volatile_type,
8348 dw_die_ref context_die)
8350 enum tree_code code = TREE_CODE (type);
8351 dw_die_ref mod_type_die = NULL;
8352 dw_die_ref sub_die = NULL;
8353 tree item_type = NULL;
8355 if (code != ERROR_MARK)
8357 tree qualified_type;
8359 /* See if we already have the appropriately qualified variant of
8362 = get_qualified_type (type,
8363 ((is_const_type ? TYPE_QUAL_CONST : 0)
8365 ? TYPE_QUAL_VOLATILE : 0)));
8367 /* If we do, then we can just use its DIE, if it exists. */
8370 mod_type_die = lookup_type_die (qualified_type);
8372 return mod_type_die;
8375 /* Handle C typedef types. */
8376 if (qualified_type && TYPE_NAME (qualified_type)
8377 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
8378 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
8380 tree type_name = TYPE_NAME (qualified_type);
8381 tree dtype = TREE_TYPE (type_name);
8383 if (qualified_type == dtype)
8385 /* For a named type, use the typedef. */
8386 gen_type_die (qualified_type, context_die);
8387 mod_type_die = lookup_type_die (qualified_type);
8389 else if (is_const_type < TYPE_READONLY (dtype)
8390 || is_volatile_type < TYPE_VOLATILE (dtype))
8391 /* cv-unqualified version of named type. Just use the unnamed
8392 type to which it refers. */
8394 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
8395 is_const_type, is_volatile_type,
8398 /* Else cv-qualified version of named type; fall through. */
8404 else if (is_const_type)
8406 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
8407 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
8409 else if (is_volatile_type)
8411 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
8412 sub_die = modified_type_die (type, 0, 0, context_die);
8414 else if (code == POINTER_TYPE)
8416 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
8417 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8418 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8420 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
8422 item_type = TREE_TYPE (type);
8424 else if (code == REFERENCE_TYPE)
8426 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
8427 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8428 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8430 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
8432 item_type = TREE_TYPE (type);
8434 else if (is_subrange_type (type))
8435 mod_type_die = subrange_type_die (type, context_die);
8436 else if (is_base_type (type))
8437 mod_type_die = base_type_die (type);
8440 gen_type_die (type, context_die);
8442 /* We have to get the type_main_variant here (and pass that to the
8443 `lookup_type_die' routine) because the ..._TYPE node we have
8444 might simply be a *copy* of some original type node (where the
8445 copy was created to help us keep track of typedef names) and
8446 that copy might have a different TYPE_UID from the original
8448 if (TREE_CODE (type) != VECTOR_TYPE)
8449 mod_type_die = lookup_type_die (type_main_variant (type));
8451 /* Vectors have the debugging information in the type,
8452 not the main variant. */
8453 mod_type_die = lookup_type_die (type);
8454 gcc_assert (mod_type_die);
8457 /* We want to equate the qualified type to the die below. */
8458 type = qualified_type;
8462 equate_type_number_to_die (type, mod_type_die);
8464 /* We must do this after the equate_type_number_to_die call, in case
8465 this is a recursive type. This ensures that the modified_type_die
8466 recursion will terminate even if the type is recursive. Recursive
8467 types are possible in Ada. */
8468 sub_die = modified_type_die (item_type,
8469 TYPE_READONLY (item_type),
8470 TYPE_VOLATILE (item_type),
8473 if (sub_die != NULL)
8474 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
8476 return mod_type_die;
8479 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8480 an enumerated type. */
8483 type_is_enum (tree type)
8485 return TREE_CODE (type) == ENUMERAL_TYPE;
8488 /* Return the DBX register number described by a given RTL node. */
8491 dbx_reg_number (rtx rtl)
8493 unsigned regno = REGNO (rtl);
8495 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
8497 #ifdef LEAF_REG_REMAP
8498 regno = LEAF_REG_REMAP (regno);
8501 return DBX_REGISTER_NUMBER (regno);
8504 /* Optionally add a DW_OP_piece term to a location description expression.
8505 DW_OP_piece is only added if the location description expression already
8506 doesn't end with DW_OP_piece. */
8509 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
8511 dw_loc_descr_ref loc;
8513 if (*list_head != NULL)
8515 /* Find the end of the chain. */
8516 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
8519 if (loc->dw_loc_opc != DW_OP_piece)
8520 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
8524 /* Return a location descriptor that designates a machine register or
8525 zero if there is none. */
8527 static dw_loc_descr_ref
8528 reg_loc_descriptor (rtx rtl)
8532 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
8535 regs = targetm.dwarf_register_span (rtl);
8537 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
8538 return multiple_reg_loc_descriptor (rtl, regs);
8540 return one_reg_loc_descriptor (dbx_reg_number (rtl));
8543 /* Return a location descriptor that designates a machine register for
8544 a given hard register number. */
8546 static dw_loc_descr_ref
8547 one_reg_loc_descriptor (unsigned int regno)
8550 return new_loc_descr (DW_OP_reg0 + regno, 0, 0);
8552 return new_loc_descr (DW_OP_regx, regno, 0);
8555 /* Given an RTL of a register, return a location descriptor that
8556 designates a value that spans more than one register. */
8558 static dw_loc_descr_ref
8559 multiple_reg_loc_descriptor (rtx rtl, rtx regs)
8563 dw_loc_descr_ref loc_result = NULL;
8566 #ifdef LEAF_REG_REMAP
8567 reg = LEAF_REG_REMAP (reg);
8569 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
8570 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
8572 /* Simple, contiguous registers. */
8573 if (regs == NULL_RTX)
8575 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
8582 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg));
8583 add_loc_descr (&loc_result, t);
8584 add_loc_descr_op_piece (&loc_result, size);
8590 /* Now onto stupid register sets in non contiguous locations. */
8592 gcc_assert (GET_CODE (regs) == PARALLEL);
8594 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8597 for (i = 0; i < XVECLEN (regs, 0); ++i)
8601 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)));
8602 add_loc_descr (&loc_result, t);
8603 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8604 add_loc_descr_op_piece (&loc_result, size);
8609 /* Return a location descriptor that designates a constant. */
8611 static dw_loc_descr_ref
8612 int_loc_descriptor (HOST_WIDE_INT i)
8614 enum dwarf_location_atom op;
8616 /* Pick the smallest representation of a constant, rather than just
8617 defaulting to the LEB encoding. */
8621 op = DW_OP_lit0 + i;
8624 else if (i <= 0xffff)
8626 else if (HOST_BITS_PER_WIDE_INT == 32
8636 else if (i >= -0x8000)
8638 else if (HOST_BITS_PER_WIDE_INT == 32
8639 || i >= -0x80000000)
8645 return new_loc_descr (op, i, 0);
8648 /* Return a location descriptor that designates a base+offset location. */
8650 static dw_loc_descr_ref
8651 based_loc_descr (rtx reg, HOST_WIDE_INT offset)
8655 /* We only use "frame base" when we're sure we're talking about the
8656 post-prologue local stack frame. We do this by *not* running
8657 register elimination until this point, and recognizing the special
8658 argument pointer and soft frame pointer rtx's. */
8659 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
8661 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
8665 if (GET_CODE (elim) == PLUS)
8667 offset += INTVAL (XEXP (elim, 1));
8668 elim = XEXP (elim, 0);
8670 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
8671 : stack_pointer_rtx));
8672 offset += frame_pointer_cfa_offset;
8674 return new_loc_descr (DW_OP_fbreg, offset, 0);
8678 regno = dbx_reg_number (reg);
8680 return new_loc_descr (DW_OP_breg0 + regno, offset, 0);
8682 return new_loc_descr (DW_OP_bregx, regno, offset);
8685 /* Return true if this RTL expression describes a base+offset calculation. */
8688 is_based_loc (rtx rtl)
8690 return (GET_CODE (rtl) == PLUS
8691 && ((REG_P (XEXP (rtl, 0))
8692 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
8693 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
8696 /* The following routine converts the RTL for a variable or parameter
8697 (resident in memory) into an equivalent Dwarf representation of a
8698 mechanism for getting the address of that same variable onto the top of a
8699 hypothetical "address evaluation" stack.
8701 When creating memory location descriptors, we are effectively transforming
8702 the RTL for a memory-resident object into its Dwarf postfix expression
8703 equivalent. This routine recursively descends an RTL tree, turning
8704 it into Dwarf postfix code as it goes.
8706 MODE is the mode of the memory reference, needed to handle some
8707 autoincrement addressing modes.
8709 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
8710 location list for RTL.
8712 Return 0 if we can't represent the location. */
8714 static dw_loc_descr_ref
8715 mem_loc_descriptor (rtx rtl, enum machine_mode mode)
8717 dw_loc_descr_ref mem_loc_result = NULL;
8718 enum dwarf_location_atom op;
8720 /* Note that for a dynamically sized array, the location we will generate a
8721 description of here will be the lowest numbered location which is
8722 actually within the array. That's *not* necessarily the same as the
8723 zeroth element of the array. */
8725 rtl = targetm.delegitimize_address (rtl);
8727 switch (GET_CODE (rtl))
8732 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8733 just fall into the SUBREG code. */
8735 /* ... fall through ... */
8738 /* The case of a subreg may arise when we have a local (register)
8739 variable or a formal (register) parameter which doesn't quite fill
8740 up an entire register. For now, just assume that it is
8741 legitimate to make the Dwarf info refer to the whole register which
8742 contains the given subreg. */
8743 rtl = XEXP (rtl, 0);
8745 /* ... fall through ... */
8748 /* Whenever a register number forms a part of the description of the
8749 method for calculating the (dynamic) address of a memory resident
8750 object, DWARF rules require the register number be referred to as
8751 a "base register". This distinction is not based in any way upon
8752 what category of register the hardware believes the given register
8753 belongs to. This is strictly DWARF terminology we're dealing with
8754 here. Note that in cases where the location of a memory-resident
8755 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8756 OP_CONST (0)) the actual DWARF location descriptor that we generate
8757 may just be OP_BASEREG (basereg). This may look deceptively like
8758 the object in question was allocated to a register (rather than in
8759 memory) so DWARF consumers need to be aware of the subtle
8760 distinction between OP_REG and OP_BASEREG. */
8761 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
8762 mem_loc_result = based_loc_descr (rtl, 0);
8766 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8767 if (mem_loc_result != 0)
8768 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
8772 rtl = XEXP (rtl, 1);
8774 /* ... fall through ... */
8777 /* Some ports can transform a symbol ref into a label ref, because
8778 the symbol ref is too far away and has to be dumped into a constant
8782 /* Alternatively, the symbol in the constant pool might be referenced
8783 by a different symbol. */
8784 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
8787 rtx tmp = get_pool_constant_mark (rtl, &marked);
8789 if (GET_CODE (tmp) == SYMBOL_REF)
8792 if (CONSTANT_POOL_ADDRESS_P (tmp))
8793 get_pool_constant_mark (tmp, &marked);
8798 /* If all references to this pool constant were optimized away,
8799 it was not output and thus we can't represent it.
8800 FIXME: might try to use DW_OP_const_value here, though
8801 DW_OP_piece complicates it. */
8806 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
8807 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
8808 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
8809 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
8813 /* Extract the PLUS expression nested inside and fall into
8815 rtl = XEXP (rtl, 1);
8820 /* Turn these into a PLUS expression and fall into the PLUS code
8822 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
8823 GEN_INT (GET_CODE (rtl) == PRE_INC
8824 ? GET_MODE_UNIT_SIZE (mode)
8825 : -GET_MODE_UNIT_SIZE (mode)));
8827 /* ... fall through ... */
8831 if (is_based_loc (rtl))
8832 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
8833 INTVAL (XEXP (rtl, 1)));
8836 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
8837 if (mem_loc_result == 0)
8840 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
8841 && INTVAL (XEXP (rtl, 1)) >= 0)
8842 add_loc_descr (&mem_loc_result,
8843 new_loc_descr (DW_OP_plus_uconst,
8844 INTVAL (XEXP (rtl, 1)), 0));
8847 add_loc_descr (&mem_loc_result,
8848 mem_loc_descriptor (XEXP (rtl, 1), mode));
8849 add_loc_descr (&mem_loc_result,
8850 new_loc_descr (DW_OP_plus, 0, 0));
8855 /* If a pseudo-reg is optimized away, it is possible for it to
8856 be replaced with a MEM containing a multiply or shift. */
8875 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
8876 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
8878 if (op0 == 0 || op1 == 0)
8881 mem_loc_result = op0;
8882 add_loc_descr (&mem_loc_result, op1);
8883 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
8888 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
8895 return mem_loc_result;
8898 /* Return a descriptor that describes the concatenation of two locations.
8899 This is typically a complex variable. */
8901 static dw_loc_descr_ref
8902 concat_loc_descriptor (rtx x0, rtx x1)
8904 dw_loc_descr_ref cc_loc_result = NULL;
8905 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
8906 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
8908 if (x0_ref == 0 || x1_ref == 0)
8911 cc_loc_result = x0_ref;
8912 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
8914 add_loc_descr (&cc_loc_result, x1_ref);
8915 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
8917 return cc_loc_result;
8920 /* Output a proper Dwarf location descriptor for a variable or parameter
8921 which is either allocated in a register or in a memory location. For a
8922 register, we just generate an OP_REG and the register number. For a
8923 memory location we provide a Dwarf postfix expression describing how to
8924 generate the (dynamic) address of the object onto the address stack.
8926 If we don't know how to describe it, return 0. */
8928 static dw_loc_descr_ref
8929 loc_descriptor (rtx rtl)
8931 dw_loc_descr_ref loc_result = NULL;
8933 switch (GET_CODE (rtl))
8936 /* The case of a subreg may arise when we have a local (register)
8937 variable or a formal (register) parameter which doesn't quite fill
8938 up an entire register. For now, just assume that it is
8939 legitimate to make the Dwarf info refer to the whole register which
8940 contains the given subreg. */
8941 rtl = SUBREG_REG (rtl);
8943 /* ... fall through ... */
8946 loc_result = reg_loc_descriptor (rtl);
8950 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8954 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8959 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
8961 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0));
8965 rtl = XEXP (rtl, 1);
8970 rtvec par_elems = XVEC (rtl, 0);
8971 int num_elem = GET_NUM_ELEM (par_elems);
8972 enum machine_mode mode;
8975 /* Create the first one, so we have something to add to. */
8976 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0));
8977 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
8978 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
8979 for (i = 1; i < num_elem; i++)
8981 dw_loc_descr_ref temp;
8983 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0));
8984 add_loc_descr (&loc_result, temp);
8985 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
8986 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
8998 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8999 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
9000 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
9001 top-level invocation, and we require the address of LOC; is 0 if we require
9002 the value of LOC. */
9004 static dw_loc_descr_ref
9005 loc_descriptor_from_tree_1 (tree loc, int want_address)
9007 dw_loc_descr_ref ret, ret1;
9008 int have_address = 0;
9009 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
9010 enum dwarf_location_atom op;
9012 /* ??? Most of the time we do not take proper care for sign/zero
9013 extending the values properly. Hopefully this won't be a real
9016 switch (TREE_CODE (loc))
9021 case PLACEHOLDER_EXPR:
9022 /* This case involves extracting fields from an object to determine the
9023 position of other fields. We don't try to encode this here. The
9024 only user of this is Ada, which encodes the needed information using
9025 the names of types. */
9031 case PREINCREMENT_EXPR:
9032 case PREDECREMENT_EXPR:
9033 case POSTINCREMENT_EXPR:
9034 case POSTDECREMENT_EXPR:
9035 /* There are no opcodes for these operations. */
9039 /* If we already want an address, there's nothing we can do. */
9043 /* Otherwise, process the argument and look for the address. */
9044 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
9047 if (DECL_THREAD_LOCAL_P (loc))
9051 /* If this is not defined, we have no way to emit the data. */
9052 if (!targetm.asm_out.output_dwarf_dtprel)
9055 /* The way DW_OP_GNU_push_tls_address is specified, we can only
9056 look up addresses of objects in the current module. */
9057 if (DECL_EXTERNAL (loc))
9060 rtl = rtl_for_decl_location (loc);
9061 if (rtl == NULL_RTX)
9066 rtl = XEXP (rtl, 0);
9067 if (! CONSTANT_P (rtl))
9070 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
9071 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9072 ret->dw_loc_oprnd1.v.val_addr = rtl;
9074 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
9075 add_loc_descr (&ret, ret1);
9083 if (DECL_HAS_VALUE_EXPR_P (loc))
9084 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
9090 rtx rtl = rtl_for_decl_location (loc);
9092 if (rtl == NULL_RTX)
9094 else if (GET_CODE (rtl) == CONST_INT)
9096 HOST_WIDE_INT val = INTVAL (rtl);
9097 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
9098 val &= GET_MODE_MASK (DECL_MODE (loc));
9099 ret = int_loc_descriptor (val);
9101 else if (GET_CODE (rtl) == CONST_STRING)
9103 else if (CONSTANT_P (rtl))
9105 ret = new_loc_descr (DW_OP_addr, 0, 0);
9106 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9107 ret->dw_loc_oprnd1.v.val_addr = rtl;
9111 enum machine_mode mode;
9113 /* Certain constructs can only be represented at top-level. */
9114 if (want_address == 2)
9115 return loc_descriptor (rtl);
9117 mode = GET_MODE (rtl);
9120 rtl = XEXP (rtl, 0);
9123 ret = mem_loc_descriptor (rtl, mode);
9129 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9134 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
9138 case NON_LVALUE_EXPR:
9139 case VIEW_CONVERT_EXPR:
9142 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
9147 case ARRAY_RANGE_REF:
9150 HOST_WIDE_INT bitsize, bitpos, bytepos;
9151 enum machine_mode mode;
9154 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
9155 &unsignedp, &volatilep, false);
9160 ret = loc_descriptor_from_tree_1 (obj, 1);
9162 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
9165 if (offset != NULL_TREE)
9167 /* Variable offset. */
9168 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
9169 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9172 bytepos = bitpos / BITS_PER_UNIT;
9174 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
9175 else if (bytepos < 0)
9177 add_loc_descr (&ret, int_loc_descriptor (bytepos));
9178 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9186 if (host_integerp (loc, 0))
9187 ret = int_loc_descriptor (tree_low_cst (loc, 0));
9194 /* Get an RTL for this, if something has been emitted. */
9195 rtx rtl = lookup_constant_def (loc);
9196 enum machine_mode mode;
9198 if (!rtl || !MEM_P (rtl))
9200 mode = GET_MODE (rtl);
9201 rtl = XEXP (rtl, 0);
9202 ret = mem_loc_descriptor (rtl, mode);
9207 case TRUTH_AND_EXPR:
9208 case TRUTH_ANDIF_EXPR:
9213 case TRUTH_XOR_EXPR:
9219 case TRUTH_ORIF_EXPR:
9224 case FLOOR_DIV_EXPR:
9226 case ROUND_DIV_EXPR:
9227 case TRUNC_DIV_EXPR:
9235 case FLOOR_MOD_EXPR:
9237 case ROUND_MOD_EXPR:
9238 case TRUNC_MOD_EXPR:
9251 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
9255 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
9256 && host_integerp (TREE_OPERAND (loc, 1), 0))
9258 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9262 add_loc_descr (&ret,
9263 new_loc_descr (DW_OP_plus_uconst,
9264 tree_low_cst (TREE_OPERAND (loc, 1),
9274 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9281 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9288 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9295 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9310 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9311 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9312 if (ret == 0 || ret1 == 0)
9315 add_loc_descr (&ret, ret1);
9316 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9319 case TRUTH_NOT_EXPR:
9333 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9337 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9343 const enum tree_code code =
9344 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
9346 loc = build3 (COND_EXPR, TREE_TYPE (loc),
9347 build2 (code, integer_type_node,
9348 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
9349 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
9352 /* ... fall through ... */
9356 dw_loc_descr_ref lhs
9357 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9358 dw_loc_descr_ref rhs
9359 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
9360 dw_loc_descr_ref bra_node, jump_node, tmp;
9362 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9363 if (ret == 0 || lhs == 0 || rhs == 0)
9366 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
9367 add_loc_descr (&ret, bra_node);
9369 add_loc_descr (&ret, rhs);
9370 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
9371 add_loc_descr (&ret, jump_node);
9373 add_loc_descr (&ret, lhs);
9374 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9375 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
9377 /* ??? Need a node to point the skip at. Use a nop. */
9378 tmp = new_loc_descr (DW_OP_nop, 0, 0);
9379 add_loc_descr (&ret, tmp);
9380 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9381 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
9385 case FIX_TRUNC_EXPR:
9387 case FIX_FLOOR_EXPR:
9388 case FIX_ROUND_EXPR:
9392 /* Leave front-end specific codes as simply unknown. This comes
9393 up, for instance, with the C STMT_EXPR. */
9394 if ((unsigned int) TREE_CODE (loc)
9395 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
9398 #ifdef ENABLE_CHECKING
9399 /* Otherwise this is a generic code; we should just lists all of
9400 these explicitly. We forgot one. */
9403 /* In a release build, we want to degrade gracefully: better to
9404 generate incomplete debugging information than to crash. */
9409 /* Show if we can't fill the request for an address. */
9410 if (want_address && !have_address)
9413 /* If we've got an address and don't want one, dereference. */
9414 if (!want_address && have_address)
9416 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
9418 if (size > DWARF2_ADDR_SIZE || size == -1)
9420 else if (size == DWARF2_ADDR_SIZE)
9423 op = DW_OP_deref_size;
9425 add_loc_descr (&ret, new_loc_descr (op, size, 0));
9431 static inline dw_loc_descr_ref
9432 loc_descriptor_from_tree (tree loc)
9434 return loc_descriptor_from_tree_1 (loc, 2);
9437 /* Given a value, round it up to the lowest multiple of `boundary'
9438 which is not less than the value itself. */
9440 static inline HOST_WIDE_INT
9441 ceiling (HOST_WIDE_INT value, unsigned int boundary)
9443 return (((value + boundary - 1) / boundary) * boundary);
9446 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9447 pointer to the declared type for the relevant field variable, or return
9448 `integer_type_node' if the given node turns out to be an
9452 field_type (tree decl)
9456 if (TREE_CODE (decl) == ERROR_MARK)
9457 return integer_type_node;
9459 type = DECL_BIT_FIELD_TYPE (decl);
9460 if (type == NULL_TREE)
9461 type = TREE_TYPE (decl);
9466 /* Given a pointer to a tree node, return the alignment in bits for
9467 it, or else return BITS_PER_WORD if the node actually turns out to
9468 be an ERROR_MARK node. */
9470 static inline unsigned
9471 simple_type_align_in_bits (tree type)
9473 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
9476 static inline unsigned
9477 simple_decl_align_in_bits (tree decl)
9479 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
9482 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9483 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9484 or return 0 if we are unable to determine what that offset is, either
9485 because the argument turns out to be a pointer to an ERROR_MARK node, or
9486 because the offset is actually variable. (We can't handle the latter case
9489 static HOST_WIDE_INT
9490 field_byte_offset (tree decl)
9492 unsigned int type_align_in_bits;
9493 unsigned int decl_align_in_bits;
9494 unsigned HOST_WIDE_INT type_size_in_bits;
9495 HOST_WIDE_INT object_offset_in_bits;
9497 tree field_size_tree;
9498 HOST_WIDE_INT bitpos_int;
9499 HOST_WIDE_INT deepest_bitpos;
9500 unsigned HOST_WIDE_INT field_size_in_bits;
9502 if (TREE_CODE (decl) == ERROR_MARK)
9505 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
9507 type = field_type (decl);
9508 field_size_tree = DECL_SIZE (decl);
9510 /* The size could be unspecified if there was an error, or for
9511 a flexible array member. */
9512 if (! field_size_tree)
9513 field_size_tree = bitsize_zero_node;
9515 /* We cannot yet cope with fields whose positions are variable, so
9516 for now, when we see such things, we simply return 0. Someday, we may
9517 be able to handle such cases, but it will be damn difficult. */
9518 if (! host_integerp (bit_position (decl), 0))
9521 bitpos_int = int_bit_position (decl);
9523 /* If we don't know the size of the field, pretend it's a full word. */
9524 if (host_integerp (field_size_tree, 1))
9525 field_size_in_bits = tree_low_cst (field_size_tree, 1);
9527 field_size_in_bits = BITS_PER_WORD;
9529 type_size_in_bits = simple_type_size_in_bits (type);
9530 type_align_in_bits = simple_type_align_in_bits (type);
9531 decl_align_in_bits = simple_decl_align_in_bits (decl);
9533 /* The GCC front-end doesn't make any attempt to keep track of the starting
9534 bit offset (relative to the start of the containing structure type) of the
9535 hypothetical "containing object" for a bit-field. Thus, when computing
9536 the byte offset value for the start of the "containing object" of a
9537 bit-field, we must deduce this information on our own. This can be rather
9538 tricky to do in some cases. For example, handling the following structure
9539 type definition when compiling for an i386/i486 target (which only aligns
9540 long long's to 32-bit boundaries) can be very tricky:
9542 struct S { int field1; long long field2:31; };
9544 Fortunately, there is a simple rule-of-thumb which can be used in such
9545 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
9546 structure shown above. It decides to do this based upon one simple rule
9547 for bit-field allocation. GCC allocates each "containing object" for each
9548 bit-field at the first (i.e. lowest addressed) legitimate alignment
9549 boundary (based upon the required minimum alignment for the declared type
9550 of the field) which it can possibly use, subject to the condition that
9551 there is still enough available space remaining in the containing object
9552 (when allocated at the selected point) to fully accommodate all of the
9553 bits of the bit-field itself.
9555 This simple rule makes it obvious why GCC allocates 8 bytes for each
9556 object of the structure type shown above. When looking for a place to
9557 allocate the "containing object" for `field2', the compiler simply tries
9558 to allocate a 64-bit "containing object" at each successive 32-bit
9559 boundary (starting at zero) until it finds a place to allocate that 64-
9560 bit field such that at least 31 contiguous (and previously unallocated)
9561 bits remain within that selected 64 bit field. (As it turns out, for the
9562 example above, the compiler finds it is OK to allocate the "containing
9563 object" 64-bit field at bit-offset zero within the structure type.)
9565 Here we attempt to work backwards from the limited set of facts we're
9566 given, and we try to deduce from those facts, where GCC must have believed
9567 that the containing object started (within the structure type). The value
9568 we deduce is then used (by the callers of this routine) to generate
9569 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
9570 and, in the case of DW_AT_location, regular fields as well). */
9572 /* Figure out the bit-distance from the start of the structure to the
9573 "deepest" bit of the bit-field. */
9574 deepest_bitpos = bitpos_int + field_size_in_bits;
9576 /* This is the tricky part. Use some fancy footwork to deduce where the
9577 lowest addressed bit of the containing object must be. */
9578 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
9580 /* Round up to type_align by default. This works best for bitfields. */
9581 object_offset_in_bits += type_align_in_bits - 1;
9582 object_offset_in_bits /= type_align_in_bits;
9583 object_offset_in_bits *= type_align_in_bits;
9585 if (object_offset_in_bits > bitpos_int)
9587 /* Sigh, the decl must be packed. */
9588 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
9590 /* Round up to decl_align instead. */
9591 object_offset_in_bits += decl_align_in_bits - 1;
9592 object_offset_in_bits /= decl_align_in_bits;
9593 object_offset_in_bits *= decl_align_in_bits;
9596 return object_offset_in_bits / BITS_PER_UNIT;
9599 /* The following routines define various Dwarf attributes and any data
9600 associated with them. */
9602 /* Add a location description attribute value to a DIE.
9604 This emits location attributes suitable for whole variables and
9605 whole parameters. Note that the location attributes for struct fields are
9606 generated by the routine `data_member_location_attribute' below. */
9609 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
9610 dw_loc_descr_ref descr)
9613 add_AT_loc (die, attr_kind, descr);
9616 /* Attach the specialized form of location attribute used for data members of
9617 struct and union types. In the special case of a FIELD_DECL node which
9618 represents a bit-field, the "offset" part of this special location
9619 descriptor must indicate the distance in bytes from the lowest-addressed
9620 byte of the containing struct or union type to the lowest-addressed byte of
9621 the "containing object" for the bit-field. (See the `field_byte_offset'
9624 For any given bit-field, the "containing object" is a hypothetical object
9625 (of some integral or enum type) within which the given bit-field lives. The
9626 type of this hypothetical "containing object" is always the same as the
9627 declared type of the individual bit-field itself (for GCC anyway... the
9628 DWARF spec doesn't actually mandate this). Note that it is the size (in
9629 bytes) of the hypothetical "containing object" which will be given in the
9630 DW_AT_byte_size attribute for this bit-field. (See the
9631 `byte_size_attribute' function below.) It is also used when calculating the
9632 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
9636 add_data_member_location_attribute (dw_die_ref die, tree decl)
9638 HOST_WIDE_INT offset;
9639 dw_loc_descr_ref loc_descr = 0;
9641 if (TREE_CODE (decl) == TREE_BINFO)
9643 /* We're working on the TAG_inheritance for a base class. */
9644 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
9646 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
9647 aren't at a fixed offset from all (sub)objects of the same
9648 type. We need to extract the appropriate offset from our
9649 vtable. The following dwarf expression means
9651 BaseAddr = ObAddr + *((*ObAddr) - Offset)
9653 This is specific to the V3 ABI, of course. */
9655 dw_loc_descr_ref tmp;
9657 /* Make a copy of the object address. */
9658 tmp = new_loc_descr (DW_OP_dup, 0, 0);
9659 add_loc_descr (&loc_descr, tmp);
9661 /* Extract the vtable address. */
9662 tmp = new_loc_descr (DW_OP_deref, 0, 0);
9663 add_loc_descr (&loc_descr, tmp);
9665 /* Calculate the address of the offset. */
9666 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
9667 gcc_assert (offset < 0);
9669 tmp = int_loc_descriptor (-offset);
9670 add_loc_descr (&loc_descr, tmp);
9671 tmp = new_loc_descr (DW_OP_minus, 0, 0);
9672 add_loc_descr (&loc_descr, tmp);
9674 /* Extract the offset. */
9675 tmp = new_loc_descr (DW_OP_deref, 0, 0);
9676 add_loc_descr (&loc_descr, tmp);
9678 /* Add it to the object address. */
9679 tmp = new_loc_descr (DW_OP_plus, 0, 0);
9680 add_loc_descr (&loc_descr, tmp);
9683 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
9686 offset = field_byte_offset (decl);
9690 enum dwarf_location_atom op;
9692 /* The DWARF2 standard says that we should assume that the structure
9693 address is already on the stack, so we can specify a structure field
9694 address by using DW_OP_plus_uconst. */
9696 #ifdef MIPS_DEBUGGING_INFO
9697 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9698 operator correctly. It works only if we leave the offset on the
9702 op = DW_OP_plus_uconst;
9705 loc_descr = new_loc_descr (op, offset, 0);
9708 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
9711 /* Writes integer values to dw_vec_const array. */
9714 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
9718 *dest++ = val & 0xff;
9724 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
9726 static HOST_WIDE_INT
9727 extract_int (const unsigned char *src, unsigned int size)
9729 HOST_WIDE_INT val = 0;
9735 val |= *--src & 0xff;
9741 /* Writes floating point values to dw_vec_const array. */
9744 insert_float (rtx rtl, unsigned char *array)
9750 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
9751 real_to_target (val, &rv, GET_MODE (rtl));
9753 /* real_to_target puts 32-bit pieces in each long. Pack them. */
9754 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
9756 insert_int (val[i], 4, array);
9761 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9762 does not have a "location" either in memory or in a register. These
9763 things can arise in GNU C when a constant is passed as an actual parameter
9764 to an inlined function. They can also arise in C++ where declared
9765 constants do not necessarily get memory "homes". */
9768 add_const_value_attribute (dw_die_ref die, rtx rtl)
9770 switch (GET_CODE (rtl))
9774 HOST_WIDE_INT val = INTVAL (rtl);
9777 add_AT_int (die, DW_AT_const_value, val);
9779 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
9784 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9785 floating-point constant. A CONST_DOUBLE is used whenever the
9786 constant requires more than one word in order to be adequately
9787 represented. We output CONST_DOUBLEs as blocks. */
9789 enum machine_mode mode = GET_MODE (rtl);
9791 if (SCALAR_FLOAT_MODE_P (mode))
9793 unsigned int length = GET_MODE_SIZE (mode);
9794 unsigned char *array = ggc_alloc (length);
9796 insert_float (rtl, array);
9797 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
9801 /* ??? We really should be using HOST_WIDE_INT throughout. */
9802 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
9804 add_AT_long_long (die, DW_AT_const_value,
9805 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
9812 enum machine_mode mode = GET_MODE (rtl);
9813 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
9814 unsigned int length = CONST_VECTOR_NUNITS (rtl);
9815 unsigned char *array = ggc_alloc (length * elt_size);
9819 switch (GET_MODE_CLASS (mode))
9821 case MODE_VECTOR_INT:
9822 for (i = 0, p = array; i < length; i++, p += elt_size)
9824 rtx elt = CONST_VECTOR_ELT (rtl, i);
9825 HOST_WIDE_INT lo, hi;
9827 switch (GET_CODE (elt))
9835 lo = CONST_DOUBLE_LOW (elt);
9836 hi = CONST_DOUBLE_HIGH (elt);
9843 if (elt_size <= sizeof (HOST_WIDE_INT))
9844 insert_int (lo, elt_size, p);
9847 unsigned char *p0 = p;
9848 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
9850 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
9851 if (WORDS_BIG_ENDIAN)
9856 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
9857 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
9862 case MODE_VECTOR_FLOAT:
9863 for (i = 0, p = array; i < length; i++, p += elt_size)
9865 rtx elt = CONST_VECTOR_ELT (rtl, i);
9866 insert_float (elt, p);
9874 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
9879 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
9885 add_AT_addr (die, DW_AT_const_value, rtl);
9886 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
9890 /* In cases where an inlined instance of an inline function is passed
9891 the address of an `auto' variable (which is local to the caller) we
9892 can get a situation where the DECL_RTL of the artificial local
9893 variable (for the inlining) which acts as a stand-in for the
9894 corresponding formal parameter (of the inline function) will look
9895 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9896 exactly a compile-time constant expression, but it isn't the address
9897 of the (artificial) local variable either. Rather, it represents the
9898 *value* which the artificial local variable always has during its
9899 lifetime. We currently have no way to represent such quasi-constant
9900 values in Dwarf, so for now we just punt and generate nothing. */
9904 /* No other kinds of rtx should be possible here. */
9910 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
9911 for use in a later add_const_value_attribute call. */
9914 rtl_for_decl_init (tree init, tree type)
9918 /* If a variable is initialized with a string constant without embedded
9919 zeros, build CONST_STRING. */
9920 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
9922 tree enttype = TREE_TYPE (type);
9923 tree domain = TYPE_DOMAIN (type);
9924 enum machine_mode mode = TYPE_MODE (enttype);
9926 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
9928 && integer_zerop (TYPE_MIN_VALUE (domain))
9929 && compare_tree_int (TYPE_MAX_VALUE (domain),
9930 TREE_STRING_LENGTH (init) - 1) == 0
9931 && ((size_t) TREE_STRING_LENGTH (init)
9932 == strlen (TREE_STRING_POINTER (init)) + 1))
9933 rtl = gen_rtx_CONST_STRING (VOIDmode,
9934 ggc_strdup (TREE_STRING_POINTER (init)));
9936 /* If the initializer is something that we know will expand into an
9937 immediate RTL constant, expand it now. Expanding anything else
9938 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
9939 /* Aggregate, vector, and complex types may contain constructors that may
9940 result in code being generated when expand_expr is called, so we can't
9941 handle them here. Integer and float are useful and safe types to handle
9943 else if ((INTEGRAL_TYPE_P (type) || SCALAR_FLOAT_TYPE_P (type))
9944 && initializer_constant_valid_p (init, type) == null_pointer_node)
9946 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
9948 /* If expand_expr returns a MEM, it wasn't immediate. */
9949 gcc_assert (!rtl || !MEM_P (rtl));
9955 /* Generate RTL for the variable DECL to represent its location. */
9958 rtl_for_decl_location (tree decl)
9962 /* Here we have to decide where we are going to say the parameter "lives"
9963 (as far as the debugger is concerned). We only have a couple of
9964 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9966 DECL_RTL normally indicates where the parameter lives during most of the
9967 activation of the function. If optimization is enabled however, this
9968 could be either NULL or else a pseudo-reg. Both of those cases indicate
9969 that the parameter doesn't really live anywhere (as far as the code
9970 generation parts of GCC are concerned) during most of the function's
9971 activation. That will happen (for example) if the parameter is never
9972 referenced within the function.
9974 We could just generate a location descriptor here for all non-NULL
9975 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
9976 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
9977 where DECL_RTL is NULL or is a pseudo-reg.
9979 Note however that we can only get away with using DECL_INCOMING_RTL as
9980 a backup substitute for DECL_RTL in certain limited cases. In cases
9981 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
9982 we can be sure that the parameter was passed using the same type as it is
9983 declared to have within the function, and that its DECL_INCOMING_RTL
9984 points us to a place where a value of that type is passed.
9986 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
9987 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
9988 because in these cases DECL_INCOMING_RTL points us to a value of some
9989 type which is *different* from the type of the parameter itself. Thus,
9990 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
9991 such cases, the debugger would end up (for example) trying to fetch a
9992 `float' from a place which actually contains the first part of a
9993 `double'. That would lead to really incorrect and confusing
9994 output at debug-time.
9996 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
9997 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
9998 are a couple of exceptions however. On little-endian machines we can
9999 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
10000 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
10001 an integral type that is smaller than TREE_TYPE (decl). These cases arise
10002 when (on a little-endian machine) a non-prototyped function has a
10003 parameter declared to be of type `short' or `char'. In such cases,
10004 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
10005 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
10006 passed `int' value. If the debugger then uses that address to fetch
10007 a `short' or a `char' (on a little-endian machine) the result will be
10008 the correct data, so we allow for such exceptional cases below.
10010 Note that our goal here is to describe the place where the given formal
10011 parameter lives during most of the function's activation (i.e. between the
10012 end of the prologue and the start of the epilogue). We'll do that as best
10013 as we can. Note however that if the given formal parameter is modified
10014 sometime during the execution of the function, then a stack backtrace (at
10015 debug-time) will show the function as having been called with the *new*
10016 value rather than the value which was originally passed in. This happens
10017 rarely enough that it is not a major problem, but it *is* a problem, and
10018 I'd like to fix it.
10020 A future version of dwarf2out.c may generate two additional attributes for
10021 any given DW_TAG_formal_parameter DIE which will describe the "passed
10022 type" and the "passed location" for the given formal parameter in addition
10023 to the attributes we now generate to indicate the "declared type" and the
10024 "active location" for each parameter. This additional set of attributes
10025 could be used by debuggers for stack backtraces. Separately, note that
10026 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
10027 This happens (for example) for inlined-instances of inline function formal
10028 parameters which are never referenced. This really shouldn't be
10029 happening. All PARM_DECL nodes should get valid non-NULL
10030 DECL_INCOMING_RTL values. FIXME. */
10032 /* Use DECL_RTL as the "location" unless we find something better. */
10033 rtl = DECL_RTL_IF_SET (decl);
10035 /* When generating abstract instances, ignore everything except
10036 constants, symbols living in memory, and symbols living in
10037 fixed registers. */
10038 if (! reload_completed)
10041 && (CONSTANT_P (rtl)
10043 && CONSTANT_P (XEXP (rtl, 0)))
10045 && TREE_CODE (decl) == VAR_DECL
10046 && TREE_STATIC (decl))))
10048 rtl = targetm.delegitimize_address (rtl);
10053 else if (TREE_CODE (decl) == PARM_DECL)
10055 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
10057 tree declared_type = TREE_TYPE (decl);
10058 tree passed_type = DECL_ARG_TYPE (decl);
10059 enum machine_mode dmode = TYPE_MODE (declared_type);
10060 enum machine_mode pmode = TYPE_MODE (passed_type);
10062 /* This decl represents a formal parameter which was optimized out.
10063 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
10064 all cases where (rtl == NULL_RTX) just below. */
10065 if (dmode == pmode)
10066 rtl = DECL_INCOMING_RTL (decl);
10067 else if (SCALAR_INT_MODE_P (dmode)
10068 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
10069 && DECL_INCOMING_RTL (decl))
10071 rtx inc = DECL_INCOMING_RTL (decl);
10074 else if (MEM_P (inc))
10076 if (BYTES_BIG_ENDIAN)
10077 rtl = adjust_address_nv (inc, dmode,
10078 GET_MODE_SIZE (pmode)
10079 - GET_MODE_SIZE (dmode));
10086 /* If the parm was passed in registers, but lives on the stack, then
10087 make a big endian correction if the mode of the type of the
10088 parameter is not the same as the mode of the rtl. */
10089 /* ??? This is the same series of checks that are made in dbxout.c before
10090 we reach the big endian correction code there. It isn't clear if all
10091 of these checks are necessary here, but keeping them all is the safe
10093 else if (MEM_P (rtl)
10094 && XEXP (rtl, 0) != const0_rtx
10095 && ! CONSTANT_P (XEXP (rtl, 0))
10096 /* Not passed in memory. */
10097 && !MEM_P (DECL_INCOMING_RTL (decl))
10098 /* Not passed by invisible reference. */
10099 && (!REG_P (XEXP (rtl, 0))
10100 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
10101 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
10102 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
10103 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
10106 /* Big endian correction check. */
10107 && BYTES_BIG_ENDIAN
10108 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
10109 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
10112 int offset = (UNITS_PER_WORD
10113 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
10115 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10116 plus_constant (XEXP (rtl, 0), offset));
10119 else if (TREE_CODE (decl) == VAR_DECL
10122 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
10123 && BYTES_BIG_ENDIAN)
10125 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
10126 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
10128 /* If a variable is declared "register" yet is smaller than
10129 a register, then if we store the variable to memory, it
10130 looks like we're storing a register-sized value, when in
10131 fact we are not. We need to adjust the offset of the
10132 storage location to reflect the actual value's bytes,
10133 else gdb will not be able to display it. */
10135 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10136 plus_constant (XEXP (rtl, 0), rsize-dsize));
10139 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
10140 and will have been substituted directly into all expressions that use it.
10141 C does not have such a concept, but C++ and other languages do. */
10142 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
10143 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
10146 rtl = targetm.delegitimize_address (rtl);
10148 /* If we don't look past the constant pool, we risk emitting a
10149 reference to a constant pool entry that isn't referenced from
10150 code, and thus is not emitted. */
10152 rtl = avoid_constant_pool_reference (rtl);
10157 /* We need to figure out what section we should use as the base for the
10158 address ranges where a given location is valid.
10159 1. If this particular DECL has a section associated with it, use that.
10160 2. If this function has a section associated with it, use that.
10161 3. Otherwise, use the text section.
10162 XXX: If you split a variable across multiple sections, we won't notice. */
10164 static const char *
10165 secname_for_decl (tree decl)
10167 const char *secname;
10169 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
10171 tree sectree = DECL_SECTION_NAME (decl);
10172 secname = TREE_STRING_POINTER (sectree);
10174 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
10176 tree sectree = DECL_SECTION_NAME (current_function_decl);
10177 secname = TREE_STRING_POINTER (sectree);
10180 && (last_text_section == in_unlikely_executed_text
10181 || (last_text_section == in_named
10182 && last_text_section_name
10183 == cfun->unlikely_text_section_name)))
10184 secname = cfun->cold_section_label;
10186 secname = text_section_label;
10191 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
10192 data attribute for a variable or a parameter. We generate the
10193 DW_AT_const_value attribute only in those cases where the given variable
10194 or parameter does not have a true "location" either in memory or in a
10195 register. This can happen (for example) when a constant is passed as an
10196 actual argument in a call to an inline function. (It's possible that
10197 these things can crop up in other ways also.) Note that one type of
10198 constant value which can be passed into an inlined function is a constant
10199 pointer. This can happen for example if an actual argument in an inlined
10200 function call evaluates to a compile-time constant address. */
10203 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
10204 enum dwarf_attribute attr)
10207 dw_loc_descr_ref descr;
10208 var_loc_list *loc_list;
10209 struct var_loc_node *node;
10210 if (TREE_CODE (decl) == ERROR_MARK)
10213 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
10214 || TREE_CODE (decl) == RESULT_DECL);
10216 /* See if we possibly have multiple locations for this variable. */
10217 loc_list = lookup_decl_loc (decl);
10219 /* If it truly has multiple locations, the first and last node will
10221 if (loc_list && loc_list->first != loc_list->last)
10223 const char *endname, *secname;
10224 dw_loc_list_ref list;
10227 /* Now that we know what section we are using for a base,
10228 actually construct the list of locations.
10229 The first location information is what is passed to the
10230 function that creates the location list, and the remaining
10231 locations just get added on to that list.
10232 Note that we only know the start address for a location
10233 (IE location changes), so to build the range, we use
10234 the range [current location start, next location start].
10235 This means we have to special case the last node, and generate
10236 a range of [last location start, end of function label]. */
10238 node = loc_list->first;
10239 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10240 secname = secname_for_decl (decl);
10242 list = new_loc_list (loc_descriptor (varloc),
10243 node->label, node->next->label, secname, 1);
10246 for (; node->next; node = node->next)
10247 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10249 /* The variable has a location between NODE->LABEL and
10250 NODE->NEXT->LABEL. */
10251 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10252 add_loc_descr_to_loc_list (&list, loc_descriptor (varloc),
10253 node->label, node->next->label, secname);
10256 /* If the variable has a location at the last label
10257 it keeps its location until the end of function. */
10258 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10260 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10262 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10263 if (!current_function_decl)
10264 endname = text_end_label;
10267 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10268 current_function_funcdef_no);
10269 endname = ggc_strdup (label_id);
10271 add_loc_descr_to_loc_list (&list, loc_descriptor (varloc),
10272 node->label, endname, secname);
10275 /* Finally, add the location list to the DIE, and we are done. */
10276 add_AT_loc_list (die, attr, list);
10280 /* Try to get some constant RTL for this decl, and use that as the value of
10283 rtl = rtl_for_decl_location (decl);
10284 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
10286 add_const_value_attribute (die, rtl);
10290 /* If we have tried to generate the location otherwise, and it
10291 didn't work out (we wouldn't be here if we did), and we have a one entry
10292 location list, try generating a location from that. */
10293 if (loc_list && loc_list->first)
10295 node = loc_list->first;
10296 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note));
10299 add_AT_location_description (die, attr, descr);
10304 /* We couldn't get any rtl, so try directly generating the location
10305 description from the tree. */
10306 descr = loc_descriptor_from_tree (decl);
10309 add_AT_location_description (die, attr, descr);
10314 /* If we don't have a copy of this variable in memory for some reason (such
10315 as a C++ member constant that doesn't have an out-of-line definition),
10316 we should tell the debugger about the constant value. */
10319 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
10321 tree init = DECL_INITIAL (decl);
10322 tree type = TREE_TYPE (decl);
10325 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
10330 rtl = rtl_for_decl_init (init, type);
10332 add_const_value_attribute (var_die, rtl);
10335 #ifdef DWARF2_UNWIND_INFO
10336 /* Convert the CFI instructions for the current function into a location
10337 list. This is used for DW_AT_frame_base when we targeting a dwarf2
10338 consumer that does not support the dwarf3 DW_OP_call_frame_cfa. */
10340 static dw_loc_list_ref
10341 convert_cfa_to_loc_list (void)
10344 dw_loc_list_ref list, *list_tail;
10346 dw_cfa_location last_cfa, next_cfa;
10347 const char *start_label, *last_label, *section;
10349 fde = &fde_table[fde_table_in_use - 1];
10351 section = secname_for_decl (current_function_decl);
10355 next_cfa.reg = INVALID_REGNUM;
10356 next_cfa.offset = 0;
10357 next_cfa.indirect = 0;
10358 next_cfa.base_offset = 0;
10360 start_label = fde->dw_fde_begin;
10362 /* ??? Bald assumption that the CIE opcode list does not contain
10363 advance opcodes. */
10364 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
10365 lookup_cfa_1 (cfi, &next_cfa);
10367 last_cfa = next_cfa;
10368 last_label = start_label;
10370 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
10371 switch (cfi->dw_cfi_opc)
10373 case DW_CFA_advance_loc1:
10374 case DW_CFA_advance_loc2:
10375 case DW_CFA_advance_loc4:
10376 if (!cfa_equal_p (&last_cfa, &next_cfa))
10378 *list_tail = new_loc_list (build_cfa_loc (&last_cfa), start_label,
10379 last_label, section, list == NULL);
10381 list_tail = &(*list_tail)->dw_loc_next;
10382 last_cfa = next_cfa;
10383 start_label = last_label;
10385 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
10388 case DW_CFA_advance_loc:
10389 /* The encoding is complex enough that we should never emit this. */
10390 case DW_CFA_remember_state:
10391 case DW_CFA_restore_state:
10392 /* We don't handle these two in this function. It would be possible
10393 if it were to be required. */
10394 gcc_unreachable ();
10397 lookup_cfa_1 (cfi, &next_cfa);
10401 if (!cfa_equal_p (&last_cfa, &next_cfa))
10403 *list_tail = new_loc_list (build_cfa_loc (&last_cfa), start_label,
10404 last_label, section, list == NULL);
10405 list_tail = &(*list_tail)->dw_loc_next;
10406 start_label = last_label;
10408 *list_tail = new_loc_list (build_cfa_loc (&next_cfa), start_label,
10409 fde->dw_fde_end, section, list == NULL);
10414 /* Compute a displacement from the "steady-state frame pointer" to
10415 the CFA, and store it in frame_pointer_cfa_offset. */
10418 compute_frame_pointer_to_cfa_displacement (void)
10420 HOST_WIDE_INT offset;
10423 #ifdef FRAME_POINTER_CFA_OFFSET
10424 reg = frame_pointer_rtx;
10425 offset = FRAME_POINTER_CFA_OFFSET (current_function_decl);
10427 reg = arg_pointer_rtx;
10428 offset = ARG_POINTER_CFA_OFFSET (current_function_decl);
10431 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10432 if (GET_CODE (elim) == PLUS)
10434 offset += INTVAL (XEXP (elim, 1));
10435 elim = XEXP (elim, 0);
10437 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
10438 : stack_pointer_rtx));
10440 frame_pointer_cfa_offset = -offset;
10444 /* Generate a DW_AT_name attribute given some string value to be included as
10445 the value of the attribute. */
10448 add_name_attribute (dw_die_ref die, const char *name_string)
10450 if (name_string != NULL && *name_string != 0)
10452 if (demangle_name_func)
10453 name_string = (*demangle_name_func) (name_string);
10455 add_AT_string (die, DW_AT_name, name_string);
10459 /* Generate a DW_AT_comp_dir attribute for DIE. */
10462 add_comp_dir_attribute (dw_die_ref die)
10464 const char *wd = get_src_pwd ();
10466 add_AT_string (die, DW_AT_comp_dir, wd);
10469 /* Given a tree node describing an array bound (either lower or upper) output
10470 a representation for that bound. */
10473 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
10475 switch (TREE_CODE (bound))
10480 /* All fixed-bounds are represented by INTEGER_CST nodes. */
10482 if (! host_integerp (bound, 0)
10483 || (bound_attr == DW_AT_lower_bound
10484 && (((is_c_family () || is_java ()) && integer_zerop (bound))
10485 || (is_fortran () && integer_onep (bound)))))
10486 /* Use the default. */
10489 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
10494 case NON_LVALUE_EXPR:
10495 case VIEW_CONVERT_EXPR:
10496 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
10506 dw_die_ref decl_die = lookup_decl_die (bound);
10508 /* ??? Can this happen, or should the variable have been bound
10509 first? Probably it can, since I imagine that we try to create
10510 the types of parameters in the order in which they exist in
10511 the list, and won't have created a forward reference to a
10512 later parameter. */
10513 if (decl_die != NULL)
10514 add_AT_die_ref (subrange_die, bound_attr, decl_die);
10520 /* Otherwise try to create a stack operation procedure to
10521 evaluate the value of the array bound. */
10523 dw_die_ref ctx, decl_die;
10524 dw_loc_descr_ref loc;
10526 loc = loc_descriptor_from_tree (bound);
10530 if (current_function_decl == 0)
10531 ctx = comp_unit_die;
10533 ctx = lookup_decl_die (current_function_decl);
10535 decl_die = new_die (DW_TAG_variable, ctx, bound);
10536 add_AT_flag (decl_die, DW_AT_artificial, 1);
10537 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
10538 add_AT_loc (decl_die, DW_AT_location, loc);
10540 add_AT_die_ref (subrange_die, bound_attr, decl_die);
10546 /* Note that the block of subscript information for an array type also
10547 includes information about the element type of type given array type. */
10550 add_subscript_info (dw_die_ref type_die, tree type)
10552 #ifndef MIPS_DEBUGGING_INFO
10553 unsigned dimension_number;
10556 dw_die_ref subrange_die;
10558 /* The GNU compilers represent multidimensional array types as sequences of
10559 one dimensional array types whose element types are themselves array
10560 types. Here we squish that down, so that each multidimensional array
10561 type gets only one array_type DIE in the Dwarf debugging info. The draft
10562 Dwarf specification say that we are allowed to do this kind of
10563 compression in C (because there is no difference between an array or
10564 arrays and a multidimensional array in C) but for other source languages
10565 (e.g. Ada) we probably shouldn't do this. */
10567 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10568 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10569 We work around this by disabling this feature. See also
10570 gen_array_type_die. */
10571 #ifndef MIPS_DEBUGGING_INFO
10572 for (dimension_number = 0;
10573 TREE_CODE (type) == ARRAY_TYPE;
10574 type = TREE_TYPE (type), dimension_number++)
10577 tree domain = TYPE_DOMAIN (type);
10579 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
10580 and (in GNU C only) variable bounds. Handle all three forms
10582 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
10585 /* We have an array type with specified bounds. */
10586 lower = TYPE_MIN_VALUE (domain);
10587 upper = TYPE_MAX_VALUE (domain);
10589 /* Define the index type. */
10590 if (TREE_TYPE (domain))
10592 /* ??? This is probably an Ada unnamed subrange type. Ignore the
10593 TREE_TYPE field. We can't emit debug info for this
10594 because it is an unnamed integral type. */
10595 if (TREE_CODE (domain) == INTEGER_TYPE
10596 && TYPE_NAME (domain) == NULL_TREE
10597 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
10598 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
10601 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
10605 /* ??? If upper is NULL, the array has unspecified length,
10606 but it does have a lower bound. This happens with Fortran
10608 Since the debugger is definitely going to need to know N
10609 to produce useful results, go ahead and output the lower
10610 bound solo, and hope the debugger can cope. */
10612 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
10614 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
10617 /* Otherwise we have an array type with an unspecified length. The
10618 DWARF-2 spec does not say how to handle this; let's just leave out the
10624 add_byte_size_attribute (dw_die_ref die, tree tree_node)
10628 switch (TREE_CODE (tree_node))
10633 case ENUMERAL_TYPE:
10636 case QUAL_UNION_TYPE:
10637 size = int_size_in_bytes (tree_node);
10640 /* For a data member of a struct or union, the DW_AT_byte_size is
10641 generally given as the number of bytes normally allocated for an
10642 object of the *declared* type of the member itself. This is true
10643 even for bit-fields. */
10644 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
10647 gcc_unreachable ();
10650 /* Note that `size' might be -1 when we get to this point. If it is, that
10651 indicates that the byte size of the entity in question is variable. We
10652 have no good way of expressing this fact in Dwarf at the present time,
10653 so just let the -1 pass on through. */
10654 add_AT_unsigned (die, DW_AT_byte_size, size);
10657 /* For a FIELD_DECL node which represents a bit-field, output an attribute
10658 which specifies the distance in bits from the highest order bit of the
10659 "containing object" for the bit-field to the highest order bit of the
10662 For any given bit-field, the "containing object" is a hypothetical object
10663 (of some integral or enum type) within which the given bit-field lives. The
10664 type of this hypothetical "containing object" is always the same as the
10665 declared type of the individual bit-field itself. The determination of the
10666 exact location of the "containing object" for a bit-field is rather
10667 complicated. It's handled by the `field_byte_offset' function (above).
10669 Note that it is the size (in bytes) of the hypothetical "containing object"
10670 which will be given in the DW_AT_byte_size attribute for this bit-field.
10671 (See `byte_size_attribute' above). */
10674 add_bit_offset_attribute (dw_die_ref die, tree decl)
10676 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
10677 tree type = DECL_BIT_FIELD_TYPE (decl);
10678 HOST_WIDE_INT bitpos_int;
10679 HOST_WIDE_INT highest_order_object_bit_offset;
10680 HOST_WIDE_INT highest_order_field_bit_offset;
10681 HOST_WIDE_INT unsigned bit_offset;
10683 /* Must be a field and a bit field. */
10684 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
10686 /* We can't yet handle bit-fields whose offsets are variable, so if we
10687 encounter such things, just return without generating any attribute
10688 whatsoever. Likewise for variable or too large size. */
10689 if (! host_integerp (bit_position (decl), 0)
10690 || ! host_integerp (DECL_SIZE (decl), 1))
10693 bitpos_int = int_bit_position (decl);
10695 /* Note that the bit offset is always the distance (in bits) from the
10696 highest-order bit of the "containing object" to the highest-order bit of
10697 the bit-field itself. Since the "high-order end" of any object or field
10698 is different on big-endian and little-endian machines, the computation
10699 below must take account of these differences. */
10700 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
10701 highest_order_field_bit_offset = bitpos_int;
10703 if (! BYTES_BIG_ENDIAN)
10705 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
10706 highest_order_object_bit_offset += simple_type_size_in_bits (type);
10710 = (! BYTES_BIG_ENDIAN
10711 ? highest_order_object_bit_offset - highest_order_field_bit_offset
10712 : highest_order_field_bit_offset - highest_order_object_bit_offset);
10714 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
10717 /* For a FIELD_DECL node which represents a bit field, output an attribute
10718 which specifies the length in bits of the given field. */
10721 add_bit_size_attribute (dw_die_ref die, tree decl)
10723 /* Must be a field and a bit field. */
10724 gcc_assert (TREE_CODE (decl) == FIELD_DECL
10725 && DECL_BIT_FIELD_TYPE (decl));
10727 if (host_integerp (DECL_SIZE (decl), 1))
10728 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
10731 /* If the compiled language is ANSI C, then add a 'prototyped'
10732 attribute, if arg types are given for the parameters of a function. */
10735 add_prototyped_attribute (dw_die_ref die, tree func_type)
10737 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
10738 && TYPE_ARG_TYPES (func_type) != NULL)
10739 add_AT_flag (die, DW_AT_prototyped, 1);
10742 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
10743 by looking in either the type declaration or object declaration
10747 add_abstract_origin_attribute (dw_die_ref die, tree origin)
10749 dw_die_ref origin_die = NULL;
10751 if (TREE_CODE (origin) != FUNCTION_DECL)
10753 /* We may have gotten separated from the block for the inlined
10754 function, if we're in an exception handler or some such; make
10755 sure that the abstract function has been written out.
10757 Doing this for nested functions is wrong, however; functions are
10758 distinct units, and our context might not even be inline. */
10762 fn = TYPE_STUB_DECL (fn);
10764 fn = decl_function_context (fn);
10766 dwarf2out_abstract_function (fn);
10769 if (DECL_P (origin))
10770 origin_die = lookup_decl_die (origin);
10771 else if (TYPE_P (origin))
10772 origin_die = lookup_type_die (origin);
10774 /* XXX: Functions that are never lowered don't always have correct block
10775 trees (in the case of java, they simply have no block tree, in some other
10776 languages). For these functions, there is nothing we can really do to
10777 output correct debug info for inlined functions in all cases. Rather
10778 than die, we'll just produce deficient debug info now, in that we will
10779 have variables without a proper abstract origin. In the future, when all
10780 functions are lowered, we should re-add a gcc_assert (origin_die)
10784 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
10787 /* We do not currently support the pure_virtual attribute. */
10790 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
10792 if (DECL_VINDEX (func_decl))
10794 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10796 if (host_integerp (DECL_VINDEX (func_decl), 0))
10797 add_AT_loc (die, DW_AT_vtable_elem_location,
10798 new_loc_descr (DW_OP_constu,
10799 tree_low_cst (DECL_VINDEX (func_decl), 0),
10802 /* GNU extension: Record what type this method came from originally. */
10803 if (debug_info_level > DINFO_LEVEL_TERSE)
10804 add_AT_die_ref (die, DW_AT_containing_type,
10805 lookup_type_die (DECL_CONTEXT (func_decl)));
10809 /* Add source coordinate attributes for the given decl. */
10812 add_src_coords_attributes (dw_die_ref die, tree decl)
10814 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
10815 unsigned file_index = lookup_filename (s.file);
10817 add_AT_unsigned (die, DW_AT_decl_file, file_index);
10818 add_AT_unsigned (die, DW_AT_decl_line, s.line);
10821 /* Add a DW_AT_name attribute and source coordinate attribute for the
10822 given decl, but only if it actually has a name. */
10825 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
10829 decl_name = DECL_NAME (decl);
10830 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
10832 add_name_attribute (die, dwarf2_name (decl, 0));
10833 if (! DECL_ARTIFICIAL (decl))
10834 add_src_coords_attributes (die, decl);
10836 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
10837 && TREE_PUBLIC (decl)
10838 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
10839 && !DECL_ABSTRACT (decl)
10840 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl)))
10841 add_AT_string (die, DW_AT_MIPS_linkage_name,
10842 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
10845 #ifdef VMS_DEBUGGING_INFO
10846 /* Get the function's name, as described by its RTL. This may be different
10847 from the DECL_NAME name used in the source file. */
10848 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
10850 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
10851 XEXP (DECL_RTL (decl), 0));
10852 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
10857 /* Push a new declaration scope. */
10860 push_decl_scope (tree scope)
10862 VEC_safe_push (tree, gc, decl_scope_table, scope);
10865 /* Pop a declaration scope. */
10868 pop_decl_scope (void)
10870 VEC_pop (tree, decl_scope_table);
10873 /* Return the DIE for the scope that immediately contains this type.
10874 Non-named types get global scope. Named types nested in other
10875 types get their containing scope if it's open, or global scope
10876 otherwise. All other types (i.e. function-local named types) get
10877 the current active scope. */
10880 scope_die_for (tree t, dw_die_ref context_die)
10882 dw_die_ref scope_die = NULL;
10883 tree containing_scope;
10886 /* Non-types always go in the current scope. */
10887 gcc_assert (TYPE_P (t));
10889 containing_scope = TYPE_CONTEXT (t);
10891 /* Use the containing namespace if it was passed in (for a declaration). */
10892 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
10894 if (context_die == lookup_decl_die (containing_scope))
10897 containing_scope = NULL_TREE;
10900 /* Ignore function type "scopes" from the C frontend. They mean that
10901 a tagged type is local to a parmlist of a function declarator, but
10902 that isn't useful to DWARF. */
10903 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
10904 containing_scope = NULL_TREE;
10906 if (containing_scope == NULL_TREE)
10907 scope_die = comp_unit_die;
10908 else if (TYPE_P (containing_scope))
10910 /* For types, we can just look up the appropriate DIE. But
10911 first we check to see if we're in the middle of emitting it
10912 so we know where the new DIE should go. */
10913 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
10914 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
10919 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
10920 || TREE_ASM_WRITTEN (containing_scope));
10922 /* If none of the current dies are suitable, we get file scope. */
10923 scope_die = comp_unit_die;
10926 scope_die = lookup_type_die (containing_scope);
10929 scope_die = context_die;
10934 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10937 local_scope_p (dw_die_ref context_die)
10939 for (; context_die; context_die = context_die->die_parent)
10940 if (context_die->die_tag == DW_TAG_inlined_subroutine
10941 || context_die->die_tag == DW_TAG_subprogram)
10947 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
10948 whether or not to treat a DIE in this context as a declaration. */
10951 class_or_namespace_scope_p (dw_die_ref context_die)
10953 return (context_die
10954 && (context_die->die_tag == DW_TAG_structure_type
10955 || context_die->die_tag == DW_TAG_union_type
10956 || context_die->die_tag == DW_TAG_namespace));
10959 /* Many forms of DIEs require a "type description" attribute. This
10960 routine locates the proper "type descriptor" die for the type given
10961 by 'type', and adds a DW_AT_type attribute below the given die. */
10964 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
10965 int decl_volatile, dw_die_ref context_die)
10967 enum tree_code code = TREE_CODE (type);
10968 dw_die_ref type_die = NULL;
10970 /* ??? If this type is an unnamed subrange type of an integral or
10971 floating-point type, use the inner type. This is because we have no
10972 support for unnamed types in base_type_die. This can happen if this is
10973 an Ada subrange type. Correct solution is emit a subrange type die. */
10974 if ((code == INTEGER_TYPE || code == REAL_TYPE)
10975 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
10976 type = TREE_TYPE (type), code = TREE_CODE (type);
10978 if (code == ERROR_MARK
10979 /* Handle a special case. For functions whose return type is void, we
10980 generate *no* type attribute. (Note that no object may have type
10981 `void', so this only applies to function return types). */
10982 || code == VOID_TYPE)
10985 type_die = modified_type_die (type,
10986 decl_const || TYPE_READONLY (type),
10987 decl_volatile || TYPE_VOLATILE (type),
10990 if (type_die != NULL)
10991 add_AT_die_ref (object_die, DW_AT_type, type_die);
10994 /* Given an object die, add the calling convention attribute for the
10995 function call type. */
10997 add_calling_convention_attribute (dw_die_ref subr_die, tree type)
10999 enum dwarf_calling_convention value = DW_CC_normal;
11001 value = targetm.dwarf_calling_convention (type);
11003 /* Only add the attribute if the backend requests it, and
11004 is not DW_CC_normal. */
11005 if (value && (value != DW_CC_normal))
11006 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
11009 /* Given a tree pointer to a struct, class, union, or enum type node, return
11010 a pointer to the (string) tag name for the given type, or zero if the type
11011 was declared without a tag. */
11013 static const char *
11014 type_tag (tree type)
11016 const char *name = 0;
11018 if (TYPE_NAME (type) != 0)
11022 /* Find the IDENTIFIER_NODE for the type name. */
11023 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
11024 t = TYPE_NAME (type);
11026 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
11027 a TYPE_DECL node, regardless of whether or not a `typedef' was
11029 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11030 && ! DECL_IGNORED_P (TYPE_NAME (type)))
11031 t = DECL_NAME (TYPE_NAME (type));
11033 /* Now get the name as a string, or invent one. */
11035 name = IDENTIFIER_POINTER (t);
11038 return (name == 0 || *name == '\0') ? 0 : name;
11041 /* Return the type associated with a data member, make a special check
11042 for bit field types. */
11045 member_declared_type (tree member)
11047 return (DECL_BIT_FIELD_TYPE (member)
11048 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
11051 /* Get the decl's label, as described by its RTL. This may be different
11052 from the DECL_NAME name used in the source file. */
11055 static const char *
11056 decl_start_label (tree decl)
11059 const char *fnname;
11061 x = DECL_RTL (decl);
11062 gcc_assert (MEM_P (x));
11065 gcc_assert (GET_CODE (x) == SYMBOL_REF);
11067 fnname = XSTR (x, 0);
11072 /* These routines generate the internal representation of the DIE's for
11073 the compilation unit. Debugging information is collected by walking
11074 the declaration trees passed in from dwarf2out_decl(). */
11077 gen_array_type_die (tree type, dw_die_ref context_die)
11079 dw_die_ref scope_die = scope_die_for (type, context_die);
11080 dw_die_ref array_die;
11083 /* ??? The SGI dwarf reader fails for array of array of enum types unless
11084 the inner array type comes before the outer array type. Thus we must
11085 call gen_type_die before we call new_die. See below also. */
11086 #ifdef MIPS_DEBUGGING_INFO
11087 gen_type_die (TREE_TYPE (type), context_die);
11090 array_die = new_die (DW_TAG_array_type, scope_die, type);
11091 add_name_attribute (array_die, type_tag (type));
11092 equate_type_number_to_die (type, array_die);
11094 if (TREE_CODE (type) == VECTOR_TYPE)
11096 /* The frontend feeds us a representation for the vector as a struct
11097 containing an array. Pull out the array type. */
11098 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
11099 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
11103 /* We default the array ordering. SDB will probably do
11104 the right things even if DW_AT_ordering is not present. It's not even
11105 an issue until we start to get into multidimensional arrays anyway. If
11106 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
11107 then we'll have to put the DW_AT_ordering attribute back in. (But if
11108 and when we find out that we need to put these in, we will only do so
11109 for multidimensional arrays. */
11110 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
11113 #ifdef MIPS_DEBUGGING_INFO
11114 /* The SGI compilers handle arrays of unknown bound by setting
11115 AT_declaration and not emitting any subrange DIEs. */
11116 if (! TYPE_DOMAIN (type))
11117 add_AT_flag (array_die, DW_AT_declaration, 1);
11120 add_subscript_info (array_die, type);
11122 /* Add representation of the type of the elements of this array type. */
11123 element_type = TREE_TYPE (type);
11125 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11126 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11127 We work around this by disabling this feature. See also
11128 add_subscript_info. */
11129 #ifndef MIPS_DEBUGGING_INFO
11130 while (TREE_CODE (element_type) == ARRAY_TYPE)
11131 element_type = TREE_TYPE (element_type);
11133 gen_type_die (element_type, context_die);
11136 add_type_attribute (array_die, element_type, 0, 0, context_die);
11141 gen_entry_point_die (tree decl, dw_die_ref context_die)
11143 tree origin = decl_ultimate_origin (decl);
11144 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
11146 if (origin != NULL)
11147 add_abstract_origin_attribute (decl_die, origin);
11150 add_name_and_src_coords_attributes (decl_die, decl);
11151 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
11152 0, 0, context_die);
11155 if (DECL_ABSTRACT (decl))
11156 equate_decl_number_to_die (decl, decl_die);
11158 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
11162 /* Walk through the list of incomplete types again, trying once more to
11163 emit full debugging info for them. */
11166 retry_incomplete_types (void)
11170 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
11171 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
11174 /* Generate a DIE to represent an inlined instance of an enumeration type. */
11177 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
11179 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
11181 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11182 be incomplete and such types are not marked. */
11183 add_abstract_origin_attribute (type_die, type);
11186 /* Generate a DIE to represent an inlined instance of a structure type. */
11189 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
11191 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
11193 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11194 be incomplete and such types are not marked. */
11195 add_abstract_origin_attribute (type_die, type);
11198 /* Generate a DIE to represent an inlined instance of a union type. */
11201 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
11203 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
11205 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11206 be incomplete and such types are not marked. */
11207 add_abstract_origin_attribute (type_die, type);
11210 /* Generate a DIE to represent an enumeration type. Note that these DIEs
11211 include all of the information about the enumeration values also. Each
11212 enumerated type name/value is listed as a child of the enumerated type
11216 gen_enumeration_type_die (tree type, dw_die_ref context_die)
11218 dw_die_ref type_die = lookup_type_die (type);
11220 if (type_die == NULL)
11222 type_die = new_die (DW_TAG_enumeration_type,
11223 scope_die_for (type, context_die), type);
11224 equate_type_number_to_die (type, type_die);
11225 add_name_attribute (type_die, type_tag (type));
11227 else if (! TYPE_SIZE (type))
11230 remove_AT (type_die, DW_AT_declaration);
11232 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
11233 given enum type is incomplete, do not generate the DW_AT_byte_size
11234 attribute or the DW_AT_element_list attribute. */
11235 if (TYPE_SIZE (type))
11239 TREE_ASM_WRITTEN (type) = 1;
11240 add_byte_size_attribute (type_die, type);
11241 if (TYPE_STUB_DECL (type) != NULL_TREE)
11242 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
11244 /* If the first reference to this type was as the return type of an
11245 inline function, then it may not have a parent. Fix this now. */
11246 if (type_die->die_parent == NULL)
11247 add_child_die (scope_die_for (type, context_die), type_die);
11249 for (link = TYPE_VALUES (type);
11250 link != NULL; link = TREE_CHAIN (link))
11252 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
11253 tree value = TREE_VALUE (link);
11255 add_name_attribute (enum_die,
11256 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
11258 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
11259 /* DWARF2 does not provide a way of indicating whether or
11260 not enumeration constants are signed or unsigned. GDB
11261 always assumes the values are signed, so we output all
11262 values as if they were signed. That means that
11263 enumeration constants with very large unsigned values
11264 will appear to have negative values in the debugger. */
11265 add_AT_int (enum_die, DW_AT_const_value,
11266 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
11270 add_AT_flag (type_die, DW_AT_declaration, 1);
11275 /* Generate a DIE to represent either a real live formal parameter decl or to
11276 represent just the type of some formal parameter position in some function
11279 Note that this routine is a bit unusual because its argument may be a
11280 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
11281 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
11282 node. If it's the former then this function is being called to output a
11283 DIE to represent a formal parameter object (or some inlining thereof). If
11284 it's the latter, then this function is only being called to output a
11285 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
11286 argument type of some subprogram type. */
11289 gen_formal_parameter_die (tree node, dw_die_ref context_die)
11291 dw_die_ref parm_die
11292 = new_die (DW_TAG_formal_parameter, context_die, node);
11295 switch (TREE_CODE_CLASS (TREE_CODE (node)))
11297 case tcc_declaration:
11298 origin = decl_ultimate_origin (node);
11299 if (origin != NULL)
11300 add_abstract_origin_attribute (parm_die, origin);
11303 add_name_and_src_coords_attributes (parm_die, node);
11304 add_type_attribute (parm_die, TREE_TYPE (node),
11305 TREE_READONLY (node),
11306 TREE_THIS_VOLATILE (node),
11308 if (DECL_ARTIFICIAL (node))
11309 add_AT_flag (parm_die, DW_AT_artificial, 1);
11312 equate_decl_number_to_die (node, parm_die);
11313 if (! DECL_ABSTRACT (node))
11314 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
11319 /* We were called with some kind of a ..._TYPE node. */
11320 add_type_attribute (parm_die, node, 0, 0, context_die);
11324 gcc_unreachable ();
11330 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
11331 at the end of an (ANSI prototyped) formal parameters list. */
11334 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
11336 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
11339 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
11340 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
11341 parameters as specified in some function type specification (except for
11342 those which appear as part of a function *definition*). */
11345 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
11348 tree formal_type = NULL;
11349 tree first_parm_type;
11352 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
11354 arg = DECL_ARGUMENTS (function_or_method_type);
11355 function_or_method_type = TREE_TYPE (function_or_method_type);
11360 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
11362 /* Make our first pass over the list of formal parameter types and output a
11363 DW_TAG_formal_parameter DIE for each one. */
11364 for (link = first_parm_type; link; )
11366 dw_die_ref parm_die;
11368 formal_type = TREE_VALUE (link);
11369 if (formal_type == void_type_node)
11372 /* Output a (nameless) DIE to represent the formal parameter itself. */
11373 parm_die = gen_formal_parameter_die (formal_type, context_die);
11374 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
11375 && link == first_parm_type)
11376 || (arg && DECL_ARTIFICIAL (arg)))
11377 add_AT_flag (parm_die, DW_AT_artificial, 1);
11379 link = TREE_CHAIN (link);
11381 arg = TREE_CHAIN (arg);
11384 /* If this function type has an ellipsis, add a
11385 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
11386 if (formal_type != void_type_node)
11387 gen_unspecified_parameters_die (function_or_method_type, context_die);
11389 /* Make our second (and final) pass over the list of formal parameter types
11390 and output DIEs to represent those types (as necessary). */
11391 for (link = TYPE_ARG_TYPES (function_or_method_type);
11392 link && TREE_VALUE (link);
11393 link = TREE_CHAIN (link))
11394 gen_type_die (TREE_VALUE (link), context_die);
11397 /* We want to generate the DIE for TYPE so that we can generate the
11398 die for MEMBER, which has been defined; we will need to refer back
11399 to the member declaration nested within TYPE. If we're trying to
11400 generate minimal debug info for TYPE, processing TYPE won't do the
11401 trick; we need to attach the member declaration by hand. */
11404 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
11406 gen_type_die (type, context_die);
11408 /* If we're trying to avoid duplicate debug info, we may not have
11409 emitted the member decl for this function. Emit it now. */
11410 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
11411 && ! lookup_decl_die (member))
11413 dw_die_ref type_die;
11414 gcc_assert (!decl_ultimate_origin (member));
11416 push_decl_scope (type);
11417 type_die = lookup_type_die (type);
11418 if (TREE_CODE (member) == FUNCTION_DECL)
11419 gen_subprogram_die (member, type_die);
11420 else if (TREE_CODE (member) == FIELD_DECL)
11422 /* Ignore the nameless fields that are used to skip bits but handle
11423 C++ anonymous unions and structs. */
11424 if (DECL_NAME (member) != NULL_TREE
11425 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
11426 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
11428 gen_type_die (member_declared_type (member), type_die);
11429 gen_field_die (member, type_die);
11433 gen_variable_die (member, type_die);
11439 /* Generate the DWARF2 info for the "abstract" instance of a function which we
11440 may later generate inlined and/or out-of-line instances of. */
11443 dwarf2out_abstract_function (tree decl)
11445 dw_die_ref old_die;
11448 int was_abstract = DECL_ABSTRACT (decl);
11450 /* Make sure we have the actual abstract inline, not a clone. */
11451 decl = DECL_ORIGIN (decl);
11453 old_die = lookup_decl_die (decl);
11454 if (old_die && get_AT (old_die, DW_AT_inline))
11455 /* We've already generated the abstract instance. */
11458 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
11459 we don't get confused by DECL_ABSTRACT. */
11460 if (debug_info_level > DINFO_LEVEL_TERSE)
11462 context = decl_class_context (decl);
11464 gen_type_die_for_member
11465 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
11468 /* Pretend we've just finished compiling this function. */
11469 save_fn = current_function_decl;
11470 current_function_decl = decl;
11472 set_decl_abstract_flags (decl, 1);
11473 dwarf2out_decl (decl);
11474 if (! was_abstract)
11475 set_decl_abstract_flags (decl, 0);
11477 current_function_decl = save_fn;
11480 /* Generate a DIE to represent a declared function (either file-scope or
11484 gen_subprogram_die (tree decl, dw_die_ref context_die)
11486 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
11487 tree origin = decl_ultimate_origin (decl);
11488 dw_die_ref subr_die;
11491 dw_die_ref old_die = lookup_decl_die (decl);
11492 int declaration = (current_function_decl != decl
11493 || class_or_namespace_scope_p (context_die));
11495 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
11496 started to generate the abstract instance of an inline, decided to output
11497 its containing class, and proceeded to emit the declaration of the inline
11498 from the member list for the class. If so, DECLARATION takes priority;
11499 we'll get back to the abstract instance when done with the class. */
11501 /* The class-scope declaration DIE must be the primary DIE. */
11502 if (origin && declaration && class_or_namespace_scope_p (context_die))
11505 gcc_assert (!old_die);
11508 /* Now that the C++ front end lazily declares artificial member fns, we
11509 might need to retrofit the declaration into its class. */
11510 if (!declaration && !origin && !old_die
11511 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
11512 && !class_or_namespace_scope_p (context_die)
11513 && debug_info_level > DINFO_LEVEL_TERSE)
11514 old_die = force_decl_die (decl);
11516 if (origin != NULL)
11518 gcc_assert (!declaration || local_scope_p (context_die));
11520 /* Fixup die_parent for the abstract instance of a nested
11521 inline function. */
11522 if (old_die && old_die->die_parent == NULL)
11523 add_child_die (context_die, old_die);
11525 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11526 add_abstract_origin_attribute (subr_die, origin);
11530 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11531 unsigned file_index = lookup_filename (s.file);
11533 if (!get_AT_flag (old_die, DW_AT_declaration)
11534 /* We can have a normal definition following an inline one in the
11535 case of redefinition of GNU C extern inlines.
11536 It seems reasonable to use AT_specification in this case. */
11537 && !get_AT (old_die, DW_AT_inline))
11539 /* Detect and ignore this case, where we are trying to output
11540 something we have already output. */
11544 /* If the definition comes from the same place as the declaration,
11545 maybe use the old DIE. We always want the DIE for this function
11546 that has the *_pc attributes to be under comp_unit_die so the
11547 debugger can find it. We also need to do this for abstract
11548 instances of inlines, since the spec requires the out-of-line copy
11549 to have the same parent. For local class methods, this doesn't
11550 apply; we just use the old DIE. */
11551 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
11552 && (DECL_ARTIFICIAL (decl)
11553 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
11554 && (get_AT_unsigned (old_die, DW_AT_decl_line)
11555 == (unsigned) s.line))))
11557 subr_die = old_die;
11559 /* Clear out the declaration attribute and the formal parameters.
11560 Do not remove all children, because it is possible that this
11561 declaration die was forced using force_decl_die(). In such
11562 cases die that forced declaration die (e.g. TAG_imported_module)
11563 is one of the children that we do not want to remove. */
11564 remove_AT (subr_die, DW_AT_declaration);
11565 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
11569 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11570 add_AT_specification (subr_die, old_die);
11571 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
11572 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
11573 if (get_AT_unsigned (old_die, DW_AT_decl_line)
11574 != (unsigned) s.line)
11576 (subr_die, DW_AT_decl_line, s.line);
11581 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11583 if (TREE_PUBLIC (decl))
11584 add_AT_flag (subr_die, DW_AT_external, 1);
11586 add_name_and_src_coords_attributes (subr_die, decl);
11587 if (debug_info_level > DINFO_LEVEL_TERSE)
11589 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
11590 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
11591 0, 0, context_die);
11594 add_pure_or_virtual_attribute (subr_die, decl);
11595 if (DECL_ARTIFICIAL (decl))
11596 add_AT_flag (subr_die, DW_AT_artificial, 1);
11598 if (TREE_PROTECTED (decl))
11599 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
11600 else if (TREE_PRIVATE (decl))
11601 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
11606 if (!old_die || !get_AT (old_die, DW_AT_inline))
11608 add_AT_flag (subr_die, DW_AT_declaration, 1);
11610 /* The first time we see a member function, it is in the context of
11611 the class to which it belongs. We make sure of this by emitting
11612 the class first. The next time is the definition, which is
11613 handled above. The two may come from the same source text.
11615 Note that force_decl_die() forces function declaration die. It is
11616 later reused to represent definition. */
11617 equate_decl_number_to_die (decl, subr_die);
11620 else if (DECL_ABSTRACT (decl))
11622 if (DECL_DECLARED_INLINE_P (decl))
11624 if (cgraph_function_possibly_inlined_p (decl))
11625 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
11627 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
11631 if (cgraph_function_possibly_inlined_p (decl))
11632 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
11634 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
11637 equate_decl_number_to_die (decl, subr_die);
11639 else if (!DECL_EXTERNAL (decl))
11641 if (!old_die || !get_AT (old_die, DW_AT_inline))
11642 equate_decl_number_to_die (decl, subr_die);
11644 if (!flag_reorder_blocks_and_partition)
11646 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
11647 current_function_funcdef_no);
11648 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
11649 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
11650 current_function_funcdef_no);
11651 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
11653 add_pubname (decl, subr_die);
11654 add_arange (decl, subr_die);
11657 { /* Do nothing for now; maybe need to duplicate die, one for
11658 hot section and ond for cold section, then use the hot/cold
11659 section begin/end labels to generate the aranges... */
11661 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
11662 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
11663 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
11664 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
11666 add_pubname (decl, subr_die);
11667 add_arange (decl, subr_die);
11668 add_arange (decl, subr_die);
11672 #ifdef MIPS_DEBUGGING_INFO
11673 /* Add a reference to the FDE for this routine. */
11674 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
11677 #ifdef DWARF2_UNWIND_INFO
11678 /* We define the "frame base" as the function's CFA. This is more
11679 convenient for several reasons: (1) It's stable across the prologue
11680 and epilogue, which makes it better than just a frame pointer,
11681 (2) With dwarf3, there exists a one-byte encoding that allows us
11682 to reference the .debug_frame data by proxy, but failing that,
11683 (3) We can at least reuse the code inspection and interpretation
11684 code that determines the CFA position at various points in the
11686 /* ??? Use some command-line or configury switch to enable the use
11687 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
11688 consumers that understand it; fall back to "pure" dwarf2 and
11689 convert the CFA data into a location list. */
11691 dw_loc_list_ref list = convert_cfa_to_loc_list ();
11692 if (list->dw_loc_next)
11693 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
11695 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
11698 /* Compute a displacement from the "steady-state frame pointer" to
11699 the CFA. The former is what all stack slots and argument slots
11700 will reference in the rtl; the later is what we've told the
11701 debugger about. We'll need to adjust all frame_base references
11702 by this displacement. */
11703 compute_frame_pointer_to_cfa_displacement ();
11705 /* For targets which support DWARF2, but not DWARF2 call-frame info,
11706 we just use the stack pointer or frame pointer. */
11707 /* ??? Should investigate getting better info via callbacks, or else
11708 by interpreting the IA-64 unwind info. */
11711 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
11712 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
11716 if (cfun->static_chain_decl)
11717 add_AT_location_description (subr_die, DW_AT_static_link,
11718 loc_descriptor_from_tree (cfun->static_chain_decl));
11721 /* Now output descriptions of the arguments for this function. This gets
11722 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
11723 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
11724 `...' at the end of the formal parameter list. In order to find out if
11725 there was a trailing ellipsis or not, we must instead look at the type
11726 associated with the FUNCTION_DECL. This will be a node of type
11727 FUNCTION_TYPE. If the chain of type nodes hanging off of this
11728 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
11729 an ellipsis at the end. */
11731 /* In the case where we are describing a mere function declaration, all we
11732 need to do here (and all we *can* do here) is to describe the *types* of
11733 its formal parameters. */
11734 if (debug_info_level <= DINFO_LEVEL_TERSE)
11736 else if (declaration)
11737 gen_formal_types_die (decl, subr_die);
11740 /* Generate DIEs to represent all known formal parameters. */
11741 tree arg_decls = DECL_ARGUMENTS (decl);
11744 /* When generating DIEs, generate the unspecified_parameters DIE
11745 instead if we come across the arg "__builtin_va_alist" */
11746 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
11747 if (TREE_CODE (parm) == PARM_DECL)
11749 if (DECL_NAME (parm)
11750 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
11751 "__builtin_va_alist"))
11752 gen_unspecified_parameters_die (parm, subr_die);
11754 gen_decl_die (parm, subr_die);
11757 /* Decide whether we need an unspecified_parameters DIE at the end.
11758 There are 2 more cases to do this for: 1) the ansi ... declaration -
11759 this is detectable when the end of the arg list is not a
11760 void_type_node 2) an unprototyped function declaration (not a
11761 definition). This just means that we have no info about the
11762 parameters at all. */
11763 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
11764 if (fn_arg_types != NULL)
11766 /* This is the prototyped case, check for.... */
11767 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
11768 gen_unspecified_parameters_die (decl, subr_die);
11770 else if (DECL_INITIAL (decl) == NULL_TREE)
11771 gen_unspecified_parameters_die (decl, subr_die);
11774 /* Output Dwarf info for all of the stuff within the body of the function
11775 (if it has one - it may be just a declaration). */
11776 outer_scope = DECL_INITIAL (decl);
11778 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
11779 a function. This BLOCK actually represents the outermost binding contour
11780 for the function, i.e. the contour in which the function's formal
11781 parameters and labels get declared. Curiously, it appears that the front
11782 end doesn't actually put the PARM_DECL nodes for the current function onto
11783 the BLOCK_VARS list for this outer scope, but are strung off of the
11784 DECL_ARGUMENTS list for the function instead.
11786 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
11787 the LABEL_DECL nodes for the function however, and we output DWARF info
11788 for those in decls_for_scope. Just within the `outer_scope' there will be
11789 a BLOCK node representing the function's outermost pair of curly braces,
11790 and any blocks used for the base and member initializers of a C++
11791 constructor function. */
11792 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
11794 /* Emit a DW_TAG_variable DIE for a named return value. */
11795 if (DECL_NAME (DECL_RESULT (decl)))
11796 gen_decl_die (DECL_RESULT (decl), subr_die);
11798 current_function_has_inlines = 0;
11799 decls_for_scope (outer_scope, subr_die, 0);
11801 #if 0 && defined (MIPS_DEBUGGING_INFO)
11802 if (current_function_has_inlines)
11804 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
11805 if (! comp_unit_has_inlines)
11807 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
11808 comp_unit_has_inlines = 1;
11813 /* Add the calling convention attribute if requested. */
11814 add_calling_convention_attribute (subr_die, TREE_TYPE (decl));
11818 /* Generate a DIE to represent a declared data object. */
11821 gen_variable_die (tree decl, dw_die_ref context_die)
11823 tree origin = decl_ultimate_origin (decl);
11824 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
11826 dw_die_ref old_die = lookup_decl_die (decl);
11827 int declaration = (DECL_EXTERNAL (decl)
11828 /* If DECL is COMDAT and has not actually been
11829 emitted, we cannot take its address; there
11830 might end up being no definition anywhere in
11831 the program. For example, consider the C++
11835 struct S { static const int i = 7; };
11840 int f() { return S<int>::i; }
11842 Here, S<int>::i is not DECL_EXTERNAL, but no
11843 definition is required, so the compiler will
11844 not emit a definition. */
11845 || (TREE_CODE (decl) == VAR_DECL
11846 && DECL_COMDAT (decl) && !TREE_ASM_WRITTEN (decl))
11847 || class_or_namespace_scope_p (context_die));
11849 if (origin != NULL)
11850 add_abstract_origin_attribute (var_die, origin);
11852 /* Loop unrolling can create multiple blocks that refer to the same
11853 static variable, so we must test for the DW_AT_declaration flag.
11855 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
11856 copy decls and set the DECL_ABSTRACT flag on them instead of
11859 ??? Duplicated blocks have been rewritten to use .debug_ranges.
11861 ??? The declare_in_namespace support causes us to get two DIEs for one
11862 variable, both of which are declarations. We want to avoid considering
11863 one to be a specification, so we must test that this DIE is not a
11865 else if (old_die && TREE_STATIC (decl) && ! declaration
11866 && get_AT_flag (old_die, DW_AT_declaration) == 1)
11868 /* This is a definition of a C++ class level static. */
11869 add_AT_specification (var_die, old_die);
11870 if (DECL_NAME (decl))
11872 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11873 unsigned file_index = lookup_filename (s.file);
11875 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
11876 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
11878 if (get_AT_unsigned (old_die, DW_AT_decl_line)
11879 != (unsigned) s.line)
11881 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
11886 add_name_and_src_coords_attributes (var_die, decl);
11887 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
11888 TREE_THIS_VOLATILE (decl), context_die);
11890 if (TREE_PUBLIC (decl))
11891 add_AT_flag (var_die, DW_AT_external, 1);
11893 if (DECL_ARTIFICIAL (decl))
11894 add_AT_flag (var_die, DW_AT_artificial, 1);
11896 if (TREE_PROTECTED (decl))
11897 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
11898 else if (TREE_PRIVATE (decl))
11899 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
11903 add_AT_flag (var_die, DW_AT_declaration, 1);
11905 if (DECL_ABSTRACT (decl) || declaration)
11906 equate_decl_number_to_die (decl, var_die);
11908 if (! declaration && ! DECL_ABSTRACT (decl))
11910 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
11911 add_pubname (decl, var_die);
11914 tree_add_const_value_attribute (var_die, decl);
11917 /* Generate a DIE to represent a label identifier. */
11920 gen_label_die (tree decl, dw_die_ref context_die)
11922 tree origin = decl_ultimate_origin (decl);
11923 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
11925 char label[MAX_ARTIFICIAL_LABEL_BYTES];
11927 if (origin != NULL)
11928 add_abstract_origin_attribute (lbl_die, origin);
11930 add_name_and_src_coords_attributes (lbl_die, decl);
11932 if (DECL_ABSTRACT (decl))
11933 equate_decl_number_to_die (decl, lbl_die);
11936 insn = DECL_RTL_IF_SET (decl);
11938 /* Deleted labels are programmer specified labels which have been
11939 eliminated because of various optimizations. We still emit them
11940 here so that it is possible to put breakpoints on them. */
11944 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))))
11946 /* When optimization is enabled (via -O) some parts of the compiler
11947 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
11948 represent source-level labels which were explicitly declared by
11949 the user. This really shouldn't be happening though, so catch
11950 it if it ever does happen. */
11951 gcc_assert (!INSN_DELETED_P (insn));
11953 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
11954 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
11959 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
11960 attributes to the DIE for a block STMT, to describe where the inlined
11961 function was called from. This is similar to add_src_coords_attributes. */
11964 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
11966 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
11967 unsigned file_index = lookup_filename (s.file);
11969 add_AT_unsigned (die, DW_AT_call_file, file_index);
11970 add_AT_unsigned (die, DW_AT_call_line, s.line);
11973 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
11974 Add low_pc and high_pc attributes to the DIE for a block STMT. */
11977 add_high_low_attributes (tree stmt, dw_die_ref die)
11979 char label[MAX_ARTIFICIAL_LABEL_BYTES];
11981 if (BLOCK_FRAGMENT_CHAIN (stmt))
11985 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
11987 chain = BLOCK_FRAGMENT_CHAIN (stmt);
11990 add_ranges (chain);
11991 chain = BLOCK_FRAGMENT_CHAIN (chain);
11998 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
11999 BLOCK_NUMBER (stmt));
12000 add_AT_lbl_id (die, DW_AT_low_pc, label);
12001 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
12002 BLOCK_NUMBER (stmt));
12003 add_AT_lbl_id (die, DW_AT_high_pc, label);
12007 /* Generate a DIE for a lexical block. */
12010 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
12012 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
12014 if (! BLOCK_ABSTRACT (stmt))
12015 add_high_low_attributes (stmt, stmt_die);
12017 decls_for_scope (stmt, stmt_die, depth);
12020 /* Generate a DIE for an inlined subprogram. */
12023 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
12025 tree decl = block_ultimate_origin (stmt);
12027 /* Emit info for the abstract instance first, if we haven't yet. We
12028 must emit this even if the block is abstract, otherwise when we
12029 emit the block below (or elsewhere), we may end up trying to emit
12030 a die whose origin die hasn't been emitted, and crashing. */
12031 dwarf2out_abstract_function (decl);
12033 if (! BLOCK_ABSTRACT (stmt))
12035 dw_die_ref subr_die
12036 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
12038 add_abstract_origin_attribute (subr_die, decl);
12039 add_high_low_attributes (stmt, subr_die);
12040 add_call_src_coords_attributes (stmt, subr_die);
12042 decls_for_scope (stmt, subr_die, depth);
12043 current_function_has_inlines = 1;
12046 /* We may get here if we're the outer block of function A that was
12047 inlined into function B that was inlined into function C. When
12048 generating debugging info for C, dwarf2out_abstract_function(B)
12049 would mark all inlined blocks as abstract, including this one.
12050 So, we wouldn't (and shouldn't) expect labels to be generated
12051 for this one. Instead, just emit debugging info for
12052 declarations within the block. This is particularly important
12053 in the case of initializers of arguments passed from B to us:
12054 if they're statement expressions containing declarations, we
12055 wouldn't generate dies for their abstract variables, and then,
12056 when generating dies for the real variables, we'd die (pun
12058 gen_lexical_block_die (stmt, context_die, depth);
12061 /* Generate a DIE for a field in a record, or structure. */
12064 gen_field_die (tree decl, dw_die_ref context_die)
12066 dw_die_ref decl_die;
12068 if (TREE_TYPE (decl) == error_mark_node)
12071 decl_die = new_die (DW_TAG_member, context_die, decl);
12072 add_name_and_src_coords_attributes (decl_die, decl);
12073 add_type_attribute (decl_die, member_declared_type (decl),
12074 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
12077 if (DECL_BIT_FIELD_TYPE (decl))
12079 add_byte_size_attribute (decl_die, decl);
12080 add_bit_size_attribute (decl_die, decl);
12081 add_bit_offset_attribute (decl_die, decl);
12084 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
12085 add_data_member_location_attribute (decl_die, decl);
12087 if (DECL_ARTIFICIAL (decl))
12088 add_AT_flag (decl_die, DW_AT_artificial, 1);
12090 if (TREE_PROTECTED (decl))
12091 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
12092 else if (TREE_PRIVATE (decl))
12093 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
12095 /* Equate decl number to die, so that we can look up this decl later on. */
12096 equate_decl_number_to_die (decl, decl_die);
12100 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12101 Use modified_type_die instead.
12102 We keep this code here just in case these types of DIEs may be needed to
12103 represent certain things in other languages (e.g. Pascal) someday. */
12106 gen_pointer_type_die (tree type, dw_die_ref context_die)
12109 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
12111 equate_type_number_to_die (type, ptr_die);
12112 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
12113 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
12116 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12117 Use modified_type_die instead.
12118 We keep this code here just in case these types of DIEs may be needed to
12119 represent certain things in other languages (e.g. Pascal) someday. */
12122 gen_reference_type_die (tree type, dw_die_ref context_die)
12125 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
12127 equate_type_number_to_die (type, ref_die);
12128 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
12129 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
12133 /* Generate a DIE for a pointer to a member type. */
12136 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
12139 = new_die (DW_TAG_ptr_to_member_type,
12140 scope_die_for (type, context_die), type);
12142 equate_type_number_to_die (type, ptr_die);
12143 add_AT_die_ref (ptr_die, DW_AT_containing_type,
12144 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
12145 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
12148 /* Generate the DIE for the compilation unit. */
12151 gen_compile_unit_die (const char *filename)
12154 char producer[250];
12155 const char *language_string = lang_hooks.name;
12158 die = new_die (DW_TAG_compile_unit, NULL, NULL);
12162 add_name_attribute (die, filename);
12163 /* Don't add cwd for <built-in>. */
12164 if (filename[0] != DIR_SEPARATOR && filename[0] != '<')
12165 add_comp_dir_attribute (die);
12168 sprintf (producer, "%s %s", language_string, version_string);
12170 #ifdef MIPS_DEBUGGING_INFO
12171 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
12172 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
12173 not appear in the producer string, the debugger reaches the conclusion
12174 that the object file is stripped and has no debugging information.
12175 To get the MIPS/SGI debugger to believe that there is debugging
12176 information in the object file, we add a -g to the producer string. */
12177 if (debug_info_level > DINFO_LEVEL_TERSE)
12178 strcat (producer, " -g");
12181 add_AT_string (die, DW_AT_producer, producer);
12183 if (strcmp (language_string, "GNU C++") == 0)
12184 language = DW_LANG_C_plus_plus;
12185 else if (strcmp (language_string, "GNU Ada") == 0)
12186 language = DW_LANG_Ada95;
12187 else if (strcmp (language_string, "GNU F77") == 0)
12188 language = DW_LANG_Fortran77;
12189 else if (strcmp (language_string, "GNU F95") == 0)
12190 language = DW_LANG_Fortran95;
12191 else if (strcmp (language_string, "GNU Pascal") == 0)
12192 language = DW_LANG_Pascal83;
12193 else if (strcmp (language_string, "GNU Java") == 0)
12194 language = DW_LANG_Java;
12196 language = DW_LANG_C89;
12198 add_AT_unsigned (die, DW_AT_language, language);
12202 /* Generate a DIE for a string type. */
12205 gen_string_type_die (tree type, dw_die_ref context_die)
12207 dw_die_ref type_die
12208 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
12210 equate_type_number_to_die (type, type_die);
12212 /* ??? Fudge the string length attribute for now.
12213 TODO: add string length info. */
12215 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
12216 bound_representation (upper_bound, 0, 'u');
12220 /* Generate the DIE for a base class. */
12223 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
12225 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
12227 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
12228 add_data_member_location_attribute (die, binfo);
12230 if (BINFO_VIRTUAL_P (binfo))
12231 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
12233 if (access == access_public_node)
12234 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
12235 else if (access == access_protected_node)
12236 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
12239 /* Generate a DIE for a class member. */
12242 gen_member_die (tree type, dw_die_ref context_die)
12245 tree binfo = TYPE_BINFO (type);
12248 /* If this is not an incomplete type, output descriptions of each of its
12249 members. Note that as we output the DIEs necessary to represent the
12250 members of this record or union type, we will also be trying to output
12251 DIEs to represent the *types* of those members. However the `type'
12252 function (above) will specifically avoid generating type DIEs for member
12253 types *within* the list of member DIEs for this (containing) type except
12254 for those types (of members) which are explicitly marked as also being
12255 members of this (containing) type themselves. The g++ front- end can
12256 force any given type to be treated as a member of some other (containing)
12257 type by setting the TYPE_CONTEXT of the given (member) type to point to
12258 the TREE node representing the appropriate (containing) type. */
12260 /* First output info about the base classes. */
12263 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
12267 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
12268 gen_inheritance_die (base,
12269 (accesses ? VEC_index (tree, accesses, i)
12270 : access_public_node), context_die);
12273 /* Now output info about the data members and type members. */
12274 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
12276 /* If we thought we were generating minimal debug info for TYPE
12277 and then changed our minds, some of the member declarations
12278 may have already been defined. Don't define them again, but
12279 do put them in the right order. */
12281 child = lookup_decl_die (member);
12283 splice_child_die (context_die, child);
12285 gen_decl_die (member, context_die);
12288 /* Now output info about the function members (if any). */
12289 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
12291 /* Don't include clones in the member list. */
12292 if (DECL_ABSTRACT_ORIGIN (member))
12295 child = lookup_decl_die (member);
12297 splice_child_die (context_die, child);
12299 gen_decl_die (member, context_die);
12303 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
12304 is set, we pretend that the type was never defined, so we only get the
12305 member DIEs needed by later specification DIEs. */
12308 gen_struct_or_union_type_die (tree type, dw_die_ref context_die)
12310 dw_die_ref type_die = lookup_type_die (type);
12311 dw_die_ref scope_die = 0;
12313 int complete = (TYPE_SIZE (type)
12314 && (! TYPE_STUB_DECL (type)
12315 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
12316 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
12318 if (type_die && ! complete)
12321 if (TYPE_CONTEXT (type) != NULL_TREE
12322 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
12323 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
12326 scope_die = scope_die_for (type, context_die);
12328 if (! type_die || (nested && scope_die == comp_unit_die))
12329 /* First occurrence of type or toplevel definition of nested class. */
12331 dw_die_ref old_die = type_die;
12333 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
12334 ? DW_TAG_structure_type : DW_TAG_union_type,
12336 equate_type_number_to_die (type, type_die);
12338 add_AT_specification (type_die, old_die);
12340 add_name_attribute (type_die, type_tag (type));
12343 remove_AT (type_die, DW_AT_declaration);
12345 /* If this type has been completed, then give it a byte_size attribute and
12346 then give a list of members. */
12347 if (complete && !ns_decl)
12349 /* Prevent infinite recursion in cases where the type of some member of
12350 this type is expressed in terms of this type itself. */
12351 TREE_ASM_WRITTEN (type) = 1;
12352 add_byte_size_attribute (type_die, type);
12353 if (TYPE_STUB_DECL (type) != NULL_TREE)
12354 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
12356 /* If the first reference to this type was as the return type of an
12357 inline function, then it may not have a parent. Fix this now. */
12358 if (type_die->die_parent == NULL)
12359 add_child_die (scope_die, type_die);
12361 push_decl_scope (type);
12362 gen_member_die (type, type_die);
12365 /* GNU extension: Record what type our vtable lives in. */
12366 if (TYPE_VFIELD (type))
12368 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
12370 gen_type_die (vtype, context_die);
12371 add_AT_die_ref (type_die, DW_AT_containing_type,
12372 lookup_type_die (vtype));
12377 add_AT_flag (type_die, DW_AT_declaration, 1);
12379 /* We don't need to do this for function-local types. */
12380 if (TYPE_STUB_DECL (type)
12381 && ! decl_function_context (TYPE_STUB_DECL (type)))
12382 VEC_safe_push (tree, gc, incomplete_types, type);
12386 /* Generate a DIE for a subroutine _type_. */
12389 gen_subroutine_type_die (tree type, dw_die_ref context_die)
12391 tree return_type = TREE_TYPE (type);
12392 dw_die_ref subr_die
12393 = new_die (DW_TAG_subroutine_type,
12394 scope_die_for (type, context_die), type);
12396 equate_type_number_to_die (type, subr_die);
12397 add_prototyped_attribute (subr_die, type);
12398 add_type_attribute (subr_die, return_type, 0, 0, context_die);
12399 gen_formal_types_die (type, subr_die);
12402 /* Generate a DIE for a type definition. */
12405 gen_typedef_die (tree decl, dw_die_ref context_die)
12407 dw_die_ref type_die;
12410 if (TREE_ASM_WRITTEN (decl))
12413 TREE_ASM_WRITTEN (decl) = 1;
12414 type_die = new_die (DW_TAG_typedef, context_die, decl);
12415 origin = decl_ultimate_origin (decl);
12416 if (origin != NULL)
12417 add_abstract_origin_attribute (type_die, origin);
12422 add_name_and_src_coords_attributes (type_die, decl);
12423 if (DECL_ORIGINAL_TYPE (decl))
12425 type = DECL_ORIGINAL_TYPE (decl);
12427 gcc_assert (type != TREE_TYPE (decl));
12428 equate_type_number_to_die (TREE_TYPE (decl), type_die);
12431 type = TREE_TYPE (decl);
12433 add_type_attribute (type_die, type, TREE_READONLY (decl),
12434 TREE_THIS_VOLATILE (decl), context_die);
12437 if (DECL_ABSTRACT (decl))
12438 equate_decl_number_to_die (decl, type_die);
12441 /* Generate a type description DIE. */
12444 gen_type_die (tree type, dw_die_ref context_die)
12448 if (type == NULL_TREE || type == error_mark_node)
12451 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12452 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
12454 if (TREE_ASM_WRITTEN (type))
12457 /* Prevent broken recursion; we can't hand off to the same type. */
12458 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
12460 TREE_ASM_WRITTEN (type) = 1;
12461 gen_decl_die (TYPE_NAME (type), context_die);
12465 /* We are going to output a DIE to represent the unqualified version
12466 of this type (i.e. without any const or volatile qualifiers) so
12467 get the main variant (i.e. the unqualified version) of this type
12468 now. (Vectors are special because the debugging info is in the
12469 cloned type itself). */
12470 if (TREE_CODE (type) != VECTOR_TYPE)
12471 type = type_main_variant (type);
12473 if (TREE_ASM_WRITTEN (type))
12476 switch (TREE_CODE (type))
12482 case REFERENCE_TYPE:
12483 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
12484 ensures that the gen_type_die recursion will terminate even if the
12485 type is recursive. Recursive types are possible in Ada. */
12486 /* ??? We could perhaps do this for all types before the switch
12488 TREE_ASM_WRITTEN (type) = 1;
12490 /* For these types, all that is required is that we output a DIE (or a
12491 set of DIEs) to represent the "basis" type. */
12492 gen_type_die (TREE_TYPE (type), context_die);
12496 /* This code is used for C++ pointer-to-data-member types.
12497 Output a description of the relevant class type. */
12498 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
12500 /* Output a description of the type of the object pointed to. */
12501 gen_type_die (TREE_TYPE (type), context_die);
12503 /* Now output a DIE to represent this pointer-to-data-member type
12505 gen_ptr_to_mbr_type_die (type, context_die);
12508 case FUNCTION_TYPE:
12509 /* Force out return type (in case it wasn't forced out already). */
12510 gen_type_die (TREE_TYPE (type), context_die);
12511 gen_subroutine_type_die (type, context_die);
12515 /* Force out return type (in case it wasn't forced out already). */
12516 gen_type_die (TREE_TYPE (type), context_die);
12517 gen_subroutine_type_die (type, context_die);
12521 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
12523 gen_type_die (TREE_TYPE (type), context_die);
12524 gen_string_type_die (type, context_die);
12527 gen_array_type_die (type, context_die);
12531 gen_array_type_die (type, context_die);
12534 case ENUMERAL_TYPE:
12537 case QUAL_UNION_TYPE:
12538 /* If this is a nested type whose containing class hasn't been written
12539 out yet, writing it out will cover this one, too. This does not apply
12540 to instantiations of member class templates; they need to be added to
12541 the containing class as they are generated. FIXME: This hurts the
12542 idea of combining type decls from multiple TUs, since we can't predict
12543 what set of template instantiations we'll get. */
12544 if (TYPE_CONTEXT (type)
12545 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
12546 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
12548 gen_type_die (TYPE_CONTEXT (type), context_die);
12550 if (TREE_ASM_WRITTEN (type))
12553 /* If that failed, attach ourselves to the stub. */
12554 push_decl_scope (TYPE_CONTEXT (type));
12555 context_die = lookup_type_die (TYPE_CONTEXT (type));
12560 declare_in_namespace (type, context_die);
12564 if (TREE_CODE (type) == ENUMERAL_TYPE)
12565 gen_enumeration_type_die (type, context_die);
12567 gen_struct_or_union_type_die (type, context_die);
12572 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
12573 it up if it is ever completed. gen_*_type_die will set it for us
12574 when appropriate. */
12583 /* No DIEs needed for fundamental types. */
12587 /* No Dwarf representation currently defined. */
12591 gcc_unreachable ();
12594 TREE_ASM_WRITTEN (type) = 1;
12597 /* Generate a DIE for a tagged type instantiation. */
12600 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
12602 if (type == NULL_TREE || type == error_mark_node)
12605 /* We are going to output a DIE to represent the unqualified version of
12606 this type (i.e. without any const or volatile qualifiers) so make sure
12607 that we have the main variant (i.e. the unqualified version) of this
12609 gcc_assert (type == type_main_variant (type));
12611 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
12612 an instance of an unresolved type. */
12614 switch (TREE_CODE (type))
12619 case ENUMERAL_TYPE:
12620 gen_inlined_enumeration_type_die (type, context_die);
12624 gen_inlined_structure_type_die (type, context_die);
12628 case QUAL_UNION_TYPE:
12629 gen_inlined_union_type_die (type, context_die);
12633 gcc_unreachable ();
12637 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
12638 things which are local to the given block. */
12641 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
12643 int must_output_die = 0;
12646 enum tree_code origin_code;
12648 /* Ignore blocks that are NULL. */
12649 if (stmt == NULL_TREE)
12652 /* If the block is one fragment of a non-contiguous block, do not
12653 process the variables, since they will have been done by the
12654 origin block. Do process subblocks. */
12655 if (BLOCK_FRAGMENT_ORIGIN (stmt))
12659 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
12660 gen_block_die (sub, context_die, depth + 1);
12665 /* Determine the "ultimate origin" of this block. This block may be an
12666 inlined instance of an inlined instance of inline function, so we have
12667 to trace all of the way back through the origin chain to find out what
12668 sort of node actually served as the original seed for the creation of
12669 the current block. */
12670 origin = block_ultimate_origin (stmt);
12671 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
12673 /* Determine if we need to output any Dwarf DIEs at all to represent this
12675 if (origin_code == FUNCTION_DECL)
12676 /* The outer scopes for inlinings *must* always be represented. We
12677 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
12678 must_output_die = 1;
12681 /* In the case where the current block represents an inlining of the
12682 "body block" of an inline function, we must *NOT* output any DIE for
12683 this block because we have already output a DIE to represent the whole
12684 inlined function scope and the "body block" of any function doesn't
12685 really represent a different scope according to ANSI C rules. So we
12686 check here to make sure that this block does not represent a "body
12687 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
12688 if (! is_body_block (origin ? origin : stmt))
12690 /* Determine if this block directly contains any "significant"
12691 local declarations which we will need to output DIEs for. */
12692 if (debug_info_level > DINFO_LEVEL_TERSE)
12693 /* We are not in terse mode so *any* local declaration counts
12694 as being a "significant" one. */
12695 must_output_die = (BLOCK_VARS (stmt) != NULL
12696 && (TREE_USED (stmt)
12697 || TREE_ASM_WRITTEN (stmt)
12698 || BLOCK_ABSTRACT (stmt)));
12700 /* We are in terse mode, so only local (nested) function
12701 definitions count as "significant" local declarations. */
12702 for (decl = BLOCK_VARS (stmt);
12703 decl != NULL; decl = TREE_CHAIN (decl))
12704 if (TREE_CODE (decl) == FUNCTION_DECL
12705 && DECL_INITIAL (decl))
12707 must_output_die = 1;
12713 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
12714 DIE for any block which contains no significant local declarations at
12715 all. Rather, in such cases we just call `decls_for_scope' so that any
12716 needed Dwarf info for any sub-blocks will get properly generated. Note
12717 that in terse mode, our definition of what constitutes a "significant"
12718 local declaration gets restricted to include only inlined function
12719 instances and local (nested) function definitions. */
12720 if (must_output_die)
12722 if (origin_code == FUNCTION_DECL)
12723 gen_inlined_subroutine_die (stmt, context_die, depth);
12725 gen_lexical_block_die (stmt, context_die, depth);
12728 decls_for_scope (stmt, context_die, depth);
12731 /* Generate all of the decls declared within a given scope and (recursively)
12732 all of its sub-blocks. */
12735 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
12740 /* Ignore NULL blocks. */
12741 if (stmt == NULL_TREE)
12744 if (TREE_USED (stmt))
12746 /* Output the DIEs to represent all of the data objects and typedefs
12747 declared directly within this block but not within any nested
12748 sub-blocks. Also, nested function and tag DIEs have been
12749 generated with a parent of NULL; fix that up now. */
12750 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
12754 if (TREE_CODE (decl) == FUNCTION_DECL)
12755 die = lookup_decl_die (decl);
12756 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
12757 die = lookup_type_die (TREE_TYPE (decl));
12761 if (die != NULL && die->die_parent == NULL)
12762 add_child_die (context_die, die);
12763 /* Do not produce debug information for static variables since
12764 these might be optimized out. We are called for these later
12765 in cgraph_varpool_analyze_pending_decls. */
12766 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
12769 gen_decl_die (decl, context_die);
12773 /* If we're at -g1, we're not interested in subblocks. */
12774 if (debug_info_level <= DINFO_LEVEL_TERSE)
12777 /* Output the DIEs to represent all sub-blocks (and the items declared
12778 therein) of this block. */
12779 for (subblocks = BLOCK_SUBBLOCKS (stmt);
12781 subblocks = BLOCK_CHAIN (subblocks))
12782 gen_block_die (subblocks, context_die, depth + 1);
12785 /* Is this a typedef we can avoid emitting? */
12788 is_redundant_typedef (tree decl)
12790 if (TYPE_DECL_IS_STUB (decl))
12793 if (DECL_ARTIFICIAL (decl)
12794 && DECL_CONTEXT (decl)
12795 && is_tagged_type (DECL_CONTEXT (decl))
12796 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
12797 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
12798 /* Also ignore the artificial member typedef for the class name. */
12804 /* Returns the DIE for decl. A DIE will always be returned. */
12807 force_decl_die (tree decl)
12809 dw_die_ref decl_die;
12810 unsigned saved_external_flag;
12811 tree save_fn = NULL_TREE;
12812 decl_die = lookup_decl_die (decl);
12815 dw_die_ref context_die;
12816 tree decl_context = DECL_CONTEXT (decl);
12819 /* Find die that represents this context. */
12820 if (TYPE_P (decl_context))
12821 context_die = force_type_die (decl_context);
12823 context_die = force_decl_die (decl_context);
12826 context_die = comp_unit_die;
12828 decl_die = lookup_decl_die (decl);
12832 switch (TREE_CODE (decl))
12834 case FUNCTION_DECL:
12835 /* Clear current_function_decl, so that gen_subprogram_die thinks
12836 that this is a declaration. At this point, we just want to force
12837 declaration die. */
12838 save_fn = current_function_decl;
12839 current_function_decl = NULL_TREE;
12840 gen_subprogram_die (decl, context_die);
12841 current_function_decl = save_fn;
12845 /* Set external flag to force declaration die. Restore it after
12846 gen_decl_die() call. */
12847 saved_external_flag = DECL_EXTERNAL (decl);
12848 DECL_EXTERNAL (decl) = 1;
12849 gen_decl_die (decl, context_die);
12850 DECL_EXTERNAL (decl) = saved_external_flag;
12853 case NAMESPACE_DECL:
12854 dwarf2out_decl (decl);
12858 gcc_unreachable ();
12861 /* We should be able to find the DIE now. */
12863 decl_die = lookup_decl_die (decl);
12864 gcc_assert (decl_die);
12870 /* Returns the DIE for TYPE. A DIE is always returned. */
12873 force_type_die (tree type)
12875 dw_die_ref type_die;
12877 type_die = lookup_type_die (type);
12880 dw_die_ref context_die;
12881 if (TYPE_CONTEXT (type))
12883 if (TYPE_P (TYPE_CONTEXT (type)))
12884 context_die = force_type_die (TYPE_CONTEXT (type));
12886 context_die = force_decl_die (TYPE_CONTEXT (type));
12889 context_die = comp_unit_die;
12891 type_die = lookup_type_die (type);
12894 gen_type_die (type, context_die);
12895 type_die = lookup_type_die (type);
12896 gcc_assert (type_die);
12901 /* Force out any required namespaces to be able to output DECL,
12902 and return the new context_die for it, if it's changed. */
12905 setup_namespace_context (tree thing, dw_die_ref context_die)
12907 tree context = (DECL_P (thing)
12908 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
12909 if (context && TREE_CODE (context) == NAMESPACE_DECL)
12910 /* Force out the namespace. */
12911 context_die = force_decl_die (context);
12913 return context_die;
12916 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
12917 type) within its namespace, if appropriate.
12919 For compatibility with older debuggers, namespace DIEs only contain
12920 declarations; all definitions are emitted at CU scope. */
12923 declare_in_namespace (tree thing, dw_die_ref context_die)
12925 dw_die_ref ns_context;
12927 if (debug_info_level <= DINFO_LEVEL_TERSE)
12930 /* If this decl is from an inlined function, then don't try to emit it in its
12931 namespace, as we will get confused. It would have already been emitted
12932 when the abstract instance of the inline function was emitted anyways. */
12933 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
12936 ns_context = setup_namespace_context (thing, context_die);
12938 if (ns_context != context_die)
12940 if (DECL_P (thing))
12941 gen_decl_die (thing, ns_context);
12943 gen_type_die (thing, ns_context);
12947 /* Generate a DIE for a namespace or namespace alias. */
12950 gen_namespace_die (tree decl)
12952 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
12954 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
12955 they are an alias of. */
12956 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
12958 /* Output a real namespace. */
12959 dw_die_ref namespace_die
12960 = new_die (DW_TAG_namespace, context_die, decl);
12961 add_name_and_src_coords_attributes (namespace_die, decl);
12962 equate_decl_number_to_die (decl, namespace_die);
12966 /* Output a namespace alias. */
12968 /* Force out the namespace we are an alias of, if necessary. */
12969 dw_die_ref origin_die
12970 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
12972 /* Now create the namespace alias DIE. */
12973 dw_die_ref namespace_die
12974 = new_die (DW_TAG_imported_declaration, context_die, decl);
12975 add_name_and_src_coords_attributes (namespace_die, decl);
12976 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
12977 equate_decl_number_to_die (decl, namespace_die);
12981 /* Generate Dwarf debug information for a decl described by DECL. */
12984 gen_decl_die (tree decl, dw_die_ref context_die)
12988 if (DECL_P (decl) && DECL_IGNORED_P (decl))
12991 switch (TREE_CODE (decl))
12997 /* The individual enumerators of an enum type get output when we output
12998 the Dwarf representation of the relevant enum type itself. */
13001 case FUNCTION_DECL:
13002 /* Don't output any DIEs to represent mere function declarations,
13003 unless they are class members or explicit block externs. */
13004 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
13005 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
13010 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
13011 on local redeclarations of global functions. That seems broken. */
13012 if (current_function_decl != decl)
13013 /* This is only a declaration. */;
13016 /* If we're emitting a clone, emit info for the abstract instance. */
13017 if (DECL_ORIGIN (decl) != decl)
13018 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
13020 /* If we're emitting an out-of-line copy of an inline function,
13021 emit info for the abstract instance and set up to refer to it. */
13022 else if (cgraph_function_possibly_inlined_p (decl)
13023 && ! DECL_ABSTRACT (decl)
13024 && ! class_or_namespace_scope_p (context_die)
13025 /* dwarf2out_abstract_function won't emit a die if this is just
13026 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
13027 that case, because that works only if we have a die. */
13028 && DECL_INITIAL (decl) != NULL_TREE)
13030 dwarf2out_abstract_function (decl);
13031 set_decl_origin_self (decl);
13034 /* Otherwise we're emitting the primary DIE for this decl. */
13035 else if (debug_info_level > DINFO_LEVEL_TERSE)
13037 /* Before we describe the FUNCTION_DECL itself, make sure that we
13038 have described its return type. */
13039 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
13041 /* And its virtual context. */
13042 if (DECL_VINDEX (decl) != NULL_TREE)
13043 gen_type_die (DECL_CONTEXT (decl), context_die);
13045 /* And its containing type. */
13046 origin = decl_class_context (decl);
13047 if (origin != NULL_TREE)
13048 gen_type_die_for_member (origin, decl, context_die);
13050 /* And its containing namespace. */
13051 declare_in_namespace (decl, context_die);
13054 /* Now output a DIE to represent the function itself. */
13055 gen_subprogram_die (decl, context_die);
13059 /* If we are in terse mode, don't generate any DIEs to represent any
13060 actual typedefs. */
13061 if (debug_info_level <= DINFO_LEVEL_TERSE)
13064 /* In the special case of a TYPE_DECL node representing the declaration
13065 of some type tag, if the given TYPE_DECL is marked as having been
13066 instantiated from some other (original) TYPE_DECL node (e.g. one which
13067 was generated within the original definition of an inline function) we
13068 have to generate a special (abbreviated) DW_TAG_structure_type,
13069 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
13070 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
13072 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
13076 if (is_redundant_typedef (decl))
13077 gen_type_die (TREE_TYPE (decl), context_die);
13079 /* Output a DIE to represent the typedef itself. */
13080 gen_typedef_die (decl, context_die);
13084 if (debug_info_level >= DINFO_LEVEL_NORMAL)
13085 gen_label_die (decl, context_die);
13090 /* If we are in terse mode, don't generate any DIEs to represent any
13091 variable declarations or definitions. */
13092 if (debug_info_level <= DINFO_LEVEL_TERSE)
13095 /* Output any DIEs that are needed to specify the type of this data
13097 gen_type_die (TREE_TYPE (decl), context_die);
13099 /* And its containing type. */
13100 origin = decl_class_context (decl);
13101 if (origin != NULL_TREE)
13102 gen_type_die_for_member (origin, decl, context_die);
13104 /* And its containing namespace. */
13105 declare_in_namespace (decl, context_die);
13107 /* Now output the DIE to represent the data object itself. This gets
13108 complicated because of the possibility that the VAR_DECL really
13109 represents an inlined instance of a formal parameter for an inline
13111 origin = decl_ultimate_origin (decl);
13112 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
13113 gen_formal_parameter_die (decl, context_die);
13115 gen_variable_die (decl, context_die);
13119 /* Ignore the nameless fields that are used to skip bits but handle C++
13120 anonymous unions and structs. */
13121 if (DECL_NAME (decl) != NULL_TREE
13122 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
13123 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
13125 gen_type_die (member_declared_type (decl), context_die);
13126 gen_field_die (decl, context_die);
13131 gen_type_die (TREE_TYPE (decl), context_die);
13132 gen_formal_parameter_die (decl, context_die);
13135 case NAMESPACE_DECL:
13136 gen_namespace_die (decl);
13140 /* Probably some frontend-internal decl. Assume we don't care. */
13141 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
13146 /* Add Ada "use" clause information for SGI Workshop debugger. */
13149 dwarf2out_add_library_unit_info (const char *filename, const char *context_list)
13151 unsigned int file_index;
13153 if (filename != NULL)
13155 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
13156 tree context_list_decl
13157 = build_decl (LABEL_DECL, get_identifier (context_list),
13160 TREE_PUBLIC (context_list_decl) = TRUE;
13161 add_name_attribute (unit_die, context_list);
13162 file_index = lookup_filename (filename);
13163 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
13164 add_pubname (context_list_decl, unit_die);
13168 /* Output debug information for global decl DECL. Called from toplev.c after
13169 compilation proper has finished. */
13172 dwarf2out_global_decl (tree decl)
13174 /* Output DWARF2 information for file-scope tentative data object
13175 declarations, file-scope (extern) function declarations (which had no
13176 corresponding body) and file-scope tagged type declarations and
13177 definitions which have not yet been forced out. */
13178 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
13179 dwarf2out_decl (decl);
13182 /* Output debug information for type decl DECL. Called from toplev.c
13183 and from language front ends (to record built-in types). */
13185 dwarf2out_type_decl (tree decl, int local)
13188 dwarf2out_decl (decl);
13191 /* Output debug information for imported module or decl. */
13194 dwarf2out_imported_module_or_decl (tree decl, tree context)
13196 dw_die_ref imported_die, at_import_die;
13197 dw_die_ref scope_die;
13198 unsigned file_index;
13199 expanded_location xloc;
13201 if (debug_info_level <= DINFO_LEVEL_TERSE)
13206 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
13207 We need decl DIE for reference and scope die. First, get DIE for the decl
13210 /* Get the scope die for decl context. Use comp_unit_die for global module
13211 or decl. If die is not found for non globals, force new die. */
13213 scope_die = comp_unit_die;
13214 else if (TYPE_P (context))
13215 scope_die = force_type_die (context);
13217 scope_die = force_decl_die (context);
13219 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
13220 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
13221 at_import_die = force_type_die (TREE_TYPE (decl));
13224 at_import_die = lookup_decl_die (decl);
13225 if (!at_import_die)
13227 /* If we're trying to avoid duplicate debug info, we may not have
13228 emitted the member decl for this field. Emit it now. */
13229 if (TREE_CODE (decl) == FIELD_DECL)
13231 tree type = DECL_CONTEXT (decl);
13232 dw_die_ref type_context_die;
13234 if (TYPE_CONTEXT (type))
13235 if (TYPE_P (TYPE_CONTEXT (type)))
13236 type_context_die = force_type_die (TYPE_CONTEXT (type));
13238 type_context_die = force_decl_die (TYPE_CONTEXT (type));
13240 type_context_die = comp_unit_die;
13241 gen_type_die_for_member (type, decl, type_context_die);
13243 at_import_die = force_decl_die (decl);
13247 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
13248 if (TREE_CODE (decl) == NAMESPACE_DECL)
13249 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
13251 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
13253 xloc = expand_location (input_location);
13254 file_index = lookup_filename (xloc.file);
13255 add_AT_unsigned (imported_die, DW_AT_decl_file, file_index);
13256 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
13257 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
13260 /* Write the debugging output for DECL. */
13263 dwarf2out_decl (tree decl)
13265 dw_die_ref context_die = comp_unit_die;
13267 switch (TREE_CODE (decl))
13272 case FUNCTION_DECL:
13273 /* What we would really like to do here is to filter out all mere
13274 file-scope declarations of file-scope functions which are never
13275 referenced later within this translation unit (and keep all of ones
13276 that *are* referenced later on) but we aren't clairvoyant, so we have
13277 no idea which functions will be referenced in the future (i.e. later
13278 on within the current translation unit). So here we just ignore all
13279 file-scope function declarations which are not also definitions. If
13280 and when the debugger needs to know something about these functions,
13281 it will have to hunt around and find the DWARF information associated
13282 with the definition of the function.
13284 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
13285 nodes represent definitions and which ones represent mere
13286 declarations. We have to check DECL_INITIAL instead. That's because
13287 the C front-end supports some weird semantics for "extern inline"
13288 function definitions. These can get inlined within the current
13289 translation unit (and thus, we need to generate Dwarf info for their
13290 abstract instances so that the Dwarf info for the concrete inlined
13291 instances can have something to refer to) but the compiler never
13292 generates any out-of-lines instances of such things (despite the fact
13293 that they *are* definitions).
13295 The important point is that the C front-end marks these "extern
13296 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
13297 them anyway. Note that the C++ front-end also plays some similar games
13298 for inline function definitions appearing within include files which
13299 also contain `#pragma interface' pragmas. */
13300 if (DECL_INITIAL (decl) == NULL_TREE)
13303 /* If we're a nested function, initially use a parent of NULL; if we're
13304 a plain function, this will be fixed up in decls_for_scope. If
13305 we're a method, it will be ignored, since we already have a DIE. */
13306 if (decl_function_context (decl)
13307 /* But if we're in terse mode, we don't care about scope. */
13308 && debug_info_level > DINFO_LEVEL_TERSE)
13309 context_die = NULL;
13313 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
13314 declaration and if the declaration was never even referenced from
13315 within this entire compilation unit. We suppress these DIEs in
13316 order to save space in the .debug section (by eliminating entries
13317 which are probably useless). Note that we must not suppress
13318 block-local extern declarations (whether used or not) because that
13319 would screw-up the debugger's name lookup mechanism and cause it to
13320 miss things which really ought to be in scope at a given point. */
13321 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
13324 /* For local statics lookup proper context die. */
13325 if (TREE_STATIC (decl) && decl_function_context (decl))
13326 context_die = lookup_decl_die (DECL_CONTEXT (decl));
13328 /* If we are in terse mode, don't generate any DIEs to represent any
13329 variable declarations or definitions. */
13330 if (debug_info_level <= DINFO_LEVEL_TERSE)
13334 case NAMESPACE_DECL:
13335 if (debug_info_level <= DINFO_LEVEL_TERSE)
13337 if (lookup_decl_die (decl) != NULL)
13342 /* Don't emit stubs for types unless they are needed by other DIEs. */
13343 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
13346 /* Don't bother trying to generate any DIEs to represent any of the
13347 normal built-in types for the language we are compiling. */
13348 if (DECL_IS_BUILTIN (decl))
13350 /* OK, we need to generate one for `bool' so GDB knows what type
13351 comparisons have. */
13352 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
13353 == DW_LANG_C_plus_plus)
13354 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
13355 && ! DECL_IGNORED_P (decl))
13356 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
13361 /* If we are in terse mode, don't generate any DIEs for types. */
13362 if (debug_info_level <= DINFO_LEVEL_TERSE)
13365 /* If we're a function-scope tag, initially use a parent of NULL;
13366 this will be fixed up in decls_for_scope. */
13367 if (decl_function_context (decl))
13368 context_die = NULL;
13376 gen_decl_die (decl, context_die);
13379 /* Output a marker (i.e. a label) for the beginning of the generated code for
13380 a lexical block. */
13383 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
13384 unsigned int blocknum)
13386 current_function_section (current_function_decl);
13387 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
13390 /* Output a marker (i.e. a label) for the end of the generated code for a
13394 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
13396 current_function_section (current_function_decl);
13397 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
13400 /* Returns nonzero if it is appropriate not to emit any debugging
13401 information for BLOCK, because it doesn't contain any instructions.
13403 Don't allow this for blocks with nested functions or local classes
13404 as we would end up with orphans, and in the presence of scheduling
13405 we may end up calling them anyway. */
13408 dwarf2out_ignore_block (tree block)
13412 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
13413 if (TREE_CODE (decl) == FUNCTION_DECL
13414 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
13420 /* Lookup FILE_NAME (in the list of filenames that we know about here in
13421 dwarf2out.c) and return its "index". The index of each (known) filename is
13422 just a unique number which is associated with only that one filename. We
13423 need such numbers for the sake of generating labels (in the .debug_sfnames
13424 section) and references to those files numbers (in the .debug_srcinfo
13425 and.debug_macinfo sections). If the filename given as an argument is not
13426 found in our current list, add it to the list and assign it the next
13427 available unique index number. In order to speed up searches, we remember
13428 the index of the filename was looked up last. This handles the majority of
13432 lookup_filename (const char *file_name)
13435 char *save_file_name;
13437 /* Check to see if the file name that was searched on the previous
13438 call matches this file name. If so, return the index. */
13439 if (file_table_last_lookup_index != 0)
13442 = VARRAY_CHAR_PTR (file_table, file_table_last_lookup_index);
13443 if (strcmp (file_name, last) == 0)
13444 return file_table_last_lookup_index;
13447 /* Didn't match the previous lookup, search the table. */
13448 n = VARRAY_ACTIVE_SIZE (file_table);
13449 for (i = 1; i < n; i++)
13450 if (strcmp (file_name, VARRAY_CHAR_PTR (file_table, i)) == 0)
13452 file_table_last_lookup_index = i;
13456 /* Add the new entry to the end of the filename table. */
13457 file_table_last_lookup_index = n;
13458 save_file_name = (char *) ggc_strdup (file_name);
13459 VARRAY_PUSH_CHAR_PTR (file_table, save_file_name);
13460 VARRAY_PUSH_UINT (file_table_emitted, 0);
13462 /* If the assembler is emitting the file table, and we aren't eliminating
13463 unused debug types, then we must emit .file here. If we are eliminating
13464 unused debug types, then this will be done by the maybe_emit_file call in
13465 prune_unused_types_walk_attribs. */
13467 if (DWARF2_ASM_LINE_DEBUG_INFO && ! flag_eliminate_unused_debug_types)
13468 return maybe_emit_file (i);
13473 /* If the assembler will construct the file table, then translate the compiler
13474 internal file table number into the assembler file table number, and emit
13475 a .file directive if we haven't already emitted one yet. The file table
13476 numbers are different because we prune debug info for unused variables and
13477 types, which may include filenames. */
13480 maybe_emit_file (int fileno)
13482 if (DWARF2_ASM_LINE_DEBUG_INFO && fileno > 0)
13484 if (!VARRAY_UINT (file_table_emitted, fileno))
13486 VARRAY_UINT (file_table_emitted, fileno) = ++emitcount;
13487 fprintf (asm_out_file, "\t.file %u ",
13488 VARRAY_UINT (file_table_emitted, fileno));
13489 output_quoted_string (asm_out_file,
13490 VARRAY_CHAR_PTR (file_table, fileno));
13491 fputc ('\n', asm_out_file);
13493 return VARRAY_UINT (file_table_emitted, fileno);
13499 /* Initialize the compiler internal file table. */
13502 init_file_table (void)
13504 /* Allocate the initial hunk of the file_table. */
13505 VARRAY_CHAR_PTR_INIT (file_table, 64, "file_table");
13506 VARRAY_UINT_INIT (file_table_emitted, 64, "file_table_emitted");
13508 /* Skip the first entry - file numbers begin at 1. */
13509 VARRAY_PUSH_CHAR_PTR (file_table, NULL);
13510 VARRAY_PUSH_UINT (file_table_emitted, 0);
13511 file_table_last_lookup_index = 0;
13514 /* Called by the final INSN scan whenever we see a var location. We
13515 use it to drop labels in the right places, and throw the location in
13516 our lookup table. */
13519 dwarf2out_var_location (rtx loc_note)
13521 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
13522 struct var_loc_node *newloc;
13524 static rtx last_insn;
13525 static const char *last_label;
13528 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
13530 prev_insn = PREV_INSN (loc_note);
13532 newloc = ggc_alloc_cleared (sizeof (struct var_loc_node));
13533 /* If the insn we processed last time is the previous insn
13534 and it is also a var location note, use the label we emitted
13536 if (last_insn != NULL_RTX
13537 && last_insn == prev_insn
13538 && NOTE_P (prev_insn)
13539 && NOTE_LINE_NUMBER (prev_insn) == NOTE_INSN_VAR_LOCATION)
13541 newloc->label = last_label;
13545 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
13546 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
13548 newloc->label = ggc_strdup (loclabel);
13550 newloc->var_loc_note = loc_note;
13551 newloc->next = NULL;
13554 && (last_text_section == in_unlikely_executed_text
13555 || (last_text_section == in_named
13556 && last_text_section_name == cfun->unlikely_text_section_name)))
13557 newloc->section_label = cfun->cold_section_label;
13559 newloc->section_label = text_section_label;
13561 last_insn = loc_note;
13562 last_label = newloc->label;
13563 decl = NOTE_VAR_LOCATION_DECL (loc_note);
13564 if (DECL_DEBUG_EXPR_IS_FROM (decl) && DECL_DEBUG_EXPR (decl)
13565 && DECL_P (DECL_DEBUG_EXPR (decl)))
13566 decl = DECL_DEBUG_EXPR (decl);
13567 add_var_loc_to_decl (decl, newloc);
13570 /* We need to reset the locations at the beginning of each
13571 function. We can't do this in the end_function hook, because the
13572 declarations that use the locations won't have been outputted when
13573 that hook is called. */
13576 dwarf2out_begin_function (tree unused ATTRIBUTE_UNUSED)
13578 htab_empty (decl_loc_table);
13581 /* Output a label to mark the beginning of a source code line entry
13582 and record information relating to this source line, in
13583 'line_info_table' for later output of the .debug_line section. */
13586 dwarf2out_source_line (unsigned int line, const char *filename)
13588 if (debug_info_level >= DINFO_LEVEL_NORMAL
13591 current_function_section (current_function_decl);
13593 /* If requested, emit something human-readable. */
13594 if (flag_debug_asm)
13595 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
13598 if (DWARF2_ASM_LINE_DEBUG_INFO)
13600 unsigned file_num = lookup_filename (filename);
13602 file_num = maybe_emit_file (file_num);
13604 /* Emit the .loc directive understood by GNU as. */
13605 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
13607 /* Indicate that line number info exists. */
13608 line_info_table_in_use++;
13610 /* Indicate that multiple line number tables exist. */
13611 if (DECL_SECTION_NAME (current_function_decl))
13612 separate_line_info_table_in_use++;
13614 else if (DECL_SECTION_NAME (current_function_decl))
13616 dw_separate_line_info_ref line_info;
13617 targetm.asm_out.internal_label (asm_out_file, SEPARATE_LINE_CODE_LABEL,
13618 separate_line_info_table_in_use);
13620 /* Expand the line info table if necessary. */
13621 if (separate_line_info_table_in_use
13622 == separate_line_info_table_allocated)
13624 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
13625 separate_line_info_table
13626 = ggc_realloc (separate_line_info_table,
13627 separate_line_info_table_allocated
13628 * sizeof (dw_separate_line_info_entry));
13629 memset (separate_line_info_table
13630 + separate_line_info_table_in_use,
13632 (LINE_INFO_TABLE_INCREMENT
13633 * sizeof (dw_separate_line_info_entry)));
13636 /* Add the new entry at the end of the line_info_table. */
13638 = &separate_line_info_table[separate_line_info_table_in_use++];
13639 line_info->dw_file_num = lookup_filename (filename);
13640 line_info->dw_line_num = line;
13641 line_info->function = current_function_funcdef_no;
13645 dw_line_info_ref line_info;
13647 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
13648 line_info_table_in_use);
13650 /* Expand the line info table if necessary. */
13651 if (line_info_table_in_use == line_info_table_allocated)
13653 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
13655 = ggc_realloc (line_info_table,
13656 (line_info_table_allocated
13657 * sizeof (dw_line_info_entry)));
13658 memset (line_info_table + line_info_table_in_use, 0,
13659 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
13662 /* Add the new entry at the end of the line_info_table. */
13663 line_info = &line_info_table[line_info_table_in_use++];
13664 line_info->dw_file_num = lookup_filename (filename);
13665 line_info->dw_line_num = line;
13670 /* Record the beginning of a new source file. */
13673 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
13675 if (flag_eliminate_dwarf2_dups)
13677 /* Record the beginning of the file for break_out_includes. */
13678 dw_die_ref bincl_die;
13680 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
13681 add_AT_string (bincl_die, DW_AT_name, filename);
13684 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13688 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13689 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
13690 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
13693 fileno = maybe_emit_file (lookup_filename (filename));
13694 dw2_asm_output_data_uleb128 (fileno, "Filename we just started");
13698 /* Record the end of a source file. */
13701 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
13703 if (flag_eliminate_dwarf2_dups)
13704 /* Record the end of the file for break_out_includes. */
13705 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
13707 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13709 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13710 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
13714 /* Called from debug_define in toplev.c. The `buffer' parameter contains
13715 the tail part of the directive line, i.e. the part which is past the
13716 initial whitespace, #, whitespace, directive-name, whitespace part. */
13719 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
13720 const char *buffer ATTRIBUTE_UNUSED)
13722 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13724 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13725 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
13726 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
13727 dw2_asm_output_nstring (buffer, -1, "The macro");
13731 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
13732 the tail part of the directive line, i.e. the part which is past the
13733 initial whitespace, #, whitespace, directive-name, whitespace part. */
13736 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
13737 const char *buffer ATTRIBUTE_UNUSED)
13739 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13741 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13742 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
13743 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
13744 dw2_asm_output_nstring (buffer, -1, "The macro");
13748 /* Set up for Dwarf output at the start of compilation. */
13751 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
13753 init_file_table ();
13755 /* Allocate the decl_die_table. */
13756 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
13757 decl_die_table_eq, NULL);
13759 /* Allocate the decl_loc_table. */
13760 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
13761 decl_loc_table_eq, NULL);
13763 /* Allocate the initial hunk of the decl_scope_table. */
13764 decl_scope_table = VEC_alloc (tree, gc, 256);
13766 /* Allocate the initial hunk of the abbrev_die_table. */
13767 abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
13768 * sizeof (dw_die_ref));
13769 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
13770 /* Zero-th entry is allocated, but unused. */
13771 abbrev_die_table_in_use = 1;
13773 /* Allocate the initial hunk of the line_info_table. */
13774 line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
13775 * sizeof (dw_line_info_entry));
13776 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
13778 /* Zero-th entry is allocated, but unused. */
13779 line_info_table_in_use = 1;
13781 /* Generate the initial DIE for the .debug section. Note that the (string)
13782 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
13783 will (typically) be a relative pathname and that this pathname should be
13784 taken as being relative to the directory from which the compiler was
13785 invoked when the given (base) source file was compiled. We will fill
13786 in this value in dwarf2out_finish. */
13787 comp_unit_die = gen_compile_unit_die (NULL);
13789 incomplete_types = VEC_alloc (tree, gc, 64);
13791 used_rtx_array = VEC_alloc (rtx, gc, 32);
13793 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
13794 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
13795 DEBUG_ABBREV_SECTION_LABEL, 0);
13796 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
13797 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
13798 COLD_TEXT_SECTION_LABEL, 0);
13799 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
13801 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
13802 DEBUG_INFO_SECTION_LABEL, 0);
13803 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
13804 DEBUG_LINE_SECTION_LABEL, 0);
13805 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
13806 DEBUG_RANGES_SECTION_LABEL, 0);
13807 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
13808 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
13809 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
13810 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
13811 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
13812 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
13814 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13816 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13817 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
13818 DEBUG_MACINFO_SECTION_LABEL, 0);
13819 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
13823 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
13824 if (flag_reorder_blocks_and_partition)
13826 unlikely_text_section ();
13827 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
13831 /* A helper function for dwarf2out_finish called through
13832 ht_forall. Emit one queued .debug_str string. */
13835 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
13837 struct indirect_string_node *node = (struct indirect_string_node *) *h;
13839 if (node->form == DW_FORM_strp)
13841 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
13842 ASM_OUTPUT_LABEL (asm_out_file, node->label);
13843 assemble_string (node->str, strlen (node->str) + 1);
13851 /* Clear the marks for a die and its children.
13852 Be cool if the mark isn't set. */
13855 prune_unmark_dies (dw_die_ref die)
13859 for (c = die->die_child; c; c = c->die_sib)
13860 prune_unmark_dies (c);
13864 /* Given DIE that we're marking as used, find any other dies
13865 it references as attributes and mark them as used. */
13868 prune_unused_types_walk_attribs (dw_die_ref die)
13872 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
13874 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
13876 /* A reference to another DIE.
13877 Make sure that it will get emitted. */
13878 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
13880 else if (a->dw_attr == DW_AT_decl_file || a->dw_attr == DW_AT_call_file)
13882 /* A reference to a file. Make sure the file name is emitted. */
13883 a->dw_attr_val.v.val_unsigned =
13884 maybe_emit_file (a->dw_attr_val.v.val_unsigned);
13890 /* Mark DIE as being used. If DOKIDS is true, then walk down
13891 to DIE's children. */
13894 prune_unused_types_mark (dw_die_ref die, int dokids)
13898 if (die->die_mark == 0)
13900 /* We haven't done this node yet. Mark it as used. */
13903 /* We also have to mark its parents as used.
13904 (But we don't want to mark our parents' kids due to this.) */
13905 if (die->die_parent)
13906 prune_unused_types_mark (die->die_parent, 0);
13908 /* Mark any referenced nodes. */
13909 prune_unused_types_walk_attribs (die);
13911 /* If this node is a specification,
13912 also mark the definition, if it exists. */
13913 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
13914 prune_unused_types_mark (die->die_definition, 1);
13917 if (dokids && die->die_mark != 2)
13919 /* We need to walk the children, but haven't done so yet.
13920 Remember that we've walked the kids. */
13924 for (c = die->die_child; c; c = c->die_sib)
13926 /* If this is an array type, we need to make sure our
13927 kids get marked, even if they're types. */
13928 if (die->die_tag == DW_TAG_array_type)
13929 prune_unused_types_mark (c, 1);
13931 prune_unused_types_walk (c);
13937 /* Walk the tree DIE and mark types that we actually use. */
13940 prune_unused_types_walk (dw_die_ref die)
13944 /* Don't do anything if this node is already marked. */
13948 switch (die->die_tag) {
13949 case DW_TAG_const_type:
13950 case DW_TAG_packed_type:
13951 case DW_TAG_pointer_type:
13952 case DW_TAG_reference_type:
13953 case DW_TAG_volatile_type:
13954 case DW_TAG_typedef:
13955 case DW_TAG_array_type:
13956 case DW_TAG_structure_type:
13957 case DW_TAG_union_type:
13958 case DW_TAG_class_type:
13959 case DW_TAG_friend:
13960 case DW_TAG_variant_part:
13961 case DW_TAG_enumeration_type:
13962 case DW_TAG_subroutine_type:
13963 case DW_TAG_string_type:
13964 case DW_TAG_set_type:
13965 case DW_TAG_subrange_type:
13966 case DW_TAG_ptr_to_member_type:
13967 case DW_TAG_file_type:
13968 /* It's a type node --- don't mark it. */
13972 /* Mark everything else. */
13978 /* Now, mark any dies referenced from here. */
13979 prune_unused_types_walk_attribs (die);
13981 /* Mark children. */
13982 for (c = die->die_child; c; c = c->die_sib)
13983 prune_unused_types_walk (c);
13987 /* Remove from the tree DIE any dies that aren't marked. */
13990 prune_unused_types_prune (dw_die_ref die)
13992 dw_die_ref c, p, n;
13994 gcc_assert (die->die_mark);
13997 for (c = die->die_child; c; c = n)
14002 prune_unused_types_prune (c);
14010 die->die_child = n;
14017 /* Remove dies representing declarations that we never use. */
14020 prune_unused_types (void)
14023 limbo_die_node *node;
14025 /* Clear all the marks. */
14026 prune_unmark_dies (comp_unit_die);
14027 for (node = limbo_die_list; node; node = node->next)
14028 prune_unmark_dies (node->die);
14030 /* Set the mark on nodes that are actually used. */
14031 prune_unused_types_walk (comp_unit_die);
14032 for (node = limbo_die_list; node; node = node->next)
14033 prune_unused_types_walk (node->die);
14035 /* Also set the mark on nodes referenced from the
14036 pubname_table or arange_table. */
14037 for (i = 0; i < pubname_table_in_use; i++)
14038 prune_unused_types_mark (pubname_table[i].die, 1);
14039 for (i = 0; i < arange_table_in_use; i++)
14040 prune_unused_types_mark (arange_table[i], 1);
14042 /* Get rid of nodes that aren't marked. */
14043 prune_unused_types_prune (comp_unit_die);
14044 for (node = limbo_die_list; node; node = node->next)
14045 prune_unused_types_prune (node->die);
14047 /* Leave the marks clear. */
14048 prune_unmark_dies (comp_unit_die);
14049 for (node = limbo_die_list; node; node = node->next)
14050 prune_unmark_dies (node->die);
14053 /* Output stuff that dwarf requires at the end of every file,
14054 and generate the DWARF-2 debugging info. */
14057 dwarf2out_finish (const char *filename)
14059 limbo_die_node *node, *next_node;
14060 dw_die_ref die = 0;
14062 /* Add the name for the main input file now. We delayed this from
14063 dwarf2out_init to avoid complications with PCH. */
14064 add_name_attribute (comp_unit_die, filename);
14065 if (filename[0] != DIR_SEPARATOR)
14066 add_comp_dir_attribute (comp_unit_die);
14067 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
14070 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
14071 if (VARRAY_CHAR_PTR (file_table, i)[0] != DIR_SEPARATOR
14072 /* Don't add cwd for <built-in>. */
14073 && VARRAY_CHAR_PTR (file_table, i)[0] != '<')
14075 add_comp_dir_attribute (comp_unit_die);
14080 /* Traverse the limbo die list, and add parent/child links. The only
14081 dies without parents that should be here are concrete instances of
14082 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
14083 For concrete instances, we can get the parent die from the abstract
14085 for (node = limbo_die_list; node; node = next_node)
14087 next_node = node->next;
14090 if (die->die_parent == NULL)
14092 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
14095 add_child_die (origin->die_parent, die);
14096 else if (die == comp_unit_die)
14098 else if (errorcount > 0 || sorrycount > 0)
14099 /* It's OK to be confused by errors in the input. */
14100 add_child_die (comp_unit_die, die);
14103 /* In certain situations, the lexical block containing a
14104 nested function can be optimized away, which results
14105 in the nested function die being orphaned. Likewise
14106 with the return type of that nested function. Force
14107 this to be a child of the containing function.
14109 It may happen that even the containing function got fully
14110 inlined and optimized out. In that case we are lost and
14111 assign the empty child. This should not be big issue as
14112 the function is likely unreachable too. */
14113 tree context = NULL_TREE;
14115 gcc_assert (node->created_for);
14117 if (DECL_P (node->created_for))
14118 context = DECL_CONTEXT (node->created_for);
14119 else if (TYPE_P (node->created_for))
14120 context = TYPE_CONTEXT (node->created_for);
14122 gcc_assert (context && TREE_CODE (context) == FUNCTION_DECL);
14124 origin = lookup_decl_die (context);
14126 add_child_die (origin, die);
14128 add_child_die (comp_unit_die, die);
14133 limbo_die_list = NULL;
14135 /* Walk through the list of incomplete types again, trying once more to
14136 emit full debugging info for them. */
14137 retry_incomplete_types ();
14139 /* We need to reverse all the dies before break_out_includes, or
14140 we'll see the end of an include file before the beginning. */
14141 reverse_all_dies (comp_unit_die);
14143 if (flag_eliminate_unused_debug_types)
14144 prune_unused_types ();
14146 /* Generate separate CUs for each of the include files we've seen.
14147 They will go into limbo_die_list. */
14148 if (flag_eliminate_dwarf2_dups)
14149 break_out_includes (comp_unit_die);
14151 /* Traverse the DIE's and add add sibling attributes to those DIE's
14152 that have children. */
14153 add_sibling_attributes (comp_unit_die);
14154 for (node = limbo_die_list; node; node = node->next)
14155 add_sibling_attributes (node->die);
14157 /* Output a terminator label for the .text section. */
14159 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
14160 if (flag_reorder_blocks_and_partition)
14162 unlikely_text_section ();
14163 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
14166 /* Output the source line correspondence table. We must do this
14167 even if there is no line information. Otherwise, on an empty
14168 translation unit, we will generate a present, but empty,
14169 .debug_info section. IRIX 6.5 `nm' will then complain when
14170 examining the file. */
14171 if (! DWARF2_ASM_LINE_DEBUG_INFO)
14173 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
14174 output_line_info ();
14177 /* Output location list section if necessary. */
14178 if (have_location_lists)
14180 /* Output the location lists info. */
14181 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
14182 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
14183 DEBUG_LOC_SECTION_LABEL, 0);
14184 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
14185 output_location_lists (die);
14186 have_location_lists = 0;
14189 /* We can only use the low/high_pc attributes if all of the code was
14191 if (!separate_line_info_table_in_use && !have_switched_text_section)
14193 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
14194 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
14197 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
14198 "base address". Use zero so that these addresses become absolute. */
14199 else if (have_location_lists || ranges_table_in_use)
14200 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
14202 if (debug_info_level >= DINFO_LEVEL_NORMAL)
14203 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
14204 debug_line_section_label);
14206 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14207 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
14209 /* Output all of the compilation units. We put the main one last so that
14210 the offsets are available to output_pubnames. */
14211 for (node = limbo_die_list; node; node = node->next)
14212 output_comp_unit (node->die, 0);
14214 output_comp_unit (comp_unit_die, 0);
14216 /* Output the abbreviation table. */
14217 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
14218 output_abbrev_section ();
14220 /* Output public names table if necessary. */
14221 if (pubname_table_in_use)
14223 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
14224 output_pubnames ();
14227 /* Output the address range information. We only put functions in the arange
14228 table, so don't write it out if we don't have any. */
14229 if (fde_table_in_use)
14231 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
14235 /* Output ranges section if necessary. */
14236 if (ranges_table_in_use)
14238 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
14239 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
14243 /* Have to end the macro section. */
14244 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14246 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
14247 dw2_asm_output_data (1, 0, "End compilation unit");
14250 /* If we emitted any DW_FORM_strp form attribute, output the string
14252 if (debug_str_hash)
14253 htab_traverse (debug_str_hash, output_indirect_string, NULL);
14257 /* This should never be used, but its address is needed for comparisons. */
14258 const struct gcc_debug_hooks dwarf2_debug_hooks;
14260 #endif /* DWARF2_DEBUGGING_INFO */
14262 #include "gt-dwarf2out.h"