* config/mips/elf.h (ASM_DECLARE_OBJECT_NAME): Use
[official-gcc.git] / gcc / dwarf2out.c
blob5ad605db8dd708492852bf14c98a5f14f9cb63a8
1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003 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
13 version.
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
18 for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 02111-1307, USA. */
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
35 information. */
37 #include "config.h"
38 #include "system.h"
39 #include "coretypes.h"
40 #include "tm.h"
41 #include "tree.h"
42 #include "flags.h"
43 #include "real.h"
44 #include "rtl.h"
45 #include "hard-reg-set.h"
46 #include "regs.h"
47 #include "insn-config.h"
48 #include "reload.h"
49 #include "function.h"
50 #include "output.h"
51 #include "expr.h"
52 #include "libfuncs.h"
53 #include "except.h"
54 #include "dwarf2.h"
55 #include "dwarf2out.h"
56 #include "dwarf2asm.h"
57 #include "toplev.h"
58 #include "varray.h"
59 #include "ggc.h"
60 #include "md5.h"
61 #include "tm_p.h"
62 #include "diagnostic.h"
63 #include "debug.h"
64 #include "target.h"
65 #include "langhooks.h"
66 #include "hashtab.h"
68 #ifdef DWARF2_DEBUGGING_INFO
69 static void dwarf2out_source_line (unsigned int, const char *);
70 #endif
72 /* DWARF2 Abbreviation Glossary:
73 CFA = Canonical Frame Address
74 a fixed address on the stack which identifies a call frame.
75 We define it to be the value of SP just before the call insn.
76 The CFA register and offset, which may change during the course
77 of the function, are used to calculate its value at runtime.
78 CFI = Call Frame Instruction
79 an instruction for the DWARF2 abstract machine
80 CIE = Common Information Entry
81 information describing information common to one or more FDEs
82 DIE = Debugging Information Entry
83 FDE = Frame Description Entry
84 information describing the stack call frame, in particular,
85 how to restore registers
87 DW_CFA_... = DWARF2 CFA call frame instruction
88 DW_TAG_... = DWARF2 DIE tag */
90 /* Decide whether we want to emit frame unwind information for the current
91 translation unit. */
93 int
94 dwarf2out_do_frame (void)
96 return (write_symbols == DWARF2_DEBUG
97 || write_symbols == VMS_AND_DWARF2_DEBUG
98 #ifdef DWARF2_FRAME_INFO
99 || DWARF2_FRAME_INFO
100 #endif
101 #ifdef DWARF2_UNWIND_INFO
102 || flag_unwind_tables
103 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
104 #endif
108 /* The size of the target's pointer type. */
109 #ifndef PTR_SIZE
110 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
111 #endif
113 /* Default version of targetm.eh_frame_section. Note this must appear
114 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
115 guards. */
117 void
118 default_eh_frame_section (void)
120 #ifdef EH_FRAME_SECTION_NAME
121 #ifdef HAVE_LD_RO_RW_SECTION_MIXING
122 int fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
123 int per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
124 int lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
125 int flags;
127 flags = (! flag_pic
128 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
129 && (fde_encoding & 0x70) != DW_EH_PE_aligned
130 && (per_encoding & 0x70) != DW_EH_PE_absptr
131 && (per_encoding & 0x70) != DW_EH_PE_aligned
132 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
133 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
134 ? 0 : SECTION_WRITE;
135 named_section_flags (EH_FRAME_SECTION_NAME, flags);
136 #else
137 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
138 #endif
139 #else
140 tree label = get_file_function_name ('F');
142 data_section ();
143 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
144 (*targetm.asm_out.globalize_label) (asm_out_file, IDENTIFIER_POINTER (label));
145 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
146 #endif
149 /* Array of RTXes referenced by the debugging information, which therefore
150 must be kept around forever. */
151 static GTY(()) varray_type used_rtx_varray;
153 /* A pointer to the base of a list of incomplete types which might be
154 completed at some later time. incomplete_types_list needs to be a VARRAY
155 because we want to tell the garbage collector about it. */
156 static GTY(()) varray_type incomplete_types;
158 /* A pointer to the base of a table of references to declaration
159 scopes. This table is a display which tracks the nesting
160 of declaration scopes at the current scope and containing
161 scopes. This table is used to find the proper place to
162 define type declaration DIE's. */
163 static GTY(()) varray_type decl_scope_table;
165 /* How to start an assembler comment. */
166 #ifndef ASM_COMMENT_START
167 #define ASM_COMMENT_START ";#"
168 #endif
170 typedef struct dw_cfi_struct *dw_cfi_ref;
171 typedef struct dw_fde_struct *dw_fde_ref;
172 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
174 /* Call frames are described using a sequence of Call Frame
175 Information instructions. The register number, offset
176 and address fields are provided as possible operands;
177 their use is selected by the opcode field. */
179 enum dw_cfi_oprnd_type {
180 dw_cfi_oprnd_unused,
181 dw_cfi_oprnd_reg_num,
182 dw_cfi_oprnd_offset,
183 dw_cfi_oprnd_addr,
184 dw_cfi_oprnd_loc
187 typedef union dw_cfi_oprnd_struct GTY(())
189 unsigned long GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
190 long int GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
191 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
192 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
194 dw_cfi_oprnd;
196 typedef struct dw_cfi_struct GTY(())
198 dw_cfi_ref dw_cfi_next;
199 enum dwarf_call_frame_info dw_cfi_opc;
200 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
201 dw_cfi_oprnd1;
202 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
203 dw_cfi_oprnd2;
205 dw_cfi_node;
207 /* This is how we define the location of the CFA. We use to handle it
208 as REG + OFFSET all the time, but now it can be more complex.
209 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
210 Instead of passing around REG and OFFSET, we pass a copy
211 of this structure. */
212 typedef struct cfa_loc GTY(())
214 unsigned long reg;
215 long offset;
216 long base_offset;
217 int indirect; /* 1 if CFA is accessed via a dereference. */
218 } dw_cfa_location;
220 /* All call frame descriptions (FDE's) in the GCC generated DWARF
221 refer to a single Common Information Entry (CIE), defined at
222 the beginning of the .debug_frame section. This use of a single
223 CIE obviates the need to keep track of multiple CIE's
224 in the DWARF generation routines below. */
226 typedef struct dw_fde_struct GTY(())
228 const char *dw_fde_begin;
229 const char *dw_fde_current_label;
230 const char *dw_fde_end;
231 dw_cfi_ref dw_fde_cfi;
232 unsigned funcdef_number;
233 unsigned all_throwers_are_sibcalls : 1;
234 unsigned nothrow : 1;
235 unsigned uses_eh_lsda : 1;
237 dw_fde_node;
239 /* Maximum size (in bytes) of an artificially generated label. */
240 #define MAX_ARTIFICIAL_LABEL_BYTES 30
242 /* The size of addresses as they appear in the Dwarf 2 data.
243 Some architectures use word addresses to refer to code locations,
244 but Dwarf 2 info always uses byte addresses. On such machines,
245 Dwarf 2 addresses need to be larger than the architecture's
246 pointers. */
247 #ifndef DWARF2_ADDR_SIZE
248 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
249 #endif
251 /* The size in bytes of a DWARF field indicating an offset or length
252 relative to a debug info section, specified to be 4 bytes in the
253 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
254 as PTR_SIZE. */
256 #ifndef DWARF_OFFSET_SIZE
257 #define DWARF_OFFSET_SIZE 4
258 #endif
260 /* According to the (draft) DWARF 3 specification, the initial length
261 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
262 bytes are 0xffffffff, followed by the length stored in the next 8
263 bytes.
265 However, the SGI/MIPS ABI uses an initial length which is equal to
266 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
268 #ifndef DWARF_INITIAL_LENGTH_SIZE
269 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
270 #endif
272 #define DWARF_VERSION 2
274 /* Round SIZE up to the nearest BOUNDARY. */
275 #define DWARF_ROUND(SIZE,BOUNDARY) \
276 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
278 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
279 #ifndef DWARF_CIE_DATA_ALIGNMENT
280 #ifdef STACK_GROWS_DOWNWARD
281 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
282 #else
283 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
284 #endif
285 #endif
287 /* A pointer to the base of a table that contains frame description
288 information for each routine. */
289 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
291 /* Number of elements currently allocated for fde_table. */
292 static GTY(()) unsigned fde_table_allocated;
294 /* Number of elements in fde_table currently in use. */
295 static GTY(()) unsigned fde_table_in_use;
297 /* Size (in elements) of increments by which we may expand the
298 fde_table. */
299 #define FDE_TABLE_INCREMENT 256
301 /* A list of call frame insns for the CIE. */
302 static GTY(()) dw_cfi_ref cie_cfi_head;
304 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
305 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
306 attribute that accelerates the lookup of the FDE associated
307 with the subprogram. This variable holds the table index of the FDE
308 associated with the current function (body) definition. */
309 static unsigned current_funcdef_fde;
310 #endif
312 struct indirect_string_node GTY(())
314 const char *str;
315 unsigned int refcount;
316 unsigned int form;
317 char *label;
320 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
322 static GTY(()) int dw2_string_counter;
323 static GTY(()) unsigned long dwarf2out_cfi_label_num;
325 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
327 /* Forward declarations for functions defined in this file. */
329 static char *stripattributes (const char *);
330 static const char *dwarf_cfi_name (unsigned);
331 static dw_cfi_ref new_cfi (void);
332 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
333 static void add_fde_cfi (const char *, dw_cfi_ref);
334 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
335 static void lookup_cfa (dw_cfa_location *);
336 static void reg_save (const char *, unsigned, unsigned, long);
337 static void initial_return_save (rtx);
338 static long stack_adjust_offset (rtx);
339 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
340 static void output_call_frame_info (int);
341 static void dwarf2out_stack_adjust (rtx);
342 static void queue_reg_save (const char *, rtx, long);
343 static void flush_queued_reg_saves (void);
344 static bool clobbers_queued_reg_save (rtx);
345 static void dwarf2out_frame_debug_expr (rtx, const char *);
347 /* Support for complex CFA locations. */
348 static void output_cfa_loc (dw_cfi_ref);
349 static void get_cfa_from_loc_descr (dw_cfa_location *,
350 struct dw_loc_descr_struct *);
351 static struct dw_loc_descr_struct *build_cfa_loc
352 (dw_cfa_location *);
353 static void def_cfa_1 (const char *, dw_cfa_location *);
355 /* How to start an assembler comment. */
356 #ifndef ASM_COMMENT_START
357 #define ASM_COMMENT_START ";#"
358 #endif
360 /* Data and reference forms for relocatable data. */
361 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
362 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
364 #ifndef DEBUG_FRAME_SECTION
365 #define DEBUG_FRAME_SECTION ".debug_frame"
366 #endif
368 #ifndef FUNC_BEGIN_LABEL
369 #define FUNC_BEGIN_LABEL "LFB"
370 #endif
372 #ifndef FUNC_END_LABEL
373 #define FUNC_END_LABEL "LFE"
374 #endif
376 #define FRAME_BEGIN_LABEL "Lframe"
377 #define CIE_AFTER_SIZE_LABEL "LSCIE"
378 #define CIE_END_LABEL "LECIE"
379 #define FDE_LABEL "LSFDE"
380 #define FDE_AFTER_SIZE_LABEL "LASFDE"
381 #define FDE_END_LABEL "LEFDE"
382 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
383 #define LINE_NUMBER_END_LABEL "LELT"
384 #define LN_PROLOG_AS_LABEL "LASLTP"
385 #define LN_PROLOG_END_LABEL "LELTP"
386 #define DIE_LABEL_PREFIX "DW"
388 /* The DWARF 2 CFA column which tracks the return address. Normally this
389 is the column for PC, or the first column after all of the hard
390 registers. */
391 #ifndef DWARF_FRAME_RETURN_COLUMN
392 #ifdef PC_REGNUM
393 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
394 #else
395 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
396 #endif
397 #endif
399 /* The mapping from gcc register number to DWARF 2 CFA column number. By
400 default, we just provide columns for all registers. */
401 #ifndef DWARF_FRAME_REGNUM
402 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
403 #endif
405 /* The offset from the incoming value of %sp to the top of the stack frame
406 for the current function. */
407 #ifndef INCOMING_FRAME_SP_OFFSET
408 #define INCOMING_FRAME_SP_OFFSET 0
409 #endif
411 /* Hook used by __throw. */
414 expand_builtin_dwarf_sp_column (void)
416 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
419 /* Return a pointer to a copy of the section string name S with all
420 attributes stripped off, and an asterisk prepended (for assemble_name). */
422 static inline char *
423 stripattributes (const char *s)
425 char *stripped = xmalloc (strlen (s) + 2);
426 char *p = stripped;
428 *p++ = '*';
430 while (*s && *s != ',')
431 *p++ = *s++;
433 *p = '\0';
434 return stripped;
437 /* Generate code to initialize the register size table. */
439 void
440 expand_builtin_init_dwarf_reg_sizes (tree address)
442 int i;
443 enum machine_mode mode = TYPE_MODE (char_type_node);
444 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
445 rtx mem = gen_rtx_MEM (BLKmode, addr);
447 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
448 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
450 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
451 enum machine_mode save_mode = reg_raw_mode[i];
452 HOST_WIDE_INT size;
454 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
455 save_mode = choose_hard_reg_mode (i, 1, true);
456 size = GET_MODE_SIZE (save_mode);
457 if (offset < 0)
458 continue;
460 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
464 /* Convert a DWARF call frame info. operation to its string name */
466 static const char *
467 dwarf_cfi_name (unsigned int cfi_opc)
469 switch (cfi_opc)
471 case DW_CFA_advance_loc:
472 return "DW_CFA_advance_loc";
473 case DW_CFA_offset:
474 return "DW_CFA_offset";
475 case DW_CFA_restore:
476 return "DW_CFA_restore";
477 case DW_CFA_nop:
478 return "DW_CFA_nop";
479 case DW_CFA_set_loc:
480 return "DW_CFA_set_loc";
481 case DW_CFA_advance_loc1:
482 return "DW_CFA_advance_loc1";
483 case DW_CFA_advance_loc2:
484 return "DW_CFA_advance_loc2";
485 case DW_CFA_advance_loc4:
486 return "DW_CFA_advance_loc4";
487 case DW_CFA_offset_extended:
488 return "DW_CFA_offset_extended";
489 case DW_CFA_restore_extended:
490 return "DW_CFA_restore_extended";
491 case DW_CFA_undefined:
492 return "DW_CFA_undefined";
493 case DW_CFA_same_value:
494 return "DW_CFA_same_value";
495 case DW_CFA_register:
496 return "DW_CFA_register";
497 case DW_CFA_remember_state:
498 return "DW_CFA_remember_state";
499 case DW_CFA_restore_state:
500 return "DW_CFA_restore_state";
501 case DW_CFA_def_cfa:
502 return "DW_CFA_def_cfa";
503 case DW_CFA_def_cfa_register:
504 return "DW_CFA_def_cfa_register";
505 case DW_CFA_def_cfa_offset:
506 return "DW_CFA_def_cfa_offset";
508 /* DWARF 3 */
509 case DW_CFA_def_cfa_expression:
510 return "DW_CFA_def_cfa_expression";
511 case DW_CFA_expression:
512 return "DW_CFA_expression";
513 case DW_CFA_offset_extended_sf:
514 return "DW_CFA_offset_extended_sf";
515 case DW_CFA_def_cfa_sf:
516 return "DW_CFA_def_cfa_sf";
517 case DW_CFA_def_cfa_offset_sf:
518 return "DW_CFA_def_cfa_offset_sf";
520 /* SGI/MIPS specific */
521 case DW_CFA_MIPS_advance_loc8:
522 return "DW_CFA_MIPS_advance_loc8";
524 /* GNU extensions */
525 case DW_CFA_GNU_window_save:
526 return "DW_CFA_GNU_window_save";
527 case DW_CFA_GNU_args_size:
528 return "DW_CFA_GNU_args_size";
529 case DW_CFA_GNU_negative_offset_extended:
530 return "DW_CFA_GNU_negative_offset_extended";
532 default:
533 return "DW_CFA_<unknown>";
537 /* Return a pointer to a newly allocated Call Frame Instruction. */
539 static inline dw_cfi_ref
540 new_cfi (void)
542 dw_cfi_ref cfi = (dw_cfi_ref) ggc_alloc (sizeof (dw_cfi_node));
544 cfi->dw_cfi_next = NULL;
545 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
546 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
548 return cfi;
551 /* Add a Call Frame Instruction to list of instructions. */
553 static inline void
554 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
556 dw_cfi_ref *p;
558 /* Find the end of the chain. */
559 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
562 *p = cfi;
565 /* Generate a new label for the CFI info to refer to. */
567 char *
568 dwarf2out_cfi_label (void)
570 static char label[20];
572 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
573 ASM_OUTPUT_LABEL (asm_out_file, label);
574 return label;
577 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
578 or to the CIE if LABEL is NULL. */
580 static void
581 add_fde_cfi (const char *label, dw_cfi_ref cfi)
583 if (label)
585 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
587 if (*label == 0)
588 label = dwarf2out_cfi_label ();
590 if (fde->dw_fde_current_label == NULL
591 || strcmp (label, fde->dw_fde_current_label) != 0)
593 dw_cfi_ref xcfi;
595 fde->dw_fde_current_label = label = xstrdup (label);
597 /* Set the location counter to the new label. */
598 xcfi = new_cfi ();
599 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
600 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
601 add_cfi (&fde->dw_fde_cfi, xcfi);
604 add_cfi (&fde->dw_fde_cfi, cfi);
607 else
608 add_cfi (&cie_cfi_head, cfi);
611 /* Subroutine of lookup_cfa. */
613 static inline void
614 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
616 switch (cfi->dw_cfi_opc)
618 case DW_CFA_def_cfa_offset:
619 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
620 break;
621 case DW_CFA_def_cfa_register:
622 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
623 break;
624 case DW_CFA_def_cfa:
625 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
626 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
627 break;
628 case DW_CFA_def_cfa_expression:
629 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
630 break;
631 default:
632 break;
636 /* Find the previous value for the CFA. */
638 static void
639 lookup_cfa (dw_cfa_location *loc)
641 dw_cfi_ref cfi;
643 loc->reg = (unsigned long) -1;
644 loc->offset = 0;
645 loc->indirect = 0;
646 loc->base_offset = 0;
648 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
649 lookup_cfa_1 (cfi, loc);
651 if (fde_table_in_use)
653 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
654 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
655 lookup_cfa_1 (cfi, loc);
659 /* The current rule for calculating the DWARF2 canonical frame address. */
660 static dw_cfa_location cfa;
662 /* The register used for saving registers to the stack, and its offset
663 from the CFA. */
664 static dw_cfa_location cfa_store;
666 /* The running total of the size of arguments pushed onto the stack. */
667 static long args_size;
669 /* The last args_size we actually output. */
670 static long old_args_size;
672 /* Entry point to update the canonical frame address (CFA).
673 LABEL is passed to add_fde_cfi. The value of CFA is now to be
674 calculated from REG+OFFSET. */
676 void
677 dwarf2out_def_cfa (const char *label, unsigned int reg, long int offset)
679 dw_cfa_location loc;
680 loc.indirect = 0;
681 loc.base_offset = 0;
682 loc.reg = reg;
683 loc.offset = offset;
684 def_cfa_1 (label, &loc);
687 /* This routine does the actual work. The CFA is now calculated from
688 the dw_cfa_location structure. */
690 static void
691 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
693 dw_cfi_ref cfi;
694 dw_cfa_location old_cfa, loc;
696 cfa = *loc_p;
697 loc = *loc_p;
699 if (cfa_store.reg == loc.reg && loc.indirect == 0)
700 cfa_store.offset = loc.offset;
702 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
703 lookup_cfa (&old_cfa);
705 /* If nothing changed, no need to issue any call frame instructions. */
706 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
707 && loc.indirect == old_cfa.indirect
708 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
709 return;
711 cfi = new_cfi ();
713 if (loc.reg == old_cfa.reg && !loc.indirect)
715 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
716 indicating the CFA register did not change but the offset
717 did. */
718 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
719 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
722 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
723 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
724 && !loc.indirect)
726 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
727 indicating the CFA register has changed to <register> but the
728 offset has not changed. */
729 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
730 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
732 #endif
734 else if (loc.indirect == 0)
736 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
737 indicating the CFA register has changed to <register> with
738 the specified offset. */
739 cfi->dw_cfi_opc = DW_CFA_def_cfa;
740 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
741 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
743 else
745 /* Construct a DW_CFA_def_cfa_expression instruction to
746 calculate the CFA using a full location expression since no
747 register-offset pair is available. */
748 struct dw_loc_descr_struct *loc_list;
750 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
751 loc_list = build_cfa_loc (&loc);
752 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
755 add_fde_cfi (label, cfi);
758 /* Add the CFI for saving a register. REG is the CFA column number.
759 LABEL is passed to add_fde_cfi.
760 If SREG is -1, the register is saved at OFFSET from the CFA;
761 otherwise it is saved in SREG. */
763 static void
764 reg_save (const char *label, unsigned int reg, unsigned int sreg, long int offset)
766 dw_cfi_ref cfi = new_cfi ();
768 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
770 /* The following comparison is correct. -1 is used to indicate that
771 the value isn't a register number. */
772 if (sreg == (unsigned int) -1)
774 if (reg & ~0x3f)
775 /* The register number won't fit in 6 bits, so we have to use
776 the long form. */
777 cfi->dw_cfi_opc = DW_CFA_offset_extended;
778 else
779 cfi->dw_cfi_opc = DW_CFA_offset;
781 #ifdef ENABLE_CHECKING
783 /* If we get an offset that is not a multiple of
784 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
785 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
786 description. */
787 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
789 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
790 abort ();
792 #endif
793 offset /= DWARF_CIE_DATA_ALIGNMENT;
794 if (offset < 0)
795 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
797 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
799 else if (sreg == reg)
800 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
801 return;
802 else
804 cfi->dw_cfi_opc = DW_CFA_register;
805 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
808 add_fde_cfi (label, cfi);
811 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
812 This CFI tells the unwinder that it needs to restore the window registers
813 from the previous frame's window save area.
815 ??? Perhaps we should note in the CIE where windows are saved (instead of
816 assuming 0(cfa)) and what registers are in the window. */
818 void
819 dwarf2out_window_save (const char *label)
821 dw_cfi_ref cfi = new_cfi ();
823 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
824 add_fde_cfi (label, cfi);
827 /* Add a CFI to update the running total of the size of arguments
828 pushed onto the stack. */
830 void
831 dwarf2out_args_size (const char *label, long int size)
833 dw_cfi_ref cfi;
835 if (size == old_args_size)
836 return;
838 old_args_size = size;
840 cfi = new_cfi ();
841 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
842 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
843 add_fde_cfi (label, cfi);
846 /* Entry point for saving a register to the stack. REG is the GCC register
847 number. LABEL and OFFSET are passed to reg_save. */
849 void
850 dwarf2out_reg_save (const char *label, unsigned int reg, long int offset)
852 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
855 /* Entry point for saving the return address in the stack.
856 LABEL and OFFSET are passed to reg_save. */
858 void
859 dwarf2out_return_save (const char *label, long int offset)
861 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
864 /* Entry point for saving the return address in a register.
865 LABEL and SREG are passed to reg_save. */
867 void
868 dwarf2out_return_reg (const char *label, unsigned int sreg)
870 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
873 /* Record the initial position of the return address. RTL is
874 INCOMING_RETURN_ADDR_RTX. */
876 static void
877 initial_return_save (rtx rtl)
879 unsigned int reg = (unsigned int) -1;
880 HOST_WIDE_INT offset = 0;
882 switch (GET_CODE (rtl))
884 case REG:
885 /* RA is in a register. */
886 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
887 break;
889 case MEM:
890 /* RA is on the stack. */
891 rtl = XEXP (rtl, 0);
892 switch (GET_CODE (rtl))
894 case REG:
895 if (REGNO (rtl) != STACK_POINTER_REGNUM)
896 abort ();
897 offset = 0;
898 break;
900 case PLUS:
901 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
902 abort ();
903 offset = INTVAL (XEXP (rtl, 1));
904 break;
906 case MINUS:
907 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
908 abort ();
909 offset = -INTVAL (XEXP (rtl, 1));
910 break;
912 default:
913 abort ();
916 break;
918 case PLUS:
919 /* The return address is at some offset from any value we can
920 actually load. For instance, on the SPARC it is in %i7+8. Just
921 ignore the offset for now; it doesn't matter for unwinding frames. */
922 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
923 abort ();
924 initial_return_save (XEXP (rtl, 0));
925 return;
927 default:
928 abort ();
931 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
934 /* Given a SET, calculate the amount of stack adjustment it
935 contains. */
937 static long
938 stack_adjust_offset (rtx pattern)
940 rtx src = SET_SRC (pattern);
941 rtx dest = SET_DEST (pattern);
942 HOST_WIDE_INT offset = 0;
943 enum rtx_code code;
945 if (dest == stack_pointer_rtx)
947 /* (set (reg sp) (plus (reg sp) (const_int))) */
948 code = GET_CODE (src);
949 if (! (code == PLUS || code == MINUS)
950 || XEXP (src, 0) != stack_pointer_rtx
951 || GET_CODE (XEXP (src, 1)) != CONST_INT)
952 return 0;
954 offset = INTVAL (XEXP (src, 1));
955 if (code == PLUS)
956 offset = -offset;
958 else if (GET_CODE (dest) == MEM)
960 /* (set (mem (pre_dec (reg sp))) (foo)) */
961 src = XEXP (dest, 0);
962 code = GET_CODE (src);
964 switch (code)
966 case PRE_MODIFY:
967 case POST_MODIFY:
968 if (XEXP (src, 0) == stack_pointer_rtx)
970 rtx val = XEXP (XEXP (src, 1), 1);
971 /* We handle only adjustments by constant amount. */
972 if (GET_CODE (XEXP (src, 1)) != PLUS ||
973 GET_CODE (val) != CONST_INT)
974 abort ();
975 offset = -INTVAL (val);
976 break;
978 return 0;
980 case PRE_DEC:
981 case POST_DEC:
982 if (XEXP (src, 0) == stack_pointer_rtx)
984 offset = GET_MODE_SIZE (GET_MODE (dest));
985 break;
987 return 0;
989 case PRE_INC:
990 case POST_INC:
991 if (XEXP (src, 0) == stack_pointer_rtx)
993 offset = -GET_MODE_SIZE (GET_MODE (dest));
994 break;
996 return 0;
998 default:
999 return 0;
1002 else
1003 return 0;
1005 return offset;
1008 /* Check INSN to see if it looks like a push or a stack adjustment, and
1009 make a note of it if it does. EH uses this information to find out how
1010 much extra space it needs to pop off the stack. */
1012 static void
1013 dwarf2out_stack_adjust (rtx insn)
1015 HOST_WIDE_INT offset;
1016 const char *label;
1017 int i;
1019 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1021 /* Extract the size of the args from the CALL rtx itself. */
1022 insn = PATTERN (insn);
1023 if (GET_CODE (insn) == PARALLEL)
1024 insn = XVECEXP (insn, 0, 0);
1025 if (GET_CODE (insn) == SET)
1026 insn = SET_SRC (insn);
1027 if (GET_CODE (insn) != CALL)
1028 abort ();
1030 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1031 return;
1034 /* If only calls can throw, and we have a frame pointer,
1035 save up adjustments until we see the CALL_INSN. */
1036 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1037 return;
1039 if (GET_CODE (insn) == BARRIER)
1041 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1042 the compiler will have already emitted a stack adjustment, but
1043 doesn't bother for calls to noreturn functions. */
1044 #ifdef STACK_GROWS_DOWNWARD
1045 offset = -args_size;
1046 #else
1047 offset = args_size;
1048 #endif
1050 else if (GET_CODE (PATTERN (insn)) == SET)
1051 offset = stack_adjust_offset (PATTERN (insn));
1052 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1053 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1055 /* There may be stack adjustments inside compound insns. Search
1056 for them. */
1057 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1058 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1059 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1061 else
1062 return;
1064 if (offset == 0)
1065 return;
1067 if (cfa.reg == STACK_POINTER_REGNUM)
1068 cfa.offset += offset;
1070 #ifndef STACK_GROWS_DOWNWARD
1071 offset = -offset;
1072 #endif
1074 args_size += offset;
1075 if (args_size < 0)
1076 args_size = 0;
1078 label = dwarf2out_cfi_label ();
1079 def_cfa_1 (label, &cfa);
1080 dwarf2out_args_size (label, args_size);
1083 #endif
1085 /* We delay emitting a register save until either (a) we reach the end
1086 of the prologue or (b) the register is clobbered. This clusters
1087 register saves so that there are fewer pc advances. */
1089 struct queued_reg_save GTY(())
1091 struct queued_reg_save *next;
1092 rtx reg;
1093 long cfa_offset;
1096 static GTY(()) struct queued_reg_save *queued_reg_saves;
1098 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1099 static const char *last_reg_save_label;
1101 static void
1102 queue_reg_save (const char *label, rtx reg, long int offset)
1104 struct queued_reg_save *q = ggc_alloc (sizeof (*q));
1106 q->next = queued_reg_saves;
1107 q->reg = reg;
1108 q->cfa_offset = offset;
1109 queued_reg_saves = q;
1111 last_reg_save_label = label;
1114 static void
1115 flush_queued_reg_saves (void)
1117 struct queued_reg_save *q, *next;
1119 for (q = queued_reg_saves; q; q = next)
1121 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1122 next = q->next;
1125 queued_reg_saves = NULL;
1126 last_reg_save_label = NULL;
1129 static bool
1130 clobbers_queued_reg_save (rtx insn)
1132 struct queued_reg_save *q;
1134 for (q = queued_reg_saves; q; q = q->next)
1135 if (modified_in_p (q->reg, insn))
1136 return true;
1138 return false;
1142 /* A temporary register holding an integral value used in adjusting SP
1143 or setting up the store_reg. The "offset" field holds the integer
1144 value, not an offset. */
1145 static dw_cfa_location cfa_temp;
1147 /* Record call frame debugging information for an expression EXPR,
1148 which either sets SP or FP (adjusting how we calculate the frame
1149 address) or saves a register to the stack. LABEL indicates the
1150 address of EXPR.
1152 This function encodes a state machine mapping rtxes to actions on
1153 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1154 users need not read the source code.
1156 The High-Level Picture
1158 Changes in the register we use to calculate the CFA: Currently we
1159 assume that if you copy the CFA register into another register, we
1160 should take the other one as the new CFA register; this seems to
1161 work pretty well. If it's wrong for some target, it's simple
1162 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1164 Changes in the register we use for saving registers to the stack:
1165 This is usually SP, but not always. Again, we deduce that if you
1166 copy SP into another register (and SP is not the CFA register),
1167 then the new register is the one we will be using for register
1168 saves. This also seems to work.
1170 Register saves: There's not much guesswork about this one; if
1171 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1172 register save, and the register used to calculate the destination
1173 had better be the one we think we're using for this purpose.
1175 Except: If the register being saved is the CFA register, and the
1176 offset is nonzero, we are saving the CFA, so we assume we have to
1177 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1178 the intent is to save the value of SP from the previous frame.
1180 Invariants / Summaries of Rules
1182 cfa current rule for calculating the CFA. It usually
1183 consists of a register and an offset.
1184 cfa_store register used by prologue code to save things to the stack
1185 cfa_store.offset is the offset from the value of
1186 cfa_store.reg to the actual CFA
1187 cfa_temp register holding an integral value. cfa_temp.offset
1188 stores the value, which will be used to adjust the
1189 stack pointer. cfa_temp is also used like cfa_store,
1190 to track stores to the stack via fp or a temp reg.
1192 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1193 with cfa.reg as the first operand changes the cfa.reg and its
1194 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1195 cfa_temp.offset.
1197 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1198 expression yielding a constant. This sets cfa_temp.reg
1199 and cfa_temp.offset.
1201 Rule 5: Create a new register cfa_store used to save items to the
1202 stack.
1204 Rules 10-14: Save a register to the stack. Define offset as the
1205 difference of the original location and cfa_store's
1206 location (or cfa_temp's location if cfa_temp is used).
1208 The Rules
1210 "{a,b}" indicates a choice of a xor b.
1211 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1213 Rule 1:
1214 (set <reg1> <reg2>:cfa.reg)
1215 effects: cfa.reg = <reg1>
1216 cfa.offset unchanged
1217 cfa_temp.reg = <reg1>
1218 cfa_temp.offset = cfa.offset
1220 Rule 2:
1221 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1222 {<const_int>,<reg>:cfa_temp.reg}))
1223 effects: cfa.reg = sp if fp used
1224 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1225 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1226 if cfa_store.reg==sp
1228 Rule 3:
1229 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1230 effects: cfa.reg = fp
1231 cfa_offset += +/- <const_int>
1233 Rule 4:
1234 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1235 constraints: <reg1> != fp
1236 <reg1> != sp
1237 effects: cfa.reg = <reg1>
1238 cfa_temp.reg = <reg1>
1239 cfa_temp.offset = cfa.offset
1241 Rule 5:
1242 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1243 constraints: <reg1> != fp
1244 <reg1> != sp
1245 effects: cfa_store.reg = <reg1>
1246 cfa_store.offset = cfa.offset - cfa_temp.offset
1248 Rule 6:
1249 (set <reg> <const_int>)
1250 effects: cfa_temp.reg = <reg>
1251 cfa_temp.offset = <const_int>
1253 Rule 7:
1254 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1255 effects: cfa_temp.reg = <reg1>
1256 cfa_temp.offset |= <const_int>
1258 Rule 8:
1259 (set <reg> (high <exp>))
1260 effects: none
1262 Rule 9:
1263 (set <reg> (lo_sum <exp> <const_int>))
1264 effects: cfa_temp.reg = <reg>
1265 cfa_temp.offset = <const_int>
1267 Rule 10:
1268 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1269 effects: cfa_store.offset -= <const_int>
1270 cfa.offset = cfa_store.offset if cfa.reg == sp
1271 cfa.reg = sp
1272 cfa.base_offset = -cfa_store.offset
1274 Rule 11:
1275 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1276 effects: cfa_store.offset += -/+ mode_size(mem)
1277 cfa.offset = cfa_store.offset if cfa.reg == sp
1278 cfa.reg = sp
1279 cfa.base_offset = -cfa_store.offset
1281 Rule 12:
1282 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1284 <reg2>)
1285 effects: cfa.reg = <reg1>
1286 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1288 Rule 13:
1289 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1290 effects: cfa.reg = <reg1>
1291 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1293 Rule 14:
1294 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1295 effects: cfa.reg = <reg1>
1296 cfa.base_offset = -cfa_temp.offset
1297 cfa_temp.offset -= mode_size(mem) */
1299 static void
1300 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1302 rtx src, dest;
1303 HOST_WIDE_INT offset;
1305 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1306 the PARALLEL independently. The first element is always processed if
1307 it is a SET. This is for backward compatibility. Other elements
1308 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1309 flag is set in them. */
1310 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1312 int par_index;
1313 int limit = XVECLEN (expr, 0);
1315 for (par_index = 0; par_index < limit; par_index++)
1316 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1317 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1318 || par_index == 0))
1319 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1321 return;
1324 if (GET_CODE (expr) != SET)
1325 abort ();
1327 src = SET_SRC (expr);
1328 dest = SET_DEST (expr);
1330 switch (GET_CODE (dest))
1332 case REG:
1333 /* Rule 1 */
1334 /* Update the CFA rule wrt SP or FP. Make sure src is
1335 relative to the current CFA register. */
1336 switch (GET_CODE (src))
1338 /* Setting FP from SP. */
1339 case REG:
1340 if (cfa.reg == (unsigned) REGNO (src))
1341 /* OK. */
1343 else
1344 abort ();
1346 /* We used to require that dest be either SP or FP, but the
1347 ARM copies SP to a temporary register, and from there to
1348 FP. So we just rely on the backends to only set
1349 RTX_FRAME_RELATED_P on appropriate insns. */
1350 cfa.reg = REGNO (dest);
1351 cfa_temp.reg = cfa.reg;
1352 cfa_temp.offset = cfa.offset;
1353 break;
1355 case PLUS:
1356 case MINUS:
1357 case LO_SUM:
1358 if (dest == stack_pointer_rtx)
1360 /* Rule 2 */
1361 /* Adjusting SP. */
1362 switch (GET_CODE (XEXP (src, 1)))
1364 case CONST_INT:
1365 offset = INTVAL (XEXP (src, 1));
1366 break;
1367 case REG:
1368 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1369 abort ();
1370 offset = cfa_temp.offset;
1371 break;
1372 default:
1373 abort ();
1376 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1378 /* Restoring SP from FP in the epilogue. */
1379 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1380 abort ();
1381 cfa.reg = STACK_POINTER_REGNUM;
1383 else if (GET_CODE (src) == LO_SUM)
1384 /* Assume we've set the source reg of the LO_SUM from sp. */
1386 else if (XEXP (src, 0) != stack_pointer_rtx)
1387 abort ();
1389 if (GET_CODE (src) != MINUS)
1390 offset = -offset;
1391 if (cfa.reg == STACK_POINTER_REGNUM)
1392 cfa.offset += offset;
1393 if (cfa_store.reg == STACK_POINTER_REGNUM)
1394 cfa_store.offset += offset;
1396 else if (dest == hard_frame_pointer_rtx)
1398 /* Rule 3 */
1399 /* Either setting the FP from an offset of the SP,
1400 or adjusting the FP */
1401 if (! frame_pointer_needed)
1402 abort ();
1404 if (GET_CODE (XEXP (src, 0)) == REG
1405 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1406 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1408 offset = INTVAL (XEXP (src, 1));
1409 if (GET_CODE (src) != MINUS)
1410 offset = -offset;
1411 cfa.offset += offset;
1412 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1414 else
1415 abort ();
1417 else
1419 if (GET_CODE (src) == MINUS)
1420 abort ();
1422 /* Rule 4 */
1423 if (GET_CODE (XEXP (src, 0)) == REG
1424 && REGNO (XEXP (src, 0)) == cfa.reg
1425 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1427 /* Setting a temporary CFA register that will be copied
1428 into the FP later on. */
1429 offset = - INTVAL (XEXP (src, 1));
1430 cfa.offset += offset;
1431 cfa.reg = REGNO (dest);
1432 /* Or used to save regs to the stack. */
1433 cfa_temp.reg = cfa.reg;
1434 cfa_temp.offset = cfa.offset;
1437 /* Rule 5 */
1438 else if (GET_CODE (XEXP (src, 0)) == REG
1439 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1440 && XEXP (src, 1) == stack_pointer_rtx)
1442 /* Setting a scratch register that we will use instead
1443 of SP for saving registers to the stack. */
1444 if (cfa.reg != STACK_POINTER_REGNUM)
1445 abort ();
1446 cfa_store.reg = REGNO (dest);
1447 cfa_store.offset = cfa.offset - cfa_temp.offset;
1450 /* Rule 9 */
1451 else if (GET_CODE (src) == LO_SUM
1452 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1454 cfa_temp.reg = REGNO (dest);
1455 cfa_temp.offset = INTVAL (XEXP (src, 1));
1457 else
1458 abort ();
1460 break;
1462 /* Rule 6 */
1463 case CONST_INT:
1464 cfa_temp.reg = REGNO (dest);
1465 cfa_temp.offset = INTVAL (src);
1466 break;
1468 /* Rule 7 */
1469 case IOR:
1470 if (GET_CODE (XEXP (src, 0)) != REG
1471 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1472 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1473 abort ();
1475 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1476 cfa_temp.reg = REGNO (dest);
1477 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1478 break;
1480 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1481 which will fill in all of the bits. */
1482 /* Rule 8 */
1483 case HIGH:
1484 break;
1486 default:
1487 abort ();
1490 def_cfa_1 (label, &cfa);
1491 break;
1493 case MEM:
1494 if (GET_CODE (src) != REG)
1495 abort ();
1497 /* Saving a register to the stack. Make sure dest is relative to the
1498 CFA register. */
1499 switch (GET_CODE (XEXP (dest, 0)))
1501 /* Rule 10 */
1502 /* With a push. */
1503 case PRE_MODIFY:
1504 /* We can't handle variable size modifications. */
1505 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1506 abort ();
1507 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1509 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1510 || cfa_store.reg != STACK_POINTER_REGNUM)
1511 abort ();
1513 cfa_store.offset += offset;
1514 if (cfa.reg == STACK_POINTER_REGNUM)
1515 cfa.offset = cfa_store.offset;
1517 offset = -cfa_store.offset;
1518 break;
1520 /* Rule 11 */
1521 case PRE_INC:
1522 case PRE_DEC:
1523 offset = GET_MODE_SIZE (GET_MODE (dest));
1524 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1525 offset = -offset;
1527 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1528 || cfa_store.reg != STACK_POINTER_REGNUM)
1529 abort ();
1531 cfa_store.offset += offset;
1532 if (cfa.reg == STACK_POINTER_REGNUM)
1533 cfa.offset = cfa_store.offset;
1535 offset = -cfa_store.offset;
1536 break;
1538 /* Rule 12 */
1539 /* With an offset. */
1540 case PLUS:
1541 case MINUS:
1542 case LO_SUM:
1543 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1544 abort ();
1545 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1546 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1547 offset = -offset;
1549 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1550 offset -= cfa_store.offset;
1551 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1552 offset -= cfa_temp.offset;
1553 else
1554 abort ();
1555 break;
1557 /* Rule 13 */
1558 /* Without an offset. */
1559 case REG:
1560 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1561 offset = -cfa_store.offset;
1562 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1563 offset = -cfa_temp.offset;
1564 else
1565 abort ();
1566 break;
1568 /* Rule 14 */
1569 case POST_INC:
1570 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1571 abort ();
1572 offset = -cfa_temp.offset;
1573 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1574 break;
1576 default:
1577 abort ();
1580 if (REGNO (src) != STACK_POINTER_REGNUM
1581 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1582 && (unsigned) REGNO (src) == cfa.reg)
1584 /* We're storing the current CFA reg into the stack. */
1586 if (cfa.offset == 0)
1588 /* If the source register is exactly the CFA, assume
1589 we're saving SP like any other register; this happens
1590 on the ARM. */
1591 def_cfa_1 (label, &cfa);
1592 queue_reg_save (label, stack_pointer_rtx, offset);
1593 break;
1595 else
1597 /* Otherwise, we'll need to look in the stack to
1598 calculate the CFA. */
1599 rtx x = XEXP (dest, 0);
1601 if (GET_CODE (x) != REG)
1602 x = XEXP (x, 0);
1603 if (GET_CODE (x) != REG)
1604 abort ();
1606 cfa.reg = REGNO (x);
1607 cfa.base_offset = offset;
1608 cfa.indirect = 1;
1609 def_cfa_1 (label, &cfa);
1610 break;
1614 def_cfa_1 (label, &cfa);
1615 queue_reg_save (label, src, offset);
1616 break;
1618 default:
1619 abort ();
1623 /* Record call frame debugging information for INSN, which either
1624 sets SP or FP (adjusting how we calculate the frame address) or saves a
1625 register to the stack. If INSN is NULL_RTX, initialize our state. */
1627 void
1628 dwarf2out_frame_debug (rtx insn)
1630 const char *label;
1631 rtx src;
1633 if (insn == NULL_RTX)
1635 /* Flush any queued register saves. */
1636 flush_queued_reg_saves ();
1638 /* Set up state for generating call frame debug info. */
1639 lookup_cfa (&cfa);
1640 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1641 abort ();
1643 cfa.reg = STACK_POINTER_REGNUM;
1644 cfa_store = cfa;
1645 cfa_temp.reg = -1;
1646 cfa_temp.offset = 0;
1647 return;
1650 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1651 flush_queued_reg_saves ();
1653 if (! RTX_FRAME_RELATED_P (insn))
1655 if (!ACCUMULATE_OUTGOING_ARGS)
1656 dwarf2out_stack_adjust (insn);
1658 return;
1661 label = dwarf2out_cfi_label ();
1662 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1663 if (src)
1664 insn = XEXP (src, 0);
1665 else
1666 insn = PATTERN (insn);
1668 dwarf2out_frame_debug_expr (insn, label);
1671 #endif
1673 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1674 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1675 (enum dwarf_call_frame_info cfi);
1677 static enum dw_cfi_oprnd_type
1678 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1680 switch (cfi)
1682 case DW_CFA_nop:
1683 case DW_CFA_GNU_window_save:
1684 return dw_cfi_oprnd_unused;
1686 case DW_CFA_set_loc:
1687 case DW_CFA_advance_loc1:
1688 case DW_CFA_advance_loc2:
1689 case DW_CFA_advance_loc4:
1690 case DW_CFA_MIPS_advance_loc8:
1691 return dw_cfi_oprnd_addr;
1693 case DW_CFA_offset:
1694 case DW_CFA_offset_extended:
1695 case DW_CFA_def_cfa:
1696 case DW_CFA_offset_extended_sf:
1697 case DW_CFA_def_cfa_sf:
1698 case DW_CFA_restore_extended:
1699 case DW_CFA_undefined:
1700 case DW_CFA_same_value:
1701 case DW_CFA_def_cfa_register:
1702 case DW_CFA_register:
1703 return dw_cfi_oprnd_reg_num;
1705 case DW_CFA_def_cfa_offset:
1706 case DW_CFA_GNU_args_size:
1707 case DW_CFA_def_cfa_offset_sf:
1708 return dw_cfi_oprnd_offset;
1710 case DW_CFA_def_cfa_expression:
1711 case DW_CFA_expression:
1712 return dw_cfi_oprnd_loc;
1714 default:
1715 abort ();
1719 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1720 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1721 (enum dwarf_call_frame_info cfi);
1723 static enum dw_cfi_oprnd_type
1724 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1726 switch (cfi)
1728 case DW_CFA_def_cfa:
1729 case DW_CFA_def_cfa_sf:
1730 case DW_CFA_offset:
1731 case DW_CFA_offset_extended_sf:
1732 case DW_CFA_offset_extended:
1733 return dw_cfi_oprnd_offset;
1735 case DW_CFA_register:
1736 return dw_cfi_oprnd_reg_num;
1738 default:
1739 return dw_cfi_oprnd_unused;
1743 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1745 /* Output a Call Frame Information opcode and its operand(s). */
1747 static void
1748 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
1750 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1751 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1752 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1753 "DW_CFA_advance_loc 0x%lx",
1754 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1755 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1757 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1758 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1759 "DW_CFA_offset, column 0x%lx",
1760 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1761 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1763 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1764 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1765 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1766 "DW_CFA_restore, column 0x%lx",
1767 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1768 else
1770 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1771 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1773 switch (cfi->dw_cfi_opc)
1775 case DW_CFA_set_loc:
1776 if (for_eh)
1777 dw2_asm_output_encoded_addr_rtx (
1778 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1779 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1780 NULL);
1781 else
1782 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1783 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1784 break;
1786 case DW_CFA_advance_loc1:
1787 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1788 fde->dw_fde_current_label, NULL);
1789 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1790 break;
1792 case DW_CFA_advance_loc2:
1793 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1794 fde->dw_fde_current_label, NULL);
1795 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1796 break;
1798 case DW_CFA_advance_loc4:
1799 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1800 fde->dw_fde_current_label, NULL);
1801 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1802 break;
1804 case DW_CFA_MIPS_advance_loc8:
1805 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1806 fde->dw_fde_current_label, NULL);
1807 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1808 break;
1810 case DW_CFA_offset_extended:
1811 case DW_CFA_def_cfa:
1812 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1813 NULL);
1814 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1815 break;
1817 case DW_CFA_offset_extended_sf:
1818 case DW_CFA_def_cfa_sf:
1819 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1820 NULL);
1821 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1822 break;
1824 case DW_CFA_restore_extended:
1825 case DW_CFA_undefined:
1826 case DW_CFA_same_value:
1827 case DW_CFA_def_cfa_register:
1828 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1829 NULL);
1830 break;
1832 case DW_CFA_register:
1833 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1834 NULL);
1835 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1836 NULL);
1837 break;
1839 case DW_CFA_def_cfa_offset:
1840 case DW_CFA_GNU_args_size:
1841 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1842 break;
1844 case DW_CFA_def_cfa_offset_sf:
1845 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1846 break;
1848 case DW_CFA_GNU_window_save:
1849 break;
1851 case DW_CFA_def_cfa_expression:
1852 case DW_CFA_expression:
1853 output_cfa_loc (cfi);
1854 break;
1856 case DW_CFA_GNU_negative_offset_extended:
1857 /* Obsoleted by DW_CFA_offset_extended_sf. */
1858 abort ();
1860 default:
1861 break;
1866 /* Output the call frame information used to used to record information
1867 that relates to calculating the frame pointer, and records the
1868 location of saved registers. */
1870 static void
1871 output_call_frame_info (int for_eh)
1873 unsigned int i;
1874 dw_fde_ref fde;
1875 dw_cfi_ref cfi;
1876 char l1[20], l2[20], section_start_label[20];
1877 bool any_lsda_needed = false;
1878 char augmentation[6];
1879 int augmentation_size;
1880 int fde_encoding = DW_EH_PE_absptr;
1881 int per_encoding = DW_EH_PE_absptr;
1882 int lsda_encoding = DW_EH_PE_absptr;
1884 /* Don't emit a CIE if there won't be any FDEs. */
1885 if (fde_table_in_use == 0)
1886 return;
1888 /* If we don't have any functions we'll want to unwind out of, don't
1889 emit any EH unwind information. Note that if exceptions aren't
1890 enabled, we won't have collected nothrow information, and if we
1891 asked for asynchronous tables, we always want this info. */
1892 if (for_eh)
1894 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
1896 for (i = 0; i < fde_table_in_use; i++)
1897 if (fde_table[i].uses_eh_lsda)
1898 any_eh_needed = any_lsda_needed = true;
1899 else if (! fde_table[i].nothrow
1900 && ! fde_table[i].all_throwers_are_sibcalls)
1901 any_eh_needed = true;
1903 if (! any_eh_needed)
1904 return;
1907 /* We're going to be generating comments, so turn on app. */
1908 if (flag_debug_asm)
1909 app_enable ();
1911 if (for_eh)
1912 (*targetm.asm_out.eh_frame_section) ();
1913 else
1914 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1916 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1917 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1919 /* Output the CIE. */
1920 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1921 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1922 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1923 "Length of Common Information Entry");
1924 ASM_OUTPUT_LABEL (asm_out_file, l1);
1926 /* Now that the CIE pointer is PC-relative for EH,
1927 use 0 to identify the CIE. */
1928 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1929 (for_eh ? 0 : DW_CIE_ID),
1930 "CIE Identifier Tag");
1932 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1934 augmentation[0] = 0;
1935 augmentation_size = 0;
1936 if (for_eh)
1938 char *p;
1940 /* Augmentation:
1941 z Indicates that a uleb128 is present to size the
1942 augmentation section.
1943 L Indicates the encoding (and thus presence) of
1944 an LSDA pointer in the FDE augmentation.
1945 R Indicates a non-default pointer encoding for
1946 FDE code pointers.
1947 P Indicates the presence of an encoding + language
1948 personality routine in the CIE augmentation. */
1950 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1951 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1952 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1954 p = augmentation + 1;
1955 if (eh_personality_libfunc)
1957 *p++ = 'P';
1958 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1960 if (any_lsda_needed)
1962 *p++ = 'L';
1963 augmentation_size += 1;
1965 if (fde_encoding != DW_EH_PE_absptr)
1967 *p++ = 'R';
1968 augmentation_size += 1;
1970 if (p > augmentation + 1)
1972 augmentation[0] = 'z';
1973 *p = '\0';
1976 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1977 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1979 int offset = ( 4 /* Length */
1980 + 4 /* CIE Id */
1981 + 1 /* CIE version */
1982 + strlen (augmentation) + 1 /* Augmentation */
1983 + size_of_uleb128 (1) /* Code alignment */
1984 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1985 + 1 /* RA column */
1986 + 1 /* Augmentation size */
1987 + 1 /* Personality encoding */ );
1988 int pad = -offset & (PTR_SIZE - 1);
1990 augmentation_size += pad;
1992 /* Augmentations should be small, so there's scarce need to
1993 iterate for a solution. Die if we exceed one uleb128 byte. */
1994 if (size_of_uleb128 (augmentation_size) != 1)
1995 abort ();
1999 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2000 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2001 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2002 "CIE Data Alignment Factor");
2003 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
2005 if (augmentation[0])
2007 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2008 if (eh_personality_libfunc)
2010 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2011 eh_data_format_name (per_encoding));
2012 dw2_asm_output_encoded_addr_rtx (per_encoding,
2013 eh_personality_libfunc, NULL);
2016 if (any_lsda_needed)
2017 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2018 eh_data_format_name (lsda_encoding));
2020 if (fde_encoding != DW_EH_PE_absptr)
2021 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2022 eh_data_format_name (fde_encoding));
2025 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2026 output_cfi (cfi, NULL, for_eh);
2028 /* Pad the CIE out to an address sized boundary. */
2029 ASM_OUTPUT_ALIGN (asm_out_file,
2030 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2031 ASM_OUTPUT_LABEL (asm_out_file, l2);
2033 /* Loop through all of the FDE's. */
2034 for (i = 0; i < fde_table_in_use; i++)
2036 fde = &fde_table[i];
2038 /* Don't emit EH unwind info for leaf functions that don't need it. */
2039 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2040 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2041 && !fde->uses_eh_lsda)
2042 continue;
2044 (*targetm.asm_out.internal_label) (asm_out_file, FDE_LABEL, for_eh + i * 2);
2045 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2046 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2047 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2048 "FDE Length");
2049 ASM_OUTPUT_LABEL (asm_out_file, l1);
2051 if (for_eh)
2052 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2053 else
2054 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2055 "FDE CIE offset");
2057 if (for_eh)
2059 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2060 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
2061 "FDE initial location");
2062 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2063 fde->dw_fde_end, fde->dw_fde_begin,
2064 "FDE address range");
2066 else
2068 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2069 "FDE initial location");
2070 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2071 fde->dw_fde_end, fde->dw_fde_begin,
2072 "FDE address range");
2075 if (augmentation[0])
2077 if (any_lsda_needed)
2079 int size = size_of_encoded_value (lsda_encoding);
2081 if (lsda_encoding == DW_EH_PE_aligned)
2083 int offset = ( 4 /* Length */
2084 + 4 /* CIE offset */
2085 + 2 * size_of_encoded_value (fde_encoding)
2086 + 1 /* Augmentation size */ );
2087 int pad = -offset & (PTR_SIZE - 1);
2089 size += pad;
2090 if (size_of_uleb128 (size) != 1)
2091 abort ();
2094 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2096 if (fde->uses_eh_lsda)
2098 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2099 fde->funcdef_number);
2100 dw2_asm_output_encoded_addr_rtx (
2101 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2102 "Language Specific Data Area");
2104 else
2106 if (lsda_encoding == DW_EH_PE_aligned)
2107 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2108 dw2_asm_output_data
2109 (size_of_encoded_value (lsda_encoding), 0,
2110 "Language Specific Data Area (none)");
2113 else
2114 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2117 /* Loop through the Call Frame Instructions associated with
2118 this FDE. */
2119 fde->dw_fde_current_label = fde->dw_fde_begin;
2120 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2121 output_cfi (cfi, fde, for_eh);
2123 /* Pad the FDE out to an address sized boundary. */
2124 ASM_OUTPUT_ALIGN (asm_out_file,
2125 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2126 ASM_OUTPUT_LABEL (asm_out_file, l2);
2129 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2130 dw2_asm_output_data (4, 0, "End of Table");
2131 #ifdef MIPS_DEBUGGING_INFO
2132 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2133 get a value of 0. Putting .align 0 after the label fixes it. */
2134 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2135 #endif
2137 /* Turn off app to make assembly quicker. */
2138 if (flag_debug_asm)
2139 app_disable ();
2142 /* Output a marker (i.e. a label) for the beginning of a function, before
2143 the prologue. */
2145 void
2146 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2147 const char *file ATTRIBUTE_UNUSED)
2149 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2150 dw_fde_ref fde;
2152 current_function_func_begin_label = 0;
2154 #ifdef IA64_UNWIND_INFO
2155 /* ??? current_function_func_begin_label is also used by except.c
2156 for call-site information. We must emit this label if it might
2157 be used. */
2158 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2159 && ! dwarf2out_do_frame ())
2160 return;
2161 #else
2162 if (! dwarf2out_do_frame ())
2163 return;
2164 #endif
2166 function_section (current_function_decl);
2167 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2168 current_function_funcdef_no);
2169 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2170 current_function_funcdef_no);
2171 current_function_func_begin_label = get_identifier (label);
2173 #ifdef IA64_UNWIND_INFO
2174 /* We can elide the fde allocation if we're not emitting debug info. */
2175 if (! dwarf2out_do_frame ())
2176 return;
2177 #endif
2179 /* Expand the fde table if necessary. */
2180 if (fde_table_in_use == fde_table_allocated)
2182 fde_table_allocated += FDE_TABLE_INCREMENT;
2183 fde_table = ggc_realloc (fde_table,
2184 fde_table_allocated * sizeof (dw_fde_node));
2185 memset (fde_table + fde_table_in_use, 0,
2186 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2189 /* Record the FDE associated with this function. */
2190 current_funcdef_fde = fde_table_in_use;
2192 /* Add the new FDE at the end of the fde_table. */
2193 fde = &fde_table[fde_table_in_use++];
2194 fde->dw_fde_begin = xstrdup (label);
2195 fde->dw_fde_current_label = NULL;
2196 fde->dw_fde_end = NULL;
2197 fde->dw_fde_cfi = NULL;
2198 fde->funcdef_number = current_function_funcdef_no;
2199 fde->nothrow = current_function_nothrow;
2200 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2201 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2203 args_size = old_args_size = 0;
2205 /* We only want to output line number information for the genuine dwarf2
2206 prologue case, not the eh frame case. */
2207 #ifdef DWARF2_DEBUGGING_INFO
2208 if (file)
2209 dwarf2out_source_line (line, file);
2210 #endif
2213 /* Output a marker (i.e. a label) for the absolute end of the generated code
2214 for a function definition. This gets called *after* the epilogue code has
2215 been generated. */
2217 void
2218 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2219 const char *file ATTRIBUTE_UNUSED)
2221 dw_fde_ref fde;
2222 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2224 /* Output a label to mark the endpoint of the code generated for this
2225 function. */
2226 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2227 current_function_funcdef_no);
2228 ASM_OUTPUT_LABEL (asm_out_file, label);
2229 fde = &fde_table[fde_table_in_use - 1];
2230 fde->dw_fde_end = xstrdup (label);
2233 void
2234 dwarf2out_frame_init (void)
2236 /* Allocate the initial hunk of the fde_table. */
2237 fde_table = (dw_fde_ref) ggc_alloc_cleared (FDE_TABLE_INCREMENT
2238 * sizeof (dw_fde_node));
2239 fde_table_allocated = FDE_TABLE_INCREMENT;
2240 fde_table_in_use = 0;
2242 /* Generate the CFA instructions common to all FDE's. Do it now for the
2243 sake of lookup_cfa. */
2245 #ifdef DWARF2_UNWIND_INFO
2246 /* On entry, the Canonical Frame Address is at SP. */
2247 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2248 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2249 #endif
2252 void
2253 dwarf2out_frame_finish (void)
2255 /* Output call frame information. */
2256 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2257 output_call_frame_info (0);
2259 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2260 output_call_frame_info (1);
2262 #endif
2264 /* And now, the subset of the debugging information support code necessary
2265 for emitting location expressions. */
2267 /* We need some way to distinguish DW_OP_addr with a direct symbol
2268 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2269 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2272 typedef struct dw_val_struct *dw_val_ref;
2273 typedef struct die_struct *dw_die_ref;
2274 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2275 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2277 /* Each DIE may have a series of attribute/value pairs. Values
2278 can take on several forms. The forms that are used in this
2279 implementation are listed below. */
2281 enum dw_val_class
2283 dw_val_class_addr,
2284 dw_val_class_offset,
2285 dw_val_class_loc,
2286 dw_val_class_loc_list,
2287 dw_val_class_range_list,
2288 dw_val_class_const,
2289 dw_val_class_unsigned_const,
2290 dw_val_class_long_long,
2291 dw_val_class_float,
2292 dw_val_class_flag,
2293 dw_val_class_die_ref,
2294 dw_val_class_fde_ref,
2295 dw_val_class_lbl_id,
2296 dw_val_class_lbl_offset,
2297 dw_val_class_str
2300 /* Describe a double word constant value. */
2301 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2303 typedef struct dw_long_long_struct GTY(())
2305 unsigned long hi;
2306 unsigned long low;
2308 dw_long_long_const;
2310 /* Describe a floating point constant value. */
2312 typedef struct dw_fp_struct GTY(())
2314 long * GTY((length ("%h.length"))) array;
2315 unsigned length;
2317 dw_float_const;
2319 /* The dw_val_node describes an attribute's value, as it is
2320 represented internally. */
2322 typedef struct dw_val_struct GTY(())
2324 enum dw_val_class val_class;
2325 union dw_val_struct_union
2327 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2328 long unsigned GTY ((tag ("dw_val_class_offset"))) val_offset;
2329 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2330 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2331 long int GTY ((default (""))) val_int;
2332 long unsigned GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2333 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2334 dw_float_const GTY ((tag ("dw_val_class_float"))) val_float;
2335 struct dw_val_die_union
2337 dw_die_ref die;
2338 int external;
2339 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2340 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2341 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2342 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2343 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2345 GTY ((desc ("%1.val_class"))) v;
2347 dw_val_node;
2349 /* Locations in memory are described using a sequence of stack machine
2350 operations. */
2352 typedef struct dw_loc_descr_struct GTY(())
2354 dw_loc_descr_ref dw_loc_next;
2355 enum dwarf_location_atom dw_loc_opc;
2356 dw_val_node dw_loc_oprnd1;
2357 dw_val_node dw_loc_oprnd2;
2358 int dw_loc_addr;
2360 dw_loc_descr_node;
2362 /* Location lists are ranges + location descriptions for that range,
2363 so you can track variables that are in different places over
2364 their entire life. */
2365 typedef struct dw_loc_list_struct GTY(())
2367 dw_loc_list_ref dw_loc_next;
2368 const char *begin; /* Label for begin address of range */
2369 const char *end; /* Label for end address of range */
2370 char *ll_symbol; /* Label for beginning of location list.
2371 Only on head of list */
2372 const char *section; /* Section this loclist is relative to */
2373 dw_loc_descr_ref expr;
2374 } dw_loc_list_node;
2376 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2378 static const char *dwarf_stack_op_name (unsigned);
2379 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2380 unsigned long, unsigned long);
2381 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2382 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2383 static unsigned long size_of_locs (dw_loc_descr_ref);
2384 static void output_loc_operands (dw_loc_descr_ref);
2385 static void output_loc_sequence (dw_loc_descr_ref);
2387 /* Convert a DWARF stack opcode into its string name. */
2389 static const char *
2390 dwarf_stack_op_name (unsigned int op)
2392 switch (op)
2394 case DW_OP_addr:
2395 case INTERNAL_DW_OP_tls_addr:
2396 return "DW_OP_addr";
2397 case DW_OP_deref:
2398 return "DW_OP_deref";
2399 case DW_OP_const1u:
2400 return "DW_OP_const1u";
2401 case DW_OP_const1s:
2402 return "DW_OP_const1s";
2403 case DW_OP_const2u:
2404 return "DW_OP_const2u";
2405 case DW_OP_const2s:
2406 return "DW_OP_const2s";
2407 case DW_OP_const4u:
2408 return "DW_OP_const4u";
2409 case DW_OP_const4s:
2410 return "DW_OP_const4s";
2411 case DW_OP_const8u:
2412 return "DW_OP_const8u";
2413 case DW_OP_const8s:
2414 return "DW_OP_const8s";
2415 case DW_OP_constu:
2416 return "DW_OP_constu";
2417 case DW_OP_consts:
2418 return "DW_OP_consts";
2419 case DW_OP_dup:
2420 return "DW_OP_dup";
2421 case DW_OP_drop:
2422 return "DW_OP_drop";
2423 case DW_OP_over:
2424 return "DW_OP_over";
2425 case DW_OP_pick:
2426 return "DW_OP_pick";
2427 case DW_OP_swap:
2428 return "DW_OP_swap";
2429 case DW_OP_rot:
2430 return "DW_OP_rot";
2431 case DW_OP_xderef:
2432 return "DW_OP_xderef";
2433 case DW_OP_abs:
2434 return "DW_OP_abs";
2435 case DW_OP_and:
2436 return "DW_OP_and";
2437 case DW_OP_div:
2438 return "DW_OP_div";
2439 case DW_OP_minus:
2440 return "DW_OP_minus";
2441 case DW_OP_mod:
2442 return "DW_OP_mod";
2443 case DW_OP_mul:
2444 return "DW_OP_mul";
2445 case DW_OP_neg:
2446 return "DW_OP_neg";
2447 case DW_OP_not:
2448 return "DW_OP_not";
2449 case DW_OP_or:
2450 return "DW_OP_or";
2451 case DW_OP_plus:
2452 return "DW_OP_plus";
2453 case DW_OP_plus_uconst:
2454 return "DW_OP_plus_uconst";
2455 case DW_OP_shl:
2456 return "DW_OP_shl";
2457 case DW_OP_shr:
2458 return "DW_OP_shr";
2459 case DW_OP_shra:
2460 return "DW_OP_shra";
2461 case DW_OP_xor:
2462 return "DW_OP_xor";
2463 case DW_OP_bra:
2464 return "DW_OP_bra";
2465 case DW_OP_eq:
2466 return "DW_OP_eq";
2467 case DW_OP_ge:
2468 return "DW_OP_ge";
2469 case DW_OP_gt:
2470 return "DW_OP_gt";
2471 case DW_OP_le:
2472 return "DW_OP_le";
2473 case DW_OP_lt:
2474 return "DW_OP_lt";
2475 case DW_OP_ne:
2476 return "DW_OP_ne";
2477 case DW_OP_skip:
2478 return "DW_OP_skip";
2479 case DW_OP_lit0:
2480 return "DW_OP_lit0";
2481 case DW_OP_lit1:
2482 return "DW_OP_lit1";
2483 case DW_OP_lit2:
2484 return "DW_OP_lit2";
2485 case DW_OP_lit3:
2486 return "DW_OP_lit3";
2487 case DW_OP_lit4:
2488 return "DW_OP_lit4";
2489 case DW_OP_lit5:
2490 return "DW_OP_lit5";
2491 case DW_OP_lit6:
2492 return "DW_OP_lit6";
2493 case DW_OP_lit7:
2494 return "DW_OP_lit7";
2495 case DW_OP_lit8:
2496 return "DW_OP_lit8";
2497 case DW_OP_lit9:
2498 return "DW_OP_lit9";
2499 case DW_OP_lit10:
2500 return "DW_OP_lit10";
2501 case DW_OP_lit11:
2502 return "DW_OP_lit11";
2503 case DW_OP_lit12:
2504 return "DW_OP_lit12";
2505 case DW_OP_lit13:
2506 return "DW_OP_lit13";
2507 case DW_OP_lit14:
2508 return "DW_OP_lit14";
2509 case DW_OP_lit15:
2510 return "DW_OP_lit15";
2511 case DW_OP_lit16:
2512 return "DW_OP_lit16";
2513 case DW_OP_lit17:
2514 return "DW_OP_lit17";
2515 case DW_OP_lit18:
2516 return "DW_OP_lit18";
2517 case DW_OP_lit19:
2518 return "DW_OP_lit19";
2519 case DW_OP_lit20:
2520 return "DW_OP_lit20";
2521 case DW_OP_lit21:
2522 return "DW_OP_lit21";
2523 case DW_OP_lit22:
2524 return "DW_OP_lit22";
2525 case DW_OP_lit23:
2526 return "DW_OP_lit23";
2527 case DW_OP_lit24:
2528 return "DW_OP_lit24";
2529 case DW_OP_lit25:
2530 return "DW_OP_lit25";
2531 case DW_OP_lit26:
2532 return "DW_OP_lit26";
2533 case DW_OP_lit27:
2534 return "DW_OP_lit27";
2535 case DW_OP_lit28:
2536 return "DW_OP_lit28";
2537 case DW_OP_lit29:
2538 return "DW_OP_lit29";
2539 case DW_OP_lit30:
2540 return "DW_OP_lit30";
2541 case DW_OP_lit31:
2542 return "DW_OP_lit31";
2543 case DW_OP_reg0:
2544 return "DW_OP_reg0";
2545 case DW_OP_reg1:
2546 return "DW_OP_reg1";
2547 case DW_OP_reg2:
2548 return "DW_OP_reg2";
2549 case DW_OP_reg3:
2550 return "DW_OP_reg3";
2551 case DW_OP_reg4:
2552 return "DW_OP_reg4";
2553 case DW_OP_reg5:
2554 return "DW_OP_reg5";
2555 case DW_OP_reg6:
2556 return "DW_OP_reg6";
2557 case DW_OP_reg7:
2558 return "DW_OP_reg7";
2559 case DW_OP_reg8:
2560 return "DW_OP_reg8";
2561 case DW_OP_reg9:
2562 return "DW_OP_reg9";
2563 case DW_OP_reg10:
2564 return "DW_OP_reg10";
2565 case DW_OP_reg11:
2566 return "DW_OP_reg11";
2567 case DW_OP_reg12:
2568 return "DW_OP_reg12";
2569 case DW_OP_reg13:
2570 return "DW_OP_reg13";
2571 case DW_OP_reg14:
2572 return "DW_OP_reg14";
2573 case DW_OP_reg15:
2574 return "DW_OP_reg15";
2575 case DW_OP_reg16:
2576 return "DW_OP_reg16";
2577 case DW_OP_reg17:
2578 return "DW_OP_reg17";
2579 case DW_OP_reg18:
2580 return "DW_OP_reg18";
2581 case DW_OP_reg19:
2582 return "DW_OP_reg19";
2583 case DW_OP_reg20:
2584 return "DW_OP_reg20";
2585 case DW_OP_reg21:
2586 return "DW_OP_reg21";
2587 case DW_OP_reg22:
2588 return "DW_OP_reg22";
2589 case DW_OP_reg23:
2590 return "DW_OP_reg23";
2591 case DW_OP_reg24:
2592 return "DW_OP_reg24";
2593 case DW_OP_reg25:
2594 return "DW_OP_reg25";
2595 case DW_OP_reg26:
2596 return "DW_OP_reg26";
2597 case DW_OP_reg27:
2598 return "DW_OP_reg27";
2599 case DW_OP_reg28:
2600 return "DW_OP_reg28";
2601 case DW_OP_reg29:
2602 return "DW_OP_reg29";
2603 case DW_OP_reg30:
2604 return "DW_OP_reg30";
2605 case DW_OP_reg31:
2606 return "DW_OP_reg31";
2607 case DW_OP_breg0:
2608 return "DW_OP_breg0";
2609 case DW_OP_breg1:
2610 return "DW_OP_breg1";
2611 case DW_OP_breg2:
2612 return "DW_OP_breg2";
2613 case DW_OP_breg3:
2614 return "DW_OP_breg3";
2615 case DW_OP_breg4:
2616 return "DW_OP_breg4";
2617 case DW_OP_breg5:
2618 return "DW_OP_breg5";
2619 case DW_OP_breg6:
2620 return "DW_OP_breg6";
2621 case DW_OP_breg7:
2622 return "DW_OP_breg7";
2623 case DW_OP_breg8:
2624 return "DW_OP_breg8";
2625 case DW_OP_breg9:
2626 return "DW_OP_breg9";
2627 case DW_OP_breg10:
2628 return "DW_OP_breg10";
2629 case DW_OP_breg11:
2630 return "DW_OP_breg11";
2631 case DW_OP_breg12:
2632 return "DW_OP_breg12";
2633 case DW_OP_breg13:
2634 return "DW_OP_breg13";
2635 case DW_OP_breg14:
2636 return "DW_OP_breg14";
2637 case DW_OP_breg15:
2638 return "DW_OP_breg15";
2639 case DW_OP_breg16:
2640 return "DW_OP_breg16";
2641 case DW_OP_breg17:
2642 return "DW_OP_breg17";
2643 case DW_OP_breg18:
2644 return "DW_OP_breg18";
2645 case DW_OP_breg19:
2646 return "DW_OP_breg19";
2647 case DW_OP_breg20:
2648 return "DW_OP_breg20";
2649 case DW_OP_breg21:
2650 return "DW_OP_breg21";
2651 case DW_OP_breg22:
2652 return "DW_OP_breg22";
2653 case DW_OP_breg23:
2654 return "DW_OP_breg23";
2655 case DW_OP_breg24:
2656 return "DW_OP_breg24";
2657 case DW_OP_breg25:
2658 return "DW_OP_breg25";
2659 case DW_OP_breg26:
2660 return "DW_OP_breg26";
2661 case DW_OP_breg27:
2662 return "DW_OP_breg27";
2663 case DW_OP_breg28:
2664 return "DW_OP_breg28";
2665 case DW_OP_breg29:
2666 return "DW_OP_breg29";
2667 case DW_OP_breg30:
2668 return "DW_OP_breg30";
2669 case DW_OP_breg31:
2670 return "DW_OP_breg31";
2671 case DW_OP_regx:
2672 return "DW_OP_regx";
2673 case DW_OP_fbreg:
2674 return "DW_OP_fbreg";
2675 case DW_OP_bregx:
2676 return "DW_OP_bregx";
2677 case DW_OP_piece:
2678 return "DW_OP_piece";
2679 case DW_OP_deref_size:
2680 return "DW_OP_deref_size";
2681 case DW_OP_xderef_size:
2682 return "DW_OP_xderef_size";
2683 case DW_OP_nop:
2684 return "DW_OP_nop";
2685 case DW_OP_push_object_address:
2686 return "DW_OP_push_object_address";
2687 case DW_OP_call2:
2688 return "DW_OP_call2";
2689 case DW_OP_call4:
2690 return "DW_OP_call4";
2691 case DW_OP_call_ref:
2692 return "DW_OP_call_ref";
2693 case DW_OP_GNU_push_tls_address:
2694 return "DW_OP_GNU_push_tls_address";
2695 default:
2696 return "OP_<unknown>";
2700 /* Return a pointer to a newly allocated location description. Location
2701 descriptions are simple expression terms that can be strung
2702 together to form more complicated location (address) descriptions. */
2704 static inline dw_loc_descr_ref
2705 new_loc_descr (enum dwarf_location_atom op, long unsigned int oprnd1,
2706 long unsigned int oprnd2)
2708 dw_loc_descr_ref descr
2709 = (dw_loc_descr_ref) ggc_alloc_cleared (sizeof (dw_loc_descr_node));
2711 descr->dw_loc_opc = op;
2712 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2713 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2714 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2715 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2717 return descr;
2721 /* Add a location description term to a location description expression. */
2723 static inline void
2724 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
2726 dw_loc_descr_ref *d;
2728 /* Find the end of the chain. */
2729 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2732 *d = descr;
2735 /* Return the size of a location descriptor. */
2737 static unsigned long
2738 size_of_loc_descr (dw_loc_descr_ref loc)
2740 unsigned long size = 1;
2742 switch (loc->dw_loc_opc)
2744 case DW_OP_addr:
2745 case INTERNAL_DW_OP_tls_addr:
2746 size += DWARF2_ADDR_SIZE;
2747 break;
2748 case DW_OP_const1u:
2749 case DW_OP_const1s:
2750 size += 1;
2751 break;
2752 case DW_OP_const2u:
2753 case DW_OP_const2s:
2754 size += 2;
2755 break;
2756 case DW_OP_const4u:
2757 case DW_OP_const4s:
2758 size += 4;
2759 break;
2760 case DW_OP_const8u:
2761 case DW_OP_const8s:
2762 size += 8;
2763 break;
2764 case DW_OP_constu:
2765 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2766 break;
2767 case DW_OP_consts:
2768 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2769 break;
2770 case DW_OP_pick:
2771 size += 1;
2772 break;
2773 case DW_OP_plus_uconst:
2774 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2775 break;
2776 case DW_OP_skip:
2777 case DW_OP_bra:
2778 size += 2;
2779 break;
2780 case DW_OP_breg0:
2781 case DW_OP_breg1:
2782 case DW_OP_breg2:
2783 case DW_OP_breg3:
2784 case DW_OP_breg4:
2785 case DW_OP_breg5:
2786 case DW_OP_breg6:
2787 case DW_OP_breg7:
2788 case DW_OP_breg8:
2789 case DW_OP_breg9:
2790 case DW_OP_breg10:
2791 case DW_OP_breg11:
2792 case DW_OP_breg12:
2793 case DW_OP_breg13:
2794 case DW_OP_breg14:
2795 case DW_OP_breg15:
2796 case DW_OP_breg16:
2797 case DW_OP_breg17:
2798 case DW_OP_breg18:
2799 case DW_OP_breg19:
2800 case DW_OP_breg20:
2801 case DW_OP_breg21:
2802 case DW_OP_breg22:
2803 case DW_OP_breg23:
2804 case DW_OP_breg24:
2805 case DW_OP_breg25:
2806 case DW_OP_breg26:
2807 case DW_OP_breg27:
2808 case DW_OP_breg28:
2809 case DW_OP_breg29:
2810 case DW_OP_breg30:
2811 case DW_OP_breg31:
2812 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2813 break;
2814 case DW_OP_regx:
2815 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2816 break;
2817 case DW_OP_fbreg:
2818 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2819 break;
2820 case DW_OP_bregx:
2821 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2822 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2823 break;
2824 case DW_OP_piece:
2825 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2826 break;
2827 case DW_OP_deref_size:
2828 case DW_OP_xderef_size:
2829 size += 1;
2830 break;
2831 case DW_OP_call2:
2832 size += 2;
2833 break;
2834 case DW_OP_call4:
2835 size += 4;
2836 break;
2837 case DW_OP_call_ref:
2838 size += DWARF2_ADDR_SIZE;
2839 break;
2840 default:
2841 break;
2844 return size;
2847 /* Return the size of a series of location descriptors. */
2849 static unsigned long
2850 size_of_locs (dw_loc_descr_ref loc)
2852 unsigned long size;
2854 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2856 loc->dw_loc_addr = size;
2857 size += size_of_loc_descr (loc);
2860 return size;
2863 /* Output location description stack opcode's operands (if any). */
2865 static void
2866 output_loc_operands (dw_loc_descr_ref loc)
2868 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2869 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2871 switch (loc->dw_loc_opc)
2873 #ifdef DWARF2_DEBUGGING_INFO
2874 case DW_OP_addr:
2875 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2876 break;
2877 case DW_OP_const2u:
2878 case DW_OP_const2s:
2879 dw2_asm_output_data (2, val1->v.val_int, NULL);
2880 break;
2881 case DW_OP_const4u:
2882 case DW_OP_const4s:
2883 dw2_asm_output_data (4, val1->v.val_int, NULL);
2884 break;
2885 case DW_OP_const8u:
2886 case DW_OP_const8s:
2887 if (HOST_BITS_PER_LONG < 64)
2888 abort ();
2889 dw2_asm_output_data (8, val1->v.val_int, NULL);
2890 break;
2891 case DW_OP_skip:
2892 case DW_OP_bra:
2894 int offset;
2896 if (val1->val_class == dw_val_class_loc)
2897 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2898 else
2899 abort ();
2901 dw2_asm_output_data (2, offset, NULL);
2903 break;
2904 #else
2905 case DW_OP_addr:
2906 case DW_OP_const2u:
2907 case DW_OP_const2s:
2908 case DW_OP_const4u:
2909 case DW_OP_const4s:
2910 case DW_OP_const8u:
2911 case DW_OP_const8s:
2912 case DW_OP_skip:
2913 case DW_OP_bra:
2914 /* We currently don't make any attempt to make sure these are
2915 aligned properly like we do for the main unwind info, so
2916 don't support emitting things larger than a byte if we're
2917 only doing unwinding. */
2918 abort ();
2919 #endif
2920 case DW_OP_const1u:
2921 case DW_OP_const1s:
2922 dw2_asm_output_data (1, val1->v.val_int, NULL);
2923 break;
2924 case DW_OP_constu:
2925 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2926 break;
2927 case DW_OP_consts:
2928 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2929 break;
2930 case DW_OP_pick:
2931 dw2_asm_output_data (1, val1->v.val_int, NULL);
2932 break;
2933 case DW_OP_plus_uconst:
2934 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2935 break;
2936 case DW_OP_breg0:
2937 case DW_OP_breg1:
2938 case DW_OP_breg2:
2939 case DW_OP_breg3:
2940 case DW_OP_breg4:
2941 case DW_OP_breg5:
2942 case DW_OP_breg6:
2943 case DW_OP_breg7:
2944 case DW_OP_breg8:
2945 case DW_OP_breg9:
2946 case DW_OP_breg10:
2947 case DW_OP_breg11:
2948 case DW_OP_breg12:
2949 case DW_OP_breg13:
2950 case DW_OP_breg14:
2951 case DW_OP_breg15:
2952 case DW_OP_breg16:
2953 case DW_OP_breg17:
2954 case DW_OP_breg18:
2955 case DW_OP_breg19:
2956 case DW_OP_breg20:
2957 case DW_OP_breg21:
2958 case DW_OP_breg22:
2959 case DW_OP_breg23:
2960 case DW_OP_breg24:
2961 case DW_OP_breg25:
2962 case DW_OP_breg26:
2963 case DW_OP_breg27:
2964 case DW_OP_breg28:
2965 case DW_OP_breg29:
2966 case DW_OP_breg30:
2967 case DW_OP_breg31:
2968 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2969 break;
2970 case DW_OP_regx:
2971 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2972 break;
2973 case DW_OP_fbreg:
2974 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2975 break;
2976 case DW_OP_bregx:
2977 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2978 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2979 break;
2980 case DW_OP_piece:
2981 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2982 break;
2983 case DW_OP_deref_size:
2984 case DW_OP_xderef_size:
2985 dw2_asm_output_data (1, val1->v.val_int, NULL);
2986 break;
2988 case INTERNAL_DW_OP_tls_addr:
2989 #ifdef ASM_OUTPUT_DWARF_DTPREL
2990 ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE,
2991 val1->v.val_addr);
2992 fputc ('\n', asm_out_file);
2993 #else
2994 abort ();
2995 #endif
2996 break;
2998 default:
2999 /* Other codes have no operands. */
3000 break;
3004 /* Output a sequence of location operations. */
3006 static void
3007 output_loc_sequence (dw_loc_descr_ref loc)
3009 for (; loc != NULL; loc = loc->dw_loc_next)
3011 /* Output the opcode. */
3012 dw2_asm_output_data (1, loc->dw_loc_opc,
3013 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3015 /* Output the operand(s) (if any). */
3016 output_loc_operands (loc);
3020 /* This routine will generate the correct assembly data for a location
3021 description based on a cfi entry with a complex address. */
3023 static void
3024 output_cfa_loc (dw_cfi_ref cfi)
3026 dw_loc_descr_ref loc;
3027 unsigned long size;
3029 /* Output the size of the block. */
3030 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3031 size = size_of_locs (loc);
3032 dw2_asm_output_data_uleb128 (size, NULL);
3034 /* Now output the operations themselves. */
3035 output_loc_sequence (loc);
3038 /* This function builds a dwarf location descriptor sequence from
3039 a dw_cfa_location. */
3041 static struct dw_loc_descr_struct *
3042 build_cfa_loc (dw_cfa_location *cfa)
3044 struct dw_loc_descr_struct *head, *tmp;
3046 if (cfa->indirect == 0)
3047 abort ();
3049 if (cfa->base_offset)
3051 if (cfa->reg <= 31)
3052 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3053 else
3054 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3056 else if (cfa->reg <= 31)
3057 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3058 else
3059 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3061 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3062 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3063 add_loc_descr (&head, tmp);
3064 if (cfa->offset != 0)
3066 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3067 add_loc_descr (&head, tmp);
3070 return head;
3073 /* This function fills in aa dw_cfa_location structure from a dwarf location
3074 descriptor sequence. */
3076 static void
3077 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3079 struct dw_loc_descr_struct *ptr;
3080 cfa->offset = 0;
3081 cfa->base_offset = 0;
3082 cfa->indirect = 0;
3083 cfa->reg = -1;
3085 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3087 enum dwarf_location_atom op = ptr->dw_loc_opc;
3089 switch (op)
3091 case DW_OP_reg0:
3092 case DW_OP_reg1:
3093 case DW_OP_reg2:
3094 case DW_OP_reg3:
3095 case DW_OP_reg4:
3096 case DW_OP_reg5:
3097 case DW_OP_reg6:
3098 case DW_OP_reg7:
3099 case DW_OP_reg8:
3100 case DW_OP_reg9:
3101 case DW_OP_reg10:
3102 case DW_OP_reg11:
3103 case DW_OP_reg12:
3104 case DW_OP_reg13:
3105 case DW_OP_reg14:
3106 case DW_OP_reg15:
3107 case DW_OP_reg16:
3108 case DW_OP_reg17:
3109 case DW_OP_reg18:
3110 case DW_OP_reg19:
3111 case DW_OP_reg20:
3112 case DW_OP_reg21:
3113 case DW_OP_reg22:
3114 case DW_OP_reg23:
3115 case DW_OP_reg24:
3116 case DW_OP_reg25:
3117 case DW_OP_reg26:
3118 case DW_OP_reg27:
3119 case DW_OP_reg28:
3120 case DW_OP_reg29:
3121 case DW_OP_reg30:
3122 case DW_OP_reg31:
3123 cfa->reg = op - DW_OP_reg0;
3124 break;
3125 case DW_OP_regx:
3126 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3127 break;
3128 case DW_OP_breg0:
3129 case DW_OP_breg1:
3130 case DW_OP_breg2:
3131 case DW_OP_breg3:
3132 case DW_OP_breg4:
3133 case DW_OP_breg5:
3134 case DW_OP_breg6:
3135 case DW_OP_breg7:
3136 case DW_OP_breg8:
3137 case DW_OP_breg9:
3138 case DW_OP_breg10:
3139 case DW_OP_breg11:
3140 case DW_OP_breg12:
3141 case DW_OP_breg13:
3142 case DW_OP_breg14:
3143 case DW_OP_breg15:
3144 case DW_OP_breg16:
3145 case DW_OP_breg17:
3146 case DW_OP_breg18:
3147 case DW_OP_breg19:
3148 case DW_OP_breg20:
3149 case DW_OP_breg21:
3150 case DW_OP_breg22:
3151 case DW_OP_breg23:
3152 case DW_OP_breg24:
3153 case DW_OP_breg25:
3154 case DW_OP_breg26:
3155 case DW_OP_breg27:
3156 case DW_OP_breg28:
3157 case DW_OP_breg29:
3158 case DW_OP_breg30:
3159 case DW_OP_breg31:
3160 cfa->reg = op - DW_OP_breg0;
3161 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3162 break;
3163 case DW_OP_bregx:
3164 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3165 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3166 break;
3167 case DW_OP_deref:
3168 cfa->indirect = 1;
3169 break;
3170 case DW_OP_plus_uconst:
3171 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3172 break;
3173 default:
3174 internal_error ("DW_LOC_OP %s not implemented\n",
3175 dwarf_stack_op_name (ptr->dw_loc_opc));
3179 #endif /* .debug_frame support */
3181 /* And now, the support for symbolic debugging information. */
3182 #ifdef DWARF2_DEBUGGING_INFO
3184 /* .debug_str support. */
3185 static int output_indirect_string (void **, void *);
3187 static void dwarf2out_init (const char *);
3188 static void dwarf2out_finish (const char *);
3189 static void dwarf2out_define (unsigned int, const char *);
3190 static void dwarf2out_undef (unsigned int, const char *);
3191 static void dwarf2out_start_source_file (unsigned, const char *);
3192 static void dwarf2out_end_source_file (unsigned);
3193 static void dwarf2out_begin_block (unsigned, unsigned);
3194 static void dwarf2out_end_block (unsigned, unsigned);
3195 static bool dwarf2out_ignore_block (tree);
3196 static void dwarf2out_global_decl (tree);
3197 static void dwarf2out_abstract_function (tree);
3199 /* The debug hooks structure. */
3201 const struct gcc_debug_hooks dwarf2_debug_hooks =
3203 dwarf2out_init,
3204 dwarf2out_finish,
3205 dwarf2out_define,
3206 dwarf2out_undef,
3207 dwarf2out_start_source_file,
3208 dwarf2out_end_source_file,
3209 dwarf2out_begin_block,
3210 dwarf2out_end_block,
3211 dwarf2out_ignore_block,
3212 dwarf2out_source_line,
3213 dwarf2out_begin_prologue,
3214 debug_nothing_int_charstar, /* end_prologue */
3215 dwarf2out_end_epilogue,
3216 debug_nothing_tree, /* begin_function */
3217 debug_nothing_int, /* end_function */
3218 dwarf2out_decl, /* function_decl */
3219 dwarf2out_global_decl,
3220 debug_nothing_tree, /* deferred_inline_function */
3221 /* The DWARF 2 backend tries to reduce debugging bloat by not
3222 emitting the abstract description of inline functions until
3223 something tries to reference them. */
3224 dwarf2out_abstract_function, /* outlining_inline_function */
3225 debug_nothing_rtx, /* label */
3226 debug_nothing_int /* handle_pch */
3228 #endif
3230 /* NOTE: In the comments in this file, many references are made to
3231 "Debugging Information Entries". This term is abbreviated as `DIE'
3232 throughout the remainder of this file. */
3234 /* An internal representation of the DWARF output is built, and then
3235 walked to generate the DWARF debugging info. The walk of the internal
3236 representation is done after the entire program has been compiled.
3237 The types below are used to describe the internal representation. */
3239 /* Various DIE's use offsets relative to the beginning of the
3240 .debug_info section to refer to each other. */
3242 typedef long int dw_offset;
3244 /* Define typedefs here to avoid circular dependencies. */
3246 typedef struct dw_attr_struct *dw_attr_ref;
3247 typedef struct dw_line_info_struct *dw_line_info_ref;
3248 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3249 typedef struct pubname_struct *pubname_ref;
3250 typedef struct dw_ranges_struct *dw_ranges_ref;
3252 /* Each entry in the line_info_table maintains the file and
3253 line number associated with the label generated for that
3254 entry. The label gives the PC value associated with
3255 the line number entry. */
3257 typedef struct dw_line_info_struct GTY(())
3259 unsigned long dw_file_num;
3260 unsigned long dw_line_num;
3262 dw_line_info_entry;
3264 /* Line information for functions in separate sections; each one gets its
3265 own sequence. */
3266 typedef struct dw_separate_line_info_struct GTY(())
3268 unsigned long dw_file_num;
3269 unsigned long dw_line_num;
3270 unsigned long function;
3272 dw_separate_line_info_entry;
3274 /* Each DIE attribute has a field specifying the attribute kind,
3275 a link to the next attribute in the chain, and an attribute value.
3276 Attributes are typically linked below the DIE they modify. */
3278 typedef struct dw_attr_struct GTY(())
3280 enum dwarf_attribute dw_attr;
3281 dw_attr_ref dw_attr_next;
3282 dw_val_node dw_attr_val;
3284 dw_attr_node;
3286 /* The Debugging Information Entry (DIE) structure */
3288 typedef struct die_struct GTY(())
3290 enum dwarf_tag die_tag;
3291 char *die_symbol;
3292 dw_attr_ref die_attr;
3293 dw_die_ref die_parent;
3294 dw_die_ref die_child;
3295 dw_die_ref die_sib;
3296 dw_offset die_offset;
3297 unsigned long die_abbrev;
3298 int die_mark;
3300 die_node;
3302 /* The pubname structure */
3304 typedef struct pubname_struct GTY(())
3306 dw_die_ref die;
3307 char *name;
3309 pubname_entry;
3311 struct dw_ranges_struct GTY(())
3313 int block_num;
3316 /* The limbo die list structure. */
3317 typedef struct limbo_die_struct GTY(())
3319 dw_die_ref die;
3320 tree created_for;
3321 struct limbo_die_struct *next;
3323 limbo_die_node;
3325 /* How to start an assembler comment. */
3326 #ifndef ASM_COMMENT_START
3327 #define ASM_COMMENT_START ";#"
3328 #endif
3330 /* Define a macro which returns nonzero for a TYPE_DECL which was
3331 implicitly generated for a tagged type.
3333 Note that unlike the gcc front end (which generates a NULL named
3334 TYPE_DECL node for each complete tagged type, each array type, and
3335 each function type node created) the g++ front end generates a
3336 _named_ TYPE_DECL node for each tagged type node created.
3337 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3338 generate a DW_TAG_typedef DIE for them. */
3340 #define TYPE_DECL_IS_STUB(decl) \
3341 (DECL_NAME (decl) == NULL_TREE \
3342 || (DECL_ARTIFICIAL (decl) \
3343 && is_tagged_type (TREE_TYPE (decl)) \
3344 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3345 /* This is necessary for stub decls that \
3346 appear in nested inline functions. */ \
3347 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3348 && (decl_ultimate_origin (decl) \
3349 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3351 /* Information concerning the compilation unit's programming
3352 language, and compiler version. */
3354 /* Fixed size portion of the DWARF compilation unit header. */
3355 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3356 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3358 /* Fixed size portion of public names info. */
3359 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3361 /* Fixed size portion of the address range info. */
3362 #define DWARF_ARANGES_HEADER_SIZE \
3363 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3364 DWARF2_ADDR_SIZE * 2) \
3365 - DWARF_INITIAL_LENGTH_SIZE)
3367 /* Size of padding portion in the address range info. It must be
3368 aligned to twice the pointer size. */
3369 #define DWARF_ARANGES_PAD_SIZE \
3370 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3371 DWARF2_ADDR_SIZE * 2) \
3372 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3374 /* Use assembler line directives if available. */
3375 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3376 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3377 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3378 #else
3379 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3380 #endif
3381 #endif
3383 /* Minimum line offset in a special line info. opcode.
3384 This value was chosen to give a reasonable range of values. */
3385 #define DWARF_LINE_BASE -10
3387 /* First special line opcode - leave room for the standard opcodes. */
3388 #define DWARF_LINE_OPCODE_BASE 10
3390 /* Range of line offsets in a special line info. opcode. */
3391 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3393 /* Flag that indicates the initial value of the is_stmt_start flag.
3394 In the present implementation, we do not mark any lines as
3395 the beginning of a source statement, because that information
3396 is not made available by the GCC front-end. */
3397 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3399 #ifdef DWARF2_DEBUGGING_INFO
3400 /* This location is used by calc_die_sizes() to keep track
3401 the offset of each DIE within the .debug_info section. */
3402 static unsigned long next_die_offset;
3403 #endif
3405 /* Record the root of the DIE's built for the current compilation unit. */
3406 static GTY(()) dw_die_ref comp_unit_die;
3408 #ifdef DWARF2_DEBUGGING_INFO
3409 /* We need special handling in dwarf2out_start_source_file if it is
3410 first one. */
3411 static int is_main_source;
3412 #endif
3414 /* A list of DIEs with a NULL parent waiting to be relocated. */
3415 static GTY(()) limbo_die_node *limbo_die_list;
3417 /* Filenames referenced by this compilation unit. */
3418 static GTY(()) varray_type file_table;
3419 static GTY(()) varray_type file_table_emitted;
3420 static GTY(()) size_t file_table_last_lookup_index;
3422 /* A pointer to the base of a table of references to DIE's that describe
3423 declarations. The table is indexed by DECL_UID() which is a unique
3424 number identifying each decl. */
3425 static GTY((length ("decl_die_table_allocated"))) dw_die_ref *decl_die_table;
3427 /* Number of elements currently allocated for the decl_die_table. */
3428 static GTY(()) unsigned decl_die_table_allocated;
3430 /* Number of elements in decl_die_table currently in use. */
3431 static GTY(()) unsigned decl_die_table_in_use;
3433 /* Size (in elements) of increments by which we may expand the
3434 decl_die_table. */
3435 #define DECL_DIE_TABLE_INCREMENT 256
3437 /* A pointer to the base of a list of references to DIE's that
3438 are uniquely identified by their tag, presence/absence of
3439 children DIE's, and list of attribute/value pairs. */
3440 static GTY((length ("abbrev_die_table_allocated")))
3441 dw_die_ref *abbrev_die_table;
3443 /* Number of elements currently allocated for abbrev_die_table. */
3444 static GTY(()) unsigned abbrev_die_table_allocated;
3446 /* Number of elements in type_die_table currently in use. */
3447 static GTY(()) unsigned abbrev_die_table_in_use;
3449 /* Size (in elements) of increments by which we may expand the
3450 abbrev_die_table. */
3451 #define ABBREV_DIE_TABLE_INCREMENT 256
3453 /* A pointer to the base of a table that contains line information
3454 for each source code line in .text in the compilation unit. */
3455 static GTY((length ("line_info_table_allocated")))
3456 dw_line_info_ref line_info_table;
3458 /* Number of elements currently allocated for line_info_table. */
3459 static GTY(()) unsigned line_info_table_allocated;
3461 /* Number of elements in line_info_table currently in use. */
3462 static GTY(()) unsigned line_info_table_in_use;
3464 /* A pointer to the base of a table that contains line information
3465 for each source code line outside of .text in the compilation unit. */
3466 static GTY ((length ("separate_line_info_table_allocated")))
3467 dw_separate_line_info_ref separate_line_info_table;
3469 /* Number of elements currently allocated for separate_line_info_table. */
3470 static GTY(()) unsigned separate_line_info_table_allocated;
3472 /* Number of elements in separate_line_info_table currently in use. */
3473 static GTY(()) unsigned separate_line_info_table_in_use;
3475 /* Size (in elements) of increments by which we may expand the
3476 line_info_table. */
3477 #define LINE_INFO_TABLE_INCREMENT 1024
3479 /* A pointer to the base of a table that contains a list of publicly
3480 accessible names. */
3481 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table;
3483 /* Number of elements currently allocated for pubname_table. */
3484 static GTY(()) unsigned pubname_table_allocated;
3486 /* Number of elements in pubname_table currently in use. */
3487 static GTY(()) unsigned pubname_table_in_use;
3489 /* Size (in elements) of increments by which we may expand the
3490 pubname_table. */
3491 #define PUBNAME_TABLE_INCREMENT 64
3493 /* Array of dies for which we should generate .debug_arange info. */
3494 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
3496 /* Number of elements currently allocated for arange_table. */
3497 static GTY(()) unsigned arange_table_allocated;
3499 /* Number of elements in arange_table currently in use. */
3500 static GTY(()) unsigned arange_table_in_use;
3502 /* Size (in elements) of increments by which we may expand the
3503 arange_table. */
3504 #define ARANGE_TABLE_INCREMENT 64
3506 /* Array of dies for which we should generate .debug_ranges info. */
3507 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3509 /* Number of elements currently allocated for ranges_table. */
3510 static GTY(()) unsigned ranges_table_allocated;
3512 /* Number of elements in ranges_table currently in use. */
3513 static GTY(()) unsigned ranges_table_in_use;
3515 /* Size (in elements) of increments by which we may expand the
3516 ranges_table. */
3517 #define RANGES_TABLE_INCREMENT 64
3519 /* Whether we have location lists that need outputting */
3520 static GTY(()) unsigned have_location_lists;
3522 #ifdef DWARF2_DEBUGGING_INFO
3523 /* Record whether the function being analyzed contains inlined functions. */
3524 static int current_function_has_inlines;
3525 #endif
3526 #if 0 && defined (MIPS_DEBUGGING_INFO)
3527 static int comp_unit_has_inlines;
3528 #endif
3530 /* Number of file tables emitted in maybe_emit_file(). */
3531 static GTY(()) int emitcount = 0;
3533 /* Number of internal labels generated by gen_internal_sym(). */
3534 static GTY(()) int label_num;
3536 #ifdef DWARF2_DEBUGGING_INFO
3538 /* Forward declarations for functions defined in this file. */
3540 static int is_pseudo_reg (rtx);
3541 static tree type_main_variant (tree);
3542 static int is_tagged_type (tree);
3543 static const char *dwarf_tag_name (unsigned);
3544 static const char *dwarf_attr_name (unsigned);
3545 static const char *dwarf_form_name (unsigned);
3546 #if 0
3547 static const char *dwarf_type_encoding_name (unsigned);
3548 #endif
3549 static tree decl_ultimate_origin (tree);
3550 static tree block_ultimate_origin (tree);
3551 static tree decl_class_context (tree);
3552 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3553 static inline enum dw_val_class AT_class (dw_attr_ref);
3554 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3555 static inline unsigned AT_flag (dw_attr_ref);
3556 static void add_AT_int (dw_die_ref, enum dwarf_attribute, long);
3557 static inline long int AT_int (dw_attr_ref);
3558 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned long);
3559 static inline unsigned long AT_unsigned (dw_attr_ref);
3560 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
3561 unsigned long);
3562 static void add_AT_float (dw_die_ref, enum dwarf_attribute, unsigned, long *);
3563 static hashval_t debug_str_do_hash (const void *);
3564 static int debug_str_eq (const void *, const void *);
3565 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3566 static inline const char *AT_string (dw_attr_ref);
3567 static int AT_string_form (dw_attr_ref);
3568 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3569 static inline dw_die_ref AT_ref (dw_attr_ref);
3570 static inline int AT_ref_external (dw_attr_ref);
3571 static inline void set_AT_ref_external (dw_attr_ref, int);
3572 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3573 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3574 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3575 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3576 dw_loc_list_ref);
3577 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3578 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3579 static inline rtx AT_addr (dw_attr_ref);
3580 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3581 static void add_AT_lbl_offset (dw_die_ref, enum dwarf_attribute, const char *);
3582 static void add_AT_offset (dw_die_ref, enum dwarf_attribute, unsigned long);
3583 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3584 unsigned long);
3585 static inline const char *AT_lbl (dw_attr_ref);
3586 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3587 static const char *get_AT_low_pc (dw_die_ref);
3588 static const char *get_AT_hi_pc (dw_die_ref);
3589 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3590 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3591 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3592 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3593 static bool is_c_family (void);
3594 static bool is_cxx (void);
3595 static bool is_java (void);
3596 static bool is_fortran (void);
3597 static bool is_ada (void);
3598 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3599 static inline void free_die (dw_die_ref);
3600 static void remove_children (dw_die_ref);
3601 static void add_child_die (dw_die_ref, dw_die_ref);
3602 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3603 static dw_die_ref lookup_type_die (tree);
3604 static void equate_type_number_to_die (tree, dw_die_ref);
3605 static dw_die_ref lookup_decl_die (tree);
3606 static void equate_decl_number_to_die (tree, dw_die_ref);
3607 static void print_spaces (FILE *);
3608 static void print_die (dw_die_ref, FILE *);
3609 static void print_dwarf_line_table (FILE *);
3610 static void reverse_die_lists (dw_die_ref);
3611 static void reverse_all_dies (dw_die_ref);
3612 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3613 static dw_die_ref pop_compile_unit (dw_die_ref);
3614 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3615 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3616 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3617 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3618 static int same_dw_val_p (dw_val_node *, dw_val_node *, int *);
3619 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3620 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3621 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3622 static void compute_section_prefix (dw_die_ref);
3623 static int is_type_die (dw_die_ref);
3624 static int is_comdat_die (dw_die_ref);
3625 static int is_symbol_die (dw_die_ref);
3626 static void assign_symbol_names (dw_die_ref);
3627 static void break_out_includes (dw_die_ref);
3628 static hashval_t htab_cu_hash (const void *);
3629 static int htab_cu_eq (const void *, const void *);
3630 static void htab_cu_del (void *);
3631 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3632 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3633 static void add_sibling_attributes (dw_die_ref);
3634 static void build_abbrev_table (dw_die_ref);
3635 static void output_location_lists (dw_die_ref);
3636 static int constant_size (long unsigned);
3637 static unsigned long size_of_die (dw_die_ref);
3638 static void calc_die_sizes (dw_die_ref);
3639 static void mark_dies (dw_die_ref);
3640 static void unmark_dies (dw_die_ref);
3641 static void unmark_all_dies (dw_die_ref);
3642 static unsigned long size_of_pubnames (void);
3643 static unsigned long size_of_aranges (void);
3644 static enum dwarf_form value_format (dw_attr_ref);
3645 static void output_value_format (dw_attr_ref);
3646 static void output_abbrev_section (void);
3647 static void output_die_symbol (dw_die_ref);
3648 static void output_die (dw_die_ref);
3649 static void output_compilation_unit_header (void);
3650 static void output_comp_unit (dw_die_ref, int);
3651 static const char *dwarf2_name (tree, int);
3652 static void add_pubname (tree, dw_die_ref);
3653 static void output_pubnames (void);
3654 static void add_arange (tree, dw_die_ref);
3655 static void output_aranges (void);
3656 static unsigned int add_ranges (tree);
3657 static void output_ranges (void);
3658 static void output_line_info (void);
3659 static void output_file_names (void);
3660 static dw_die_ref base_type_die (tree);
3661 static tree root_type (tree);
3662 static int is_base_type (tree);
3663 static bool is_ada_subrange_type (tree);
3664 static dw_die_ref subrange_type_die (tree);
3665 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
3666 static int type_is_enum (tree);
3667 static unsigned int reg_number (rtx);
3668 static dw_loc_descr_ref reg_loc_descriptor (rtx);
3669 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int);
3670 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx);
3671 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3672 static dw_loc_descr_ref based_loc_descr (unsigned, long);
3673 static int is_based_loc (rtx);
3674 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode);
3675 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx);
3676 static dw_loc_descr_ref loc_descriptor (rtx);
3677 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
3678 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3679 static tree field_type (tree);
3680 static unsigned int simple_type_align_in_bits (tree);
3681 static unsigned int simple_decl_align_in_bits (tree);
3682 static unsigned HOST_WIDE_INT simple_type_size_in_bits (tree);
3683 static HOST_WIDE_INT field_byte_offset (tree);
3684 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3685 dw_loc_descr_ref);
3686 static void add_data_member_location_attribute (dw_die_ref, tree);
3687 static void add_const_value_attribute (dw_die_ref, rtx);
3688 static rtx rtl_for_decl_location (tree);
3689 static void add_location_or_const_value_attribute (dw_die_ref, tree);
3690 static void tree_add_const_value_attribute (dw_die_ref, tree);
3691 static void add_name_attribute (dw_die_ref, const char *);
3692 static void add_comp_dir_attribute (dw_die_ref);
3693 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
3694 static void add_subscript_info (dw_die_ref, tree);
3695 static void add_byte_size_attribute (dw_die_ref, tree);
3696 static void add_bit_offset_attribute (dw_die_ref, tree);
3697 static void add_bit_size_attribute (dw_die_ref, tree);
3698 static void add_prototyped_attribute (dw_die_ref, tree);
3699 static void add_abstract_origin_attribute (dw_die_ref, tree);
3700 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3701 static void add_src_coords_attributes (dw_die_ref, tree);
3702 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3703 static void push_decl_scope (tree);
3704 static void pop_decl_scope (void);
3705 static dw_die_ref scope_die_for (tree, dw_die_ref);
3706 static inline int local_scope_p (dw_die_ref);
3707 static inline int class_scope_p (dw_die_ref);
3708 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
3709 static const char *type_tag (tree);
3710 static tree member_declared_type (tree);
3711 #if 0
3712 static const char *decl_start_label (tree);
3713 #endif
3714 static void gen_array_type_die (tree, dw_die_ref);
3715 static void gen_set_type_die (tree, dw_die_ref);
3716 #if 0
3717 static void gen_entry_point_die (tree, dw_die_ref);
3718 #endif
3719 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
3720 static void gen_inlined_structure_type_die (tree, dw_die_ref);
3721 static void gen_inlined_union_type_die (tree, dw_die_ref);
3722 static void gen_enumeration_type_die (tree, dw_die_ref);
3723 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
3724 static void gen_unspecified_parameters_die (tree, dw_die_ref);
3725 static void gen_formal_types_die (tree, dw_die_ref);
3726 static void gen_subprogram_die (tree, dw_die_ref);
3727 static void gen_variable_die (tree, dw_die_ref);
3728 static void gen_label_die (tree, dw_die_ref);
3729 static void gen_lexical_block_die (tree, dw_die_ref, int);
3730 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
3731 static void gen_field_die (tree, dw_die_ref);
3732 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3733 static dw_die_ref gen_compile_unit_die (const char *);
3734 static void gen_string_type_die (tree, dw_die_ref);
3735 static void gen_inheritance_die (tree, tree, dw_die_ref);
3736 static void gen_member_die (tree, dw_die_ref);
3737 static void gen_struct_or_union_type_die (tree, dw_die_ref);
3738 static void gen_subroutine_type_die (tree, dw_die_ref);
3739 static void gen_typedef_die (tree, dw_die_ref);
3740 static void gen_type_die (tree, dw_die_ref);
3741 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
3742 static void gen_block_die (tree, dw_die_ref, int);
3743 static void decls_for_scope (tree, dw_die_ref, int);
3744 static int is_redundant_typedef (tree);
3745 static void gen_decl_die (tree, dw_die_ref);
3746 static unsigned lookup_filename (const char *);
3747 static void init_file_table (void);
3748 static void retry_incomplete_types (void);
3749 static void gen_type_die_for_member (tree, tree, dw_die_ref);
3750 static void splice_child_die (dw_die_ref, dw_die_ref);
3751 static int file_info_cmp (const void *, const void *);
3752 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
3753 const char *, const char *, unsigned);
3754 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
3755 const char *, const char *,
3756 const char *);
3757 static void output_loc_list (dw_loc_list_ref);
3758 static char *gen_internal_sym (const char *);
3760 static void prune_unmark_dies (dw_die_ref);
3761 static void prune_unused_types_mark (dw_die_ref, int);
3762 static void prune_unused_types_walk (dw_die_ref);
3763 static void prune_unused_types_walk_attribs (dw_die_ref);
3764 static void prune_unused_types_prune (dw_die_ref);
3765 static void prune_unused_types (void);
3766 static int maybe_emit_file (int);
3768 /* Section names used to hold DWARF debugging information. */
3769 #ifndef DEBUG_INFO_SECTION
3770 #define DEBUG_INFO_SECTION ".debug_info"
3771 #endif
3772 #ifndef DEBUG_ABBREV_SECTION
3773 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3774 #endif
3775 #ifndef DEBUG_ARANGES_SECTION
3776 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3777 #endif
3778 #ifndef DEBUG_MACINFO_SECTION
3779 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3780 #endif
3781 #ifndef DEBUG_LINE_SECTION
3782 #define DEBUG_LINE_SECTION ".debug_line"
3783 #endif
3784 #ifndef DEBUG_LOC_SECTION
3785 #define DEBUG_LOC_SECTION ".debug_loc"
3786 #endif
3787 #ifndef DEBUG_PUBNAMES_SECTION
3788 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3789 #endif
3790 #ifndef DEBUG_STR_SECTION
3791 #define DEBUG_STR_SECTION ".debug_str"
3792 #endif
3793 #ifndef DEBUG_RANGES_SECTION
3794 #define DEBUG_RANGES_SECTION ".debug_ranges"
3795 #endif
3797 /* Standard ELF section names for compiled code and data. */
3798 #ifndef TEXT_SECTION_NAME
3799 #define TEXT_SECTION_NAME ".text"
3800 #endif
3802 /* Section flags for .debug_str section. */
3803 #ifdef HAVE_GAS_SHF_MERGE
3804 #define DEBUG_STR_SECTION_FLAGS \
3805 (flag_merge_constants \
3806 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3807 : SECTION_DEBUG)
3808 #else
3809 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3810 #endif
3812 /* Labels we insert at beginning sections we can reference instead of
3813 the section names themselves. */
3815 #ifndef TEXT_SECTION_LABEL
3816 #define TEXT_SECTION_LABEL "Ltext"
3817 #endif
3818 #ifndef DEBUG_LINE_SECTION_LABEL
3819 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3820 #endif
3821 #ifndef DEBUG_INFO_SECTION_LABEL
3822 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3823 #endif
3824 #ifndef DEBUG_ABBREV_SECTION_LABEL
3825 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3826 #endif
3827 #ifndef DEBUG_LOC_SECTION_LABEL
3828 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3829 #endif
3830 #ifndef DEBUG_RANGES_SECTION_LABEL
3831 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3832 #endif
3833 #ifndef DEBUG_MACINFO_SECTION_LABEL
3834 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3835 #endif
3837 /* Definitions of defaults for formats and names of various special
3838 (artificial) labels which may be generated within this file (when the -g
3839 options is used and DWARF_DEBUGGING_INFO is in effect.
3840 If necessary, these may be overridden from within the tm.h file, but
3841 typically, overriding these defaults is unnecessary. */
3843 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3844 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3845 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3846 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3847 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3848 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3849 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3850 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3852 #ifndef TEXT_END_LABEL
3853 #define TEXT_END_LABEL "Letext"
3854 #endif
3855 #ifndef BLOCK_BEGIN_LABEL
3856 #define BLOCK_BEGIN_LABEL "LBB"
3857 #endif
3858 #ifndef BLOCK_END_LABEL
3859 #define BLOCK_END_LABEL "LBE"
3860 #endif
3861 #ifndef LINE_CODE_LABEL
3862 #define LINE_CODE_LABEL "LM"
3863 #endif
3864 #ifndef SEPARATE_LINE_CODE_LABEL
3865 #define SEPARATE_LINE_CODE_LABEL "LSM"
3866 #endif
3868 /* We allow a language front-end to designate a function that is to be
3869 called to "demangle" any name before it it put into a DIE. */
3871 static const char *(*demangle_name_func) (const char *);
3873 void
3874 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
3876 demangle_name_func = func;
3879 /* Test if rtl node points to a pseudo register. */
3881 static inline int
3882 is_pseudo_reg (rtx rtl)
3884 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3885 || (GET_CODE (rtl) == SUBREG
3886 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3889 /* Return a reference to a type, with its const and volatile qualifiers
3890 removed. */
3892 static inline tree
3893 type_main_variant (tree type)
3895 type = TYPE_MAIN_VARIANT (type);
3897 /* ??? There really should be only one main variant among any group of
3898 variants of a given type (and all of the MAIN_VARIANT values for all
3899 members of the group should point to that one type) but sometimes the C
3900 front-end messes this up for array types, so we work around that bug
3901 here. */
3902 if (TREE_CODE (type) == ARRAY_TYPE)
3903 while (type != TYPE_MAIN_VARIANT (type))
3904 type = TYPE_MAIN_VARIANT (type);
3906 return type;
3909 /* Return nonzero if the given type node represents a tagged type. */
3911 static inline int
3912 is_tagged_type (tree type)
3914 enum tree_code code = TREE_CODE (type);
3916 return (code == RECORD_TYPE || code == UNION_TYPE
3917 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3920 /* Convert a DIE tag into its string name. */
3922 static const char *
3923 dwarf_tag_name (unsigned int tag)
3925 switch (tag)
3927 case DW_TAG_padding:
3928 return "DW_TAG_padding";
3929 case DW_TAG_array_type:
3930 return "DW_TAG_array_type";
3931 case DW_TAG_class_type:
3932 return "DW_TAG_class_type";
3933 case DW_TAG_entry_point:
3934 return "DW_TAG_entry_point";
3935 case DW_TAG_enumeration_type:
3936 return "DW_TAG_enumeration_type";
3937 case DW_TAG_formal_parameter:
3938 return "DW_TAG_formal_parameter";
3939 case DW_TAG_imported_declaration:
3940 return "DW_TAG_imported_declaration";
3941 case DW_TAG_label:
3942 return "DW_TAG_label";
3943 case DW_TAG_lexical_block:
3944 return "DW_TAG_lexical_block";
3945 case DW_TAG_member:
3946 return "DW_TAG_member";
3947 case DW_TAG_pointer_type:
3948 return "DW_TAG_pointer_type";
3949 case DW_TAG_reference_type:
3950 return "DW_TAG_reference_type";
3951 case DW_TAG_compile_unit:
3952 return "DW_TAG_compile_unit";
3953 case DW_TAG_string_type:
3954 return "DW_TAG_string_type";
3955 case DW_TAG_structure_type:
3956 return "DW_TAG_structure_type";
3957 case DW_TAG_subroutine_type:
3958 return "DW_TAG_subroutine_type";
3959 case DW_TAG_typedef:
3960 return "DW_TAG_typedef";
3961 case DW_TAG_union_type:
3962 return "DW_TAG_union_type";
3963 case DW_TAG_unspecified_parameters:
3964 return "DW_TAG_unspecified_parameters";
3965 case DW_TAG_variant:
3966 return "DW_TAG_variant";
3967 case DW_TAG_common_block:
3968 return "DW_TAG_common_block";
3969 case DW_TAG_common_inclusion:
3970 return "DW_TAG_common_inclusion";
3971 case DW_TAG_inheritance:
3972 return "DW_TAG_inheritance";
3973 case DW_TAG_inlined_subroutine:
3974 return "DW_TAG_inlined_subroutine";
3975 case DW_TAG_module:
3976 return "DW_TAG_module";
3977 case DW_TAG_ptr_to_member_type:
3978 return "DW_TAG_ptr_to_member_type";
3979 case DW_TAG_set_type:
3980 return "DW_TAG_set_type";
3981 case DW_TAG_subrange_type:
3982 return "DW_TAG_subrange_type";
3983 case DW_TAG_with_stmt:
3984 return "DW_TAG_with_stmt";
3985 case DW_TAG_access_declaration:
3986 return "DW_TAG_access_declaration";
3987 case DW_TAG_base_type:
3988 return "DW_TAG_base_type";
3989 case DW_TAG_catch_block:
3990 return "DW_TAG_catch_block";
3991 case DW_TAG_const_type:
3992 return "DW_TAG_const_type";
3993 case DW_TAG_constant:
3994 return "DW_TAG_constant";
3995 case DW_TAG_enumerator:
3996 return "DW_TAG_enumerator";
3997 case DW_TAG_file_type:
3998 return "DW_TAG_file_type";
3999 case DW_TAG_friend:
4000 return "DW_TAG_friend";
4001 case DW_TAG_namelist:
4002 return "DW_TAG_namelist";
4003 case DW_TAG_namelist_item:
4004 return "DW_TAG_namelist_item";
4005 case DW_TAG_packed_type:
4006 return "DW_TAG_packed_type";
4007 case DW_TAG_subprogram:
4008 return "DW_TAG_subprogram";
4009 case DW_TAG_template_type_param:
4010 return "DW_TAG_template_type_param";
4011 case DW_TAG_template_value_param:
4012 return "DW_TAG_template_value_param";
4013 case DW_TAG_thrown_type:
4014 return "DW_TAG_thrown_type";
4015 case DW_TAG_try_block:
4016 return "DW_TAG_try_block";
4017 case DW_TAG_variant_part:
4018 return "DW_TAG_variant_part";
4019 case DW_TAG_variable:
4020 return "DW_TAG_variable";
4021 case DW_TAG_volatile_type:
4022 return "DW_TAG_volatile_type";
4023 case DW_TAG_MIPS_loop:
4024 return "DW_TAG_MIPS_loop";
4025 case DW_TAG_format_label:
4026 return "DW_TAG_format_label";
4027 case DW_TAG_function_template:
4028 return "DW_TAG_function_template";
4029 case DW_TAG_class_template:
4030 return "DW_TAG_class_template";
4031 case DW_TAG_GNU_BINCL:
4032 return "DW_TAG_GNU_BINCL";
4033 case DW_TAG_GNU_EINCL:
4034 return "DW_TAG_GNU_EINCL";
4035 default:
4036 return "DW_TAG_<unknown>";
4040 /* Convert a DWARF attribute code into its string name. */
4042 static const char *
4043 dwarf_attr_name (unsigned int attr)
4045 switch (attr)
4047 case DW_AT_sibling:
4048 return "DW_AT_sibling";
4049 case DW_AT_location:
4050 return "DW_AT_location";
4051 case DW_AT_name:
4052 return "DW_AT_name";
4053 case DW_AT_ordering:
4054 return "DW_AT_ordering";
4055 case DW_AT_subscr_data:
4056 return "DW_AT_subscr_data";
4057 case DW_AT_byte_size:
4058 return "DW_AT_byte_size";
4059 case DW_AT_bit_offset:
4060 return "DW_AT_bit_offset";
4061 case DW_AT_bit_size:
4062 return "DW_AT_bit_size";
4063 case DW_AT_element_list:
4064 return "DW_AT_element_list";
4065 case DW_AT_stmt_list:
4066 return "DW_AT_stmt_list";
4067 case DW_AT_low_pc:
4068 return "DW_AT_low_pc";
4069 case DW_AT_high_pc:
4070 return "DW_AT_high_pc";
4071 case DW_AT_language:
4072 return "DW_AT_language";
4073 case DW_AT_member:
4074 return "DW_AT_member";
4075 case DW_AT_discr:
4076 return "DW_AT_discr";
4077 case DW_AT_discr_value:
4078 return "DW_AT_discr_value";
4079 case DW_AT_visibility:
4080 return "DW_AT_visibility";
4081 case DW_AT_import:
4082 return "DW_AT_import";
4083 case DW_AT_string_length:
4084 return "DW_AT_string_length";
4085 case DW_AT_common_reference:
4086 return "DW_AT_common_reference";
4087 case DW_AT_comp_dir:
4088 return "DW_AT_comp_dir";
4089 case DW_AT_const_value:
4090 return "DW_AT_const_value";
4091 case DW_AT_containing_type:
4092 return "DW_AT_containing_type";
4093 case DW_AT_default_value:
4094 return "DW_AT_default_value";
4095 case DW_AT_inline:
4096 return "DW_AT_inline";
4097 case DW_AT_is_optional:
4098 return "DW_AT_is_optional";
4099 case DW_AT_lower_bound:
4100 return "DW_AT_lower_bound";
4101 case DW_AT_producer:
4102 return "DW_AT_producer";
4103 case DW_AT_prototyped:
4104 return "DW_AT_prototyped";
4105 case DW_AT_return_addr:
4106 return "DW_AT_return_addr";
4107 case DW_AT_start_scope:
4108 return "DW_AT_start_scope";
4109 case DW_AT_stride_size:
4110 return "DW_AT_stride_size";
4111 case DW_AT_upper_bound:
4112 return "DW_AT_upper_bound";
4113 case DW_AT_abstract_origin:
4114 return "DW_AT_abstract_origin";
4115 case DW_AT_accessibility:
4116 return "DW_AT_accessibility";
4117 case DW_AT_address_class:
4118 return "DW_AT_address_class";
4119 case DW_AT_artificial:
4120 return "DW_AT_artificial";
4121 case DW_AT_base_types:
4122 return "DW_AT_base_types";
4123 case DW_AT_calling_convention:
4124 return "DW_AT_calling_convention";
4125 case DW_AT_count:
4126 return "DW_AT_count";
4127 case DW_AT_data_member_location:
4128 return "DW_AT_data_member_location";
4129 case DW_AT_decl_column:
4130 return "DW_AT_decl_column";
4131 case DW_AT_decl_file:
4132 return "DW_AT_decl_file";
4133 case DW_AT_decl_line:
4134 return "DW_AT_decl_line";
4135 case DW_AT_declaration:
4136 return "DW_AT_declaration";
4137 case DW_AT_discr_list:
4138 return "DW_AT_discr_list";
4139 case DW_AT_encoding:
4140 return "DW_AT_encoding";
4141 case DW_AT_external:
4142 return "DW_AT_external";
4143 case DW_AT_frame_base:
4144 return "DW_AT_frame_base";
4145 case DW_AT_friend:
4146 return "DW_AT_friend";
4147 case DW_AT_identifier_case:
4148 return "DW_AT_identifier_case";
4149 case DW_AT_macro_info:
4150 return "DW_AT_macro_info";
4151 case DW_AT_namelist_items:
4152 return "DW_AT_namelist_items";
4153 case DW_AT_priority:
4154 return "DW_AT_priority";
4155 case DW_AT_segment:
4156 return "DW_AT_segment";
4157 case DW_AT_specification:
4158 return "DW_AT_specification";
4159 case DW_AT_static_link:
4160 return "DW_AT_static_link";
4161 case DW_AT_type:
4162 return "DW_AT_type";
4163 case DW_AT_use_location:
4164 return "DW_AT_use_location";
4165 case DW_AT_variable_parameter:
4166 return "DW_AT_variable_parameter";
4167 case DW_AT_virtuality:
4168 return "DW_AT_virtuality";
4169 case DW_AT_vtable_elem_location:
4170 return "DW_AT_vtable_elem_location";
4172 case DW_AT_allocated:
4173 return "DW_AT_allocated";
4174 case DW_AT_associated:
4175 return "DW_AT_associated";
4176 case DW_AT_data_location:
4177 return "DW_AT_data_location";
4178 case DW_AT_stride:
4179 return "DW_AT_stride";
4180 case DW_AT_entry_pc:
4181 return "DW_AT_entry_pc";
4182 case DW_AT_use_UTF8:
4183 return "DW_AT_use_UTF8";
4184 case DW_AT_extension:
4185 return "DW_AT_extension";
4186 case DW_AT_ranges:
4187 return "DW_AT_ranges";
4188 case DW_AT_trampoline:
4189 return "DW_AT_trampoline";
4190 case DW_AT_call_column:
4191 return "DW_AT_call_column";
4192 case DW_AT_call_file:
4193 return "DW_AT_call_file";
4194 case DW_AT_call_line:
4195 return "DW_AT_call_line";
4197 case DW_AT_MIPS_fde:
4198 return "DW_AT_MIPS_fde";
4199 case DW_AT_MIPS_loop_begin:
4200 return "DW_AT_MIPS_loop_begin";
4201 case DW_AT_MIPS_tail_loop_begin:
4202 return "DW_AT_MIPS_tail_loop_begin";
4203 case DW_AT_MIPS_epilog_begin:
4204 return "DW_AT_MIPS_epilog_begin";
4205 case DW_AT_MIPS_loop_unroll_factor:
4206 return "DW_AT_MIPS_loop_unroll_factor";
4207 case DW_AT_MIPS_software_pipeline_depth:
4208 return "DW_AT_MIPS_software_pipeline_depth";
4209 case DW_AT_MIPS_linkage_name:
4210 return "DW_AT_MIPS_linkage_name";
4211 case DW_AT_MIPS_stride:
4212 return "DW_AT_MIPS_stride";
4213 case DW_AT_MIPS_abstract_name:
4214 return "DW_AT_MIPS_abstract_name";
4215 case DW_AT_MIPS_clone_origin:
4216 return "DW_AT_MIPS_clone_origin";
4217 case DW_AT_MIPS_has_inlines:
4218 return "DW_AT_MIPS_has_inlines";
4220 case DW_AT_sf_names:
4221 return "DW_AT_sf_names";
4222 case DW_AT_src_info:
4223 return "DW_AT_src_info";
4224 case DW_AT_mac_info:
4225 return "DW_AT_mac_info";
4226 case DW_AT_src_coords:
4227 return "DW_AT_src_coords";
4228 case DW_AT_body_begin:
4229 return "DW_AT_body_begin";
4230 case DW_AT_body_end:
4231 return "DW_AT_body_end";
4232 case DW_AT_GNU_vector:
4233 return "DW_AT_GNU_vector";
4235 case DW_AT_VMS_rtnbeg_pd_address:
4236 return "DW_AT_VMS_rtnbeg_pd_address";
4238 default:
4239 return "DW_AT_<unknown>";
4243 /* Convert a DWARF value form code into its string name. */
4245 static const char *
4246 dwarf_form_name (unsigned int form)
4248 switch (form)
4250 case DW_FORM_addr:
4251 return "DW_FORM_addr";
4252 case DW_FORM_block2:
4253 return "DW_FORM_block2";
4254 case DW_FORM_block4:
4255 return "DW_FORM_block4";
4256 case DW_FORM_data2:
4257 return "DW_FORM_data2";
4258 case DW_FORM_data4:
4259 return "DW_FORM_data4";
4260 case DW_FORM_data8:
4261 return "DW_FORM_data8";
4262 case DW_FORM_string:
4263 return "DW_FORM_string";
4264 case DW_FORM_block:
4265 return "DW_FORM_block";
4266 case DW_FORM_block1:
4267 return "DW_FORM_block1";
4268 case DW_FORM_data1:
4269 return "DW_FORM_data1";
4270 case DW_FORM_flag:
4271 return "DW_FORM_flag";
4272 case DW_FORM_sdata:
4273 return "DW_FORM_sdata";
4274 case DW_FORM_strp:
4275 return "DW_FORM_strp";
4276 case DW_FORM_udata:
4277 return "DW_FORM_udata";
4278 case DW_FORM_ref_addr:
4279 return "DW_FORM_ref_addr";
4280 case DW_FORM_ref1:
4281 return "DW_FORM_ref1";
4282 case DW_FORM_ref2:
4283 return "DW_FORM_ref2";
4284 case DW_FORM_ref4:
4285 return "DW_FORM_ref4";
4286 case DW_FORM_ref8:
4287 return "DW_FORM_ref8";
4288 case DW_FORM_ref_udata:
4289 return "DW_FORM_ref_udata";
4290 case DW_FORM_indirect:
4291 return "DW_FORM_indirect";
4292 default:
4293 return "DW_FORM_<unknown>";
4297 /* Convert a DWARF type code into its string name. */
4299 #if 0
4300 static const char *
4301 dwarf_type_encoding_name (unsigned enc)
4303 switch (enc)
4305 case DW_ATE_address:
4306 return "DW_ATE_address";
4307 case DW_ATE_boolean:
4308 return "DW_ATE_boolean";
4309 case DW_ATE_complex_float:
4310 return "DW_ATE_complex_float";
4311 case DW_ATE_float:
4312 return "DW_ATE_float";
4313 case DW_ATE_signed:
4314 return "DW_ATE_signed";
4315 case DW_ATE_signed_char:
4316 return "DW_ATE_signed_char";
4317 case DW_ATE_unsigned:
4318 return "DW_ATE_unsigned";
4319 case DW_ATE_unsigned_char:
4320 return "DW_ATE_unsigned_char";
4321 default:
4322 return "DW_ATE_<unknown>";
4325 #endif
4327 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4328 instance of an inlined instance of a decl which is local to an inline
4329 function, so we have to trace all of the way back through the origin chain
4330 to find out what sort of node actually served as the original seed for the
4331 given block. */
4333 static tree
4334 decl_ultimate_origin (tree decl)
4336 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4337 nodes in the function to point to themselves; ignore that if
4338 we're trying to output the abstract instance of this function. */
4339 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4340 return NULL_TREE;
4342 #ifdef ENABLE_CHECKING
4343 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4344 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4345 most distant ancestor, this should never happen. */
4346 abort ();
4347 #endif
4349 return DECL_ABSTRACT_ORIGIN (decl);
4352 /* Determine the "ultimate origin" of a block. The block may be an inlined
4353 instance of an inlined instance of a block which is local to an inline
4354 function, so we have to trace all of the way back through the origin chain
4355 to find out what sort of node actually served as the original seed for the
4356 given block. */
4358 static tree
4359 block_ultimate_origin (tree block)
4361 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4363 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4364 nodes in the function to point to themselves; ignore that if
4365 we're trying to output the abstract instance of this function. */
4366 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4367 return NULL_TREE;
4369 if (immediate_origin == NULL_TREE)
4370 return NULL_TREE;
4371 else
4373 tree ret_val;
4374 tree lookahead = immediate_origin;
4378 ret_val = lookahead;
4379 lookahead = (TREE_CODE (ret_val) == BLOCK
4380 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4382 while (lookahead != NULL && lookahead != ret_val);
4384 return ret_val;
4388 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4389 of a virtual function may refer to a base class, so we check the 'this'
4390 parameter. */
4392 static tree
4393 decl_class_context (tree decl)
4395 tree context = NULL_TREE;
4397 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4398 context = DECL_CONTEXT (decl);
4399 else
4400 context = TYPE_MAIN_VARIANT
4401 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4403 if (context && !TYPE_P (context))
4404 context = NULL_TREE;
4406 return context;
4409 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4410 addition order, and correct that in reverse_all_dies. */
4412 static inline void
4413 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4415 if (die != NULL && attr != NULL)
4417 attr->dw_attr_next = die->die_attr;
4418 die->die_attr = attr;
4422 static inline enum dw_val_class
4423 AT_class (dw_attr_ref a)
4425 return a->dw_attr_val.val_class;
4428 /* Add a flag value attribute to a DIE. */
4430 static inline void
4431 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4433 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4435 attr->dw_attr_next = NULL;
4436 attr->dw_attr = attr_kind;
4437 attr->dw_attr_val.val_class = dw_val_class_flag;
4438 attr->dw_attr_val.v.val_flag = flag;
4439 add_dwarf_attr (die, attr);
4442 static inline unsigned
4443 AT_flag (dw_attr_ref a)
4445 if (a && AT_class (a) == dw_val_class_flag)
4446 return a->dw_attr_val.v.val_flag;
4448 abort ();
4451 /* Add a signed integer attribute value to a DIE. */
4453 static inline void
4454 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, long int int_val)
4456 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4458 attr->dw_attr_next = NULL;
4459 attr->dw_attr = attr_kind;
4460 attr->dw_attr_val.val_class = dw_val_class_const;
4461 attr->dw_attr_val.v.val_int = int_val;
4462 add_dwarf_attr (die, attr);
4465 static inline long int
4466 AT_int (dw_attr_ref a)
4468 if (a && AT_class (a) == dw_val_class_const)
4469 return a->dw_attr_val.v.val_int;
4471 abort ();
4474 /* Add an unsigned integer attribute value to a DIE. */
4476 static inline void
4477 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4478 long unsigned int unsigned_val)
4480 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4482 attr->dw_attr_next = NULL;
4483 attr->dw_attr = attr_kind;
4484 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4485 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4486 add_dwarf_attr (die, attr);
4489 static inline unsigned long
4490 AT_unsigned (dw_attr_ref a)
4492 if (a && AT_class (a) == dw_val_class_unsigned_const)
4493 return a->dw_attr_val.v.val_unsigned;
4495 abort ();
4498 /* Add an unsigned double integer attribute value to a DIE. */
4500 static inline void
4501 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
4502 long unsigned int val_hi, long unsigned int val_low)
4504 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4506 attr->dw_attr_next = NULL;
4507 attr->dw_attr = attr_kind;
4508 attr->dw_attr_val.val_class = dw_val_class_long_long;
4509 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4510 attr->dw_attr_val.v.val_long_long.low = val_low;
4511 add_dwarf_attr (die, attr);
4514 /* Add a floating point attribute value to a DIE and return it. */
4516 static inline void
4517 add_AT_float (dw_die_ref die, enum dwarf_attribute attr_kind,
4518 unsigned int length, long int *array)
4520 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4522 attr->dw_attr_next = NULL;
4523 attr->dw_attr = attr_kind;
4524 attr->dw_attr_val.val_class = dw_val_class_float;
4525 attr->dw_attr_val.v.val_float.length = length;
4526 attr->dw_attr_val.v.val_float.array = array;
4527 add_dwarf_attr (die, attr);
4530 /* Hash and equality functions for debug_str_hash. */
4532 static hashval_t
4533 debug_str_do_hash (const void *x)
4535 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4538 static int
4539 debug_str_eq (const void *x1, const void *x2)
4541 return strcmp ((((const struct indirect_string_node *)x1)->str),
4542 (const char *)x2) == 0;
4545 /* Add a string attribute value to a DIE. */
4547 static inline void
4548 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4550 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4551 struct indirect_string_node *node;
4552 void **slot;
4554 if (! debug_str_hash)
4555 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4556 debug_str_eq, NULL);
4558 slot = htab_find_slot_with_hash (debug_str_hash, str,
4559 htab_hash_string (str), INSERT);
4560 if (*slot == NULL)
4561 *slot = ggc_alloc_cleared (sizeof (struct indirect_string_node));
4562 node = (struct indirect_string_node *) *slot;
4563 node->str = ggc_strdup (str);
4564 node->refcount++;
4566 attr->dw_attr_next = NULL;
4567 attr->dw_attr = attr_kind;
4568 attr->dw_attr_val.val_class = dw_val_class_str;
4569 attr->dw_attr_val.v.val_str = node;
4570 add_dwarf_attr (die, attr);
4573 static inline const char *
4574 AT_string (dw_attr_ref a)
4576 if (a && AT_class (a) == dw_val_class_str)
4577 return a->dw_attr_val.v.val_str->str;
4579 abort ();
4582 /* Find out whether a string should be output inline in DIE
4583 or out-of-line in .debug_str section. */
4585 static int
4586 AT_string_form (dw_attr_ref a)
4588 if (a && AT_class (a) == dw_val_class_str)
4590 struct indirect_string_node *node;
4591 unsigned int len;
4592 char label[32];
4594 node = a->dw_attr_val.v.val_str;
4595 if (node->form)
4596 return node->form;
4598 len = strlen (node->str) + 1;
4600 /* If the string is shorter or equal to the size of the reference, it is
4601 always better to put it inline. */
4602 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4603 return node->form = DW_FORM_string;
4605 /* If we cannot expect the linker to merge strings in .debug_str
4606 section, only put it into .debug_str if it is worth even in this
4607 single module. */
4608 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4609 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4610 return node->form = DW_FORM_string;
4612 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4613 ++dw2_string_counter;
4614 node->label = xstrdup (label);
4616 return node->form = DW_FORM_strp;
4619 abort ();
4622 /* Add a DIE reference attribute value to a DIE. */
4624 static inline void
4625 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4627 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4629 attr->dw_attr_next = NULL;
4630 attr->dw_attr = attr_kind;
4631 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4632 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4633 attr->dw_attr_val.v.val_die_ref.external = 0;
4634 add_dwarf_attr (die, attr);
4637 static inline dw_die_ref
4638 AT_ref (dw_attr_ref a)
4640 if (a && AT_class (a) == dw_val_class_die_ref)
4641 return a->dw_attr_val.v.val_die_ref.die;
4643 abort ();
4646 static inline int
4647 AT_ref_external (dw_attr_ref a)
4649 if (a && AT_class (a) == dw_val_class_die_ref)
4650 return a->dw_attr_val.v.val_die_ref.external;
4652 return 0;
4655 static inline void
4656 set_AT_ref_external (dw_attr_ref a, int i)
4658 if (a && AT_class (a) == dw_val_class_die_ref)
4659 a->dw_attr_val.v.val_die_ref.external = i;
4660 else
4661 abort ();
4664 /* Add an FDE reference attribute value to a DIE. */
4666 static inline void
4667 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
4669 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4671 attr->dw_attr_next = NULL;
4672 attr->dw_attr = attr_kind;
4673 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4674 attr->dw_attr_val.v.val_fde_index = targ_fde;
4675 add_dwarf_attr (die, attr);
4678 /* Add a location description attribute value to a DIE. */
4680 static inline void
4681 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4683 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4685 attr->dw_attr_next = NULL;
4686 attr->dw_attr = attr_kind;
4687 attr->dw_attr_val.val_class = dw_val_class_loc;
4688 attr->dw_attr_val.v.val_loc = loc;
4689 add_dwarf_attr (die, attr);
4692 static inline dw_loc_descr_ref
4693 AT_loc (dw_attr_ref a)
4695 if (a && AT_class (a) == dw_val_class_loc)
4696 return a->dw_attr_val.v.val_loc;
4698 abort ();
4701 static inline void
4702 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
4704 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4706 attr->dw_attr_next = NULL;
4707 attr->dw_attr = attr_kind;
4708 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4709 attr->dw_attr_val.v.val_loc_list = loc_list;
4710 add_dwarf_attr (die, attr);
4711 have_location_lists = 1;
4714 static inline dw_loc_list_ref
4715 AT_loc_list (dw_attr_ref a)
4717 if (a && AT_class (a) == dw_val_class_loc_list)
4718 return a->dw_attr_val.v.val_loc_list;
4720 abort ();
4723 /* Add an address constant attribute value to a DIE. */
4725 static inline void
4726 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
4728 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4730 attr->dw_attr_next = NULL;
4731 attr->dw_attr = attr_kind;
4732 attr->dw_attr_val.val_class = dw_val_class_addr;
4733 attr->dw_attr_val.v.val_addr = addr;
4734 add_dwarf_attr (die, attr);
4737 static inline rtx
4738 AT_addr (dw_attr_ref a)
4740 if (a && AT_class (a) == dw_val_class_addr)
4741 return a->dw_attr_val.v.val_addr;
4743 abort ();
4746 /* Add a label identifier attribute value to a DIE. */
4748 static inline void
4749 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
4751 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4753 attr->dw_attr_next = NULL;
4754 attr->dw_attr = attr_kind;
4755 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4756 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4757 add_dwarf_attr (die, attr);
4760 /* Add a section offset attribute value to a DIE. */
4762 static inline void
4763 add_AT_lbl_offset (dw_die_ref die, enum dwarf_attribute attr_kind, const char *label)
4765 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4767 attr->dw_attr_next = NULL;
4768 attr->dw_attr = attr_kind;
4769 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4770 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4771 add_dwarf_attr (die, attr);
4774 /* Add an offset attribute value to a DIE. */
4776 static inline void
4777 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind, long unsigned int offset)
4779 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4781 attr->dw_attr_next = NULL;
4782 attr->dw_attr = attr_kind;
4783 attr->dw_attr_val.val_class = dw_val_class_offset;
4784 attr->dw_attr_val.v.val_offset = offset;
4785 add_dwarf_attr (die, attr);
4788 /* Add an range_list attribute value to a DIE. */
4790 static void
4791 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
4792 long unsigned int offset)
4794 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4796 attr->dw_attr_next = NULL;
4797 attr->dw_attr = attr_kind;
4798 attr->dw_attr_val.val_class = dw_val_class_range_list;
4799 attr->dw_attr_val.v.val_offset = offset;
4800 add_dwarf_attr (die, attr);
4803 static inline const char *
4804 AT_lbl (dw_attr_ref a)
4806 if (a && (AT_class (a) == dw_val_class_lbl_id
4807 || AT_class (a) == dw_val_class_lbl_offset))
4808 return a->dw_attr_val.v.val_lbl_id;
4810 abort ();
4813 /* Get the attribute of type attr_kind. */
4815 static inline dw_attr_ref
4816 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4818 dw_attr_ref a;
4819 dw_die_ref spec = NULL;
4821 if (die != NULL)
4823 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4824 if (a->dw_attr == attr_kind)
4825 return a;
4826 else if (a->dw_attr == DW_AT_specification
4827 || a->dw_attr == DW_AT_abstract_origin)
4828 spec = AT_ref (a);
4830 if (spec)
4831 return get_AT (spec, attr_kind);
4834 return NULL;
4837 /* Return the "low pc" attribute value, typically associated with a subprogram
4838 DIE. Return null if the "low pc" attribute is either not present, or if it
4839 cannot be represented as an assembler label identifier. */
4841 static inline const char *
4842 get_AT_low_pc (dw_die_ref die)
4844 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4846 return a ? AT_lbl (a) : NULL;
4849 /* Return the "high pc" attribute value, typically associated with a subprogram
4850 DIE. Return null if the "high pc" attribute is either not present, or if it
4851 cannot be represented as an assembler label identifier. */
4853 static inline const char *
4854 get_AT_hi_pc (dw_die_ref die)
4856 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4858 return a ? AT_lbl (a) : NULL;
4861 /* Return the value of the string attribute designated by ATTR_KIND, or
4862 NULL if it is not present. */
4864 static inline const char *
4865 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
4867 dw_attr_ref a = get_AT (die, attr_kind);
4869 return a ? AT_string (a) : NULL;
4872 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4873 if it is not present. */
4875 static inline int
4876 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
4878 dw_attr_ref a = get_AT (die, attr_kind);
4880 return a ? AT_flag (a) : 0;
4883 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4884 if it is not present. */
4886 static inline unsigned
4887 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
4889 dw_attr_ref a = get_AT (die, attr_kind);
4891 return a ? AT_unsigned (a) : 0;
4894 static inline dw_die_ref
4895 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
4897 dw_attr_ref a = get_AT (die, attr_kind);
4899 return a ? AT_ref (a) : NULL;
4902 /* Return TRUE if the language is C or C++. */
4904 static inline bool
4905 is_c_family (void)
4907 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4909 return (lang == DW_LANG_C || lang == DW_LANG_C89
4910 || lang == DW_LANG_C_plus_plus);
4913 /* Return TRUE if the language is C++. */
4915 static inline bool
4916 is_cxx (void)
4918 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4919 == DW_LANG_C_plus_plus);
4922 /* Return TRUE if the language is Fortran. */
4924 static inline bool
4925 is_fortran (void)
4927 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4929 return lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90;
4932 /* Return TRUE if the language is Java. */
4934 static inline bool
4935 is_java (void)
4937 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4939 return lang == DW_LANG_Java;
4942 /* Return TRUE if the language is Ada. */
4944 static inline bool
4945 is_ada (void)
4947 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4949 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
4952 /* Free up the memory used by A. */
4954 static inline void free_AT (dw_attr_ref);
4955 static inline void
4956 free_AT (dw_attr_ref a)
4958 if (AT_class (a) == dw_val_class_str)
4959 if (a->dw_attr_val.v.val_str->refcount)
4960 a->dw_attr_val.v.val_str->refcount--;
4963 /* Remove the specified attribute if present. */
4965 static void
4966 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4968 dw_attr_ref *p;
4969 dw_attr_ref removed = NULL;
4971 if (die != NULL)
4973 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4974 if ((*p)->dw_attr == attr_kind)
4976 removed = *p;
4977 *p = (*p)->dw_attr_next;
4978 break;
4981 if (removed != 0)
4982 free_AT (removed);
4986 /* Free up the memory used by DIE. */
4988 static inline void
4989 free_die (dw_die_ref die)
4991 remove_children (die);
4994 /* Discard the children of this DIE. */
4996 static void
4997 remove_children (dw_die_ref die)
4999 dw_die_ref child_die = die->die_child;
5001 die->die_child = NULL;
5003 while (child_die != NULL)
5005 dw_die_ref tmp_die = child_die;
5006 dw_attr_ref a;
5008 child_die = child_die->die_sib;
5010 for (a = tmp_die->die_attr; a != NULL;)
5012 dw_attr_ref tmp_a = a;
5014 a = a->dw_attr_next;
5015 free_AT (tmp_a);
5018 free_die (tmp_die);
5022 /* Add a child DIE below its parent. We build the lists up in reverse
5023 addition order, and correct that in reverse_all_dies. */
5025 static inline void
5026 add_child_die (dw_die_ref die, dw_die_ref child_die)
5028 if (die != NULL && child_die != NULL)
5030 if (die == child_die)
5031 abort ();
5033 child_die->die_parent = die;
5034 child_die->die_sib = die->die_child;
5035 die->die_child = child_die;
5039 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5040 is the specification, to the front of PARENT's list of children. */
5042 static void
5043 splice_child_die (dw_die_ref parent, dw_die_ref child)
5045 dw_die_ref *p;
5047 /* We want the declaration DIE from inside the class, not the
5048 specification DIE at toplevel. */
5049 if (child->die_parent != parent)
5051 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5053 if (tmp)
5054 child = tmp;
5057 if (child->die_parent != parent
5058 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
5059 abort ();
5061 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5062 if (*p == child)
5064 *p = child->die_sib;
5065 break;
5068 child->die_parent = parent;
5069 child->die_sib = parent->die_child;
5070 parent->die_child = child;
5073 /* Return a pointer to a newly created DIE node. */
5075 static inline dw_die_ref
5076 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5078 dw_die_ref die = (dw_die_ref) ggc_alloc_cleared (sizeof (die_node));
5080 die->die_tag = tag_value;
5082 if (parent_die != NULL)
5083 add_child_die (parent_die, die);
5084 else
5086 limbo_die_node *limbo_node;
5088 limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node));
5089 limbo_node->die = die;
5090 limbo_node->created_for = t;
5091 limbo_node->next = limbo_die_list;
5092 limbo_die_list = limbo_node;
5095 return die;
5098 /* Return the DIE associated with the given type specifier. */
5100 static inline dw_die_ref
5101 lookup_type_die (tree type)
5103 return TYPE_SYMTAB_DIE (type);
5106 /* Equate a DIE to a given type specifier. */
5108 static inline void
5109 equate_type_number_to_die (tree type, dw_die_ref type_die)
5111 TYPE_SYMTAB_DIE (type) = type_die;
5114 /* Return the DIE associated with a given declaration. */
5116 static inline dw_die_ref
5117 lookup_decl_die (tree decl)
5119 unsigned decl_id = DECL_UID (decl);
5121 return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
5124 /* Equate a DIE to a particular declaration. */
5126 static void
5127 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5129 unsigned int decl_id = DECL_UID (decl);
5130 unsigned int num_allocated;
5132 if (decl_id >= decl_die_table_allocated)
5134 num_allocated
5135 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5136 / DECL_DIE_TABLE_INCREMENT)
5137 * DECL_DIE_TABLE_INCREMENT;
5139 decl_die_table = ggc_realloc (decl_die_table,
5140 sizeof (dw_die_ref) * num_allocated);
5142 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5143 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5144 decl_die_table_allocated = num_allocated;
5147 if (decl_id >= decl_die_table_in_use)
5148 decl_die_table_in_use = (decl_id + 1);
5150 decl_die_table[decl_id] = decl_die;
5153 /* Keep track of the number of spaces used to indent the
5154 output of the debugging routines that print the structure of
5155 the DIE internal representation. */
5156 static int print_indent;
5158 /* Indent the line the number of spaces given by print_indent. */
5160 static inline void
5161 print_spaces (FILE *outfile)
5163 fprintf (outfile, "%*s", print_indent, "");
5166 /* Print the information associated with a given DIE, and its children.
5167 This routine is a debugging aid only. */
5169 static void
5170 print_die (dw_die_ref die, FILE *outfile)
5172 dw_attr_ref a;
5173 dw_die_ref c;
5175 print_spaces (outfile);
5176 fprintf (outfile, "DIE %4lu: %s\n",
5177 die->die_offset, dwarf_tag_name (die->die_tag));
5178 print_spaces (outfile);
5179 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5180 fprintf (outfile, " offset: %lu\n", die->die_offset);
5182 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5184 print_spaces (outfile);
5185 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5187 switch (AT_class (a))
5189 case dw_val_class_addr:
5190 fprintf (outfile, "address");
5191 break;
5192 case dw_val_class_offset:
5193 fprintf (outfile, "offset");
5194 break;
5195 case dw_val_class_loc:
5196 fprintf (outfile, "location descriptor");
5197 break;
5198 case dw_val_class_loc_list:
5199 fprintf (outfile, "location list -> label:%s",
5200 AT_loc_list (a)->ll_symbol);
5201 break;
5202 case dw_val_class_range_list:
5203 fprintf (outfile, "range list");
5204 break;
5205 case dw_val_class_const:
5206 fprintf (outfile, "%ld", AT_int (a));
5207 break;
5208 case dw_val_class_unsigned_const:
5209 fprintf (outfile, "%lu", AT_unsigned (a));
5210 break;
5211 case dw_val_class_long_long:
5212 fprintf (outfile, "constant (%lu,%lu)",
5213 a->dw_attr_val.v.val_long_long.hi,
5214 a->dw_attr_val.v.val_long_long.low);
5215 break;
5216 case dw_val_class_float:
5217 fprintf (outfile, "floating-point constant");
5218 break;
5219 case dw_val_class_flag:
5220 fprintf (outfile, "%u", AT_flag (a));
5221 break;
5222 case dw_val_class_die_ref:
5223 if (AT_ref (a) != NULL)
5225 if (AT_ref (a)->die_symbol)
5226 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5227 else
5228 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5230 else
5231 fprintf (outfile, "die -> <null>");
5232 break;
5233 case dw_val_class_lbl_id:
5234 case dw_val_class_lbl_offset:
5235 fprintf (outfile, "label: %s", AT_lbl (a));
5236 break;
5237 case dw_val_class_str:
5238 if (AT_string (a) != NULL)
5239 fprintf (outfile, "\"%s\"", AT_string (a));
5240 else
5241 fprintf (outfile, "<null>");
5242 break;
5243 default:
5244 break;
5247 fprintf (outfile, "\n");
5250 if (die->die_child != NULL)
5252 print_indent += 4;
5253 for (c = die->die_child; c != NULL; c = c->die_sib)
5254 print_die (c, outfile);
5256 print_indent -= 4;
5258 if (print_indent == 0)
5259 fprintf (outfile, "\n");
5262 /* Print the contents of the source code line number correspondence table.
5263 This routine is a debugging aid only. */
5265 static void
5266 print_dwarf_line_table (FILE *outfile)
5268 unsigned i;
5269 dw_line_info_ref line_info;
5271 fprintf (outfile, "\n\nDWARF source line information\n");
5272 for (i = 1; i < line_info_table_in_use; i++)
5274 line_info = &line_info_table[i];
5275 fprintf (outfile, "%5d: ", i);
5276 fprintf (outfile, "%-20s",
5277 VARRAY_CHAR_PTR (file_table, line_info->dw_file_num));
5278 fprintf (outfile, "%6ld", line_info->dw_line_num);
5279 fprintf (outfile, "\n");
5282 fprintf (outfile, "\n\n");
5285 /* Print the information collected for a given DIE. */
5287 void
5288 debug_dwarf_die (dw_die_ref die)
5290 print_die (die, stderr);
5293 /* Print all DWARF information collected for the compilation unit.
5294 This routine is a debugging aid only. */
5296 void
5297 debug_dwarf (void)
5299 print_indent = 0;
5300 print_die (comp_unit_die, stderr);
5301 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5302 print_dwarf_line_table (stderr);
5305 /* We build up the lists of children and attributes by pushing new ones
5306 onto the beginning of the list. Reverse the lists for DIE so that
5307 they are in order of addition. */
5309 static void
5310 reverse_die_lists (dw_die_ref die)
5312 dw_die_ref c, cp, cn;
5313 dw_attr_ref a, ap, an;
5315 for (a = die->die_attr, ap = 0; a; a = an)
5317 an = a->dw_attr_next;
5318 a->dw_attr_next = ap;
5319 ap = a;
5322 die->die_attr = ap;
5324 for (c = die->die_child, cp = 0; c; c = cn)
5326 cn = c->die_sib;
5327 c->die_sib = cp;
5328 cp = c;
5331 die->die_child = cp;
5334 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5335 reverse all dies in add_sibling_attributes, which runs through all the dies,
5336 it would reverse all the dies. Now, however, since we don't call
5337 reverse_die_lists in add_sibling_attributes, we need a routine to
5338 recursively reverse all the dies. This is that routine. */
5340 static void
5341 reverse_all_dies (dw_die_ref die)
5343 dw_die_ref c;
5345 reverse_die_lists (die);
5347 for (c = die->die_child; c; c = c->die_sib)
5348 reverse_all_dies (c);
5351 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5352 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5353 DIE that marks the start of the DIEs for this include file. */
5355 static dw_die_ref
5356 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5358 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5359 dw_die_ref new_unit = gen_compile_unit_die (filename);
5361 new_unit->die_sib = old_unit;
5362 return new_unit;
5365 /* Close an include-file CU and reopen the enclosing one. */
5367 static dw_die_ref
5368 pop_compile_unit (dw_die_ref old_unit)
5370 dw_die_ref new_unit = old_unit->die_sib;
5372 old_unit->die_sib = NULL;
5373 return new_unit;
5376 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5377 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5379 /* Calculate the checksum of a location expression. */
5381 static inline void
5382 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5384 CHECKSUM (loc->dw_loc_opc);
5385 CHECKSUM (loc->dw_loc_oprnd1);
5386 CHECKSUM (loc->dw_loc_oprnd2);
5389 /* Calculate the checksum of an attribute. */
5391 static void
5392 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5394 dw_loc_descr_ref loc;
5395 rtx r;
5397 CHECKSUM (at->dw_attr);
5399 /* We don't care about differences in file numbering. */
5400 if (at->dw_attr == DW_AT_decl_file
5401 /* Or that this was compiled with a different compiler snapshot; if
5402 the output is the same, that's what matters. */
5403 || at->dw_attr == DW_AT_producer)
5404 return;
5406 switch (AT_class (at))
5408 case dw_val_class_const:
5409 CHECKSUM (at->dw_attr_val.v.val_int);
5410 break;
5411 case dw_val_class_unsigned_const:
5412 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5413 break;
5414 case dw_val_class_long_long:
5415 CHECKSUM (at->dw_attr_val.v.val_long_long);
5416 break;
5417 case dw_val_class_float:
5418 CHECKSUM (at->dw_attr_val.v.val_float);
5419 break;
5420 case dw_val_class_flag:
5421 CHECKSUM (at->dw_attr_val.v.val_flag);
5422 break;
5423 case dw_val_class_str:
5424 CHECKSUM_STRING (AT_string (at));
5425 break;
5427 case dw_val_class_addr:
5428 r = AT_addr (at);
5429 switch (GET_CODE (r))
5431 case SYMBOL_REF:
5432 CHECKSUM_STRING (XSTR (r, 0));
5433 break;
5435 default:
5436 abort ();
5438 break;
5440 case dw_val_class_offset:
5441 CHECKSUM (at->dw_attr_val.v.val_offset);
5442 break;
5444 case dw_val_class_loc:
5445 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5446 loc_checksum (loc, ctx);
5447 break;
5449 case dw_val_class_die_ref:
5450 die_checksum (AT_ref (at), ctx, mark);
5451 break;
5453 case dw_val_class_fde_ref:
5454 case dw_val_class_lbl_id:
5455 case dw_val_class_lbl_offset:
5456 break;
5458 default:
5459 break;
5463 /* Calculate the checksum of a DIE. */
5465 static void
5466 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5468 dw_die_ref c;
5469 dw_attr_ref a;
5471 /* To avoid infinite recursion. */
5472 if (die->die_mark)
5474 CHECKSUM (die->die_mark);
5475 return;
5477 die->die_mark = ++(*mark);
5479 CHECKSUM (die->die_tag);
5481 for (a = die->die_attr; a; a = a->dw_attr_next)
5482 attr_checksum (a, ctx, mark);
5484 for (c = die->die_child; c; c = c->die_sib)
5485 die_checksum (c, ctx, mark);
5488 #undef CHECKSUM
5489 #undef CHECKSUM_STRING
5491 /* Do the location expressions look same? */
5492 static inline int
5493 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
5495 return loc1->dw_loc_opc == loc2->dw_loc_opc
5496 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
5497 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
5500 /* Do the values look the same? */
5501 static int
5502 same_dw_val_p (dw_val_node *v1, dw_val_node *v2, int *mark)
5504 dw_loc_descr_ref loc1, loc2;
5505 rtx r1, r2;
5506 unsigned i;
5508 if (v1->val_class != v2->val_class)
5509 return 0;
5511 switch (v1->val_class)
5513 case dw_val_class_const:
5514 return v1->v.val_int == v2->v.val_int;
5515 case dw_val_class_unsigned_const:
5516 return v1->v.val_unsigned == v2->v.val_unsigned;
5517 case dw_val_class_long_long:
5518 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
5519 && v1->v.val_long_long.low == v2->v.val_long_long.low;
5520 case dw_val_class_float:
5521 if (v1->v.val_float.length != v2->v.val_float.length)
5522 return 0;
5523 for (i = 0; i < v1->v.val_float.length; i++)
5524 if (v1->v.val_float.array[i] != v2->v.val_float.array[i])
5525 return 0;
5526 return 1;
5527 case dw_val_class_flag:
5528 return v1->v.val_flag == v2->v.val_flag;
5529 case dw_val_class_str:
5530 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
5532 case dw_val_class_addr:
5533 r1 = v1->v.val_addr;
5534 r2 = v2->v.val_addr;
5535 if (GET_CODE (r1) != GET_CODE (r2))
5536 return 0;
5537 switch (GET_CODE (r1))
5539 case SYMBOL_REF:
5540 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
5542 default:
5543 abort ();
5546 case dw_val_class_offset:
5547 return v1->v.val_offset == v2->v.val_offset;
5549 case dw_val_class_loc:
5550 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
5551 loc1 && loc2;
5552 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
5553 if (!same_loc_p (loc1, loc2, mark))
5554 return 0;
5555 return !loc1 && !loc2;
5557 case dw_val_class_die_ref:
5558 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
5560 case dw_val_class_fde_ref:
5561 case dw_val_class_lbl_id:
5562 case dw_val_class_lbl_offset:
5563 return 1;
5565 default:
5566 return 1;
5570 /* Do the attributes look the same? */
5572 static int
5573 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
5575 if (at1->dw_attr != at2->dw_attr)
5576 return 0;
5578 /* We don't care about differences in file numbering. */
5579 if (at1->dw_attr == DW_AT_decl_file
5580 /* Or that this was compiled with a different compiler snapshot; if
5581 the output is the same, that's what matters. */
5582 || at1->dw_attr == DW_AT_producer)
5583 return 1;
5585 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
5588 /* Do the dies look the same? */
5590 static int
5591 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
5593 dw_die_ref c1, c2;
5594 dw_attr_ref a1, a2;
5596 /* To avoid infinite recursion. */
5597 if (die1->die_mark)
5598 return die1->die_mark == die2->die_mark;
5599 die1->die_mark = die2->die_mark = ++(*mark);
5601 if (die1->die_tag != die2->die_tag)
5602 return 0;
5604 for (a1 = die1->die_attr, a2 = die2->die_attr;
5605 a1 && a2;
5606 a1 = a1->dw_attr_next, a2 = a2->dw_attr_next)
5607 if (!same_attr_p (a1, a2, mark))
5608 return 0;
5609 if (a1 || a2)
5610 return 0;
5612 for (c1 = die1->die_child, c2 = die2->die_child;
5613 c1 && c2;
5614 c1 = c1->die_sib, c2 = c2->die_sib)
5615 if (!same_die_p (c1, c2, mark))
5616 return 0;
5617 if (c1 || c2)
5618 return 0;
5620 return 1;
5623 /* Do the dies look the same? Wrapper around same_die_p. */
5625 static int
5626 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
5628 int mark = 0;
5629 int ret = same_die_p (die1, die2, &mark);
5631 unmark_all_dies (die1);
5632 unmark_all_dies (die2);
5634 return ret;
5637 /* The prefix to attach to symbols on DIEs in the current comdat debug
5638 info section. */
5639 static char *comdat_symbol_id;
5641 /* The index of the current symbol within the current comdat CU. */
5642 static unsigned int comdat_symbol_number;
5644 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5645 children, and set comdat_symbol_id accordingly. */
5647 static void
5648 compute_section_prefix (dw_die_ref unit_die)
5650 const char *die_name = get_AT_string (unit_die, DW_AT_name);
5651 const char *base = die_name ? lbasename (die_name) : "anonymous";
5652 char *name = (char *) alloca (strlen (base) + 64);
5653 char *p;
5654 int i, mark;
5655 unsigned char checksum[16];
5656 struct md5_ctx ctx;
5658 /* Compute the checksum of the DIE, then append part of it as hex digits to
5659 the name filename of the unit. */
5661 md5_init_ctx (&ctx);
5662 mark = 0;
5663 die_checksum (unit_die, &ctx, &mark);
5664 unmark_all_dies (unit_die);
5665 md5_finish_ctx (&ctx, checksum);
5667 sprintf (name, "%s.", base);
5668 clean_symbol_name (name);
5670 p = name + strlen (name);
5671 for (i = 0; i < 4; i++)
5673 sprintf (p, "%.2x", checksum[i]);
5674 p += 2;
5677 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5678 comdat_symbol_number = 0;
5681 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5683 static int
5684 is_type_die (dw_die_ref die)
5686 switch (die->die_tag)
5688 case DW_TAG_array_type:
5689 case DW_TAG_class_type:
5690 case DW_TAG_enumeration_type:
5691 case DW_TAG_pointer_type:
5692 case DW_TAG_reference_type:
5693 case DW_TAG_string_type:
5694 case DW_TAG_structure_type:
5695 case DW_TAG_subroutine_type:
5696 case DW_TAG_union_type:
5697 case DW_TAG_ptr_to_member_type:
5698 case DW_TAG_set_type:
5699 case DW_TAG_subrange_type:
5700 case DW_TAG_base_type:
5701 case DW_TAG_const_type:
5702 case DW_TAG_file_type:
5703 case DW_TAG_packed_type:
5704 case DW_TAG_volatile_type:
5705 case DW_TAG_typedef:
5706 return 1;
5707 default:
5708 return 0;
5712 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5713 Basically, we want to choose the bits that are likely to be shared between
5714 compilations (types) and leave out the bits that are specific to individual
5715 compilations (functions). */
5717 static int
5718 is_comdat_die (dw_die_ref c)
5720 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5721 we do for stabs. The advantage is a greater likelihood of sharing between
5722 objects that don't include headers in the same order (and therefore would
5723 put the base types in a different comdat). jason 8/28/00 */
5725 if (c->die_tag == DW_TAG_base_type)
5726 return 0;
5728 if (c->die_tag == DW_TAG_pointer_type
5729 || c->die_tag == DW_TAG_reference_type
5730 || c->die_tag == DW_TAG_const_type
5731 || c->die_tag == DW_TAG_volatile_type)
5733 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5735 return t ? is_comdat_die (t) : 0;
5738 return is_type_die (c);
5741 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5742 compilation unit. */
5744 static int
5745 is_symbol_die (dw_die_ref c)
5747 return (is_type_die (c)
5748 || (get_AT (c, DW_AT_declaration)
5749 && !get_AT (c, DW_AT_specification)));
5752 static char *
5753 gen_internal_sym (const char *prefix)
5755 char buf[256];
5757 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5758 return xstrdup (buf);
5761 /* Assign symbols to all worthy DIEs under DIE. */
5763 static void
5764 assign_symbol_names (dw_die_ref die)
5766 dw_die_ref c;
5768 if (is_symbol_die (die))
5770 if (comdat_symbol_id)
5772 char *p = alloca (strlen (comdat_symbol_id) + 64);
5774 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5775 comdat_symbol_id, comdat_symbol_number++);
5776 die->die_symbol = xstrdup (p);
5778 else
5779 die->die_symbol = gen_internal_sym ("LDIE");
5782 for (c = die->die_child; c != NULL; c = c->die_sib)
5783 assign_symbol_names (c);
5786 struct cu_hash_table_entry
5788 dw_die_ref cu;
5789 unsigned min_comdat_num, max_comdat_num;
5790 struct cu_hash_table_entry *next;
5793 /* Routines to manipulate hash table of CUs. */
5794 static hashval_t
5795 htab_cu_hash (const void *of)
5797 const struct cu_hash_table_entry *entry = of;
5799 return htab_hash_string (entry->cu->die_symbol);
5802 static int
5803 htab_cu_eq (const void *of1, const void *of2)
5805 const struct cu_hash_table_entry *entry1 = of1;
5806 const struct die_struct *entry2 = of2;
5808 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
5811 static void
5812 htab_cu_del (void *what)
5814 struct cu_hash_table_entry *next, *entry = what;
5816 while (entry)
5818 next = entry->next;
5819 free (entry);
5820 entry = next;
5824 /* Check whether we have already seen this CU and set up SYM_NUM
5825 accordingly. */
5826 static int
5827 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
5829 struct cu_hash_table_entry dummy;
5830 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
5832 dummy.max_comdat_num = 0;
5834 slot = (struct cu_hash_table_entry **)
5835 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
5836 INSERT);
5837 entry = *slot;
5839 for (; entry; last = entry, entry = entry->next)
5841 if (same_die_p_wrap (cu, entry->cu))
5842 break;
5845 if (entry)
5847 *sym_num = entry->min_comdat_num;
5848 return 1;
5851 entry = xcalloc (1, sizeof (struct cu_hash_table_entry));
5852 entry->cu = cu;
5853 entry->min_comdat_num = *sym_num = last->max_comdat_num;
5854 entry->next = *slot;
5855 *slot = entry;
5857 return 0;
5860 /* Record SYM_NUM to record of CU in HTABLE. */
5861 static void
5862 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
5864 struct cu_hash_table_entry **slot, *entry;
5866 slot = (struct cu_hash_table_entry **)
5867 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
5868 NO_INSERT);
5869 entry = *slot;
5871 entry->max_comdat_num = sym_num;
5874 /* Traverse the DIE (which is always comp_unit_die), and set up
5875 additional compilation units for each of the include files we see
5876 bracketed by BINCL/EINCL. */
5878 static void
5879 break_out_includes (dw_die_ref die)
5881 dw_die_ref *ptr;
5882 dw_die_ref unit = NULL;
5883 limbo_die_node *node, **pnode;
5884 htab_t cu_hash_table;
5886 for (ptr = &(die->die_child); *ptr;)
5888 dw_die_ref c = *ptr;
5890 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
5891 || (unit && is_comdat_die (c)))
5893 /* This DIE is for a secondary CU; remove it from the main one. */
5894 *ptr = c->die_sib;
5896 if (c->die_tag == DW_TAG_GNU_BINCL)
5898 unit = push_new_compile_unit (unit, c);
5899 free_die (c);
5901 else if (c->die_tag == DW_TAG_GNU_EINCL)
5903 unit = pop_compile_unit (unit);
5904 free_die (c);
5906 else
5907 add_child_die (unit, c);
5909 else
5911 /* Leave this DIE in the main CU. */
5912 ptr = &(c->die_sib);
5913 continue;
5917 #if 0
5918 /* We can only use this in debugging, since the frontend doesn't check
5919 to make sure that we leave every include file we enter. */
5920 if (unit != NULL)
5921 abort ();
5922 #endif
5924 assign_symbol_names (die);
5925 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
5926 for (node = limbo_die_list, pnode = &limbo_die_list;
5927 node;
5928 node = node->next)
5930 int is_dupl;
5932 compute_section_prefix (node->die);
5933 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
5934 &comdat_symbol_number);
5935 assign_symbol_names (node->die);
5936 if (is_dupl)
5937 *pnode = node->next;
5938 else
5940 pnode = &node->next;
5941 record_comdat_symbol_number (node->die, cu_hash_table,
5942 comdat_symbol_number);
5945 htab_delete (cu_hash_table);
5948 /* Traverse the DIE and add a sibling attribute if it may have the
5949 effect of speeding up access to siblings. To save some space,
5950 avoid generating sibling attributes for DIE's without children. */
5952 static void
5953 add_sibling_attributes (dw_die_ref die)
5955 dw_die_ref c;
5957 if (die->die_tag != DW_TAG_compile_unit
5958 && die->die_sib && die->die_child != NULL)
5959 /* Add the sibling link to the front of the attribute list. */
5960 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5962 for (c = die->die_child; c != NULL; c = c->die_sib)
5963 add_sibling_attributes (c);
5966 /* Output all location lists for the DIE and its children. */
5968 static void
5969 output_location_lists (dw_die_ref die)
5971 dw_die_ref c;
5972 dw_attr_ref d_attr;
5974 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5975 if (AT_class (d_attr) == dw_val_class_loc_list)
5976 output_loc_list (AT_loc_list (d_attr));
5978 for (c = die->die_child; c != NULL; c = c->die_sib)
5979 output_location_lists (c);
5983 /* The format of each DIE (and its attribute value pairs) is encoded in an
5984 abbreviation table. This routine builds the abbreviation table and assigns
5985 a unique abbreviation id for each abbreviation entry. The children of each
5986 die are visited recursively. */
5988 static void
5989 build_abbrev_table (dw_die_ref die)
5991 unsigned long abbrev_id;
5992 unsigned int n_alloc;
5993 dw_die_ref c;
5994 dw_attr_ref d_attr, a_attr;
5996 /* Scan the DIE references, and mark as external any that refer to
5997 DIEs from other CUs (i.e. those which are not marked). */
5998 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5999 if (AT_class (d_attr) == dw_val_class_die_ref
6000 && AT_ref (d_attr)->die_mark == 0)
6002 if (AT_ref (d_attr)->die_symbol == 0)
6003 abort ();
6005 set_AT_ref_external (d_attr, 1);
6008 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6010 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6012 if (abbrev->die_tag == die->die_tag)
6014 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
6016 a_attr = abbrev->die_attr;
6017 d_attr = die->die_attr;
6019 while (a_attr != NULL && d_attr != NULL)
6021 if ((a_attr->dw_attr != d_attr->dw_attr)
6022 || (value_format (a_attr) != value_format (d_attr)))
6023 break;
6025 a_attr = a_attr->dw_attr_next;
6026 d_attr = d_attr->dw_attr_next;
6029 if (a_attr == NULL && d_attr == NULL)
6030 break;
6035 if (abbrev_id >= abbrev_die_table_in_use)
6037 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
6039 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
6040 abbrev_die_table = ggc_realloc (abbrev_die_table,
6041 sizeof (dw_die_ref) * n_alloc);
6043 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
6044 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
6045 abbrev_die_table_allocated = n_alloc;
6048 ++abbrev_die_table_in_use;
6049 abbrev_die_table[abbrev_id] = die;
6052 die->die_abbrev = abbrev_id;
6053 for (c = die->die_child; c != NULL; c = c->die_sib)
6054 build_abbrev_table (c);
6057 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6059 static int
6060 constant_size (long unsigned int value)
6062 int log;
6064 if (value == 0)
6065 log = 0;
6066 else
6067 log = floor_log2 (value);
6069 log = log / 8;
6070 log = 1 << (floor_log2 (log) + 1);
6072 return log;
6075 /* Return the size of a DIE as it is represented in the
6076 .debug_info section. */
6078 static unsigned long
6079 size_of_die (dw_die_ref die)
6081 unsigned long size = 0;
6082 dw_attr_ref a;
6084 size += size_of_uleb128 (die->die_abbrev);
6085 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6087 switch (AT_class (a))
6089 case dw_val_class_addr:
6090 size += DWARF2_ADDR_SIZE;
6091 break;
6092 case dw_val_class_offset:
6093 size += DWARF_OFFSET_SIZE;
6094 break;
6095 case dw_val_class_loc:
6097 unsigned long lsize = size_of_locs (AT_loc (a));
6099 /* Block length. */
6100 size += constant_size (lsize);
6101 size += lsize;
6103 break;
6104 case dw_val_class_loc_list:
6105 size += DWARF_OFFSET_SIZE;
6106 break;
6107 case dw_val_class_range_list:
6108 size += DWARF_OFFSET_SIZE;
6109 break;
6110 case dw_val_class_const:
6111 size += size_of_sleb128 (AT_int (a));
6112 break;
6113 case dw_val_class_unsigned_const:
6114 size += constant_size (AT_unsigned (a));
6115 break;
6116 case dw_val_class_long_long:
6117 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
6118 break;
6119 case dw_val_class_float:
6120 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
6121 break;
6122 case dw_val_class_flag:
6123 size += 1;
6124 break;
6125 case dw_val_class_die_ref:
6126 if (AT_ref_external (a))
6127 size += DWARF2_ADDR_SIZE;
6128 else
6129 size += DWARF_OFFSET_SIZE;
6130 break;
6131 case dw_val_class_fde_ref:
6132 size += DWARF_OFFSET_SIZE;
6133 break;
6134 case dw_val_class_lbl_id:
6135 size += DWARF2_ADDR_SIZE;
6136 break;
6137 case dw_val_class_lbl_offset:
6138 size += DWARF_OFFSET_SIZE;
6139 break;
6140 case dw_val_class_str:
6141 if (AT_string_form (a) == DW_FORM_strp)
6142 size += DWARF_OFFSET_SIZE;
6143 else
6144 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
6145 break;
6146 default:
6147 abort ();
6151 return size;
6154 /* Size the debugging information associated with a given DIE. Visits the
6155 DIE's children recursively. Updates the global variable next_die_offset, on
6156 each time through. Uses the current value of next_die_offset to update the
6157 die_offset field in each DIE. */
6159 static void
6160 calc_die_sizes (dw_die_ref die)
6162 dw_die_ref c;
6164 die->die_offset = next_die_offset;
6165 next_die_offset += size_of_die (die);
6167 for (c = die->die_child; c != NULL; c = c->die_sib)
6168 calc_die_sizes (c);
6170 if (die->die_child != NULL)
6171 /* Count the null byte used to terminate sibling lists. */
6172 next_die_offset += 1;
6175 /* Set the marks for a die and its children. We do this so
6176 that we know whether or not a reference needs to use FORM_ref_addr; only
6177 DIEs in the same CU will be marked. We used to clear out the offset
6178 and use that as the flag, but ran into ordering problems. */
6180 static void
6181 mark_dies (dw_die_ref die)
6183 dw_die_ref c;
6185 if (die->die_mark)
6186 abort ();
6188 die->die_mark = 1;
6189 for (c = die->die_child; c; c = c->die_sib)
6190 mark_dies (c);
6193 /* Clear the marks for a die and its children. */
6195 static void
6196 unmark_dies (dw_die_ref die)
6198 dw_die_ref c;
6200 if (!die->die_mark)
6201 abort ();
6203 die->die_mark = 0;
6204 for (c = die->die_child; c; c = c->die_sib)
6205 unmark_dies (c);
6208 /* Clear the marks for a die, its children and referred dies. */
6210 static void
6211 unmark_all_dies (dw_die_ref die)
6213 dw_die_ref c;
6214 dw_attr_ref a;
6216 if (!die->die_mark)
6217 return;
6218 die->die_mark = 0;
6220 for (c = die->die_child; c; c = c->die_sib)
6221 unmark_all_dies (c);
6223 for (a = die->die_attr; a; a = a->dw_attr_next)
6224 if (AT_class (a) == dw_val_class_die_ref)
6225 unmark_all_dies (AT_ref (a));
6228 /* Return the size of the .debug_pubnames table generated for the
6229 compilation unit. */
6231 static unsigned long
6232 size_of_pubnames (void)
6234 unsigned long size;
6235 unsigned i;
6237 size = DWARF_PUBNAMES_HEADER_SIZE;
6238 for (i = 0; i < pubname_table_in_use; i++)
6240 pubname_ref p = &pubname_table[i];
6241 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
6244 size += DWARF_OFFSET_SIZE;
6245 return size;
6248 /* Return the size of the information in the .debug_aranges section. */
6250 static unsigned long
6251 size_of_aranges (void)
6253 unsigned long size;
6255 size = DWARF_ARANGES_HEADER_SIZE;
6257 /* Count the address/length pair for this compilation unit. */
6258 size += 2 * DWARF2_ADDR_SIZE;
6259 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6261 /* Count the two zero words used to terminated the address range table. */
6262 size += 2 * DWARF2_ADDR_SIZE;
6263 return size;
6266 /* Select the encoding of an attribute value. */
6268 static enum dwarf_form
6269 value_format (dw_attr_ref a)
6271 switch (a->dw_attr_val.val_class)
6273 case dw_val_class_addr:
6274 return DW_FORM_addr;
6275 case dw_val_class_range_list:
6276 case dw_val_class_offset:
6277 if (DWARF_OFFSET_SIZE == 4)
6278 return DW_FORM_data4;
6279 if (DWARF_OFFSET_SIZE == 8)
6280 return DW_FORM_data8;
6281 abort ();
6282 case dw_val_class_loc_list:
6283 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6284 .debug_loc section */
6285 return DW_FORM_data4;
6286 case dw_val_class_loc:
6287 switch (constant_size (size_of_locs (AT_loc (a))))
6289 case 1:
6290 return DW_FORM_block1;
6291 case 2:
6292 return DW_FORM_block2;
6293 default:
6294 abort ();
6296 case dw_val_class_const:
6297 return DW_FORM_sdata;
6298 case dw_val_class_unsigned_const:
6299 switch (constant_size (AT_unsigned (a)))
6301 case 1:
6302 return DW_FORM_data1;
6303 case 2:
6304 return DW_FORM_data2;
6305 case 4:
6306 return DW_FORM_data4;
6307 case 8:
6308 return DW_FORM_data8;
6309 default:
6310 abort ();
6312 case dw_val_class_long_long:
6313 return DW_FORM_block1;
6314 case dw_val_class_float:
6315 return DW_FORM_block1;
6316 case dw_val_class_flag:
6317 return DW_FORM_flag;
6318 case dw_val_class_die_ref:
6319 if (AT_ref_external (a))
6320 return DW_FORM_ref_addr;
6321 else
6322 return DW_FORM_ref;
6323 case dw_val_class_fde_ref:
6324 return DW_FORM_data;
6325 case dw_val_class_lbl_id:
6326 return DW_FORM_addr;
6327 case dw_val_class_lbl_offset:
6328 return DW_FORM_data;
6329 case dw_val_class_str:
6330 return AT_string_form (a);
6332 default:
6333 abort ();
6337 /* Output the encoding of an attribute value. */
6339 static void
6340 output_value_format (dw_attr_ref a)
6342 enum dwarf_form form = value_format (a);
6344 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6347 /* Output the .debug_abbrev section which defines the DIE abbreviation
6348 table. */
6350 static void
6351 output_abbrev_section (void)
6353 unsigned long abbrev_id;
6355 dw_attr_ref a_attr;
6357 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6359 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6361 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6362 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6363 dwarf_tag_name (abbrev->die_tag));
6365 if (abbrev->die_child != NULL)
6366 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6367 else
6368 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6370 for (a_attr = abbrev->die_attr; a_attr != NULL;
6371 a_attr = a_attr->dw_attr_next)
6373 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6374 dwarf_attr_name (a_attr->dw_attr));
6375 output_value_format (a_attr);
6378 dw2_asm_output_data (1, 0, NULL);
6379 dw2_asm_output_data (1, 0, NULL);
6382 /* Terminate the table. */
6383 dw2_asm_output_data (1, 0, NULL);
6386 /* Output a symbol we can use to refer to this DIE from another CU. */
6388 static inline void
6389 output_die_symbol (dw_die_ref die)
6391 char *sym = die->die_symbol;
6393 if (sym == 0)
6394 return;
6396 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6397 /* We make these global, not weak; if the target doesn't support
6398 .linkonce, it doesn't support combining the sections, so debugging
6399 will break. */
6400 (*targetm.asm_out.globalize_label) (asm_out_file, sym);
6402 ASM_OUTPUT_LABEL (asm_out_file, sym);
6405 /* Return a new location list, given the begin and end range, and the
6406 expression. gensym tells us whether to generate a new internal symbol for
6407 this location list node, which is done for the head of the list only. */
6409 static inline dw_loc_list_ref
6410 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
6411 const char *section, unsigned int gensym)
6413 dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node));
6415 retlist->begin = begin;
6416 retlist->end = end;
6417 retlist->expr = expr;
6418 retlist->section = section;
6419 if (gensym)
6420 retlist->ll_symbol = gen_internal_sym ("LLST");
6422 return retlist;
6425 /* Add a location description expression to a location list. */
6427 static inline void
6428 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
6429 const char *begin, const char *end,
6430 const char *section)
6432 dw_loc_list_ref *d;
6434 /* Find the end of the chain. */
6435 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6438 /* Add a new location list node to the list. */
6439 *d = new_loc_list (descr, begin, end, section, 0);
6442 /* Output the location list given to us. */
6444 static void
6445 output_loc_list (dw_loc_list_ref list_head)
6447 dw_loc_list_ref curr = list_head;
6449 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6451 /* ??? This shouldn't be needed now that we've forced the
6452 compilation unit base address to zero when there is code
6453 in more than one section. */
6454 if (strcmp (curr->section, ".text") == 0)
6456 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6457 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
6458 "Location list base address specifier fake entry");
6459 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6460 "Location list base address specifier base");
6463 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
6465 unsigned long size;
6467 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6468 "Location list begin address (%s)",
6469 list_head->ll_symbol);
6470 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6471 "Location list end address (%s)",
6472 list_head->ll_symbol);
6473 size = size_of_locs (curr->expr);
6475 /* Output the block length for this list of location operations. */
6476 if (size > 0xffff)
6477 abort ();
6478 dw2_asm_output_data (2, size, "%s", "Location expression size");
6480 output_loc_sequence (curr->expr);
6483 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6484 "Location list terminator begin (%s)",
6485 list_head->ll_symbol);
6486 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6487 "Location list terminator end (%s)",
6488 list_head->ll_symbol);
6491 /* Output the DIE and its attributes. Called recursively to generate
6492 the definitions of each child DIE. */
6494 static void
6495 output_die (dw_die_ref die)
6497 dw_attr_ref a;
6498 dw_die_ref c;
6499 unsigned long size;
6501 /* If someone in another CU might refer to us, set up a symbol for
6502 them to point to. */
6503 if (die->die_symbol)
6504 output_die_symbol (die);
6506 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6507 die->die_offset, dwarf_tag_name (die->die_tag));
6509 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6511 const char *name = dwarf_attr_name (a->dw_attr);
6513 switch (AT_class (a))
6515 case dw_val_class_addr:
6516 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6517 break;
6519 case dw_val_class_offset:
6520 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6521 "%s", name);
6522 break;
6524 case dw_val_class_range_list:
6526 char *p = strchr (ranges_section_label, '\0');
6528 sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset);
6529 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6530 "%s", name);
6531 *p = '\0';
6533 break;
6535 case dw_val_class_loc:
6536 size = size_of_locs (AT_loc (a));
6538 /* Output the block length for this list of location operations. */
6539 dw2_asm_output_data (constant_size (size), size, "%s", name);
6541 output_loc_sequence (AT_loc (a));
6542 break;
6544 case dw_val_class_const:
6545 /* ??? It would be slightly more efficient to use a scheme like is
6546 used for unsigned constants below, but gdb 4.x does not sign
6547 extend. Gdb 5.x does sign extend. */
6548 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6549 break;
6551 case dw_val_class_unsigned_const:
6552 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6553 AT_unsigned (a), "%s", name);
6554 break;
6556 case dw_val_class_long_long:
6558 unsigned HOST_WIDE_INT first, second;
6560 dw2_asm_output_data (1,
6561 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6562 "%s", name);
6564 if (WORDS_BIG_ENDIAN)
6566 first = a->dw_attr_val.v.val_long_long.hi;
6567 second = a->dw_attr_val.v.val_long_long.low;
6569 else
6571 first = a->dw_attr_val.v.val_long_long.low;
6572 second = a->dw_attr_val.v.val_long_long.hi;
6575 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6576 first, "long long constant");
6577 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6578 second, NULL);
6580 break;
6582 case dw_val_class_float:
6584 unsigned int i;
6586 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6587 "%s", name);
6589 for (i = 0; i < a->dw_attr_val.v.val_float.length; i++)
6590 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6591 "fp constant word %u", i);
6592 break;
6595 case dw_val_class_flag:
6596 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6597 break;
6599 case dw_val_class_loc_list:
6601 char *sym = AT_loc_list (a)->ll_symbol;
6603 if (sym == 0)
6604 abort ();
6605 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6606 loc_section_label, "%s", name);
6608 break;
6610 case dw_val_class_die_ref:
6611 if (AT_ref_external (a))
6613 char *sym = AT_ref (a)->die_symbol;
6615 if (sym == 0)
6616 abort ();
6617 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6619 else if (AT_ref (a)->die_offset == 0)
6620 abort ();
6621 else
6622 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6623 "%s", name);
6624 break;
6626 case dw_val_class_fde_ref:
6628 char l1[20];
6630 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6631 a->dw_attr_val.v.val_fde_index * 2);
6632 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6634 break;
6636 case dw_val_class_lbl_id:
6637 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6638 break;
6640 case dw_val_class_lbl_offset:
6641 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6642 break;
6644 case dw_val_class_str:
6645 if (AT_string_form (a) == DW_FORM_strp)
6646 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6647 a->dw_attr_val.v.val_str->label,
6648 "%s: \"%s\"", name, AT_string (a));
6649 else
6650 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6651 break;
6653 default:
6654 abort ();
6658 for (c = die->die_child; c != NULL; c = c->die_sib)
6659 output_die (c);
6661 /* Add null byte to terminate sibling list. */
6662 if (die->die_child != NULL)
6663 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6664 die->die_offset);
6667 /* Output the compilation unit that appears at the beginning of the
6668 .debug_info section, and precedes the DIE descriptions. */
6670 static void
6671 output_compilation_unit_header (void)
6673 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
6674 dw2_asm_output_data (4, 0xffffffff,
6675 "Initial length escape value indicating 64-bit DWARF extension");
6676 dw2_asm_output_data (DWARF_OFFSET_SIZE,
6677 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
6678 "Length of Compilation Unit Info");
6679 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6680 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6681 "Offset Into Abbrev. Section");
6682 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6685 /* Output the compilation unit DIE and its children. */
6687 static void
6688 output_comp_unit (dw_die_ref die, int output_if_empty)
6690 const char *secname;
6691 char *oldsym, *tmp;
6693 /* Unless we are outputting main CU, we may throw away empty ones. */
6694 if (!output_if_empty && die->die_child == NULL)
6695 return;
6697 /* Even if there are no children of this DIE, we must output the information
6698 about the compilation unit. Otherwise, on an empty translation unit, we
6699 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6700 will then complain when examining the file. First mark all the DIEs in
6701 this CU so we know which get local refs. */
6702 mark_dies (die);
6704 build_abbrev_table (die);
6706 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6707 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6708 calc_die_sizes (die);
6710 oldsym = die->die_symbol;
6711 if (oldsym)
6713 tmp = (char *) alloca (strlen (oldsym) + 24);
6715 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
6716 secname = tmp;
6717 die->die_symbol = NULL;
6719 else
6720 secname = (const char *) DEBUG_INFO_SECTION;
6722 /* Output debugging information. */
6723 named_section_flags (secname, SECTION_DEBUG);
6724 output_compilation_unit_header ();
6725 output_die (die);
6727 /* Leave the marks on the main CU, so we can check them in
6728 output_pubnames. */
6729 if (oldsym)
6731 unmark_dies (die);
6732 die->die_symbol = oldsym;
6736 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6737 output of lang_hooks.decl_printable_name for C++ looks like
6738 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6740 static const char *
6741 dwarf2_name (tree decl, int scope)
6743 return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0);
6746 /* Add a new entry to .debug_pubnames if appropriate. */
6748 static void
6749 add_pubname (tree decl, dw_die_ref die)
6751 pubname_ref p;
6753 if (! TREE_PUBLIC (decl))
6754 return;
6756 if (pubname_table_in_use == pubname_table_allocated)
6758 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6759 pubname_table
6760 = (pubname_ref) ggc_realloc (pubname_table,
6761 (pubname_table_allocated
6762 * sizeof (pubname_entry)));
6763 memset (pubname_table + pubname_table_in_use, 0,
6764 PUBNAME_TABLE_INCREMENT * sizeof (pubname_entry));
6767 p = &pubname_table[pubname_table_in_use++];
6768 p->die = die;
6769 p->name = xstrdup (dwarf2_name (decl, 1));
6772 /* Output the public names table used to speed up access to externally
6773 visible names. For now, only generate entries for externally
6774 visible procedures. */
6776 static void
6777 output_pubnames (void)
6779 unsigned i;
6780 unsigned long pubnames_length = size_of_pubnames ();
6782 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
6783 dw2_asm_output_data (4, 0xffffffff,
6784 "Initial length escape value indicating 64-bit DWARF extension");
6785 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6786 "Length of Public Names Info");
6787 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6788 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6789 "Offset of Compilation Unit Info");
6790 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6791 "Compilation Unit Length");
6793 for (i = 0; i < pubname_table_in_use; i++)
6795 pubname_ref pub = &pubname_table[i];
6797 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6798 if (pub->die->die_mark == 0)
6799 abort ();
6801 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6802 "DIE offset");
6804 dw2_asm_output_nstring (pub->name, -1, "external name");
6807 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6810 /* Add a new entry to .debug_aranges if appropriate. */
6812 static void
6813 add_arange (tree decl, dw_die_ref die)
6815 if (! DECL_SECTION_NAME (decl))
6816 return;
6818 if (arange_table_in_use == arange_table_allocated)
6820 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6821 arange_table = ggc_realloc (arange_table,
6822 (arange_table_allocated
6823 * sizeof (dw_die_ref)));
6824 memset (arange_table + arange_table_in_use, 0,
6825 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
6828 arange_table[arange_table_in_use++] = die;
6831 /* Output the information that goes into the .debug_aranges table.
6832 Namely, define the beginning and ending address range of the
6833 text section generated for this compilation unit. */
6835 static void
6836 output_aranges (void)
6838 unsigned i;
6839 unsigned long aranges_length = size_of_aranges ();
6841 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
6842 dw2_asm_output_data (4, 0xffffffff,
6843 "Initial length escape value indicating 64-bit DWARF extension");
6844 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6845 "Length of Address Ranges Info");
6846 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6847 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6848 "Offset of Compilation Unit Info");
6849 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6850 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6852 /* We need to align to twice the pointer size here. */
6853 if (DWARF_ARANGES_PAD_SIZE)
6855 /* Pad using a 2 byte words so that padding is correct for any
6856 pointer size. */
6857 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6858 2 * DWARF2_ADDR_SIZE);
6859 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6860 dw2_asm_output_data (2, 0, NULL);
6863 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6864 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6865 text_section_label, "Length");
6867 for (i = 0; i < arange_table_in_use; i++)
6869 dw_die_ref die = arange_table[i];
6871 /* We shouldn't see aranges for DIEs outside of the main CU. */
6872 if (die->die_mark == 0)
6873 abort ();
6875 if (die->die_tag == DW_TAG_subprogram)
6877 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6878 "Address");
6879 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6880 get_AT_low_pc (die), "Length");
6882 else
6884 /* A static variable; extract the symbol from DW_AT_location.
6885 Note that this code isn't currently hit, as we only emit
6886 aranges for functions (jason 9/23/99). */
6887 dw_attr_ref a = get_AT (die, DW_AT_location);
6888 dw_loc_descr_ref loc;
6890 if (! a || AT_class (a) != dw_val_class_loc)
6891 abort ();
6893 loc = AT_loc (a);
6894 if (loc->dw_loc_opc != DW_OP_addr)
6895 abort ();
6897 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6898 loc->dw_loc_oprnd1.v.val_addr, "Address");
6899 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6900 get_AT_unsigned (die, DW_AT_byte_size),
6901 "Length");
6905 /* Output the terminator words. */
6906 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6907 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6910 /* Add a new entry to .debug_ranges. Return the offset at which it
6911 was placed. */
6913 static unsigned int
6914 add_ranges (tree block)
6916 unsigned int in_use = ranges_table_in_use;
6918 if (in_use == ranges_table_allocated)
6920 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6921 ranges_table = (dw_ranges_ref)
6922 ggc_realloc (ranges_table, (ranges_table_allocated
6923 * sizeof (struct dw_ranges_struct)));
6924 memset (ranges_table + ranges_table_in_use, 0,
6925 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
6928 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6929 ranges_table_in_use = in_use + 1;
6931 return in_use * 2 * DWARF2_ADDR_SIZE;
6934 static void
6935 output_ranges (void)
6937 unsigned i;
6938 static const char *const start_fmt = "Offset 0x%x";
6939 const char *fmt = start_fmt;
6941 for (i = 0; i < ranges_table_in_use; i++)
6943 int block_num = ranges_table[i].block_num;
6945 if (block_num)
6947 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6948 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6950 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6951 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6953 /* If all code is in the text section, then the compilation
6954 unit base address defaults to DW_AT_low_pc, which is the
6955 base of the text section. */
6956 if (separate_line_info_table_in_use == 0)
6958 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6959 text_section_label,
6960 fmt, i * 2 * DWARF2_ADDR_SIZE);
6961 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6962 text_section_label, NULL);
6965 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6966 compilation unit base address to zero, which allows us to
6967 use absolute addresses, and not worry about whether the
6968 target supports cross-section arithmetic. */
6969 else
6971 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6972 fmt, i * 2 * DWARF2_ADDR_SIZE);
6973 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6976 fmt = NULL;
6978 else
6980 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6981 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6982 fmt = start_fmt;
6987 /* Data structure containing information about input files. */
6988 struct file_info
6990 char *path; /* Complete file name. */
6991 char *fname; /* File name part. */
6992 int length; /* Length of entire string. */
6993 int file_idx; /* Index in input file table. */
6994 int dir_idx; /* Index in directory table. */
6997 /* Data structure containing information about directories with source
6998 files. */
6999 struct dir_info
7001 char *path; /* Path including directory name. */
7002 int length; /* Path length. */
7003 int prefix; /* Index of directory entry which is a prefix. */
7004 int count; /* Number of files in this directory. */
7005 int dir_idx; /* Index of directory used as base. */
7006 int used; /* Used in the end? */
7009 /* Callback function for file_info comparison. We sort by looking at
7010 the directories in the path. */
7012 static int
7013 file_info_cmp (const void *p1, const void *p2)
7015 const struct file_info *s1 = p1;
7016 const struct file_info *s2 = p2;
7017 unsigned char *cp1;
7018 unsigned char *cp2;
7020 /* Take care of file names without directories. We need to make sure that
7021 we return consistent values to qsort since some will get confused if
7022 we return the same value when identical operands are passed in opposite
7023 orders. So if neither has a directory, return 0 and otherwise return
7024 1 or -1 depending on which one has the directory. */
7025 if ((s1->path == s1->fname || s2->path == s2->fname))
7026 return (s2->path == s2->fname) - (s1->path == s1->fname);
7028 cp1 = (unsigned char *) s1->path;
7029 cp2 = (unsigned char *) s2->path;
7031 while (1)
7033 ++cp1;
7034 ++cp2;
7035 /* Reached the end of the first path? If so, handle like above. */
7036 if ((cp1 == (unsigned char *) s1->fname)
7037 || (cp2 == (unsigned char *) s2->fname))
7038 return ((cp2 == (unsigned char *) s2->fname)
7039 - (cp1 == (unsigned char *) s1->fname));
7041 /* Character of current path component the same? */
7042 else if (*cp1 != *cp2)
7043 return *cp1 - *cp2;
7047 /* Output the directory table and the file name table. We try to minimize
7048 the total amount of memory needed. A heuristic is used to avoid large
7049 slowdowns with many input files. */
7051 static void
7052 output_file_names (void)
7054 struct file_info *files;
7055 struct dir_info *dirs;
7056 int *saved;
7057 int *savehere;
7058 int *backmap;
7059 size_t ndirs;
7060 int idx_offset;
7061 size_t i;
7062 int idx;
7064 /* Handle the case where file_table is empty. */
7065 if (VARRAY_ACTIVE_SIZE (file_table) <= 1)
7067 dw2_asm_output_data (1, 0, "End directory table");
7068 dw2_asm_output_data (1, 0, "End file name table");
7069 return;
7072 /* Allocate the various arrays we need. */
7073 files = (struct file_info *) alloca (VARRAY_ACTIVE_SIZE (file_table)
7074 * sizeof (struct file_info));
7075 dirs = (struct dir_info *) alloca (VARRAY_ACTIVE_SIZE (file_table)
7076 * sizeof (struct dir_info));
7078 /* Sort the file names. */
7079 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7081 char *f;
7083 /* Skip all leading "./". */
7084 f = VARRAY_CHAR_PTR (file_table, i);
7085 while (f[0] == '.' && f[1] == '/')
7086 f += 2;
7088 /* Create a new array entry. */
7089 files[i].path = f;
7090 files[i].length = strlen (f);
7091 files[i].file_idx = i;
7093 /* Search for the file name part. */
7094 f = strrchr (f, '/');
7095 files[i].fname = f == NULL ? files[i].path : f + 1;
7098 qsort (files + 1, VARRAY_ACTIVE_SIZE (file_table) - 1,
7099 sizeof (files[0]), file_info_cmp);
7101 /* Find all the different directories used. */
7102 dirs[0].path = files[1].path;
7103 dirs[0].length = files[1].fname - files[1].path;
7104 dirs[0].prefix = -1;
7105 dirs[0].count = 1;
7106 dirs[0].dir_idx = 0;
7107 dirs[0].used = 0;
7108 files[1].dir_idx = 0;
7109 ndirs = 1;
7111 for (i = 2; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7112 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
7113 && memcmp (dirs[ndirs - 1].path, files[i].path,
7114 dirs[ndirs - 1].length) == 0)
7116 /* Same directory as last entry. */
7117 files[i].dir_idx = ndirs - 1;
7118 ++dirs[ndirs - 1].count;
7120 else
7122 size_t j;
7124 /* This is a new directory. */
7125 dirs[ndirs].path = files[i].path;
7126 dirs[ndirs].length = files[i].fname - files[i].path;
7127 dirs[ndirs].count = 1;
7128 dirs[ndirs].dir_idx = ndirs;
7129 dirs[ndirs].used = 0;
7130 files[i].dir_idx = ndirs;
7132 /* Search for a prefix. */
7133 dirs[ndirs].prefix = -1;
7134 for (j = 0; j < ndirs; j++)
7135 if (dirs[j].length < dirs[ndirs].length
7136 && dirs[j].length > 1
7137 && (dirs[ndirs].prefix == -1
7138 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
7139 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
7140 dirs[ndirs].prefix = j;
7142 ++ndirs;
7145 /* Now to the actual work. We have to find a subset of the directories which
7146 allow expressing the file name using references to the directory table
7147 with the least amount of characters. We do not do an exhaustive search
7148 where we would have to check out every combination of every single
7149 possible prefix. Instead we use a heuristic which provides nearly optimal
7150 results in most cases and never is much off. */
7151 saved = (int *) alloca (ndirs * sizeof (int));
7152 savehere = (int *) alloca (ndirs * sizeof (int));
7154 memset (saved, '\0', ndirs * sizeof (saved[0]));
7155 for (i = 0; i < ndirs; i++)
7157 size_t j;
7158 int total;
7160 /* We can always save some space for the current directory. But this
7161 does not mean it will be enough to justify adding the directory. */
7162 savehere[i] = dirs[i].length;
7163 total = (savehere[i] - saved[i]) * dirs[i].count;
7165 for (j = i + 1; j < ndirs; j++)
7167 savehere[j] = 0;
7168 if (saved[j] < dirs[i].length)
7170 /* Determine whether the dirs[i] path is a prefix of the
7171 dirs[j] path. */
7172 int k;
7174 k = dirs[j].prefix;
7175 while (k != -1 && k != (int) i)
7176 k = dirs[k].prefix;
7178 if (k == (int) i)
7180 /* Yes it is. We can possibly safe some memory but
7181 writing the filenames in dirs[j] relative to
7182 dirs[i]. */
7183 savehere[j] = dirs[i].length;
7184 total += (savehere[j] - saved[j]) * dirs[j].count;
7189 /* Check whether we can safe enough to justify adding the dirs[i]
7190 directory. */
7191 if (total > dirs[i].length + 1)
7193 /* It's worthwhile adding. */
7194 for (j = i; j < ndirs; j++)
7195 if (savehere[j] > 0)
7197 /* Remember how much we saved for this directory so far. */
7198 saved[j] = savehere[j];
7200 /* Remember the prefix directory. */
7201 dirs[j].dir_idx = i;
7206 /* We have to emit them in the order they appear in the file_table array
7207 since the index is used in the debug info generation. To do this
7208 efficiently we generate a back-mapping of the indices first. */
7209 backmap = (int *) alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (int));
7210 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7212 backmap[files[i].file_idx] = i;
7214 /* Mark this directory as used. */
7215 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
7218 /* That was it. We are ready to emit the information. First emit the
7219 directory name table. We have to make sure the first actually emitted
7220 directory name has index one; zero is reserved for the current working
7221 directory. Make sure we do not confuse these indices with the one for the
7222 constructed table (even though most of the time they are identical). */
7223 idx = 1;
7224 idx_offset = dirs[0].length > 0 ? 1 : 0;
7225 for (i = 1 - idx_offset; i < ndirs; i++)
7226 if (dirs[i].used != 0)
7228 dirs[i].used = idx++;
7229 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
7230 "Directory Entry: 0x%x", dirs[i].used);
7233 dw2_asm_output_data (1, 0, "End directory table");
7235 /* Correct the index for the current working directory entry if it
7236 exists. */
7237 if (idx_offset == 0)
7238 dirs[0].used = 0;
7240 /* Now write all the file names. */
7241 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7243 int file_idx = backmap[i];
7244 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
7246 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
7247 "File Entry: 0x%lx", (unsigned long) i);
7249 /* Include directory index. */
7250 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
7252 /* Modification time. */
7253 dw2_asm_output_data_uleb128 (0, NULL);
7255 /* File length in bytes. */
7256 dw2_asm_output_data_uleb128 (0, NULL);
7259 dw2_asm_output_data (1, 0, "End file name table");
7263 /* Output the source line number correspondence information. This
7264 information goes into the .debug_line section. */
7266 static void
7267 output_line_info (void)
7269 char l1[20], l2[20], p1[20], p2[20];
7270 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7271 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7272 unsigned opc;
7273 unsigned n_op_args;
7274 unsigned long lt_index;
7275 unsigned long current_line;
7276 long line_offset;
7277 long line_delta;
7278 unsigned long current_file;
7279 unsigned long function;
7281 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7282 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7283 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7284 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7286 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7287 dw2_asm_output_data (4, 0xffffffff,
7288 "Initial length escape value indicating 64-bit DWARF extension");
7289 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7290 "Length of Source Line Info");
7291 ASM_OUTPUT_LABEL (asm_out_file, l1);
7293 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7294 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7295 ASM_OUTPUT_LABEL (asm_out_file, p1);
7297 /* Define the architecture-dependent minimum instruction length (in
7298 bytes). In this implementation of DWARF, this field is used for
7299 information purposes only. Since GCC generates assembly language,
7300 we have no a priori knowledge of how many instruction bytes are
7301 generated for each source line, and therefore can use only the
7302 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7303 commands. Accordingly, we fix this as `1', which is "correct
7304 enough" for all architectures, and don't let the target override. */
7305 dw2_asm_output_data (1, 1,
7306 "Minimum Instruction Length");
7308 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7309 "Default is_stmt_start flag");
7310 dw2_asm_output_data (1, DWARF_LINE_BASE,
7311 "Line Base Value (Special Opcodes)");
7312 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7313 "Line Range Value (Special Opcodes)");
7314 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7315 "Special Opcode Base");
7317 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7319 switch (opc)
7321 case DW_LNS_advance_pc:
7322 case DW_LNS_advance_line:
7323 case DW_LNS_set_file:
7324 case DW_LNS_set_column:
7325 case DW_LNS_fixed_advance_pc:
7326 n_op_args = 1;
7327 break;
7328 default:
7329 n_op_args = 0;
7330 break;
7333 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7334 opc, n_op_args);
7337 /* Write out the information about the files we use. */
7338 output_file_names ();
7339 ASM_OUTPUT_LABEL (asm_out_file, p2);
7341 /* We used to set the address register to the first location in the text
7342 section here, but that didn't accomplish anything since we already
7343 have a line note for the opening brace of the first function. */
7345 /* Generate the line number to PC correspondence table, encoded as
7346 a series of state machine operations. */
7347 current_file = 1;
7348 current_line = 1;
7349 strcpy (prev_line_label, text_section_label);
7350 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7352 dw_line_info_ref line_info = &line_info_table[lt_index];
7354 #if 0
7355 /* Disable this optimization for now; GDB wants to see two line notes
7356 at the beginning of a function so it can find the end of the
7357 prologue. */
7359 /* Don't emit anything for redundant notes. Just updating the
7360 address doesn't accomplish anything, because we already assume
7361 that anything after the last address is this line. */
7362 if (line_info->dw_line_num == current_line
7363 && line_info->dw_file_num == current_file)
7364 continue;
7365 #endif
7367 /* Emit debug info for the address of the current line.
7369 Unfortunately, we have little choice here currently, and must always
7370 use the most general form. GCC does not know the address delta
7371 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7372 attributes which will give an upper bound on the address range. We
7373 could perhaps use length attributes to determine when it is safe to
7374 use DW_LNS_fixed_advance_pc. */
7376 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7377 if (0)
7379 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7380 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7381 "DW_LNS_fixed_advance_pc");
7382 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7384 else
7386 /* This can handle any delta. This takes
7387 4+DWARF2_ADDR_SIZE bytes. */
7388 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7389 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7390 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7391 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7394 strcpy (prev_line_label, line_label);
7396 /* Emit debug info for the source file of the current line, if
7397 different from the previous line. */
7398 if (line_info->dw_file_num != current_file)
7400 current_file = line_info->dw_file_num;
7401 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7402 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7403 VARRAY_CHAR_PTR (file_table,
7404 current_file));
7407 /* Emit debug info for the current line number, choosing the encoding
7408 that uses the least amount of space. */
7409 if (line_info->dw_line_num != current_line)
7411 line_offset = line_info->dw_line_num - current_line;
7412 line_delta = line_offset - DWARF_LINE_BASE;
7413 current_line = line_info->dw_line_num;
7414 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7415 /* This can handle deltas from -10 to 234, using the current
7416 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7417 takes 1 byte. */
7418 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7419 "line %lu", current_line);
7420 else
7422 /* This can handle any delta. This takes at least 4 bytes,
7423 depending on the value being encoded. */
7424 dw2_asm_output_data (1, DW_LNS_advance_line,
7425 "advance to line %lu", current_line);
7426 dw2_asm_output_data_sleb128 (line_offset, NULL);
7427 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7430 else
7431 /* We still need to start a new row, so output a copy insn. */
7432 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7435 /* Emit debug info for the address of the end of the function. */
7436 if (0)
7438 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7439 "DW_LNS_fixed_advance_pc");
7440 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7442 else
7444 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7445 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7446 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7447 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7450 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7451 dw2_asm_output_data_uleb128 (1, NULL);
7452 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7454 function = 0;
7455 current_file = 1;
7456 current_line = 1;
7457 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7459 dw_separate_line_info_ref line_info
7460 = &separate_line_info_table[lt_index];
7462 #if 0
7463 /* Don't emit anything for redundant notes. */
7464 if (line_info->dw_line_num == current_line
7465 && line_info->dw_file_num == current_file
7466 && line_info->function == function)
7467 goto cont;
7468 #endif
7470 /* Emit debug info for the address of the current line. If this is
7471 a new function, or the first line of a function, then we need
7472 to handle it differently. */
7473 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7474 lt_index);
7475 if (function != line_info->function)
7477 function = line_info->function;
7479 /* Set the address register to the first line in the function. */
7480 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7481 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7482 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7483 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7485 else
7487 /* ??? See the DW_LNS_advance_pc comment above. */
7488 if (0)
7490 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7491 "DW_LNS_fixed_advance_pc");
7492 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7494 else
7496 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7497 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7498 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7499 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7503 strcpy (prev_line_label, line_label);
7505 /* Emit debug info for the source file of the current line, if
7506 different from the previous line. */
7507 if (line_info->dw_file_num != current_file)
7509 current_file = line_info->dw_file_num;
7510 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7511 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7512 VARRAY_CHAR_PTR (file_table,
7513 current_file));
7516 /* Emit debug info for the current line number, choosing the encoding
7517 that uses the least amount of space. */
7518 if (line_info->dw_line_num != current_line)
7520 line_offset = line_info->dw_line_num - current_line;
7521 line_delta = line_offset - DWARF_LINE_BASE;
7522 current_line = line_info->dw_line_num;
7523 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7524 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7525 "line %lu", current_line);
7526 else
7528 dw2_asm_output_data (1, DW_LNS_advance_line,
7529 "advance to line %lu", current_line);
7530 dw2_asm_output_data_sleb128 (line_offset, NULL);
7531 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7534 else
7535 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7537 #if 0
7538 cont:
7539 #endif
7541 lt_index++;
7543 /* If we're done with a function, end its sequence. */
7544 if (lt_index == separate_line_info_table_in_use
7545 || separate_line_info_table[lt_index].function != function)
7547 current_file = 1;
7548 current_line = 1;
7550 /* Emit debug info for the address of the end of the function. */
7551 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7552 if (0)
7554 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7555 "DW_LNS_fixed_advance_pc");
7556 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7558 else
7560 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7561 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7562 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7563 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7566 /* Output the marker for the end of this sequence. */
7567 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7568 dw2_asm_output_data_uleb128 (1, NULL);
7569 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7573 /* Output the marker for the end of the line number info. */
7574 ASM_OUTPUT_LABEL (asm_out_file, l2);
7577 /* Given a pointer to a tree node for some base type, return a pointer to
7578 a DIE that describes the given type.
7580 This routine must only be called for GCC type nodes that correspond to
7581 Dwarf base (fundamental) types. */
7583 static dw_die_ref
7584 base_type_die (tree type)
7586 dw_die_ref base_type_result;
7587 const char *type_name;
7588 enum dwarf_type encoding;
7589 tree name = TYPE_NAME (type);
7591 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7592 return 0;
7594 if (name)
7596 if (TREE_CODE (name) == TYPE_DECL)
7597 name = DECL_NAME (name);
7599 type_name = IDENTIFIER_POINTER (name);
7601 else
7602 type_name = "__unknown__";
7604 switch (TREE_CODE (type))
7606 case INTEGER_TYPE:
7607 /* Carefully distinguish the C character types, without messing
7608 up if the language is not C. Note that we check only for the names
7609 that contain spaces; other names might occur by coincidence in other
7610 languages. */
7611 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7612 && (type == char_type_node
7613 || ! strcmp (type_name, "signed char")
7614 || ! strcmp (type_name, "unsigned char"))))
7616 if (TREE_UNSIGNED (type))
7617 encoding = DW_ATE_unsigned;
7618 else
7619 encoding = DW_ATE_signed;
7620 break;
7622 /* else fall through. */
7624 case CHAR_TYPE:
7625 /* GNU Pascal/Ada CHAR type. Not used in C. */
7626 if (TREE_UNSIGNED (type))
7627 encoding = DW_ATE_unsigned_char;
7628 else
7629 encoding = DW_ATE_signed_char;
7630 break;
7632 case REAL_TYPE:
7633 encoding = DW_ATE_float;
7634 break;
7636 /* Dwarf2 doesn't know anything about complex ints, so use
7637 a user defined type for it. */
7638 case COMPLEX_TYPE:
7639 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7640 encoding = DW_ATE_complex_float;
7641 else
7642 encoding = DW_ATE_lo_user;
7643 break;
7645 case BOOLEAN_TYPE:
7646 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7647 encoding = DW_ATE_boolean;
7648 break;
7650 default:
7651 /* No other TREE_CODEs are Dwarf fundamental types. */
7652 abort ();
7655 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
7656 if (demangle_name_func)
7657 type_name = (*demangle_name_func) (type_name);
7659 add_AT_string (base_type_result, DW_AT_name, type_name);
7660 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7661 int_size_in_bytes (type));
7662 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7664 return base_type_result;
7667 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7668 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7669 a given type is generally the same as the given type, except that if the
7670 given type is a pointer or reference type, then the root type of the given
7671 type is the root type of the "basis" type for the pointer or reference
7672 type. (This definition of the "root" type is recursive.) Also, the root
7673 type of a `const' qualified type or a `volatile' qualified type is the
7674 root type of the given type without the qualifiers. */
7676 static tree
7677 root_type (tree type)
7679 if (TREE_CODE (type) == ERROR_MARK)
7680 return error_mark_node;
7682 switch (TREE_CODE (type))
7684 case ERROR_MARK:
7685 return error_mark_node;
7687 case POINTER_TYPE:
7688 case REFERENCE_TYPE:
7689 return type_main_variant (root_type (TREE_TYPE (type)));
7691 default:
7692 return type_main_variant (type);
7696 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
7697 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7699 static inline int
7700 is_base_type (tree type)
7702 switch (TREE_CODE (type))
7704 case ERROR_MARK:
7705 case VOID_TYPE:
7706 case INTEGER_TYPE:
7707 case REAL_TYPE:
7708 case COMPLEX_TYPE:
7709 case BOOLEAN_TYPE:
7710 case CHAR_TYPE:
7711 return 1;
7713 case SET_TYPE:
7714 case ARRAY_TYPE:
7715 case RECORD_TYPE:
7716 case UNION_TYPE:
7717 case QUAL_UNION_TYPE:
7718 case ENUMERAL_TYPE:
7719 case FUNCTION_TYPE:
7720 case METHOD_TYPE:
7721 case POINTER_TYPE:
7722 case REFERENCE_TYPE:
7723 case FILE_TYPE:
7724 case OFFSET_TYPE:
7725 case LANG_TYPE:
7726 case VECTOR_TYPE:
7727 return 0;
7729 default:
7730 abort ();
7733 return 0;
7736 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7737 node, return the size in bits for the type if it is a constant, or else
7738 return the alignment for the type if the type's size is not constant, or
7739 else return BITS_PER_WORD if the type actually turns out to be an
7740 ERROR_MARK node. */
7742 static inline unsigned HOST_WIDE_INT
7743 simple_type_size_in_bits (tree type)
7745 if (TREE_CODE (type) == ERROR_MARK)
7746 return BITS_PER_WORD;
7747 else if (TYPE_SIZE (type) == NULL_TREE)
7748 return 0;
7749 else if (host_integerp (TYPE_SIZE (type), 1))
7750 return tree_low_cst (TYPE_SIZE (type), 1);
7751 else
7752 return TYPE_ALIGN (type);
7755 /* Return true if the debug information for the given type should be
7756 emitted as a subrange type. */
7758 static inline bool
7759 is_ada_subrange_type (tree type)
7761 /* We do this for INTEGER_TYPEs that have names, parent types, and when
7762 we are compiling Ada code. */
7763 return (TREE_CODE (type) == INTEGER_TYPE
7764 && TYPE_NAME (type) != 0 && TREE_TYPE (type) != 0
7765 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE
7766 && TREE_UNSIGNED (TREE_TYPE (type)) && is_ada ());
7769 /* Given a pointer to a tree node for a subrange type, return a pointer
7770 to a DIE that describes the given type. */
7772 static dw_die_ref
7773 subrange_type_die (tree type)
7775 dw_die_ref subtype_die;
7776 dw_die_ref subrange_die;
7777 tree name = TYPE_NAME (type);
7779 subtype_die = base_type_die (TREE_TYPE (type));
7781 if (TREE_CODE (name) == TYPE_DECL)
7782 name = DECL_NAME (name);
7784 subrange_die = new_die (DW_TAG_subrange_type, comp_unit_die, type);
7785 add_name_attribute (subrange_die, IDENTIFIER_POINTER (name));
7786 if (TYPE_MIN_VALUE (type) != NULL)
7787 add_bound_info (subrange_die, DW_AT_lower_bound,
7788 TYPE_MIN_VALUE (type));
7789 if (TYPE_MAX_VALUE (type) != NULL)
7790 add_bound_info (subrange_die, DW_AT_upper_bound,
7791 TYPE_MAX_VALUE (type));
7792 add_AT_die_ref (subrange_die, DW_AT_type, subtype_die);
7794 return subrange_die;
7797 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7798 entry that chains various modifiers in front of the given type. */
7800 static dw_die_ref
7801 modified_type_die (tree type, int is_const_type, int is_volatile_type,
7802 dw_die_ref context_die)
7804 enum tree_code code = TREE_CODE (type);
7805 dw_die_ref mod_type_die = NULL;
7806 dw_die_ref sub_die = NULL;
7807 tree item_type = NULL;
7809 if (code != ERROR_MARK)
7811 tree qualified_type;
7813 /* See if we already have the appropriately qualified variant of
7814 this type. */
7815 qualified_type
7816 = get_qualified_type (type,
7817 ((is_const_type ? TYPE_QUAL_CONST : 0)
7818 | (is_volatile_type
7819 ? TYPE_QUAL_VOLATILE : 0)));
7821 /* If we do, then we can just use its DIE, if it exists. */
7822 if (qualified_type)
7824 mod_type_die = lookup_type_die (qualified_type);
7825 if (mod_type_die)
7826 return mod_type_die;
7829 /* Handle C typedef types. */
7830 if (qualified_type && TYPE_NAME (qualified_type)
7831 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7832 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7834 tree type_name = TYPE_NAME (qualified_type);
7835 tree dtype = TREE_TYPE (type_name);
7837 if (qualified_type == dtype)
7839 /* For a named type, use the typedef. */
7840 gen_type_die (qualified_type, context_die);
7841 mod_type_die = lookup_type_die (qualified_type);
7843 else if (is_const_type < TYPE_READONLY (dtype)
7844 || is_volatile_type < TYPE_VOLATILE (dtype))
7845 /* cv-unqualified version of named type. Just use the unnamed
7846 type to which it refers. */
7847 mod_type_die
7848 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7849 is_const_type, is_volatile_type,
7850 context_die);
7852 /* Else cv-qualified version of named type; fall through. */
7855 if (mod_type_die)
7856 /* OK. */
7858 else if (is_const_type)
7860 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
7861 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7863 else if (is_volatile_type)
7865 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
7866 sub_die = modified_type_die (type, 0, 0, context_die);
7868 else if (code == POINTER_TYPE)
7870 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
7871 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
7872 simple_type_size_in_bits (type) / BITS_PER_UNIT);
7873 #if 0
7874 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7875 #endif
7876 item_type = TREE_TYPE (type);
7878 else if (code == REFERENCE_TYPE)
7880 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
7881 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
7882 simple_type_size_in_bits (type) / BITS_PER_UNIT);
7883 #if 0
7884 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7885 #endif
7886 item_type = TREE_TYPE (type);
7888 else if (is_ada_subrange_type (type))
7889 mod_type_die = subrange_type_die (type);
7890 else if (is_base_type (type))
7891 mod_type_die = base_type_die (type);
7892 else
7894 gen_type_die (type, context_die);
7896 /* We have to get the type_main_variant here (and pass that to the
7897 `lookup_type_die' routine) because the ..._TYPE node we have
7898 might simply be a *copy* of some original type node (where the
7899 copy was created to help us keep track of typedef names) and
7900 that copy might have a different TYPE_UID from the original
7901 ..._TYPE node. */
7902 if (TREE_CODE (type) != VECTOR_TYPE)
7903 mod_type_die = lookup_type_die (type_main_variant (type));
7904 else
7905 /* Vectors have the debugging information in the type,
7906 not the main variant. */
7907 mod_type_die = lookup_type_die (type);
7908 if (mod_type_die == NULL)
7909 abort ();
7912 /* We want to equate the qualified type to the die below. */
7913 type = qualified_type;
7916 if (type)
7917 equate_type_number_to_die (type, mod_type_die);
7918 if (item_type)
7919 /* We must do this after the equate_type_number_to_die call, in case
7920 this is a recursive type. This ensures that the modified_type_die
7921 recursion will terminate even if the type is recursive. Recursive
7922 types are possible in Ada. */
7923 sub_die = modified_type_die (item_type,
7924 TYPE_READONLY (item_type),
7925 TYPE_VOLATILE (item_type),
7926 context_die);
7928 if (sub_die != NULL)
7929 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7931 return mod_type_die;
7934 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7935 an enumerated type. */
7937 static inline int
7938 type_is_enum (tree type)
7940 return TREE_CODE (type) == ENUMERAL_TYPE;
7943 /* Return the register number described by a given RTL node. */
7945 static unsigned int
7946 reg_number (rtx rtl)
7948 unsigned regno = REGNO (rtl);
7950 if (regno >= FIRST_PSEUDO_REGISTER)
7951 abort ();
7953 return DBX_REGISTER_NUMBER (regno);
7956 /* Return a location descriptor that designates a machine register or
7957 zero if there is none. */
7959 static dw_loc_descr_ref
7960 reg_loc_descriptor (rtx rtl)
7962 unsigned reg;
7963 rtx regs;
7965 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7966 return 0;
7968 reg = reg_number (rtl);
7969 regs = (*targetm.dwarf_register_span) (rtl);
7971 if (HARD_REGNO_NREGS (reg, GET_MODE (rtl)) > 1
7972 || regs)
7973 return multiple_reg_loc_descriptor (rtl, regs);
7974 else
7975 return one_reg_loc_descriptor (reg);
7978 /* Return a location descriptor that designates a machine register for
7979 a given hard register number. */
7981 static dw_loc_descr_ref
7982 one_reg_loc_descriptor (unsigned int regno)
7984 if (regno <= 31)
7985 return new_loc_descr (DW_OP_reg0 + regno, 0, 0);
7986 else
7987 return new_loc_descr (DW_OP_regx, regno, 0);
7990 /* Given an RTL of a register, return a location descriptor that
7991 designates a value that spans more than one register. */
7993 static dw_loc_descr_ref
7994 multiple_reg_loc_descriptor (rtx rtl, rtx regs)
7996 int nregs, size, i;
7997 unsigned reg;
7998 dw_loc_descr_ref loc_result = NULL;
8000 reg = reg_number (rtl);
8001 nregs = HARD_REGNO_NREGS (reg, GET_MODE (rtl));
8003 /* Simple, contiguous registers. */
8004 if (regs == NULL_RTX)
8006 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
8008 loc_result = NULL;
8009 while (nregs--)
8011 dw_loc_descr_ref t;
8013 t = one_reg_loc_descriptor (reg);
8014 add_loc_descr (&loc_result, t);
8015 add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0));
8016 ++reg;
8018 return loc_result;
8021 /* Now onto stupid register sets in non contiguous locations. */
8023 if (GET_CODE (regs) != PARALLEL)
8024 abort ();
8026 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8027 loc_result = NULL;
8029 for (i = 0; i < XVECLEN (regs, 0); ++i)
8031 dw_loc_descr_ref t;
8033 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)));
8034 add_loc_descr (&loc_result, t);
8035 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8036 add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0));
8038 return loc_result;
8041 /* Return a location descriptor that designates a constant. */
8043 static dw_loc_descr_ref
8044 int_loc_descriptor (HOST_WIDE_INT i)
8046 enum dwarf_location_atom op;
8048 /* Pick the smallest representation of a constant, rather than just
8049 defaulting to the LEB encoding. */
8050 if (i >= 0)
8052 if (i <= 31)
8053 op = DW_OP_lit0 + i;
8054 else if (i <= 0xff)
8055 op = DW_OP_const1u;
8056 else if (i <= 0xffff)
8057 op = DW_OP_const2u;
8058 else if (HOST_BITS_PER_WIDE_INT == 32
8059 || i <= 0xffffffff)
8060 op = DW_OP_const4u;
8061 else
8062 op = DW_OP_constu;
8064 else
8066 if (i >= -0x80)
8067 op = DW_OP_const1s;
8068 else if (i >= -0x8000)
8069 op = DW_OP_const2s;
8070 else if (HOST_BITS_PER_WIDE_INT == 32
8071 || i >= -0x80000000)
8072 op = DW_OP_const4s;
8073 else
8074 op = DW_OP_consts;
8077 return new_loc_descr (op, i, 0);
8080 /* Return a location descriptor that designates a base+offset location. */
8082 static dw_loc_descr_ref
8083 based_loc_descr (unsigned int reg, long int offset)
8085 dw_loc_descr_ref loc_result;
8086 /* For the "frame base", we use the frame pointer or stack pointer
8087 registers, since the RTL for local variables is relative to one of
8088 them. */
8089 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
8090 ? HARD_FRAME_POINTER_REGNUM
8091 : STACK_POINTER_REGNUM);
8093 if (reg == fp_reg)
8094 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
8095 else if (reg <= 31)
8096 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
8097 else
8098 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
8100 return loc_result;
8103 /* Return true if this RTL expression describes a base+offset calculation. */
8105 static inline int
8106 is_based_loc (rtx rtl)
8108 return (GET_CODE (rtl) == PLUS
8109 && ((GET_CODE (XEXP (rtl, 0)) == REG
8110 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
8111 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
8114 /* The following routine converts the RTL for a variable or parameter
8115 (resident in memory) into an equivalent Dwarf representation of a
8116 mechanism for getting the address of that same variable onto the top of a
8117 hypothetical "address evaluation" stack.
8119 When creating memory location descriptors, we are effectively transforming
8120 the RTL for a memory-resident object into its Dwarf postfix expression
8121 equivalent. This routine recursively descends an RTL tree, turning
8122 it into Dwarf postfix code as it goes.
8124 MODE is the mode of the memory reference, needed to handle some
8125 autoincrement addressing modes.
8127 Return 0 if we can't represent the location. */
8129 static dw_loc_descr_ref
8130 mem_loc_descriptor (rtx rtl, enum machine_mode mode)
8132 dw_loc_descr_ref mem_loc_result = NULL;
8134 /* Note that for a dynamically sized array, the location we will generate a
8135 description of here will be the lowest numbered location which is
8136 actually within the array. That's *not* necessarily the same as the
8137 zeroth element of the array. */
8139 rtl = (*targetm.delegitimize_address) (rtl);
8141 switch (GET_CODE (rtl))
8143 case POST_INC:
8144 case POST_DEC:
8145 case POST_MODIFY:
8146 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8147 just fall into the SUBREG code. */
8149 /* ... fall through ... */
8151 case SUBREG:
8152 /* The case of a subreg may arise when we have a local (register)
8153 variable or a formal (register) parameter which doesn't quite fill
8154 up an entire register. For now, just assume that it is
8155 legitimate to make the Dwarf info refer to the whole register which
8156 contains the given subreg. */
8157 rtl = SUBREG_REG (rtl);
8159 /* ... fall through ... */
8161 case REG:
8162 /* Whenever a register number forms a part of the description of the
8163 method for calculating the (dynamic) address of a memory resident
8164 object, DWARF rules require the register number be referred to as
8165 a "base register". This distinction is not based in any way upon
8166 what category of register the hardware believes the given register
8167 belongs to. This is strictly DWARF terminology we're dealing with
8168 here. Note that in cases where the location of a memory-resident
8169 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8170 OP_CONST (0)) the actual DWARF location descriptor that we generate
8171 may just be OP_BASEREG (basereg). This may look deceptively like
8172 the object in question was allocated to a register (rather than in
8173 memory) so DWARF consumers need to be aware of the subtle
8174 distinction between OP_REG and OP_BASEREG. */
8175 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
8176 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
8177 break;
8179 case MEM:
8180 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8181 if (mem_loc_result != 0)
8182 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
8183 break;
8185 case LO_SUM:
8186 rtl = XEXP (rtl, 1);
8188 /* ... fall through ... */
8190 case LABEL_REF:
8191 /* Some ports can transform a symbol ref into a label ref, because
8192 the symbol ref is too far away and has to be dumped into a constant
8193 pool. */
8194 case CONST:
8195 case SYMBOL_REF:
8196 /* Alternatively, the symbol in the constant pool might be referenced
8197 by a different symbol. */
8198 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
8200 bool marked;
8201 rtx tmp = get_pool_constant_mark (rtl, &marked);
8203 if (GET_CODE (tmp) == SYMBOL_REF)
8205 rtl = tmp;
8206 if (CONSTANT_POOL_ADDRESS_P (tmp))
8207 get_pool_constant_mark (tmp, &marked);
8208 else
8209 marked = true;
8212 /* If all references to this pool constant were optimized away,
8213 it was not output and thus we can't represent it.
8214 FIXME: might try to use DW_OP_const_value here, though
8215 DW_OP_piece complicates it. */
8216 if (!marked)
8217 return 0;
8220 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
8221 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
8222 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
8223 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
8224 break;
8226 case PRE_MODIFY:
8227 /* Extract the PLUS expression nested inside and fall into
8228 PLUS code below. */
8229 rtl = XEXP (rtl, 1);
8230 goto plus;
8232 case PRE_INC:
8233 case PRE_DEC:
8234 /* Turn these into a PLUS expression and fall into the PLUS code
8235 below. */
8236 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
8237 GEN_INT (GET_CODE (rtl) == PRE_INC
8238 ? GET_MODE_UNIT_SIZE (mode)
8239 : -GET_MODE_UNIT_SIZE (mode)));
8241 /* ... fall through ... */
8243 case PLUS:
8244 plus:
8245 if (is_based_loc (rtl))
8246 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
8247 INTVAL (XEXP (rtl, 1)));
8248 else
8250 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
8251 if (mem_loc_result == 0)
8252 break;
8254 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
8255 && INTVAL (XEXP (rtl, 1)) >= 0)
8256 add_loc_descr (&mem_loc_result,
8257 new_loc_descr (DW_OP_plus_uconst,
8258 INTVAL (XEXP (rtl, 1)), 0));
8259 else
8261 add_loc_descr (&mem_loc_result,
8262 mem_loc_descriptor (XEXP (rtl, 1), mode));
8263 add_loc_descr (&mem_loc_result,
8264 new_loc_descr (DW_OP_plus, 0, 0));
8267 break;
8269 case MULT:
8271 /* If a pseudo-reg is optimized away, it is possible for it to
8272 be replaced with a MEM containing a multiply. */
8273 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
8274 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
8276 if (op0 == 0 || op1 == 0)
8277 break;
8279 mem_loc_result = op0;
8280 add_loc_descr (&mem_loc_result, op1);
8281 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
8282 break;
8285 case CONST_INT:
8286 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
8287 break;
8289 case ADDRESSOF:
8290 /* If this is a MEM, return its address. Otherwise, we can't
8291 represent this. */
8292 if (GET_CODE (XEXP (rtl, 0)) == MEM)
8293 return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode);
8294 else
8295 return 0;
8297 default:
8298 abort ();
8301 return mem_loc_result;
8304 /* Return a descriptor that describes the concatenation of two locations.
8305 This is typically a complex variable. */
8307 static dw_loc_descr_ref
8308 concat_loc_descriptor (rtx x0, rtx x1)
8310 dw_loc_descr_ref cc_loc_result = NULL;
8311 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
8312 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
8314 if (x0_ref == 0 || x1_ref == 0)
8315 return 0;
8317 cc_loc_result = x0_ref;
8318 add_loc_descr (&cc_loc_result,
8319 new_loc_descr (DW_OP_piece,
8320 GET_MODE_SIZE (GET_MODE (x0)), 0));
8322 add_loc_descr (&cc_loc_result, x1_ref);
8323 add_loc_descr (&cc_loc_result,
8324 new_loc_descr (DW_OP_piece,
8325 GET_MODE_SIZE (GET_MODE (x1)), 0));
8327 return cc_loc_result;
8330 /* Output a proper Dwarf location descriptor for a variable or parameter
8331 which is either allocated in a register or in a memory location. For a
8332 register, we just generate an OP_REG and the register number. For a
8333 memory location we provide a Dwarf postfix expression describing how to
8334 generate the (dynamic) address of the object onto the address stack.
8336 If we don't know how to describe it, return 0. */
8338 static dw_loc_descr_ref
8339 loc_descriptor (rtx rtl)
8341 dw_loc_descr_ref loc_result = NULL;
8343 switch (GET_CODE (rtl))
8345 case SUBREG:
8346 /* The case of a subreg may arise when we have a local (register)
8347 variable or a formal (register) parameter which doesn't quite fill
8348 up an entire register. For now, just assume that it is
8349 legitimate to make the Dwarf info refer to the whole register which
8350 contains the given subreg. */
8351 rtl = SUBREG_REG (rtl);
8353 /* ... fall through ... */
8355 case REG:
8356 loc_result = reg_loc_descriptor (rtl);
8357 break;
8359 case MEM:
8360 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8361 break;
8363 case CONCAT:
8364 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8365 break;
8367 default:
8368 abort ();
8371 return loc_result;
8374 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8375 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8376 looking for an address. Otherwise, we return a value. If we can't make a
8377 descriptor, return 0. */
8379 static dw_loc_descr_ref
8380 loc_descriptor_from_tree (tree loc, int addressp)
8382 dw_loc_descr_ref ret, ret1;
8383 int indirect_p = 0;
8384 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
8385 enum dwarf_location_atom op;
8387 /* ??? Most of the time we do not take proper care for sign/zero
8388 extending the values properly. Hopefully this won't be a real
8389 problem... */
8391 switch (TREE_CODE (loc))
8393 case ERROR_MARK:
8394 return 0;
8396 case WITH_RECORD_EXPR:
8397 case PLACEHOLDER_EXPR:
8398 /* This case involves extracting fields from an object to determine the
8399 position of other fields. We don't try to encode this here. The
8400 only user of this is Ada, which encodes the needed information using
8401 the names of types. */
8402 return 0;
8404 case CALL_EXPR:
8405 return 0;
8407 case ADDR_EXPR:
8408 /* We can support this only if we can look through conversions and
8409 find an INDIRECT_EXPR. */
8410 for (loc = TREE_OPERAND (loc, 0);
8411 TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR
8412 || TREE_CODE (loc) == NON_LVALUE_EXPR
8413 || TREE_CODE (loc) == VIEW_CONVERT_EXPR
8414 || TREE_CODE (loc) == SAVE_EXPR;
8415 loc = TREE_OPERAND (loc, 0))
8418 return (TREE_CODE (loc) == INDIRECT_REF
8419 ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp)
8420 : 0);
8422 case VAR_DECL:
8423 if (DECL_THREAD_LOCAL (loc))
8425 rtx rtl;
8427 #ifndef ASM_OUTPUT_DWARF_DTPREL
8428 /* If this is not defined, we have no way to emit the data. */
8429 return 0;
8430 #endif
8432 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8433 look up addresses of objects in the current module. */
8434 if (DECL_EXTERNAL (loc))
8435 return 0;
8437 rtl = rtl_for_decl_location (loc);
8438 if (rtl == NULL_RTX)
8439 return 0;
8441 if (GET_CODE (rtl) != MEM)
8442 return 0;
8443 rtl = XEXP (rtl, 0);
8444 if (! CONSTANT_P (rtl))
8445 return 0;
8447 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
8448 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8449 ret->dw_loc_oprnd1.v.val_addr = rtl;
8451 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
8452 add_loc_descr (&ret, ret1);
8454 indirect_p = 1;
8455 break;
8457 /* FALLTHRU */
8459 case PARM_DECL:
8461 rtx rtl = rtl_for_decl_location (loc);
8463 if (rtl == NULL_RTX)
8464 return 0;
8465 else if (CONSTANT_P (rtl))
8467 ret = new_loc_descr (DW_OP_addr, 0, 0);
8468 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8469 ret->dw_loc_oprnd1.v.val_addr = rtl;
8470 indirect_p = 1;
8472 else
8474 enum machine_mode mode = GET_MODE (rtl);
8476 if (GET_CODE (rtl) == MEM)
8478 indirect_p = 1;
8479 rtl = XEXP (rtl, 0);
8482 ret = mem_loc_descriptor (rtl, mode);
8485 break;
8487 case INDIRECT_REF:
8488 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8489 indirect_p = 1;
8490 break;
8492 case COMPOUND_EXPR:
8493 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
8495 case NOP_EXPR:
8496 case CONVERT_EXPR:
8497 case NON_LVALUE_EXPR:
8498 case VIEW_CONVERT_EXPR:
8499 case SAVE_EXPR:
8500 case MODIFY_EXPR:
8501 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8503 case COMPONENT_REF:
8504 case BIT_FIELD_REF:
8505 case ARRAY_REF:
8506 case ARRAY_RANGE_REF:
8508 tree obj, offset;
8509 HOST_WIDE_INT bitsize, bitpos, bytepos;
8510 enum machine_mode mode;
8511 int volatilep;
8513 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8514 &unsignedp, &volatilep);
8516 if (obj == loc)
8517 return 0;
8519 ret = loc_descriptor_from_tree (obj, 1);
8520 if (ret == 0
8521 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
8522 return 0;
8524 if (offset != NULL_TREE)
8526 /* Variable offset. */
8527 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8528 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8531 if (!addressp)
8532 indirect_p = 1;
8534 bytepos = bitpos / BITS_PER_UNIT;
8535 if (bytepos > 0)
8536 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8537 else if (bytepos < 0)
8539 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8540 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8542 break;
8545 case INTEGER_CST:
8546 if (host_integerp (loc, 0))
8547 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8548 else
8549 return 0;
8550 break;
8552 case TRUTH_AND_EXPR:
8553 case TRUTH_ANDIF_EXPR:
8554 case BIT_AND_EXPR:
8555 op = DW_OP_and;
8556 goto do_binop;
8558 case TRUTH_XOR_EXPR:
8559 case BIT_XOR_EXPR:
8560 op = DW_OP_xor;
8561 goto do_binop;
8563 case TRUTH_OR_EXPR:
8564 case TRUTH_ORIF_EXPR:
8565 case BIT_IOR_EXPR:
8566 op = DW_OP_or;
8567 goto do_binop;
8569 case FLOOR_DIV_EXPR:
8570 case CEIL_DIV_EXPR:
8571 case ROUND_DIV_EXPR:
8572 case TRUNC_DIV_EXPR:
8573 op = DW_OP_div;
8574 goto do_binop;
8576 case MINUS_EXPR:
8577 op = DW_OP_minus;
8578 goto do_binop;
8580 case FLOOR_MOD_EXPR:
8581 case CEIL_MOD_EXPR:
8582 case ROUND_MOD_EXPR:
8583 case TRUNC_MOD_EXPR:
8584 op = DW_OP_mod;
8585 goto do_binop;
8587 case MULT_EXPR:
8588 op = DW_OP_mul;
8589 goto do_binop;
8591 case LSHIFT_EXPR:
8592 op = DW_OP_shl;
8593 goto do_binop;
8595 case RSHIFT_EXPR:
8596 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8597 goto do_binop;
8599 case PLUS_EXPR:
8600 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8601 && host_integerp (TREE_OPERAND (loc, 1), 0))
8603 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8604 if (ret == 0)
8605 return 0;
8607 add_loc_descr (&ret,
8608 new_loc_descr (DW_OP_plus_uconst,
8609 tree_low_cst (TREE_OPERAND (loc, 1),
8611 0));
8612 break;
8615 op = DW_OP_plus;
8616 goto do_binop;
8618 case LE_EXPR:
8619 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8620 return 0;
8622 op = DW_OP_le;
8623 goto do_binop;
8625 case GE_EXPR:
8626 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8627 return 0;
8629 op = DW_OP_ge;
8630 goto do_binop;
8632 case LT_EXPR:
8633 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8634 return 0;
8636 op = DW_OP_lt;
8637 goto do_binop;
8639 case GT_EXPR:
8640 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8641 return 0;
8643 op = DW_OP_gt;
8644 goto do_binop;
8646 case EQ_EXPR:
8647 op = DW_OP_eq;
8648 goto do_binop;
8650 case NE_EXPR:
8651 op = DW_OP_ne;
8652 goto do_binop;
8654 do_binop:
8655 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8656 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8657 if (ret == 0 || ret1 == 0)
8658 return 0;
8660 add_loc_descr (&ret, ret1);
8661 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8662 break;
8664 case TRUTH_NOT_EXPR:
8665 case BIT_NOT_EXPR:
8666 op = DW_OP_not;
8667 goto do_unop;
8669 case ABS_EXPR:
8670 op = DW_OP_abs;
8671 goto do_unop;
8673 case NEGATE_EXPR:
8674 op = DW_OP_neg;
8675 goto do_unop;
8677 do_unop:
8678 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8679 if (ret == 0)
8680 return 0;
8682 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8683 break;
8685 case MAX_EXPR:
8686 loc = build (COND_EXPR, TREE_TYPE (loc),
8687 build (LT_EXPR, integer_type_node,
8688 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8689 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8691 /* ... fall through ... */
8693 case COND_EXPR:
8695 dw_loc_descr_ref lhs
8696 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8697 dw_loc_descr_ref rhs
8698 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8699 dw_loc_descr_ref bra_node, jump_node, tmp;
8701 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8702 if (ret == 0 || lhs == 0 || rhs == 0)
8703 return 0;
8705 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8706 add_loc_descr (&ret, bra_node);
8708 add_loc_descr (&ret, rhs);
8709 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8710 add_loc_descr (&ret, jump_node);
8712 add_loc_descr (&ret, lhs);
8713 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8714 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
8716 /* ??? Need a node to point the skip at. Use a nop. */
8717 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8718 add_loc_descr (&ret, tmp);
8719 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8720 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8722 break;
8724 default:
8725 /* Leave front-end specific codes as simply unknown. This comes
8726 up, for instance, with the C STMT_EXPR. */
8727 if ((unsigned int) TREE_CODE (loc)
8728 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
8729 return 0;
8731 /* Otherwise this is a generic code; we should just lists all of
8732 these explicitly. Aborting means we forgot one. */
8733 abort ();
8736 /* Show if we can't fill the request for an address. */
8737 if (addressp && indirect_p == 0)
8738 return 0;
8740 /* If we've got an address and don't want one, dereference. */
8741 if (!addressp && indirect_p > 0)
8743 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8745 if (size > DWARF2_ADDR_SIZE || size == -1)
8746 return 0;
8747 else if (size == DWARF2_ADDR_SIZE)
8748 op = DW_OP_deref;
8749 else
8750 op = DW_OP_deref_size;
8752 add_loc_descr (&ret, new_loc_descr (op, size, 0));
8755 return ret;
8758 /* Given a value, round it up to the lowest multiple of `boundary'
8759 which is not less than the value itself. */
8761 static inline HOST_WIDE_INT
8762 ceiling (HOST_WIDE_INT value, unsigned int boundary)
8764 return (((value + boundary - 1) / boundary) * boundary);
8767 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8768 pointer to the declared type for the relevant field variable, or return
8769 `integer_type_node' if the given node turns out to be an
8770 ERROR_MARK node. */
8772 static inline tree
8773 field_type (tree decl)
8775 tree type;
8777 if (TREE_CODE (decl) == ERROR_MARK)
8778 return integer_type_node;
8780 type = DECL_BIT_FIELD_TYPE (decl);
8781 if (type == NULL_TREE)
8782 type = TREE_TYPE (decl);
8784 return type;
8787 /* Given a pointer to a tree node, return the alignment in bits for
8788 it, or else return BITS_PER_WORD if the node actually turns out to
8789 be an ERROR_MARK node. */
8791 static inline unsigned
8792 simple_type_align_in_bits (tree type)
8794 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8797 static inline unsigned
8798 simple_decl_align_in_bits (tree decl)
8800 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8803 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8804 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8805 or return 0 if we are unable to determine what that offset is, either
8806 because the argument turns out to be a pointer to an ERROR_MARK node, or
8807 because the offset is actually variable. (We can't handle the latter case
8808 just yet). */
8810 static HOST_WIDE_INT
8811 field_byte_offset (tree decl)
8813 unsigned int type_align_in_bits;
8814 unsigned int decl_align_in_bits;
8815 unsigned HOST_WIDE_INT type_size_in_bits;
8816 HOST_WIDE_INT object_offset_in_bits;
8817 tree type;
8818 tree field_size_tree;
8819 HOST_WIDE_INT bitpos_int;
8820 HOST_WIDE_INT deepest_bitpos;
8821 unsigned HOST_WIDE_INT field_size_in_bits;
8823 if (TREE_CODE (decl) == ERROR_MARK)
8824 return 0;
8825 else if (TREE_CODE (decl) != FIELD_DECL)
8826 abort ();
8828 type = field_type (decl);
8829 field_size_tree = DECL_SIZE (decl);
8831 /* The size could be unspecified if there was an error, or for
8832 a flexible array member. */
8833 if (! field_size_tree)
8834 field_size_tree = bitsize_zero_node;
8836 /* We cannot yet cope with fields whose positions are variable, so
8837 for now, when we see such things, we simply return 0. Someday, we may
8838 be able to handle such cases, but it will be damn difficult. */
8839 if (! host_integerp (bit_position (decl), 0))
8840 return 0;
8842 bitpos_int = int_bit_position (decl);
8844 /* If we don't know the size of the field, pretend it's a full word. */
8845 if (host_integerp (field_size_tree, 1))
8846 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8847 else
8848 field_size_in_bits = BITS_PER_WORD;
8850 type_size_in_bits = simple_type_size_in_bits (type);
8851 type_align_in_bits = simple_type_align_in_bits (type);
8852 decl_align_in_bits = simple_decl_align_in_bits (decl);
8854 /* The GCC front-end doesn't make any attempt to keep track of the starting
8855 bit offset (relative to the start of the containing structure type) of the
8856 hypothetical "containing object" for a bit-field. Thus, when computing
8857 the byte offset value for the start of the "containing object" of a
8858 bit-field, we must deduce this information on our own. This can be rather
8859 tricky to do in some cases. For example, handling the following structure
8860 type definition when compiling for an i386/i486 target (which only aligns
8861 long long's to 32-bit boundaries) can be very tricky:
8863 struct S { int field1; long long field2:31; };
8865 Fortunately, there is a simple rule-of-thumb which can be used in such
8866 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8867 structure shown above. It decides to do this based upon one simple rule
8868 for bit-field allocation. GCC allocates each "containing object" for each
8869 bit-field at the first (i.e. lowest addressed) legitimate alignment
8870 boundary (based upon the required minimum alignment for the declared type
8871 of the field) which it can possibly use, subject to the condition that
8872 there is still enough available space remaining in the containing object
8873 (when allocated at the selected point) to fully accommodate all of the
8874 bits of the bit-field itself.
8876 This simple rule makes it obvious why GCC allocates 8 bytes for each
8877 object of the structure type shown above. When looking for a place to
8878 allocate the "containing object" for `field2', the compiler simply tries
8879 to allocate a 64-bit "containing object" at each successive 32-bit
8880 boundary (starting at zero) until it finds a place to allocate that 64-
8881 bit field such that at least 31 contiguous (and previously unallocated)
8882 bits remain within that selected 64 bit field. (As it turns out, for the
8883 example above, the compiler finds it is OK to allocate the "containing
8884 object" 64-bit field at bit-offset zero within the structure type.)
8886 Here we attempt to work backwards from the limited set of facts we're
8887 given, and we try to deduce from those facts, where GCC must have believed
8888 that the containing object started (within the structure type). The value
8889 we deduce is then used (by the callers of this routine) to generate
8890 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8891 and, in the case of DW_AT_location, regular fields as well). */
8893 /* Figure out the bit-distance from the start of the structure to the
8894 "deepest" bit of the bit-field. */
8895 deepest_bitpos = bitpos_int + field_size_in_bits;
8897 /* This is the tricky part. Use some fancy footwork to deduce where the
8898 lowest addressed bit of the containing object must be. */
8899 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8901 /* Round up to type_align by default. This works best for bitfields. */
8902 object_offset_in_bits += type_align_in_bits - 1;
8903 object_offset_in_bits /= type_align_in_bits;
8904 object_offset_in_bits *= type_align_in_bits;
8906 if (object_offset_in_bits > bitpos_int)
8908 /* Sigh, the decl must be packed. */
8909 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8911 /* Round up to decl_align instead. */
8912 object_offset_in_bits += decl_align_in_bits - 1;
8913 object_offset_in_bits /= decl_align_in_bits;
8914 object_offset_in_bits *= decl_align_in_bits;
8917 return object_offset_in_bits / BITS_PER_UNIT;
8920 /* The following routines define various Dwarf attributes and any data
8921 associated with them. */
8923 /* Add a location description attribute value to a DIE.
8925 This emits location attributes suitable for whole variables and
8926 whole parameters. Note that the location attributes for struct fields are
8927 generated by the routine `data_member_location_attribute' below. */
8929 static inline void
8930 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
8931 dw_loc_descr_ref descr)
8933 if (descr != 0)
8934 add_AT_loc (die, attr_kind, descr);
8937 /* Attach the specialized form of location attribute used for data members of
8938 struct and union types. In the special case of a FIELD_DECL node which
8939 represents a bit-field, the "offset" part of this special location
8940 descriptor must indicate the distance in bytes from the lowest-addressed
8941 byte of the containing struct or union type to the lowest-addressed byte of
8942 the "containing object" for the bit-field. (See the `field_byte_offset'
8943 function above).
8945 For any given bit-field, the "containing object" is a hypothetical object
8946 (of some integral or enum type) within which the given bit-field lives. The
8947 type of this hypothetical "containing object" is always the same as the
8948 declared type of the individual bit-field itself (for GCC anyway... the
8949 DWARF spec doesn't actually mandate this). Note that it is the size (in
8950 bytes) of the hypothetical "containing object" which will be given in the
8951 DW_AT_byte_size attribute for this bit-field. (See the
8952 `byte_size_attribute' function below.) It is also used when calculating the
8953 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8954 function below.) */
8956 static void
8957 add_data_member_location_attribute (dw_die_ref die, tree decl)
8959 long offset;
8960 dw_loc_descr_ref loc_descr = 0;
8962 if (TREE_CODE (decl) == TREE_VEC)
8964 /* We're working on the TAG_inheritance for a base class. */
8965 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
8967 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8968 aren't at a fixed offset from all (sub)objects of the same
8969 type. We need to extract the appropriate offset from our
8970 vtable. The following dwarf expression means
8972 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8974 This is specific to the V3 ABI, of course. */
8976 dw_loc_descr_ref tmp;
8978 /* Make a copy of the object address. */
8979 tmp = new_loc_descr (DW_OP_dup, 0, 0);
8980 add_loc_descr (&loc_descr, tmp);
8982 /* Extract the vtable address. */
8983 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8984 add_loc_descr (&loc_descr, tmp);
8986 /* Calculate the address of the offset. */
8987 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
8988 if (offset >= 0)
8989 abort ();
8991 tmp = int_loc_descriptor (-offset);
8992 add_loc_descr (&loc_descr, tmp);
8993 tmp = new_loc_descr (DW_OP_minus, 0, 0);
8994 add_loc_descr (&loc_descr, tmp);
8996 /* Extract the offset. */
8997 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8998 add_loc_descr (&loc_descr, tmp);
9000 /* Add it to the object address. */
9001 tmp = new_loc_descr (DW_OP_plus, 0, 0);
9002 add_loc_descr (&loc_descr, tmp);
9004 else
9005 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
9007 else
9008 offset = field_byte_offset (decl);
9010 if (! loc_descr)
9012 enum dwarf_location_atom op;
9014 /* The DWARF2 standard says that we should assume that the structure
9015 address is already on the stack, so we can specify a structure field
9016 address by using DW_OP_plus_uconst. */
9018 #ifdef MIPS_DEBUGGING_INFO
9019 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9020 operator correctly. It works only if we leave the offset on the
9021 stack. */
9022 op = DW_OP_constu;
9023 #else
9024 op = DW_OP_plus_uconst;
9025 #endif
9027 loc_descr = new_loc_descr (op, offset, 0);
9030 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
9033 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9034 does not have a "location" either in memory or in a register. These
9035 things can arise in GNU C when a constant is passed as an actual parameter
9036 to an inlined function. They can also arise in C++ where declared
9037 constants do not necessarily get memory "homes". */
9039 static void
9040 add_const_value_attribute (dw_die_ref die, rtx rtl)
9042 switch (GET_CODE (rtl))
9044 case CONST_INT:
9045 /* Note that a CONST_INT rtx could represent either an integer
9046 or a floating-point constant. A CONST_INT is used whenever
9047 the constant will fit into a single word. In all such
9048 cases, the original mode of the constant value is wiped
9049 out, and the CONST_INT rtx is assigned VOIDmode. */
9051 HOST_WIDE_INT val = INTVAL (rtl);
9053 /* ??? We really should be using HOST_WIDE_INT throughout. */
9054 if (val < 0 && (long) val == val)
9055 add_AT_int (die, DW_AT_const_value, (long) val);
9056 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
9057 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
9058 else
9060 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
9061 add_AT_long_long (die, DW_AT_const_value,
9062 val >> HOST_BITS_PER_LONG, val);
9063 #else
9064 abort ();
9065 #endif
9068 break;
9070 case CONST_DOUBLE:
9071 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9072 floating-point constant. A CONST_DOUBLE is used whenever the
9073 constant requires more than one word in order to be adequately
9074 represented. We output CONST_DOUBLEs as blocks. */
9076 enum machine_mode mode = GET_MODE (rtl);
9078 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
9080 unsigned length = GET_MODE_SIZE (mode) / 4;
9081 long *array = (long *) ggc_alloc (sizeof (long) * length);
9082 REAL_VALUE_TYPE rv;
9084 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
9085 switch (mode)
9087 case SFmode:
9088 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
9089 break;
9091 case DFmode:
9092 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
9093 break;
9095 case XFmode:
9096 case TFmode:
9097 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
9098 break;
9100 default:
9101 abort ();
9104 add_AT_float (die, DW_AT_const_value, length, array);
9106 else
9108 /* ??? We really should be using HOST_WIDE_INT throughout. */
9109 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
9110 abort ();
9112 add_AT_long_long (die, DW_AT_const_value,
9113 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
9116 break;
9118 case CONST_STRING:
9119 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
9120 break;
9122 case SYMBOL_REF:
9123 case LABEL_REF:
9124 case CONST:
9125 add_AT_addr (die, DW_AT_const_value, rtl);
9126 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
9127 break;
9129 case PLUS:
9130 /* In cases where an inlined instance of an inline function is passed
9131 the address of an `auto' variable (which is local to the caller) we
9132 can get a situation where the DECL_RTL of the artificial local
9133 variable (for the inlining) which acts as a stand-in for the
9134 corresponding formal parameter (of the inline function) will look
9135 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9136 exactly a compile-time constant expression, but it isn't the address
9137 of the (artificial) local variable either. Rather, it represents the
9138 *value* which the artificial local variable always has during its
9139 lifetime. We currently have no way to represent such quasi-constant
9140 values in Dwarf, so for now we just punt and generate nothing. */
9141 break;
9143 default:
9144 /* No other kinds of rtx should be possible here. */
9145 abort ();
9150 static rtx
9151 rtl_for_decl_location (tree decl)
9153 rtx rtl;
9155 /* Here we have to decide where we are going to say the parameter "lives"
9156 (as far as the debugger is concerned). We only have a couple of
9157 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9159 DECL_RTL normally indicates where the parameter lives during most of the
9160 activation of the function. If optimization is enabled however, this
9161 could be either NULL or else a pseudo-reg. Both of those cases indicate
9162 that the parameter doesn't really live anywhere (as far as the code
9163 generation parts of GCC are concerned) during most of the function's
9164 activation. That will happen (for example) if the parameter is never
9165 referenced within the function.
9167 We could just generate a location descriptor here for all non-NULL
9168 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
9169 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
9170 where DECL_RTL is NULL or is a pseudo-reg.
9172 Note however that we can only get away with using DECL_INCOMING_RTL as
9173 a backup substitute for DECL_RTL in certain limited cases. In cases
9174 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
9175 we can be sure that the parameter was passed using the same type as it is
9176 declared to have within the function, and that its DECL_INCOMING_RTL
9177 points us to a place where a value of that type is passed.
9179 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
9180 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
9181 because in these cases DECL_INCOMING_RTL points us to a value of some
9182 type which is *different* from the type of the parameter itself. Thus,
9183 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
9184 such cases, the debugger would end up (for example) trying to fetch a
9185 `float' from a place which actually contains the first part of a
9186 `double'. That would lead to really incorrect and confusing
9187 output at debug-time.
9189 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
9190 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
9191 are a couple of exceptions however. On little-endian machines we can
9192 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
9193 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
9194 an integral type that is smaller than TREE_TYPE (decl). These cases arise
9195 when (on a little-endian machine) a non-prototyped function has a
9196 parameter declared to be of type `short' or `char'. In such cases,
9197 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
9198 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
9199 passed `int' value. If the debugger then uses that address to fetch
9200 a `short' or a `char' (on a little-endian machine) the result will be
9201 the correct data, so we allow for such exceptional cases below.
9203 Note that our goal here is to describe the place where the given formal
9204 parameter lives during most of the function's activation (i.e. between the
9205 end of the prologue and the start of the epilogue). We'll do that as best
9206 as we can. Note however that if the given formal parameter is modified
9207 sometime during the execution of the function, then a stack backtrace (at
9208 debug-time) will show the function as having been called with the *new*
9209 value rather than the value which was originally passed in. This happens
9210 rarely enough that it is not a major problem, but it *is* a problem, and
9211 I'd like to fix it.
9213 A future version of dwarf2out.c may generate two additional attributes for
9214 any given DW_TAG_formal_parameter DIE which will describe the "passed
9215 type" and the "passed location" for the given formal parameter in addition
9216 to the attributes we now generate to indicate the "declared type" and the
9217 "active location" for each parameter. This additional set of attributes
9218 could be used by debuggers for stack backtraces. Separately, note that
9219 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
9220 This happens (for example) for inlined-instances of inline function formal
9221 parameters which are never referenced. This really shouldn't be
9222 happening. All PARM_DECL nodes should get valid non-NULL
9223 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
9224 values for inlined instances of inline function parameters, so when we see
9225 such cases, we are just out-of-luck for the time being (until integrate.c
9226 gets fixed). */
9228 /* Use DECL_RTL as the "location" unless we find something better. */
9229 rtl = DECL_RTL_IF_SET (decl);
9231 /* When generating abstract instances, ignore everything except
9232 constants, symbols living in memory, and symbols living in
9233 fixed registers. */
9234 if (! reload_completed)
9236 if (rtl
9237 && (CONSTANT_P (rtl)
9238 || (GET_CODE (rtl) == MEM
9239 && CONSTANT_P (XEXP (rtl, 0)))
9240 || (GET_CODE (rtl) == REG
9241 && TREE_CODE (decl) == VAR_DECL
9242 && TREE_STATIC (decl))))
9244 rtl = (*targetm.delegitimize_address) (rtl);
9245 return rtl;
9247 rtl = NULL_RTX;
9249 else if (TREE_CODE (decl) == PARM_DECL)
9251 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
9253 tree declared_type = type_main_variant (TREE_TYPE (decl));
9254 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
9256 /* This decl represents a formal parameter which was optimized out.
9257 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
9258 all cases where (rtl == NULL_RTX) just below. */
9259 if (declared_type == passed_type)
9260 rtl = DECL_INCOMING_RTL (decl);
9261 else if (! BYTES_BIG_ENDIAN
9262 && TREE_CODE (declared_type) == INTEGER_TYPE
9263 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
9264 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
9265 rtl = DECL_INCOMING_RTL (decl);
9268 /* If the parm was passed in registers, but lives on the stack, then
9269 make a big endian correction if the mode of the type of the
9270 parameter is not the same as the mode of the rtl. */
9271 /* ??? This is the same series of checks that are made in dbxout.c before
9272 we reach the big endian correction code there. It isn't clear if all
9273 of these checks are necessary here, but keeping them all is the safe
9274 thing to do. */
9275 else if (GET_CODE (rtl) == MEM
9276 && XEXP (rtl, 0) != const0_rtx
9277 && ! CONSTANT_P (XEXP (rtl, 0))
9278 /* Not passed in memory. */
9279 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
9280 /* Not passed by invisible reference. */
9281 && (GET_CODE (XEXP (rtl, 0)) != REG
9282 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
9283 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
9284 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
9285 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
9286 #endif
9288 /* Big endian correction check. */
9289 && BYTES_BIG_ENDIAN
9290 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
9291 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
9292 < UNITS_PER_WORD))
9294 int offset = (UNITS_PER_WORD
9295 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
9297 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
9298 plus_constant (XEXP (rtl, 0), offset));
9302 if (rtl != NULL_RTX)
9304 rtl = eliminate_regs (rtl, 0, NULL_RTX);
9305 #ifdef LEAF_REG_REMAP
9306 if (current_function_uses_only_leaf_regs)
9307 leaf_renumber_regs_insn (rtl);
9308 #endif
9311 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
9312 and will have been substituted directly into all expressions that use it.
9313 C does not have such a concept, but C++ and other languages do. */
9314 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
9316 /* If a variable is initialized with a string constant without embedded
9317 zeros, build CONST_STRING. */
9318 if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
9319 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
9321 tree arrtype = TREE_TYPE (decl);
9322 tree enttype = TREE_TYPE (arrtype);
9323 tree domain = TYPE_DOMAIN (arrtype);
9324 tree init = DECL_INITIAL (decl);
9325 enum machine_mode mode = TYPE_MODE (enttype);
9327 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
9328 && domain
9329 && integer_zerop (TYPE_MIN_VALUE (domain))
9330 && compare_tree_int (TYPE_MAX_VALUE (domain),
9331 TREE_STRING_LENGTH (init) - 1) == 0
9332 && ((size_t) TREE_STRING_LENGTH (init)
9333 == strlen (TREE_STRING_POINTER (init)) + 1))
9334 rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init));
9336 /* If the initializer is something that we know will expand into an
9337 immediate RTL constant, expand it now. Expanding anything else
9338 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
9339 else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST
9340 || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST)
9342 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
9343 EXPAND_INITIALIZER);
9344 /* If expand_expr returns a MEM, it wasn't immediate. */
9345 if (rtl && GET_CODE (rtl) == MEM)
9346 abort ();
9350 if (rtl)
9351 rtl = (*targetm.delegitimize_address) (rtl);
9353 /* If we don't look past the constant pool, we risk emitting a
9354 reference to a constant pool entry that isn't referenced from
9355 code, and thus is not emitted. */
9356 if (rtl)
9357 rtl = avoid_constant_pool_reference (rtl);
9359 return rtl;
9362 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
9363 data attribute for a variable or a parameter. We generate the
9364 DW_AT_const_value attribute only in those cases where the given variable
9365 or parameter does not have a true "location" either in memory or in a
9366 register. This can happen (for example) when a constant is passed as an
9367 actual argument in a call to an inline function. (It's possible that
9368 these things can crop up in other ways also.) Note that one type of
9369 constant value which can be passed into an inlined function is a constant
9370 pointer. This can happen for example if an actual argument in an inlined
9371 function call evaluates to a compile-time constant address. */
9373 static void
9374 add_location_or_const_value_attribute (dw_die_ref die, tree decl)
9376 rtx rtl;
9377 dw_loc_descr_ref descr;
9379 if (TREE_CODE (decl) == ERROR_MARK)
9380 return;
9381 else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
9382 abort ();
9384 rtl = rtl_for_decl_location (decl);
9385 if (rtl == NULL_RTX)
9386 return;
9388 switch (GET_CODE (rtl))
9390 case ADDRESSOF:
9391 /* The address of a variable that was optimized away;
9392 don't emit anything. */
9393 break;
9395 case CONST_INT:
9396 case CONST_DOUBLE:
9397 case CONST_STRING:
9398 case SYMBOL_REF:
9399 case LABEL_REF:
9400 case CONST:
9401 case PLUS:
9402 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9403 add_const_value_attribute (die, rtl);
9404 break;
9406 case MEM:
9407 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
9409 /* Need loc_descriptor_from_tree since that's where we know
9410 how to handle TLS variables. Want the object's address
9411 since the top-level DW_AT_location assumes such. See
9412 the confusion in loc_descriptor for reference. */
9413 descr = loc_descriptor_from_tree (decl, 1);
9415 else
9417 case REG:
9418 case SUBREG:
9419 case CONCAT:
9420 descr = loc_descriptor (rtl);
9422 add_AT_location_description (die, DW_AT_location, descr);
9423 break;
9425 default:
9426 abort ();
9430 /* If we don't have a copy of this variable in memory for some reason (such
9431 as a C++ member constant that doesn't have an out-of-line definition),
9432 we should tell the debugger about the constant value. */
9434 static void
9435 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
9437 tree init = DECL_INITIAL (decl);
9438 tree type = TREE_TYPE (decl);
9440 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
9441 && initializer_constant_valid_p (init, type) == null_pointer_node)
9442 /* OK */;
9443 else
9444 return;
9446 switch (TREE_CODE (type))
9448 case INTEGER_TYPE:
9449 if (host_integerp (init, 0))
9450 add_AT_unsigned (var_die, DW_AT_const_value,
9451 tree_low_cst (init, 0));
9452 else
9453 add_AT_long_long (var_die, DW_AT_const_value,
9454 TREE_INT_CST_HIGH (init),
9455 TREE_INT_CST_LOW (init));
9456 break;
9458 default:;
9462 /* Generate a DW_AT_name attribute given some string value to be included as
9463 the value of the attribute. */
9465 static void
9466 add_name_attribute (dw_die_ref die, const char *name_string)
9468 if (name_string != NULL && *name_string != 0)
9470 if (demangle_name_func)
9471 name_string = (*demangle_name_func) (name_string);
9473 add_AT_string (die, DW_AT_name, name_string);
9477 /* Generate a DW_AT_comp_dir attribute for DIE. */
9479 static void
9480 add_comp_dir_attribute (dw_die_ref die)
9482 const char *wd = getpwd ();
9483 if (wd != NULL)
9484 add_AT_string (die, DW_AT_comp_dir, wd);
9487 /* Given a tree node describing an array bound (either lower or upper) output
9488 a representation for that bound. */
9490 static void
9491 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
9493 switch (TREE_CODE (bound))
9495 case ERROR_MARK:
9496 return;
9498 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9499 case INTEGER_CST:
9500 if (! host_integerp (bound, 0)
9501 || (bound_attr == DW_AT_lower_bound
9502 && (((is_c_family () || is_java ()) && integer_zerop (bound))
9503 || (is_fortran () && integer_onep (bound)))))
9504 /* use the default */
9506 else
9507 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
9508 break;
9510 case CONVERT_EXPR:
9511 case NOP_EXPR:
9512 case NON_LVALUE_EXPR:
9513 case VIEW_CONVERT_EXPR:
9514 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
9515 break;
9517 case SAVE_EXPR:
9518 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9519 access the upper bound values may be bogus. If they refer to a
9520 register, they may only describe how to get at these values at the
9521 points in the generated code right after they have just been
9522 computed. Worse yet, in the typical case, the upper bound values
9523 will not even *be* computed in the optimized code (though the
9524 number of elements will), so these SAVE_EXPRs are entirely
9525 bogus. In order to compensate for this fact, we check here to see
9526 if optimization is enabled, and if so, we don't add an attribute
9527 for the (unknown and unknowable) upper bound. This should not
9528 cause too much trouble for existing (stupid?) debuggers because
9529 they have to deal with empty upper bounds location descriptions
9530 anyway in order to be able to deal with incomplete array types.
9531 Of course an intelligent debugger (GDB?) should be able to
9532 comprehend that a missing upper bound specification in an array
9533 type used for a storage class `auto' local array variable
9534 indicates that the upper bound is both unknown (at compile- time)
9535 and unknowable (at run-time) due to optimization.
9537 We assume that a MEM rtx is safe because gcc wouldn't put the
9538 value there unless it was going to be used repeatedly in the
9539 function, i.e. for cleanups. */
9540 if (SAVE_EXPR_RTL (bound)
9541 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9543 dw_die_ref ctx = lookup_decl_die (current_function_decl);
9544 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound);
9545 rtx loc = SAVE_EXPR_RTL (bound);
9547 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9548 it references an outer function's frame. */
9549 if (GET_CODE (loc) == MEM)
9551 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9553 if (XEXP (loc, 0) != new_addr)
9554 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9557 add_AT_flag (decl_die, DW_AT_artificial, 1);
9558 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9559 add_AT_location_description (decl_die, DW_AT_location,
9560 loc_descriptor (loc));
9561 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9564 /* Else leave out the attribute. */
9565 break;
9567 case VAR_DECL:
9568 case PARM_DECL:
9570 dw_die_ref decl_die = lookup_decl_die (bound);
9572 /* ??? Can this happen, or should the variable have been bound
9573 first? Probably it can, since I imagine that we try to create
9574 the types of parameters in the order in which they exist in
9575 the list, and won't have created a forward reference to a
9576 later parameter. */
9577 if (decl_die != NULL)
9578 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9579 break;
9582 default:
9584 /* Otherwise try to create a stack operation procedure to
9585 evaluate the value of the array bound. */
9587 dw_die_ref ctx, decl_die;
9588 dw_loc_descr_ref loc;
9590 loc = loc_descriptor_from_tree (bound, 0);
9591 if (loc == NULL)
9592 break;
9594 if (current_function_decl == 0)
9595 ctx = comp_unit_die;
9596 else
9597 ctx = lookup_decl_die (current_function_decl);
9599 /* If we weren't able to find a context, it's most likely the case
9600 that we are processing the return type of the function. So
9601 make a SAVE_EXPR to point to it and have the limbo DIE code
9602 find the proper die. The save_expr function doesn't always
9603 make a SAVE_EXPR, so do it ourselves. */
9604 if (ctx == 0)
9605 bound = build (SAVE_EXPR, TREE_TYPE (bound), bound,
9606 current_function_decl, NULL_TREE);
9608 decl_die = new_die (DW_TAG_variable, ctx, bound);
9609 add_AT_flag (decl_die, DW_AT_artificial, 1);
9610 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9611 add_AT_loc (decl_die, DW_AT_location, loc);
9613 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9614 break;
9619 /* Note that the block of subscript information for an array type also
9620 includes information about the element type of type given array type. */
9622 static void
9623 add_subscript_info (dw_die_ref type_die, tree type)
9625 #ifndef MIPS_DEBUGGING_INFO
9626 unsigned dimension_number;
9627 #endif
9628 tree lower, upper;
9629 dw_die_ref subrange_die;
9631 /* The GNU compilers represent multidimensional array types as sequences of
9632 one dimensional array types whose element types are themselves array
9633 types. Here we squish that down, so that each multidimensional array
9634 type gets only one array_type DIE in the Dwarf debugging info. The draft
9635 Dwarf specification say that we are allowed to do this kind of
9636 compression in C (because there is no difference between an array or
9637 arrays and a multidimensional array in C) but for other source languages
9638 (e.g. Ada) we probably shouldn't do this. */
9640 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9641 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9642 We work around this by disabling this feature. See also
9643 gen_array_type_die. */
9644 #ifndef MIPS_DEBUGGING_INFO
9645 for (dimension_number = 0;
9646 TREE_CODE (type) == ARRAY_TYPE;
9647 type = TREE_TYPE (type), dimension_number++)
9648 #endif
9650 tree domain = TYPE_DOMAIN (type);
9652 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9653 and (in GNU C only) variable bounds. Handle all three forms
9654 here. */
9655 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
9656 if (domain)
9658 /* We have an array type with specified bounds. */
9659 lower = TYPE_MIN_VALUE (domain);
9660 upper = TYPE_MAX_VALUE (domain);
9662 /* define the index type. */
9663 if (TREE_TYPE (domain))
9665 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9666 TREE_TYPE field. We can't emit debug info for this
9667 because it is an unnamed integral type. */
9668 if (TREE_CODE (domain) == INTEGER_TYPE
9669 && TYPE_NAME (domain) == NULL_TREE
9670 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9671 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9673 else
9674 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9675 type_die);
9678 /* ??? If upper is NULL, the array has unspecified length,
9679 but it does have a lower bound. This happens with Fortran
9680 dimension arr(N:*)
9681 Since the debugger is definitely going to need to know N
9682 to produce useful results, go ahead and output the lower
9683 bound solo, and hope the debugger can cope. */
9685 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9686 if (upper)
9687 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9690 /* Otherwise we have an array type with an unspecified length. The
9691 DWARF-2 spec does not say how to handle this; let's just leave out the
9692 bounds. */
9696 static void
9697 add_byte_size_attribute (dw_die_ref die, tree tree_node)
9699 unsigned size;
9701 switch (TREE_CODE (tree_node))
9703 case ERROR_MARK:
9704 size = 0;
9705 break;
9706 case ENUMERAL_TYPE:
9707 case RECORD_TYPE:
9708 case UNION_TYPE:
9709 case QUAL_UNION_TYPE:
9710 size = int_size_in_bytes (tree_node);
9711 break;
9712 case FIELD_DECL:
9713 /* For a data member of a struct or union, the DW_AT_byte_size is
9714 generally given as the number of bytes normally allocated for an
9715 object of the *declared* type of the member itself. This is true
9716 even for bit-fields. */
9717 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9718 break;
9719 default:
9720 abort ();
9723 /* Note that `size' might be -1 when we get to this point. If it is, that
9724 indicates that the byte size of the entity in question is variable. We
9725 have no good way of expressing this fact in Dwarf at the present time,
9726 so just let the -1 pass on through. */
9727 add_AT_unsigned (die, DW_AT_byte_size, size);
9730 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9731 which specifies the distance in bits from the highest order bit of the
9732 "containing object" for the bit-field to the highest order bit of the
9733 bit-field itself.
9735 For any given bit-field, the "containing object" is a hypothetical object
9736 (of some integral or enum type) within which the given bit-field lives. The
9737 type of this hypothetical "containing object" is always the same as the
9738 declared type of the individual bit-field itself. The determination of the
9739 exact location of the "containing object" for a bit-field is rather
9740 complicated. It's handled by the `field_byte_offset' function (above).
9742 Note that it is the size (in bytes) of the hypothetical "containing object"
9743 which will be given in the DW_AT_byte_size attribute for this bit-field.
9744 (See `byte_size_attribute' above). */
9746 static inline void
9747 add_bit_offset_attribute (dw_die_ref die, tree decl)
9749 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9750 tree type = DECL_BIT_FIELD_TYPE (decl);
9751 HOST_WIDE_INT bitpos_int;
9752 HOST_WIDE_INT highest_order_object_bit_offset;
9753 HOST_WIDE_INT highest_order_field_bit_offset;
9754 HOST_WIDE_INT unsigned bit_offset;
9756 /* Must be a field and a bit field. */
9757 if (!type
9758 || TREE_CODE (decl) != FIELD_DECL)
9759 abort ();
9761 /* We can't yet handle bit-fields whose offsets are variable, so if we
9762 encounter such things, just return without generating any attribute
9763 whatsoever. Likewise for variable or too large size. */
9764 if (! host_integerp (bit_position (decl), 0)
9765 || ! host_integerp (DECL_SIZE (decl), 1))
9766 return;
9768 bitpos_int = int_bit_position (decl);
9770 /* Note that the bit offset is always the distance (in bits) from the
9771 highest-order bit of the "containing object" to the highest-order bit of
9772 the bit-field itself. Since the "high-order end" of any object or field
9773 is different on big-endian and little-endian machines, the computation
9774 below must take account of these differences. */
9775 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9776 highest_order_field_bit_offset = bitpos_int;
9778 if (! BYTES_BIG_ENDIAN)
9780 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9781 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9784 bit_offset
9785 = (! BYTES_BIG_ENDIAN
9786 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9787 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9789 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9792 /* For a FIELD_DECL node which represents a bit field, output an attribute
9793 which specifies the length in bits of the given field. */
9795 static inline void
9796 add_bit_size_attribute (dw_die_ref die, tree decl)
9798 /* Must be a field and a bit field. */
9799 if (TREE_CODE (decl) != FIELD_DECL
9800 || ! DECL_BIT_FIELD_TYPE (decl))
9801 abort ();
9803 if (host_integerp (DECL_SIZE (decl), 1))
9804 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9807 /* If the compiled language is ANSI C, then add a 'prototyped'
9808 attribute, if arg types are given for the parameters of a function. */
9810 static inline void
9811 add_prototyped_attribute (dw_die_ref die, tree func_type)
9813 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9814 && TYPE_ARG_TYPES (func_type) != NULL)
9815 add_AT_flag (die, DW_AT_prototyped, 1);
9818 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9819 by looking in either the type declaration or object declaration
9820 equate table. */
9822 static inline void
9823 add_abstract_origin_attribute (dw_die_ref die, tree origin)
9825 dw_die_ref origin_die = NULL;
9827 if (TREE_CODE (origin) != FUNCTION_DECL)
9829 /* We may have gotten separated from the block for the inlined
9830 function, if we're in an exception handler or some such; make
9831 sure that the abstract function has been written out.
9833 Doing this for nested functions is wrong, however; functions are
9834 distinct units, and our context might not even be inline. */
9835 tree fn = origin;
9837 if (TYPE_P (fn))
9838 fn = TYPE_STUB_DECL (fn);
9840 fn = decl_function_context (fn);
9841 if (fn)
9842 dwarf2out_abstract_function (fn);
9845 if (DECL_P (origin))
9846 origin_die = lookup_decl_die (origin);
9847 else if (TYPE_P (origin))
9848 origin_die = lookup_type_die (origin);
9850 if (origin_die == NULL)
9851 abort ();
9853 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9856 /* We do not currently support the pure_virtual attribute. */
9858 static inline void
9859 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
9861 if (DECL_VINDEX (func_decl))
9863 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9865 if (host_integerp (DECL_VINDEX (func_decl), 0))
9866 add_AT_loc (die, DW_AT_vtable_elem_location,
9867 new_loc_descr (DW_OP_constu,
9868 tree_low_cst (DECL_VINDEX (func_decl), 0),
9869 0));
9871 /* GNU extension: Record what type this method came from originally. */
9872 if (debug_info_level > DINFO_LEVEL_TERSE)
9873 add_AT_die_ref (die, DW_AT_containing_type,
9874 lookup_type_die (DECL_CONTEXT (func_decl)));
9878 /* Add source coordinate attributes for the given decl. */
9880 static void
9881 add_src_coords_attributes (dw_die_ref die, tree decl)
9883 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9885 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9886 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9889 /* Add a DW_AT_name attribute and source coordinate attribute for the
9890 given decl, but only if it actually has a name. */
9892 static void
9893 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
9895 tree decl_name;
9897 decl_name = DECL_NAME (decl);
9898 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9900 add_name_attribute (die, dwarf2_name (decl, 0));
9901 if (! DECL_ARTIFICIAL (decl))
9902 add_src_coords_attributes (die, decl);
9904 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9905 && TREE_PUBLIC (decl)
9906 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9907 && !DECL_ABSTRACT (decl))
9908 add_AT_string (die, DW_AT_MIPS_linkage_name,
9909 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9912 #ifdef VMS_DEBUGGING_INFO
9913 /* Get the function's name, as described by its RTL. This may be different
9914 from the DECL_NAME name used in the source file. */
9915 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
9917 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
9918 XEXP (DECL_RTL (decl), 0));
9919 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
9921 #endif
9924 /* Push a new declaration scope. */
9926 static void
9927 push_decl_scope (tree scope)
9929 VARRAY_PUSH_TREE (decl_scope_table, scope);
9932 /* Pop a declaration scope. */
9934 static inline void
9935 pop_decl_scope (void)
9937 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9938 abort ();
9940 VARRAY_POP (decl_scope_table);
9943 /* Return the DIE for the scope that immediately contains this type.
9944 Non-named types get global scope. Named types nested in other
9945 types get their containing scope if it's open, or global scope
9946 otherwise. All other types (i.e. function-local named types) get
9947 the current active scope. */
9949 static dw_die_ref
9950 scope_die_for (tree t, dw_die_ref context_die)
9952 dw_die_ref scope_die = NULL;
9953 tree containing_scope;
9954 int i;
9956 /* Non-types always go in the current scope. */
9957 if (! TYPE_P (t))
9958 abort ();
9960 containing_scope = TYPE_CONTEXT (t);
9962 /* Ignore namespaces for the moment. */
9963 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9964 containing_scope = NULL_TREE;
9966 /* Ignore function type "scopes" from the C frontend. They mean that
9967 a tagged type is local to a parmlist of a function declarator, but
9968 that isn't useful to DWARF. */
9969 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9970 containing_scope = NULL_TREE;
9972 if (containing_scope == NULL_TREE)
9973 scope_die = comp_unit_die;
9974 else if (TYPE_P (containing_scope))
9976 /* For types, we can just look up the appropriate DIE. But
9977 first we check to see if we're in the middle of emitting it
9978 so we know where the new DIE should go. */
9979 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9980 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
9981 break;
9983 if (i < 0)
9985 if (debug_info_level > DINFO_LEVEL_TERSE
9986 && !TREE_ASM_WRITTEN (containing_scope))
9987 abort ();
9989 /* If none of the current dies are suitable, we get file scope. */
9990 scope_die = comp_unit_die;
9992 else
9993 scope_die = lookup_type_die (containing_scope);
9995 else
9996 scope_die = context_die;
9998 return scope_die;
10001 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10003 static inline int
10004 local_scope_p (dw_die_ref context_die)
10006 for (; context_die; context_die = context_die->die_parent)
10007 if (context_die->die_tag == DW_TAG_inlined_subroutine
10008 || context_die->die_tag == DW_TAG_subprogram)
10009 return 1;
10011 return 0;
10014 /* Returns nonzero if CONTEXT_DIE is a class. */
10016 static inline int
10017 class_scope_p (dw_die_ref context_die)
10019 return (context_die
10020 && (context_die->die_tag == DW_TAG_structure_type
10021 || context_die->die_tag == DW_TAG_union_type));
10024 /* Many forms of DIEs require a "type description" attribute. This
10025 routine locates the proper "type descriptor" die for the type given
10026 by 'type', and adds a DW_AT_type attribute below the given die. */
10028 static void
10029 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
10030 int decl_volatile, dw_die_ref context_die)
10032 enum tree_code code = TREE_CODE (type);
10033 dw_die_ref type_die = NULL;
10035 /* ??? If this type is an unnamed subrange type of an integral or
10036 floating-point type, use the inner type. This is because we have no
10037 support for unnamed types in base_type_die. This can happen if this is
10038 an Ada subrange type. Correct solution is emit a subrange type die. */
10039 if ((code == INTEGER_TYPE || code == REAL_TYPE)
10040 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
10041 type = TREE_TYPE (type), code = TREE_CODE (type);
10043 if (code == ERROR_MARK
10044 /* Handle a special case. For functions whose return type is void, we
10045 generate *no* type attribute. (Note that no object may have type
10046 `void', so this only applies to function return types). */
10047 || code == VOID_TYPE)
10048 return;
10050 type_die = modified_type_die (type,
10051 decl_const || TYPE_READONLY (type),
10052 decl_volatile || TYPE_VOLATILE (type),
10053 context_die);
10055 if (type_die != NULL)
10056 add_AT_die_ref (object_die, DW_AT_type, type_die);
10059 /* Given a tree pointer to a struct, class, union, or enum type node, return
10060 a pointer to the (string) tag name for the given type, or zero if the type
10061 was declared without a tag. */
10063 static const char *
10064 type_tag (tree type)
10066 const char *name = 0;
10068 if (TYPE_NAME (type) != 0)
10070 tree t = 0;
10072 /* Find the IDENTIFIER_NODE for the type name. */
10073 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
10074 t = TYPE_NAME (type);
10076 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
10077 a TYPE_DECL node, regardless of whether or not a `typedef' was
10078 involved. */
10079 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10080 && ! DECL_IGNORED_P (TYPE_NAME (type)))
10081 t = DECL_NAME (TYPE_NAME (type));
10083 /* Now get the name as a string, or invent one. */
10084 if (t != 0)
10085 name = IDENTIFIER_POINTER (t);
10088 return (name == 0 || *name == '\0') ? 0 : name;
10091 /* Return the type associated with a data member, make a special check
10092 for bit field types. */
10094 static inline tree
10095 member_declared_type (tree member)
10097 return (DECL_BIT_FIELD_TYPE (member)
10098 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
10101 /* Get the decl's label, as described by its RTL. This may be different
10102 from the DECL_NAME name used in the source file. */
10104 #if 0
10105 static const char *
10106 decl_start_label (tree decl)
10108 rtx x;
10109 const char *fnname;
10111 x = DECL_RTL (decl);
10112 if (GET_CODE (x) != MEM)
10113 abort ();
10115 x = XEXP (x, 0);
10116 if (GET_CODE (x) != SYMBOL_REF)
10117 abort ();
10119 fnname = XSTR (x, 0);
10120 return fnname;
10122 #endif
10124 /* These routines generate the internal representation of the DIE's for
10125 the compilation unit. Debugging information is collected by walking
10126 the declaration trees passed in from dwarf2out_decl(). */
10128 static void
10129 gen_array_type_die (tree type, dw_die_ref context_die)
10131 dw_die_ref scope_die = scope_die_for (type, context_die);
10132 dw_die_ref array_die;
10133 tree element_type;
10135 /* ??? The SGI dwarf reader fails for array of array of enum types unless
10136 the inner array type comes before the outer array type. Thus we must
10137 call gen_type_die before we call new_die. See below also. */
10138 #ifdef MIPS_DEBUGGING_INFO
10139 gen_type_die (TREE_TYPE (type), context_die);
10140 #endif
10142 array_die = new_die (DW_TAG_array_type, scope_die, type);
10143 add_name_attribute (array_die, type_tag (type));
10144 equate_type_number_to_die (type, array_die);
10146 if (TREE_CODE (type) == VECTOR_TYPE)
10148 /* The frontend feeds us a representation for the vector as a struct
10149 containing an array. Pull out the array type. */
10150 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
10151 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
10154 #if 0
10155 /* We default the array ordering. SDB will probably do
10156 the right things even if DW_AT_ordering is not present. It's not even
10157 an issue until we start to get into multidimensional arrays anyway. If
10158 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
10159 then we'll have to put the DW_AT_ordering attribute back in. (But if
10160 and when we find out that we need to put these in, we will only do so
10161 for multidimensional arrays. */
10162 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
10163 #endif
10165 #ifdef MIPS_DEBUGGING_INFO
10166 /* The SGI compilers handle arrays of unknown bound by setting
10167 AT_declaration and not emitting any subrange DIEs. */
10168 if (! TYPE_DOMAIN (type))
10169 add_AT_unsigned (array_die, DW_AT_declaration, 1);
10170 else
10171 #endif
10172 add_subscript_info (array_die, type);
10174 /* Add representation of the type of the elements of this array type. */
10175 element_type = TREE_TYPE (type);
10177 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10178 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10179 We work around this by disabling this feature. See also
10180 add_subscript_info. */
10181 #ifndef MIPS_DEBUGGING_INFO
10182 while (TREE_CODE (element_type) == ARRAY_TYPE)
10183 element_type = TREE_TYPE (element_type);
10185 gen_type_die (element_type, context_die);
10186 #endif
10188 add_type_attribute (array_die, element_type, 0, 0, context_die);
10191 static void
10192 gen_set_type_die (tree type, dw_die_ref context_die)
10194 dw_die_ref type_die
10195 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
10197 equate_type_number_to_die (type, type_die);
10198 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
10201 #if 0
10202 static void
10203 gen_entry_point_die (tree decl, dw_die_ref context_die)
10205 tree origin = decl_ultimate_origin (decl);
10206 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
10208 if (origin != NULL)
10209 add_abstract_origin_attribute (decl_die, origin);
10210 else
10212 add_name_and_src_coords_attributes (decl_die, decl);
10213 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
10214 0, 0, context_die);
10217 if (DECL_ABSTRACT (decl))
10218 equate_decl_number_to_die (decl, decl_die);
10219 else
10220 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
10222 #endif
10224 /* Walk through the list of incomplete types again, trying once more to
10225 emit full debugging info for them. */
10227 static void
10228 retry_incomplete_types (void)
10230 int i;
10232 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
10233 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
10236 /* Generate a DIE to represent an inlined instance of an enumeration type. */
10238 static void
10239 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
10241 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
10243 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10244 be incomplete and such types are not marked. */
10245 add_abstract_origin_attribute (type_die, type);
10248 /* Generate a DIE to represent an inlined instance of a structure type. */
10250 static void
10251 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
10253 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
10255 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10256 be incomplete and such types are not marked. */
10257 add_abstract_origin_attribute (type_die, type);
10260 /* Generate a DIE to represent an inlined instance of a union type. */
10262 static void
10263 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
10265 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
10267 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10268 be incomplete and such types are not marked. */
10269 add_abstract_origin_attribute (type_die, type);
10272 /* Generate a DIE to represent an enumeration type. Note that these DIEs
10273 include all of the information about the enumeration values also. Each
10274 enumerated type name/value is listed as a child of the enumerated type
10275 DIE. */
10277 static void
10278 gen_enumeration_type_die (tree type, dw_die_ref context_die)
10280 dw_die_ref type_die = lookup_type_die (type);
10282 if (type_die == NULL)
10284 type_die = new_die (DW_TAG_enumeration_type,
10285 scope_die_for (type, context_die), type);
10286 equate_type_number_to_die (type, type_die);
10287 add_name_attribute (type_die, type_tag (type));
10289 else if (! TYPE_SIZE (type))
10290 return;
10291 else
10292 remove_AT (type_die, DW_AT_declaration);
10294 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
10295 given enum type is incomplete, do not generate the DW_AT_byte_size
10296 attribute or the DW_AT_element_list attribute. */
10297 if (TYPE_SIZE (type))
10299 tree link;
10301 TREE_ASM_WRITTEN (type) = 1;
10302 add_byte_size_attribute (type_die, type);
10303 if (TYPE_STUB_DECL (type) != NULL_TREE)
10304 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10306 /* If the first reference to this type was as the return type of an
10307 inline function, then it may not have a parent. Fix this now. */
10308 if (type_die->die_parent == NULL)
10309 add_child_die (scope_die_for (type, context_die), type_die);
10311 for (link = TYPE_FIELDS (type);
10312 link != NULL; link = TREE_CHAIN (link))
10314 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
10316 add_name_attribute (enum_die,
10317 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
10319 if (host_integerp (TREE_VALUE (link), 0))
10321 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
10322 add_AT_int (enum_die, DW_AT_const_value,
10323 tree_low_cst (TREE_VALUE (link), 0));
10324 else
10325 add_AT_unsigned (enum_die, DW_AT_const_value,
10326 tree_low_cst (TREE_VALUE (link), 0));
10330 else
10331 add_AT_flag (type_die, DW_AT_declaration, 1);
10334 /* Generate a DIE to represent either a real live formal parameter decl or to
10335 represent just the type of some formal parameter position in some function
10336 type.
10338 Note that this routine is a bit unusual because its argument may be a
10339 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
10340 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
10341 node. If it's the former then this function is being called to output a
10342 DIE to represent a formal parameter object (or some inlining thereof). If
10343 it's the latter, then this function is only being called to output a
10344 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
10345 argument type of some subprogram type. */
10347 static dw_die_ref
10348 gen_formal_parameter_die (tree node, dw_die_ref context_die)
10350 dw_die_ref parm_die
10351 = new_die (DW_TAG_formal_parameter, context_die, node);
10352 tree origin;
10354 switch (TREE_CODE_CLASS (TREE_CODE (node)))
10356 case 'd':
10357 origin = decl_ultimate_origin (node);
10358 if (origin != NULL)
10359 add_abstract_origin_attribute (parm_die, origin);
10360 else
10362 add_name_and_src_coords_attributes (parm_die, node);
10363 add_type_attribute (parm_die, TREE_TYPE (node),
10364 TREE_READONLY (node),
10365 TREE_THIS_VOLATILE (node),
10366 context_die);
10367 if (DECL_ARTIFICIAL (node))
10368 add_AT_flag (parm_die, DW_AT_artificial, 1);
10371 equate_decl_number_to_die (node, parm_die);
10372 if (! DECL_ABSTRACT (node))
10373 add_location_or_const_value_attribute (parm_die, node);
10375 break;
10377 case 't':
10378 /* We were called with some kind of a ..._TYPE node. */
10379 add_type_attribute (parm_die, node, 0, 0, context_die);
10380 break;
10382 default:
10383 abort ();
10386 return parm_die;
10389 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10390 at the end of an (ANSI prototyped) formal parameters list. */
10392 static void
10393 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
10395 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
10398 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10399 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10400 parameters as specified in some function type specification (except for
10401 those which appear as part of a function *definition*). */
10403 static void
10404 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
10406 tree link;
10407 tree formal_type = NULL;
10408 tree first_parm_type;
10409 tree arg;
10411 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
10413 arg = DECL_ARGUMENTS (function_or_method_type);
10414 function_or_method_type = TREE_TYPE (function_or_method_type);
10416 else
10417 arg = NULL_TREE;
10419 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
10421 /* Make our first pass over the list of formal parameter types and output a
10422 DW_TAG_formal_parameter DIE for each one. */
10423 for (link = first_parm_type; link; )
10425 dw_die_ref parm_die;
10427 formal_type = TREE_VALUE (link);
10428 if (formal_type == void_type_node)
10429 break;
10431 /* Output a (nameless) DIE to represent the formal parameter itself. */
10432 parm_die = gen_formal_parameter_die (formal_type, context_die);
10433 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
10434 && link == first_parm_type)
10435 || (arg && DECL_ARTIFICIAL (arg)))
10436 add_AT_flag (parm_die, DW_AT_artificial, 1);
10438 link = TREE_CHAIN (link);
10439 if (arg)
10440 arg = TREE_CHAIN (arg);
10443 /* If this function type has an ellipsis, add a
10444 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10445 if (formal_type != void_type_node)
10446 gen_unspecified_parameters_die (function_or_method_type, context_die);
10448 /* Make our second (and final) pass over the list of formal parameter types
10449 and output DIEs to represent those types (as necessary). */
10450 for (link = TYPE_ARG_TYPES (function_or_method_type);
10451 link && TREE_VALUE (link);
10452 link = TREE_CHAIN (link))
10453 gen_type_die (TREE_VALUE (link), context_die);
10456 /* We want to generate the DIE for TYPE so that we can generate the
10457 die for MEMBER, which has been defined; we will need to refer back
10458 to the member declaration nested within TYPE. If we're trying to
10459 generate minimal debug info for TYPE, processing TYPE won't do the
10460 trick; we need to attach the member declaration by hand. */
10462 static void
10463 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
10465 gen_type_die (type, context_die);
10467 /* If we're trying to avoid duplicate debug info, we may not have
10468 emitted the member decl for this function. Emit it now. */
10469 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10470 && ! lookup_decl_die (member))
10472 if (decl_ultimate_origin (member))
10473 abort ();
10475 push_decl_scope (type);
10476 if (TREE_CODE (member) == FUNCTION_DECL)
10477 gen_subprogram_die (member, lookup_type_die (type));
10478 else
10479 gen_variable_die (member, lookup_type_die (type));
10481 pop_decl_scope ();
10485 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10486 may later generate inlined and/or out-of-line instances of. */
10488 static void
10489 dwarf2out_abstract_function (tree decl)
10491 dw_die_ref old_die;
10492 tree save_fn;
10493 tree context;
10494 int was_abstract = DECL_ABSTRACT (decl);
10496 /* Make sure we have the actual abstract inline, not a clone. */
10497 decl = DECL_ORIGIN (decl);
10499 old_die = lookup_decl_die (decl);
10500 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10501 /* We've already generated the abstract instance. */
10502 return;
10504 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10505 we don't get confused by DECL_ABSTRACT. */
10506 if (debug_info_level > DINFO_LEVEL_TERSE)
10508 context = decl_class_context (decl);
10509 if (context)
10510 gen_type_die_for_member
10511 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
10514 /* Pretend we've just finished compiling this function. */
10515 save_fn = current_function_decl;
10516 current_function_decl = decl;
10518 set_decl_abstract_flags (decl, 1);
10519 dwarf2out_decl (decl);
10520 if (! was_abstract)
10521 set_decl_abstract_flags (decl, 0);
10523 current_function_decl = save_fn;
10526 /* Generate a DIE to represent a declared function (either file-scope or
10527 block-local). */
10529 static void
10530 gen_subprogram_die (tree decl, dw_die_ref context_die)
10532 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10533 tree origin = decl_ultimate_origin (decl);
10534 dw_die_ref subr_die;
10535 rtx fp_reg;
10536 tree fn_arg_types;
10537 tree outer_scope;
10538 dw_die_ref old_die = lookup_decl_die (decl);
10539 int declaration = (current_function_decl != decl
10540 || class_scope_p (context_die));
10542 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10543 started to generate the abstract instance of an inline, decided to output
10544 its containing class, and proceeded to emit the declaration of the inline
10545 from the member list for the class. If so, DECLARATION takes priority;
10546 we'll get back to the abstract instance when done with the class. */
10548 /* The class-scope declaration DIE must be the primary DIE. */
10549 if (origin && declaration && class_scope_p (context_die))
10551 origin = NULL;
10552 if (old_die)
10553 abort ();
10556 if (origin != NULL)
10558 if (declaration && ! local_scope_p (context_die))
10559 abort ();
10561 /* Fixup die_parent for the abstract instance of a nested
10562 inline function. */
10563 if (old_die && old_die->die_parent == NULL)
10564 add_child_die (context_die, old_die);
10566 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10567 add_abstract_origin_attribute (subr_die, origin);
10569 else if (old_die)
10571 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10573 if (!get_AT_flag (old_die, DW_AT_declaration)
10574 /* We can have a normal definition following an inline one in the
10575 case of redefinition of GNU C extern inlines.
10576 It seems reasonable to use AT_specification in this case. */
10577 && !get_AT_unsigned (old_die, DW_AT_inline))
10579 /* ??? This can happen if there is a bug in the program, for
10580 instance, if it has duplicate function definitions. Ideally,
10581 we should detect this case and ignore it. For now, if we have
10582 already reported an error, any error at all, then assume that
10583 we got here because of an input error, not a dwarf2 bug. */
10584 if (errorcount)
10585 return;
10586 abort ();
10589 /* If the definition comes from the same place as the declaration,
10590 maybe use the old DIE. We always want the DIE for this function
10591 that has the *_pc attributes to be under comp_unit_die so the
10592 debugger can find it. We also need to do this for abstract
10593 instances of inlines, since the spec requires the out-of-line copy
10594 to have the same parent. For local class methods, this doesn't
10595 apply; we just use the old DIE. */
10596 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10597 && (DECL_ARTIFICIAL (decl)
10598 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10599 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10600 == (unsigned) DECL_SOURCE_LINE (decl)))))
10602 subr_die = old_die;
10604 /* Clear out the declaration attribute and the parm types. */
10605 remove_AT (subr_die, DW_AT_declaration);
10606 remove_children (subr_die);
10608 else
10610 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10611 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10612 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10613 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10614 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10615 != (unsigned) DECL_SOURCE_LINE (decl))
10616 add_AT_unsigned
10617 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10620 else
10622 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10624 if (TREE_PUBLIC (decl))
10625 add_AT_flag (subr_die, DW_AT_external, 1);
10627 add_name_and_src_coords_attributes (subr_die, decl);
10628 if (debug_info_level > DINFO_LEVEL_TERSE)
10630 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
10631 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
10632 0, 0, context_die);
10635 add_pure_or_virtual_attribute (subr_die, decl);
10636 if (DECL_ARTIFICIAL (decl))
10637 add_AT_flag (subr_die, DW_AT_artificial, 1);
10639 if (TREE_PROTECTED (decl))
10640 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10641 else if (TREE_PRIVATE (decl))
10642 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10645 if (declaration)
10647 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10649 add_AT_flag (subr_die, DW_AT_declaration, 1);
10651 /* The first time we see a member function, it is in the context of
10652 the class to which it belongs. We make sure of this by emitting
10653 the class first. The next time is the definition, which is
10654 handled above. The two may come from the same source text. */
10655 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10656 equate_decl_number_to_die (decl, subr_die);
10659 else if (DECL_ABSTRACT (decl))
10661 if (DECL_INLINE (decl) && !flag_no_inline)
10663 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10664 inline functions, but not for extern inline functions.
10665 We can't get this completely correct because information
10666 about whether the function was declared inline is not
10667 saved anywhere. */
10668 if (DECL_DEFER_OUTPUT (decl))
10669 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10670 else
10671 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10673 else
10674 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10676 equate_decl_number_to_die (decl, subr_die);
10678 else if (!DECL_EXTERNAL (decl))
10680 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10681 equate_decl_number_to_die (decl, subr_die);
10683 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10684 current_function_funcdef_no);
10685 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10686 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10687 current_function_funcdef_no);
10688 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10690 add_pubname (decl, subr_die);
10691 add_arange (decl, subr_die);
10693 #ifdef MIPS_DEBUGGING_INFO
10694 /* Add a reference to the FDE for this routine. */
10695 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10696 #endif
10698 /* Define the "frame base" location for this routine. We use the
10699 frame pointer or stack pointer registers, since the RTL for local
10700 variables is relative to one of them. */
10701 fp_reg
10702 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10703 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10705 #if 0
10706 /* ??? This fails for nested inline functions, because context_display
10707 is not part of the state saved/restored for inline functions. */
10708 if (current_function_needs_context)
10709 add_AT_location_description (subr_die, DW_AT_static_link,
10710 loc_descriptor (lookup_static_chain (decl)));
10711 #endif
10714 /* Now output descriptions of the arguments for this function. This gets
10715 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10716 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10717 `...' at the end of the formal parameter list. In order to find out if
10718 there was a trailing ellipsis or not, we must instead look at the type
10719 associated with the FUNCTION_DECL. This will be a node of type
10720 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10721 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10722 an ellipsis at the end. */
10724 /* In the case where we are describing a mere function declaration, all we
10725 need to do here (and all we *can* do here) is to describe the *types* of
10726 its formal parameters. */
10727 if (debug_info_level <= DINFO_LEVEL_TERSE)
10729 else if (declaration)
10730 gen_formal_types_die (decl, subr_die);
10731 else
10733 /* Generate DIEs to represent all known formal parameters. */
10734 tree arg_decls = DECL_ARGUMENTS (decl);
10735 tree parm;
10737 /* When generating DIEs, generate the unspecified_parameters DIE
10738 instead if we come across the arg "__builtin_va_alist" */
10739 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10740 if (TREE_CODE (parm) == PARM_DECL)
10742 if (DECL_NAME (parm)
10743 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10744 "__builtin_va_alist"))
10745 gen_unspecified_parameters_die (parm, subr_die);
10746 else
10747 gen_decl_die (parm, subr_die);
10750 /* Decide whether we need an unspecified_parameters DIE at the end.
10751 There are 2 more cases to do this for: 1) the ansi ... declaration -
10752 this is detectable when the end of the arg list is not a
10753 void_type_node 2) an unprototyped function declaration (not a
10754 definition). This just means that we have no info about the
10755 parameters at all. */
10756 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10757 if (fn_arg_types != NULL)
10759 /* this is the prototyped case, check for ... */
10760 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10761 gen_unspecified_parameters_die (decl, subr_die);
10763 else if (DECL_INITIAL (decl) == NULL_TREE)
10764 gen_unspecified_parameters_die (decl, subr_die);
10767 /* Output Dwarf info for all of the stuff within the body of the function
10768 (if it has one - it may be just a declaration). */
10769 outer_scope = DECL_INITIAL (decl);
10771 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10772 a function. This BLOCK actually represents the outermost binding contour
10773 for the function, i.e. the contour in which the function's formal
10774 parameters and labels get declared. Curiously, it appears that the front
10775 end doesn't actually put the PARM_DECL nodes for the current function onto
10776 the BLOCK_VARS list for this outer scope, but are strung off of the
10777 DECL_ARGUMENTS list for the function instead.
10779 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10780 the LABEL_DECL nodes for the function however, and we output DWARF info
10781 for those in decls_for_scope. Just within the `outer_scope' there will be
10782 a BLOCK node representing the function's outermost pair of curly braces,
10783 and any blocks used for the base and member initializers of a C++
10784 constructor function. */
10785 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10787 current_function_has_inlines = 0;
10788 decls_for_scope (outer_scope, subr_die, 0);
10790 #if 0 && defined (MIPS_DEBUGGING_INFO)
10791 if (current_function_has_inlines)
10793 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10794 if (! comp_unit_has_inlines)
10796 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10797 comp_unit_has_inlines = 1;
10800 #endif
10804 /* Generate a DIE to represent a declared data object. */
10806 static void
10807 gen_variable_die (tree decl, dw_die_ref context_die)
10809 tree origin = decl_ultimate_origin (decl);
10810 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
10812 dw_die_ref old_die = lookup_decl_die (decl);
10813 int declaration = (DECL_EXTERNAL (decl)
10814 || class_scope_p (context_die));
10816 if (origin != NULL)
10817 add_abstract_origin_attribute (var_die, origin);
10819 /* Loop unrolling can create multiple blocks that refer to the same
10820 static variable, so we must test for the DW_AT_declaration flag.
10822 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10823 copy decls and set the DECL_ABSTRACT flag on them instead of
10824 sharing them.
10826 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10827 else if (old_die && TREE_STATIC (decl)
10828 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10830 /* This is a definition of a C++ class level static. */
10831 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10832 if (DECL_NAME (decl))
10834 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10836 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10837 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10839 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10840 != (unsigned) DECL_SOURCE_LINE (decl))
10842 add_AT_unsigned (var_die, DW_AT_decl_line,
10843 DECL_SOURCE_LINE (decl));
10846 else
10848 add_name_and_src_coords_attributes (var_die, decl);
10849 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
10850 TREE_THIS_VOLATILE (decl), context_die);
10852 if (TREE_PUBLIC (decl))
10853 add_AT_flag (var_die, DW_AT_external, 1);
10855 if (DECL_ARTIFICIAL (decl))
10856 add_AT_flag (var_die, DW_AT_artificial, 1);
10858 if (TREE_PROTECTED (decl))
10859 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10860 else if (TREE_PRIVATE (decl))
10861 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10864 if (declaration)
10865 add_AT_flag (var_die, DW_AT_declaration, 1);
10867 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10868 equate_decl_number_to_die (decl, var_die);
10870 if (! declaration && ! DECL_ABSTRACT (decl))
10872 add_location_or_const_value_attribute (var_die, decl);
10873 add_pubname (decl, var_die);
10875 else
10876 tree_add_const_value_attribute (var_die, decl);
10879 /* Generate a DIE to represent a label identifier. */
10881 static void
10882 gen_label_die (tree decl, dw_die_ref context_die)
10884 tree origin = decl_ultimate_origin (decl);
10885 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
10886 rtx insn;
10887 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10889 if (origin != NULL)
10890 add_abstract_origin_attribute (lbl_die, origin);
10891 else
10892 add_name_and_src_coords_attributes (lbl_die, decl);
10894 if (DECL_ABSTRACT (decl))
10895 equate_decl_number_to_die (decl, lbl_die);
10896 else
10898 insn = DECL_RTL (decl);
10900 /* Deleted labels are programmer specified labels which have been
10901 eliminated because of various optimizations. We still emit them
10902 here so that it is possible to put breakpoints on them. */
10903 if (GET_CODE (insn) == CODE_LABEL
10904 || ((GET_CODE (insn) == NOTE
10905 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10907 /* When optimization is enabled (via -O) some parts of the compiler
10908 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10909 represent source-level labels which were explicitly declared by
10910 the user. This really shouldn't be happening though, so catch
10911 it if it ever does happen. */
10912 if (INSN_DELETED_P (insn))
10913 abort ();
10915 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10916 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10921 /* Generate a DIE for a lexical block. */
10923 static void
10924 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
10926 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
10927 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10929 if (! BLOCK_ABSTRACT (stmt))
10931 if (BLOCK_FRAGMENT_CHAIN (stmt))
10933 tree chain;
10935 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
10937 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10940 add_ranges (chain);
10941 chain = BLOCK_FRAGMENT_CHAIN (chain);
10943 while (chain);
10944 add_ranges (NULL);
10946 else
10948 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10949 BLOCK_NUMBER (stmt));
10950 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10951 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10952 BLOCK_NUMBER (stmt));
10953 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10957 decls_for_scope (stmt, stmt_die, depth);
10960 /* Generate a DIE for an inlined subprogram. */
10962 static void
10963 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
10965 if (! BLOCK_ABSTRACT (stmt))
10967 dw_die_ref subr_die
10968 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
10969 tree decl = block_ultimate_origin (stmt);
10970 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10972 /* Emit info for the abstract instance first, if we haven't yet. */
10973 dwarf2out_abstract_function (decl);
10975 add_abstract_origin_attribute (subr_die, decl);
10976 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10977 BLOCK_NUMBER (stmt));
10978 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10979 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10980 BLOCK_NUMBER (stmt));
10981 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10982 decls_for_scope (stmt, subr_die, depth);
10983 current_function_has_inlines = 1;
10985 else
10986 /* We may get here if we're the outer block of function A that was
10987 inlined into function B that was inlined into function C. When
10988 generating debugging info for C, dwarf2out_abstract_function(B)
10989 would mark all inlined blocks as abstract, including this one.
10990 So, we wouldn't (and shouldn't) expect labels to be generated
10991 for this one. Instead, just emit debugging info for
10992 declarations within the block. This is particularly important
10993 in the case of initializers of arguments passed from B to us:
10994 if they're statement expressions containing declarations, we
10995 wouldn't generate dies for their abstract variables, and then,
10996 when generating dies for the real variables, we'd die (pun
10997 intended :-) */
10998 gen_lexical_block_die (stmt, context_die, depth);
11001 /* Generate a DIE for a field in a record, or structure. */
11003 static void
11004 gen_field_die (tree decl, dw_die_ref context_die)
11006 dw_die_ref decl_die;
11008 if (TREE_TYPE (decl) == error_mark_node)
11009 return;
11011 decl_die = new_die (DW_TAG_member, context_die, decl);
11012 add_name_and_src_coords_attributes (decl_die, decl);
11013 add_type_attribute (decl_die, member_declared_type (decl),
11014 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
11015 context_die);
11017 if (DECL_BIT_FIELD_TYPE (decl))
11019 add_byte_size_attribute (decl_die, decl);
11020 add_bit_size_attribute (decl_die, decl);
11021 add_bit_offset_attribute (decl_die, decl);
11024 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
11025 add_data_member_location_attribute (decl_die, decl);
11027 if (DECL_ARTIFICIAL (decl))
11028 add_AT_flag (decl_die, DW_AT_artificial, 1);
11030 if (TREE_PROTECTED (decl))
11031 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
11032 else if (TREE_PRIVATE (decl))
11033 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
11036 #if 0
11037 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11038 Use modified_type_die instead.
11039 We keep this code here just in case these types of DIEs may be needed to
11040 represent certain things in other languages (e.g. Pascal) someday. */
11042 static void
11043 gen_pointer_type_die (tree type, dw_die_ref context_die)
11045 dw_die_ref ptr_die
11046 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
11048 equate_type_number_to_die (type, ptr_die);
11049 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
11050 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
11053 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11054 Use modified_type_die instead.
11055 We keep this code here just in case these types of DIEs may be needed to
11056 represent certain things in other languages (e.g. Pascal) someday. */
11058 static void
11059 gen_reference_type_die (tree type, dw_die_ref context_die)
11061 dw_die_ref ref_die
11062 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
11064 equate_type_number_to_die (type, ref_die);
11065 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
11066 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
11068 #endif
11070 /* Generate a DIE for a pointer to a member type. */
11072 static void
11073 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
11075 dw_die_ref ptr_die
11076 = new_die (DW_TAG_ptr_to_member_type,
11077 scope_die_for (type, context_die), type);
11079 equate_type_number_to_die (type, ptr_die);
11080 add_AT_die_ref (ptr_die, DW_AT_containing_type,
11081 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
11082 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
11085 /* Generate the DIE for the compilation unit. */
11087 static dw_die_ref
11088 gen_compile_unit_die (const char *filename)
11090 dw_die_ref die;
11091 char producer[250];
11092 const char *language_string = lang_hooks.name;
11093 int language;
11095 die = new_die (DW_TAG_compile_unit, NULL, NULL);
11097 if (filename)
11099 add_name_attribute (die, filename);
11100 /* Don't add cwd for <built-in>. */
11101 if (filename[0] != DIR_SEPARATOR && filename[0] != '<')
11102 add_comp_dir_attribute (die);
11105 sprintf (producer, "%s %s", language_string, version_string);
11107 #ifdef MIPS_DEBUGGING_INFO
11108 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
11109 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
11110 not appear in the producer string, the debugger reaches the conclusion
11111 that the object file is stripped and has no debugging information.
11112 To get the MIPS/SGI debugger to believe that there is debugging
11113 information in the object file, we add a -g to the producer string. */
11114 if (debug_info_level > DINFO_LEVEL_TERSE)
11115 strcat (producer, " -g");
11116 #endif
11118 add_AT_string (die, DW_AT_producer, producer);
11120 if (strcmp (language_string, "GNU C++") == 0)
11121 language = DW_LANG_C_plus_plus;
11122 else if (strcmp (language_string, "GNU Ada") == 0)
11123 language = DW_LANG_Ada95;
11124 else if (strcmp (language_string, "GNU F77") == 0)
11125 language = DW_LANG_Fortran77;
11126 else if (strcmp (language_string, "GNU Pascal") == 0)
11127 language = DW_LANG_Pascal83;
11128 else if (strcmp (language_string, "GNU Java") == 0)
11129 language = DW_LANG_Java;
11130 else
11131 language = DW_LANG_C89;
11133 add_AT_unsigned (die, DW_AT_language, language);
11134 return die;
11137 /* Generate a DIE for a string type. */
11139 static void
11140 gen_string_type_die (tree type, dw_die_ref context_die)
11142 dw_die_ref type_die
11143 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
11145 equate_type_number_to_die (type, type_die);
11147 /* ??? Fudge the string length attribute for now.
11148 TODO: add string length info. */
11149 #if 0
11150 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
11151 bound_representation (upper_bound, 0, 'u');
11152 #endif
11155 /* Generate the DIE for a base class. */
11157 static void
11158 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
11160 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
11162 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
11163 add_data_member_location_attribute (die, binfo);
11165 if (TREE_VIA_VIRTUAL (binfo))
11166 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
11168 if (access == access_public_node)
11169 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
11170 else if (access == access_protected_node)
11171 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
11174 /* Generate a DIE for a class member. */
11176 static void
11177 gen_member_die (tree type, dw_die_ref context_die)
11179 tree member;
11180 tree binfo = TYPE_BINFO (type);
11181 dw_die_ref child;
11183 /* If this is not an incomplete type, output descriptions of each of its
11184 members. Note that as we output the DIEs necessary to represent the
11185 members of this record or union type, we will also be trying to output
11186 DIEs to represent the *types* of those members. However the `type'
11187 function (above) will specifically avoid generating type DIEs for member
11188 types *within* the list of member DIEs for this (containing) type except
11189 for those types (of members) which are explicitly marked as also being
11190 members of this (containing) type themselves. The g++ front- end can
11191 force any given type to be treated as a member of some other (containing)
11192 type by setting the TYPE_CONTEXT of the given (member) type to point to
11193 the TREE node representing the appropriate (containing) type. */
11195 /* First output info about the base classes. */
11196 if (binfo && BINFO_BASETYPES (binfo))
11198 tree bases = BINFO_BASETYPES (binfo);
11199 tree accesses = BINFO_BASEACCESSES (binfo);
11200 int n_bases = TREE_VEC_LENGTH (bases);
11201 int i;
11203 for (i = 0; i < n_bases; i++)
11204 gen_inheritance_die (TREE_VEC_ELT (bases, i),
11205 (accesses ? TREE_VEC_ELT (accesses, i)
11206 : access_public_node), context_die);
11209 /* Now output info about the data members and type members. */
11210 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
11212 /* If we thought we were generating minimal debug info for TYPE
11213 and then changed our minds, some of the member declarations
11214 may have already been defined. Don't define them again, but
11215 do put them in the right order. */
11217 child = lookup_decl_die (member);
11218 if (child)
11219 splice_child_die (context_die, child);
11220 else
11221 gen_decl_die (member, context_die);
11224 /* Now output info about the function members (if any). */
11225 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
11227 /* Don't include clones in the member list. */
11228 if (DECL_ABSTRACT_ORIGIN (member))
11229 continue;
11231 child = lookup_decl_die (member);
11232 if (child)
11233 splice_child_die (context_die, child);
11234 else
11235 gen_decl_die (member, context_die);
11239 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
11240 is set, we pretend that the type was never defined, so we only get the
11241 member DIEs needed by later specification DIEs. */
11243 static void
11244 gen_struct_or_union_type_die (tree type, dw_die_ref context_die)
11246 dw_die_ref type_die = lookup_type_die (type);
11247 dw_die_ref scope_die = 0;
11248 int nested = 0;
11249 int complete = (TYPE_SIZE (type)
11250 && (! TYPE_STUB_DECL (type)
11251 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
11253 if (type_die && ! complete)
11254 return;
11256 if (TYPE_CONTEXT (type) != NULL_TREE
11257 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
11258 nested = 1;
11260 scope_die = scope_die_for (type, context_die);
11262 if (! type_die || (nested && scope_die == comp_unit_die))
11263 /* First occurrence of type or toplevel definition of nested class. */
11265 dw_die_ref old_die = type_die;
11267 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
11268 ? DW_TAG_structure_type : DW_TAG_union_type,
11269 scope_die, type);
11270 equate_type_number_to_die (type, type_die);
11271 if (old_die)
11272 add_AT_die_ref (type_die, DW_AT_specification, old_die);
11273 else
11274 add_name_attribute (type_die, type_tag (type));
11276 else
11277 remove_AT (type_die, DW_AT_declaration);
11279 /* If this type has been completed, then give it a byte_size attribute and
11280 then give a list of members. */
11281 if (complete)
11283 /* Prevent infinite recursion in cases where the type of some member of
11284 this type is expressed in terms of this type itself. */
11285 TREE_ASM_WRITTEN (type) = 1;
11286 add_byte_size_attribute (type_die, type);
11287 if (TYPE_STUB_DECL (type) != NULL_TREE)
11288 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
11290 /* If the first reference to this type was as the return type of an
11291 inline function, then it may not have a parent. Fix this now. */
11292 if (type_die->die_parent == NULL)
11293 add_child_die (scope_die, type_die);
11295 push_decl_scope (type);
11296 gen_member_die (type, type_die);
11297 pop_decl_scope ();
11299 /* GNU extension: Record what type our vtable lives in. */
11300 if (TYPE_VFIELD (type))
11302 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
11304 gen_type_die (vtype, context_die);
11305 add_AT_die_ref (type_die, DW_AT_containing_type,
11306 lookup_type_die (vtype));
11309 else
11311 add_AT_flag (type_die, DW_AT_declaration, 1);
11313 /* We don't need to do this for function-local types. */
11314 if (TYPE_STUB_DECL (type)
11315 && ! decl_function_context (TYPE_STUB_DECL (type)))
11316 VARRAY_PUSH_TREE (incomplete_types, type);
11320 /* Generate a DIE for a subroutine _type_. */
11322 static void
11323 gen_subroutine_type_die (tree type, dw_die_ref context_die)
11325 tree return_type = TREE_TYPE (type);
11326 dw_die_ref subr_die
11327 = new_die (DW_TAG_subroutine_type,
11328 scope_die_for (type, context_die), type);
11330 equate_type_number_to_die (type, subr_die);
11331 add_prototyped_attribute (subr_die, type);
11332 add_type_attribute (subr_die, return_type, 0, 0, context_die);
11333 gen_formal_types_die (type, subr_die);
11336 /* Generate a DIE for a type definition. */
11338 static void
11339 gen_typedef_die (tree decl, dw_die_ref context_die)
11341 dw_die_ref type_die;
11342 tree origin;
11344 if (TREE_ASM_WRITTEN (decl))
11345 return;
11347 TREE_ASM_WRITTEN (decl) = 1;
11348 type_die = new_die (DW_TAG_typedef, context_die, decl);
11349 origin = decl_ultimate_origin (decl);
11350 if (origin != NULL)
11351 add_abstract_origin_attribute (type_die, origin);
11352 else
11354 tree type;
11356 add_name_and_src_coords_attributes (type_die, decl);
11357 if (DECL_ORIGINAL_TYPE (decl))
11359 type = DECL_ORIGINAL_TYPE (decl);
11361 if (type == TREE_TYPE (decl))
11362 abort ();
11363 else
11364 equate_type_number_to_die (TREE_TYPE (decl), type_die);
11366 else
11367 type = TREE_TYPE (decl);
11369 add_type_attribute (type_die, type, TREE_READONLY (decl),
11370 TREE_THIS_VOLATILE (decl), context_die);
11373 if (DECL_ABSTRACT (decl))
11374 equate_decl_number_to_die (decl, type_die);
11377 /* Generate a type description DIE. */
11379 static void
11380 gen_type_die (tree type, dw_die_ref context_die)
11382 int need_pop;
11384 if (type == NULL_TREE || type == error_mark_node)
11385 return;
11387 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11388 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
11390 if (TREE_ASM_WRITTEN (type))
11391 return;
11393 /* Prevent broken recursion; we can't hand off to the same type. */
11394 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type)
11395 abort ();
11397 TREE_ASM_WRITTEN (type) = 1;
11398 gen_decl_die (TYPE_NAME (type), context_die);
11399 return;
11402 /* We are going to output a DIE to represent the unqualified version
11403 of this type (i.e. without any const or volatile qualifiers) so
11404 get the main variant (i.e. the unqualified version) of this type
11405 now. (Vectors are special because the debugging info is in the
11406 cloned type itself). */
11407 if (TREE_CODE (type) != VECTOR_TYPE)
11408 type = type_main_variant (type);
11410 if (TREE_ASM_WRITTEN (type))
11411 return;
11413 switch (TREE_CODE (type))
11415 case ERROR_MARK:
11416 break;
11418 case POINTER_TYPE:
11419 case REFERENCE_TYPE:
11420 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11421 ensures that the gen_type_die recursion will terminate even if the
11422 type is recursive. Recursive types are possible in Ada. */
11423 /* ??? We could perhaps do this for all types before the switch
11424 statement. */
11425 TREE_ASM_WRITTEN (type) = 1;
11427 /* For these types, all that is required is that we output a DIE (or a
11428 set of DIEs) to represent the "basis" type. */
11429 gen_type_die (TREE_TYPE (type), context_die);
11430 break;
11432 case OFFSET_TYPE:
11433 /* This code is used for C++ pointer-to-data-member types.
11434 Output a description of the relevant class type. */
11435 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
11437 /* Output a description of the type of the object pointed to. */
11438 gen_type_die (TREE_TYPE (type), context_die);
11440 /* Now output a DIE to represent this pointer-to-data-member type
11441 itself. */
11442 gen_ptr_to_mbr_type_die (type, context_die);
11443 break;
11445 case SET_TYPE:
11446 gen_type_die (TYPE_DOMAIN (type), context_die);
11447 gen_set_type_die (type, context_die);
11448 break;
11450 case FILE_TYPE:
11451 gen_type_die (TREE_TYPE (type), context_die);
11452 abort (); /* No way to represent these in Dwarf yet! */
11453 break;
11455 case FUNCTION_TYPE:
11456 /* Force out return type (in case it wasn't forced out already). */
11457 gen_type_die (TREE_TYPE (type), context_die);
11458 gen_subroutine_type_die (type, context_die);
11459 break;
11461 case METHOD_TYPE:
11462 /* Force out return type (in case it wasn't forced out already). */
11463 gen_type_die (TREE_TYPE (type), context_die);
11464 gen_subroutine_type_die (type, context_die);
11465 break;
11467 case ARRAY_TYPE:
11468 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
11470 gen_type_die (TREE_TYPE (type), context_die);
11471 gen_string_type_die (type, context_die);
11473 else
11474 gen_array_type_die (type, context_die);
11475 break;
11477 case VECTOR_TYPE:
11478 gen_array_type_die (type, context_die);
11479 break;
11481 case ENUMERAL_TYPE:
11482 case RECORD_TYPE:
11483 case UNION_TYPE:
11484 case QUAL_UNION_TYPE:
11485 /* If this is a nested type whose containing class hasn't been written
11486 out yet, writing it out will cover this one, too. This does not apply
11487 to instantiations of member class templates; they need to be added to
11488 the containing class as they are generated. FIXME: This hurts the
11489 idea of combining type decls from multiple TUs, since we can't predict
11490 what set of template instantiations we'll get. */
11491 if (TYPE_CONTEXT (type)
11492 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
11493 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
11495 gen_type_die (TYPE_CONTEXT (type), context_die);
11497 if (TREE_ASM_WRITTEN (type))
11498 return;
11500 /* If that failed, attach ourselves to the stub. */
11501 push_decl_scope (TYPE_CONTEXT (type));
11502 context_die = lookup_type_die (TYPE_CONTEXT (type));
11503 need_pop = 1;
11505 else
11506 need_pop = 0;
11508 if (TREE_CODE (type) == ENUMERAL_TYPE)
11509 gen_enumeration_type_die (type, context_die);
11510 else
11511 gen_struct_or_union_type_die (type, context_die);
11513 if (need_pop)
11514 pop_decl_scope ();
11516 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11517 it up if it is ever completed. gen_*_type_die will set it for us
11518 when appropriate. */
11519 return;
11521 case VOID_TYPE:
11522 case INTEGER_TYPE:
11523 case REAL_TYPE:
11524 case COMPLEX_TYPE:
11525 case BOOLEAN_TYPE:
11526 case CHAR_TYPE:
11527 /* No DIEs needed for fundamental types. */
11528 break;
11530 case LANG_TYPE:
11531 /* No Dwarf representation currently defined. */
11532 break;
11534 default:
11535 abort ();
11538 TREE_ASM_WRITTEN (type) = 1;
11541 /* Generate a DIE for a tagged type instantiation. */
11543 static void
11544 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
11546 if (type == NULL_TREE || type == error_mark_node)
11547 return;
11549 /* We are going to output a DIE to represent the unqualified version of
11550 this type (i.e. without any const or volatile qualifiers) so make sure
11551 that we have the main variant (i.e. the unqualified version) of this
11552 type now. */
11553 if (type != type_main_variant (type))
11554 abort ();
11556 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11557 an instance of an unresolved type. */
11559 switch (TREE_CODE (type))
11561 case ERROR_MARK:
11562 break;
11564 case ENUMERAL_TYPE:
11565 gen_inlined_enumeration_type_die (type, context_die);
11566 break;
11568 case RECORD_TYPE:
11569 gen_inlined_structure_type_die (type, context_die);
11570 break;
11572 case UNION_TYPE:
11573 case QUAL_UNION_TYPE:
11574 gen_inlined_union_type_die (type, context_die);
11575 break;
11577 default:
11578 abort ();
11582 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11583 things which are local to the given block. */
11585 static void
11586 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
11588 int must_output_die = 0;
11589 tree origin;
11590 tree decl;
11591 enum tree_code origin_code;
11593 /* Ignore blocks never really used to make RTL. */
11594 if (stmt == NULL_TREE || !TREE_USED (stmt)
11595 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11596 return;
11598 /* If the block is one fragment of a non-contiguous block, do not
11599 process the variables, since they will have been done by the
11600 origin block. Do process subblocks. */
11601 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11603 tree sub;
11605 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
11606 gen_block_die (sub, context_die, depth + 1);
11608 return;
11611 /* Determine the "ultimate origin" of this block. This block may be an
11612 inlined instance of an inlined instance of inline function, so we have
11613 to trace all of the way back through the origin chain to find out what
11614 sort of node actually served as the original seed for the creation of
11615 the current block. */
11616 origin = block_ultimate_origin (stmt);
11617 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11619 /* Determine if we need to output any Dwarf DIEs at all to represent this
11620 block. */
11621 if (origin_code == FUNCTION_DECL)
11622 /* The outer scopes for inlinings *must* always be represented. We
11623 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11624 must_output_die = 1;
11625 else
11627 /* In the case where the current block represents an inlining of the
11628 "body block" of an inline function, we must *NOT* output any DIE for
11629 this block because we have already output a DIE to represent the whole
11630 inlined function scope and the "body block" of any function doesn't
11631 really represent a different scope according to ANSI C rules. So we
11632 check here to make sure that this block does not represent a "body
11633 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11634 if (! is_body_block (origin ? origin : stmt))
11636 /* Determine if this block directly contains any "significant"
11637 local declarations which we will need to output DIEs for. */
11638 if (debug_info_level > DINFO_LEVEL_TERSE)
11639 /* We are not in terse mode so *any* local declaration counts
11640 as being a "significant" one. */
11641 must_output_die = (BLOCK_VARS (stmt) != NULL);
11642 else
11643 /* We are in terse mode, so only local (nested) function
11644 definitions count as "significant" local declarations. */
11645 for (decl = BLOCK_VARS (stmt);
11646 decl != NULL; decl = TREE_CHAIN (decl))
11647 if (TREE_CODE (decl) == FUNCTION_DECL
11648 && DECL_INITIAL (decl))
11650 must_output_die = 1;
11651 break;
11656 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11657 DIE for any block which contains no significant local declarations at
11658 all. Rather, in such cases we just call `decls_for_scope' so that any
11659 needed Dwarf info for any sub-blocks will get properly generated. Note
11660 that in terse mode, our definition of what constitutes a "significant"
11661 local declaration gets restricted to include only inlined function
11662 instances and local (nested) function definitions. */
11663 if (must_output_die)
11665 if (origin_code == FUNCTION_DECL)
11666 gen_inlined_subroutine_die (stmt, context_die, depth);
11667 else
11668 gen_lexical_block_die (stmt, context_die, depth);
11670 else
11671 decls_for_scope (stmt, context_die, depth);
11674 /* Generate all of the decls declared within a given scope and (recursively)
11675 all of its sub-blocks. */
11677 static void
11678 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
11680 tree decl;
11681 tree subblocks;
11683 /* Ignore blocks never really used to make RTL. */
11684 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11685 return;
11687 /* Output the DIEs to represent all of the data objects and typedefs
11688 declared directly within this block but not within any nested
11689 sub-blocks. Also, nested function and tag DIEs have been
11690 generated with a parent of NULL; fix that up now. */
11691 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
11693 dw_die_ref die;
11695 if (TREE_CODE (decl) == FUNCTION_DECL)
11696 die = lookup_decl_die (decl);
11697 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11698 die = lookup_type_die (TREE_TYPE (decl));
11699 else
11700 die = NULL;
11702 if (die != NULL && die->die_parent == NULL)
11703 add_child_die (context_die, die);
11704 else
11705 gen_decl_die (decl, context_die);
11708 /* If we're at -g1, we're not interested in subblocks. */
11709 if (debug_info_level <= DINFO_LEVEL_TERSE)
11710 return;
11712 /* Output the DIEs to represent all sub-blocks (and the items declared
11713 therein) of this block. */
11714 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11715 subblocks != NULL;
11716 subblocks = BLOCK_CHAIN (subblocks))
11717 gen_block_die (subblocks, context_die, depth + 1);
11720 /* Is this a typedef we can avoid emitting? */
11722 static inline int
11723 is_redundant_typedef (tree decl)
11725 if (TYPE_DECL_IS_STUB (decl))
11726 return 1;
11728 if (DECL_ARTIFICIAL (decl)
11729 && DECL_CONTEXT (decl)
11730 && is_tagged_type (DECL_CONTEXT (decl))
11731 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11732 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11733 /* Also ignore the artificial member typedef for the class name. */
11734 return 1;
11736 return 0;
11739 /* Generate Dwarf debug information for a decl described by DECL. */
11741 static void
11742 gen_decl_die (tree decl, dw_die_ref context_die)
11744 tree origin;
11746 if (DECL_P (decl) && DECL_IGNORED_P (decl))
11747 return;
11749 switch (TREE_CODE (decl))
11751 case ERROR_MARK:
11752 break;
11754 case CONST_DECL:
11755 /* The individual enumerators of an enum type get output when we output
11756 the Dwarf representation of the relevant enum type itself. */
11757 break;
11759 case FUNCTION_DECL:
11760 /* Don't output any DIEs to represent mere function declarations,
11761 unless they are class members or explicit block externs. */
11762 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11763 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11764 break;
11766 /* If we're emitting a clone, emit info for the abstract instance. */
11767 if (DECL_ORIGIN (decl) != decl)
11768 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11770 /* If we're emitting an out-of-line copy of an inline function,
11771 emit info for the abstract instance and set up to refer to it. */
11772 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11773 && ! class_scope_p (context_die)
11774 /* dwarf2out_abstract_function won't emit a die if this is just
11775 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11776 that case, because that works only if we have a die. */
11777 && DECL_INITIAL (decl) != NULL_TREE)
11779 dwarf2out_abstract_function (decl);
11780 set_decl_origin_self (decl);
11783 /* Otherwise we're emitting the primary DIE for this decl. */
11784 else if (debug_info_level > DINFO_LEVEL_TERSE)
11786 /* Before we describe the FUNCTION_DECL itself, make sure that we
11787 have described its return type. */
11788 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11790 /* And its virtual context. */
11791 if (DECL_VINDEX (decl) != NULL_TREE)
11792 gen_type_die (DECL_CONTEXT (decl), context_die);
11794 /* And its containing type. */
11795 origin = decl_class_context (decl);
11796 if (origin != NULL_TREE)
11797 gen_type_die_for_member (origin, decl, context_die);
11800 /* Now output a DIE to represent the function itself. */
11801 gen_subprogram_die (decl, context_die);
11802 break;
11804 case TYPE_DECL:
11805 /* If we are in terse mode, don't generate any DIEs to represent any
11806 actual typedefs. */
11807 if (debug_info_level <= DINFO_LEVEL_TERSE)
11808 break;
11810 /* In the special case of a TYPE_DECL node representing the declaration
11811 of some type tag, if the given TYPE_DECL is marked as having been
11812 instantiated from some other (original) TYPE_DECL node (e.g. one which
11813 was generated within the original definition of an inline function) we
11814 have to generate a special (abbreviated) DW_TAG_structure_type,
11815 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11816 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11818 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11819 break;
11822 if (is_redundant_typedef (decl))
11823 gen_type_die (TREE_TYPE (decl), context_die);
11824 else
11825 /* Output a DIE to represent the typedef itself. */
11826 gen_typedef_die (decl, context_die);
11827 break;
11829 case LABEL_DECL:
11830 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11831 gen_label_die (decl, context_die);
11832 break;
11834 case VAR_DECL:
11835 /* If we are in terse mode, don't generate any DIEs to represent any
11836 variable declarations or definitions. */
11837 if (debug_info_level <= DINFO_LEVEL_TERSE)
11838 break;
11840 /* Output any DIEs that are needed to specify the type of this data
11841 object. */
11842 gen_type_die (TREE_TYPE (decl), context_die);
11844 /* And its containing type. */
11845 origin = decl_class_context (decl);
11846 if (origin != NULL_TREE)
11847 gen_type_die_for_member (origin, decl, context_die);
11849 /* Now output the DIE to represent the data object itself. This gets
11850 complicated because of the possibility that the VAR_DECL really
11851 represents an inlined instance of a formal parameter for an inline
11852 function. */
11853 origin = decl_ultimate_origin (decl);
11854 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11855 gen_formal_parameter_die (decl, context_die);
11856 else
11857 gen_variable_die (decl, context_die);
11858 break;
11860 case FIELD_DECL:
11861 /* Ignore the nameless fields that are used to skip bits but handle C++
11862 anonymous unions. */
11863 if (DECL_NAME (decl) != NULL_TREE
11864 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11866 gen_type_die (member_declared_type (decl), context_die);
11867 gen_field_die (decl, context_die);
11869 break;
11871 case PARM_DECL:
11872 gen_type_die (TREE_TYPE (decl), context_die);
11873 gen_formal_parameter_die (decl, context_die);
11874 break;
11876 case NAMESPACE_DECL:
11877 /* Ignore for now. */
11878 break;
11880 default:
11881 if ((int)TREE_CODE (decl) > NUM_TREE_CODES)
11882 /* Probably some frontend-internal decl. Assume we don't care. */
11883 break;
11884 abort ();
11888 /* Add Ada "use" clause information for SGI Workshop debugger. */
11890 void
11891 dwarf2out_add_library_unit_info (const char *filename, const char *context_list)
11893 unsigned int file_index;
11895 if (filename != NULL)
11897 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
11898 tree context_list_decl
11899 = build_decl (LABEL_DECL, get_identifier (context_list),
11900 void_type_node);
11902 TREE_PUBLIC (context_list_decl) = TRUE;
11903 add_name_attribute (unit_die, context_list);
11904 file_index = lookup_filename (filename);
11905 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11906 add_pubname (context_list_decl, unit_die);
11910 /* Output debug information for global decl DECL. Called from toplev.c after
11911 compilation proper has finished. */
11913 static void
11914 dwarf2out_global_decl (tree decl)
11916 /* Output DWARF2 information for file-scope tentative data object
11917 declarations, file-scope (extern) function declarations (which had no
11918 corresponding body) and file-scope tagged type declarations and
11919 definitions which have not yet been forced out. */
11920 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11921 dwarf2out_decl (decl);
11924 /* Write the debugging output for DECL. */
11926 void
11927 dwarf2out_decl (tree decl)
11929 dw_die_ref context_die = comp_unit_die;
11931 switch (TREE_CODE (decl))
11933 case ERROR_MARK:
11934 return;
11936 case FUNCTION_DECL:
11937 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11938 builtin function. Explicit programmer-supplied declarations of
11939 these same functions should NOT be ignored however. */
11940 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11941 return;
11943 /* What we would really like to do here is to filter out all mere
11944 file-scope declarations of file-scope functions which are never
11945 referenced later within this translation unit (and keep all of ones
11946 that *are* referenced later on) but we aren't clairvoyant, so we have
11947 no idea which functions will be referenced in the future (i.e. later
11948 on within the current translation unit). So here we just ignore all
11949 file-scope function declarations which are not also definitions. If
11950 and when the debugger needs to know something about these functions,
11951 it will have to hunt around and find the DWARF information associated
11952 with the definition of the function.
11954 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11955 nodes represent definitions and which ones represent mere
11956 declarations. We have to check DECL_INITIAL instead. That's because
11957 the C front-end supports some weird semantics for "extern inline"
11958 function definitions. These can get inlined within the current
11959 translation unit (an thus, we need to generate Dwarf info for their
11960 abstract instances so that the Dwarf info for the concrete inlined
11961 instances can have something to refer to) but the compiler never
11962 generates any out-of-lines instances of such things (despite the fact
11963 that they *are* definitions).
11965 The important point is that the C front-end marks these "extern
11966 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11967 them anyway. Note that the C++ front-end also plays some similar games
11968 for inline function definitions appearing within include files which
11969 also contain `#pragma interface' pragmas. */
11970 if (DECL_INITIAL (decl) == NULL_TREE)
11971 return;
11973 /* If we're a nested function, initially use a parent of NULL; if we're
11974 a plain function, this will be fixed up in decls_for_scope. If
11975 we're a method, it will be ignored, since we already have a DIE. */
11976 if (decl_function_context (decl)
11977 /* But if we're in terse mode, we don't care about scope. */
11978 && debug_info_level > DINFO_LEVEL_TERSE)
11979 context_die = NULL;
11980 break;
11982 case VAR_DECL:
11983 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11984 declaration and if the declaration was never even referenced from
11985 within this entire compilation unit. We suppress these DIEs in
11986 order to save space in the .debug section (by eliminating entries
11987 which are probably useless). Note that we must not suppress
11988 block-local extern declarations (whether used or not) because that
11989 would screw-up the debugger's name lookup mechanism and cause it to
11990 miss things which really ought to be in scope at a given point. */
11991 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11992 return;
11994 /* If we are in terse mode, don't generate any DIEs to represent any
11995 variable declarations or definitions. */
11996 if (debug_info_level <= DINFO_LEVEL_TERSE)
11997 return;
11998 break;
12000 case TYPE_DECL:
12001 /* Don't emit stubs for types unless they are needed by other DIEs. */
12002 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
12003 return;
12005 /* Don't bother trying to generate any DIEs to represent any of the
12006 normal built-in types for the language we are compiling. */
12007 if (DECL_SOURCE_LINE (decl) == 0)
12009 /* OK, we need to generate one for `bool' so GDB knows what type
12010 comparisons have. */
12011 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
12012 == DW_LANG_C_plus_plus)
12013 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
12014 && ! DECL_IGNORED_P (decl))
12015 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
12017 return;
12020 /* If we are in terse mode, don't generate any DIEs for types. */
12021 if (debug_info_level <= DINFO_LEVEL_TERSE)
12022 return;
12024 /* If we're a function-scope tag, initially use a parent of NULL;
12025 this will be fixed up in decls_for_scope. */
12026 if (decl_function_context (decl))
12027 context_die = NULL;
12029 break;
12031 default:
12032 return;
12035 gen_decl_die (decl, context_die);
12038 /* Output a marker (i.e. a label) for the beginning of the generated code for
12039 a lexical block. */
12041 static void
12042 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
12043 unsigned int blocknum)
12045 function_section (current_function_decl);
12046 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
12049 /* Output a marker (i.e. a label) for the end of the generated code for a
12050 lexical block. */
12052 static void
12053 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
12055 function_section (current_function_decl);
12056 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
12059 /* Returns nonzero if it is appropriate not to emit any debugging
12060 information for BLOCK, because it doesn't contain any instructions.
12062 Don't allow this for blocks with nested functions or local classes
12063 as we would end up with orphans, and in the presence of scheduling
12064 we may end up calling them anyway. */
12066 static bool
12067 dwarf2out_ignore_block (tree block)
12069 tree decl;
12071 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
12072 if (TREE_CODE (decl) == FUNCTION_DECL
12073 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
12074 return 0;
12076 return 1;
12079 /* Lookup FILE_NAME (in the list of filenames that we know about here in
12080 dwarf2out.c) and return its "index". The index of each (known) filename is
12081 just a unique number which is associated with only that one filename. We
12082 need such numbers for the sake of generating labels (in the .debug_sfnames
12083 section) and references to those files numbers (in the .debug_srcinfo
12084 and.debug_macinfo sections). If the filename given as an argument is not
12085 found in our current list, add it to the list and assign it the next
12086 available unique index number. In order to speed up searches, we remember
12087 the index of the filename was looked up last. This handles the majority of
12088 all searches. */
12090 static unsigned
12091 lookup_filename (const char *file_name)
12093 size_t i, n;
12094 char *save_file_name;
12096 /* Check to see if the file name that was searched on the previous
12097 call matches this file name. If so, return the index. */
12098 if (file_table_last_lookup_index != 0)
12100 const char *last
12101 = VARRAY_CHAR_PTR (file_table, file_table_last_lookup_index);
12102 if (strcmp (file_name, last) == 0)
12103 return file_table_last_lookup_index;
12106 /* Didn't match the previous lookup, search the table */
12107 n = VARRAY_ACTIVE_SIZE (file_table);
12108 for (i = 1; i < n; i++)
12109 if (strcmp (file_name, VARRAY_CHAR_PTR (file_table, i)) == 0)
12111 file_table_last_lookup_index = i;
12112 return i;
12115 /* Add the new entry to the end of the filename table. */
12116 file_table_last_lookup_index = n;
12117 save_file_name = (char *) ggc_strdup (file_name);
12118 VARRAY_PUSH_CHAR_PTR (file_table, save_file_name);
12119 VARRAY_PUSH_UINT (file_table_emitted, 0);
12121 return i;
12124 static int
12125 maybe_emit_file (int fileno)
12127 if (DWARF2_ASM_LINE_DEBUG_INFO && fileno > 0)
12129 if (!VARRAY_UINT (file_table_emitted, fileno))
12131 VARRAY_UINT (file_table_emitted, fileno) = ++emitcount;
12132 fprintf (asm_out_file, "\t.file %u ",
12133 VARRAY_UINT (file_table_emitted, fileno));
12134 output_quoted_string (asm_out_file,
12135 VARRAY_CHAR_PTR (file_table, fileno));
12136 fputc ('\n', asm_out_file);
12138 return VARRAY_UINT (file_table_emitted, fileno);
12140 else
12141 return fileno;
12144 static void
12145 init_file_table (void)
12147 /* Allocate the initial hunk of the file_table. */
12148 VARRAY_CHAR_PTR_INIT (file_table, 64, "file_table");
12149 VARRAY_UINT_INIT (file_table_emitted, 64, "file_table_emitted");
12151 /* Skip the first entry - file numbers begin at 1. */
12152 VARRAY_PUSH_CHAR_PTR (file_table, NULL);
12153 VARRAY_PUSH_UINT (file_table_emitted, 0);
12154 file_table_last_lookup_index = 0;
12157 /* Output a label to mark the beginning of a source code line entry
12158 and record information relating to this source line, in
12159 'line_info_table' for later output of the .debug_line section. */
12161 static void
12162 dwarf2out_source_line (unsigned int line, const char *filename)
12164 if (debug_info_level >= DINFO_LEVEL_NORMAL
12165 && line != 0)
12167 function_section (current_function_decl);
12169 /* If requested, emit something human-readable. */
12170 if (flag_debug_asm)
12171 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
12172 filename, line);
12174 if (DWARF2_ASM_LINE_DEBUG_INFO)
12176 unsigned file_num = lookup_filename (filename);
12178 file_num = maybe_emit_file (file_num);
12180 /* Emit the .loc directive understood by GNU as. */
12181 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
12183 /* Indicate that line number info exists. */
12184 line_info_table_in_use++;
12186 /* Indicate that multiple line number tables exist. */
12187 if (DECL_SECTION_NAME (current_function_decl))
12188 separate_line_info_table_in_use++;
12190 else if (DECL_SECTION_NAME (current_function_decl))
12192 dw_separate_line_info_ref line_info;
12193 (*targetm.asm_out.internal_label) (asm_out_file, SEPARATE_LINE_CODE_LABEL,
12194 separate_line_info_table_in_use);
12196 /* expand the line info table if necessary */
12197 if (separate_line_info_table_in_use
12198 == separate_line_info_table_allocated)
12200 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
12201 separate_line_info_table
12202 = (dw_separate_line_info_ref)
12203 ggc_realloc (separate_line_info_table,
12204 separate_line_info_table_allocated
12205 * sizeof (dw_separate_line_info_entry));
12206 memset ((separate_line_info_table
12207 + separate_line_info_table_in_use),
12209 (LINE_INFO_TABLE_INCREMENT
12210 * sizeof (dw_separate_line_info_entry)));
12213 /* Add the new entry at the end of the line_info_table. */
12214 line_info
12215 = &separate_line_info_table[separate_line_info_table_in_use++];
12216 line_info->dw_file_num = lookup_filename (filename);
12217 line_info->dw_line_num = line;
12218 line_info->function = current_function_funcdef_no;
12220 else
12222 dw_line_info_ref line_info;
12224 (*targetm.asm_out.internal_label) (asm_out_file, LINE_CODE_LABEL,
12225 line_info_table_in_use);
12227 /* Expand the line info table if necessary. */
12228 if (line_info_table_in_use == line_info_table_allocated)
12230 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
12231 line_info_table
12232 = ggc_realloc (line_info_table,
12233 (line_info_table_allocated
12234 * sizeof (dw_line_info_entry)));
12235 memset (line_info_table + line_info_table_in_use, 0,
12236 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
12239 /* Add the new entry at the end of the line_info_table. */
12240 line_info = &line_info_table[line_info_table_in_use++];
12241 line_info->dw_file_num = lookup_filename (filename);
12242 line_info->dw_line_num = line;
12247 /* Record the beginning of a new source file. */
12249 static void
12250 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
12252 if (flag_eliminate_dwarf2_dups && !is_main_source)
12254 /* Record the beginning of the file for break_out_includes. */
12255 dw_die_ref bincl_die;
12257 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
12258 add_AT_string (bincl_die, DW_AT_name, filename);
12261 is_main_source = 0;
12263 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12265 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12266 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
12267 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
12268 lineno);
12269 maybe_emit_file (lookup_filename (filename));
12270 dw2_asm_output_data_uleb128 (lookup_filename (filename),
12271 "Filename we just started");
12275 /* Record the end of a source file. */
12277 static void
12278 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
12280 if (flag_eliminate_dwarf2_dups)
12281 /* Record the end of the file for break_out_includes. */
12282 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
12284 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12286 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12287 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12291 /* Called from debug_define in toplev.c. The `buffer' parameter contains
12292 the tail part of the directive line, i.e. the part which is past the
12293 initial whitespace, #, whitespace, directive-name, whitespace part. */
12295 static void
12296 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
12297 const char *buffer ATTRIBUTE_UNUSED)
12299 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12301 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12302 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
12303 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12304 dw2_asm_output_nstring (buffer, -1, "The macro");
12308 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
12309 the tail part of the directive line, i.e. the part which is past the
12310 initial whitespace, #, whitespace, directive-name, whitespace part. */
12312 static void
12313 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
12314 const char *buffer ATTRIBUTE_UNUSED)
12316 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12318 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12319 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
12320 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12321 dw2_asm_output_nstring (buffer, -1, "The macro");
12325 /* Set up for Dwarf output at the start of compilation. */
12327 static void
12328 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
12330 init_file_table ();
12332 /* Allocate the initial hunk of the decl_die_table. */
12333 decl_die_table = ggc_alloc_cleared (DECL_DIE_TABLE_INCREMENT
12334 * sizeof (dw_die_ref));
12335 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
12336 decl_die_table_in_use = 0;
12338 /* Allocate the initial hunk of the decl_scope_table. */
12339 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
12341 /* Allocate the initial hunk of the abbrev_die_table. */
12342 abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
12343 * sizeof (dw_die_ref));
12344 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
12345 /* Zero-th entry is allocated, but unused */
12346 abbrev_die_table_in_use = 1;
12348 /* Allocate the initial hunk of the line_info_table. */
12349 line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
12350 * sizeof (dw_line_info_entry));
12351 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
12353 /* Zero-th entry is allocated, but unused */
12354 line_info_table_in_use = 1;
12356 /* Generate the initial DIE for the .debug section. Note that the (string)
12357 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12358 will (typically) be a relative pathname and that this pathname should be
12359 taken as being relative to the directory from which the compiler was
12360 invoked when the given (base) source file was compiled. We will fill
12361 in this value in dwarf2out_finish. */
12362 comp_unit_die = gen_compile_unit_die (NULL);
12363 is_main_source = 1;
12365 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
12367 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
12369 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
12370 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
12371 DEBUG_ABBREV_SECTION_LABEL, 0);
12372 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12373 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
12374 else
12375 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
12377 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
12378 DEBUG_INFO_SECTION_LABEL, 0);
12379 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
12380 DEBUG_LINE_SECTION_LABEL, 0);
12381 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
12382 DEBUG_RANGES_SECTION_LABEL, 0);
12383 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12384 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
12385 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
12386 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
12387 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12388 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
12390 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12392 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12393 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
12394 DEBUG_MACINFO_SECTION_LABEL, 0);
12395 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
12398 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12400 text_section ();
12401 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
12405 /* A helper function for dwarf2out_finish called through
12406 ht_forall. Emit one queued .debug_str string. */
12408 static int
12409 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
12411 struct indirect_string_node *node = (struct indirect_string_node *) *h;
12413 if (node->form == DW_FORM_strp)
12415 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
12416 ASM_OUTPUT_LABEL (asm_out_file, node->label);
12417 assemble_string (node->str, strlen (node->str) + 1);
12420 return 1;
12425 /* Clear the marks for a die and its children.
12426 Be cool if the mark isn't set. */
12428 static void
12429 prune_unmark_dies (dw_die_ref die)
12431 dw_die_ref c;
12432 die->die_mark = 0;
12433 for (c = die->die_child; c; c = c->die_sib)
12434 prune_unmark_dies (c);
12438 /* Given DIE that we're marking as used, find any other dies
12439 it references as attributes and mark them as used. */
12441 static void
12442 prune_unused_types_walk_attribs (dw_die_ref die)
12444 dw_attr_ref a;
12446 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
12448 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
12450 /* A reference to another DIE.
12451 Make sure that it will get emitted. */
12452 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
12454 else if (a->dw_attr == DW_AT_decl_file)
12456 /* A reference to a file. Make sure the file name is emitted. */
12457 a->dw_attr_val.v.val_unsigned =
12458 maybe_emit_file (a->dw_attr_val.v.val_unsigned);
12464 /* Mark DIE as being used. If DOKIDS is true, then walk down
12465 to DIE's children. */
12467 static void
12468 prune_unused_types_mark (dw_die_ref die, int dokids)
12470 dw_die_ref c;
12472 if (die->die_mark == 0)
12474 /* We haven't done this node yet. Mark it as used. */
12475 die->die_mark = 1;
12477 /* We also have to mark its parents as used.
12478 (But we don't want to mark our parents' kids due to this.) */
12479 if (die->die_parent)
12480 prune_unused_types_mark (die->die_parent, 0);
12482 /* Mark any referenced nodes. */
12483 prune_unused_types_walk_attribs (die);
12486 if (dokids && die->die_mark != 2)
12488 /* We need to walk the children, but haven't done so yet.
12489 Remember that we've walked the kids. */
12490 die->die_mark = 2;
12492 /* Walk them. */
12493 for (c = die->die_child; c; c = c->die_sib)
12495 /* If this is an array type, we need to make sure our
12496 kids get marked, even if they're types. */
12497 if (die->die_tag == DW_TAG_array_type)
12498 prune_unused_types_mark (c, 1);
12499 else
12500 prune_unused_types_walk (c);
12506 /* Walk the tree DIE and mark types that we actually use. */
12508 static void
12509 prune_unused_types_walk (dw_die_ref die)
12511 dw_die_ref c;
12513 /* Don't do anything if this node is already marked. */
12514 if (die->die_mark)
12515 return;
12517 switch (die->die_tag) {
12518 case DW_TAG_const_type:
12519 case DW_TAG_packed_type:
12520 case DW_TAG_pointer_type:
12521 case DW_TAG_reference_type:
12522 case DW_TAG_volatile_type:
12523 case DW_TAG_typedef:
12524 case DW_TAG_array_type:
12525 case DW_TAG_structure_type:
12526 case DW_TAG_union_type:
12527 case DW_TAG_class_type:
12528 case DW_TAG_friend:
12529 case DW_TAG_variant_part:
12530 case DW_TAG_enumeration_type:
12531 case DW_TAG_subroutine_type:
12532 case DW_TAG_string_type:
12533 case DW_TAG_set_type:
12534 case DW_TAG_subrange_type:
12535 case DW_TAG_ptr_to_member_type:
12536 case DW_TAG_file_type:
12537 /* It's a type node --- don't mark it. */
12538 return;
12540 default:
12541 /* Mark everything else. */
12542 break;
12545 die->die_mark = 1;
12547 /* Now, mark any dies referenced from here. */
12548 prune_unused_types_walk_attribs (die);
12550 /* Mark children. */
12551 for (c = die->die_child; c; c = c->die_sib)
12552 prune_unused_types_walk (c);
12556 /* Remove from the tree DIE any dies that aren't marked. */
12558 static void
12559 prune_unused_types_prune (dw_die_ref die)
12561 dw_die_ref c, p, n;
12562 if (!die->die_mark)
12563 abort();
12565 p = NULL;
12566 for (c = die->die_child; c; c = n)
12568 n = c->die_sib;
12569 if (c->die_mark)
12571 prune_unused_types_prune (c);
12572 p = c;
12574 else
12576 if (p)
12577 p->die_sib = n;
12578 else
12579 die->die_child = n;
12580 free_die (c);
12586 /* Remove dies representing declarations that we never use. */
12588 static void
12589 prune_unused_types (void)
12591 unsigned int i;
12592 limbo_die_node *node;
12594 /* Clear all the marks. */
12595 prune_unmark_dies (comp_unit_die);
12596 for (node = limbo_die_list; node; node = node->next)
12597 prune_unmark_dies (node->die);
12599 /* Set the mark on nodes that are actually used. */
12600 prune_unused_types_walk (comp_unit_die);
12601 for (node = limbo_die_list; node; node = node->next)
12602 prune_unused_types_walk (node->die);
12604 /* Also set the mark on nodes referenced from the
12605 pubname_table or arange_table. */
12606 for (i = 0; i < pubname_table_in_use; i++)
12607 prune_unused_types_mark (pubname_table[i].die, 1);
12608 for (i = 0; i < arange_table_in_use; i++)
12609 prune_unused_types_mark (arange_table[i], 1);
12611 /* Get rid of nodes that aren't marked. */
12612 prune_unused_types_prune (comp_unit_die);
12613 for (node = limbo_die_list; node; node = node->next)
12614 prune_unused_types_prune (node->die);
12616 /* Leave the marks clear. */
12617 prune_unmark_dies (comp_unit_die);
12618 for (node = limbo_die_list; node; node = node->next)
12619 prune_unmark_dies (node->die);
12622 /* Output stuff that dwarf requires at the end of every file,
12623 and generate the DWARF-2 debugging info. */
12625 static void
12626 dwarf2out_finish (const char *filename)
12628 limbo_die_node *node, *next_node;
12629 dw_die_ref die = 0;
12631 /* Add the name for the main input file now. We delayed this from
12632 dwarf2out_init to avoid complications with PCH. */
12633 add_name_attribute (comp_unit_die, filename);
12634 if (filename[0] != DIR_SEPARATOR)
12635 add_comp_dir_attribute (comp_unit_die);
12636 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
12638 size_t i;
12639 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
12640 if (VARRAY_CHAR_PTR (file_table, i)[0] != DIR_SEPARATOR
12641 /* Don't add cwd for <built-in>. */
12642 && VARRAY_CHAR_PTR (file_table, i)[0] != '<')
12644 add_comp_dir_attribute (comp_unit_die);
12645 break;
12649 /* Traverse the limbo die list, and add parent/child links. The only
12650 dies without parents that should be here are concrete instances of
12651 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12652 For concrete instances, we can get the parent die from the abstract
12653 instance. */
12654 for (node = limbo_die_list; node; node = next_node)
12656 next_node = node->next;
12657 die = node->die;
12659 if (die->die_parent == NULL)
12661 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
12662 tree context;
12664 if (origin)
12665 add_child_die (origin->die_parent, die);
12666 else if (die == comp_unit_die)
12668 /* If this was an expression for a bound involved in a function
12669 return type, it may be a SAVE_EXPR for which we weren't able
12670 to find a DIE previously. So try now. */
12671 else if (node->created_for
12672 && TREE_CODE (node->created_for) == SAVE_EXPR
12673 && 0 != (origin = (lookup_decl_die
12674 (SAVE_EXPR_CONTEXT
12675 (node->created_for)))))
12676 add_child_die (origin, die);
12677 else if (errorcount > 0 || sorrycount > 0)
12678 /* It's OK to be confused by errors in the input. */
12679 add_child_die (comp_unit_die, die);
12680 else if (node->created_for
12681 && ((DECL_P (node->created_for)
12682 && (context = DECL_CONTEXT (node->created_for)))
12683 || (TYPE_P (node->created_for)
12684 && (context = TYPE_CONTEXT (node->created_for))))
12685 && TREE_CODE (context) == FUNCTION_DECL)
12687 /* In certain situations, the lexical block containing a
12688 nested function can be optimized away, which results
12689 in the nested function die being orphaned. Likewise
12690 with the return type of that nested function. Force
12691 this to be a child of the containing function. */
12692 origin = lookup_decl_die (context);
12693 if (! origin)
12694 abort ();
12695 add_child_die (origin, die);
12697 else
12698 abort ();
12702 limbo_die_list = NULL;
12704 /* Walk through the list of incomplete types again, trying once more to
12705 emit full debugging info for them. */
12706 retry_incomplete_types ();
12708 /* We need to reverse all the dies before break_out_includes, or
12709 we'll see the end of an include file before the beginning. */
12710 reverse_all_dies (comp_unit_die);
12712 if (flag_eliminate_unused_debug_types)
12713 prune_unused_types ();
12715 /* Generate separate CUs for each of the include files we've seen.
12716 They will go into limbo_die_list. */
12717 if (flag_eliminate_dwarf2_dups)
12718 break_out_includes (comp_unit_die);
12720 /* Traverse the DIE's and add add sibling attributes to those DIE's
12721 that have children. */
12722 add_sibling_attributes (comp_unit_die);
12723 for (node = limbo_die_list; node; node = node->next)
12724 add_sibling_attributes (node->die);
12726 /* Output a terminator label for the .text section. */
12727 text_section ();
12728 (*targetm.asm_out.internal_label) (asm_out_file, TEXT_END_LABEL, 0);
12730 /* Output the source line correspondence table. We must do this
12731 even if there is no line information. Otherwise, on an empty
12732 translation unit, we will generate a present, but empty,
12733 .debug_info section. IRIX 6.5 `nm' will then complain when
12734 examining the file. */
12735 if (! DWARF2_ASM_LINE_DEBUG_INFO)
12737 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12738 output_line_info ();
12741 /* Output location list section if necessary. */
12742 if (have_location_lists)
12744 /* Output the location lists info. */
12745 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
12746 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
12747 DEBUG_LOC_SECTION_LABEL, 0);
12748 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
12749 output_location_lists (die);
12750 have_location_lists = 0;
12753 /* We can only use the low/high_pc attributes if all of the code was
12754 in .text. */
12755 if (separate_line_info_table_in_use == 0)
12757 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
12758 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
12761 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12762 "base address". Use zero so that these addresses become absolute. */
12763 else if (have_location_lists || ranges_table_in_use)
12764 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
12766 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12767 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
12768 debug_line_section_label);
12770 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12771 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
12773 /* Output all of the compilation units. We put the main one last so that
12774 the offsets are available to output_pubnames. */
12775 for (node = limbo_die_list; node; node = node->next)
12776 output_comp_unit (node->die, 0);
12778 output_comp_unit (comp_unit_die, 0);
12780 /* Output the abbreviation table. */
12781 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12782 output_abbrev_section ();
12784 /* Output public names table if necessary. */
12785 if (pubname_table_in_use)
12787 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
12788 output_pubnames ();
12791 /* Output the address range information. We only put functions in the arange
12792 table, so don't write it out if we don't have any. */
12793 if (fde_table_in_use)
12795 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
12796 output_aranges ();
12799 /* Output ranges section if necessary. */
12800 if (ranges_table_in_use)
12802 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
12803 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12804 output_ranges ();
12807 /* Have to end the primary source file. */
12808 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12810 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12811 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12812 dw2_asm_output_data (1, 0, "End compilation unit");
12815 /* If we emitted any DW_FORM_strp form attribute, output the string
12816 table too. */
12817 if (debug_str_hash)
12818 htab_traverse (debug_str_hash, output_indirect_string, NULL);
12820 #else
12822 /* This should never be used, but its address is needed for comparisons. */
12823 const struct gcc_debug_hooks dwarf2_debug_hooks;
12825 #endif /* DWARF2_DEBUGGING_INFO */
12827 #include "gt-dwarf2out.h"