include/ChangeLog:
[official-gcc.git] / gcc / dwarf2out.c
blob5c104987ef96f8f161126a50746b29f929f0a9c6
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 HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]);
453 if (offset < 0)
454 continue;
456 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
460 /* Convert a DWARF call frame info. operation to its string name */
462 static const char *
463 dwarf_cfi_name (unsigned int cfi_opc)
465 switch (cfi_opc)
467 case DW_CFA_advance_loc:
468 return "DW_CFA_advance_loc";
469 case DW_CFA_offset:
470 return "DW_CFA_offset";
471 case DW_CFA_restore:
472 return "DW_CFA_restore";
473 case DW_CFA_nop:
474 return "DW_CFA_nop";
475 case DW_CFA_set_loc:
476 return "DW_CFA_set_loc";
477 case DW_CFA_advance_loc1:
478 return "DW_CFA_advance_loc1";
479 case DW_CFA_advance_loc2:
480 return "DW_CFA_advance_loc2";
481 case DW_CFA_advance_loc4:
482 return "DW_CFA_advance_loc4";
483 case DW_CFA_offset_extended:
484 return "DW_CFA_offset_extended";
485 case DW_CFA_restore_extended:
486 return "DW_CFA_restore_extended";
487 case DW_CFA_undefined:
488 return "DW_CFA_undefined";
489 case DW_CFA_same_value:
490 return "DW_CFA_same_value";
491 case DW_CFA_register:
492 return "DW_CFA_register";
493 case DW_CFA_remember_state:
494 return "DW_CFA_remember_state";
495 case DW_CFA_restore_state:
496 return "DW_CFA_restore_state";
497 case DW_CFA_def_cfa:
498 return "DW_CFA_def_cfa";
499 case DW_CFA_def_cfa_register:
500 return "DW_CFA_def_cfa_register";
501 case DW_CFA_def_cfa_offset:
502 return "DW_CFA_def_cfa_offset";
504 /* DWARF 3 */
505 case DW_CFA_def_cfa_expression:
506 return "DW_CFA_def_cfa_expression";
507 case DW_CFA_expression:
508 return "DW_CFA_expression";
509 case DW_CFA_offset_extended_sf:
510 return "DW_CFA_offset_extended_sf";
511 case DW_CFA_def_cfa_sf:
512 return "DW_CFA_def_cfa_sf";
513 case DW_CFA_def_cfa_offset_sf:
514 return "DW_CFA_def_cfa_offset_sf";
516 /* SGI/MIPS specific */
517 case DW_CFA_MIPS_advance_loc8:
518 return "DW_CFA_MIPS_advance_loc8";
520 /* GNU extensions */
521 case DW_CFA_GNU_window_save:
522 return "DW_CFA_GNU_window_save";
523 case DW_CFA_GNU_args_size:
524 return "DW_CFA_GNU_args_size";
525 case DW_CFA_GNU_negative_offset_extended:
526 return "DW_CFA_GNU_negative_offset_extended";
528 default:
529 return "DW_CFA_<unknown>";
533 /* Return a pointer to a newly allocated Call Frame Instruction. */
535 static inline dw_cfi_ref
536 new_cfi (void)
538 dw_cfi_ref cfi = (dw_cfi_ref) ggc_alloc (sizeof (dw_cfi_node));
540 cfi->dw_cfi_next = NULL;
541 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
542 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
544 return cfi;
547 /* Add a Call Frame Instruction to list of instructions. */
549 static inline void
550 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
552 dw_cfi_ref *p;
554 /* Find the end of the chain. */
555 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
558 *p = cfi;
561 /* Generate a new label for the CFI info to refer to. */
563 char *
564 dwarf2out_cfi_label (void)
566 static char label[20];
568 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
569 ASM_OUTPUT_LABEL (asm_out_file, label);
570 return label;
573 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
574 or to the CIE if LABEL is NULL. */
576 static void
577 add_fde_cfi (const char *label, dw_cfi_ref cfi)
579 if (label)
581 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
583 if (*label == 0)
584 label = dwarf2out_cfi_label ();
586 if (fde->dw_fde_current_label == NULL
587 || strcmp (label, fde->dw_fde_current_label) != 0)
589 dw_cfi_ref xcfi;
591 fde->dw_fde_current_label = label = xstrdup (label);
593 /* Set the location counter to the new label. */
594 xcfi = new_cfi ();
595 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
596 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
597 add_cfi (&fde->dw_fde_cfi, xcfi);
600 add_cfi (&fde->dw_fde_cfi, cfi);
603 else
604 add_cfi (&cie_cfi_head, cfi);
607 /* Subroutine of lookup_cfa. */
609 static inline void
610 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
612 switch (cfi->dw_cfi_opc)
614 case DW_CFA_def_cfa_offset:
615 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
616 break;
617 case DW_CFA_def_cfa_register:
618 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
619 break;
620 case DW_CFA_def_cfa:
621 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
622 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
623 break;
624 case DW_CFA_def_cfa_expression:
625 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
626 break;
627 default:
628 break;
632 /* Find the previous value for the CFA. */
634 static void
635 lookup_cfa (dw_cfa_location *loc)
637 dw_cfi_ref cfi;
639 loc->reg = (unsigned long) -1;
640 loc->offset = 0;
641 loc->indirect = 0;
642 loc->base_offset = 0;
644 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
645 lookup_cfa_1 (cfi, loc);
647 if (fde_table_in_use)
649 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
650 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
651 lookup_cfa_1 (cfi, loc);
655 /* The current rule for calculating the DWARF2 canonical frame address. */
656 static dw_cfa_location cfa;
658 /* The register used for saving registers to the stack, and its offset
659 from the CFA. */
660 static dw_cfa_location cfa_store;
662 /* The running total of the size of arguments pushed onto the stack. */
663 static long args_size;
665 /* The last args_size we actually output. */
666 static long old_args_size;
668 /* Entry point to update the canonical frame address (CFA).
669 LABEL is passed to add_fde_cfi. The value of CFA is now to be
670 calculated from REG+OFFSET. */
672 void
673 dwarf2out_def_cfa (const char *label, unsigned int reg, long int offset)
675 dw_cfa_location loc;
676 loc.indirect = 0;
677 loc.base_offset = 0;
678 loc.reg = reg;
679 loc.offset = offset;
680 def_cfa_1 (label, &loc);
683 /* This routine does the actual work. The CFA is now calculated from
684 the dw_cfa_location structure. */
686 static void
687 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
689 dw_cfi_ref cfi;
690 dw_cfa_location old_cfa, loc;
692 cfa = *loc_p;
693 loc = *loc_p;
695 if (cfa_store.reg == loc.reg && loc.indirect == 0)
696 cfa_store.offset = loc.offset;
698 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
699 lookup_cfa (&old_cfa);
701 /* If nothing changed, no need to issue any call frame instructions. */
702 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
703 && loc.indirect == old_cfa.indirect
704 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
705 return;
707 cfi = new_cfi ();
709 if (loc.reg == old_cfa.reg && !loc.indirect)
711 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
712 indicating the CFA register did not change but the offset
713 did. */
714 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
715 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
718 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
719 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
720 && !loc.indirect)
722 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
723 indicating the CFA register has changed to <register> but the
724 offset has not changed. */
725 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
726 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
728 #endif
730 else if (loc.indirect == 0)
732 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
733 indicating the CFA register has changed to <register> with
734 the specified offset. */
735 cfi->dw_cfi_opc = DW_CFA_def_cfa;
736 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
737 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
739 else
741 /* Construct a DW_CFA_def_cfa_expression instruction to
742 calculate the CFA using a full location expression since no
743 register-offset pair is available. */
744 struct dw_loc_descr_struct *loc_list;
746 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
747 loc_list = build_cfa_loc (&loc);
748 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
751 add_fde_cfi (label, cfi);
754 /* Add the CFI for saving a register. REG is the CFA column number.
755 LABEL is passed to add_fde_cfi.
756 If SREG is -1, the register is saved at OFFSET from the CFA;
757 otherwise it is saved in SREG. */
759 static void
760 reg_save (const char *label, unsigned int reg, unsigned int sreg, long int offset)
762 dw_cfi_ref cfi = new_cfi ();
764 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
766 /* The following comparison is correct. -1 is used to indicate that
767 the value isn't a register number. */
768 if (sreg == (unsigned int) -1)
770 if (reg & ~0x3f)
771 /* The register number won't fit in 6 bits, so we have to use
772 the long form. */
773 cfi->dw_cfi_opc = DW_CFA_offset_extended;
774 else
775 cfi->dw_cfi_opc = DW_CFA_offset;
777 #ifdef ENABLE_CHECKING
779 /* If we get an offset that is not a multiple of
780 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
781 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
782 description. */
783 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
785 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
786 abort ();
788 #endif
789 offset /= DWARF_CIE_DATA_ALIGNMENT;
790 if (offset < 0)
791 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
793 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
795 else if (sreg == reg)
796 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
797 return;
798 else
800 cfi->dw_cfi_opc = DW_CFA_register;
801 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
804 add_fde_cfi (label, cfi);
807 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
808 This CFI tells the unwinder that it needs to restore the window registers
809 from the previous frame's window save area.
811 ??? Perhaps we should note in the CIE where windows are saved (instead of
812 assuming 0(cfa)) and what registers are in the window. */
814 void
815 dwarf2out_window_save (const char *label)
817 dw_cfi_ref cfi = new_cfi ();
819 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
820 add_fde_cfi (label, cfi);
823 /* Add a CFI to update the running total of the size of arguments
824 pushed onto the stack. */
826 void
827 dwarf2out_args_size (const char *label, long int size)
829 dw_cfi_ref cfi;
831 if (size == old_args_size)
832 return;
834 old_args_size = size;
836 cfi = new_cfi ();
837 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
838 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
839 add_fde_cfi (label, cfi);
842 /* Entry point for saving a register to the stack. REG is the GCC register
843 number. LABEL and OFFSET are passed to reg_save. */
845 void
846 dwarf2out_reg_save (const char *label, unsigned int reg, long int offset)
848 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
851 /* Entry point for saving the return address in the stack.
852 LABEL and OFFSET are passed to reg_save. */
854 void
855 dwarf2out_return_save (const char *label, long int offset)
857 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
860 /* Entry point for saving the return address in a register.
861 LABEL and SREG are passed to reg_save. */
863 void
864 dwarf2out_return_reg (const char *label, unsigned int sreg)
866 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
869 /* Record the initial position of the return address. RTL is
870 INCOMING_RETURN_ADDR_RTX. */
872 static void
873 initial_return_save (rtx rtl)
875 unsigned int reg = (unsigned int) -1;
876 HOST_WIDE_INT offset = 0;
878 switch (GET_CODE (rtl))
880 case REG:
881 /* RA is in a register. */
882 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
883 break;
885 case MEM:
886 /* RA is on the stack. */
887 rtl = XEXP (rtl, 0);
888 switch (GET_CODE (rtl))
890 case REG:
891 if (REGNO (rtl) != STACK_POINTER_REGNUM)
892 abort ();
893 offset = 0;
894 break;
896 case PLUS:
897 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
898 abort ();
899 offset = INTVAL (XEXP (rtl, 1));
900 break;
902 case MINUS:
903 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
904 abort ();
905 offset = -INTVAL (XEXP (rtl, 1));
906 break;
908 default:
909 abort ();
912 break;
914 case PLUS:
915 /* The return address is at some offset from any value we can
916 actually load. For instance, on the SPARC it is in %i7+8. Just
917 ignore the offset for now; it doesn't matter for unwinding frames. */
918 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
919 abort ();
920 initial_return_save (XEXP (rtl, 0));
921 return;
923 default:
924 abort ();
927 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
930 /* Given a SET, calculate the amount of stack adjustment it
931 contains. */
933 static long
934 stack_adjust_offset (rtx pattern)
936 rtx src = SET_SRC (pattern);
937 rtx dest = SET_DEST (pattern);
938 HOST_WIDE_INT offset = 0;
939 enum rtx_code code;
941 if (dest == stack_pointer_rtx)
943 /* (set (reg sp) (plus (reg sp) (const_int))) */
944 code = GET_CODE (src);
945 if (! (code == PLUS || code == MINUS)
946 || XEXP (src, 0) != stack_pointer_rtx
947 || GET_CODE (XEXP (src, 1)) != CONST_INT)
948 return 0;
950 offset = INTVAL (XEXP (src, 1));
951 if (code == PLUS)
952 offset = -offset;
954 else if (GET_CODE (dest) == MEM)
956 /* (set (mem (pre_dec (reg sp))) (foo)) */
957 src = XEXP (dest, 0);
958 code = GET_CODE (src);
960 switch (code)
962 case PRE_MODIFY:
963 case POST_MODIFY:
964 if (XEXP (src, 0) == stack_pointer_rtx)
966 rtx val = XEXP (XEXP (src, 1), 1);
967 /* We handle only adjustments by constant amount. */
968 if (GET_CODE (XEXP (src, 1)) != PLUS ||
969 GET_CODE (val) != CONST_INT)
970 abort ();
971 offset = -INTVAL (val);
972 break;
974 return 0;
976 case PRE_DEC:
977 case POST_DEC:
978 if (XEXP (src, 0) == stack_pointer_rtx)
980 offset = GET_MODE_SIZE (GET_MODE (dest));
981 break;
983 return 0;
985 case PRE_INC:
986 case POST_INC:
987 if (XEXP (src, 0) == stack_pointer_rtx)
989 offset = -GET_MODE_SIZE (GET_MODE (dest));
990 break;
992 return 0;
994 default:
995 return 0;
998 else
999 return 0;
1001 return offset;
1004 /* Check INSN to see if it looks like a push or a stack adjustment, and
1005 make a note of it if it does. EH uses this information to find out how
1006 much extra space it needs to pop off the stack. */
1008 static void
1009 dwarf2out_stack_adjust (rtx insn)
1011 HOST_WIDE_INT offset;
1012 const char *label;
1013 int i;
1015 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1017 /* Extract the size of the args from the CALL rtx itself. */
1018 insn = PATTERN (insn);
1019 if (GET_CODE (insn) == PARALLEL)
1020 insn = XVECEXP (insn, 0, 0);
1021 if (GET_CODE (insn) == SET)
1022 insn = SET_SRC (insn);
1023 if (GET_CODE (insn) != CALL)
1024 abort ();
1026 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1027 return;
1030 /* If only calls can throw, and we have a frame pointer,
1031 save up adjustments until we see the CALL_INSN. */
1032 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1033 return;
1035 if (GET_CODE (insn) == BARRIER)
1037 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1038 the compiler will have already emitted a stack adjustment, but
1039 doesn't bother for calls to noreturn functions. */
1040 #ifdef STACK_GROWS_DOWNWARD
1041 offset = -args_size;
1042 #else
1043 offset = args_size;
1044 #endif
1046 else if (GET_CODE (PATTERN (insn)) == SET)
1047 offset = stack_adjust_offset (PATTERN (insn));
1048 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1049 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1051 /* There may be stack adjustments inside compound insns. Search
1052 for them. */
1053 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1054 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1055 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1057 else
1058 return;
1060 if (offset == 0)
1061 return;
1063 if (cfa.reg == STACK_POINTER_REGNUM)
1064 cfa.offset += offset;
1066 #ifndef STACK_GROWS_DOWNWARD
1067 offset = -offset;
1068 #endif
1070 args_size += offset;
1071 if (args_size < 0)
1072 args_size = 0;
1074 label = dwarf2out_cfi_label ();
1075 def_cfa_1 (label, &cfa);
1076 dwarf2out_args_size (label, args_size);
1079 #endif
1081 /* We delay emitting a register save until either (a) we reach the end
1082 of the prologue or (b) the register is clobbered. This clusters
1083 register saves so that there are fewer pc advances. */
1085 struct queued_reg_save GTY(())
1087 struct queued_reg_save *next;
1088 rtx reg;
1089 long cfa_offset;
1092 static GTY(()) struct queued_reg_save *queued_reg_saves;
1094 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1095 static const char *last_reg_save_label;
1097 static void
1098 queue_reg_save (const char *label, rtx reg, long int offset)
1100 struct queued_reg_save *q = ggc_alloc (sizeof (*q));
1102 q->next = queued_reg_saves;
1103 q->reg = reg;
1104 q->cfa_offset = offset;
1105 queued_reg_saves = q;
1107 last_reg_save_label = label;
1110 static void
1111 flush_queued_reg_saves (void)
1113 struct queued_reg_save *q, *next;
1115 for (q = queued_reg_saves; q; q = next)
1117 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1118 next = q->next;
1121 queued_reg_saves = NULL;
1122 last_reg_save_label = NULL;
1125 static bool
1126 clobbers_queued_reg_save (rtx insn)
1128 struct queued_reg_save *q;
1130 for (q = queued_reg_saves; q; q = q->next)
1131 if (modified_in_p (q->reg, insn))
1132 return true;
1134 return false;
1138 /* A temporary register holding an integral value used in adjusting SP
1139 or setting up the store_reg. The "offset" field holds the integer
1140 value, not an offset. */
1141 static dw_cfa_location cfa_temp;
1143 /* Record call frame debugging information for an expression EXPR,
1144 which either sets SP or FP (adjusting how we calculate the frame
1145 address) or saves a register to the stack. LABEL indicates the
1146 address of EXPR.
1148 This function encodes a state machine mapping rtxes to actions on
1149 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1150 users need not read the source code.
1152 The High-Level Picture
1154 Changes in the register we use to calculate the CFA: Currently we
1155 assume that if you copy the CFA register into another register, we
1156 should take the other one as the new CFA register; this seems to
1157 work pretty well. If it's wrong for some target, it's simple
1158 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1160 Changes in the register we use for saving registers to the stack:
1161 This is usually SP, but not always. Again, we deduce that if you
1162 copy SP into another register (and SP is not the CFA register),
1163 then the new register is the one we will be using for register
1164 saves. This also seems to work.
1166 Register saves: There's not much guesswork about this one; if
1167 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1168 register save, and the register used to calculate the destination
1169 had better be the one we think we're using for this purpose.
1171 Except: If the register being saved is the CFA register, and the
1172 offset is nonzero, we are saving the CFA, so we assume we have to
1173 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1174 the intent is to save the value of SP from the previous frame.
1176 Invariants / Summaries of Rules
1178 cfa current rule for calculating the CFA. It usually
1179 consists of a register and an offset.
1180 cfa_store register used by prologue code to save things to the stack
1181 cfa_store.offset is the offset from the value of
1182 cfa_store.reg to the actual CFA
1183 cfa_temp register holding an integral value. cfa_temp.offset
1184 stores the value, which will be used to adjust the
1185 stack pointer. cfa_temp is also used like cfa_store,
1186 to track stores to the stack via fp or a temp reg.
1188 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1189 with cfa.reg as the first operand changes the cfa.reg and its
1190 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1191 cfa_temp.offset.
1193 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1194 expression yielding a constant. This sets cfa_temp.reg
1195 and cfa_temp.offset.
1197 Rule 5: Create a new register cfa_store used to save items to the
1198 stack.
1200 Rules 10-14: Save a register to the stack. Define offset as the
1201 difference of the original location and cfa_store's
1202 location (or cfa_temp's location if cfa_temp is used).
1204 The Rules
1206 "{a,b}" indicates a choice of a xor b.
1207 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1209 Rule 1:
1210 (set <reg1> <reg2>:cfa.reg)
1211 effects: cfa.reg = <reg1>
1212 cfa.offset unchanged
1213 cfa_temp.reg = <reg1>
1214 cfa_temp.offset = cfa.offset
1216 Rule 2:
1217 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1218 {<const_int>,<reg>:cfa_temp.reg}))
1219 effects: cfa.reg = sp if fp used
1220 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1221 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1222 if cfa_store.reg==sp
1224 Rule 3:
1225 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1226 effects: cfa.reg = fp
1227 cfa_offset += +/- <const_int>
1229 Rule 4:
1230 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1231 constraints: <reg1> != fp
1232 <reg1> != sp
1233 effects: cfa.reg = <reg1>
1234 cfa_temp.reg = <reg1>
1235 cfa_temp.offset = cfa.offset
1237 Rule 5:
1238 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1239 constraints: <reg1> != fp
1240 <reg1> != sp
1241 effects: cfa_store.reg = <reg1>
1242 cfa_store.offset = cfa.offset - cfa_temp.offset
1244 Rule 6:
1245 (set <reg> <const_int>)
1246 effects: cfa_temp.reg = <reg>
1247 cfa_temp.offset = <const_int>
1249 Rule 7:
1250 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1251 effects: cfa_temp.reg = <reg1>
1252 cfa_temp.offset |= <const_int>
1254 Rule 8:
1255 (set <reg> (high <exp>))
1256 effects: none
1258 Rule 9:
1259 (set <reg> (lo_sum <exp> <const_int>))
1260 effects: cfa_temp.reg = <reg>
1261 cfa_temp.offset = <const_int>
1263 Rule 10:
1264 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1265 effects: cfa_store.offset -= <const_int>
1266 cfa.offset = cfa_store.offset if cfa.reg == sp
1267 cfa.reg = sp
1268 cfa.base_offset = -cfa_store.offset
1270 Rule 11:
1271 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1272 effects: cfa_store.offset += -/+ mode_size(mem)
1273 cfa.offset = cfa_store.offset if cfa.reg == sp
1274 cfa.reg = sp
1275 cfa.base_offset = -cfa_store.offset
1277 Rule 12:
1278 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1280 <reg2>)
1281 effects: cfa.reg = <reg1>
1282 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1284 Rule 13:
1285 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1286 effects: cfa.reg = <reg1>
1287 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1289 Rule 14:
1290 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1291 effects: cfa.reg = <reg1>
1292 cfa.base_offset = -cfa_temp.offset
1293 cfa_temp.offset -= mode_size(mem) */
1295 static void
1296 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1298 rtx src, dest;
1299 HOST_WIDE_INT offset;
1301 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1302 the PARALLEL independently. The first element is always processed if
1303 it is a SET. This is for backward compatibility. Other elements
1304 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1305 flag is set in them. */
1306 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1308 int par_index;
1309 int limit = XVECLEN (expr, 0);
1311 for (par_index = 0; par_index < limit; par_index++)
1312 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1313 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1314 || par_index == 0))
1315 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1317 return;
1320 if (GET_CODE (expr) != SET)
1321 abort ();
1323 src = SET_SRC (expr);
1324 dest = SET_DEST (expr);
1326 switch (GET_CODE (dest))
1328 case REG:
1329 /* Rule 1 */
1330 /* Update the CFA rule wrt SP or FP. Make sure src is
1331 relative to the current CFA register. */
1332 switch (GET_CODE (src))
1334 /* Setting FP from SP. */
1335 case REG:
1336 if (cfa.reg == (unsigned) REGNO (src))
1337 /* OK. */
1339 else
1340 abort ();
1342 /* We used to require that dest be either SP or FP, but the
1343 ARM copies SP to a temporary register, and from there to
1344 FP. So we just rely on the backends to only set
1345 RTX_FRAME_RELATED_P on appropriate insns. */
1346 cfa.reg = REGNO (dest);
1347 cfa_temp.reg = cfa.reg;
1348 cfa_temp.offset = cfa.offset;
1349 break;
1351 case PLUS:
1352 case MINUS:
1353 case LO_SUM:
1354 if (dest == stack_pointer_rtx)
1356 /* Rule 2 */
1357 /* Adjusting SP. */
1358 switch (GET_CODE (XEXP (src, 1)))
1360 case CONST_INT:
1361 offset = INTVAL (XEXP (src, 1));
1362 break;
1363 case REG:
1364 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1365 abort ();
1366 offset = cfa_temp.offset;
1367 break;
1368 default:
1369 abort ();
1372 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1374 /* Restoring SP from FP in the epilogue. */
1375 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1376 abort ();
1377 cfa.reg = STACK_POINTER_REGNUM;
1379 else if (GET_CODE (src) == LO_SUM)
1380 /* Assume we've set the source reg of the LO_SUM from sp. */
1382 else if (XEXP (src, 0) != stack_pointer_rtx)
1383 abort ();
1385 if (GET_CODE (src) != MINUS)
1386 offset = -offset;
1387 if (cfa.reg == STACK_POINTER_REGNUM)
1388 cfa.offset += offset;
1389 if (cfa_store.reg == STACK_POINTER_REGNUM)
1390 cfa_store.offset += offset;
1392 else if (dest == hard_frame_pointer_rtx)
1394 /* Rule 3 */
1395 /* Either setting the FP from an offset of the SP,
1396 or adjusting the FP */
1397 if (! frame_pointer_needed)
1398 abort ();
1400 if (GET_CODE (XEXP (src, 0)) == REG
1401 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1402 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1404 offset = INTVAL (XEXP (src, 1));
1405 if (GET_CODE (src) != MINUS)
1406 offset = -offset;
1407 cfa.offset += offset;
1408 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1410 else
1411 abort ();
1413 else
1415 if (GET_CODE (src) == MINUS)
1416 abort ();
1418 /* Rule 4 */
1419 if (GET_CODE (XEXP (src, 0)) == REG
1420 && REGNO (XEXP (src, 0)) == cfa.reg
1421 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1423 /* Setting a temporary CFA register that will be copied
1424 into the FP later on. */
1425 offset = - INTVAL (XEXP (src, 1));
1426 cfa.offset += offset;
1427 cfa.reg = REGNO (dest);
1428 /* Or used to save regs to the stack. */
1429 cfa_temp.reg = cfa.reg;
1430 cfa_temp.offset = cfa.offset;
1433 /* Rule 5 */
1434 else if (GET_CODE (XEXP (src, 0)) == REG
1435 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1436 && XEXP (src, 1) == stack_pointer_rtx)
1438 /* Setting a scratch register that we will use instead
1439 of SP for saving registers to the stack. */
1440 if (cfa.reg != STACK_POINTER_REGNUM)
1441 abort ();
1442 cfa_store.reg = REGNO (dest);
1443 cfa_store.offset = cfa.offset - cfa_temp.offset;
1446 /* Rule 9 */
1447 else if (GET_CODE (src) == LO_SUM
1448 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1450 cfa_temp.reg = REGNO (dest);
1451 cfa_temp.offset = INTVAL (XEXP (src, 1));
1453 else
1454 abort ();
1456 break;
1458 /* Rule 6 */
1459 case CONST_INT:
1460 cfa_temp.reg = REGNO (dest);
1461 cfa_temp.offset = INTVAL (src);
1462 break;
1464 /* Rule 7 */
1465 case IOR:
1466 if (GET_CODE (XEXP (src, 0)) != REG
1467 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1468 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1469 abort ();
1471 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1472 cfa_temp.reg = REGNO (dest);
1473 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1474 break;
1476 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1477 which will fill in all of the bits. */
1478 /* Rule 8 */
1479 case HIGH:
1480 break;
1482 default:
1483 abort ();
1486 def_cfa_1 (label, &cfa);
1487 break;
1489 case MEM:
1490 if (GET_CODE (src) != REG)
1491 abort ();
1493 /* Saving a register to the stack. Make sure dest is relative to the
1494 CFA register. */
1495 switch (GET_CODE (XEXP (dest, 0)))
1497 /* Rule 10 */
1498 /* With a push. */
1499 case PRE_MODIFY:
1500 /* We can't handle variable size modifications. */
1501 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1502 abort ();
1503 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1505 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1506 || cfa_store.reg != STACK_POINTER_REGNUM)
1507 abort ();
1509 cfa_store.offset += offset;
1510 if (cfa.reg == STACK_POINTER_REGNUM)
1511 cfa.offset = cfa_store.offset;
1513 offset = -cfa_store.offset;
1514 break;
1516 /* Rule 11 */
1517 case PRE_INC:
1518 case PRE_DEC:
1519 offset = GET_MODE_SIZE (GET_MODE (dest));
1520 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1521 offset = -offset;
1523 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1524 || cfa_store.reg != STACK_POINTER_REGNUM)
1525 abort ();
1527 cfa_store.offset += offset;
1528 if (cfa.reg == STACK_POINTER_REGNUM)
1529 cfa.offset = cfa_store.offset;
1531 offset = -cfa_store.offset;
1532 break;
1534 /* Rule 12 */
1535 /* With an offset. */
1536 case PLUS:
1537 case MINUS:
1538 case LO_SUM:
1539 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1540 abort ();
1541 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1542 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1543 offset = -offset;
1545 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1546 offset -= cfa_store.offset;
1547 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1548 offset -= cfa_temp.offset;
1549 else
1550 abort ();
1551 break;
1553 /* Rule 13 */
1554 /* Without an offset. */
1555 case REG:
1556 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1557 offset = -cfa_store.offset;
1558 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1559 offset = -cfa_temp.offset;
1560 else
1561 abort ();
1562 break;
1564 /* Rule 14 */
1565 case POST_INC:
1566 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1567 abort ();
1568 offset = -cfa_temp.offset;
1569 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1570 break;
1572 default:
1573 abort ();
1576 if (REGNO (src) != STACK_POINTER_REGNUM
1577 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1578 && (unsigned) REGNO (src) == cfa.reg)
1580 /* We're storing the current CFA reg into the stack. */
1582 if (cfa.offset == 0)
1584 /* If the source register is exactly the CFA, assume
1585 we're saving SP like any other register; this happens
1586 on the ARM. */
1587 def_cfa_1 (label, &cfa);
1588 queue_reg_save (label, stack_pointer_rtx, offset);
1589 break;
1591 else
1593 /* Otherwise, we'll need to look in the stack to
1594 calculate the CFA. */
1595 rtx x = XEXP (dest, 0);
1597 if (GET_CODE (x) != REG)
1598 x = XEXP (x, 0);
1599 if (GET_CODE (x) != REG)
1600 abort ();
1602 cfa.reg = REGNO (x);
1603 cfa.base_offset = offset;
1604 cfa.indirect = 1;
1605 def_cfa_1 (label, &cfa);
1606 break;
1610 def_cfa_1 (label, &cfa);
1611 queue_reg_save (label, src, offset);
1612 break;
1614 default:
1615 abort ();
1619 /* Record call frame debugging information for INSN, which either
1620 sets SP or FP (adjusting how we calculate the frame address) or saves a
1621 register to the stack. If INSN is NULL_RTX, initialize our state. */
1623 void
1624 dwarf2out_frame_debug (rtx insn)
1626 const char *label;
1627 rtx src;
1629 if (insn == NULL_RTX)
1631 /* Flush any queued register saves. */
1632 flush_queued_reg_saves ();
1634 /* Set up state for generating call frame debug info. */
1635 lookup_cfa (&cfa);
1636 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1637 abort ();
1639 cfa.reg = STACK_POINTER_REGNUM;
1640 cfa_store = cfa;
1641 cfa_temp.reg = -1;
1642 cfa_temp.offset = 0;
1643 return;
1646 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1647 flush_queued_reg_saves ();
1649 if (! RTX_FRAME_RELATED_P (insn))
1651 if (!ACCUMULATE_OUTGOING_ARGS)
1652 dwarf2out_stack_adjust (insn);
1654 return;
1657 label = dwarf2out_cfi_label ();
1658 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1659 if (src)
1660 insn = XEXP (src, 0);
1661 else
1662 insn = PATTERN (insn);
1664 dwarf2out_frame_debug_expr (insn, label);
1667 #endif
1669 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1670 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1671 (enum dwarf_call_frame_info cfi);
1673 static enum dw_cfi_oprnd_type
1674 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1676 switch (cfi)
1678 case DW_CFA_nop:
1679 case DW_CFA_GNU_window_save:
1680 return dw_cfi_oprnd_unused;
1682 case DW_CFA_set_loc:
1683 case DW_CFA_advance_loc1:
1684 case DW_CFA_advance_loc2:
1685 case DW_CFA_advance_loc4:
1686 case DW_CFA_MIPS_advance_loc8:
1687 return dw_cfi_oprnd_addr;
1689 case DW_CFA_offset:
1690 case DW_CFA_offset_extended:
1691 case DW_CFA_def_cfa:
1692 case DW_CFA_offset_extended_sf:
1693 case DW_CFA_def_cfa_sf:
1694 case DW_CFA_restore_extended:
1695 case DW_CFA_undefined:
1696 case DW_CFA_same_value:
1697 case DW_CFA_def_cfa_register:
1698 case DW_CFA_register:
1699 return dw_cfi_oprnd_reg_num;
1701 case DW_CFA_def_cfa_offset:
1702 case DW_CFA_GNU_args_size:
1703 case DW_CFA_def_cfa_offset_sf:
1704 return dw_cfi_oprnd_offset;
1706 case DW_CFA_def_cfa_expression:
1707 case DW_CFA_expression:
1708 return dw_cfi_oprnd_loc;
1710 default:
1711 abort ();
1715 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1716 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1717 (enum dwarf_call_frame_info cfi);
1719 static enum dw_cfi_oprnd_type
1720 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1722 switch (cfi)
1724 case DW_CFA_def_cfa:
1725 case DW_CFA_def_cfa_sf:
1726 case DW_CFA_offset:
1727 case DW_CFA_offset_extended_sf:
1728 case DW_CFA_offset_extended:
1729 return dw_cfi_oprnd_offset;
1731 case DW_CFA_register:
1732 return dw_cfi_oprnd_reg_num;
1734 default:
1735 return dw_cfi_oprnd_unused;
1739 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1741 /* Output a Call Frame Information opcode and its operand(s). */
1743 static void
1744 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
1746 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1747 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1748 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1749 "DW_CFA_advance_loc 0x%lx",
1750 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1751 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1753 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1754 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1755 "DW_CFA_offset, column 0x%lx",
1756 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1757 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1759 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1760 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1761 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1762 "DW_CFA_restore, column 0x%lx",
1763 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1764 else
1766 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1767 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1769 switch (cfi->dw_cfi_opc)
1771 case DW_CFA_set_loc:
1772 if (for_eh)
1773 dw2_asm_output_encoded_addr_rtx (
1774 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1775 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1776 NULL);
1777 else
1778 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1779 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1780 break;
1782 case DW_CFA_advance_loc1:
1783 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1784 fde->dw_fde_current_label, NULL);
1785 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1786 break;
1788 case DW_CFA_advance_loc2:
1789 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1790 fde->dw_fde_current_label, NULL);
1791 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1792 break;
1794 case DW_CFA_advance_loc4:
1795 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1796 fde->dw_fde_current_label, NULL);
1797 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1798 break;
1800 case DW_CFA_MIPS_advance_loc8:
1801 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1802 fde->dw_fde_current_label, NULL);
1803 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1804 break;
1806 case DW_CFA_offset_extended:
1807 case DW_CFA_def_cfa:
1808 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1809 NULL);
1810 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1811 break;
1813 case DW_CFA_offset_extended_sf:
1814 case DW_CFA_def_cfa_sf:
1815 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1816 NULL);
1817 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1818 break;
1820 case DW_CFA_restore_extended:
1821 case DW_CFA_undefined:
1822 case DW_CFA_same_value:
1823 case DW_CFA_def_cfa_register:
1824 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1825 NULL);
1826 break;
1828 case DW_CFA_register:
1829 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1830 NULL);
1831 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1832 NULL);
1833 break;
1835 case DW_CFA_def_cfa_offset:
1836 case DW_CFA_GNU_args_size:
1837 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1838 break;
1840 case DW_CFA_def_cfa_offset_sf:
1841 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1842 break;
1844 case DW_CFA_GNU_window_save:
1845 break;
1847 case DW_CFA_def_cfa_expression:
1848 case DW_CFA_expression:
1849 output_cfa_loc (cfi);
1850 break;
1852 case DW_CFA_GNU_negative_offset_extended:
1853 /* Obsoleted by DW_CFA_offset_extended_sf. */
1854 abort ();
1856 default:
1857 break;
1862 /* Output the call frame information used to used to record information
1863 that relates to calculating the frame pointer, and records the
1864 location of saved registers. */
1866 static void
1867 output_call_frame_info (int for_eh)
1869 unsigned int i;
1870 dw_fde_ref fde;
1871 dw_cfi_ref cfi;
1872 char l1[20], l2[20], section_start_label[20];
1873 bool any_lsda_needed = false;
1874 char augmentation[6];
1875 int augmentation_size;
1876 int fde_encoding = DW_EH_PE_absptr;
1877 int per_encoding = DW_EH_PE_absptr;
1878 int lsda_encoding = DW_EH_PE_absptr;
1880 /* Don't emit a CIE if there won't be any FDEs. */
1881 if (fde_table_in_use == 0)
1882 return;
1884 /* If we don't have any functions we'll want to unwind out of, don't
1885 emit any EH unwind information. Note that if exceptions aren't
1886 enabled, we won't have collected nothrow information, and if we
1887 asked for asynchronous tables, we always want this info. */
1888 if (for_eh)
1890 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
1892 for (i = 0; i < fde_table_in_use; i++)
1893 if (fde_table[i].uses_eh_lsda)
1894 any_eh_needed = any_lsda_needed = true;
1895 else if (! fde_table[i].nothrow
1896 && ! fde_table[i].all_throwers_are_sibcalls)
1897 any_eh_needed = true;
1899 if (! any_eh_needed)
1900 return;
1903 /* We're going to be generating comments, so turn on app. */
1904 if (flag_debug_asm)
1905 app_enable ();
1907 if (for_eh)
1908 (*targetm.asm_out.eh_frame_section) ();
1909 else
1910 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1912 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1913 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1915 /* Output the CIE. */
1916 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1917 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1918 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1919 "Length of Common Information Entry");
1920 ASM_OUTPUT_LABEL (asm_out_file, l1);
1922 /* Now that the CIE pointer is PC-relative for EH,
1923 use 0 to identify the CIE. */
1924 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1925 (for_eh ? 0 : DW_CIE_ID),
1926 "CIE Identifier Tag");
1928 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1930 augmentation[0] = 0;
1931 augmentation_size = 0;
1932 if (for_eh)
1934 char *p;
1936 /* Augmentation:
1937 z Indicates that a uleb128 is present to size the
1938 augmentation section.
1939 L Indicates the encoding (and thus presence) of
1940 an LSDA pointer in the FDE augmentation.
1941 R Indicates a non-default pointer encoding for
1942 FDE code pointers.
1943 P Indicates the presence of an encoding + language
1944 personality routine in the CIE augmentation. */
1946 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1947 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1948 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1950 p = augmentation + 1;
1951 if (eh_personality_libfunc)
1953 *p++ = 'P';
1954 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1956 if (any_lsda_needed)
1958 *p++ = 'L';
1959 augmentation_size += 1;
1961 if (fde_encoding != DW_EH_PE_absptr)
1963 *p++ = 'R';
1964 augmentation_size += 1;
1966 if (p > augmentation + 1)
1968 augmentation[0] = 'z';
1969 *p = '\0';
1972 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1973 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1975 int offset = ( 4 /* Length */
1976 + 4 /* CIE Id */
1977 + 1 /* CIE version */
1978 + strlen (augmentation) + 1 /* Augmentation */
1979 + size_of_uleb128 (1) /* Code alignment */
1980 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1981 + 1 /* RA column */
1982 + 1 /* Augmentation size */
1983 + 1 /* Personality encoding */ );
1984 int pad = -offset & (PTR_SIZE - 1);
1986 augmentation_size += pad;
1988 /* Augmentations should be small, so there's scarce need to
1989 iterate for a solution. Die if we exceed one uleb128 byte. */
1990 if (size_of_uleb128 (augmentation_size) != 1)
1991 abort ();
1995 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1996 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1997 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1998 "CIE Data Alignment Factor");
1999 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
2001 if (augmentation[0])
2003 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2004 if (eh_personality_libfunc)
2006 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2007 eh_data_format_name (per_encoding));
2008 dw2_asm_output_encoded_addr_rtx (per_encoding,
2009 eh_personality_libfunc, NULL);
2012 if (any_lsda_needed)
2013 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2014 eh_data_format_name (lsda_encoding));
2016 if (fde_encoding != DW_EH_PE_absptr)
2017 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2018 eh_data_format_name (fde_encoding));
2021 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2022 output_cfi (cfi, NULL, for_eh);
2024 /* Pad the CIE out to an address sized boundary. */
2025 ASM_OUTPUT_ALIGN (asm_out_file,
2026 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2027 ASM_OUTPUT_LABEL (asm_out_file, l2);
2029 /* Loop through all of the FDE's. */
2030 for (i = 0; i < fde_table_in_use; i++)
2032 fde = &fde_table[i];
2034 /* Don't emit EH unwind info for leaf functions that don't need it. */
2035 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2036 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2037 && !fde->uses_eh_lsda)
2038 continue;
2040 (*targetm.asm_out.internal_label) (asm_out_file, FDE_LABEL, for_eh + i * 2);
2041 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2042 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2043 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2044 "FDE Length");
2045 ASM_OUTPUT_LABEL (asm_out_file, l1);
2047 if (for_eh)
2048 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2049 else
2050 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2051 "FDE CIE offset");
2053 if (for_eh)
2055 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2056 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
2057 "FDE initial location");
2058 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2059 fde->dw_fde_end, fde->dw_fde_begin,
2060 "FDE address range");
2062 else
2064 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2065 "FDE initial location");
2066 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2067 fde->dw_fde_end, fde->dw_fde_begin,
2068 "FDE address range");
2071 if (augmentation[0])
2073 if (any_lsda_needed)
2075 int size = size_of_encoded_value (lsda_encoding);
2077 if (lsda_encoding == DW_EH_PE_aligned)
2079 int offset = ( 4 /* Length */
2080 + 4 /* CIE offset */
2081 + 2 * size_of_encoded_value (fde_encoding)
2082 + 1 /* Augmentation size */ );
2083 int pad = -offset & (PTR_SIZE - 1);
2085 size += pad;
2086 if (size_of_uleb128 (size) != 1)
2087 abort ();
2090 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2092 if (fde->uses_eh_lsda)
2094 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2095 fde->funcdef_number);
2096 dw2_asm_output_encoded_addr_rtx (
2097 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2098 "Language Specific Data Area");
2100 else
2102 if (lsda_encoding == DW_EH_PE_aligned)
2103 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2104 dw2_asm_output_data
2105 (size_of_encoded_value (lsda_encoding), 0,
2106 "Language Specific Data Area (none)");
2109 else
2110 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2113 /* Loop through the Call Frame Instructions associated with
2114 this FDE. */
2115 fde->dw_fde_current_label = fde->dw_fde_begin;
2116 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2117 output_cfi (cfi, fde, for_eh);
2119 /* Pad the FDE out to an address sized boundary. */
2120 ASM_OUTPUT_ALIGN (asm_out_file,
2121 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2122 ASM_OUTPUT_LABEL (asm_out_file, l2);
2125 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2126 dw2_asm_output_data (4, 0, "End of Table");
2127 #ifdef MIPS_DEBUGGING_INFO
2128 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2129 get a value of 0. Putting .align 0 after the label fixes it. */
2130 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2131 #endif
2133 /* Turn off app to make assembly quicker. */
2134 if (flag_debug_asm)
2135 app_disable ();
2138 /* Output a marker (i.e. a label) for the beginning of a function, before
2139 the prologue. */
2141 void
2142 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2143 const char *file ATTRIBUTE_UNUSED)
2145 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2146 dw_fde_ref fde;
2148 current_function_func_begin_label = 0;
2150 #ifdef IA64_UNWIND_INFO
2151 /* ??? current_function_func_begin_label is also used by except.c
2152 for call-site information. We must emit this label if it might
2153 be used. */
2154 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2155 && ! dwarf2out_do_frame ())
2156 return;
2157 #else
2158 if (! dwarf2out_do_frame ())
2159 return;
2160 #endif
2162 function_section (current_function_decl);
2163 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2164 current_function_funcdef_no);
2165 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2166 current_function_funcdef_no);
2167 current_function_func_begin_label = get_identifier (label);
2169 #ifdef IA64_UNWIND_INFO
2170 /* We can elide the fde allocation if we're not emitting debug info. */
2171 if (! dwarf2out_do_frame ())
2172 return;
2173 #endif
2175 /* Expand the fde table if necessary. */
2176 if (fde_table_in_use == fde_table_allocated)
2178 fde_table_allocated += FDE_TABLE_INCREMENT;
2179 fde_table = ggc_realloc (fde_table,
2180 fde_table_allocated * sizeof (dw_fde_node));
2181 memset (fde_table + fde_table_in_use, 0,
2182 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2185 /* Record the FDE associated with this function. */
2186 current_funcdef_fde = fde_table_in_use;
2188 /* Add the new FDE at the end of the fde_table. */
2189 fde = &fde_table[fde_table_in_use++];
2190 fde->dw_fde_begin = xstrdup (label);
2191 fde->dw_fde_current_label = NULL;
2192 fde->dw_fde_end = NULL;
2193 fde->dw_fde_cfi = NULL;
2194 fde->funcdef_number = current_function_funcdef_no;
2195 fde->nothrow = current_function_nothrow;
2196 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2197 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2199 args_size = old_args_size = 0;
2201 /* We only want to output line number information for the genuine dwarf2
2202 prologue case, not the eh frame case. */
2203 #ifdef DWARF2_DEBUGGING_INFO
2204 if (file)
2205 dwarf2out_source_line (line, file);
2206 #endif
2209 /* Output a marker (i.e. a label) for the absolute end of the generated code
2210 for a function definition. This gets called *after* the epilogue code has
2211 been generated. */
2213 void
2214 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2215 const char *file ATTRIBUTE_UNUSED)
2217 dw_fde_ref fde;
2218 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2220 /* Output a label to mark the endpoint of the code generated for this
2221 function. */
2222 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2223 current_function_funcdef_no);
2224 ASM_OUTPUT_LABEL (asm_out_file, label);
2225 fde = &fde_table[fde_table_in_use - 1];
2226 fde->dw_fde_end = xstrdup (label);
2229 void
2230 dwarf2out_frame_init (void)
2232 /* Allocate the initial hunk of the fde_table. */
2233 fde_table = (dw_fde_ref) ggc_alloc_cleared (FDE_TABLE_INCREMENT
2234 * sizeof (dw_fde_node));
2235 fde_table_allocated = FDE_TABLE_INCREMENT;
2236 fde_table_in_use = 0;
2238 /* Generate the CFA instructions common to all FDE's. Do it now for the
2239 sake of lookup_cfa. */
2241 #ifdef DWARF2_UNWIND_INFO
2242 /* On entry, the Canonical Frame Address is at SP. */
2243 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2244 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2245 #endif
2248 void
2249 dwarf2out_frame_finish (void)
2251 /* Output call frame information. */
2252 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2253 output_call_frame_info (0);
2255 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2256 output_call_frame_info (1);
2258 #endif
2260 /* And now, the subset of the debugging information support code necessary
2261 for emitting location expressions. */
2263 /* We need some way to distinguish DW_OP_addr with a direct symbol
2264 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2265 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2268 typedef struct dw_val_struct *dw_val_ref;
2269 typedef struct die_struct *dw_die_ref;
2270 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2271 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2273 /* Each DIE may have a series of attribute/value pairs. Values
2274 can take on several forms. The forms that are used in this
2275 implementation are listed below. */
2277 enum dw_val_class
2279 dw_val_class_addr,
2280 dw_val_class_offset,
2281 dw_val_class_loc,
2282 dw_val_class_loc_list,
2283 dw_val_class_range_list,
2284 dw_val_class_const,
2285 dw_val_class_unsigned_const,
2286 dw_val_class_long_long,
2287 dw_val_class_float,
2288 dw_val_class_flag,
2289 dw_val_class_die_ref,
2290 dw_val_class_fde_ref,
2291 dw_val_class_lbl_id,
2292 dw_val_class_lbl_offset,
2293 dw_val_class_str
2296 /* Describe a double word constant value. */
2297 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2299 typedef struct dw_long_long_struct GTY(())
2301 unsigned long hi;
2302 unsigned long low;
2304 dw_long_long_const;
2306 /* Describe a floating point constant value. */
2308 typedef struct dw_fp_struct GTY(())
2310 long * GTY((length ("%h.length"))) array;
2311 unsigned length;
2313 dw_float_const;
2315 /* The dw_val_node describes an attribute's value, as it is
2316 represented internally. */
2318 typedef struct dw_val_struct GTY(())
2320 enum dw_val_class val_class;
2321 union dw_val_struct_union
2323 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2324 long unsigned GTY ((tag ("dw_val_class_offset"))) val_offset;
2325 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2326 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2327 long int GTY ((default (""))) val_int;
2328 long unsigned GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2329 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2330 dw_float_const GTY ((tag ("dw_val_class_float"))) val_float;
2331 struct dw_val_die_union
2333 dw_die_ref die;
2334 int external;
2335 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2336 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2337 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2338 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2339 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2341 GTY ((desc ("%1.val_class"))) v;
2343 dw_val_node;
2345 /* Locations in memory are described using a sequence of stack machine
2346 operations. */
2348 typedef struct dw_loc_descr_struct GTY(())
2350 dw_loc_descr_ref dw_loc_next;
2351 enum dwarf_location_atom dw_loc_opc;
2352 dw_val_node dw_loc_oprnd1;
2353 dw_val_node dw_loc_oprnd2;
2354 int dw_loc_addr;
2356 dw_loc_descr_node;
2358 /* Location lists are ranges + location descriptions for that range,
2359 so you can track variables that are in different places over
2360 their entire life. */
2361 typedef struct dw_loc_list_struct GTY(())
2363 dw_loc_list_ref dw_loc_next;
2364 const char *begin; /* Label for begin address of range */
2365 const char *end; /* Label for end address of range */
2366 char *ll_symbol; /* Label for beginning of location list.
2367 Only on head of list */
2368 const char *section; /* Section this loclist is relative to */
2369 dw_loc_descr_ref expr;
2370 } dw_loc_list_node;
2372 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2374 static const char *dwarf_stack_op_name (unsigned);
2375 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2376 unsigned long, unsigned long);
2377 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2378 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2379 static unsigned long size_of_locs (dw_loc_descr_ref);
2380 static void output_loc_operands (dw_loc_descr_ref);
2381 static void output_loc_sequence (dw_loc_descr_ref);
2383 /* Convert a DWARF stack opcode into its string name. */
2385 static const char *
2386 dwarf_stack_op_name (unsigned int op)
2388 switch (op)
2390 case DW_OP_addr:
2391 case INTERNAL_DW_OP_tls_addr:
2392 return "DW_OP_addr";
2393 case DW_OP_deref:
2394 return "DW_OP_deref";
2395 case DW_OP_const1u:
2396 return "DW_OP_const1u";
2397 case DW_OP_const1s:
2398 return "DW_OP_const1s";
2399 case DW_OP_const2u:
2400 return "DW_OP_const2u";
2401 case DW_OP_const2s:
2402 return "DW_OP_const2s";
2403 case DW_OP_const4u:
2404 return "DW_OP_const4u";
2405 case DW_OP_const4s:
2406 return "DW_OP_const4s";
2407 case DW_OP_const8u:
2408 return "DW_OP_const8u";
2409 case DW_OP_const8s:
2410 return "DW_OP_const8s";
2411 case DW_OP_constu:
2412 return "DW_OP_constu";
2413 case DW_OP_consts:
2414 return "DW_OP_consts";
2415 case DW_OP_dup:
2416 return "DW_OP_dup";
2417 case DW_OP_drop:
2418 return "DW_OP_drop";
2419 case DW_OP_over:
2420 return "DW_OP_over";
2421 case DW_OP_pick:
2422 return "DW_OP_pick";
2423 case DW_OP_swap:
2424 return "DW_OP_swap";
2425 case DW_OP_rot:
2426 return "DW_OP_rot";
2427 case DW_OP_xderef:
2428 return "DW_OP_xderef";
2429 case DW_OP_abs:
2430 return "DW_OP_abs";
2431 case DW_OP_and:
2432 return "DW_OP_and";
2433 case DW_OP_div:
2434 return "DW_OP_div";
2435 case DW_OP_minus:
2436 return "DW_OP_minus";
2437 case DW_OP_mod:
2438 return "DW_OP_mod";
2439 case DW_OP_mul:
2440 return "DW_OP_mul";
2441 case DW_OP_neg:
2442 return "DW_OP_neg";
2443 case DW_OP_not:
2444 return "DW_OP_not";
2445 case DW_OP_or:
2446 return "DW_OP_or";
2447 case DW_OP_plus:
2448 return "DW_OP_plus";
2449 case DW_OP_plus_uconst:
2450 return "DW_OP_plus_uconst";
2451 case DW_OP_shl:
2452 return "DW_OP_shl";
2453 case DW_OP_shr:
2454 return "DW_OP_shr";
2455 case DW_OP_shra:
2456 return "DW_OP_shra";
2457 case DW_OP_xor:
2458 return "DW_OP_xor";
2459 case DW_OP_bra:
2460 return "DW_OP_bra";
2461 case DW_OP_eq:
2462 return "DW_OP_eq";
2463 case DW_OP_ge:
2464 return "DW_OP_ge";
2465 case DW_OP_gt:
2466 return "DW_OP_gt";
2467 case DW_OP_le:
2468 return "DW_OP_le";
2469 case DW_OP_lt:
2470 return "DW_OP_lt";
2471 case DW_OP_ne:
2472 return "DW_OP_ne";
2473 case DW_OP_skip:
2474 return "DW_OP_skip";
2475 case DW_OP_lit0:
2476 return "DW_OP_lit0";
2477 case DW_OP_lit1:
2478 return "DW_OP_lit1";
2479 case DW_OP_lit2:
2480 return "DW_OP_lit2";
2481 case DW_OP_lit3:
2482 return "DW_OP_lit3";
2483 case DW_OP_lit4:
2484 return "DW_OP_lit4";
2485 case DW_OP_lit5:
2486 return "DW_OP_lit5";
2487 case DW_OP_lit6:
2488 return "DW_OP_lit6";
2489 case DW_OP_lit7:
2490 return "DW_OP_lit7";
2491 case DW_OP_lit8:
2492 return "DW_OP_lit8";
2493 case DW_OP_lit9:
2494 return "DW_OP_lit9";
2495 case DW_OP_lit10:
2496 return "DW_OP_lit10";
2497 case DW_OP_lit11:
2498 return "DW_OP_lit11";
2499 case DW_OP_lit12:
2500 return "DW_OP_lit12";
2501 case DW_OP_lit13:
2502 return "DW_OP_lit13";
2503 case DW_OP_lit14:
2504 return "DW_OP_lit14";
2505 case DW_OP_lit15:
2506 return "DW_OP_lit15";
2507 case DW_OP_lit16:
2508 return "DW_OP_lit16";
2509 case DW_OP_lit17:
2510 return "DW_OP_lit17";
2511 case DW_OP_lit18:
2512 return "DW_OP_lit18";
2513 case DW_OP_lit19:
2514 return "DW_OP_lit19";
2515 case DW_OP_lit20:
2516 return "DW_OP_lit20";
2517 case DW_OP_lit21:
2518 return "DW_OP_lit21";
2519 case DW_OP_lit22:
2520 return "DW_OP_lit22";
2521 case DW_OP_lit23:
2522 return "DW_OP_lit23";
2523 case DW_OP_lit24:
2524 return "DW_OP_lit24";
2525 case DW_OP_lit25:
2526 return "DW_OP_lit25";
2527 case DW_OP_lit26:
2528 return "DW_OP_lit26";
2529 case DW_OP_lit27:
2530 return "DW_OP_lit27";
2531 case DW_OP_lit28:
2532 return "DW_OP_lit28";
2533 case DW_OP_lit29:
2534 return "DW_OP_lit29";
2535 case DW_OP_lit30:
2536 return "DW_OP_lit30";
2537 case DW_OP_lit31:
2538 return "DW_OP_lit31";
2539 case DW_OP_reg0:
2540 return "DW_OP_reg0";
2541 case DW_OP_reg1:
2542 return "DW_OP_reg1";
2543 case DW_OP_reg2:
2544 return "DW_OP_reg2";
2545 case DW_OP_reg3:
2546 return "DW_OP_reg3";
2547 case DW_OP_reg4:
2548 return "DW_OP_reg4";
2549 case DW_OP_reg5:
2550 return "DW_OP_reg5";
2551 case DW_OP_reg6:
2552 return "DW_OP_reg6";
2553 case DW_OP_reg7:
2554 return "DW_OP_reg7";
2555 case DW_OP_reg8:
2556 return "DW_OP_reg8";
2557 case DW_OP_reg9:
2558 return "DW_OP_reg9";
2559 case DW_OP_reg10:
2560 return "DW_OP_reg10";
2561 case DW_OP_reg11:
2562 return "DW_OP_reg11";
2563 case DW_OP_reg12:
2564 return "DW_OP_reg12";
2565 case DW_OP_reg13:
2566 return "DW_OP_reg13";
2567 case DW_OP_reg14:
2568 return "DW_OP_reg14";
2569 case DW_OP_reg15:
2570 return "DW_OP_reg15";
2571 case DW_OP_reg16:
2572 return "DW_OP_reg16";
2573 case DW_OP_reg17:
2574 return "DW_OP_reg17";
2575 case DW_OP_reg18:
2576 return "DW_OP_reg18";
2577 case DW_OP_reg19:
2578 return "DW_OP_reg19";
2579 case DW_OP_reg20:
2580 return "DW_OP_reg20";
2581 case DW_OP_reg21:
2582 return "DW_OP_reg21";
2583 case DW_OP_reg22:
2584 return "DW_OP_reg22";
2585 case DW_OP_reg23:
2586 return "DW_OP_reg23";
2587 case DW_OP_reg24:
2588 return "DW_OP_reg24";
2589 case DW_OP_reg25:
2590 return "DW_OP_reg25";
2591 case DW_OP_reg26:
2592 return "DW_OP_reg26";
2593 case DW_OP_reg27:
2594 return "DW_OP_reg27";
2595 case DW_OP_reg28:
2596 return "DW_OP_reg28";
2597 case DW_OP_reg29:
2598 return "DW_OP_reg29";
2599 case DW_OP_reg30:
2600 return "DW_OP_reg30";
2601 case DW_OP_reg31:
2602 return "DW_OP_reg31";
2603 case DW_OP_breg0:
2604 return "DW_OP_breg0";
2605 case DW_OP_breg1:
2606 return "DW_OP_breg1";
2607 case DW_OP_breg2:
2608 return "DW_OP_breg2";
2609 case DW_OP_breg3:
2610 return "DW_OP_breg3";
2611 case DW_OP_breg4:
2612 return "DW_OP_breg4";
2613 case DW_OP_breg5:
2614 return "DW_OP_breg5";
2615 case DW_OP_breg6:
2616 return "DW_OP_breg6";
2617 case DW_OP_breg7:
2618 return "DW_OP_breg7";
2619 case DW_OP_breg8:
2620 return "DW_OP_breg8";
2621 case DW_OP_breg9:
2622 return "DW_OP_breg9";
2623 case DW_OP_breg10:
2624 return "DW_OP_breg10";
2625 case DW_OP_breg11:
2626 return "DW_OP_breg11";
2627 case DW_OP_breg12:
2628 return "DW_OP_breg12";
2629 case DW_OP_breg13:
2630 return "DW_OP_breg13";
2631 case DW_OP_breg14:
2632 return "DW_OP_breg14";
2633 case DW_OP_breg15:
2634 return "DW_OP_breg15";
2635 case DW_OP_breg16:
2636 return "DW_OP_breg16";
2637 case DW_OP_breg17:
2638 return "DW_OP_breg17";
2639 case DW_OP_breg18:
2640 return "DW_OP_breg18";
2641 case DW_OP_breg19:
2642 return "DW_OP_breg19";
2643 case DW_OP_breg20:
2644 return "DW_OP_breg20";
2645 case DW_OP_breg21:
2646 return "DW_OP_breg21";
2647 case DW_OP_breg22:
2648 return "DW_OP_breg22";
2649 case DW_OP_breg23:
2650 return "DW_OP_breg23";
2651 case DW_OP_breg24:
2652 return "DW_OP_breg24";
2653 case DW_OP_breg25:
2654 return "DW_OP_breg25";
2655 case DW_OP_breg26:
2656 return "DW_OP_breg26";
2657 case DW_OP_breg27:
2658 return "DW_OP_breg27";
2659 case DW_OP_breg28:
2660 return "DW_OP_breg28";
2661 case DW_OP_breg29:
2662 return "DW_OP_breg29";
2663 case DW_OP_breg30:
2664 return "DW_OP_breg30";
2665 case DW_OP_breg31:
2666 return "DW_OP_breg31";
2667 case DW_OP_regx:
2668 return "DW_OP_regx";
2669 case DW_OP_fbreg:
2670 return "DW_OP_fbreg";
2671 case DW_OP_bregx:
2672 return "DW_OP_bregx";
2673 case DW_OP_piece:
2674 return "DW_OP_piece";
2675 case DW_OP_deref_size:
2676 return "DW_OP_deref_size";
2677 case DW_OP_xderef_size:
2678 return "DW_OP_xderef_size";
2679 case DW_OP_nop:
2680 return "DW_OP_nop";
2681 case DW_OP_push_object_address:
2682 return "DW_OP_push_object_address";
2683 case DW_OP_call2:
2684 return "DW_OP_call2";
2685 case DW_OP_call4:
2686 return "DW_OP_call4";
2687 case DW_OP_call_ref:
2688 return "DW_OP_call_ref";
2689 case DW_OP_GNU_push_tls_address:
2690 return "DW_OP_GNU_push_tls_address";
2691 default:
2692 return "OP_<unknown>";
2696 /* Return a pointer to a newly allocated location description. Location
2697 descriptions are simple expression terms that can be strung
2698 together to form more complicated location (address) descriptions. */
2700 static inline dw_loc_descr_ref
2701 new_loc_descr (enum dwarf_location_atom op, long unsigned int oprnd1,
2702 long unsigned int oprnd2)
2704 dw_loc_descr_ref descr
2705 = (dw_loc_descr_ref) ggc_alloc_cleared (sizeof (dw_loc_descr_node));
2707 descr->dw_loc_opc = op;
2708 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2709 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2710 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2711 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2713 return descr;
2717 /* Add a location description term to a location description expression. */
2719 static inline void
2720 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
2722 dw_loc_descr_ref *d;
2724 /* Find the end of the chain. */
2725 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2728 *d = descr;
2731 /* Return the size of a location descriptor. */
2733 static unsigned long
2734 size_of_loc_descr (dw_loc_descr_ref loc)
2736 unsigned long size = 1;
2738 switch (loc->dw_loc_opc)
2740 case DW_OP_addr:
2741 case INTERNAL_DW_OP_tls_addr:
2742 size += DWARF2_ADDR_SIZE;
2743 break;
2744 case DW_OP_const1u:
2745 case DW_OP_const1s:
2746 size += 1;
2747 break;
2748 case DW_OP_const2u:
2749 case DW_OP_const2s:
2750 size += 2;
2751 break;
2752 case DW_OP_const4u:
2753 case DW_OP_const4s:
2754 size += 4;
2755 break;
2756 case DW_OP_const8u:
2757 case DW_OP_const8s:
2758 size += 8;
2759 break;
2760 case DW_OP_constu:
2761 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2762 break;
2763 case DW_OP_consts:
2764 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2765 break;
2766 case DW_OP_pick:
2767 size += 1;
2768 break;
2769 case DW_OP_plus_uconst:
2770 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2771 break;
2772 case DW_OP_skip:
2773 case DW_OP_bra:
2774 size += 2;
2775 break;
2776 case DW_OP_breg0:
2777 case DW_OP_breg1:
2778 case DW_OP_breg2:
2779 case DW_OP_breg3:
2780 case DW_OP_breg4:
2781 case DW_OP_breg5:
2782 case DW_OP_breg6:
2783 case DW_OP_breg7:
2784 case DW_OP_breg8:
2785 case DW_OP_breg9:
2786 case DW_OP_breg10:
2787 case DW_OP_breg11:
2788 case DW_OP_breg12:
2789 case DW_OP_breg13:
2790 case DW_OP_breg14:
2791 case DW_OP_breg15:
2792 case DW_OP_breg16:
2793 case DW_OP_breg17:
2794 case DW_OP_breg18:
2795 case DW_OP_breg19:
2796 case DW_OP_breg20:
2797 case DW_OP_breg21:
2798 case DW_OP_breg22:
2799 case DW_OP_breg23:
2800 case DW_OP_breg24:
2801 case DW_OP_breg25:
2802 case DW_OP_breg26:
2803 case DW_OP_breg27:
2804 case DW_OP_breg28:
2805 case DW_OP_breg29:
2806 case DW_OP_breg30:
2807 case DW_OP_breg31:
2808 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2809 break;
2810 case DW_OP_regx:
2811 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2812 break;
2813 case DW_OP_fbreg:
2814 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2815 break;
2816 case DW_OP_bregx:
2817 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2818 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2819 break;
2820 case DW_OP_piece:
2821 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2822 break;
2823 case DW_OP_deref_size:
2824 case DW_OP_xderef_size:
2825 size += 1;
2826 break;
2827 case DW_OP_call2:
2828 size += 2;
2829 break;
2830 case DW_OP_call4:
2831 size += 4;
2832 break;
2833 case DW_OP_call_ref:
2834 size += DWARF2_ADDR_SIZE;
2835 break;
2836 default:
2837 break;
2840 return size;
2843 /* Return the size of a series of location descriptors. */
2845 static unsigned long
2846 size_of_locs (dw_loc_descr_ref loc)
2848 unsigned long size;
2850 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2852 loc->dw_loc_addr = size;
2853 size += size_of_loc_descr (loc);
2856 return size;
2859 /* Output location description stack opcode's operands (if any). */
2861 static void
2862 output_loc_operands (dw_loc_descr_ref loc)
2864 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2865 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2867 switch (loc->dw_loc_opc)
2869 #ifdef DWARF2_DEBUGGING_INFO
2870 case DW_OP_addr:
2871 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2872 break;
2873 case DW_OP_const2u:
2874 case DW_OP_const2s:
2875 dw2_asm_output_data (2, val1->v.val_int, NULL);
2876 break;
2877 case DW_OP_const4u:
2878 case DW_OP_const4s:
2879 dw2_asm_output_data (4, val1->v.val_int, NULL);
2880 break;
2881 case DW_OP_const8u:
2882 case DW_OP_const8s:
2883 if (HOST_BITS_PER_LONG < 64)
2884 abort ();
2885 dw2_asm_output_data (8, val1->v.val_int, NULL);
2886 break;
2887 case DW_OP_skip:
2888 case DW_OP_bra:
2890 int offset;
2892 if (val1->val_class == dw_val_class_loc)
2893 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2894 else
2895 abort ();
2897 dw2_asm_output_data (2, offset, NULL);
2899 break;
2900 #else
2901 case DW_OP_addr:
2902 case DW_OP_const2u:
2903 case DW_OP_const2s:
2904 case DW_OP_const4u:
2905 case DW_OP_const4s:
2906 case DW_OP_const8u:
2907 case DW_OP_const8s:
2908 case DW_OP_skip:
2909 case DW_OP_bra:
2910 /* We currently don't make any attempt to make sure these are
2911 aligned properly like we do for the main unwind info, so
2912 don't support emitting things larger than a byte if we're
2913 only doing unwinding. */
2914 abort ();
2915 #endif
2916 case DW_OP_const1u:
2917 case DW_OP_const1s:
2918 dw2_asm_output_data (1, val1->v.val_int, NULL);
2919 break;
2920 case DW_OP_constu:
2921 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2922 break;
2923 case DW_OP_consts:
2924 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2925 break;
2926 case DW_OP_pick:
2927 dw2_asm_output_data (1, val1->v.val_int, NULL);
2928 break;
2929 case DW_OP_plus_uconst:
2930 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2931 break;
2932 case DW_OP_breg0:
2933 case DW_OP_breg1:
2934 case DW_OP_breg2:
2935 case DW_OP_breg3:
2936 case DW_OP_breg4:
2937 case DW_OP_breg5:
2938 case DW_OP_breg6:
2939 case DW_OP_breg7:
2940 case DW_OP_breg8:
2941 case DW_OP_breg9:
2942 case DW_OP_breg10:
2943 case DW_OP_breg11:
2944 case DW_OP_breg12:
2945 case DW_OP_breg13:
2946 case DW_OP_breg14:
2947 case DW_OP_breg15:
2948 case DW_OP_breg16:
2949 case DW_OP_breg17:
2950 case DW_OP_breg18:
2951 case DW_OP_breg19:
2952 case DW_OP_breg20:
2953 case DW_OP_breg21:
2954 case DW_OP_breg22:
2955 case DW_OP_breg23:
2956 case DW_OP_breg24:
2957 case DW_OP_breg25:
2958 case DW_OP_breg26:
2959 case DW_OP_breg27:
2960 case DW_OP_breg28:
2961 case DW_OP_breg29:
2962 case DW_OP_breg30:
2963 case DW_OP_breg31:
2964 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2965 break;
2966 case DW_OP_regx:
2967 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2968 break;
2969 case DW_OP_fbreg:
2970 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2971 break;
2972 case DW_OP_bregx:
2973 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2974 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2975 break;
2976 case DW_OP_piece:
2977 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2978 break;
2979 case DW_OP_deref_size:
2980 case DW_OP_xderef_size:
2981 dw2_asm_output_data (1, val1->v.val_int, NULL);
2982 break;
2984 case INTERNAL_DW_OP_tls_addr:
2985 #ifdef ASM_OUTPUT_DWARF_DTPREL
2986 ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE,
2987 val1->v.val_addr);
2988 fputc ('\n', asm_out_file);
2989 #else
2990 abort ();
2991 #endif
2992 break;
2994 default:
2995 /* Other codes have no operands. */
2996 break;
3000 /* Output a sequence of location operations. */
3002 static void
3003 output_loc_sequence (dw_loc_descr_ref loc)
3005 for (; loc != NULL; loc = loc->dw_loc_next)
3007 /* Output the opcode. */
3008 dw2_asm_output_data (1, loc->dw_loc_opc,
3009 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3011 /* Output the operand(s) (if any). */
3012 output_loc_operands (loc);
3016 /* This routine will generate the correct assembly data for a location
3017 description based on a cfi entry with a complex address. */
3019 static void
3020 output_cfa_loc (dw_cfi_ref cfi)
3022 dw_loc_descr_ref loc;
3023 unsigned long size;
3025 /* Output the size of the block. */
3026 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3027 size = size_of_locs (loc);
3028 dw2_asm_output_data_uleb128 (size, NULL);
3030 /* Now output the operations themselves. */
3031 output_loc_sequence (loc);
3034 /* This function builds a dwarf location descriptor sequence from
3035 a dw_cfa_location. */
3037 static struct dw_loc_descr_struct *
3038 build_cfa_loc (dw_cfa_location *cfa)
3040 struct dw_loc_descr_struct *head, *tmp;
3042 if (cfa->indirect == 0)
3043 abort ();
3045 if (cfa->base_offset)
3047 if (cfa->reg <= 31)
3048 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3049 else
3050 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3052 else if (cfa->reg <= 31)
3053 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3054 else
3055 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3057 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3058 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3059 add_loc_descr (&head, tmp);
3060 if (cfa->offset != 0)
3062 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3063 add_loc_descr (&head, tmp);
3066 return head;
3069 /* This function fills in aa dw_cfa_location structure from a dwarf location
3070 descriptor sequence. */
3072 static void
3073 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3075 struct dw_loc_descr_struct *ptr;
3076 cfa->offset = 0;
3077 cfa->base_offset = 0;
3078 cfa->indirect = 0;
3079 cfa->reg = -1;
3081 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3083 enum dwarf_location_atom op = ptr->dw_loc_opc;
3085 switch (op)
3087 case DW_OP_reg0:
3088 case DW_OP_reg1:
3089 case DW_OP_reg2:
3090 case DW_OP_reg3:
3091 case DW_OP_reg4:
3092 case DW_OP_reg5:
3093 case DW_OP_reg6:
3094 case DW_OP_reg7:
3095 case DW_OP_reg8:
3096 case DW_OP_reg9:
3097 case DW_OP_reg10:
3098 case DW_OP_reg11:
3099 case DW_OP_reg12:
3100 case DW_OP_reg13:
3101 case DW_OP_reg14:
3102 case DW_OP_reg15:
3103 case DW_OP_reg16:
3104 case DW_OP_reg17:
3105 case DW_OP_reg18:
3106 case DW_OP_reg19:
3107 case DW_OP_reg20:
3108 case DW_OP_reg21:
3109 case DW_OP_reg22:
3110 case DW_OP_reg23:
3111 case DW_OP_reg24:
3112 case DW_OP_reg25:
3113 case DW_OP_reg26:
3114 case DW_OP_reg27:
3115 case DW_OP_reg28:
3116 case DW_OP_reg29:
3117 case DW_OP_reg30:
3118 case DW_OP_reg31:
3119 cfa->reg = op - DW_OP_reg0;
3120 break;
3121 case DW_OP_regx:
3122 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3123 break;
3124 case DW_OP_breg0:
3125 case DW_OP_breg1:
3126 case DW_OP_breg2:
3127 case DW_OP_breg3:
3128 case DW_OP_breg4:
3129 case DW_OP_breg5:
3130 case DW_OP_breg6:
3131 case DW_OP_breg7:
3132 case DW_OP_breg8:
3133 case DW_OP_breg9:
3134 case DW_OP_breg10:
3135 case DW_OP_breg11:
3136 case DW_OP_breg12:
3137 case DW_OP_breg13:
3138 case DW_OP_breg14:
3139 case DW_OP_breg15:
3140 case DW_OP_breg16:
3141 case DW_OP_breg17:
3142 case DW_OP_breg18:
3143 case DW_OP_breg19:
3144 case DW_OP_breg20:
3145 case DW_OP_breg21:
3146 case DW_OP_breg22:
3147 case DW_OP_breg23:
3148 case DW_OP_breg24:
3149 case DW_OP_breg25:
3150 case DW_OP_breg26:
3151 case DW_OP_breg27:
3152 case DW_OP_breg28:
3153 case DW_OP_breg29:
3154 case DW_OP_breg30:
3155 case DW_OP_breg31:
3156 cfa->reg = op - DW_OP_breg0;
3157 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3158 break;
3159 case DW_OP_bregx:
3160 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3161 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3162 break;
3163 case DW_OP_deref:
3164 cfa->indirect = 1;
3165 break;
3166 case DW_OP_plus_uconst:
3167 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3168 break;
3169 default:
3170 internal_error ("DW_LOC_OP %s not implemented\n",
3171 dwarf_stack_op_name (ptr->dw_loc_opc));
3175 #endif /* .debug_frame support */
3177 /* And now, the support for symbolic debugging information. */
3178 #ifdef DWARF2_DEBUGGING_INFO
3180 /* .debug_str support. */
3181 static int output_indirect_string (void **, void *);
3183 static void dwarf2out_init (const char *);
3184 static void dwarf2out_finish (const char *);
3185 static void dwarf2out_define (unsigned int, const char *);
3186 static void dwarf2out_undef (unsigned int, const char *);
3187 static void dwarf2out_start_source_file (unsigned, const char *);
3188 static void dwarf2out_end_source_file (unsigned);
3189 static void dwarf2out_begin_block (unsigned, unsigned);
3190 static void dwarf2out_end_block (unsigned, unsigned);
3191 static bool dwarf2out_ignore_block (tree);
3192 static void dwarf2out_global_decl (tree);
3193 static void dwarf2out_abstract_function (tree);
3195 /* The debug hooks structure. */
3197 const struct gcc_debug_hooks dwarf2_debug_hooks =
3199 dwarf2out_init,
3200 dwarf2out_finish,
3201 dwarf2out_define,
3202 dwarf2out_undef,
3203 dwarf2out_start_source_file,
3204 dwarf2out_end_source_file,
3205 dwarf2out_begin_block,
3206 dwarf2out_end_block,
3207 dwarf2out_ignore_block,
3208 dwarf2out_source_line,
3209 dwarf2out_begin_prologue,
3210 debug_nothing_int_charstar, /* end_prologue */
3211 dwarf2out_end_epilogue,
3212 debug_nothing_tree, /* begin_function */
3213 debug_nothing_int, /* end_function */
3214 dwarf2out_decl, /* function_decl */
3215 dwarf2out_global_decl,
3216 debug_nothing_tree, /* deferred_inline_function */
3217 /* The DWARF 2 backend tries to reduce debugging bloat by not
3218 emitting the abstract description of inline functions until
3219 something tries to reference them. */
3220 dwarf2out_abstract_function, /* outlining_inline_function */
3221 debug_nothing_rtx, /* label */
3222 debug_nothing_int /* handle_pch */
3224 #endif
3226 /* NOTE: In the comments in this file, many references are made to
3227 "Debugging Information Entries". This term is abbreviated as `DIE'
3228 throughout the remainder of this file. */
3230 /* An internal representation of the DWARF output is built, and then
3231 walked to generate the DWARF debugging info. The walk of the internal
3232 representation is done after the entire program has been compiled.
3233 The types below are used to describe the internal representation. */
3235 /* Various DIE's use offsets relative to the beginning of the
3236 .debug_info section to refer to each other. */
3238 typedef long int dw_offset;
3240 /* Define typedefs here to avoid circular dependencies. */
3242 typedef struct dw_attr_struct *dw_attr_ref;
3243 typedef struct dw_line_info_struct *dw_line_info_ref;
3244 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3245 typedef struct pubname_struct *pubname_ref;
3246 typedef struct dw_ranges_struct *dw_ranges_ref;
3248 /* Each entry in the line_info_table maintains the file and
3249 line number associated with the label generated for that
3250 entry. The label gives the PC value associated with
3251 the line number entry. */
3253 typedef struct dw_line_info_struct GTY(())
3255 unsigned long dw_file_num;
3256 unsigned long dw_line_num;
3258 dw_line_info_entry;
3260 /* Line information for functions in separate sections; each one gets its
3261 own sequence. */
3262 typedef struct dw_separate_line_info_struct GTY(())
3264 unsigned long dw_file_num;
3265 unsigned long dw_line_num;
3266 unsigned long function;
3268 dw_separate_line_info_entry;
3270 /* Each DIE attribute has a field specifying the attribute kind,
3271 a link to the next attribute in the chain, and an attribute value.
3272 Attributes are typically linked below the DIE they modify. */
3274 typedef struct dw_attr_struct GTY(())
3276 enum dwarf_attribute dw_attr;
3277 dw_attr_ref dw_attr_next;
3278 dw_val_node dw_attr_val;
3280 dw_attr_node;
3282 /* The Debugging Information Entry (DIE) structure */
3284 typedef struct die_struct GTY(())
3286 enum dwarf_tag die_tag;
3287 char *die_symbol;
3288 dw_attr_ref die_attr;
3289 dw_die_ref die_parent;
3290 dw_die_ref die_child;
3291 dw_die_ref die_sib;
3292 dw_offset die_offset;
3293 unsigned long die_abbrev;
3294 int die_mark;
3296 die_node;
3298 /* The pubname structure */
3300 typedef struct pubname_struct GTY(())
3302 dw_die_ref die;
3303 char *name;
3305 pubname_entry;
3307 struct dw_ranges_struct GTY(())
3309 int block_num;
3312 /* The limbo die list structure. */
3313 typedef struct limbo_die_struct GTY(())
3315 dw_die_ref die;
3316 tree created_for;
3317 struct limbo_die_struct *next;
3319 limbo_die_node;
3321 /* How to start an assembler comment. */
3322 #ifndef ASM_COMMENT_START
3323 #define ASM_COMMENT_START ";#"
3324 #endif
3326 /* Define a macro which returns nonzero for a TYPE_DECL which was
3327 implicitly generated for a tagged type.
3329 Note that unlike the gcc front end (which generates a NULL named
3330 TYPE_DECL node for each complete tagged type, each array type, and
3331 each function type node created) the g++ front end generates a
3332 _named_ TYPE_DECL node for each tagged type node created.
3333 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3334 generate a DW_TAG_typedef DIE for them. */
3336 #define TYPE_DECL_IS_STUB(decl) \
3337 (DECL_NAME (decl) == NULL_TREE \
3338 || (DECL_ARTIFICIAL (decl) \
3339 && is_tagged_type (TREE_TYPE (decl)) \
3340 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3341 /* This is necessary for stub decls that \
3342 appear in nested inline functions. */ \
3343 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3344 && (decl_ultimate_origin (decl) \
3345 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3347 /* Information concerning the compilation unit's programming
3348 language, and compiler version. */
3350 /* Fixed size portion of the DWARF compilation unit header. */
3351 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3352 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3354 /* Fixed size portion of public names info. */
3355 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3357 /* Fixed size portion of the address range info. */
3358 #define DWARF_ARANGES_HEADER_SIZE \
3359 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3360 DWARF2_ADDR_SIZE * 2) \
3361 - DWARF_INITIAL_LENGTH_SIZE)
3363 /* Size of padding portion in the address range info. It must be
3364 aligned to twice the pointer size. */
3365 #define DWARF_ARANGES_PAD_SIZE \
3366 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3367 DWARF2_ADDR_SIZE * 2) \
3368 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3370 /* Use assembler line directives if available. */
3371 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3372 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3373 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3374 #else
3375 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3376 #endif
3377 #endif
3379 /* Minimum line offset in a special line info. opcode.
3380 This value was chosen to give a reasonable range of values. */
3381 #define DWARF_LINE_BASE -10
3383 /* First special line opcode - leave room for the standard opcodes. */
3384 #define DWARF_LINE_OPCODE_BASE 10
3386 /* Range of line offsets in a special line info. opcode. */
3387 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3389 /* Flag that indicates the initial value of the is_stmt_start flag.
3390 In the present implementation, we do not mark any lines as
3391 the beginning of a source statement, because that information
3392 is not made available by the GCC front-end. */
3393 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3395 #ifdef DWARF2_DEBUGGING_INFO
3396 /* This location is used by calc_die_sizes() to keep track
3397 the offset of each DIE within the .debug_info section. */
3398 static unsigned long next_die_offset;
3399 #endif
3401 /* Record the root of the DIE's built for the current compilation unit. */
3402 static GTY(()) dw_die_ref comp_unit_die;
3404 #ifdef DWARF2_DEBUGGING_INFO
3405 /* We need special handling in dwarf2out_start_source_file if it is
3406 first one. */
3407 static int is_main_source;
3408 #endif
3410 /* A list of DIEs with a NULL parent waiting to be relocated. */
3411 static GTY(()) limbo_die_node *limbo_die_list;
3413 /* Filenames referenced by this compilation unit. */
3414 static GTY(()) varray_type file_table;
3415 static GTY(()) varray_type file_table_emitted;
3416 static GTY(()) size_t file_table_last_lookup_index;
3418 /* A pointer to the base of a table of references to DIE's that describe
3419 declarations. The table is indexed by DECL_UID() which is a unique
3420 number identifying each decl. */
3421 static GTY((length ("decl_die_table_allocated"))) dw_die_ref *decl_die_table;
3423 /* Number of elements currently allocated for the decl_die_table. */
3424 static GTY(()) unsigned decl_die_table_allocated;
3426 /* Number of elements in decl_die_table currently in use. */
3427 static GTY(()) unsigned decl_die_table_in_use;
3429 /* Size (in elements) of increments by which we may expand the
3430 decl_die_table. */
3431 #define DECL_DIE_TABLE_INCREMENT 256
3433 /* A pointer to the base of a list of references to DIE's that
3434 are uniquely identified by their tag, presence/absence of
3435 children DIE's, and list of attribute/value pairs. */
3436 static GTY((length ("abbrev_die_table_allocated")))
3437 dw_die_ref *abbrev_die_table;
3439 /* Number of elements currently allocated for abbrev_die_table. */
3440 static GTY(()) unsigned abbrev_die_table_allocated;
3442 /* Number of elements in type_die_table currently in use. */
3443 static GTY(()) unsigned abbrev_die_table_in_use;
3445 /* Size (in elements) of increments by which we may expand the
3446 abbrev_die_table. */
3447 #define ABBREV_DIE_TABLE_INCREMENT 256
3449 /* A pointer to the base of a table that contains line information
3450 for each source code line in .text in the compilation unit. */
3451 static GTY((length ("line_info_table_allocated")))
3452 dw_line_info_ref line_info_table;
3454 /* Number of elements currently allocated for line_info_table. */
3455 static GTY(()) unsigned line_info_table_allocated;
3457 /* Number of elements in line_info_table currently in use. */
3458 static GTY(()) unsigned line_info_table_in_use;
3460 /* A pointer to the base of a table that contains line information
3461 for each source code line outside of .text in the compilation unit. */
3462 static GTY ((length ("separate_line_info_table_allocated")))
3463 dw_separate_line_info_ref separate_line_info_table;
3465 /* Number of elements currently allocated for separate_line_info_table. */
3466 static GTY(()) unsigned separate_line_info_table_allocated;
3468 /* Number of elements in separate_line_info_table currently in use. */
3469 static GTY(()) unsigned separate_line_info_table_in_use;
3471 /* Size (in elements) of increments by which we may expand the
3472 line_info_table. */
3473 #define LINE_INFO_TABLE_INCREMENT 1024
3475 /* A pointer to the base of a table that contains a list of publicly
3476 accessible names. */
3477 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table;
3479 /* Number of elements currently allocated for pubname_table. */
3480 static GTY(()) unsigned pubname_table_allocated;
3482 /* Number of elements in pubname_table currently in use. */
3483 static GTY(()) unsigned pubname_table_in_use;
3485 /* Size (in elements) of increments by which we may expand the
3486 pubname_table. */
3487 #define PUBNAME_TABLE_INCREMENT 64
3489 /* Array of dies for which we should generate .debug_arange info. */
3490 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
3492 /* Number of elements currently allocated for arange_table. */
3493 static GTY(()) unsigned arange_table_allocated;
3495 /* Number of elements in arange_table currently in use. */
3496 static GTY(()) unsigned arange_table_in_use;
3498 /* Size (in elements) of increments by which we may expand the
3499 arange_table. */
3500 #define ARANGE_TABLE_INCREMENT 64
3502 /* Array of dies for which we should generate .debug_ranges info. */
3503 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3505 /* Number of elements currently allocated for ranges_table. */
3506 static GTY(()) unsigned ranges_table_allocated;
3508 /* Number of elements in ranges_table currently in use. */
3509 static GTY(()) unsigned ranges_table_in_use;
3511 /* Size (in elements) of increments by which we may expand the
3512 ranges_table. */
3513 #define RANGES_TABLE_INCREMENT 64
3515 /* Whether we have location lists that need outputting */
3516 static GTY(()) unsigned have_location_lists;
3518 #ifdef DWARF2_DEBUGGING_INFO
3519 /* Record whether the function being analyzed contains inlined functions. */
3520 static int current_function_has_inlines;
3521 #endif
3522 #if 0 && defined (MIPS_DEBUGGING_INFO)
3523 static int comp_unit_has_inlines;
3524 #endif
3526 /* Number of file tables emited in maybe_emit_file(). */
3527 static GTY(()) int emitcount = 0;
3529 /* Number of internal labels generated by gen_internal_sym(). */
3530 static GTY(()) int label_num;
3532 #ifdef DWARF2_DEBUGGING_INFO
3534 /* Forward declarations for functions defined in this file. */
3536 static int is_pseudo_reg (rtx);
3537 static tree type_main_variant (tree);
3538 static int is_tagged_type (tree);
3539 static const char *dwarf_tag_name (unsigned);
3540 static const char *dwarf_attr_name (unsigned);
3541 static const char *dwarf_form_name (unsigned);
3542 #if 0
3543 static const char *dwarf_type_encoding_name (unsigned);
3544 #endif
3545 static tree decl_ultimate_origin (tree);
3546 static tree block_ultimate_origin (tree);
3547 static tree decl_class_context (tree);
3548 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3549 static inline enum dw_val_class AT_class (dw_attr_ref);
3550 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3551 static inline unsigned AT_flag (dw_attr_ref);
3552 static void add_AT_int (dw_die_ref, enum dwarf_attribute, long);
3553 static inline long int AT_int (dw_attr_ref);
3554 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned long);
3555 static inline unsigned long AT_unsigned (dw_attr_ref);
3556 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
3557 unsigned long);
3558 static void add_AT_float (dw_die_ref, enum dwarf_attribute, unsigned, long *);
3559 static hashval_t debug_str_do_hash (const void *);
3560 static int debug_str_eq (const void *, const void *);
3561 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3562 static inline const char *AT_string (dw_attr_ref);
3563 static int AT_string_form (dw_attr_ref);
3564 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3565 static inline dw_die_ref AT_ref (dw_attr_ref);
3566 static inline int AT_ref_external (dw_attr_ref);
3567 static inline void set_AT_ref_external (dw_attr_ref, int);
3568 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3569 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3570 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3571 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3572 dw_loc_list_ref);
3573 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3574 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3575 static inline rtx AT_addr (dw_attr_ref);
3576 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3577 static void add_AT_lbl_offset (dw_die_ref, enum dwarf_attribute, const char *);
3578 static void add_AT_offset (dw_die_ref, enum dwarf_attribute, unsigned long);
3579 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3580 unsigned long);
3581 static inline const char *AT_lbl (dw_attr_ref);
3582 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3583 static const char *get_AT_low_pc (dw_die_ref);
3584 static const char *get_AT_hi_pc (dw_die_ref);
3585 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3586 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3587 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3588 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3589 static bool is_c_family (void);
3590 static bool is_cxx (void);
3591 static bool is_java (void);
3592 static bool is_fortran (void);
3593 static bool is_ada (void);
3594 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3595 static inline void free_die (dw_die_ref);
3596 static void remove_children (dw_die_ref);
3597 static void add_child_die (dw_die_ref, dw_die_ref);
3598 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3599 static dw_die_ref lookup_type_die (tree);
3600 static void equate_type_number_to_die (tree, dw_die_ref);
3601 static dw_die_ref lookup_decl_die (tree);
3602 static void equate_decl_number_to_die (tree, dw_die_ref);
3603 static void print_spaces (FILE *);
3604 static void print_die (dw_die_ref, FILE *);
3605 static void print_dwarf_line_table (FILE *);
3606 static void reverse_die_lists (dw_die_ref);
3607 static void reverse_all_dies (dw_die_ref);
3608 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3609 static dw_die_ref pop_compile_unit (dw_die_ref);
3610 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3611 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3612 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3613 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3614 static int same_dw_val_p (dw_val_node *, dw_val_node *, int *);
3615 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3616 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3617 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3618 static void compute_section_prefix (dw_die_ref);
3619 static int is_type_die (dw_die_ref);
3620 static int is_comdat_die (dw_die_ref);
3621 static int is_symbol_die (dw_die_ref);
3622 static void assign_symbol_names (dw_die_ref);
3623 static void break_out_includes (dw_die_ref);
3624 static hashval_t htab_cu_hash (const void *);
3625 static int htab_cu_eq (const void *, const void *);
3626 static void htab_cu_del (void *);
3627 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3628 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3629 static void add_sibling_attributes (dw_die_ref);
3630 static void build_abbrev_table (dw_die_ref);
3631 static void output_location_lists (dw_die_ref);
3632 static int constant_size (long unsigned);
3633 static unsigned long size_of_die (dw_die_ref);
3634 static void calc_die_sizes (dw_die_ref);
3635 static void mark_dies (dw_die_ref);
3636 static void unmark_dies (dw_die_ref);
3637 static void unmark_all_dies (dw_die_ref);
3638 static unsigned long size_of_pubnames (void);
3639 static unsigned long size_of_aranges (void);
3640 static enum dwarf_form value_format (dw_attr_ref);
3641 static void output_value_format (dw_attr_ref);
3642 static void output_abbrev_section (void);
3643 static void output_die_symbol (dw_die_ref);
3644 static void output_die (dw_die_ref);
3645 static void output_compilation_unit_header (void);
3646 static void output_comp_unit (dw_die_ref, int);
3647 static const char *dwarf2_name (tree, int);
3648 static void add_pubname (tree, dw_die_ref);
3649 static void output_pubnames (void);
3650 static void add_arange (tree, dw_die_ref);
3651 static void output_aranges (void);
3652 static unsigned int add_ranges (tree);
3653 static void output_ranges (void);
3654 static void output_line_info (void);
3655 static void output_file_names (void);
3656 static dw_die_ref base_type_die (tree);
3657 static tree root_type (tree);
3658 static int is_base_type (tree);
3659 static bool is_ada_subrange_type (tree);
3660 static dw_die_ref subrange_type_die (tree);
3661 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
3662 static int type_is_enum (tree);
3663 static unsigned int reg_number (rtx);
3664 static dw_loc_descr_ref reg_loc_descriptor (rtx);
3665 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int);
3666 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx);
3667 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3668 static dw_loc_descr_ref based_loc_descr (unsigned, long);
3669 static int is_based_loc (rtx);
3670 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode);
3671 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx);
3672 static dw_loc_descr_ref loc_descriptor (rtx);
3673 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
3674 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3675 static tree field_type (tree);
3676 static unsigned int simple_type_align_in_bits (tree);
3677 static unsigned int simple_decl_align_in_bits (tree);
3678 static unsigned HOST_WIDE_INT simple_type_size_in_bits (tree);
3679 static HOST_WIDE_INT field_byte_offset (tree);
3680 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3681 dw_loc_descr_ref);
3682 static void add_data_member_location_attribute (dw_die_ref, tree);
3683 static void add_const_value_attribute (dw_die_ref, rtx);
3684 static rtx rtl_for_decl_location (tree);
3685 static void add_location_or_const_value_attribute (dw_die_ref, tree);
3686 static void tree_add_const_value_attribute (dw_die_ref, tree);
3687 static void add_name_attribute (dw_die_ref, const char *);
3688 static void add_comp_dir_attribute (dw_die_ref);
3689 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
3690 static void add_subscript_info (dw_die_ref, tree);
3691 static void add_byte_size_attribute (dw_die_ref, tree);
3692 static void add_bit_offset_attribute (dw_die_ref, tree);
3693 static void add_bit_size_attribute (dw_die_ref, tree);
3694 static void add_prototyped_attribute (dw_die_ref, tree);
3695 static void add_abstract_origin_attribute (dw_die_ref, tree);
3696 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3697 static void add_src_coords_attributes (dw_die_ref, tree);
3698 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3699 static void push_decl_scope (tree);
3700 static void pop_decl_scope (void);
3701 static dw_die_ref scope_die_for (tree, dw_die_ref);
3702 static inline int local_scope_p (dw_die_ref);
3703 static inline int class_scope_p (dw_die_ref);
3704 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
3705 static const char *type_tag (tree);
3706 static tree member_declared_type (tree);
3707 #if 0
3708 static const char *decl_start_label (tree);
3709 #endif
3710 static void gen_array_type_die (tree, dw_die_ref);
3711 static void gen_set_type_die (tree, dw_die_ref);
3712 #if 0
3713 static void gen_entry_point_die (tree, dw_die_ref);
3714 #endif
3715 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
3716 static void gen_inlined_structure_type_die (tree, dw_die_ref);
3717 static void gen_inlined_union_type_die (tree, dw_die_ref);
3718 static void gen_enumeration_type_die (tree, dw_die_ref);
3719 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
3720 static void gen_unspecified_parameters_die (tree, dw_die_ref);
3721 static void gen_formal_types_die (tree, dw_die_ref);
3722 static void gen_subprogram_die (tree, dw_die_ref);
3723 static void gen_variable_die (tree, dw_die_ref);
3724 static void gen_label_die (tree, dw_die_ref);
3725 static void gen_lexical_block_die (tree, dw_die_ref, int);
3726 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
3727 static void gen_field_die (tree, dw_die_ref);
3728 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3729 static dw_die_ref gen_compile_unit_die (const char *);
3730 static void gen_string_type_die (tree, dw_die_ref);
3731 static void gen_inheritance_die (tree, tree, dw_die_ref);
3732 static void gen_member_die (tree, dw_die_ref);
3733 static void gen_struct_or_union_type_die (tree, dw_die_ref);
3734 static void gen_subroutine_type_die (tree, dw_die_ref);
3735 static void gen_typedef_die (tree, dw_die_ref);
3736 static void gen_type_die (tree, dw_die_ref);
3737 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
3738 static void gen_block_die (tree, dw_die_ref, int);
3739 static void decls_for_scope (tree, dw_die_ref, int);
3740 static int is_redundant_typedef (tree);
3741 static void gen_decl_die (tree, dw_die_ref);
3742 static unsigned lookup_filename (const char *);
3743 static void init_file_table (void);
3744 static void retry_incomplete_types (void);
3745 static void gen_type_die_for_member (tree, tree, dw_die_ref);
3746 static void splice_child_die (dw_die_ref, dw_die_ref);
3747 static int file_info_cmp (const void *, const void *);
3748 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
3749 const char *, const char *, unsigned);
3750 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
3751 const char *, const char *,
3752 const char *);
3753 static void output_loc_list (dw_loc_list_ref);
3754 static char *gen_internal_sym (const char *);
3756 static void prune_unmark_dies (dw_die_ref);
3757 static void prune_unused_types_mark (dw_die_ref, int);
3758 static void prune_unused_types_walk (dw_die_ref);
3759 static void prune_unused_types_walk_attribs (dw_die_ref);
3760 static void prune_unused_types_prune (dw_die_ref);
3761 static void prune_unused_types (void);
3762 static int maybe_emit_file (int);
3764 /* Section names used to hold DWARF debugging information. */
3765 #ifndef DEBUG_INFO_SECTION
3766 #define DEBUG_INFO_SECTION ".debug_info"
3767 #endif
3768 #ifndef DEBUG_ABBREV_SECTION
3769 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3770 #endif
3771 #ifndef DEBUG_ARANGES_SECTION
3772 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3773 #endif
3774 #ifndef DEBUG_MACINFO_SECTION
3775 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3776 #endif
3777 #ifndef DEBUG_LINE_SECTION
3778 #define DEBUG_LINE_SECTION ".debug_line"
3779 #endif
3780 #ifndef DEBUG_LOC_SECTION
3781 #define DEBUG_LOC_SECTION ".debug_loc"
3782 #endif
3783 #ifndef DEBUG_PUBNAMES_SECTION
3784 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3785 #endif
3786 #ifndef DEBUG_STR_SECTION
3787 #define DEBUG_STR_SECTION ".debug_str"
3788 #endif
3789 #ifndef DEBUG_RANGES_SECTION
3790 #define DEBUG_RANGES_SECTION ".debug_ranges"
3791 #endif
3793 /* Standard ELF section names for compiled code and data. */
3794 #ifndef TEXT_SECTION_NAME
3795 #define TEXT_SECTION_NAME ".text"
3796 #endif
3798 /* Section flags for .debug_str section. */
3799 #ifdef HAVE_GAS_SHF_MERGE
3800 #define DEBUG_STR_SECTION_FLAGS \
3801 (flag_merge_constants \
3802 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3803 : SECTION_DEBUG)
3804 #else
3805 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3806 #endif
3808 /* Labels we insert at beginning sections we can reference instead of
3809 the section names themselves. */
3811 #ifndef TEXT_SECTION_LABEL
3812 #define TEXT_SECTION_LABEL "Ltext"
3813 #endif
3814 #ifndef DEBUG_LINE_SECTION_LABEL
3815 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3816 #endif
3817 #ifndef DEBUG_INFO_SECTION_LABEL
3818 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3819 #endif
3820 #ifndef DEBUG_ABBREV_SECTION_LABEL
3821 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3822 #endif
3823 #ifndef DEBUG_LOC_SECTION_LABEL
3824 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3825 #endif
3826 #ifndef DEBUG_RANGES_SECTION_LABEL
3827 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3828 #endif
3829 #ifndef DEBUG_MACINFO_SECTION_LABEL
3830 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3831 #endif
3833 /* Definitions of defaults for formats and names of various special
3834 (artificial) labels which may be generated within this file (when the -g
3835 options is used and DWARF_DEBUGGING_INFO is in effect.
3836 If necessary, these may be overridden from within the tm.h file, but
3837 typically, overriding these defaults is unnecessary. */
3839 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3840 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3841 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3842 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3843 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3844 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3845 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3846 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3848 #ifndef TEXT_END_LABEL
3849 #define TEXT_END_LABEL "Letext"
3850 #endif
3851 #ifndef BLOCK_BEGIN_LABEL
3852 #define BLOCK_BEGIN_LABEL "LBB"
3853 #endif
3854 #ifndef BLOCK_END_LABEL
3855 #define BLOCK_END_LABEL "LBE"
3856 #endif
3857 #ifndef LINE_CODE_LABEL
3858 #define LINE_CODE_LABEL "LM"
3859 #endif
3860 #ifndef SEPARATE_LINE_CODE_LABEL
3861 #define SEPARATE_LINE_CODE_LABEL "LSM"
3862 #endif
3864 /* We allow a language front-end to designate a function that is to be
3865 called to "demangle" any name before it it put into a DIE. */
3867 static const char *(*demangle_name_func) (const char *);
3869 void
3870 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
3872 demangle_name_func = func;
3875 /* Test if rtl node points to a pseudo register. */
3877 static inline int
3878 is_pseudo_reg (rtx rtl)
3880 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3881 || (GET_CODE (rtl) == SUBREG
3882 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3885 /* Return a reference to a type, with its const and volatile qualifiers
3886 removed. */
3888 static inline tree
3889 type_main_variant (tree type)
3891 type = TYPE_MAIN_VARIANT (type);
3893 /* ??? There really should be only one main variant among any group of
3894 variants of a given type (and all of the MAIN_VARIANT values for all
3895 members of the group should point to that one type) but sometimes the C
3896 front-end messes this up for array types, so we work around that bug
3897 here. */
3898 if (TREE_CODE (type) == ARRAY_TYPE)
3899 while (type != TYPE_MAIN_VARIANT (type))
3900 type = TYPE_MAIN_VARIANT (type);
3902 return type;
3905 /* Return nonzero if the given type node represents a tagged type. */
3907 static inline int
3908 is_tagged_type (tree type)
3910 enum tree_code code = TREE_CODE (type);
3912 return (code == RECORD_TYPE || code == UNION_TYPE
3913 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3916 /* Convert a DIE tag into its string name. */
3918 static const char *
3919 dwarf_tag_name (unsigned int tag)
3921 switch (tag)
3923 case DW_TAG_padding:
3924 return "DW_TAG_padding";
3925 case DW_TAG_array_type:
3926 return "DW_TAG_array_type";
3927 case DW_TAG_class_type:
3928 return "DW_TAG_class_type";
3929 case DW_TAG_entry_point:
3930 return "DW_TAG_entry_point";
3931 case DW_TAG_enumeration_type:
3932 return "DW_TAG_enumeration_type";
3933 case DW_TAG_formal_parameter:
3934 return "DW_TAG_formal_parameter";
3935 case DW_TAG_imported_declaration:
3936 return "DW_TAG_imported_declaration";
3937 case DW_TAG_label:
3938 return "DW_TAG_label";
3939 case DW_TAG_lexical_block:
3940 return "DW_TAG_lexical_block";
3941 case DW_TAG_member:
3942 return "DW_TAG_member";
3943 case DW_TAG_pointer_type:
3944 return "DW_TAG_pointer_type";
3945 case DW_TAG_reference_type:
3946 return "DW_TAG_reference_type";
3947 case DW_TAG_compile_unit:
3948 return "DW_TAG_compile_unit";
3949 case DW_TAG_string_type:
3950 return "DW_TAG_string_type";
3951 case DW_TAG_structure_type:
3952 return "DW_TAG_structure_type";
3953 case DW_TAG_subroutine_type:
3954 return "DW_TAG_subroutine_type";
3955 case DW_TAG_typedef:
3956 return "DW_TAG_typedef";
3957 case DW_TAG_union_type:
3958 return "DW_TAG_union_type";
3959 case DW_TAG_unspecified_parameters:
3960 return "DW_TAG_unspecified_parameters";
3961 case DW_TAG_variant:
3962 return "DW_TAG_variant";
3963 case DW_TAG_common_block:
3964 return "DW_TAG_common_block";
3965 case DW_TAG_common_inclusion:
3966 return "DW_TAG_common_inclusion";
3967 case DW_TAG_inheritance:
3968 return "DW_TAG_inheritance";
3969 case DW_TAG_inlined_subroutine:
3970 return "DW_TAG_inlined_subroutine";
3971 case DW_TAG_module:
3972 return "DW_TAG_module";
3973 case DW_TAG_ptr_to_member_type:
3974 return "DW_TAG_ptr_to_member_type";
3975 case DW_TAG_set_type:
3976 return "DW_TAG_set_type";
3977 case DW_TAG_subrange_type:
3978 return "DW_TAG_subrange_type";
3979 case DW_TAG_with_stmt:
3980 return "DW_TAG_with_stmt";
3981 case DW_TAG_access_declaration:
3982 return "DW_TAG_access_declaration";
3983 case DW_TAG_base_type:
3984 return "DW_TAG_base_type";
3985 case DW_TAG_catch_block:
3986 return "DW_TAG_catch_block";
3987 case DW_TAG_const_type:
3988 return "DW_TAG_const_type";
3989 case DW_TAG_constant:
3990 return "DW_TAG_constant";
3991 case DW_TAG_enumerator:
3992 return "DW_TAG_enumerator";
3993 case DW_TAG_file_type:
3994 return "DW_TAG_file_type";
3995 case DW_TAG_friend:
3996 return "DW_TAG_friend";
3997 case DW_TAG_namelist:
3998 return "DW_TAG_namelist";
3999 case DW_TAG_namelist_item:
4000 return "DW_TAG_namelist_item";
4001 case DW_TAG_packed_type:
4002 return "DW_TAG_packed_type";
4003 case DW_TAG_subprogram:
4004 return "DW_TAG_subprogram";
4005 case DW_TAG_template_type_param:
4006 return "DW_TAG_template_type_param";
4007 case DW_TAG_template_value_param:
4008 return "DW_TAG_template_value_param";
4009 case DW_TAG_thrown_type:
4010 return "DW_TAG_thrown_type";
4011 case DW_TAG_try_block:
4012 return "DW_TAG_try_block";
4013 case DW_TAG_variant_part:
4014 return "DW_TAG_variant_part";
4015 case DW_TAG_variable:
4016 return "DW_TAG_variable";
4017 case DW_TAG_volatile_type:
4018 return "DW_TAG_volatile_type";
4019 case DW_TAG_MIPS_loop:
4020 return "DW_TAG_MIPS_loop";
4021 case DW_TAG_format_label:
4022 return "DW_TAG_format_label";
4023 case DW_TAG_function_template:
4024 return "DW_TAG_function_template";
4025 case DW_TAG_class_template:
4026 return "DW_TAG_class_template";
4027 case DW_TAG_GNU_BINCL:
4028 return "DW_TAG_GNU_BINCL";
4029 case DW_TAG_GNU_EINCL:
4030 return "DW_TAG_GNU_EINCL";
4031 default:
4032 return "DW_TAG_<unknown>";
4036 /* Convert a DWARF attribute code into its string name. */
4038 static const char *
4039 dwarf_attr_name (unsigned int attr)
4041 switch (attr)
4043 case DW_AT_sibling:
4044 return "DW_AT_sibling";
4045 case DW_AT_location:
4046 return "DW_AT_location";
4047 case DW_AT_name:
4048 return "DW_AT_name";
4049 case DW_AT_ordering:
4050 return "DW_AT_ordering";
4051 case DW_AT_subscr_data:
4052 return "DW_AT_subscr_data";
4053 case DW_AT_byte_size:
4054 return "DW_AT_byte_size";
4055 case DW_AT_bit_offset:
4056 return "DW_AT_bit_offset";
4057 case DW_AT_bit_size:
4058 return "DW_AT_bit_size";
4059 case DW_AT_element_list:
4060 return "DW_AT_element_list";
4061 case DW_AT_stmt_list:
4062 return "DW_AT_stmt_list";
4063 case DW_AT_low_pc:
4064 return "DW_AT_low_pc";
4065 case DW_AT_high_pc:
4066 return "DW_AT_high_pc";
4067 case DW_AT_language:
4068 return "DW_AT_language";
4069 case DW_AT_member:
4070 return "DW_AT_member";
4071 case DW_AT_discr:
4072 return "DW_AT_discr";
4073 case DW_AT_discr_value:
4074 return "DW_AT_discr_value";
4075 case DW_AT_visibility:
4076 return "DW_AT_visibility";
4077 case DW_AT_import:
4078 return "DW_AT_import";
4079 case DW_AT_string_length:
4080 return "DW_AT_string_length";
4081 case DW_AT_common_reference:
4082 return "DW_AT_common_reference";
4083 case DW_AT_comp_dir:
4084 return "DW_AT_comp_dir";
4085 case DW_AT_const_value:
4086 return "DW_AT_const_value";
4087 case DW_AT_containing_type:
4088 return "DW_AT_containing_type";
4089 case DW_AT_default_value:
4090 return "DW_AT_default_value";
4091 case DW_AT_inline:
4092 return "DW_AT_inline";
4093 case DW_AT_is_optional:
4094 return "DW_AT_is_optional";
4095 case DW_AT_lower_bound:
4096 return "DW_AT_lower_bound";
4097 case DW_AT_producer:
4098 return "DW_AT_producer";
4099 case DW_AT_prototyped:
4100 return "DW_AT_prototyped";
4101 case DW_AT_return_addr:
4102 return "DW_AT_return_addr";
4103 case DW_AT_start_scope:
4104 return "DW_AT_start_scope";
4105 case DW_AT_stride_size:
4106 return "DW_AT_stride_size";
4107 case DW_AT_upper_bound:
4108 return "DW_AT_upper_bound";
4109 case DW_AT_abstract_origin:
4110 return "DW_AT_abstract_origin";
4111 case DW_AT_accessibility:
4112 return "DW_AT_accessibility";
4113 case DW_AT_address_class:
4114 return "DW_AT_address_class";
4115 case DW_AT_artificial:
4116 return "DW_AT_artificial";
4117 case DW_AT_base_types:
4118 return "DW_AT_base_types";
4119 case DW_AT_calling_convention:
4120 return "DW_AT_calling_convention";
4121 case DW_AT_count:
4122 return "DW_AT_count";
4123 case DW_AT_data_member_location:
4124 return "DW_AT_data_member_location";
4125 case DW_AT_decl_column:
4126 return "DW_AT_decl_column";
4127 case DW_AT_decl_file:
4128 return "DW_AT_decl_file";
4129 case DW_AT_decl_line:
4130 return "DW_AT_decl_line";
4131 case DW_AT_declaration:
4132 return "DW_AT_declaration";
4133 case DW_AT_discr_list:
4134 return "DW_AT_discr_list";
4135 case DW_AT_encoding:
4136 return "DW_AT_encoding";
4137 case DW_AT_external:
4138 return "DW_AT_external";
4139 case DW_AT_frame_base:
4140 return "DW_AT_frame_base";
4141 case DW_AT_friend:
4142 return "DW_AT_friend";
4143 case DW_AT_identifier_case:
4144 return "DW_AT_identifier_case";
4145 case DW_AT_macro_info:
4146 return "DW_AT_macro_info";
4147 case DW_AT_namelist_items:
4148 return "DW_AT_namelist_items";
4149 case DW_AT_priority:
4150 return "DW_AT_priority";
4151 case DW_AT_segment:
4152 return "DW_AT_segment";
4153 case DW_AT_specification:
4154 return "DW_AT_specification";
4155 case DW_AT_static_link:
4156 return "DW_AT_static_link";
4157 case DW_AT_type:
4158 return "DW_AT_type";
4159 case DW_AT_use_location:
4160 return "DW_AT_use_location";
4161 case DW_AT_variable_parameter:
4162 return "DW_AT_variable_parameter";
4163 case DW_AT_virtuality:
4164 return "DW_AT_virtuality";
4165 case DW_AT_vtable_elem_location:
4166 return "DW_AT_vtable_elem_location";
4168 case DW_AT_allocated:
4169 return "DW_AT_allocated";
4170 case DW_AT_associated:
4171 return "DW_AT_associated";
4172 case DW_AT_data_location:
4173 return "DW_AT_data_location";
4174 case DW_AT_stride:
4175 return "DW_AT_stride";
4176 case DW_AT_entry_pc:
4177 return "DW_AT_entry_pc";
4178 case DW_AT_use_UTF8:
4179 return "DW_AT_use_UTF8";
4180 case DW_AT_extension:
4181 return "DW_AT_extension";
4182 case DW_AT_ranges:
4183 return "DW_AT_ranges";
4184 case DW_AT_trampoline:
4185 return "DW_AT_trampoline";
4186 case DW_AT_call_column:
4187 return "DW_AT_call_column";
4188 case DW_AT_call_file:
4189 return "DW_AT_call_file";
4190 case DW_AT_call_line:
4191 return "DW_AT_call_line";
4193 case DW_AT_MIPS_fde:
4194 return "DW_AT_MIPS_fde";
4195 case DW_AT_MIPS_loop_begin:
4196 return "DW_AT_MIPS_loop_begin";
4197 case DW_AT_MIPS_tail_loop_begin:
4198 return "DW_AT_MIPS_tail_loop_begin";
4199 case DW_AT_MIPS_epilog_begin:
4200 return "DW_AT_MIPS_epilog_begin";
4201 case DW_AT_MIPS_loop_unroll_factor:
4202 return "DW_AT_MIPS_loop_unroll_factor";
4203 case DW_AT_MIPS_software_pipeline_depth:
4204 return "DW_AT_MIPS_software_pipeline_depth";
4205 case DW_AT_MIPS_linkage_name:
4206 return "DW_AT_MIPS_linkage_name";
4207 case DW_AT_MIPS_stride:
4208 return "DW_AT_MIPS_stride";
4209 case DW_AT_MIPS_abstract_name:
4210 return "DW_AT_MIPS_abstract_name";
4211 case DW_AT_MIPS_clone_origin:
4212 return "DW_AT_MIPS_clone_origin";
4213 case DW_AT_MIPS_has_inlines:
4214 return "DW_AT_MIPS_has_inlines";
4216 case DW_AT_sf_names:
4217 return "DW_AT_sf_names";
4218 case DW_AT_src_info:
4219 return "DW_AT_src_info";
4220 case DW_AT_mac_info:
4221 return "DW_AT_mac_info";
4222 case DW_AT_src_coords:
4223 return "DW_AT_src_coords";
4224 case DW_AT_body_begin:
4225 return "DW_AT_body_begin";
4226 case DW_AT_body_end:
4227 return "DW_AT_body_end";
4228 case DW_AT_GNU_vector:
4229 return "DW_AT_GNU_vector";
4231 case DW_AT_VMS_rtnbeg_pd_address:
4232 return "DW_AT_VMS_rtnbeg_pd_address";
4234 default:
4235 return "DW_AT_<unknown>";
4239 /* Convert a DWARF value form code into its string name. */
4241 static const char *
4242 dwarf_form_name (unsigned int form)
4244 switch (form)
4246 case DW_FORM_addr:
4247 return "DW_FORM_addr";
4248 case DW_FORM_block2:
4249 return "DW_FORM_block2";
4250 case DW_FORM_block4:
4251 return "DW_FORM_block4";
4252 case DW_FORM_data2:
4253 return "DW_FORM_data2";
4254 case DW_FORM_data4:
4255 return "DW_FORM_data4";
4256 case DW_FORM_data8:
4257 return "DW_FORM_data8";
4258 case DW_FORM_string:
4259 return "DW_FORM_string";
4260 case DW_FORM_block:
4261 return "DW_FORM_block";
4262 case DW_FORM_block1:
4263 return "DW_FORM_block1";
4264 case DW_FORM_data1:
4265 return "DW_FORM_data1";
4266 case DW_FORM_flag:
4267 return "DW_FORM_flag";
4268 case DW_FORM_sdata:
4269 return "DW_FORM_sdata";
4270 case DW_FORM_strp:
4271 return "DW_FORM_strp";
4272 case DW_FORM_udata:
4273 return "DW_FORM_udata";
4274 case DW_FORM_ref_addr:
4275 return "DW_FORM_ref_addr";
4276 case DW_FORM_ref1:
4277 return "DW_FORM_ref1";
4278 case DW_FORM_ref2:
4279 return "DW_FORM_ref2";
4280 case DW_FORM_ref4:
4281 return "DW_FORM_ref4";
4282 case DW_FORM_ref8:
4283 return "DW_FORM_ref8";
4284 case DW_FORM_ref_udata:
4285 return "DW_FORM_ref_udata";
4286 case DW_FORM_indirect:
4287 return "DW_FORM_indirect";
4288 default:
4289 return "DW_FORM_<unknown>";
4293 /* Convert a DWARF type code into its string name. */
4295 #if 0
4296 static const char *
4297 dwarf_type_encoding_name (unsigned enc)
4299 switch (enc)
4301 case DW_ATE_address:
4302 return "DW_ATE_address";
4303 case DW_ATE_boolean:
4304 return "DW_ATE_boolean";
4305 case DW_ATE_complex_float:
4306 return "DW_ATE_complex_float";
4307 case DW_ATE_float:
4308 return "DW_ATE_float";
4309 case DW_ATE_signed:
4310 return "DW_ATE_signed";
4311 case DW_ATE_signed_char:
4312 return "DW_ATE_signed_char";
4313 case DW_ATE_unsigned:
4314 return "DW_ATE_unsigned";
4315 case DW_ATE_unsigned_char:
4316 return "DW_ATE_unsigned_char";
4317 default:
4318 return "DW_ATE_<unknown>";
4321 #endif
4323 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4324 instance of an inlined instance of a decl which is local to an inline
4325 function, so we have to trace all of the way back through the origin chain
4326 to find out what sort of node actually served as the original seed for the
4327 given block. */
4329 static tree
4330 decl_ultimate_origin (tree decl)
4332 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4333 nodes in the function to point to themselves; ignore that if
4334 we're trying to output the abstract instance of this function. */
4335 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4336 return NULL_TREE;
4338 #ifdef ENABLE_CHECKING
4339 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4340 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4341 most distant ancestor, this should never happen. */
4342 abort ();
4343 #endif
4345 return DECL_ABSTRACT_ORIGIN (decl);
4348 /* Determine the "ultimate origin" of a block. The block may be an inlined
4349 instance of an inlined instance of a block which is local to an inline
4350 function, so we have to trace all of the way back through the origin chain
4351 to find out what sort of node actually served as the original seed for the
4352 given block. */
4354 static tree
4355 block_ultimate_origin (tree block)
4357 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4359 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4360 nodes in the function to point to themselves; ignore that if
4361 we're trying to output the abstract instance of this function. */
4362 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4363 return NULL_TREE;
4365 if (immediate_origin == NULL_TREE)
4366 return NULL_TREE;
4367 else
4369 tree ret_val;
4370 tree lookahead = immediate_origin;
4374 ret_val = lookahead;
4375 lookahead = (TREE_CODE (ret_val) == BLOCK
4376 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4378 while (lookahead != NULL && lookahead != ret_val);
4380 return ret_val;
4384 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4385 of a virtual function may refer to a base class, so we check the 'this'
4386 parameter. */
4388 static tree
4389 decl_class_context (tree decl)
4391 tree context = NULL_TREE;
4393 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4394 context = DECL_CONTEXT (decl);
4395 else
4396 context = TYPE_MAIN_VARIANT
4397 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4399 if (context && !TYPE_P (context))
4400 context = NULL_TREE;
4402 return context;
4405 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4406 addition order, and correct that in reverse_all_dies. */
4408 static inline void
4409 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4411 if (die != NULL && attr != NULL)
4413 attr->dw_attr_next = die->die_attr;
4414 die->die_attr = attr;
4418 static inline enum dw_val_class
4419 AT_class (dw_attr_ref a)
4421 return a->dw_attr_val.val_class;
4424 /* Add a flag value attribute to a DIE. */
4426 static inline void
4427 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4429 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4431 attr->dw_attr_next = NULL;
4432 attr->dw_attr = attr_kind;
4433 attr->dw_attr_val.val_class = dw_val_class_flag;
4434 attr->dw_attr_val.v.val_flag = flag;
4435 add_dwarf_attr (die, attr);
4438 static inline unsigned
4439 AT_flag (dw_attr_ref a)
4441 if (a && AT_class (a) == dw_val_class_flag)
4442 return a->dw_attr_val.v.val_flag;
4444 abort ();
4447 /* Add a signed integer attribute value to a DIE. */
4449 static inline void
4450 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, long int int_val)
4452 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4454 attr->dw_attr_next = NULL;
4455 attr->dw_attr = attr_kind;
4456 attr->dw_attr_val.val_class = dw_val_class_const;
4457 attr->dw_attr_val.v.val_int = int_val;
4458 add_dwarf_attr (die, attr);
4461 static inline long int
4462 AT_int (dw_attr_ref a)
4464 if (a && AT_class (a) == dw_val_class_const)
4465 return a->dw_attr_val.v.val_int;
4467 abort ();
4470 /* Add an unsigned integer attribute value to a DIE. */
4472 static inline void
4473 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4474 long unsigned int unsigned_val)
4476 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4478 attr->dw_attr_next = NULL;
4479 attr->dw_attr = attr_kind;
4480 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4481 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4482 add_dwarf_attr (die, attr);
4485 static inline unsigned long
4486 AT_unsigned (dw_attr_ref a)
4488 if (a && AT_class (a) == dw_val_class_unsigned_const)
4489 return a->dw_attr_val.v.val_unsigned;
4491 abort ();
4494 /* Add an unsigned double integer attribute value to a DIE. */
4496 static inline void
4497 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
4498 long unsigned int val_hi, long unsigned int val_low)
4500 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4502 attr->dw_attr_next = NULL;
4503 attr->dw_attr = attr_kind;
4504 attr->dw_attr_val.val_class = dw_val_class_long_long;
4505 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4506 attr->dw_attr_val.v.val_long_long.low = val_low;
4507 add_dwarf_attr (die, attr);
4510 /* Add a floating point attribute value to a DIE and return it. */
4512 static inline void
4513 add_AT_float (dw_die_ref die, enum dwarf_attribute attr_kind,
4514 unsigned int length, long int *array)
4516 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4518 attr->dw_attr_next = NULL;
4519 attr->dw_attr = attr_kind;
4520 attr->dw_attr_val.val_class = dw_val_class_float;
4521 attr->dw_attr_val.v.val_float.length = length;
4522 attr->dw_attr_val.v.val_float.array = array;
4523 add_dwarf_attr (die, attr);
4526 /* Hash and equality functions for debug_str_hash. */
4528 static hashval_t
4529 debug_str_do_hash (const void *x)
4531 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4534 static int
4535 debug_str_eq (const void *x1, const void *x2)
4537 return strcmp ((((const struct indirect_string_node *)x1)->str),
4538 (const char *)x2) == 0;
4541 /* Add a string attribute value to a DIE. */
4543 static inline void
4544 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4546 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4547 struct indirect_string_node *node;
4548 void **slot;
4550 if (! debug_str_hash)
4551 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4552 debug_str_eq, NULL);
4554 slot = htab_find_slot_with_hash (debug_str_hash, str,
4555 htab_hash_string (str), INSERT);
4556 if (*slot == NULL)
4557 *slot = ggc_alloc_cleared (sizeof (struct indirect_string_node));
4558 node = (struct indirect_string_node *) *slot;
4559 node->str = ggc_strdup (str);
4560 node->refcount++;
4562 attr->dw_attr_next = NULL;
4563 attr->dw_attr = attr_kind;
4564 attr->dw_attr_val.val_class = dw_val_class_str;
4565 attr->dw_attr_val.v.val_str = node;
4566 add_dwarf_attr (die, attr);
4569 static inline const char *
4570 AT_string (dw_attr_ref a)
4572 if (a && AT_class (a) == dw_val_class_str)
4573 return a->dw_attr_val.v.val_str->str;
4575 abort ();
4578 /* Find out whether a string should be output inline in DIE
4579 or out-of-line in .debug_str section. */
4581 static int
4582 AT_string_form (dw_attr_ref a)
4584 if (a && AT_class (a) == dw_val_class_str)
4586 struct indirect_string_node *node;
4587 unsigned int len;
4588 char label[32];
4590 node = a->dw_attr_val.v.val_str;
4591 if (node->form)
4592 return node->form;
4594 len = strlen (node->str) + 1;
4596 /* If the string is shorter or equal to the size of the reference, it is
4597 always better to put it inline. */
4598 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4599 return node->form = DW_FORM_string;
4601 /* If we cannot expect the linker to merge strings in .debug_str
4602 section, only put it into .debug_str if it is worth even in this
4603 single module. */
4604 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4605 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4606 return node->form = DW_FORM_string;
4608 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4609 ++dw2_string_counter;
4610 node->label = xstrdup (label);
4612 return node->form = DW_FORM_strp;
4615 abort ();
4618 /* Add a DIE reference attribute value to a DIE. */
4620 static inline void
4621 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4623 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4625 attr->dw_attr_next = NULL;
4626 attr->dw_attr = attr_kind;
4627 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4628 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4629 attr->dw_attr_val.v.val_die_ref.external = 0;
4630 add_dwarf_attr (die, attr);
4633 static inline dw_die_ref
4634 AT_ref (dw_attr_ref a)
4636 if (a && AT_class (a) == dw_val_class_die_ref)
4637 return a->dw_attr_val.v.val_die_ref.die;
4639 abort ();
4642 static inline int
4643 AT_ref_external (dw_attr_ref a)
4645 if (a && AT_class (a) == dw_val_class_die_ref)
4646 return a->dw_attr_val.v.val_die_ref.external;
4648 return 0;
4651 static inline void
4652 set_AT_ref_external (dw_attr_ref a, int i)
4654 if (a && AT_class (a) == dw_val_class_die_ref)
4655 a->dw_attr_val.v.val_die_ref.external = i;
4656 else
4657 abort ();
4660 /* Add an FDE reference attribute value to a DIE. */
4662 static inline void
4663 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
4665 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4667 attr->dw_attr_next = NULL;
4668 attr->dw_attr = attr_kind;
4669 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4670 attr->dw_attr_val.v.val_fde_index = targ_fde;
4671 add_dwarf_attr (die, attr);
4674 /* Add a location description attribute value to a DIE. */
4676 static inline void
4677 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4679 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4681 attr->dw_attr_next = NULL;
4682 attr->dw_attr = attr_kind;
4683 attr->dw_attr_val.val_class = dw_val_class_loc;
4684 attr->dw_attr_val.v.val_loc = loc;
4685 add_dwarf_attr (die, attr);
4688 static inline dw_loc_descr_ref
4689 AT_loc (dw_attr_ref a)
4691 if (a && AT_class (a) == dw_val_class_loc)
4692 return a->dw_attr_val.v.val_loc;
4694 abort ();
4697 static inline void
4698 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
4700 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4702 attr->dw_attr_next = NULL;
4703 attr->dw_attr = attr_kind;
4704 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4705 attr->dw_attr_val.v.val_loc_list = loc_list;
4706 add_dwarf_attr (die, attr);
4707 have_location_lists = 1;
4710 static inline dw_loc_list_ref
4711 AT_loc_list (dw_attr_ref a)
4713 if (a && AT_class (a) == dw_val_class_loc_list)
4714 return a->dw_attr_val.v.val_loc_list;
4716 abort ();
4719 /* Add an address constant attribute value to a DIE. */
4721 static inline void
4722 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
4724 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4726 attr->dw_attr_next = NULL;
4727 attr->dw_attr = attr_kind;
4728 attr->dw_attr_val.val_class = dw_val_class_addr;
4729 attr->dw_attr_val.v.val_addr = addr;
4730 add_dwarf_attr (die, attr);
4733 static inline rtx
4734 AT_addr (dw_attr_ref a)
4736 if (a && AT_class (a) == dw_val_class_addr)
4737 return a->dw_attr_val.v.val_addr;
4739 abort ();
4742 /* Add a label identifier attribute value to a DIE. */
4744 static inline void
4745 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
4747 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4749 attr->dw_attr_next = NULL;
4750 attr->dw_attr = attr_kind;
4751 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4752 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4753 add_dwarf_attr (die, attr);
4756 /* Add a section offset attribute value to a DIE. */
4758 static inline void
4759 add_AT_lbl_offset (dw_die_ref die, enum dwarf_attribute attr_kind, const char *label)
4761 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4763 attr->dw_attr_next = NULL;
4764 attr->dw_attr = attr_kind;
4765 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4766 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4767 add_dwarf_attr (die, attr);
4770 /* Add an offset attribute value to a DIE. */
4772 static inline void
4773 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind, long unsigned int offset)
4775 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4777 attr->dw_attr_next = NULL;
4778 attr->dw_attr = attr_kind;
4779 attr->dw_attr_val.val_class = dw_val_class_offset;
4780 attr->dw_attr_val.v.val_offset = offset;
4781 add_dwarf_attr (die, attr);
4784 /* Add an range_list attribute value to a DIE. */
4786 static void
4787 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
4788 long unsigned int offset)
4790 dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
4792 attr->dw_attr_next = NULL;
4793 attr->dw_attr = attr_kind;
4794 attr->dw_attr_val.val_class = dw_val_class_range_list;
4795 attr->dw_attr_val.v.val_offset = offset;
4796 add_dwarf_attr (die, attr);
4799 static inline const char *
4800 AT_lbl (dw_attr_ref a)
4802 if (a && (AT_class (a) == dw_val_class_lbl_id
4803 || AT_class (a) == dw_val_class_lbl_offset))
4804 return a->dw_attr_val.v.val_lbl_id;
4806 abort ();
4809 /* Get the attribute of type attr_kind. */
4811 static inline dw_attr_ref
4812 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4814 dw_attr_ref a;
4815 dw_die_ref spec = NULL;
4817 if (die != NULL)
4819 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4820 if (a->dw_attr == attr_kind)
4821 return a;
4822 else if (a->dw_attr == DW_AT_specification
4823 || a->dw_attr == DW_AT_abstract_origin)
4824 spec = AT_ref (a);
4826 if (spec)
4827 return get_AT (spec, attr_kind);
4830 return NULL;
4833 /* Return the "low pc" attribute value, typically associated with a subprogram
4834 DIE. Return null if the "low pc" attribute is either not present, or if it
4835 cannot be represented as an assembler label identifier. */
4837 static inline const char *
4838 get_AT_low_pc (dw_die_ref die)
4840 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4842 return a ? AT_lbl (a) : NULL;
4845 /* Return the "high pc" attribute value, typically associated with a subprogram
4846 DIE. Return null if the "high pc" attribute is either not present, or if it
4847 cannot be represented as an assembler label identifier. */
4849 static inline const char *
4850 get_AT_hi_pc (dw_die_ref die)
4852 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4854 return a ? AT_lbl (a) : NULL;
4857 /* Return the value of the string attribute designated by ATTR_KIND, or
4858 NULL if it is not present. */
4860 static inline const char *
4861 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
4863 dw_attr_ref a = get_AT (die, attr_kind);
4865 return a ? AT_string (a) : NULL;
4868 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4869 if it is not present. */
4871 static inline int
4872 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
4874 dw_attr_ref a = get_AT (die, attr_kind);
4876 return a ? AT_flag (a) : 0;
4879 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4880 if it is not present. */
4882 static inline unsigned
4883 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
4885 dw_attr_ref a = get_AT (die, attr_kind);
4887 return a ? AT_unsigned (a) : 0;
4890 static inline dw_die_ref
4891 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
4893 dw_attr_ref a = get_AT (die, attr_kind);
4895 return a ? AT_ref (a) : NULL;
4898 /* Return TRUE if the language is C or C++. */
4900 static inline bool
4901 is_c_family (void)
4903 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4905 return (lang == DW_LANG_C || lang == DW_LANG_C89
4906 || lang == DW_LANG_C_plus_plus);
4909 /* Return TRUE if the language is C++. */
4911 static inline bool
4912 is_cxx (void)
4914 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4915 == DW_LANG_C_plus_plus);
4918 /* Return TRUE if the language is Fortran. */
4920 static inline bool
4921 is_fortran (void)
4923 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4925 return lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90;
4928 /* Return TRUE if the language is Java. */
4930 static inline bool
4931 is_java (void)
4933 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4935 return lang == DW_LANG_Java;
4938 /* Return TRUE if the language is Ada. */
4940 static inline bool
4941 is_ada (void)
4943 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4945 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
4948 /* Free up the memory used by A. */
4950 static inline void free_AT (dw_attr_ref);
4951 static inline void
4952 free_AT (dw_attr_ref a)
4954 if (AT_class (a) == dw_val_class_str)
4955 if (a->dw_attr_val.v.val_str->refcount)
4956 a->dw_attr_val.v.val_str->refcount--;
4959 /* Remove the specified attribute if present. */
4961 static void
4962 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4964 dw_attr_ref *p;
4965 dw_attr_ref removed = NULL;
4967 if (die != NULL)
4969 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4970 if ((*p)->dw_attr == attr_kind)
4972 removed = *p;
4973 *p = (*p)->dw_attr_next;
4974 break;
4977 if (removed != 0)
4978 free_AT (removed);
4982 /* Free up the memory used by DIE. */
4984 static inline void
4985 free_die (dw_die_ref die)
4987 remove_children (die);
4990 /* Discard the children of this DIE. */
4992 static void
4993 remove_children (dw_die_ref die)
4995 dw_die_ref child_die = die->die_child;
4997 die->die_child = NULL;
4999 while (child_die != NULL)
5001 dw_die_ref tmp_die = child_die;
5002 dw_attr_ref a;
5004 child_die = child_die->die_sib;
5006 for (a = tmp_die->die_attr; a != NULL;)
5008 dw_attr_ref tmp_a = a;
5010 a = a->dw_attr_next;
5011 free_AT (tmp_a);
5014 free_die (tmp_die);
5018 /* Add a child DIE below its parent. We build the lists up in reverse
5019 addition order, and correct that in reverse_all_dies. */
5021 static inline void
5022 add_child_die (dw_die_ref die, dw_die_ref child_die)
5024 if (die != NULL && child_die != NULL)
5026 if (die == child_die)
5027 abort ();
5029 child_die->die_parent = die;
5030 child_die->die_sib = die->die_child;
5031 die->die_child = child_die;
5035 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5036 is the specification, to the front of PARENT's list of children. */
5038 static void
5039 splice_child_die (dw_die_ref parent, dw_die_ref child)
5041 dw_die_ref *p;
5043 /* We want the declaration DIE from inside the class, not the
5044 specification DIE at toplevel. */
5045 if (child->die_parent != parent)
5047 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5049 if (tmp)
5050 child = tmp;
5053 if (child->die_parent != parent
5054 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
5055 abort ();
5057 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5058 if (*p == child)
5060 *p = child->die_sib;
5061 break;
5064 child->die_parent = parent;
5065 child->die_sib = parent->die_child;
5066 parent->die_child = child;
5069 /* Return a pointer to a newly created DIE node. */
5071 static inline dw_die_ref
5072 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5074 dw_die_ref die = (dw_die_ref) ggc_alloc_cleared (sizeof (die_node));
5076 die->die_tag = tag_value;
5078 if (parent_die != NULL)
5079 add_child_die (parent_die, die);
5080 else
5082 limbo_die_node *limbo_node;
5084 limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node));
5085 limbo_node->die = die;
5086 limbo_node->created_for = t;
5087 limbo_node->next = limbo_die_list;
5088 limbo_die_list = limbo_node;
5091 return die;
5094 /* Return the DIE associated with the given type specifier. */
5096 static inline dw_die_ref
5097 lookup_type_die (tree type)
5099 return TYPE_SYMTAB_DIE (type);
5102 /* Equate a DIE to a given type specifier. */
5104 static inline void
5105 equate_type_number_to_die (tree type, dw_die_ref type_die)
5107 TYPE_SYMTAB_DIE (type) = type_die;
5110 /* Return the DIE associated with a given declaration. */
5112 static inline dw_die_ref
5113 lookup_decl_die (tree decl)
5115 unsigned decl_id = DECL_UID (decl);
5117 return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
5120 /* Equate a DIE to a particular declaration. */
5122 static void
5123 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5125 unsigned int decl_id = DECL_UID (decl);
5126 unsigned int num_allocated;
5128 if (decl_id >= decl_die_table_allocated)
5130 num_allocated
5131 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5132 / DECL_DIE_TABLE_INCREMENT)
5133 * DECL_DIE_TABLE_INCREMENT;
5135 decl_die_table = ggc_realloc (decl_die_table,
5136 sizeof (dw_die_ref) * num_allocated);
5138 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5139 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5140 decl_die_table_allocated = num_allocated;
5143 if (decl_id >= decl_die_table_in_use)
5144 decl_die_table_in_use = (decl_id + 1);
5146 decl_die_table[decl_id] = decl_die;
5149 /* Keep track of the number of spaces used to indent the
5150 output of the debugging routines that print the structure of
5151 the DIE internal representation. */
5152 static int print_indent;
5154 /* Indent the line the number of spaces given by print_indent. */
5156 static inline void
5157 print_spaces (FILE *outfile)
5159 fprintf (outfile, "%*s", print_indent, "");
5162 /* Print the information associated with a given DIE, and its children.
5163 This routine is a debugging aid only. */
5165 static void
5166 print_die (dw_die_ref die, FILE *outfile)
5168 dw_attr_ref a;
5169 dw_die_ref c;
5171 print_spaces (outfile);
5172 fprintf (outfile, "DIE %4lu: %s\n",
5173 die->die_offset, dwarf_tag_name (die->die_tag));
5174 print_spaces (outfile);
5175 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5176 fprintf (outfile, " offset: %lu\n", die->die_offset);
5178 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5180 print_spaces (outfile);
5181 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5183 switch (AT_class (a))
5185 case dw_val_class_addr:
5186 fprintf (outfile, "address");
5187 break;
5188 case dw_val_class_offset:
5189 fprintf (outfile, "offset");
5190 break;
5191 case dw_val_class_loc:
5192 fprintf (outfile, "location descriptor");
5193 break;
5194 case dw_val_class_loc_list:
5195 fprintf (outfile, "location list -> label:%s",
5196 AT_loc_list (a)->ll_symbol);
5197 break;
5198 case dw_val_class_range_list:
5199 fprintf (outfile, "range list");
5200 break;
5201 case dw_val_class_const:
5202 fprintf (outfile, "%ld", AT_int (a));
5203 break;
5204 case dw_val_class_unsigned_const:
5205 fprintf (outfile, "%lu", AT_unsigned (a));
5206 break;
5207 case dw_val_class_long_long:
5208 fprintf (outfile, "constant (%lu,%lu)",
5209 a->dw_attr_val.v.val_long_long.hi,
5210 a->dw_attr_val.v.val_long_long.low);
5211 break;
5212 case dw_val_class_float:
5213 fprintf (outfile, "floating-point constant");
5214 break;
5215 case dw_val_class_flag:
5216 fprintf (outfile, "%u", AT_flag (a));
5217 break;
5218 case dw_val_class_die_ref:
5219 if (AT_ref (a) != NULL)
5221 if (AT_ref (a)->die_symbol)
5222 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5223 else
5224 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5226 else
5227 fprintf (outfile, "die -> <null>");
5228 break;
5229 case dw_val_class_lbl_id:
5230 case dw_val_class_lbl_offset:
5231 fprintf (outfile, "label: %s", AT_lbl (a));
5232 break;
5233 case dw_val_class_str:
5234 if (AT_string (a) != NULL)
5235 fprintf (outfile, "\"%s\"", AT_string (a));
5236 else
5237 fprintf (outfile, "<null>");
5238 break;
5239 default:
5240 break;
5243 fprintf (outfile, "\n");
5246 if (die->die_child != NULL)
5248 print_indent += 4;
5249 for (c = die->die_child; c != NULL; c = c->die_sib)
5250 print_die (c, outfile);
5252 print_indent -= 4;
5254 if (print_indent == 0)
5255 fprintf (outfile, "\n");
5258 /* Print the contents of the source code line number correspondence table.
5259 This routine is a debugging aid only. */
5261 static void
5262 print_dwarf_line_table (FILE *outfile)
5264 unsigned i;
5265 dw_line_info_ref line_info;
5267 fprintf (outfile, "\n\nDWARF source line information\n");
5268 for (i = 1; i < line_info_table_in_use; i++)
5270 line_info = &line_info_table[i];
5271 fprintf (outfile, "%5d: ", i);
5272 fprintf (outfile, "%-20s",
5273 VARRAY_CHAR_PTR (file_table, line_info->dw_file_num));
5274 fprintf (outfile, "%6ld", line_info->dw_line_num);
5275 fprintf (outfile, "\n");
5278 fprintf (outfile, "\n\n");
5281 /* Print the information collected for a given DIE. */
5283 void
5284 debug_dwarf_die (dw_die_ref die)
5286 print_die (die, stderr);
5289 /* Print all DWARF information collected for the compilation unit.
5290 This routine is a debugging aid only. */
5292 void
5293 debug_dwarf (void)
5295 print_indent = 0;
5296 print_die (comp_unit_die, stderr);
5297 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5298 print_dwarf_line_table (stderr);
5301 /* We build up the lists of children and attributes by pushing new ones
5302 onto the beginning of the list. Reverse the lists for DIE so that
5303 they are in order of addition. */
5305 static void
5306 reverse_die_lists (dw_die_ref die)
5308 dw_die_ref c, cp, cn;
5309 dw_attr_ref a, ap, an;
5311 for (a = die->die_attr, ap = 0; a; a = an)
5313 an = a->dw_attr_next;
5314 a->dw_attr_next = ap;
5315 ap = a;
5318 die->die_attr = ap;
5320 for (c = die->die_child, cp = 0; c; c = cn)
5322 cn = c->die_sib;
5323 c->die_sib = cp;
5324 cp = c;
5327 die->die_child = cp;
5330 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5331 reverse all dies in add_sibling_attributes, which runs through all the dies,
5332 it would reverse all the dies. Now, however, since we don't call
5333 reverse_die_lists in add_sibling_attributes, we need a routine to
5334 recursively reverse all the dies. This is that routine. */
5336 static void
5337 reverse_all_dies (dw_die_ref die)
5339 dw_die_ref c;
5341 reverse_die_lists (die);
5343 for (c = die->die_child; c; c = c->die_sib)
5344 reverse_all_dies (c);
5347 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5348 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5349 DIE that marks the start of the DIEs for this include file. */
5351 static dw_die_ref
5352 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5354 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5355 dw_die_ref new_unit = gen_compile_unit_die (filename);
5357 new_unit->die_sib = old_unit;
5358 return new_unit;
5361 /* Close an include-file CU and reopen the enclosing one. */
5363 static dw_die_ref
5364 pop_compile_unit (dw_die_ref old_unit)
5366 dw_die_ref new_unit = old_unit->die_sib;
5368 old_unit->die_sib = NULL;
5369 return new_unit;
5372 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5373 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5375 /* Calculate the checksum of a location expression. */
5377 static inline void
5378 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5380 CHECKSUM (loc->dw_loc_opc);
5381 CHECKSUM (loc->dw_loc_oprnd1);
5382 CHECKSUM (loc->dw_loc_oprnd2);
5385 /* Calculate the checksum of an attribute. */
5387 static void
5388 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5390 dw_loc_descr_ref loc;
5391 rtx r;
5393 CHECKSUM (at->dw_attr);
5395 /* We don't care about differences in file numbering. */
5396 if (at->dw_attr == DW_AT_decl_file
5397 /* Or that this was compiled with a different compiler snapshot; if
5398 the output is the same, that's what matters. */
5399 || at->dw_attr == DW_AT_producer)
5400 return;
5402 switch (AT_class (at))
5404 case dw_val_class_const:
5405 CHECKSUM (at->dw_attr_val.v.val_int);
5406 break;
5407 case dw_val_class_unsigned_const:
5408 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5409 break;
5410 case dw_val_class_long_long:
5411 CHECKSUM (at->dw_attr_val.v.val_long_long);
5412 break;
5413 case dw_val_class_float:
5414 CHECKSUM (at->dw_attr_val.v.val_float);
5415 break;
5416 case dw_val_class_flag:
5417 CHECKSUM (at->dw_attr_val.v.val_flag);
5418 break;
5419 case dw_val_class_str:
5420 CHECKSUM_STRING (AT_string (at));
5421 break;
5423 case dw_val_class_addr:
5424 r = AT_addr (at);
5425 switch (GET_CODE (r))
5427 case SYMBOL_REF:
5428 CHECKSUM_STRING (XSTR (r, 0));
5429 break;
5431 default:
5432 abort ();
5434 break;
5436 case dw_val_class_offset:
5437 CHECKSUM (at->dw_attr_val.v.val_offset);
5438 break;
5440 case dw_val_class_loc:
5441 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5442 loc_checksum (loc, ctx);
5443 break;
5445 case dw_val_class_die_ref:
5446 die_checksum (AT_ref (at), ctx, mark);
5447 break;
5449 case dw_val_class_fde_ref:
5450 case dw_val_class_lbl_id:
5451 case dw_val_class_lbl_offset:
5452 break;
5454 default:
5455 break;
5459 /* Calculate the checksum of a DIE. */
5461 static void
5462 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5464 dw_die_ref c;
5465 dw_attr_ref a;
5467 /* To avoid infinite recursion. */
5468 if (die->die_mark)
5470 CHECKSUM (die->die_mark);
5471 return;
5473 die->die_mark = ++(*mark);
5475 CHECKSUM (die->die_tag);
5477 for (a = die->die_attr; a; a = a->dw_attr_next)
5478 attr_checksum (a, ctx, mark);
5480 for (c = die->die_child; c; c = c->die_sib)
5481 die_checksum (c, ctx, mark);
5484 #undef CHECKSUM
5485 #undef CHECKSUM_STRING
5487 /* Do the location expressions look same? */
5488 static inline int
5489 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
5491 return loc1->dw_loc_opc == loc2->dw_loc_opc
5492 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
5493 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
5496 /* Do the values look the same? */
5497 static int
5498 same_dw_val_p (dw_val_node *v1, dw_val_node *v2, int *mark)
5500 dw_loc_descr_ref loc1, loc2;
5501 rtx r1, r2;
5502 unsigned i;
5504 if (v1->val_class != v2->val_class)
5505 return 0;
5507 switch (v1->val_class)
5509 case dw_val_class_const:
5510 return v1->v.val_int == v2->v.val_int;
5511 case dw_val_class_unsigned_const:
5512 return v1->v.val_unsigned == v2->v.val_unsigned;
5513 case dw_val_class_long_long:
5514 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
5515 && v1->v.val_long_long.low == v2->v.val_long_long.low;
5516 case dw_val_class_float:
5517 if (v1->v.val_float.length != v2->v.val_float.length)
5518 return 0;
5519 for (i = 0; i < v1->v.val_float.length; i++)
5520 if (v1->v.val_float.array[i] != v2->v.val_float.array[i])
5521 return 0;
5522 return 1;
5523 case dw_val_class_flag:
5524 return v1->v.val_flag == v2->v.val_flag;
5525 case dw_val_class_str:
5526 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
5528 case dw_val_class_addr:
5529 r1 = v1->v.val_addr;
5530 r2 = v2->v.val_addr;
5531 if (GET_CODE (r1) != GET_CODE (r2))
5532 return 0;
5533 switch (GET_CODE (r1))
5535 case SYMBOL_REF:
5536 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
5538 default:
5539 abort ();
5542 case dw_val_class_offset:
5543 return v1->v.val_offset == v2->v.val_offset;
5545 case dw_val_class_loc:
5546 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
5547 loc1 && loc2;
5548 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
5549 if (!same_loc_p (loc1, loc2, mark))
5550 return 0;
5551 return !loc1 && !loc2;
5553 case dw_val_class_die_ref:
5554 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
5556 case dw_val_class_fde_ref:
5557 case dw_val_class_lbl_id:
5558 case dw_val_class_lbl_offset:
5559 return 1;
5561 default:
5562 return 1;
5566 /* Do the attributes look the same? */
5568 static int
5569 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
5571 if (at1->dw_attr != at2->dw_attr)
5572 return 0;
5574 /* We don't care about differences in file numbering. */
5575 if (at1->dw_attr == DW_AT_decl_file
5576 /* Or that this was compiled with a different compiler snapshot; if
5577 the output is the same, that's what matters. */
5578 || at1->dw_attr == DW_AT_producer)
5579 return 1;
5581 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
5584 /* Do the dies look the same? */
5586 static int
5587 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
5589 dw_die_ref c1, c2;
5590 dw_attr_ref a1, a2;
5592 /* To avoid infinite recursion. */
5593 if (die1->die_mark)
5594 return die1->die_mark == die2->die_mark;
5595 die1->die_mark = die2->die_mark = ++(*mark);
5597 if (die1->die_tag != die2->die_tag)
5598 return 0;
5600 for (a1 = die1->die_attr, a2 = die2->die_attr;
5601 a1 && a2;
5602 a1 = a1->dw_attr_next, a2 = a2->dw_attr_next)
5603 if (!same_attr_p (a1, a2, mark))
5604 return 0;
5605 if (a1 || a2)
5606 return 0;
5608 for (c1 = die1->die_child, c2 = die2->die_child;
5609 c1 && c2;
5610 c1 = c1->die_sib, c2 = c2->die_sib)
5611 if (!same_die_p (c1, c2, mark))
5612 return 0;
5613 if (c1 || c2)
5614 return 0;
5616 return 1;
5619 /* Do the dies look the same? Wrapper around same_die_p. */
5621 static int
5622 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
5624 int mark = 0;
5625 int ret = same_die_p (die1, die2, &mark);
5627 unmark_all_dies (die1);
5628 unmark_all_dies (die2);
5630 return ret;
5633 /* The prefix to attach to symbols on DIEs in the current comdat debug
5634 info section. */
5635 static char *comdat_symbol_id;
5637 /* The index of the current symbol within the current comdat CU. */
5638 static unsigned int comdat_symbol_number;
5640 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5641 children, and set comdat_symbol_id accordingly. */
5643 static void
5644 compute_section_prefix (dw_die_ref unit_die)
5646 const char *die_name = get_AT_string (unit_die, DW_AT_name);
5647 const char *base = die_name ? lbasename (die_name) : "anonymous";
5648 char *name = (char *) alloca (strlen (base) + 64);
5649 char *p;
5650 int i, mark;
5651 unsigned char checksum[16];
5652 struct md5_ctx ctx;
5654 /* Compute the checksum of the DIE, then append part of it as hex digits to
5655 the name filename of the unit. */
5657 md5_init_ctx (&ctx);
5658 mark = 0;
5659 die_checksum (unit_die, &ctx, &mark);
5660 unmark_all_dies (unit_die);
5661 md5_finish_ctx (&ctx, checksum);
5663 sprintf (name, "%s.", base);
5664 clean_symbol_name (name);
5666 p = name + strlen (name);
5667 for (i = 0; i < 4; i++)
5669 sprintf (p, "%.2x", checksum[i]);
5670 p += 2;
5673 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5674 comdat_symbol_number = 0;
5677 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5679 static int
5680 is_type_die (dw_die_ref die)
5682 switch (die->die_tag)
5684 case DW_TAG_array_type:
5685 case DW_TAG_class_type:
5686 case DW_TAG_enumeration_type:
5687 case DW_TAG_pointer_type:
5688 case DW_TAG_reference_type:
5689 case DW_TAG_string_type:
5690 case DW_TAG_structure_type:
5691 case DW_TAG_subroutine_type:
5692 case DW_TAG_union_type:
5693 case DW_TAG_ptr_to_member_type:
5694 case DW_TAG_set_type:
5695 case DW_TAG_subrange_type:
5696 case DW_TAG_base_type:
5697 case DW_TAG_const_type:
5698 case DW_TAG_file_type:
5699 case DW_TAG_packed_type:
5700 case DW_TAG_volatile_type:
5701 case DW_TAG_typedef:
5702 return 1;
5703 default:
5704 return 0;
5708 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5709 Basically, we want to choose the bits that are likely to be shared between
5710 compilations (types) and leave out the bits that are specific to individual
5711 compilations (functions). */
5713 static int
5714 is_comdat_die (dw_die_ref c)
5716 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5717 we do for stabs. The advantage is a greater likelihood of sharing between
5718 objects that don't include headers in the same order (and therefore would
5719 put the base types in a different comdat). jason 8/28/00 */
5721 if (c->die_tag == DW_TAG_base_type)
5722 return 0;
5724 if (c->die_tag == DW_TAG_pointer_type
5725 || c->die_tag == DW_TAG_reference_type
5726 || c->die_tag == DW_TAG_const_type
5727 || c->die_tag == DW_TAG_volatile_type)
5729 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5731 return t ? is_comdat_die (t) : 0;
5734 return is_type_die (c);
5737 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5738 compilation unit. */
5740 static int
5741 is_symbol_die (dw_die_ref c)
5743 return (is_type_die (c)
5744 || (get_AT (c, DW_AT_declaration)
5745 && !get_AT (c, DW_AT_specification)));
5748 static char *
5749 gen_internal_sym (const char *prefix)
5751 char buf[256];
5753 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5754 return xstrdup (buf);
5757 /* Assign symbols to all worthy DIEs under DIE. */
5759 static void
5760 assign_symbol_names (dw_die_ref die)
5762 dw_die_ref c;
5764 if (is_symbol_die (die))
5766 if (comdat_symbol_id)
5768 char *p = alloca (strlen (comdat_symbol_id) + 64);
5770 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5771 comdat_symbol_id, comdat_symbol_number++);
5772 die->die_symbol = xstrdup (p);
5774 else
5775 die->die_symbol = gen_internal_sym ("LDIE");
5778 for (c = die->die_child; c != NULL; c = c->die_sib)
5779 assign_symbol_names (c);
5782 struct cu_hash_table_entry
5784 dw_die_ref cu;
5785 unsigned min_comdat_num, max_comdat_num;
5786 struct cu_hash_table_entry *next;
5789 /* Routines to manipulate hash table of CUs. */
5790 static hashval_t
5791 htab_cu_hash (const void *of)
5793 const struct cu_hash_table_entry *entry = of;
5795 return htab_hash_string (entry->cu->die_symbol);
5798 static int
5799 htab_cu_eq (const void *of1, const void *of2)
5801 const struct cu_hash_table_entry *entry1 = of1;
5802 const struct die_struct *entry2 = of2;
5804 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
5807 static void
5808 htab_cu_del (void *what)
5810 struct cu_hash_table_entry *next, *entry = what;
5812 while (entry)
5814 next = entry->next;
5815 free (entry);
5816 entry = next;
5820 /* Check whether we have already seen this CU and set up SYM_NUM
5821 accordingly. */
5822 static int
5823 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
5825 struct cu_hash_table_entry dummy;
5826 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
5828 dummy.max_comdat_num = 0;
5830 slot = (struct cu_hash_table_entry **)
5831 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
5832 INSERT);
5833 entry = *slot;
5835 for (; entry; last = entry, entry = entry->next)
5837 if (same_die_p_wrap (cu, entry->cu))
5838 break;
5841 if (entry)
5843 *sym_num = entry->min_comdat_num;
5844 return 1;
5847 entry = xcalloc (1, sizeof (struct cu_hash_table_entry));
5848 entry->cu = cu;
5849 entry->min_comdat_num = *sym_num = last->max_comdat_num;
5850 entry->next = *slot;
5851 *slot = entry;
5853 return 0;
5856 /* Record SYM_NUM to record of CU in HTABLE. */
5857 static void
5858 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
5860 struct cu_hash_table_entry **slot, *entry;
5862 slot = (struct cu_hash_table_entry **)
5863 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
5864 NO_INSERT);
5865 entry = *slot;
5867 entry->max_comdat_num = sym_num;
5870 /* Traverse the DIE (which is always comp_unit_die), and set up
5871 additional compilation units for each of the include files we see
5872 bracketed by BINCL/EINCL. */
5874 static void
5875 break_out_includes (dw_die_ref die)
5877 dw_die_ref *ptr;
5878 dw_die_ref unit = NULL;
5879 limbo_die_node *node, **pnode;
5880 htab_t cu_hash_table;
5882 for (ptr = &(die->die_child); *ptr;)
5884 dw_die_ref c = *ptr;
5886 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
5887 || (unit && is_comdat_die (c)))
5889 /* This DIE is for a secondary CU; remove it from the main one. */
5890 *ptr = c->die_sib;
5892 if (c->die_tag == DW_TAG_GNU_BINCL)
5894 unit = push_new_compile_unit (unit, c);
5895 free_die (c);
5897 else if (c->die_tag == DW_TAG_GNU_EINCL)
5899 unit = pop_compile_unit (unit);
5900 free_die (c);
5902 else
5903 add_child_die (unit, c);
5905 else
5907 /* Leave this DIE in the main CU. */
5908 ptr = &(c->die_sib);
5909 continue;
5913 #if 0
5914 /* We can only use this in debugging, since the frontend doesn't check
5915 to make sure that we leave every include file we enter. */
5916 if (unit != NULL)
5917 abort ();
5918 #endif
5920 assign_symbol_names (die);
5921 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
5922 for (node = limbo_die_list, pnode = &limbo_die_list;
5923 node;
5924 node = node->next)
5926 int is_dupl;
5928 compute_section_prefix (node->die);
5929 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
5930 &comdat_symbol_number);
5931 assign_symbol_names (node->die);
5932 if (is_dupl)
5933 *pnode = node->next;
5934 else
5936 pnode = &node->next;
5937 record_comdat_symbol_number (node->die, cu_hash_table,
5938 comdat_symbol_number);
5941 htab_delete (cu_hash_table);
5944 /* Traverse the DIE and add a sibling attribute if it may have the
5945 effect of speeding up access to siblings. To save some space,
5946 avoid generating sibling attributes for DIE's without children. */
5948 static void
5949 add_sibling_attributes (dw_die_ref die)
5951 dw_die_ref c;
5953 if (die->die_tag != DW_TAG_compile_unit
5954 && die->die_sib && die->die_child != NULL)
5955 /* Add the sibling link to the front of the attribute list. */
5956 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5958 for (c = die->die_child; c != NULL; c = c->die_sib)
5959 add_sibling_attributes (c);
5962 /* Output all location lists for the DIE and its children. */
5964 static void
5965 output_location_lists (dw_die_ref die)
5967 dw_die_ref c;
5968 dw_attr_ref d_attr;
5970 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5971 if (AT_class (d_attr) == dw_val_class_loc_list)
5972 output_loc_list (AT_loc_list (d_attr));
5974 for (c = die->die_child; c != NULL; c = c->die_sib)
5975 output_location_lists (c);
5979 /* The format of each DIE (and its attribute value pairs) is encoded in an
5980 abbreviation table. This routine builds the abbreviation table and assigns
5981 a unique abbreviation id for each abbreviation entry. The children of each
5982 die are visited recursively. */
5984 static void
5985 build_abbrev_table (dw_die_ref die)
5987 unsigned long abbrev_id;
5988 unsigned int n_alloc;
5989 dw_die_ref c;
5990 dw_attr_ref d_attr, a_attr;
5992 /* Scan the DIE references, and mark as external any that refer to
5993 DIEs from other CUs (i.e. those which are not marked). */
5994 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5995 if (AT_class (d_attr) == dw_val_class_die_ref
5996 && AT_ref (d_attr)->die_mark == 0)
5998 if (AT_ref (d_attr)->die_symbol == 0)
5999 abort ();
6001 set_AT_ref_external (d_attr, 1);
6004 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6006 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6008 if (abbrev->die_tag == die->die_tag)
6010 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
6012 a_attr = abbrev->die_attr;
6013 d_attr = die->die_attr;
6015 while (a_attr != NULL && d_attr != NULL)
6017 if ((a_attr->dw_attr != d_attr->dw_attr)
6018 || (value_format (a_attr) != value_format (d_attr)))
6019 break;
6021 a_attr = a_attr->dw_attr_next;
6022 d_attr = d_attr->dw_attr_next;
6025 if (a_attr == NULL && d_attr == NULL)
6026 break;
6031 if (abbrev_id >= abbrev_die_table_in_use)
6033 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
6035 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
6036 abbrev_die_table = ggc_realloc (abbrev_die_table,
6037 sizeof (dw_die_ref) * n_alloc);
6039 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
6040 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
6041 abbrev_die_table_allocated = n_alloc;
6044 ++abbrev_die_table_in_use;
6045 abbrev_die_table[abbrev_id] = die;
6048 die->die_abbrev = abbrev_id;
6049 for (c = die->die_child; c != NULL; c = c->die_sib)
6050 build_abbrev_table (c);
6053 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6055 static int
6056 constant_size (long unsigned int value)
6058 int log;
6060 if (value == 0)
6061 log = 0;
6062 else
6063 log = floor_log2 (value);
6065 log = log / 8;
6066 log = 1 << (floor_log2 (log) + 1);
6068 return log;
6071 /* Return the size of a DIE as it is represented in the
6072 .debug_info section. */
6074 static unsigned long
6075 size_of_die (dw_die_ref die)
6077 unsigned long size = 0;
6078 dw_attr_ref a;
6080 size += size_of_uleb128 (die->die_abbrev);
6081 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6083 switch (AT_class (a))
6085 case dw_val_class_addr:
6086 size += DWARF2_ADDR_SIZE;
6087 break;
6088 case dw_val_class_offset:
6089 size += DWARF_OFFSET_SIZE;
6090 break;
6091 case dw_val_class_loc:
6093 unsigned long lsize = size_of_locs (AT_loc (a));
6095 /* Block length. */
6096 size += constant_size (lsize);
6097 size += lsize;
6099 break;
6100 case dw_val_class_loc_list:
6101 size += DWARF_OFFSET_SIZE;
6102 break;
6103 case dw_val_class_range_list:
6104 size += DWARF_OFFSET_SIZE;
6105 break;
6106 case dw_val_class_const:
6107 size += size_of_sleb128 (AT_int (a));
6108 break;
6109 case dw_val_class_unsigned_const:
6110 size += constant_size (AT_unsigned (a));
6111 break;
6112 case dw_val_class_long_long:
6113 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
6114 break;
6115 case dw_val_class_float:
6116 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
6117 break;
6118 case dw_val_class_flag:
6119 size += 1;
6120 break;
6121 case dw_val_class_die_ref:
6122 if (AT_ref_external (a))
6123 size += DWARF2_ADDR_SIZE;
6124 else
6125 size += DWARF_OFFSET_SIZE;
6126 break;
6127 case dw_val_class_fde_ref:
6128 size += DWARF_OFFSET_SIZE;
6129 break;
6130 case dw_val_class_lbl_id:
6131 size += DWARF2_ADDR_SIZE;
6132 break;
6133 case dw_val_class_lbl_offset:
6134 size += DWARF_OFFSET_SIZE;
6135 break;
6136 case dw_val_class_str:
6137 if (AT_string_form (a) == DW_FORM_strp)
6138 size += DWARF_OFFSET_SIZE;
6139 else
6140 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
6141 break;
6142 default:
6143 abort ();
6147 return size;
6150 /* Size the debugging information associated with a given DIE. Visits the
6151 DIE's children recursively. Updates the global variable next_die_offset, on
6152 each time through. Uses the current value of next_die_offset to update the
6153 die_offset field in each DIE. */
6155 static void
6156 calc_die_sizes (dw_die_ref die)
6158 dw_die_ref c;
6160 die->die_offset = next_die_offset;
6161 next_die_offset += size_of_die (die);
6163 for (c = die->die_child; c != NULL; c = c->die_sib)
6164 calc_die_sizes (c);
6166 if (die->die_child != NULL)
6167 /* Count the null byte used to terminate sibling lists. */
6168 next_die_offset += 1;
6171 /* Set the marks for a die and its children. We do this so
6172 that we know whether or not a reference needs to use FORM_ref_addr; only
6173 DIEs in the same CU will be marked. We used to clear out the offset
6174 and use that as the flag, but ran into ordering problems. */
6176 static void
6177 mark_dies (dw_die_ref die)
6179 dw_die_ref c;
6181 if (die->die_mark)
6182 abort ();
6184 die->die_mark = 1;
6185 for (c = die->die_child; c; c = c->die_sib)
6186 mark_dies (c);
6189 /* Clear the marks for a die and its children. */
6191 static void
6192 unmark_dies (dw_die_ref die)
6194 dw_die_ref c;
6196 if (!die->die_mark)
6197 abort ();
6199 die->die_mark = 0;
6200 for (c = die->die_child; c; c = c->die_sib)
6201 unmark_dies (c);
6204 /* Clear the marks for a die, its children and referred dies. */
6206 static void
6207 unmark_all_dies (dw_die_ref die)
6209 dw_die_ref c;
6210 dw_attr_ref a;
6212 if (!die->die_mark)
6213 return;
6214 die->die_mark = 0;
6216 for (c = die->die_child; c; c = c->die_sib)
6217 unmark_all_dies (c);
6219 for (a = die->die_attr; a; a = a->dw_attr_next)
6220 if (AT_class (a) == dw_val_class_die_ref)
6221 unmark_all_dies (AT_ref (a));
6224 /* Return the size of the .debug_pubnames table generated for the
6225 compilation unit. */
6227 static unsigned long
6228 size_of_pubnames (void)
6230 unsigned long size;
6231 unsigned i;
6233 size = DWARF_PUBNAMES_HEADER_SIZE;
6234 for (i = 0; i < pubname_table_in_use; i++)
6236 pubname_ref p = &pubname_table[i];
6237 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
6240 size += DWARF_OFFSET_SIZE;
6241 return size;
6244 /* Return the size of the information in the .debug_aranges section. */
6246 static unsigned long
6247 size_of_aranges (void)
6249 unsigned long size;
6251 size = DWARF_ARANGES_HEADER_SIZE;
6253 /* Count the address/length pair for this compilation unit. */
6254 size += 2 * DWARF2_ADDR_SIZE;
6255 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6257 /* Count the two zero words used to terminated the address range table. */
6258 size += 2 * DWARF2_ADDR_SIZE;
6259 return size;
6262 /* Select the encoding of an attribute value. */
6264 static enum dwarf_form
6265 value_format (dw_attr_ref a)
6267 switch (a->dw_attr_val.val_class)
6269 case dw_val_class_addr:
6270 return DW_FORM_addr;
6271 case dw_val_class_range_list:
6272 case dw_val_class_offset:
6273 if (DWARF_OFFSET_SIZE == 4)
6274 return DW_FORM_data4;
6275 if (DWARF_OFFSET_SIZE == 8)
6276 return DW_FORM_data8;
6277 abort ();
6278 case dw_val_class_loc_list:
6279 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6280 .debug_loc section */
6281 return DW_FORM_data4;
6282 case dw_val_class_loc:
6283 switch (constant_size (size_of_locs (AT_loc (a))))
6285 case 1:
6286 return DW_FORM_block1;
6287 case 2:
6288 return DW_FORM_block2;
6289 default:
6290 abort ();
6292 case dw_val_class_const:
6293 return DW_FORM_sdata;
6294 case dw_val_class_unsigned_const:
6295 switch (constant_size (AT_unsigned (a)))
6297 case 1:
6298 return DW_FORM_data1;
6299 case 2:
6300 return DW_FORM_data2;
6301 case 4:
6302 return DW_FORM_data4;
6303 case 8:
6304 return DW_FORM_data8;
6305 default:
6306 abort ();
6308 case dw_val_class_long_long:
6309 return DW_FORM_block1;
6310 case dw_val_class_float:
6311 return DW_FORM_block1;
6312 case dw_val_class_flag:
6313 return DW_FORM_flag;
6314 case dw_val_class_die_ref:
6315 if (AT_ref_external (a))
6316 return DW_FORM_ref_addr;
6317 else
6318 return DW_FORM_ref;
6319 case dw_val_class_fde_ref:
6320 return DW_FORM_data;
6321 case dw_val_class_lbl_id:
6322 return DW_FORM_addr;
6323 case dw_val_class_lbl_offset:
6324 return DW_FORM_data;
6325 case dw_val_class_str:
6326 return AT_string_form (a);
6328 default:
6329 abort ();
6333 /* Output the encoding of an attribute value. */
6335 static void
6336 output_value_format (dw_attr_ref a)
6338 enum dwarf_form form = value_format (a);
6340 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6343 /* Output the .debug_abbrev section which defines the DIE abbreviation
6344 table. */
6346 static void
6347 output_abbrev_section (void)
6349 unsigned long abbrev_id;
6351 dw_attr_ref a_attr;
6353 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6355 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6357 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6358 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6359 dwarf_tag_name (abbrev->die_tag));
6361 if (abbrev->die_child != NULL)
6362 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6363 else
6364 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6366 for (a_attr = abbrev->die_attr; a_attr != NULL;
6367 a_attr = a_attr->dw_attr_next)
6369 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6370 dwarf_attr_name (a_attr->dw_attr));
6371 output_value_format (a_attr);
6374 dw2_asm_output_data (1, 0, NULL);
6375 dw2_asm_output_data (1, 0, NULL);
6378 /* Terminate the table. */
6379 dw2_asm_output_data (1, 0, NULL);
6382 /* Output a symbol we can use to refer to this DIE from another CU. */
6384 static inline void
6385 output_die_symbol (dw_die_ref die)
6387 char *sym = die->die_symbol;
6389 if (sym == 0)
6390 return;
6392 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6393 /* We make these global, not weak; if the target doesn't support
6394 .linkonce, it doesn't support combining the sections, so debugging
6395 will break. */
6396 (*targetm.asm_out.globalize_label) (asm_out_file, sym);
6398 ASM_OUTPUT_LABEL (asm_out_file, sym);
6401 /* Return a new location list, given the begin and end range, and the
6402 expression. gensym tells us whether to generate a new internal symbol for
6403 this location list node, which is done for the head of the list only. */
6405 static inline dw_loc_list_ref
6406 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
6407 const char *section, unsigned int gensym)
6409 dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node));
6411 retlist->begin = begin;
6412 retlist->end = end;
6413 retlist->expr = expr;
6414 retlist->section = section;
6415 if (gensym)
6416 retlist->ll_symbol = gen_internal_sym ("LLST");
6418 return retlist;
6421 /* Add a location description expression to a location list. */
6423 static inline void
6424 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
6425 const char *begin, const char *end,
6426 const char *section)
6428 dw_loc_list_ref *d;
6430 /* Find the end of the chain. */
6431 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6434 /* Add a new location list node to the list. */
6435 *d = new_loc_list (descr, begin, end, section, 0);
6438 /* Output the location list given to us. */
6440 static void
6441 output_loc_list (dw_loc_list_ref list_head)
6443 dw_loc_list_ref curr = list_head;
6445 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6447 /* ??? This shouldn't be needed now that we've forced the
6448 compilation unit base address to zero when there is code
6449 in more than one section. */
6450 if (strcmp (curr->section, ".text") == 0)
6452 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6453 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
6454 "Location list base address specifier fake entry");
6455 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6456 "Location list base address specifier base");
6459 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
6461 unsigned long size;
6463 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6464 "Location list begin address (%s)",
6465 list_head->ll_symbol);
6466 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6467 "Location list end address (%s)",
6468 list_head->ll_symbol);
6469 size = size_of_locs (curr->expr);
6471 /* Output the block length for this list of location operations. */
6472 if (size > 0xffff)
6473 abort ();
6474 dw2_asm_output_data (2, size, "%s", "Location expression size");
6476 output_loc_sequence (curr->expr);
6479 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6480 "Location list terminator begin (%s)",
6481 list_head->ll_symbol);
6482 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6483 "Location list terminator end (%s)",
6484 list_head->ll_symbol);
6487 /* Output the DIE and its attributes. Called recursively to generate
6488 the definitions of each child DIE. */
6490 static void
6491 output_die (dw_die_ref die)
6493 dw_attr_ref a;
6494 dw_die_ref c;
6495 unsigned long size;
6497 /* If someone in another CU might refer to us, set up a symbol for
6498 them to point to. */
6499 if (die->die_symbol)
6500 output_die_symbol (die);
6502 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6503 die->die_offset, dwarf_tag_name (die->die_tag));
6505 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6507 const char *name = dwarf_attr_name (a->dw_attr);
6509 switch (AT_class (a))
6511 case dw_val_class_addr:
6512 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6513 break;
6515 case dw_val_class_offset:
6516 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6517 "%s", name);
6518 break;
6520 case dw_val_class_range_list:
6522 char *p = strchr (ranges_section_label, '\0');
6524 sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset);
6525 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6526 "%s", name);
6527 *p = '\0';
6529 break;
6531 case dw_val_class_loc:
6532 size = size_of_locs (AT_loc (a));
6534 /* Output the block length for this list of location operations. */
6535 dw2_asm_output_data (constant_size (size), size, "%s", name);
6537 output_loc_sequence (AT_loc (a));
6538 break;
6540 case dw_val_class_const:
6541 /* ??? It would be slightly more efficient to use a scheme like is
6542 used for unsigned constants below, but gdb 4.x does not sign
6543 extend. Gdb 5.x does sign extend. */
6544 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6545 break;
6547 case dw_val_class_unsigned_const:
6548 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6549 AT_unsigned (a), "%s", name);
6550 break;
6552 case dw_val_class_long_long:
6554 unsigned HOST_WIDE_INT first, second;
6556 dw2_asm_output_data (1,
6557 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6558 "%s", name);
6560 if (WORDS_BIG_ENDIAN)
6562 first = a->dw_attr_val.v.val_long_long.hi;
6563 second = a->dw_attr_val.v.val_long_long.low;
6565 else
6567 first = a->dw_attr_val.v.val_long_long.low;
6568 second = a->dw_attr_val.v.val_long_long.hi;
6571 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6572 first, "long long constant");
6573 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6574 second, NULL);
6576 break;
6578 case dw_val_class_float:
6580 unsigned int i;
6582 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6583 "%s", name);
6585 for (i = 0; i < a->dw_attr_val.v.val_float.length; i++)
6586 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6587 "fp constant word %u", i);
6588 break;
6591 case dw_val_class_flag:
6592 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6593 break;
6595 case dw_val_class_loc_list:
6597 char *sym = AT_loc_list (a)->ll_symbol;
6599 if (sym == 0)
6600 abort ();
6601 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6602 loc_section_label, "%s", name);
6604 break;
6606 case dw_val_class_die_ref:
6607 if (AT_ref_external (a))
6609 char *sym = AT_ref (a)->die_symbol;
6611 if (sym == 0)
6612 abort ();
6613 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6615 else if (AT_ref (a)->die_offset == 0)
6616 abort ();
6617 else
6618 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6619 "%s", name);
6620 break;
6622 case dw_val_class_fde_ref:
6624 char l1[20];
6626 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6627 a->dw_attr_val.v.val_fde_index * 2);
6628 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6630 break;
6632 case dw_val_class_lbl_id:
6633 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6634 break;
6636 case dw_val_class_lbl_offset:
6637 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6638 break;
6640 case dw_val_class_str:
6641 if (AT_string_form (a) == DW_FORM_strp)
6642 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6643 a->dw_attr_val.v.val_str->label,
6644 "%s: \"%s\"", name, AT_string (a));
6645 else
6646 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6647 break;
6649 default:
6650 abort ();
6654 for (c = die->die_child; c != NULL; c = c->die_sib)
6655 output_die (c);
6657 /* Add null byte to terminate sibling list. */
6658 if (die->die_child != NULL)
6659 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6660 die->die_offset);
6663 /* Output the compilation unit that appears at the beginning of the
6664 .debug_info section, and precedes the DIE descriptions. */
6666 static void
6667 output_compilation_unit_header (void)
6669 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
6670 dw2_asm_output_data (4, 0xffffffff,
6671 "Initial length escape value indicating 64-bit DWARF extension");
6672 dw2_asm_output_data (DWARF_OFFSET_SIZE,
6673 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
6674 "Length of Compilation Unit Info");
6675 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6676 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6677 "Offset Into Abbrev. Section");
6678 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6681 /* Output the compilation unit DIE and its children. */
6683 static void
6684 output_comp_unit (dw_die_ref die, int output_if_empty)
6686 const char *secname;
6687 char *oldsym, *tmp;
6689 /* Unless we are outputting main CU, we may throw away empty ones. */
6690 if (!output_if_empty && die->die_child == NULL)
6691 return;
6693 /* Even if there are no children of this DIE, we must output the information
6694 about the compilation unit. Otherwise, on an empty translation unit, we
6695 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6696 will then complain when examining the file. First mark all the DIEs in
6697 this CU so we know which get local refs. */
6698 mark_dies (die);
6700 build_abbrev_table (die);
6702 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6703 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6704 calc_die_sizes (die);
6706 oldsym = die->die_symbol;
6707 if (oldsym)
6709 tmp = (char *) alloca (strlen (oldsym) + 24);
6711 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
6712 secname = tmp;
6713 die->die_symbol = NULL;
6715 else
6716 secname = (const char *) DEBUG_INFO_SECTION;
6718 /* Output debugging information. */
6719 named_section_flags (secname, SECTION_DEBUG);
6720 output_compilation_unit_header ();
6721 output_die (die);
6723 /* Leave the marks on the main CU, so we can check them in
6724 output_pubnames. */
6725 if (oldsym)
6727 unmark_dies (die);
6728 die->die_symbol = oldsym;
6732 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6733 output of lang_hooks.decl_printable_name for C++ looks like
6734 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6736 static const char *
6737 dwarf2_name (tree decl, int scope)
6739 return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0);
6742 /* Add a new entry to .debug_pubnames if appropriate. */
6744 static void
6745 add_pubname (tree decl, dw_die_ref die)
6747 pubname_ref p;
6749 if (! TREE_PUBLIC (decl))
6750 return;
6752 if (pubname_table_in_use == pubname_table_allocated)
6754 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6755 pubname_table
6756 = (pubname_ref) ggc_realloc (pubname_table,
6757 (pubname_table_allocated
6758 * sizeof (pubname_entry)));
6759 memset (pubname_table + pubname_table_in_use, 0,
6760 PUBNAME_TABLE_INCREMENT * sizeof (pubname_entry));
6763 p = &pubname_table[pubname_table_in_use++];
6764 p->die = die;
6765 p->name = xstrdup (dwarf2_name (decl, 1));
6768 /* Output the public names table used to speed up access to externally
6769 visible names. For now, only generate entries for externally
6770 visible procedures. */
6772 static void
6773 output_pubnames (void)
6775 unsigned i;
6776 unsigned long pubnames_length = size_of_pubnames ();
6778 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
6779 dw2_asm_output_data (4, 0xffffffff,
6780 "Initial length escape value indicating 64-bit DWARF extension");
6781 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6782 "Length of Public Names Info");
6783 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6784 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6785 "Offset of Compilation Unit Info");
6786 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6787 "Compilation Unit Length");
6789 for (i = 0; i < pubname_table_in_use; i++)
6791 pubname_ref pub = &pubname_table[i];
6793 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6794 if (pub->die->die_mark == 0)
6795 abort ();
6797 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6798 "DIE offset");
6800 dw2_asm_output_nstring (pub->name, -1, "external name");
6803 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6806 /* Add a new entry to .debug_aranges if appropriate. */
6808 static void
6809 add_arange (tree decl, dw_die_ref die)
6811 if (! DECL_SECTION_NAME (decl))
6812 return;
6814 if (arange_table_in_use == arange_table_allocated)
6816 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6817 arange_table = ggc_realloc (arange_table,
6818 (arange_table_allocated
6819 * sizeof (dw_die_ref)));
6820 memset (arange_table + arange_table_in_use, 0,
6821 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
6824 arange_table[arange_table_in_use++] = die;
6827 /* Output the information that goes into the .debug_aranges table.
6828 Namely, define the beginning and ending address range of the
6829 text section generated for this compilation unit. */
6831 static void
6832 output_aranges (void)
6834 unsigned i;
6835 unsigned long aranges_length = size_of_aranges ();
6837 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
6838 dw2_asm_output_data (4, 0xffffffff,
6839 "Initial length escape value indicating 64-bit DWARF extension");
6840 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6841 "Length of Address Ranges Info");
6842 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6843 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6844 "Offset of Compilation Unit Info");
6845 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6846 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6848 /* We need to align to twice the pointer size here. */
6849 if (DWARF_ARANGES_PAD_SIZE)
6851 /* Pad using a 2 byte words so that padding is correct for any
6852 pointer size. */
6853 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6854 2 * DWARF2_ADDR_SIZE);
6855 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6856 dw2_asm_output_data (2, 0, NULL);
6859 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6860 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6861 text_section_label, "Length");
6863 for (i = 0; i < arange_table_in_use; i++)
6865 dw_die_ref die = arange_table[i];
6867 /* We shouldn't see aranges for DIEs outside of the main CU. */
6868 if (die->die_mark == 0)
6869 abort ();
6871 if (die->die_tag == DW_TAG_subprogram)
6873 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6874 "Address");
6875 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6876 get_AT_low_pc (die), "Length");
6878 else
6880 /* A static variable; extract the symbol from DW_AT_location.
6881 Note that this code isn't currently hit, as we only emit
6882 aranges for functions (jason 9/23/99). */
6883 dw_attr_ref a = get_AT (die, DW_AT_location);
6884 dw_loc_descr_ref loc;
6886 if (! a || AT_class (a) != dw_val_class_loc)
6887 abort ();
6889 loc = AT_loc (a);
6890 if (loc->dw_loc_opc != DW_OP_addr)
6891 abort ();
6893 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6894 loc->dw_loc_oprnd1.v.val_addr, "Address");
6895 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6896 get_AT_unsigned (die, DW_AT_byte_size),
6897 "Length");
6901 /* Output the terminator words. */
6902 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6903 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6906 /* Add a new entry to .debug_ranges. Return the offset at which it
6907 was placed. */
6909 static unsigned int
6910 add_ranges (tree block)
6912 unsigned int in_use = ranges_table_in_use;
6914 if (in_use == ranges_table_allocated)
6916 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6917 ranges_table = (dw_ranges_ref)
6918 ggc_realloc (ranges_table, (ranges_table_allocated
6919 * sizeof (struct dw_ranges_struct)));
6920 memset (ranges_table + ranges_table_in_use, 0,
6921 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
6924 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6925 ranges_table_in_use = in_use + 1;
6927 return in_use * 2 * DWARF2_ADDR_SIZE;
6930 static void
6931 output_ranges (void)
6933 unsigned i;
6934 static const char *const start_fmt = "Offset 0x%x";
6935 const char *fmt = start_fmt;
6937 for (i = 0; i < ranges_table_in_use; i++)
6939 int block_num = ranges_table[i].block_num;
6941 if (block_num)
6943 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6944 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6946 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6947 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6949 /* If all code is in the text section, then the compilation
6950 unit base address defaults to DW_AT_low_pc, which is the
6951 base of the text section. */
6952 if (separate_line_info_table_in_use == 0)
6954 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6955 text_section_label,
6956 fmt, i * 2 * DWARF2_ADDR_SIZE);
6957 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6958 text_section_label, NULL);
6961 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6962 compilation unit base address to zero, which allows us to
6963 use absolute addresses, and not worry about whether the
6964 target supports cross-section arithmetic. */
6965 else
6967 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6968 fmt, i * 2 * DWARF2_ADDR_SIZE);
6969 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6972 fmt = NULL;
6974 else
6976 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6977 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6978 fmt = start_fmt;
6983 /* Data structure containing information about input files. */
6984 struct file_info
6986 char *path; /* Complete file name. */
6987 char *fname; /* File name part. */
6988 int length; /* Length of entire string. */
6989 int file_idx; /* Index in input file table. */
6990 int dir_idx; /* Index in directory table. */
6993 /* Data structure containing information about directories with source
6994 files. */
6995 struct dir_info
6997 char *path; /* Path including directory name. */
6998 int length; /* Path length. */
6999 int prefix; /* Index of directory entry which is a prefix. */
7000 int count; /* Number of files in this directory. */
7001 int dir_idx; /* Index of directory used as base. */
7002 int used; /* Used in the end? */
7005 /* Callback function for file_info comparison. We sort by looking at
7006 the directories in the path. */
7008 static int
7009 file_info_cmp (const void *p1, const void *p2)
7011 const struct file_info *s1 = p1;
7012 const struct file_info *s2 = p2;
7013 unsigned char *cp1;
7014 unsigned char *cp2;
7016 /* Take care of file names without directories. We need to make sure that
7017 we return consistent values to qsort since some will get confused if
7018 we return the same value when identical operands are passed in opposite
7019 orders. So if neither has a directory, return 0 and otherwise return
7020 1 or -1 depending on which one has the directory. */
7021 if ((s1->path == s1->fname || s2->path == s2->fname))
7022 return (s2->path == s2->fname) - (s1->path == s1->fname);
7024 cp1 = (unsigned char *) s1->path;
7025 cp2 = (unsigned char *) s2->path;
7027 while (1)
7029 ++cp1;
7030 ++cp2;
7031 /* Reached the end of the first path? If so, handle like above. */
7032 if ((cp1 == (unsigned char *) s1->fname)
7033 || (cp2 == (unsigned char *) s2->fname))
7034 return ((cp2 == (unsigned char *) s2->fname)
7035 - (cp1 == (unsigned char *) s1->fname));
7037 /* Character of current path component the same? */
7038 else if (*cp1 != *cp2)
7039 return *cp1 - *cp2;
7043 /* Output the directory table and the file name table. We try to minimize
7044 the total amount of memory needed. A heuristic is used to avoid large
7045 slowdowns with many input files. */
7047 static void
7048 output_file_names (void)
7050 struct file_info *files;
7051 struct dir_info *dirs;
7052 int *saved;
7053 int *savehere;
7054 int *backmap;
7055 size_t ndirs;
7056 int idx_offset;
7057 size_t i;
7058 int idx;
7060 /* Handle the case where file_table is empty. */
7061 if (VARRAY_ACTIVE_SIZE (file_table) <= 1)
7063 dw2_asm_output_data (1, 0, "End directory table");
7064 dw2_asm_output_data (1, 0, "End file name table");
7065 return;
7068 /* Allocate the various arrays we need. */
7069 files = (struct file_info *) alloca (VARRAY_ACTIVE_SIZE (file_table)
7070 * sizeof (struct file_info));
7071 dirs = (struct dir_info *) alloca (VARRAY_ACTIVE_SIZE (file_table)
7072 * sizeof (struct dir_info));
7074 /* Sort the file names. */
7075 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7077 char *f;
7079 /* Skip all leading "./". */
7080 f = VARRAY_CHAR_PTR (file_table, i);
7081 while (f[0] == '.' && f[1] == '/')
7082 f += 2;
7084 /* Create a new array entry. */
7085 files[i].path = f;
7086 files[i].length = strlen (f);
7087 files[i].file_idx = i;
7089 /* Search for the file name part. */
7090 f = strrchr (f, '/');
7091 files[i].fname = f == NULL ? files[i].path : f + 1;
7094 qsort (files + 1, VARRAY_ACTIVE_SIZE (file_table) - 1,
7095 sizeof (files[0]), file_info_cmp);
7097 /* Find all the different directories used. */
7098 dirs[0].path = files[1].path;
7099 dirs[0].length = files[1].fname - files[1].path;
7100 dirs[0].prefix = -1;
7101 dirs[0].count = 1;
7102 dirs[0].dir_idx = 0;
7103 dirs[0].used = 0;
7104 files[1].dir_idx = 0;
7105 ndirs = 1;
7107 for (i = 2; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7108 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
7109 && memcmp (dirs[ndirs - 1].path, files[i].path,
7110 dirs[ndirs - 1].length) == 0)
7112 /* Same directory as last entry. */
7113 files[i].dir_idx = ndirs - 1;
7114 ++dirs[ndirs - 1].count;
7116 else
7118 size_t j;
7120 /* This is a new directory. */
7121 dirs[ndirs].path = files[i].path;
7122 dirs[ndirs].length = files[i].fname - files[i].path;
7123 dirs[ndirs].count = 1;
7124 dirs[ndirs].dir_idx = ndirs;
7125 dirs[ndirs].used = 0;
7126 files[i].dir_idx = ndirs;
7128 /* Search for a prefix. */
7129 dirs[ndirs].prefix = -1;
7130 for (j = 0; j < ndirs; j++)
7131 if (dirs[j].length < dirs[ndirs].length
7132 && dirs[j].length > 1
7133 && (dirs[ndirs].prefix == -1
7134 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
7135 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
7136 dirs[ndirs].prefix = j;
7138 ++ndirs;
7141 /* Now to the actual work. We have to find a subset of the directories which
7142 allow expressing the file name using references to the directory table
7143 with the least amount of characters. We do not do an exhaustive search
7144 where we would have to check out every combination of every single
7145 possible prefix. Instead we use a heuristic which provides nearly optimal
7146 results in most cases and never is much off. */
7147 saved = (int *) alloca (ndirs * sizeof (int));
7148 savehere = (int *) alloca (ndirs * sizeof (int));
7150 memset (saved, '\0', ndirs * sizeof (saved[0]));
7151 for (i = 0; i < ndirs; i++)
7153 size_t j;
7154 int total;
7156 /* We can always save some space for the current directory. But this
7157 does not mean it will be enough to justify adding the directory. */
7158 savehere[i] = dirs[i].length;
7159 total = (savehere[i] - saved[i]) * dirs[i].count;
7161 for (j = i + 1; j < ndirs; j++)
7163 savehere[j] = 0;
7164 if (saved[j] < dirs[i].length)
7166 /* Determine whether the dirs[i] path is a prefix of the
7167 dirs[j] path. */
7168 int k;
7170 k = dirs[j].prefix;
7171 while (k != -1 && k != (int) i)
7172 k = dirs[k].prefix;
7174 if (k == (int) i)
7176 /* Yes it is. We can possibly safe some memory but
7177 writing the filenames in dirs[j] relative to
7178 dirs[i]. */
7179 savehere[j] = dirs[i].length;
7180 total += (savehere[j] - saved[j]) * dirs[j].count;
7185 /* Check whether we can safe enough to justify adding the dirs[i]
7186 directory. */
7187 if (total > dirs[i].length + 1)
7189 /* It's worthwhile adding. */
7190 for (j = i; j < ndirs; j++)
7191 if (savehere[j] > 0)
7193 /* Remember how much we saved for this directory so far. */
7194 saved[j] = savehere[j];
7196 /* Remember the prefix directory. */
7197 dirs[j].dir_idx = i;
7202 /* We have to emit them in the order they appear in the file_table array
7203 since the index is used in the debug info generation. To do this
7204 efficiently we generate a back-mapping of the indices first. */
7205 backmap = (int *) alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (int));
7206 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7208 backmap[files[i].file_idx] = i;
7210 /* Mark this directory as used. */
7211 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
7214 /* That was it. We are ready to emit the information. First emit the
7215 directory name table. We have to make sure the first actually emitted
7216 directory name has index one; zero is reserved for the current working
7217 directory. Make sure we do not confuse these indices with the one for the
7218 constructed table (even though most of the time they are identical). */
7219 idx = 1;
7220 idx_offset = dirs[0].length > 0 ? 1 : 0;
7221 for (i = 1 - idx_offset; i < ndirs; i++)
7222 if (dirs[i].used != 0)
7224 dirs[i].used = idx++;
7225 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
7226 "Directory Entry: 0x%x", dirs[i].used);
7229 dw2_asm_output_data (1, 0, "End directory table");
7231 /* Correct the index for the current working directory entry if it
7232 exists. */
7233 if (idx_offset == 0)
7234 dirs[0].used = 0;
7236 /* Now write all the file names. */
7237 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7239 int file_idx = backmap[i];
7240 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
7242 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
7243 "File Entry: 0x%lx", (unsigned long) i);
7245 /* Include directory index. */
7246 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
7248 /* Modification time. */
7249 dw2_asm_output_data_uleb128 (0, NULL);
7251 /* File length in bytes. */
7252 dw2_asm_output_data_uleb128 (0, NULL);
7255 dw2_asm_output_data (1, 0, "End file name table");
7259 /* Output the source line number correspondence information. This
7260 information goes into the .debug_line section. */
7262 static void
7263 output_line_info (void)
7265 char l1[20], l2[20], p1[20], p2[20];
7266 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7267 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7268 unsigned opc;
7269 unsigned n_op_args;
7270 unsigned long lt_index;
7271 unsigned long current_line;
7272 long line_offset;
7273 long line_delta;
7274 unsigned long current_file;
7275 unsigned long function;
7277 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7278 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7279 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7280 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7282 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7283 dw2_asm_output_data (4, 0xffffffff,
7284 "Initial length escape value indicating 64-bit DWARF extension");
7285 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7286 "Length of Source Line Info");
7287 ASM_OUTPUT_LABEL (asm_out_file, l1);
7289 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7290 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7291 ASM_OUTPUT_LABEL (asm_out_file, p1);
7293 /* Define the architecture-dependent minimum instruction length (in
7294 bytes). In this implementation of DWARF, this field is used for
7295 information purposes only. Since GCC generates assembly language,
7296 we have no a priori knowledge of how many instruction bytes are
7297 generated for each source line, and therefore can use only the
7298 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7299 commands. Accordingly, we fix this as `1', which is "correct
7300 enough" for all architectures, and don't let the target override. */
7301 dw2_asm_output_data (1, 1,
7302 "Minimum Instruction Length");
7304 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7305 "Default is_stmt_start flag");
7306 dw2_asm_output_data (1, DWARF_LINE_BASE,
7307 "Line Base Value (Special Opcodes)");
7308 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7309 "Line Range Value (Special Opcodes)");
7310 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7311 "Special Opcode Base");
7313 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7315 switch (opc)
7317 case DW_LNS_advance_pc:
7318 case DW_LNS_advance_line:
7319 case DW_LNS_set_file:
7320 case DW_LNS_set_column:
7321 case DW_LNS_fixed_advance_pc:
7322 n_op_args = 1;
7323 break;
7324 default:
7325 n_op_args = 0;
7326 break;
7329 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7330 opc, n_op_args);
7333 /* Write out the information about the files we use. */
7334 output_file_names ();
7335 ASM_OUTPUT_LABEL (asm_out_file, p2);
7337 /* We used to set the address register to the first location in the text
7338 section here, but that didn't accomplish anything since we already
7339 have a line note for the opening brace of the first function. */
7341 /* Generate the line number to PC correspondence table, encoded as
7342 a series of state machine operations. */
7343 current_file = 1;
7344 current_line = 1;
7345 strcpy (prev_line_label, text_section_label);
7346 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7348 dw_line_info_ref line_info = &line_info_table[lt_index];
7350 #if 0
7351 /* Disable this optimization for now; GDB wants to see two line notes
7352 at the beginning of a function so it can find the end of the
7353 prologue. */
7355 /* Don't emit anything for redundant notes. Just updating the
7356 address doesn't accomplish anything, because we already assume
7357 that anything after the last address is this line. */
7358 if (line_info->dw_line_num == current_line
7359 && line_info->dw_file_num == current_file)
7360 continue;
7361 #endif
7363 /* Emit debug info for the address of the current line.
7365 Unfortunately, we have little choice here currently, and must always
7366 use the most general form. GCC does not know the address delta
7367 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7368 attributes which will give an upper bound on the address range. We
7369 could perhaps use length attributes to determine when it is safe to
7370 use DW_LNS_fixed_advance_pc. */
7372 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7373 if (0)
7375 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7376 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7377 "DW_LNS_fixed_advance_pc");
7378 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7380 else
7382 /* This can handle any delta. This takes
7383 4+DWARF2_ADDR_SIZE bytes. */
7384 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7385 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7386 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7387 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7390 strcpy (prev_line_label, line_label);
7392 /* Emit debug info for the source file of the current line, if
7393 different from the previous line. */
7394 if (line_info->dw_file_num != current_file)
7396 current_file = line_info->dw_file_num;
7397 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7398 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7399 VARRAY_CHAR_PTR (file_table,
7400 current_file));
7403 /* Emit debug info for the current line number, choosing the encoding
7404 that uses the least amount of space. */
7405 if (line_info->dw_line_num != current_line)
7407 line_offset = line_info->dw_line_num - current_line;
7408 line_delta = line_offset - DWARF_LINE_BASE;
7409 current_line = line_info->dw_line_num;
7410 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7411 /* This can handle deltas from -10 to 234, using the current
7412 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7413 takes 1 byte. */
7414 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7415 "line %lu", current_line);
7416 else
7418 /* This can handle any delta. This takes at least 4 bytes,
7419 depending on the value being encoded. */
7420 dw2_asm_output_data (1, DW_LNS_advance_line,
7421 "advance to line %lu", current_line);
7422 dw2_asm_output_data_sleb128 (line_offset, NULL);
7423 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7426 else
7427 /* We still need to start a new row, so output a copy insn. */
7428 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7431 /* Emit debug info for the address of the end of the function. */
7432 if (0)
7434 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7435 "DW_LNS_fixed_advance_pc");
7436 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7438 else
7440 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7441 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7442 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7443 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7446 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7447 dw2_asm_output_data_uleb128 (1, NULL);
7448 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7450 function = 0;
7451 current_file = 1;
7452 current_line = 1;
7453 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7455 dw_separate_line_info_ref line_info
7456 = &separate_line_info_table[lt_index];
7458 #if 0
7459 /* Don't emit anything for redundant notes. */
7460 if (line_info->dw_line_num == current_line
7461 && line_info->dw_file_num == current_file
7462 && line_info->function == function)
7463 goto cont;
7464 #endif
7466 /* Emit debug info for the address of the current line. If this is
7467 a new function, or the first line of a function, then we need
7468 to handle it differently. */
7469 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7470 lt_index);
7471 if (function != line_info->function)
7473 function = line_info->function;
7475 /* Set the address register to the first line in the function. */
7476 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7477 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7478 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7479 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7481 else
7483 /* ??? See the DW_LNS_advance_pc comment above. */
7484 if (0)
7486 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7487 "DW_LNS_fixed_advance_pc");
7488 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7490 else
7492 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7493 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7494 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7495 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7499 strcpy (prev_line_label, line_label);
7501 /* Emit debug info for the source file of the current line, if
7502 different from the previous line. */
7503 if (line_info->dw_file_num != current_file)
7505 current_file = line_info->dw_file_num;
7506 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7507 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7508 VARRAY_CHAR_PTR (file_table,
7509 current_file));
7512 /* Emit debug info for the current line number, choosing the encoding
7513 that uses the least amount of space. */
7514 if (line_info->dw_line_num != current_line)
7516 line_offset = line_info->dw_line_num - current_line;
7517 line_delta = line_offset - DWARF_LINE_BASE;
7518 current_line = line_info->dw_line_num;
7519 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7520 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7521 "line %lu", current_line);
7522 else
7524 dw2_asm_output_data (1, DW_LNS_advance_line,
7525 "advance to line %lu", current_line);
7526 dw2_asm_output_data_sleb128 (line_offset, NULL);
7527 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7530 else
7531 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7533 #if 0
7534 cont:
7535 #endif
7537 lt_index++;
7539 /* If we're done with a function, end its sequence. */
7540 if (lt_index == separate_line_info_table_in_use
7541 || separate_line_info_table[lt_index].function != function)
7543 current_file = 1;
7544 current_line = 1;
7546 /* Emit debug info for the address of the end of the function. */
7547 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7548 if (0)
7550 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7551 "DW_LNS_fixed_advance_pc");
7552 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7554 else
7556 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7557 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7558 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7559 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7562 /* Output the marker for the end of this sequence. */
7563 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7564 dw2_asm_output_data_uleb128 (1, NULL);
7565 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7569 /* Output the marker for the end of the line number info. */
7570 ASM_OUTPUT_LABEL (asm_out_file, l2);
7573 /* Given a pointer to a tree node for some base type, return a pointer to
7574 a DIE that describes the given type.
7576 This routine must only be called for GCC type nodes that correspond to
7577 Dwarf base (fundamental) types. */
7579 static dw_die_ref
7580 base_type_die (tree type)
7582 dw_die_ref base_type_result;
7583 const char *type_name;
7584 enum dwarf_type encoding;
7585 tree name = TYPE_NAME (type);
7587 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7588 return 0;
7590 if (name)
7592 if (TREE_CODE (name) == TYPE_DECL)
7593 name = DECL_NAME (name);
7595 type_name = IDENTIFIER_POINTER (name);
7597 else
7598 type_name = "__unknown__";
7600 switch (TREE_CODE (type))
7602 case INTEGER_TYPE:
7603 /* Carefully distinguish the C character types, without messing
7604 up if the language is not C. Note that we check only for the names
7605 that contain spaces; other names might occur by coincidence in other
7606 languages. */
7607 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7608 && (type == char_type_node
7609 || ! strcmp (type_name, "signed char")
7610 || ! strcmp (type_name, "unsigned char"))))
7612 if (TREE_UNSIGNED (type))
7613 encoding = DW_ATE_unsigned;
7614 else
7615 encoding = DW_ATE_signed;
7616 break;
7618 /* else fall through. */
7620 case CHAR_TYPE:
7621 /* GNU Pascal/Ada CHAR type. Not used in C. */
7622 if (TREE_UNSIGNED (type))
7623 encoding = DW_ATE_unsigned_char;
7624 else
7625 encoding = DW_ATE_signed_char;
7626 break;
7628 case REAL_TYPE:
7629 encoding = DW_ATE_float;
7630 break;
7632 /* Dwarf2 doesn't know anything about complex ints, so use
7633 a user defined type for it. */
7634 case COMPLEX_TYPE:
7635 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7636 encoding = DW_ATE_complex_float;
7637 else
7638 encoding = DW_ATE_lo_user;
7639 break;
7641 case BOOLEAN_TYPE:
7642 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7643 encoding = DW_ATE_boolean;
7644 break;
7646 default:
7647 /* No other TREE_CODEs are Dwarf fundamental types. */
7648 abort ();
7651 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
7652 if (demangle_name_func)
7653 type_name = (*demangle_name_func) (type_name);
7655 add_AT_string (base_type_result, DW_AT_name, type_name);
7656 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7657 int_size_in_bytes (type));
7658 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7660 return base_type_result;
7663 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7664 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7665 a given type is generally the same as the given type, except that if the
7666 given type is a pointer or reference type, then the root type of the given
7667 type is the root type of the "basis" type for the pointer or reference
7668 type. (This definition of the "root" type is recursive.) Also, the root
7669 type of a `const' qualified type or a `volatile' qualified type is the
7670 root type of the given type without the qualifiers. */
7672 static tree
7673 root_type (tree type)
7675 if (TREE_CODE (type) == ERROR_MARK)
7676 return error_mark_node;
7678 switch (TREE_CODE (type))
7680 case ERROR_MARK:
7681 return error_mark_node;
7683 case POINTER_TYPE:
7684 case REFERENCE_TYPE:
7685 return type_main_variant (root_type (TREE_TYPE (type)));
7687 default:
7688 return type_main_variant (type);
7692 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
7693 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7695 static inline int
7696 is_base_type (tree type)
7698 switch (TREE_CODE (type))
7700 case ERROR_MARK:
7701 case VOID_TYPE:
7702 case INTEGER_TYPE:
7703 case REAL_TYPE:
7704 case COMPLEX_TYPE:
7705 case BOOLEAN_TYPE:
7706 case CHAR_TYPE:
7707 return 1;
7709 case SET_TYPE:
7710 case ARRAY_TYPE:
7711 case RECORD_TYPE:
7712 case UNION_TYPE:
7713 case QUAL_UNION_TYPE:
7714 case ENUMERAL_TYPE:
7715 case FUNCTION_TYPE:
7716 case METHOD_TYPE:
7717 case POINTER_TYPE:
7718 case REFERENCE_TYPE:
7719 case FILE_TYPE:
7720 case OFFSET_TYPE:
7721 case LANG_TYPE:
7722 case VECTOR_TYPE:
7723 return 0;
7725 default:
7726 abort ();
7729 return 0;
7732 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7733 node, return the size in bits for the type if it is a constant, or else
7734 return the alignment for the type if the type's size is not constant, or
7735 else return BITS_PER_WORD if the type actually turns out to be an
7736 ERROR_MARK node. */
7738 static inline unsigned HOST_WIDE_INT
7739 simple_type_size_in_bits (tree type)
7741 if (TREE_CODE (type) == ERROR_MARK)
7742 return BITS_PER_WORD;
7743 else if (TYPE_SIZE (type) == NULL_TREE)
7744 return 0;
7745 else if (host_integerp (TYPE_SIZE (type), 1))
7746 return tree_low_cst (TYPE_SIZE (type), 1);
7747 else
7748 return TYPE_ALIGN (type);
7751 /* Return true if the debug information for the given type should be
7752 emitted as a subrange type. */
7754 static inline bool
7755 is_ada_subrange_type (tree type)
7757 /* We do this for INTEGER_TYPEs that have names, parent types, and when
7758 we are compiling Ada code. */
7759 return (TREE_CODE (type) == INTEGER_TYPE
7760 && TYPE_NAME (type) != 0 && TREE_TYPE (type) != 0
7761 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE
7762 && TREE_UNSIGNED (TREE_TYPE (type)) && is_ada ());
7765 /* Given a pointer to a tree node for a subrange type, return a pointer
7766 to a DIE that describes the given type. */
7768 static dw_die_ref
7769 subrange_type_die (tree type)
7771 dw_die_ref subtype_die;
7772 dw_die_ref subrange_die;
7773 tree name = TYPE_NAME (type);
7775 subtype_die = base_type_die (TREE_TYPE (type));
7777 if (TREE_CODE (name) == TYPE_DECL)
7778 name = DECL_NAME (name);
7780 subrange_die = new_die (DW_TAG_subrange_type, comp_unit_die, type);
7781 add_name_attribute (subrange_die, IDENTIFIER_POINTER (name));
7782 if (TYPE_MIN_VALUE (type) != NULL)
7783 add_bound_info (subrange_die, DW_AT_lower_bound,
7784 TYPE_MIN_VALUE (type));
7785 if (TYPE_MAX_VALUE (type) != NULL)
7786 add_bound_info (subrange_die, DW_AT_upper_bound,
7787 TYPE_MAX_VALUE (type));
7788 add_AT_die_ref (subrange_die, DW_AT_type, subtype_die);
7790 return subrange_die;
7793 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7794 entry that chains various modifiers in front of the given type. */
7796 static dw_die_ref
7797 modified_type_die (tree type, int is_const_type, int is_volatile_type,
7798 dw_die_ref context_die)
7800 enum tree_code code = TREE_CODE (type);
7801 dw_die_ref mod_type_die = NULL;
7802 dw_die_ref sub_die = NULL;
7803 tree item_type = NULL;
7805 if (code != ERROR_MARK)
7807 tree qualified_type;
7809 /* See if we already have the appropriately qualified variant of
7810 this type. */
7811 qualified_type
7812 = get_qualified_type (type,
7813 ((is_const_type ? TYPE_QUAL_CONST : 0)
7814 | (is_volatile_type
7815 ? TYPE_QUAL_VOLATILE : 0)));
7817 /* If we do, then we can just use its DIE, if it exists. */
7818 if (qualified_type)
7820 mod_type_die = lookup_type_die (qualified_type);
7821 if (mod_type_die)
7822 return mod_type_die;
7825 /* Handle C typedef types. */
7826 if (qualified_type && TYPE_NAME (qualified_type)
7827 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7828 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7830 tree type_name = TYPE_NAME (qualified_type);
7831 tree dtype = TREE_TYPE (type_name);
7833 if (qualified_type == dtype)
7835 /* For a named type, use the typedef. */
7836 gen_type_die (qualified_type, context_die);
7837 mod_type_die = lookup_type_die (qualified_type);
7839 else if (is_const_type < TYPE_READONLY (dtype)
7840 || is_volatile_type < TYPE_VOLATILE (dtype))
7841 /* cv-unqualified version of named type. Just use the unnamed
7842 type to which it refers. */
7843 mod_type_die
7844 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7845 is_const_type, is_volatile_type,
7846 context_die);
7848 /* Else cv-qualified version of named type; fall through. */
7851 if (mod_type_die)
7852 /* OK. */
7854 else if (is_const_type)
7856 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
7857 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7859 else if (is_volatile_type)
7861 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
7862 sub_die = modified_type_die (type, 0, 0, context_die);
7864 else if (code == POINTER_TYPE)
7866 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
7867 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
7868 simple_type_size_in_bits (type) / BITS_PER_UNIT);
7869 #if 0
7870 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7871 #endif
7872 item_type = TREE_TYPE (type);
7874 else if (code == REFERENCE_TYPE)
7876 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
7877 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
7878 simple_type_size_in_bits (type) / BITS_PER_UNIT);
7879 #if 0
7880 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7881 #endif
7882 item_type = TREE_TYPE (type);
7884 else if (is_ada_subrange_type (type))
7885 mod_type_die = subrange_type_die (type);
7886 else if (is_base_type (type))
7887 mod_type_die = base_type_die (type);
7888 else
7890 gen_type_die (type, context_die);
7892 /* We have to get the type_main_variant here (and pass that to the
7893 `lookup_type_die' routine) because the ..._TYPE node we have
7894 might simply be a *copy* of some original type node (where the
7895 copy was created to help us keep track of typedef names) and
7896 that copy might have a different TYPE_UID from the original
7897 ..._TYPE node. */
7898 if (TREE_CODE (type) != VECTOR_TYPE)
7899 mod_type_die = lookup_type_die (type_main_variant (type));
7900 else
7901 /* Vectors have the debugging information in the type,
7902 not the main variant. */
7903 mod_type_die = lookup_type_die (type);
7904 if (mod_type_die == NULL)
7905 abort ();
7908 /* We want to equate the qualified type to the die below. */
7909 type = qualified_type;
7912 if (type)
7913 equate_type_number_to_die (type, mod_type_die);
7914 if (item_type)
7915 /* We must do this after the equate_type_number_to_die call, in case
7916 this is a recursive type. This ensures that the modified_type_die
7917 recursion will terminate even if the type is recursive. Recursive
7918 types are possible in Ada. */
7919 sub_die = modified_type_die (item_type,
7920 TYPE_READONLY (item_type),
7921 TYPE_VOLATILE (item_type),
7922 context_die);
7924 if (sub_die != NULL)
7925 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7927 return mod_type_die;
7930 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7931 an enumerated type. */
7933 static inline int
7934 type_is_enum (tree type)
7936 return TREE_CODE (type) == ENUMERAL_TYPE;
7939 /* Return the register number described by a given RTL node. */
7941 static unsigned int
7942 reg_number (rtx rtl)
7944 unsigned regno = REGNO (rtl);
7946 if (regno >= FIRST_PSEUDO_REGISTER)
7947 abort ();
7949 return DBX_REGISTER_NUMBER (regno);
7952 /* Return a location descriptor that designates a machine register or
7953 zero if there is none. */
7955 static dw_loc_descr_ref
7956 reg_loc_descriptor (rtx rtl)
7958 unsigned reg;
7959 rtx regs;
7961 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7962 return 0;
7964 reg = reg_number (rtl);
7965 regs = (*targetm.dwarf_register_span) (rtl);
7967 if (HARD_REGNO_NREGS (reg, GET_MODE (rtl)) > 1
7968 || regs)
7969 return multiple_reg_loc_descriptor (rtl, regs);
7970 else
7971 return one_reg_loc_descriptor (reg);
7974 /* Return a location descriptor that designates a machine register for
7975 a given hard register number. */
7977 static dw_loc_descr_ref
7978 one_reg_loc_descriptor (unsigned int regno)
7980 if (regno <= 31)
7981 return new_loc_descr (DW_OP_reg0 + regno, 0, 0);
7982 else
7983 return new_loc_descr (DW_OP_regx, regno, 0);
7986 /* Given an RTL of a register, return a location descriptor that
7987 designates a value that spans more than one register. */
7989 static dw_loc_descr_ref
7990 multiple_reg_loc_descriptor (rtx rtl, rtx regs)
7992 int nregs, size, i;
7993 unsigned reg;
7994 dw_loc_descr_ref loc_result = NULL;
7996 reg = reg_number (rtl);
7997 nregs = HARD_REGNO_NREGS (reg, GET_MODE (rtl));
7999 /* Simple, contiguous registers. */
8000 if (regs == NULL_RTX)
8002 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
8004 loc_result = NULL;
8005 while (nregs--)
8007 dw_loc_descr_ref t;
8009 t = one_reg_loc_descriptor (reg);
8010 add_loc_descr (&loc_result, t);
8011 add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0));
8012 ++reg;
8014 return loc_result;
8017 /* Now onto stupid register sets in non contiguous locations. */
8019 if (GET_CODE (regs) != PARALLEL)
8020 abort ();
8022 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8023 loc_result = NULL;
8025 for (i = 0; i < XVECLEN (regs, 0); ++i)
8027 dw_loc_descr_ref t;
8029 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)));
8030 add_loc_descr (&loc_result, t);
8031 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8032 add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0));
8034 return loc_result;
8037 /* Return a location descriptor that designates a constant. */
8039 static dw_loc_descr_ref
8040 int_loc_descriptor (HOST_WIDE_INT i)
8042 enum dwarf_location_atom op;
8044 /* Pick the smallest representation of a constant, rather than just
8045 defaulting to the LEB encoding. */
8046 if (i >= 0)
8048 if (i <= 31)
8049 op = DW_OP_lit0 + i;
8050 else if (i <= 0xff)
8051 op = DW_OP_const1u;
8052 else if (i <= 0xffff)
8053 op = DW_OP_const2u;
8054 else if (HOST_BITS_PER_WIDE_INT == 32
8055 || i <= 0xffffffff)
8056 op = DW_OP_const4u;
8057 else
8058 op = DW_OP_constu;
8060 else
8062 if (i >= -0x80)
8063 op = DW_OP_const1s;
8064 else if (i >= -0x8000)
8065 op = DW_OP_const2s;
8066 else if (HOST_BITS_PER_WIDE_INT == 32
8067 || i >= -0x80000000)
8068 op = DW_OP_const4s;
8069 else
8070 op = DW_OP_consts;
8073 return new_loc_descr (op, i, 0);
8076 /* Return a location descriptor that designates a base+offset location. */
8078 static dw_loc_descr_ref
8079 based_loc_descr (unsigned int reg, long int offset)
8081 dw_loc_descr_ref loc_result;
8082 /* For the "frame base", we use the frame pointer or stack pointer
8083 registers, since the RTL for local variables is relative to one of
8084 them. */
8085 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
8086 ? HARD_FRAME_POINTER_REGNUM
8087 : STACK_POINTER_REGNUM);
8089 if (reg == fp_reg)
8090 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
8091 else if (reg <= 31)
8092 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
8093 else
8094 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
8096 return loc_result;
8099 /* Return true if this RTL expression describes a base+offset calculation. */
8101 static inline int
8102 is_based_loc (rtx rtl)
8104 return (GET_CODE (rtl) == PLUS
8105 && ((GET_CODE (XEXP (rtl, 0)) == REG
8106 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
8107 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
8110 /* The following routine converts the RTL for a variable or parameter
8111 (resident in memory) into an equivalent Dwarf representation of a
8112 mechanism for getting the address of that same variable onto the top of a
8113 hypothetical "address evaluation" stack.
8115 When creating memory location descriptors, we are effectively transforming
8116 the RTL for a memory-resident object into its Dwarf postfix expression
8117 equivalent. This routine recursively descends an RTL tree, turning
8118 it into Dwarf postfix code as it goes.
8120 MODE is the mode of the memory reference, needed to handle some
8121 autoincrement addressing modes.
8123 Return 0 if we can't represent the location. */
8125 static dw_loc_descr_ref
8126 mem_loc_descriptor (rtx rtl, enum machine_mode mode)
8128 dw_loc_descr_ref mem_loc_result = NULL;
8130 /* Note that for a dynamically sized array, the location we will generate a
8131 description of here will be the lowest numbered location which is
8132 actually within the array. That's *not* necessarily the same as the
8133 zeroth element of the array. */
8135 rtl = (*targetm.delegitimize_address) (rtl);
8137 switch (GET_CODE (rtl))
8139 case POST_INC:
8140 case POST_DEC:
8141 case POST_MODIFY:
8142 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8143 just fall into the SUBREG code. */
8145 /* ... fall through ... */
8147 case SUBREG:
8148 /* The case of a subreg may arise when we have a local (register)
8149 variable or a formal (register) parameter which doesn't quite fill
8150 up an entire register. For now, just assume that it is
8151 legitimate to make the Dwarf info refer to the whole register which
8152 contains the given subreg. */
8153 rtl = SUBREG_REG (rtl);
8155 /* ... fall through ... */
8157 case REG:
8158 /* Whenever a register number forms a part of the description of the
8159 method for calculating the (dynamic) address of a memory resident
8160 object, DWARF rules require the register number be referred to as
8161 a "base register". This distinction is not based in any way upon
8162 what category of register the hardware believes the given register
8163 belongs to. This is strictly DWARF terminology we're dealing with
8164 here. Note that in cases where the location of a memory-resident
8165 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8166 OP_CONST (0)) the actual DWARF location descriptor that we generate
8167 may just be OP_BASEREG (basereg). This may look deceptively like
8168 the object in question was allocated to a register (rather than in
8169 memory) so DWARF consumers need to be aware of the subtle
8170 distinction between OP_REG and OP_BASEREG. */
8171 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
8172 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
8173 break;
8175 case MEM:
8176 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8177 if (mem_loc_result != 0)
8178 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
8179 break;
8181 case LO_SUM:
8182 rtl = XEXP (rtl, 1);
8184 /* ... fall through ... */
8186 case LABEL_REF:
8187 /* Some ports can transform a symbol ref into a label ref, because
8188 the symbol ref is too far away and has to be dumped into a constant
8189 pool. */
8190 case CONST:
8191 case SYMBOL_REF:
8192 /* Alternatively, the symbol in the constant pool might be referenced
8193 by a different symbol. */
8194 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
8196 bool marked;
8197 rtx tmp = get_pool_constant_mark (rtl, &marked);
8199 if (GET_CODE (tmp) == SYMBOL_REF)
8201 rtl = tmp;
8202 if (CONSTANT_POOL_ADDRESS_P (tmp))
8203 get_pool_constant_mark (tmp, &marked);
8204 else
8205 marked = true;
8208 /* If all references to this pool constant were optimized away,
8209 it was not output and thus we can't represent it.
8210 FIXME: might try to use DW_OP_const_value here, though
8211 DW_OP_piece complicates it. */
8212 if (!marked)
8213 return 0;
8216 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
8217 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
8218 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
8219 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
8220 break;
8222 case PRE_MODIFY:
8223 /* Extract the PLUS expression nested inside and fall into
8224 PLUS code below. */
8225 rtl = XEXP (rtl, 1);
8226 goto plus;
8228 case PRE_INC:
8229 case PRE_DEC:
8230 /* Turn these into a PLUS expression and fall into the PLUS code
8231 below. */
8232 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
8233 GEN_INT (GET_CODE (rtl) == PRE_INC
8234 ? GET_MODE_UNIT_SIZE (mode)
8235 : -GET_MODE_UNIT_SIZE (mode)));
8237 /* ... fall through ... */
8239 case PLUS:
8240 plus:
8241 if (is_based_loc (rtl))
8242 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
8243 INTVAL (XEXP (rtl, 1)));
8244 else
8246 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
8247 if (mem_loc_result == 0)
8248 break;
8250 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
8251 && INTVAL (XEXP (rtl, 1)) >= 0)
8252 add_loc_descr (&mem_loc_result,
8253 new_loc_descr (DW_OP_plus_uconst,
8254 INTVAL (XEXP (rtl, 1)), 0));
8255 else
8257 add_loc_descr (&mem_loc_result,
8258 mem_loc_descriptor (XEXP (rtl, 1), mode));
8259 add_loc_descr (&mem_loc_result,
8260 new_loc_descr (DW_OP_plus, 0, 0));
8263 break;
8265 case MULT:
8267 /* If a pseudo-reg is optimized away, it is possible for it to
8268 be replaced with a MEM containing a multiply. */
8269 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
8270 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
8272 if (op0 == 0 || op1 == 0)
8273 break;
8275 mem_loc_result = op0;
8276 add_loc_descr (&mem_loc_result, op1);
8277 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
8278 break;
8281 case CONST_INT:
8282 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
8283 break;
8285 case ADDRESSOF:
8286 /* If this is a MEM, return its address. Otherwise, we can't
8287 represent this. */
8288 if (GET_CODE (XEXP (rtl, 0)) == MEM)
8289 return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode);
8290 else
8291 return 0;
8293 default:
8294 abort ();
8297 return mem_loc_result;
8300 /* Return a descriptor that describes the concatenation of two locations.
8301 This is typically a complex variable. */
8303 static dw_loc_descr_ref
8304 concat_loc_descriptor (rtx x0, rtx x1)
8306 dw_loc_descr_ref cc_loc_result = NULL;
8307 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
8308 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
8310 if (x0_ref == 0 || x1_ref == 0)
8311 return 0;
8313 cc_loc_result = x0_ref;
8314 add_loc_descr (&cc_loc_result,
8315 new_loc_descr (DW_OP_piece,
8316 GET_MODE_SIZE (GET_MODE (x0)), 0));
8318 add_loc_descr (&cc_loc_result, x1_ref);
8319 add_loc_descr (&cc_loc_result,
8320 new_loc_descr (DW_OP_piece,
8321 GET_MODE_SIZE (GET_MODE (x1)), 0));
8323 return cc_loc_result;
8326 /* Output a proper Dwarf location descriptor for a variable or parameter
8327 which is either allocated in a register or in a memory location. For a
8328 register, we just generate an OP_REG and the register number. For a
8329 memory location we provide a Dwarf postfix expression describing how to
8330 generate the (dynamic) address of the object onto the address stack.
8332 If we don't know how to describe it, return 0. */
8334 static dw_loc_descr_ref
8335 loc_descriptor (rtx rtl)
8337 dw_loc_descr_ref loc_result = NULL;
8339 switch (GET_CODE (rtl))
8341 case SUBREG:
8342 /* The case of a subreg may arise when we have a local (register)
8343 variable or a formal (register) parameter which doesn't quite fill
8344 up an entire register. For now, just assume that it is
8345 legitimate to make the Dwarf info refer to the whole register which
8346 contains the given subreg. */
8347 rtl = SUBREG_REG (rtl);
8349 /* ... fall through ... */
8351 case REG:
8352 loc_result = reg_loc_descriptor (rtl);
8353 break;
8355 case MEM:
8356 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8357 break;
8359 case CONCAT:
8360 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8361 break;
8363 default:
8364 abort ();
8367 return loc_result;
8370 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8371 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8372 looking for an address. Otherwise, we return a value. If we can't make a
8373 descriptor, return 0. */
8375 static dw_loc_descr_ref
8376 loc_descriptor_from_tree (tree loc, int addressp)
8378 dw_loc_descr_ref ret, ret1;
8379 int indirect_p = 0;
8380 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
8381 enum dwarf_location_atom op;
8383 /* ??? Most of the time we do not take proper care for sign/zero
8384 extending the values properly. Hopefully this won't be a real
8385 problem... */
8387 switch (TREE_CODE (loc))
8389 case ERROR_MARK:
8390 return 0;
8392 case WITH_RECORD_EXPR:
8393 case PLACEHOLDER_EXPR:
8394 /* This case involves extracting fields from an object to determine the
8395 position of other fields. We don't try to encode this here. The
8396 only user of this is Ada, which encodes the needed information using
8397 the names of types. */
8398 return 0;
8400 case CALL_EXPR:
8401 return 0;
8403 case ADDR_EXPR:
8404 /* We can support this only if we can look through conversions and
8405 find an INDIRECT_EXPR. */
8406 for (loc = TREE_OPERAND (loc, 0);
8407 TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR
8408 || TREE_CODE (loc) == NON_LVALUE_EXPR
8409 || TREE_CODE (loc) == VIEW_CONVERT_EXPR
8410 || TREE_CODE (loc) == SAVE_EXPR;
8411 loc = TREE_OPERAND (loc, 0))
8414 return (TREE_CODE (loc) == INDIRECT_REF
8415 ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp)
8416 : 0);
8418 case VAR_DECL:
8419 if (DECL_THREAD_LOCAL (loc))
8421 rtx rtl;
8423 #ifndef ASM_OUTPUT_DWARF_DTPREL
8424 /* If this is not defined, we have no way to emit the data. */
8425 return 0;
8426 #endif
8428 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8429 look up addresses of objects in the current module. */
8430 if (DECL_EXTERNAL (loc))
8431 return 0;
8433 rtl = rtl_for_decl_location (loc);
8434 if (rtl == NULL_RTX)
8435 return 0;
8437 if (GET_CODE (rtl) != MEM)
8438 return 0;
8439 rtl = XEXP (rtl, 0);
8440 if (! CONSTANT_P (rtl))
8441 return 0;
8443 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
8444 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8445 ret->dw_loc_oprnd1.v.val_addr = rtl;
8447 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
8448 add_loc_descr (&ret, ret1);
8450 indirect_p = 1;
8451 break;
8453 /* FALLTHRU */
8455 case PARM_DECL:
8457 rtx rtl = rtl_for_decl_location (loc);
8459 if (rtl == NULL_RTX)
8460 return 0;
8461 else if (CONSTANT_P (rtl))
8463 ret = new_loc_descr (DW_OP_addr, 0, 0);
8464 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8465 ret->dw_loc_oprnd1.v.val_addr = rtl;
8466 indirect_p = 1;
8468 else
8470 enum machine_mode mode = GET_MODE (rtl);
8472 if (GET_CODE (rtl) == MEM)
8474 indirect_p = 1;
8475 rtl = XEXP (rtl, 0);
8478 ret = mem_loc_descriptor (rtl, mode);
8481 break;
8483 case INDIRECT_REF:
8484 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8485 indirect_p = 1;
8486 break;
8488 case COMPOUND_EXPR:
8489 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
8491 case NOP_EXPR:
8492 case CONVERT_EXPR:
8493 case NON_LVALUE_EXPR:
8494 case VIEW_CONVERT_EXPR:
8495 case SAVE_EXPR:
8496 case MODIFY_EXPR:
8497 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8499 case COMPONENT_REF:
8500 case BIT_FIELD_REF:
8501 case ARRAY_REF:
8502 case ARRAY_RANGE_REF:
8504 tree obj, offset;
8505 HOST_WIDE_INT bitsize, bitpos, bytepos;
8506 enum machine_mode mode;
8507 int volatilep;
8509 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8510 &unsignedp, &volatilep);
8512 if (obj == loc)
8513 return 0;
8515 ret = loc_descriptor_from_tree (obj, 1);
8516 if (ret == 0
8517 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
8518 return 0;
8520 if (offset != NULL_TREE)
8522 /* Variable offset. */
8523 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8524 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8527 if (!addressp)
8528 indirect_p = 1;
8530 bytepos = bitpos / BITS_PER_UNIT;
8531 if (bytepos > 0)
8532 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8533 else if (bytepos < 0)
8535 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8536 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8538 break;
8541 case INTEGER_CST:
8542 if (host_integerp (loc, 0))
8543 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8544 else
8545 return 0;
8546 break;
8548 case TRUTH_AND_EXPR:
8549 case TRUTH_ANDIF_EXPR:
8550 case BIT_AND_EXPR:
8551 op = DW_OP_and;
8552 goto do_binop;
8554 case TRUTH_XOR_EXPR:
8555 case BIT_XOR_EXPR:
8556 op = DW_OP_xor;
8557 goto do_binop;
8559 case TRUTH_OR_EXPR:
8560 case TRUTH_ORIF_EXPR:
8561 case BIT_IOR_EXPR:
8562 op = DW_OP_or;
8563 goto do_binop;
8565 case FLOOR_DIV_EXPR:
8566 case CEIL_DIV_EXPR:
8567 case ROUND_DIV_EXPR:
8568 case TRUNC_DIV_EXPR:
8569 op = DW_OP_div;
8570 goto do_binop;
8572 case MINUS_EXPR:
8573 op = DW_OP_minus;
8574 goto do_binop;
8576 case FLOOR_MOD_EXPR:
8577 case CEIL_MOD_EXPR:
8578 case ROUND_MOD_EXPR:
8579 case TRUNC_MOD_EXPR:
8580 op = DW_OP_mod;
8581 goto do_binop;
8583 case MULT_EXPR:
8584 op = DW_OP_mul;
8585 goto do_binop;
8587 case LSHIFT_EXPR:
8588 op = DW_OP_shl;
8589 goto do_binop;
8591 case RSHIFT_EXPR:
8592 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8593 goto do_binop;
8595 case PLUS_EXPR:
8596 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8597 && host_integerp (TREE_OPERAND (loc, 1), 0))
8599 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8600 if (ret == 0)
8601 return 0;
8603 add_loc_descr (&ret,
8604 new_loc_descr (DW_OP_plus_uconst,
8605 tree_low_cst (TREE_OPERAND (loc, 1),
8607 0));
8608 break;
8611 op = DW_OP_plus;
8612 goto do_binop;
8614 case LE_EXPR:
8615 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8616 return 0;
8618 op = DW_OP_le;
8619 goto do_binop;
8621 case GE_EXPR:
8622 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8623 return 0;
8625 op = DW_OP_ge;
8626 goto do_binop;
8628 case LT_EXPR:
8629 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8630 return 0;
8632 op = DW_OP_lt;
8633 goto do_binop;
8635 case GT_EXPR:
8636 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8637 return 0;
8639 op = DW_OP_gt;
8640 goto do_binop;
8642 case EQ_EXPR:
8643 op = DW_OP_eq;
8644 goto do_binop;
8646 case NE_EXPR:
8647 op = DW_OP_ne;
8648 goto do_binop;
8650 do_binop:
8651 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8652 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8653 if (ret == 0 || ret1 == 0)
8654 return 0;
8656 add_loc_descr (&ret, ret1);
8657 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8658 break;
8660 case TRUTH_NOT_EXPR:
8661 case BIT_NOT_EXPR:
8662 op = DW_OP_not;
8663 goto do_unop;
8665 case ABS_EXPR:
8666 op = DW_OP_abs;
8667 goto do_unop;
8669 case NEGATE_EXPR:
8670 op = DW_OP_neg;
8671 goto do_unop;
8673 do_unop:
8674 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8675 if (ret == 0)
8676 return 0;
8678 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8679 break;
8681 case MAX_EXPR:
8682 loc = build (COND_EXPR, TREE_TYPE (loc),
8683 build (LT_EXPR, integer_type_node,
8684 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8685 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8687 /* ... fall through ... */
8689 case COND_EXPR:
8691 dw_loc_descr_ref lhs
8692 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8693 dw_loc_descr_ref rhs
8694 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8695 dw_loc_descr_ref bra_node, jump_node, tmp;
8697 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8698 if (ret == 0 || lhs == 0 || rhs == 0)
8699 return 0;
8701 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8702 add_loc_descr (&ret, bra_node);
8704 add_loc_descr (&ret, rhs);
8705 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8706 add_loc_descr (&ret, jump_node);
8708 add_loc_descr (&ret, lhs);
8709 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8710 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
8712 /* ??? Need a node to point the skip at. Use a nop. */
8713 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8714 add_loc_descr (&ret, tmp);
8715 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8716 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8718 break;
8720 default:
8721 /* Leave front-end specific codes as simply unknown. This comes
8722 up, for instance, with the C STMT_EXPR. */
8723 if ((unsigned int) TREE_CODE (loc)
8724 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
8725 return 0;
8727 /* Otherwise this is a generic code; we should just lists all of
8728 these explicitly. Aborting means we forgot one. */
8729 abort ();
8732 /* Show if we can't fill the request for an address. */
8733 if (addressp && indirect_p == 0)
8734 return 0;
8736 /* If we've got an address and don't want one, dereference. */
8737 if (!addressp && indirect_p > 0)
8739 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8741 if (size > DWARF2_ADDR_SIZE || size == -1)
8742 return 0;
8743 else if (size == DWARF2_ADDR_SIZE)
8744 op = DW_OP_deref;
8745 else
8746 op = DW_OP_deref_size;
8748 add_loc_descr (&ret, new_loc_descr (op, size, 0));
8751 return ret;
8754 /* Given a value, round it up to the lowest multiple of `boundary'
8755 which is not less than the value itself. */
8757 static inline HOST_WIDE_INT
8758 ceiling (HOST_WIDE_INT value, unsigned int boundary)
8760 return (((value + boundary - 1) / boundary) * boundary);
8763 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8764 pointer to the declared type for the relevant field variable, or return
8765 `integer_type_node' if the given node turns out to be an
8766 ERROR_MARK node. */
8768 static inline tree
8769 field_type (tree decl)
8771 tree type;
8773 if (TREE_CODE (decl) == ERROR_MARK)
8774 return integer_type_node;
8776 type = DECL_BIT_FIELD_TYPE (decl);
8777 if (type == NULL_TREE)
8778 type = TREE_TYPE (decl);
8780 return type;
8783 /* Given a pointer to a tree node, return the alignment in bits for
8784 it, or else return BITS_PER_WORD if the node actually turns out to
8785 be an ERROR_MARK node. */
8787 static inline unsigned
8788 simple_type_align_in_bits (tree type)
8790 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8793 static inline unsigned
8794 simple_decl_align_in_bits (tree decl)
8796 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8799 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8800 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8801 or return 0 if we are unable to determine what that offset is, either
8802 because the argument turns out to be a pointer to an ERROR_MARK node, or
8803 because the offset is actually variable. (We can't handle the latter case
8804 just yet). */
8806 static HOST_WIDE_INT
8807 field_byte_offset (tree decl)
8809 unsigned int type_align_in_bits;
8810 unsigned int decl_align_in_bits;
8811 unsigned HOST_WIDE_INT type_size_in_bits;
8812 HOST_WIDE_INT object_offset_in_bits;
8813 tree type;
8814 tree field_size_tree;
8815 HOST_WIDE_INT bitpos_int;
8816 HOST_WIDE_INT deepest_bitpos;
8817 unsigned HOST_WIDE_INT field_size_in_bits;
8819 if (TREE_CODE (decl) == ERROR_MARK)
8820 return 0;
8821 else if (TREE_CODE (decl) != FIELD_DECL)
8822 abort ();
8824 type = field_type (decl);
8825 field_size_tree = DECL_SIZE (decl);
8827 /* The size could be unspecified if there was an error, or for
8828 a flexible array member. */
8829 if (! field_size_tree)
8830 field_size_tree = bitsize_zero_node;
8832 /* We cannot yet cope with fields whose positions are variable, so
8833 for now, when we see such things, we simply return 0. Someday, we may
8834 be able to handle such cases, but it will be damn difficult. */
8835 if (! host_integerp (bit_position (decl), 0))
8836 return 0;
8838 bitpos_int = int_bit_position (decl);
8840 /* If we don't know the size of the field, pretend it's a full word. */
8841 if (host_integerp (field_size_tree, 1))
8842 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8843 else
8844 field_size_in_bits = BITS_PER_WORD;
8846 type_size_in_bits = simple_type_size_in_bits (type);
8847 type_align_in_bits = simple_type_align_in_bits (type);
8848 decl_align_in_bits = simple_decl_align_in_bits (decl);
8850 /* The GCC front-end doesn't make any attempt to keep track of the starting
8851 bit offset (relative to the start of the containing structure type) of the
8852 hypothetical "containing object" for a bit-field. Thus, when computing
8853 the byte offset value for the start of the "containing object" of a
8854 bit-field, we must deduce this information on our own. This can be rather
8855 tricky to do in some cases. For example, handling the following structure
8856 type definition when compiling for an i386/i486 target (which only aligns
8857 long long's to 32-bit boundaries) can be very tricky:
8859 struct S { int field1; long long field2:31; };
8861 Fortunately, there is a simple rule-of-thumb which can be used in such
8862 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8863 structure shown above. It decides to do this based upon one simple rule
8864 for bit-field allocation. GCC allocates each "containing object" for each
8865 bit-field at the first (i.e. lowest addressed) legitimate alignment
8866 boundary (based upon the required minimum alignment for the declared type
8867 of the field) which it can possibly use, subject to the condition that
8868 there is still enough available space remaining in the containing object
8869 (when allocated at the selected point) to fully accommodate all of the
8870 bits of the bit-field itself.
8872 This simple rule makes it obvious why GCC allocates 8 bytes for each
8873 object of the structure type shown above. When looking for a place to
8874 allocate the "containing object" for `field2', the compiler simply tries
8875 to allocate a 64-bit "containing object" at each successive 32-bit
8876 boundary (starting at zero) until it finds a place to allocate that 64-
8877 bit field such that at least 31 contiguous (and previously unallocated)
8878 bits remain within that selected 64 bit field. (As it turns out, for the
8879 example above, the compiler finds it is OK to allocate the "containing
8880 object" 64-bit field at bit-offset zero within the structure type.)
8882 Here we attempt to work backwards from the limited set of facts we're
8883 given, and we try to deduce from those facts, where GCC must have believed
8884 that the containing object started (within the structure type). The value
8885 we deduce is then used (by the callers of this routine) to generate
8886 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8887 and, in the case of DW_AT_location, regular fields as well). */
8889 /* Figure out the bit-distance from the start of the structure to the
8890 "deepest" bit of the bit-field. */
8891 deepest_bitpos = bitpos_int + field_size_in_bits;
8893 /* This is the tricky part. Use some fancy footwork to deduce where the
8894 lowest addressed bit of the containing object must be. */
8895 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8897 /* Round up to type_align by default. This works best for bitfields. */
8898 object_offset_in_bits += type_align_in_bits - 1;
8899 object_offset_in_bits /= type_align_in_bits;
8900 object_offset_in_bits *= type_align_in_bits;
8902 if (object_offset_in_bits > bitpos_int)
8904 /* Sigh, the decl must be packed. */
8905 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8907 /* Round up to decl_align instead. */
8908 object_offset_in_bits += decl_align_in_bits - 1;
8909 object_offset_in_bits /= decl_align_in_bits;
8910 object_offset_in_bits *= decl_align_in_bits;
8913 return object_offset_in_bits / BITS_PER_UNIT;
8916 /* The following routines define various Dwarf attributes and any data
8917 associated with them. */
8919 /* Add a location description attribute value to a DIE.
8921 This emits location attributes suitable for whole variables and
8922 whole parameters. Note that the location attributes for struct fields are
8923 generated by the routine `data_member_location_attribute' below. */
8925 static inline void
8926 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
8927 dw_loc_descr_ref descr)
8929 if (descr != 0)
8930 add_AT_loc (die, attr_kind, descr);
8933 /* Attach the specialized form of location attribute used for data members of
8934 struct and union types. In the special case of a FIELD_DECL node which
8935 represents a bit-field, the "offset" part of this special location
8936 descriptor must indicate the distance in bytes from the lowest-addressed
8937 byte of the containing struct or union type to the lowest-addressed byte of
8938 the "containing object" for the bit-field. (See the `field_byte_offset'
8939 function above).
8941 For any given bit-field, the "containing object" is a hypothetical object
8942 (of some integral or enum type) within which the given bit-field lives. The
8943 type of this hypothetical "containing object" is always the same as the
8944 declared type of the individual bit-field itself (for GCC anyway... the
8945 DWARF spec doesn't actually mandate this). Note that it is the size (in
8946 bytes) of the hypothetical "containing object" which will be given in the
8947 DW_AT_byte_size attribute for this bit-field. (See the
8948 `byte_size_attribute' function below.) It is also used when calculating the
8949 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8950 function below.) */
8952 static void
8953 add_data_member_location_attribute (dw_die_ref die, tree decl)
8955 long offset;
8956 dw_loc_descr_ref loc_descr = 0;
8958 if (TREE_CODE (decl) == TREE_VEC)
8960 /* We're working on the TAG_inheritance for a base class. */
8961 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
8963 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8964 aren't at a fixed offset from all (sub)objects of the same
8965 type. We need to extract the appropriate offset from our
8966 vtable. The following dwarf expression means
8968 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8970 This is specific to the V3 ABI, of course. */
8972 dw_loc_descr_ref tmp;
8974 /* Make a copy of the object address. */
8975 tmp = new_loc_descr (DW_OP_dup, 0, 0);
8976 add_loc_descr (&loc_descr, tmp);
8978 /* Extract the vtable address. */
8979 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8980 add_loc_descr (&loc_descr, tmp);
8982 /* Calculate the address of the offset. */
8983 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
8984 if (offset >= 0)
8985 abort ();
8987 tmp = int_loc_descriptor (-offset);
8988 add_loc_descr (&loc_descr, tmp);
8989 tmp = new_loc_descr (DW_OP_minus, 0, 0);
8990 add_loc_descr (&loc_descr, tmp);
8992 /* Extract the offset. */
8993 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8994 add_loc_descr (&loc_descr, tmp);
8996 /* Add it to the object address. */
8997 tmp = new_loc_descr (DW_OP_plus, 0, 0);
8998 add_loc_descr (&loc_descr, tmp);
9000 else
9001 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
9003 else
9004 offset = field_byte_offset (decl);
9006 if (! loc_descr)
9008 enum dwarf_location_atom op;
9010 /* The DWARF2 standard says that we should assume that the structure
9011 address is already on the stack, so we can specify a structure field
9012 address by using DW_OP_plus_uconst. */
9014 #ifdef MIPS_DEBUGGING_INFO
9015 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9016 operator correctly. It works only if we leave the offset on the
9017 stack. */
9018 op = DW_OP_constu;
9019 #else
9020 op = DW_OP_plus_uconst;
9021 #endif
9023 loc_descr = new_loc_descr (op, offset, 0);
9026 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
9029 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9030 does not have a "location" either in memory or in a register. These
9031 things can arise in GNU C when a constant is passed as an actual parameter
9032 to an inlined function. They can also arise in C++ where declared
9033 constants do not necessarily get memory "homes". */
9035 static void
9036 add_const_value_attribute (dw_die_ref die, rtx rtl)
9038 switch (GET_CODE (rtl))
9040 case CONST_INT:
9041 /* Note that a CONST_INT rtx could represent either an integer
9042 or a floating-point constant. A CONST_INT is used whenever
9043 the constant will fit into a single word. In all such
9044 cases, the original mode of the constant value is wiped
9045 out, and the CONST_INT rtx is assigned VOIDmode. */
9047 HOST_WIDE_INT val = INTVAL (rtl);
9049 /* ??? We really should be using HOST_WIDE_INT throughout. */
9050 if (val < 0 && (long) val == val)
9051 add_AT_int (die, DW_AT_const_value, (long) val);
9052 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
9053 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
9054 else
9056 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
9057 add_AT_long_long (die, DW_AT_const_value,
9058 val >> HOST_BITS_PER_LONG, val);
9059 #else
9060 abort ();
9061 #endif
9064 break;
9066 case CONST_DOUBLE:
9067 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9068 floating-point constant. A CONST_DOUBLE is used whenever the
9069 constant requires more than one word in order to be adequately
9070 represented. We output CONST_DOUBLEs as blocks. */
9072 enum machine_mode mode = GET_MODE (rtl);
9074 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
9076 unsigned length = GET_MODE_SIZE (mode) / 4;
9077 long *array = (long *) ggc_alloc (sizeof (long) * length);
9078 REAL_VALUE_TYPE rv;
9080 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
9081 switch (mode)
9083 case SFmode:
9084 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
9085 break;
9087 case DFmode:
9088 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
9089 break;
9091 case XFmode:
9092 case TFmode:
9093 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
9094 break;
9096 default:
9097 abort ();
9100 add_AT_float (die, DW_AT_const_value, length, array);
9102 else
9104 /* ??? We really should be using HOST_WIDE_INT throughout. */
9105 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
9106 abort ();
9108 add_AT_long_long (die, DW_AT_const_value,
9109 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
9112 break;
9114 case CONST_STRING:
9115 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
9116 break;
9118 case SYMBOL_REF:
9119 case LABEL_REF:
9120 case CONST:
9121 add_AT_addr (die, DW_AT_const_value, rtl);
9122 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
9123 break;
9125 case PLUS:
9126 /* In cases where an inlined instance of an inline function is passed
9127 the address of an `auto' variable (which is local to the caller) we
9128 can get a situation where the DECL_RTL of the artificial local
9129 variable (for the inlining) which acts as a stand-in for the
9130 corresponding formal parameter (of the inline function) will look
9131 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9132 exactly a compile-time constant expression, but it isn't the address
9133 of the (artificial) local variable either. Rather, it represents the
9134 *value* which the artificial local variable always has during its
9135 lifetime. We currently have no way to represent such quasi-constant
9136 values in Dwarf, so for now we just punt and generate nothing. */
9137 break;
9139 default:
9140 /* No other kinds of rtx should be possible here. */
9141 abort ();
9146 static rtx
9147 rtl_for_decl_location (tree decl)
9149 rtx rtl;
9151 /* Here we have to decide where we are going to say the parameter "lives"
9152 (as far as the debugger is concerned). We only have a couple of
9153 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9155 DECL_RTL normally indicates where the parameter lives during most of the
9156 activation of the function. If optimization is enabled however, this
9157 could be either NULL or else a pseudo-reg. Both of those cases indicate
9158 that the parameter doesn't really live anywhere (as far as the code
9159 generation parts of GCC are concerned) during most of the function's
9160 activation. That will happen (for example) if the parameter is never
9161 referenced within the function.
9163 We could just generate a location descriptor here for all non-NULL
9164 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
9165 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
9166 where DECL_RTL is NULL or is a pseudo-reg.
9168 Note however that we can only get away with using DECL_INCOMING_RTL as
9169 a backup substitute for DECL_RTL in certain limited cases. In cases
9170 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
9171 we can be sure that the parameter was passed using the same type as it is
9172 declared to have within the function, and that its DECL_INCOMING_RTL
9173 points us to a place where a value of that type is passed.
9175 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
9176 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
9177 because in these cases DECL_INCOMING_RTL points us to a value of some
9178 type which is *different* from the type of the parameter itself. Thus,
9179 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
9180 such cases, the debugger would end up (for example) trying to fetch a
9181 `float' from a place which actually contains the first part of a
9182 `double'. That would lead to really incorrect and confusing
9183 output at debug-time.
9185 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
9186 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
9187 are a couple of exceptions however. On little-endian machines we can
9188 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
9189 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
9190 an integral type that is smaller than TREE_TYPE (decl). These cases arise
9191 when (on a little-endian machine) a non-prototyped function has a
9192 parameter declared to be of type `short' or `char'. In such cases,
9193 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
9194 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
9195 passed `int' value. If the debugger then uses that address to fetch
9196 a `short' or a `char' (on a little-endian machine) the result will be
9197 the correct data, so we allow for such exceptional cases below.
9199 Note that our goal here is to describe the place where the given formal
9200 parameter lives during most of the function's activation (i.e. between the
9201 end of the prologue and the start of the epilogue). We'll do that as best
9202 as we can. Note however that if the given formal parameter is modified
9203 sometime during the execution of the function, then a stack backtrace (at
9204 debug-time) will show the function as having been called with the *new*
9205 value rather than the value which was originally passed in. This happens
9206 rarely enough that it is not a major problem, but it *is* a problem, and
9207 I'd like to fix it.
9209 A future version of dwarf2out.c may generate two additional attributes for
9210 any given DW_TAG_formal_parameter DIE which will describe the "passed
9211 type" and the "passed location" for the given formal parameter in addition
9212 to the attributes we now generate to indicate the "declared type" and the
9213 "active location" for each parameter. This additional set of attributes
9214 could be used by debuggers for stack backtraces. Separately, note that
9215 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
9216 This happens (for example) for inlined-instances of inline function formal
9217 parameters which are never referenced. This really shouldn't be
9218 happening. All PARM_DECL nodes should get valid non-NULL
9219 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
9220 values for inlined instances of inline function parameters, so when we see
9221 such cases, we are just out-of-luck for the time being (until integrate.c
9222 gets fixed). */
9224 /* Use DECL_RTL as the "location" unless we find something better. */
9225 rtl = DECL_RTL_IF_SET (decl);
9227 /* When generating abstract instances, ignore everything except
9228 constants, symbols living in memory, and symbols living in
9229 fixed registers. */
9230 if (! reload_completed)
9232 if (rtl
9233 && (CONSTANT_P (rtl)
9234 || (GET_CODE (rtl) == MEM
9235 && CONSTANT_P (XEXP (rtl, 0)))
9236 || (GET_CODE (rtl) == REG
9237 && TREE_CODE (decl) == VAR_DECL
9238 && TREE_STATIC (decl))))
9240 rtl = (*targetm.delegitimize_address) (rtl);
9241 return rtl;
9243 rtl = NULL_RTX;
9245 else if (TREE_CODE (decl) == PARM_DECL)
9247 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
9249 tree declared_type = type_main_variant (TREE_TYPE (decl));
9250 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
9252 /* This decl represents a formal parameter which was optimized out.
9253 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
9254 all cases where (rtl == NULL_RTX) just below. */
9255 if (declared_type == passed_type)
9256 rtl = DECL_INCOMING_RTL (decl);
9257 else if (! BYTES_BIG_ENDIAN
9258 && TREE_CODE (declared_type) == INTEGER_TYPE
9259 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
9260 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
9261 rtl = DECL_INCOMING_RTL (decl);
9264 /* If the parm was passed in registers, but lives on the stack, then
9265 make a big endian correction if the mode of the type of the
9266 parameter is not the same as the mode of the rtl. */
9267 /* ??? This is the same series of checks that are made in dbxout.c before
9268 we reach the big endian correction code there. It isn't clear if all
9269 of these checks are necessary here, but keeping them all is the safe
9270 thing to do. */
9271 else if (GET_CODE (rtl) == MEM
9272 && XEXP (rtl, 0) != const0_rtx
9273 && ! CONSTANT_P (XEXP (rtl, 0))
9274 /* Not passed in memory. */
9275 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
9276 /* Not passed by invisible reference. */
9277 && (GET_CODE (XEXP (rtl, 0)) != REG
9278 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
9279 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
9280 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
9281 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
9282 #endif
9284 /* Big endian correction check. */
9285 && BYTES_BIG_ENDIAN
9286 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
9287 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
9288 < UNITS_PER_WORD))
9290 int offset = (UNITS_PER_WORD
9291 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
9293 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
9294 plus_constant (XEXP (rtl, 0), offset));
9298 if (rtl != NULL_RTX)
9300 rtl = eliminate_regs (rtl, 0, NULL_RTX);
9301 #ifdef LEAF_REG_REMAP
9302 if (current_function_uses_only_leaf_regs)
9303 leaf_renumber_regs_insn (rtl);
9304 #endif
9307 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
9308 and will have been substituted directly into all expressions that use it.
9309 C does not have such a concept, but C++ and other languages do. */
9310 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
9312 /* If a variable is initialized with a string constant without embedded
9313 zeros, build CONST_STRING. */
9314 if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
9315 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
9317 tree arrtype = TREE_TYPE (decl);
9318 tree enttype = TREE_TYPE (arrtype);
9319 tree domain = TYPE_DOMAIN (arrtype);
9320 tree init = DECL_INITIAL (decl);
9321 enum machine_mode mode = TYPE_MODE (enttype);
9323 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
9324 && domain
9325 && integer_zerop (TYPE_MIN_VALUE (domain))
9326 && compare_tree_int (TYPE_MAX_VALUE (domain),
9327 TREE_STRING_LENGTH (init) - 1) == 0
9328 && ((size_t) TREE_STRING_LENGTH (init)
9329 == strlen (TREE_STRING_POINTER (init)) + 1))
9330 rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init));
9332 /* If the initializer is something that we know will expand into an
9333 immediate RTL constant, expand it now. Expanding anything else
9334 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
9335 else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST
9336 || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST)
9338 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
9339 EXPAND_INITIALIZER);
9340 /* If expand_expr returns a MEM, it wasn't immediate. */
9341 if (rtl && GET_CODE (rtl) == MEM)
9342 abort ();
9346 if (rtl)
9347 rtl = (*targetm.delegitimize_address) (rtl);
9349 /* If we don't look past the constant pool, we risk emitting a
9350 reference to a constant pool entry that isn't referenced from
9351 code, and thus is not emitted. */
9352 if (rtl)
9353 rtl = avoid_constant_pool_reference (rtl);
9355 return rtl;
9358 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
9359 data attribute for a variable or a parameter. We generate the
9360 DW_AT_const_value attribute only in those cases where the given variable
9361 or parameter does not have a true "location" either in memory or in a
9362 register. This can happen (for example) when a constant is passed as an
9363 actual argument in a call to an inline function. (It's possible that
9364 these things can crop up in other ways also.) Note that one type of
9365 constant value which can be passed into an inlined function is a constant
9366 pointer. This can happen for example if an actual argument in an inlined
9367 function call evaluates to a compile-time constant address. */
9369 static void
9370 add_location_or_const_value_attribute (dw_die_ref die, tree decl)
9372 rtx rtl;
9373 dw_loc_descr_ref descr;
9375 if (TREE_CODE (decl) == ERROR_MARK)
9376 return;
9377 else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
9378 abort ();
9380 rtl = rtl_for_decl_location (decl);
9381 if (rtl == NULL_RTX)
9382 return;
9384 switch (GET_CODE (rtl))
9386 case ADDRESSOF:
9387 /* The address of a variable that was optimized away;
9388 don't emit anything. */
9389 break;
9391 case CONST_INT:
9392 case CONST_DOUBLE:
9393 case CONST_STRING:
9394 case SYMBOL_REF:
9395 case LABEL_REF:
9396 case CONST:
9397 case PLUS:
9398 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9399 add_const_value_attribute (die, rtl);
9400 break;
9402 case MEM:
9403 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
9405 /* Need loc_descriptor_from_tree since that's where we know
9406 how to handle TLS variables. Want the object's address
9407 since the top-level DW_AT_location assumes such. See
9408 the confusion in loc_descriptor for reference. */
9409 descr = loc_descriptor_from_tree (decl, 1);
9411 else
9413 case REG:
9414 case SUBREG:
9415 case CONCAT:
9416 descr = loc_descriptor (rtl);
9418 add_AT_location_description (die, DW_AT_location, descr);
9419 break;
9421 default:
9422 abort ();
9426 /* If we don't have a copy of this variable in memory for some reason (such
9427 as a C++ member constant that doesn't have an out-of-line definition),
9428 we should tell the debugger about the constant value. */
9430 static void
9431 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
9433 tree init = DECL_INITIAL (decl);
9434 tree type = TREE_TYPE (decl);
9436 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
9437 && initializer_constant_valid_p (init, type) == null_pointer_node)
9438 /* OK */;
9439 else
9440 return;
9442 switch (TREE_CODE (type))
9444 case INTEGER_TYPE:
9445 if (host_integerp (init, 0))
9446 add_AT_unsigned (var_die, DW_AT_const_value,
9447 tree_low_cst (init, 0));
9448 else
9449 add_AT_long_long (var_die, DW_AT_const_value,
9450 TREE_INT_CST_HIGH (init),
9451 TREE_INT_CST_LOW (init));
9452 break;
9454 default:;
9458 /* Generate a DW_AT_name attribute given some string value to be included as
9459 the value of the attribute. */
9461 static void
9462 add_name_attribute (dw_die_ref die, const char *name_string)
9464 if (name_string != NULL && *name_string != 0)
9466 if (demangle_name_func)
9467 name_string = (*demangle_name_func) (name_string);
9469 add_AT_string (die, DW_AT_name, name_string);
9473 /* Generate a DW_AT_comp_dir attribute for DIE. */
9475 static void
9476 add_comp_dir_attribute (dw_die_ref die)
9478 const char *wd = getpwd ();
9479 if (wd != NULL)
9480 add_AT_string (die, DW_AT_comp_dir, wd);
9483 /* Given a tree node describing an array bound (either lower or upper) output
9484 a representation for that bound. */
9486 static void
9487 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
9489 switch (TREE_CODE (bound))
9491 case ERROR_MARK:
9492 return;
9494 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9495 case INTEGER_CST:
9496 if (! host_integerp (bound, 0)
9497 || (bound_attr == DW_AT_lower_bound
9498 && (((is_c_family () || is_java ()) && integer_zerop (bound))
9499 || (is_fortran () && integer_onep (bound)))))
9500 /* use the default */
9502 else
9503 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
9504 break;
9506 case CONVERT_EXPR:
9507 case NOP_EXPR:
9508 case NON_LVALUE_EXPR:
9509 case VIEW_CONVERT_EXPR:
9510 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
9511 break;
9513 case SAVE_EXPR:
9514 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9515 access the upper bound values may be bogus. If they refer to a
9516 register, they may only describe how to get at these values at the
9517 points in the generated code right after they have just been
9518 computed. Worse yet, in the typical case, the upper bound values
9519 will not even *be* computed in the optimized code (though the
9520 number of elements will), so these SAVE_EXPRs are entirely
9521 bogus. In order to compensate for this fact, we check here to see
9522 if optimization is enabled, and if so, we don't add an attribute
9523 for the (unknown and unknowable) upper bound. This should not
9524 cause too much trouble for existing (stupid?) debuggers because
9525 they have to deal with empty upper bounds location descriptions
9526 anyway in order to be able to deal with incomplete array types.
9527 Of course an intelligent debugger (GDB?) should be able to
9528 comprehend that a missing upper bound specification in an array
9529 type used for a storage class `auto' local array variable
9530 indicates that the upper bound is both unknown (at compile- time)
9531 and unknowable (at run-time) due to optimization.
9533 We assume that a MEM rtx is safe because gcc wouldn't put the
9534 value there unless it was going to be used repeatedly in the
9535 function, i.e. for cleanups. */
9536 if (SAVE_EXPR_RTL (bound)
9537 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9539 dw_die_ref ctx = lookup_decl_die (current_function_decl);
9540 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound);
9541 rtx loc = SAVE_EXPR_RTL (bound);
9543 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9544 it references an outer function's frame. */
9545 if (GET_CODE (loc) == MEM)
9547 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9549 if (XEXP (loc, 0) != new_addr)
9550 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9553 add_AT_flag (decl_die, DW_AT_artificial, 1);
9554 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9555 add_AT_location_description (decl_die, DW_AT_location,
9556 loc_descriptor (loc));
9557 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9560 /* Else leave out the attribute. */
9561 break;
9563 case VAR_DECL:
9564 case PARM_DECL:
9566 dw_die_ref decl_die = lookup_decl_die (bound);
9568 /* ??? Can this happen, or should the variable have been bound
9569 first? Probably it can, since I imagine that we try to create
9570 the types of parameters in the order in which they exist in
9571 the list, and won't have created a forward reference to a
9572 later parameter. */
9573 if (decl_die != NULL)
9574 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9575 break;
9578 default:
9580 /* Otherwise try to create a stack operation procedure to
9581 evaluate the value of the array bound. */
9583 dw_die_ref ctx, decl_die;
9584 dw_loc_descr_ref loc;
9586 loc = loc_descriptor_from_tree (bound, 0);
9587 if (loc == NULL)
9588 break;
9590 if (current_function_decl == 0)
9591 ctx = comp_unit_die;
9592 else
9593 ctx = lookup_decl_die (current_function_decl);
9595 /* If we weren't able to find a context, it's most likely the case
9596 that we are processing the return type of the function. So
9597 make a SAVE_EXPR to point to it and have the limbo DIE code
9598 find the proper die. The save_expr function doesn't always
9599 make a SAVE_EXPR, so do it ourselves. */
9600 if (ctx == 0)
9601 bound = build (SAVE_EXPR, TREE_TYPE (bound), bound,
9602 current_function_decl, NULL_TREE);
9604 decl_die = new_die (DW_TAG_variable, ctx, bound);
9605 add_AT_flag (decl_die, DW_AT_artificial, 1);
9606 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9607 add_AT_loc (decl_die, DW_AT_location, loc);
9609 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9610 break;
9615 /* Note that the block of subscript information for an array type also
9616 includes information about the element type of type given array type. */
9618 static void
9619 add_subscript_info (dw_die_ref type_die, tree type)
9621 #ifndef MIPS_DEBUGGING_INFO
9622 unsigned dimension_number;
9623 #endif
9624 tree lower, upper;
9625 dw_die_ref subrange_die;
9627 /* The GNU compilers represent multidimensional array types as sequences of
9628 one dimensional array types whose element types are themselves array
9629 types. Here we squish that down, so that each multidimensional array
9630 type gets only one array_type DIE in the Dwarf debugging info. The draft
9631 Dwarf specification say that we are allowed to do this kind of
9632 compression in C (because there is no difference between an array or
9633 arrays and a multidimensional array in C) but for other source languages
9634 (e.g. Ada) we probably shouldn't do this. */
9636 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9637 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9638 We work around this by disabling this feature. See also
9639 gen_array_type_die. */
9640 #ifndef MIPS_DEBUGGING_INFO
9641 for (dimension_number = 0;
9642 TREE_CODE (type) == ARRAY_TYPE;
9643 type = TREE_TYPE (type), dimension_number++)
9644 #endif
9646 tree domain = TYPE_DOMAIN (type);
9648 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9649 and (in GNU C only) variable bounds. Handle all three forms
9650 here. */
9651 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
9652 if (domain)
9654 /* We have an array type with specified bounds. */
9655 lower = TYPE_MIN_VALUE (domain);
9656 upper = TYPE_MAX_VALUE (domain);
9658 /* define the index type. */
9659 if (TREE_TYPE (domain))
9661 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9662 TREE_TYPE field. We can't emit debug info for this
9663 because it is an unnamed integral type. */
9664 if (TREE_CODE (domain) == INTEGER_TYPE
9665 && TYPE_NAME (domain) == NULL_TREE
9666 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9667 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9669 else
9670 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9671 type_die);
9674 /* ??? If upper is NULL, the array has unspecified length,
9675 but it does have a lower bound. This happens with Fortran
9676 dimension arr(N:*)
9677 Since the debugger is definitely going to need to know N
9678 to produce useful results, go ahead and output the lower
9679 bound solo, and hope the debugger can cope. */
9681 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9682 if (upper)
9683 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9686 /* Otherwise we have an array type with an unspecified length. The
9687 DWARF-2 spec does not say how to handle this; let's just leave out the
9688 bounds. */
9692 static void
9693 add_byte_size_attribute (dw_die_ref die, tree tree_node)
9695 unsigned size;
9697 switch (TREE_CODE (tree_node))
9699 case ERROR_MARK:
9700 size = 0;
9701 break;
9702 case ENUMERAL_TYPE:
9703 case RECORD_TYPE:
9704 case UNION_TYPE:
9705 case QUAL_UNION_TYPE:
9706 size = int_size_in_bytes (tree_node);
9707 break;
9708 case FIELD_DECL:
9709 /* For a data member of a struct or union, the DW_AT_byte_size is
9710 generally given as the number of bytes normally allocated for an
9711 object of the *declared* type of the member itself. This is true
9712 even for bit-fields. */
9713 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9714 break;
9715 default:
9716 abort ();
9719 /* Note that `size' might be -1 when we get to this point. If it is, that
9720 indicates that the byte size of the entity in question is variable. We
9721 have no good way of expressing this fact in Dwarf at the present time,
9722 so just let the -1 pass on through. */
9723 add_AT_unsigned (die, DW_AT_byte_size, size);
9726 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9727 which specifies the distance in bits from the highest order bit of the
9728 "containing object" for the bit-field to the highest order bit of the
9729 bit-field itself.
9731 For any given bit-field, the "containing object" is a hypothetical object
9732 (of some integral or enum type) within which the given bit-field lives. The
9733 type of this hypothetical "containing object" is always the same as the
9734 declared type of the individual bit-field itself. The determination of the
9735 exact location of the "containing object" for a bit-field is rather
9736 complicated. It's handled by the `field_byte_offset' function (above).
9738 Note that it is the size (in bytes) of the hypothetical "containing object"
9739 which will be given in the DW_AT_byte_size attribute for this bit-field.
9740 (See `byte_size_attribute' above). */
9742 static inline void
9743 add_bit_offset_attribute (dw_die_ref die, tree decl)
9745 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9746 tree type = DECL_BIT_FIELD_TYPE (decl);
9747 HOST_WIDE_INT bitpos_int;
9748 HOST_WIDE_INT highest_order_object_bit_offset;
9749 HOST_WIDE_INT highest_order_field_bit_offset;
9750 HOST_WIDE_INT unsigned bit_offset;
9752 /* Must be a field and a bit field. */
9753 if (!type
9754 || TREE_CODE (decl) != FIELD_DECL)
9755 abort ();
9757 /* We can't yet handle bit-fields whose offsets are variable, so if we
9758 encounter such things, just return without generating any attribute
9759 whatsoever. Likewise for variable or too large size. */
9760 if (! host_integerp (bit_position (decl), 0)
9761 || ! host_integerp (DECL_SIZE (decl), 1))
9762 return;
9764 bitpos_int = int_bit_position (decl);
9766 /* Note that the bit offset is always the distance (in bits) from the
9767 highest-order bit of the "containing object" to the highest-order bit of
9768 the bit-field itself. Since the "high-order end" of any object or field
9769 is different on big-endian and little-endian machines, the computation
9770 below must take account of these differences. */
9771 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9772 highest_order_field_bit_offset = bitpos_int;
9774 if (! BYTES_BIG_ENDIAN)
9776 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9777 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9780 bit_offset
9781 = (! BYTES_BIG_ENDIAN
9782 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9783 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9785 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9788 /* For a FIELD_DECL node which represents a bit field, output an attribute
9789 which specifies the length in bits of the given field. */
9791 static inline void
9792 add_bit_size_attribute (dw_die_ref die, tree decl)
9794 /* Must be a field and a bit field. */
9795 if (TREE_CODE (decl) != FIELD_DECL
9796 || ! DECL_BIT_FIELD_TYPE (decl))
9797 abort ();
9799 if (host_integerp (DECL_SIZE (decl), 1))
9800 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9803 /* If the compiled language is ANSI C, then add a 'prototyped'
9804 attribute, if arg types are given for the parameters of a function. */
9806 static inline void
9807 add_prototyped_attribute (dw_die_ref die, tree func_type)
9809 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9810 && TYPE_ARG_TYPES (func_type) != NULL)
9811 add_AT_flag (die, DW_AT_prototyped, 1);
9814 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9815 by looking in either the type declaration or object declaration
9816 equate table. */
9818 static inline void
9819 add_abstract_origin_attribute (dw_die_ref die, tree origin)
9821 dw_die_ref origin_die = NULL;
9823 if (TREE_CODE (origin) != FUNCTION_DECL)
9825 /* We may have gotten separated from the block for the inlined
9826 function, if we're in an exception handler or some such; make
9827 sure that the abstract function has been written out.
9829 Doing this for nested functions is wrong, however; functions are
9830 distinct units, and our context might not even be inline. */
9831 tree fn = origin;
9833 if (TYPE_P (fn))
9834 fn = TYPE_STUB_DECL (fn);
9836 fn = decl_function_context (fn);
9837 if (fn)
9838 dwarf2out_abstract_function (fn);
9841 if (DECL_P (origin))
9842 origin_die = lookup_decl_die (origin);
9843 else if (TYPE_P (origin))
9844 origin_die = lookup_type_die (origin);
9846 if (origin_die == NULL)
9847 abort ();
9849 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9852 /* We do not currently support the pure_virtual attribute. */
9854 static inline void
9855 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
9857 if (DECL_VINDEX (func_decl))
9859 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9861 if (host_integerp (DECL_VINDEX (func_decl), 0))
9862 add_AT_loc (die, DW_AT_vtable_elem_location,
9863 new_loc_descr (DW_OP_constu,
9864 tree_low_cst (DECL_VINDEX (func_decl), 0),
9865 0));
9867 /* GNU extension: Record what type this method came from originally. */
9868 if (debug_info_level > DINFO_LEVEL_TERSE)
9869 add_AT_die_ref (die, DW_AT_containing_type,
9870 lookup_type_die (DECL_CONTEXT (func_decl)));
9874 /* Add source coordinate attributes for the given decl. */
9876 static void
9877 add_src_coords_attributes (dw_die_ref die, tree decl)
9879 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9881 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9882 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9885 /* Add a DW_AT_name attribute and source coordinate attribute for the
9886 given decl, but only if it actually has a name. */
9888 static void
9889 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
9891 tree decl_name;
9893 decl_name = DECL_NAME (decl);
9894 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9896 add_name_attribute (die, dwarf2_name (decl, 0));
9897 if (! DECL_ARTIFICIAL (decl))
9898 add_src_coords_attributes (die, decl);
9900 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9901 && TREE_PUBLIC (decl)
9902 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9903 && !DECL_ABSTRACT (decl))
9904 add_AT_string (die, DW_AT_MIPS_linkage_name,
9905 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9908 #ifdef VMS_DEBUGGING_INFO
9909 /* Get the function's name, as described by its RTL. This may be different
9910 from the DECL_NAME name used in the source file. */
9911 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
9913 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
9914 XEXP (DECL_RTL (decl), 0));
9915 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
9917 #endif
9920 /* Push a new declaration scope. */
9922 static void
9923 push_decl_scope (tree scope)
9925 VARRAY_PUSH_TREE (decl_scope_table, scope);
9928 /* Pop a declaration scope. */
9930 static inline void
9931 pop_decl_scope (void)
9933 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9934 abort ();
9936 VARRAY_POP (decl_scope_table);
9939 /* Return the DIE for the scope that immediately contains this type.
9940 Non-named types get global scope. Named types nested in other
9941 types get their containing scope if it's open, or global scope
9942 otherwise. All other types (i.e. function-local named types) get
9943 the current active scope. */
9945 static dw_die_ref
9946 scope_die_for (tree t, dw_die_ref context_die)
9948 dw_die_ref scope_die = NULL;
9949 tree containing_scope;
9950 int i;
9952 /* Non-types always go in the current scope. */
9953 if (! TYPE_P (t))
9954 abort ();
9956 containing_scope = TYPE_CONTEXT (t);
9958 /* Ignore namespaces for the moment. */
9959 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9960 containing_scope = NULL_TREE;
9962 /* Ignore function type "scopes" from the C frontend. They mean that
9963 a tagged type is local to a parmlist of a function declarator, but
9964 that isn't useful to DWARF. */
9965 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9966 containing_scope = NULL_TREE;
9968 if (containing_scope == NULL_TREE)
9969 scope_die = comp_unit_die;
9970 else if (TYPE_P (containing_scope))
9972 /* For types, we can just look up the appropriate DIE. But
9973 first we check to see if we're in the middle of emitting it
9974 so we know where the new DIE should go. */
9975 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9976 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
9977 break;
9979 if (i < 0)
9981 if (debug_info_level > DINFO_LEVEL_TERSE
9982 && !TREE_ASM_WRITTEN (containing_scope))
9983 abort ();
9985 /* If none of the current dies are suitable, we get file scope. */
9986 scope_die = comp_unit_die;
9988 else
9989 scope_die = lookup_type_die (containing_scope);
9991 else
9992 scope_die = context_die;
9994 return scope_die;
9997 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9999 static inline int
10000 local_scope_p (dw_die_ref context_die)
10002 for (; context_die; context_die = context_die->die_parent)
10003 if (context_die->die_tag == DW_TAG_inlined_subroutine
10004 || context_die->die_tag == DW_TAG_subprogram)
10005 return 1;
10007 return 0;
10010 /* Returns nonzero if CONTEXT_DIE is a class. */
10012 static inline int
10013 class_scope_p (dw_die_ref context_die)
10015 return (context_die
10016 && (context_die->die_tag == DW_TAG_structure_type
10017 || context_die->die_tag == DW_TAG_union_type));
10020 /* Many forms of DIEs require a "type description" attribute. This
10021 routine locates the proper "type descriptor" die for the type given
10022 by 'type', and adds a DW_AT_type attribute below the given die. */
10024 static void
10025 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
10026 int decl_volatile, dw_die_ref context_die)
10028 enum tree_code code = TREE_CODE (type);
10029 dw_die_ref type_die = NULL;
10031 /* ??? If this type is an unnamed subrange type of an integral or
10032 floating-point type, use the inner type. This is because we have no
10033 support for unnamed types in base_type_die. This can happen if this is
10034 an Ada subrange type. Correct solution is emit a subrange type die. */
10035 if ((code == INTEGER_TYPE || code == REAL_TYPE)
10036 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
10037 type = TREE_TYPE (type), code = TREE_CODE (type);
10039 if (code == ERROR_MARK
10040 /* Handle a special case. For functions whose return type is void, we
10041 generate *no* type attribute. (Note that no object may have type
10042 `void', so this only applies to function return types). */
10043 || code == VOID_TYPE)
10044 return;
10046 type_die = modified_type_die (type,
10047 decl_const || TYPE_READONLY (type),
10048 decl_volatile || TYPE_VOLATILE (type),
10049 context_die);
10051 if (type_die != NULL)
10052 add_AT_die_ref (object_die, DW_AT_type, type_die);
10055 /* Given a tree pointer to a struct, class, union, or enum type node, return
10056 a pointer to the (string) tag name for the given type, or zero if the type
10057 was declared without a tag. */
10059 static const char *
10060 type_tag (tree type)
10062 const char *name = 0;
10064 if (TYPE_NAME (type) != 0)
10066 tree t = 0;
10068 /* Find the IDENTIFIER_NODE for the type name. */
10069 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
10070 t = TYPE_NAME (type);
10072 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
10073 a TYPE_DECL node, regardless of whether or not a `typedef' was
10074 involved. */
10075 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10076 && ! DECL_IGNORED_P (TYPE_NAME (type)))
10077 t = DECL_NAME (TYPE_NAME (type));
10079 /* Now get the name as a string, or invent one. */
10080 if (t != 0)
10081 name = IDENTIFIER_POINTER (t);
10084 return (name == 0 || *name == '\0') ? 0 : name;
10087 /* Return the type associated with a data member, make a special check
10088 for bit field types. */
10090 static inline tree
10091 member_declared_type (tree member)
10093 return (DECL_BIT_FIELD_TYPE (member)
10094 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
10097 /* Get the decl's label, as described by its RTL. This may be different
10098 from the DECL_NAME name used in the source file. */
10100 #if 0
10101 static const char *
10102 decl_start_label (tree decl)
10104 rtx x;
10105 const char *fnname;
10107 x = DECL_RTL (decl);
10108 if (GET_CODE (x) != MEM)
10109 abort ();
10111 x = XEXP (x, 0);
10112 if (GET_CODE (x) != SYMBOL_REF)
10113 abort ();
10115 fnname = XSTR (x, 0);
10116 return fnname;
10118 #endif
10120 /* These routines generate the internal representation of the DIE's for
10121 the compilation unit. Debugging information is collected by walking
10122 the declaration trees passed in from dwarf2out_decl(). */
10124 static void
10125 gen_array_type_die (tree type, dw_die_ref context_die)
10127 dw_die_ref scope_die = scope_die_for (type, context_die);
10128 dw_die_ref array_die;
10129 tree element_type;
10131 /* ??? The SGI dwarf reader fails for array of array of enum types unless
10132 the inner array type comes before the outer array type. Thus we must
10133 call gen_type_die before we call new_die. See below also. */
10134 #ifdef MIPS_DEBUGGING_INFO
10135 gen_type_die (TREE_TYPE (type), context_die);
10136 #endif
10138 array_die = new_die (DW_TAG_array_type, scope_die, type);
10139 add_name_attribute (array_die, type_tag (type));
10140 equate_type_number_to_die (type, array_die);
10142 if (TREE_CODE (type) == VECTOR_TYPE)
10144 /* The frontend feeds us a representation for the vector as a struct
10145 containing an array. Pull out the array type. */
10146 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
10147 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
10150 #if 0
10151 /* We default the array ordering. SDB will probably do
10152 the right things even if DW_AT_ordering is not present. It's not even
10153 an issue until we start to get into multidimensional arrays anyway. If
10154 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
10155 then we'll have to put the DW_AT_ordering attribute back in. (But if
10156 and when we find out that we need to put these in, we will only do so
10157 for multidimensional arrays. */
10158 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
10159 #endif
10161 #ifdef MIPS_DEBUGGING_INFO
10162 /* The SGI compilers handle arrays of unknown bound by setting
10163 AT_declaration and not emitting any subrange DIEs. */
10164 if (! TYPE_DOMAIN (type))
10165 add_AT_unsigned (array_die, DW_AT_declaration, 1);
10166 else
10167 #endif
10168 add_subscript_info (array_die, type);
10170 /* Add representation of the type of the elements of this array type. */
10171 element_type = TREE_TYPE (type);
10173 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10174 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10175 We work around this by disabling this feature. See also
10176 add_subscript_info. */
10177 #ifndef MIPS_DEBUGGING_INFO
10178 while (TREE_CODE (element_type) == ARRAY_TYPE)
10179 element_type = TREE_TYPE (element_type);
10181 gen_type_die (element_type, context_die);
10182 #endif
10184 add_type_attribute (array_die, element_type, 0, 0, context_die);
10187 static void
10188 gen_set_type_die (tree type, dw_die_ref context_die)
10190 dw_die_ref type_die
10191 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
10193 equate_type_number_to_die (type, type_die);
10194 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
10197 #if 0
10198 static void
10199 gen_entry_point_die (tree decl, dw_die_ref context_die)
10201 tree origin = decl_ultimate_origin (decl);
10202 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
10204 if (origin != NULL)
10205 add_abstract_origin_attribute (decl_die, origin);
10206 else
10208 add_name_and_src_coords_attributes (decl_die, decl);
10209 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
10210 0, 0, context_die);
10213 if (DECL_ABSTRACT (decl))
10214 equate_decl_number_to_die (decl, decl_die);
10215 else
10216 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
10218 #endif
10220 /* Walk through the list of incomplete types again, trying once more to
10221 emit full debugging info for them. */
10223 static void
10224 retry_incomplete_types (void)
10226 int i;
10228 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
10229 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
10232 /* Generate a DIE to represent an inlined instance of an enumeration type. */
10234 static void
10235 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
10237 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
10239 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10240 be incomplete and such types are not marked. */
10241 add_abstract_origin_attribute (type_die, type);
10244 /* Generate a DIE to represent an inlined instance of a structure type. */
10246 static void
10247 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
10249 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
10251 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10252 be incomplete and such types are not marked. */
10253 add_abstract_origin_attribute (type_die, type);
10256 /* Generate a DIE to represent an inlined instance of a union type. */
10258 static void
10259 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
10261 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
10263 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10264 be incomplete and such types are not marked. */
10265 add_abstract_origin_attribute (type_die, type);
10268 /* Generate a DIE to represent an enumeration type. Note that these DIEs
10269 include all of the information about the enumeration values also. Each
10270 enumerated type name/value is listed as a child of the enumerated type
10271 DIE. */
10273 static void
10274 gen_enumeration_type_die (tree type, dw_die_ref context_die)
10276 dw_die_ref type_die = lookup_type_die (type);
10278 if (type_die == NULL)
10280 type_die = new_die (DW_TAG_enumeration_type,
10281 scope_die_for (type, context_die), type);
10282 equate_type_number_to_die (type, type_die);
10283 add_name_attribute (type_die, type_tag (type));
10285 else if (! TYPE_SIZE (type))
10286 return;
10287 else
10288 remove_AT (type_die, DW_AT_declaration);
10290 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
10291 given enum type is incomplete, do not generate the DW_AT_byte_size
10292 attribute or the DW_AT_element_list attribute. */
10293 if (TYPE_SIZE (type))
10295 tree link;
10297 TREE_ASM_WRITTEN (type) = 1;
10298 add_byte_size_attribute (type_die, type);
10299 if (TYPE_STUB_DECL (type) != NULL_TREE)
10300 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10302 /* If the first reference to this type was as the return type of an
10303 inline function, then it may not have a parent. Fix this now. */
10304 if (type_die->die_parent == NULL)
10305 add_child_die (scope_die_for (type, context_die), type_die);
10307 for (link = TYPE_FIELDS (type);
10308 link != NULL; link = TREE_CHAIN (link))
10310 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
10312 add_name_attribute (enum_die,
10313 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
10315 if (host_integerp (TREE_VALUE (link), 0))
10317 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
10318 add_AT_int (enum_die, DW_AT_const_value,
10319 tree_low_cst (TREE_VALUE (link), 0));
10320 else
10321 add_AT_unsigned (enum_die, DW_AT_const_value,
10322 tree_low_cst (TREE_VALUE (link), 0));
10326 else
10327 add_AT_flag (type_die, DW_AT_declaration, 1);
10330 /* Generate a DIE to represent either a real live formal parameter decl or to
10331 represent just the type of some formal parameter position in some function
10332 type.
10334 Note that this routine is a bit unusual because its argument may be a
10335 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
10336 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
10337 node. If it's the former then this function is being called to output a
10338 DIE to represent a formal parameter object (or some inlining thereof). If
10339 it's the latter, then this function is only being called to output a
10340 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
10341 argument type of some subprogram type. */
10343 static dw_die_ref
10344 gen_formal_parameter_die (tree node, dw_die_ref context_die)
10346 dw_die_ref parm_die
10347 = new_die (DW_TAG_formal_parameter, context_die, node);
10348 tree origin;
10350 switch (TREE_CODE_CLASS (TREE_CODE (node)))
10352 case 'd':
10353 origin = decl_ultimate_origin (node);
10354 if (origin != NULL)
10355 add_abstract_origin_attribute (parm_die, origin);
10356 else
10358 add_name_and_src_coords_attributes (parm_die, node);
10359 add_type_attribute (parm_die, TREE_TYPE (node),
10360 TREE_READONLY (node),
10361 TREE_THIS_VOLATILE (node),
10362 context_die);
10363 if (DECL_ARTIFICIAL (node))
10364 add_AT_flag (parm_die, DW_AT_artificial, 1);
10367 equate_decl_number_to_die (node, parm_die);
10368 if (! DECL_ABSTRACT (node))
10369 add_location_or_const_value_attribute (parm_die, node);
10371 break;
10373 case 't':
10374 /* We were called with some kind of a ..._TYPE node. */
10375 add_type_attribute (parm_die, node, 0, 0, context_die);
10376 break;
10378 default:
10379 abort ();
10382 return parm_die;
10385 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10386 at the end of an (ANSI prototyped) formal parameters list. */
10388 static void
10389 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
10391 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
10394 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10395 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10396 parameters as specified in some function type specification (except for
10397 those which appear as part of a function *definition*). */
10399 static void
10400 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
10402 tree link;
10403 tree formal_type = NULL;
10404 tree first_parm_type;
10405 tree arg;
10407 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
10409 arg = DECL_ARGUMENTS (function_or_method_type);
10410 function_or_method_type = TREE_TYPE (function_or_method_type);
10412 else
10413 arg = NULL_TREE;
10415 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
10417 /* Make our first pass over the list of formal parameter types and output a
10418 DW_TAG_formal_parameter DIE for each one. */
10419 for (link = first_parm_type; link; )
10421 dw_die_ref parm_die;
10423 formal_type = TREE_VALUE (link);
10424 if (formal_type == void_type_node)
10425 break;
10427 /* Output a (nameless) DIE to represent the formal parameter itself. */
10428 parm_die = gen_formal_parameter_die (formal_type, context_die);
10429 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
10430 && link == first_parm_type)
10431 || (arg && DECL_ARTIFICIAL (arg)))
10432 add_AT_flag (parm_die, DW_AT_artificial, 1);
10434 link = TREE_CHAIN (link);
10435 if (arg)
10436 arg = TREE_CHAIN (arg);
10439 /* If this function type has an ellipsis, add a
10440 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10441 if (formal_type != void_type_node)
10442 gen_unspecified_parameters_die (function_or_method_type, context_die);
10444 /* Make our second (and final) pass over the list of formal parameter types
10445 and output DIEs to represent those types (as necessary). */
10446 for (link = TYPE_ARG_TYPES (function_or_method_type);
10447 link && TREE_VALUE (link);
10448 link = TREE_CHAIN (link))
10449 gen_type_die (TREE_VALUE (link), context_die);
10452 /* We want to generate the DIE for TYPE so that we can generate the
10453 die for MEMBER, which has been defined; we will need to refer back
10454 to the member declaration nested within TYPE. If we're trying to
10455 generate minimal debug info for TYPE, processing TYPE won't do the
10456 trick; we need to attach the member declaration by hand. */
10458 static void
10459 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
10461 gen_type_die (type, context_die);
10463 /* If we're trying to avoid duplicate debug info, we may not have
10464 emitted the member decl for this function. Emit it now. */
10465 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10466 && ! lookup_decl_die (member))
10468 if (decl_ultimate_origin (member))
10469 abort ();
10471 push_decl_scope (type);
10472 if (TREE_CODE (member) == FUNCTION_DECL)
10473 gen_subprogram_die (member, lookup_type_die (type));
10474 else
10475 gen_variable_die (member, lookup_type_die (type));
10477 pop_decl_scope ();
10481 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10482 may later generate inlined and/or out-of-line instances of. */
10484 static void
10485 dwarf2out_abstract_function (tree decl)
10487 dw_die_ref old_die;
10488 tree save_fn;
10489 tree context;
10490 int was_abstract = DECL_ABSTRACT (decl);
10492 /* Make sure we have the actual abstract inline, not a clone. */
10493 decl = DECL_ORIGIN (decl);
10495 old_die = lookup_decl_die (decl);
10496 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10497 /* We've already generated the abstract instance. */
10498 return;
10500 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10501 we don't get confused by DECL_ABSTRACT. */
10502 if (debug_info_level > DINFO_LEVEL_TERSE)
10504 context = decl_class_context (decl);
10505 if (context)
10506 gen_type_die_for_member
10507 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
10510 /* Pretend we've just finished compiling this function. */
10511 save_fn = current_function_decl;
10512 current_function_decl = decl;
10514 set_decl_abstract_flags (decl, 1);
10515 dwarf2out_decl (decl);
10516 if (! was_abstract)
10517 set_decl_abstract_flags (decl, 0);
10519 current_function_decl = save_fn;
10522 /* Generate a DIE to represent a declared function (either file-scope or
10523 block-local). */
10525 static void
10526 gen_subprogram_die (tree decl, dw_die_ref context_die)
10528 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10529 tree origin = decl_ultimate_origin (decl);
10530 dw_die_ref subr_die;
10531 rtx fp_reg;
10532 tree fn_arg_types;
10533 tree outer_scope;
10534 dw_die_ref old_die = lookup_decl_die (decl);
10535 int declaration = (current_function_decl != decl
10536 || class_scope_p (context_die));
10538 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10539 started to generate the abstract instance of an inline, decided to output
10540 its containing class, and proceeded to emit the declaration of the inline
10541 from the member list for the class. If so, DECLARATION takes priority;
10542 we'll get back to the abstract instance when done with the class. */
10544 /* The class-scope declaration DIE must be the primary DIE. */
10545 if (origin && declaration && class_scope_p (context_die))
10547 origin = NULL;
10548 if (old_die)
10549 abort ();
10552 if (origin != NULL)
10554 if (declaration && ! local_scope_p (context_die))
10555 abort ();
10557 /* Fixup die_parent for the abstract instance of a nested
10558 inline function. */
10559 if (old_die && old_die->die_parent == NULL)
10560 add_child_die (context_die, old_die);
10562 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10563 add_abstract_origin_attribute (subr_die, origin);
10565 else if (old_die)
10567 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10569 if (!get_AT_flag (old_die, DW_AT_declaration)
10570 /* We can have a normal definition following an inline one in the
10571 case of redefinition of GNU C extern inlines.
10572 It seems reasonable to use AT_specification in this case. */
10573 && !get_AT_unsigned (old_die, DW_AT_inline))
10575 /* ??? This can happen if there is a bug in the program, for
10576 instance, if it has duplicate function definitions. Ideally,
10577 we should detect this case and ignore it. For now, if we have
10578 already reported an error, any error at all, then assume that
10579 we got here because of an input error, not a dwarf2 bug. */
10580 if (errorcount)
10581 return;
10582 abort ();
10585 /* If the definition comes from the same place as the declaration,
10586 maybe use the old DIE. We always want the DIE for this function
10587 that has the *_pc attributes to be under comp_unit_die so the
10588 debugger can find it. We also need to do this for abstract
10589 instances of inlines, since the spec requires the out-of-line copy
10590 to have the same parent. For local class methods, this doesn't
10591 apply; we just use the old DIE. */
10592 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10593 && (DECL_ARTIFICIAL (decl)
10594 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10595 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10596 == (unsigned) DECL_SOURCE_LINE (decl)))))
10598 subr_die = old_die;
10600 /* Clear out the declaration attribute and the parm types. */
10601 remove_AT (subr_die, DW_AT_declaration);
10602 remove_children (subr_die);
10604 else
10606 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10607 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10608 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10609 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10610 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10611 != (unsigned) DECL_SOURCE_LINE (decl))
10612 add_AT_unsigned
10613 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10616 else
10618 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10620 if (TREE_PUBLIC (decl))
10621 add_AT_flag (subr_die, DW_AT_external, 1);
10623 add_name_and_src_coords_attributes (subr_die, decl);
10624 if (debug_info_level > DINFO_LEVEL_TERSE)
10626 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
10627 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
10628 0, 0, context_die);
10631 add_pure_or_virtual_attribute (subr_die, decl);
10632 if (DECL_ARTIFICIAL (decl))
10633 add_AT_flag (subr_die, DW_AT_artificial, 1);
10635 if (TREE_PROTECTED (decl))
10636 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10637 else if (TREE_PRIVATE (decl))
10638 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10641 if (declaration)
10643 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10645 add_AT_flag (subr_die, DW_AT_declaration, 1);
10647 /* The first time we see a member function, it is in the context of
10648 the class to which it belongs. We make sure of this by emitting
10649 the class first. The next time is the definition, which is
10650 handled above. The two may come from the same source text. */
10651 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10652 equate_decl_number_to_die (decl, subr_die);
10655 else if (DECL_ABSTRACT (decl))
10657 if (DECL_INLINE (decl) && !flag_no_inline)
10659 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10660 inline functions, but not for extern inline functions.
10661 We can't get this completely correct because information
10662 about whether the function was declared inline is not
10663 saved anywhere. */
10664 if (DECL_DEFER_OUTPUT (decl))
10665 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10666 else
10667 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10669 else
10670 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10672 equate_decl_number_to_die (decl, subr_die);
10674 else if (!DECL_EXTERNAL (decl))
10676 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10677 equate_decl_number_to_die (decl, subr_die);
10679 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10680 current_function_funcdef_no);
10681 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10682 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10683 current_function_funcdef_no);
10684 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10686 add_pubname (decl, subr_die);
10687 add_arange (decl, subr_die);
10689 #ifdef MIPS_DEBUGGING_INFO
10690 /* Add a reference to the FDE for this routine. */
10691 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10692 #endif
10694 /* Define the "frame base" location for this routine. We use the
10695 frame pointer or stack pointer registers, since the RTL for local
10696 variables is relative to one of them. */
10697 fp_reg
10698 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10699 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10701 #if 0
10702 /* ??? This fails for nested inline functions, because context_display
10703 is not part of the state saved/restored for inline functions. */
10704 if (current_function_needs_context)
10705 add_AT_location_description (subr_die, DW_AT_static_link,
10706 loc_descriptor (lookup_static_chain (decl)));
10707 #endif
10710 /* Now output descriptions of the arguments for this function. This gets
10711 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10712 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10713 `...' at the end of the formal parameter list. In order to find out if
10714 there was a trailing ellipsis or not, we must instead look at the type
10715 associated with the FUNCTION_DECL. This will be a node of type
10716 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10717 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10718 an ellipsis at the end. */
10720 /* In the case where we are describing a mere function declaration, all we
10721 need to do here (and all we *can* do here) is to describe the *types* of
10722 its formal parameters. */
10723 if (debug_info_level <= DINFO_LEVEL_TERSE)
10725 else if (declaration)
10726 gen_formal_types_die (decl, subr_die);
10727 else
10729 /* Generate DIEs to represent all known formal parameters. */
10730 tree arg_decls = DECL_ARGUMENTS (decl);
10731 tree parm;
10733 /* When generating DIEs, generate the unspecified_parameters DIE
10734 instead if we come across the arg "__builtin_va_alist" */
10735 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10736 if (TREE_CODE (parm) == PARM_DECL)
10738 if (DECL_NAME (parm)
10739 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10740 "__builtin_va_alist"))
10741 gen_unspecified_parameters_die (parm, subr_die);
10742 else
10743 gen_decl_die (parm, subr_die);
10746 /* Decide whether we need an unspecified_parameters DIE at the end.
10747 There are 2 more cases to do this for: 1) the ansi ... declaration -
10748 this is detectable when the end of the arg list is not a
10749 void_type_node 2) an unprototyped function declaration (not a
10750 definition). This just means that we have no info about the
10751 parameters at all. */
10752 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10753 if (fn_arg_types != NULL)
10755 /* this is the prototyped case, check for ... */
10756 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10757 gen_unspecified_parameters_die (decl, subr_die);
10759 else if (DECL_INITIAL (decl) == NULL_TREE)
10760 gen_unspecified_parameters_die (decl, subr_die);
10763 /* Output Dwarf info for all of the stuff within the body of the function
10764 (if it has one - it may be just a declaration). */
10765 outer_scope = DECL_INITIAL (decl);
10767 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10768 a function. This BLOCK actually represents the outermost binding contour
10769 for the function, i.e. the contour in which the function's formal
10770 parameters and labels get declared. Curiously, it appears that the front
10771 end doesn't actually put the PARM_DECL nodes for the current function onto
10772 the BLOCK_VARS list for this outer scope, but are strung off of the
10773 DECL_ARGUMENTS list for the function instead.
10775 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10776 the LABEL_DECL nodes for the function however, and we output DWARF info
10777 for those in decls_for_scope. Just within the `outer_scope' there will be
10778 a BLOCK node representing the function's outermost pair of curly braces,
10779 and any blocks used for the base and member initializers of a C++
10780 constructor function. */
10781 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10783 current_function_has_inlines = 0;
10784 decls_for_scope (outer_scope, subr_die, 0);
10786 #if 0 && defined (MIPS_DEBUGGING_INFO)
10787 if (current_function_has_inlines)
10789 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10790 if (! comp_unit_has_inlines)
10792 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10793 comp_unit_has_inlines = 1;
10796 #endif
10800 /* Generate a DIE to represent a declared data object. */
10802 static void
10803 gen_variable_die (tree decl, dw_die_ref context_die)
10805 tree origin = decl_ultimate_origin (decl);
10806 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
10808 dw_die_ref old_die = lookup_decl_die (decl);
10809 int declaration = (DECL_EXTERNAL (decl)
10810 || class_scope_p (context_die));
10812 if (origin != NULL)
10813 add_abstract_origin_attribute (var_die, origin);
10815 /* Loop unrolling can create multiple blocks that refer to the same
10816 static variable, so we must test for the DW_AT_declaration flag.
10818 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10819 copy decls and set the DECL_ABSTRACT flag on them instead of
10820 sharing them.
10822 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10823 else if (old_die && TREE_STATIC (decl)
10824 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10826 /* This is a definition of a C++ class level static. */
10827 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10828 if (DECL_NAME (decl))
10830 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10832 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10833 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10835 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10836 != (unsigned) DECL_SOURCE_LINE (decl))
10838 add_AT_unsigned (var_die, DW_AT_decl_line,
10839 DECL_SOURCE_LINE (decl));
10842 else
10844 add_name_and_src_coords_attributes (var_die, decl);
10845 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
10846 TREE_THIS_VOLATILE (decl), context_die);
10848 if (TREE_PUBLIC (decl))
10849 add_AT_flag (var_die, DW_AT_external, 1);
10851 if (DECL_ARTIFICIAL (decl))
10852 add_AT_flag (var_die, DW_AT_artificial, 1);
10854 if (TREE_PROTECTED (decl))
10855 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10856 else if (TREE_PRIVATE (decl))
10857 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10860 if (declaration)
10861 add_AT_flag (var_die, DW_AT_declaration, 1);
10863 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10864 equate_decl_number_to_die (decl, var_die);
10866 if (! declaration && ! DECL_ABSTRACT (decl))
10868 add_location_or_const_value_attribute (var_die, decl);
10869 add_pubname (decl, var_die);
10871 else
10872 tree_add_const_value_attribute (var_die, decl);
10875 /* Generate a DIE to represent a label identifier. */
10877 static void
10878 gen_label_die (tree decl, dw_die_ref context_die)
10880 tree origin = decl_ultimate_origin (decl);
10881 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
10882 rtx insn;
10883 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10885 if (origin != NULL)
10886 add_abstract_origin_attribute (lbl_die, origin);
10887 else
10888 add_name_and_src_coords_attributes (lbl_die, decl);
10890 if (DECL_ABSTRACT (decl))
10891 equate_decl_number_to_die (decl, lbl_die);
10892 else
10894 insn = DECL_RTL (decl);
10896 /* Deleted labels are programmer specified labels which have been
10897 eliminated because of various optimizations. We still emit them
10898 here so that it is possible to put breakpoints on them. */
10899 if (GET_CODE (insn) == CODE_LABEL
10900 || ((GET_CODE (insn) == NOTE
10901 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10903 /* When optimization is enabled (via -O) some parts of the compiler
10904 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10905 represent source-level labels which were explicitly declared by
10906 the user. This really shouldn't be happening though, so catch
10907 it if it ever does happen. */
10908 if (INSN_DELETED_P (insn))
10909 abort ();
10911 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10912 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10917 /* Generate a DIE for a lexical block. */
10919 static void
10920 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
10922 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
10923 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10925 if (! BLOCK_ABSTRACT (stmt))
10927 if (BLOCK_FRAGMENT_CHAIN (stmt))
10929 tree chain;
10931 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
10933 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10936 add_ranges (chain);
10937 chain = BLOCK_FRAGMENT_CHAIN (chain);
10939 while (chain);
10940 add_ranges (NULL);
10942 else
10944 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10945 BLOCK_NUMBER (stmt));
10946 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10947 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10948 BLOCK_NUMBER (stmt));
10949 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10953 decls_for_scope (stmt, stmt_die, depth);
10956 /* Generate a DIE for an inlined subprogram. */
10958 static void
10959 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
10961 if (! BLOCK_ABSTRACT (stmt))
10963 dw_die_ref subr_die
10964 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
10965 tree decl = block_ultimate_origin (stmt);
10966 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10968 /* Emit info for the abstract instance first, if we haven't yet. */
10969 dwarf2out_abstract_function (decl);
10971 add_abstract_origin_attribute (subr_die, decl);
10972 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10973 BLOCK_NUMBER (stmt));
10974 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10975 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10976 BLOCK_NUMBER (stmt));
10977 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10978 decls_for_scope (stmt, subr_die, depth);
10979 current_function_has_inlines = 1;
10981 else
10982 /* We may get here if we're the outer block of function A that was
10983 inlined into function B that was inlined into function C. When
10984 generating debugging info for C, dwarf2out_abstract_function(B)
10985 would mark all inlined blocks as abstract, including this one.
10986 So, we wouldn't (and shouldn't) expect labels to be generated
10987 for this one. Instead, just emit debugging info for
10988 declarations within the block. This is particularly important
10989 in the case of initializers of arguments passed from B to us:
10990 if they're statement expressions containing declarations, we
10991 wouldn't generate dies for their abstract variables, and then,
10992 when generating dies for the real variables, we'd die (pun
10993 intended :-) */
10994 gen_lexical_block_die (stmt, context_die, depth);
10997 /* Generate a DIE for a field in a record, or structure. */
10999 static void
11000 gen_field_die (tree decl, dw_die_ref context_die)
11002 dw_die_ref decl_die;
11004 if (TREE_TYPE (decl) == error_mark_node)
11005 return;
11007 decl_die = new_die (DW_TAG_member, context_die, decl);
11008 add_name_and_src_coords_attributes (decl_die, decl);
11009 add_type_attribute (decl_die, member_declared_type (decl),
11010 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
11011 context_die);
11013 if (DECL_BIT_FIELD_TYPE (decl))
11015 add_byte_size_attribute (decl_die, decl);
11016 add_bit_size_attribute (decl_die, decl);
11017 add_bit_offset_attribute (decl_die, decl);
11020 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
11021 add_data_member_location_attribute (decl_die, decl);
11023 if (DECL_ARTIFICIAL (decl))
11024 add_AT_flag (decl_die, DW_AT_artificial, 1);
11026 if (TREE_PROTECTED (decl))
11027 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
11028 else if (TREE_PRIVATE (decl))
11029 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
11032 #if 0
11033 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11034 Use modified_type_die instead.
11035 We keep this code here just in case these types of DIEs may be needed to
11036 represent certain things in other languages (e.g. Pascal) someday. */
11038 static void
11039 gen_pointer_type_die (tree type, dw_die_ref context_die)
11041 dw_die_ref ptr_die
11042 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
11044 equate_type_number_to_die (type, ptr_die);
11045 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
11046 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
11049 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11050 Use modified_type_die instead.
11051 We keep this code here just in case these types of DIEs may be needed to
11052 represent certain things in other languages (e.g. Pascal) someday. */
11054 static void
11055 gen_reference_type_die (tree type, dw_die_ref context_die)
11057 dw_die_ref ref_die
11058 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
11060 equate_type_number_to_die (type, ref_die);
11061 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
11062 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
11064 #endif
11066 /* Generate a DIE for a pointer to a member type. */
11068 static void
11069 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
11071 dw_die_ref ptr_die
11072 = new_die (DW_TAG_ptr_to_member_type,
11073 scope_die_for (type, context_die), type);
11075 equate_type_number_to_die (type, ptr_die);
11076 add_AT_die_ref (ptr_die, DW_AT_containing_type,
11077 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
11078 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
11081 /* Generate the DIE for the compilation unit. */
11083 static dw_die_ref
11084 gen_compile_unit_die (const char *filename)
11086 dw_die_ref die;
11087 char producer[250];
11088 const char *language_string = lang_hooks.name;
11089 int language;
11091 die = new_die (DW_TAG_compile_unit, NULL, NULL);
11093 if (filename)
11095 add_name_attribute (die, filename);
11096 /* Don't add cwd for <built-in>. */
11097 if (filename[0] != DIR_SEPARATOR && filename[0] != '<')
11098 add_comp_dir_attribute (die);
11101 sprintf (producer, "%s %s", language_string, version_string);
11103 #ifdef MIPS_DEBUGGING_INFO
11104 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
11105 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
11106 not appear in the producer string, the debugger reaches the conclusion
11107 that the object file is stripped and has no debugging information.
11108 To get the MIPS/SGI debugger to believe that there is debugging
11109 information in the object file, we add a -g to the producer string. */
11110 if (debug_info_level > DINFO_LEVEL_TERSE)
11111 strcat (producer, " -g");
11112 #endif
11114 add_AT_string (die, DW_AT_producer, producer);
11116 if (strcmp (language_string, "GNU C++") == 0)
11117 language = DW_LANG_C_plus_plus;
11118 else if (strcmp (language_string, "GNU Ada") == 0)
11119 language = DW_LANG_Ada95;
11120 else if (strcmp (language_string, "GNU F77") == 0)
11121 language = DW_LANG_Fortran77;
11122 else if (strcmp (language_string, "GNU Pascal") == 0)
11123 language = DW_LANG_Pascal83;
11124 else if (strcmp (language_string, "GNU Java") == 0)
11125 language = DW_LANG_Java;
11126 else
11127 language = DW_LANG_C89;
11129 add_AT_unsigned (die, DW_AT_language, language);
11130 return die;
11133 /* Generate a DIE for a string type. */
11135 static void
11136 gen_string_type_die (tree type, dw_die_ref context_die)
11138 dw_die_ref type_die
11139 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
11141 equate_type_number_to_die (type, type_die);
11143 /* ??? Fudge the string length attribute for now.
11144 TODO: add string length info. */
11145 #if 0
11146 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
11147 bound_representation (upper_bound, 0, 'u');
11148 #endif
11151 /* Generate the DIE for a base class. */
11153 static void
11154 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
11156 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
11158 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
11159 add_data_member_location_attribute (die, binfo);
11161 if (TREE_VIA_VIRTUAL (binfo))
11162 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
11164 if (access == access_public_node)
11165 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
11166 else if (access == access_protected_node)
11167 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
11170 /* Generate a DIE for a class member. */
11172 static void
11173 gen_member_die (tree type, dw_die_ref context_die)
11175 tree member;
11176 tree binfo = TYPE_BINFO (type);
11177 dw_die_ref child;
11179 /* If this is not an incomplete type, output descriptions of each of its
11180 members. Note that as we output the DIEs necessary to represent the
11181 members of this record or union type, we will also be trying to output
11182 DIEs to represent the *types* of those members. However the `type'
11183 function (above) will specifically avoid generating type DIEs for member
11184 types *within* the list of member DIEs for this (containing) type except
11185 for those types (of members) which are explicitly marked as also being
11186 members of this (containing) type themselves. The g++ front- end can
11187 force any given type to be treated as a member of some other (containing)
11188 type by setting the TYPE_CONTEXT of the given (member) type to point to
11189 the TREE node representing the appropriate (containing) type. */
11191 /* First output info about the base classes. */
11192 if (binfo && BINFO_BASETYPES (binfo))
11194 tree bases = BINFO_BASETYPES (binfo);
11195 tree accesses = BINFO_BASEACCESSES (binfo);
11196 int n_bases = TREE_VEC_LENGTH (bases);
11197 int i;
11199 for (i = 0; i < n_bases; i++)
11200 gen_inheritance_die (TREE_VEC_ELT (bases, i),
11201 (accesses ? TREE_VEC_ELT (accesses, i)
11202 : access_public_node), context_die);
11205 /* Now output info about the data members and type members. */
11206 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
11208 /* If we thought we were generating minimal debug info for TYPE
11209 and then changed our minds, some of the member declarations
11210 may have already been defined. Don't define them again, but
11211 do put them in the right order. */
11213 child = lookup_decl_die (member);
11214 if (child)
11215 splice_child_die (context_die, child);
11216 else
11217 gen_decl_die (member, context_die);
11220 /* Now output info about the function members (if any). */
11221 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
11223 /* Don't include clones in the member list. */
11224 if (DECL_ABSTRACT_ORIGIN (member))
11225 continue;
11227 child = lookup_decl_die (member);
11228 if (child)
11229 splice_child_die (context_die, child);
11230 else
11231 gen_decl_die (member, context_die);
11235 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
11236 is set, we pretend that the type was never defined, so we only get the
11237 member DIEs needed by later specification DIEs. */
11239 static void
11240 gen_struct_or_union_type_die (tree type, dw_die_ref context_die)
11242 dw_die_ref type_die = lookup_type_die (type);
11243 dw_die_ref scope_die = 0;
11244 int nested = 0;
11245 int complete = (TYPE_SIZE (type)
11246 && (! TYPE_STUB_DECL (type)
11247 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
11249 if (type_die && ! complete)
11250 return;
11252 if (TYPE_CONTEXT (type) != NULL_TREE
11253 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
11254 nested = 1;
11256 scope_die = scope_die_for (type, context_die);
11258 if (! type_die || (nested && scope_die == comp_unit_die))
11259 /* First occurrence of type or toplevel definition of nested class. */
11261 dw_die_ref old_die = type_die;
11263 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
11264 ? DW_TAG_structure_type : DW_TAG_union_type,
11265 scope_die, type);
11266 equate_type_number_to_die (type, type_die);
11267 if (old_die)
11268 add_AT_die_ref (type_die, DW_AT_specification, old_die);
11269 else
11270 add_name_attribute (type_die, type_tag (type));
11272 else
11273 remove_AT (type_die, DW_AT_declaration);
11275 /* If this type has been completed, then give it a byte_size attribute and
11276 then give a list of members. */
11277 if (complete)
11279 /* Prevent infinite recursion in cases where the type of some member of
11280 this type is expressed in terms of this type itself. */
11281 TREE_ASM_WRITTEN (type) = 1;
11282 add_byte_size_attribute (type_die, type);
11283 if (TYPE_STUB_DECL (type) != NULL_TREE)
11284 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
11286 /* If the first reference to this type was as the return type of an
11287 inline function, then it may not have a parent. Fix this now. */
11288 if (type_die->die_parent == NULL)
11289 add_child_die (scope_die, type_die);
11291 push_decl_scope (type);
11292 gen_member_die (type, type_die);
11293 pop_decl_scope ();
11295 /* GNU extension: Record what type our vtable lives in. */
11296 if (TYPE_VFIELD (type))
11298 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
11300 gen_type_die (vtype, context_die);
11301 add_AT_die_ref (type_die, DW_AT_containing_type,
11302 lookup_type_die (vtype));
11305 else
11307 add_AT_flag (type_die, DW_AT_declaration, 1);
11309 /* We don't need to do this for function-local types. */
11310 if (TYPE_STUB_DECL (type)
11311 && ! decl_function_context (TYPE_STUB_DECL (type)))
11312 VARRAY_PUSH_TREE (incomplete_types, type);
11316 /* Generate a DIE for a subroutine _type_. */
11318 static void
11319 gen_subroutine_type_die (tree type, dw_die_ref context_die)
11321 tree return_type = TREE_TYPE (type);
11322 dw_die_ref subr_die
11323 = new_die (DW_TAG_subroutine_type,
11324 scope_die_for (type, context_die), type);
11326 equate_type_number_to_die (type, subr_die);
11327 add_prototyped_attribute (subr_die, type);
11328 add_type_attribute (subr_die, return_type, 0, 0, context_die);
11329 gen_formal_types_die (type, subr_die);
11332 /* Generate a DIE for a type definition. */
11334 static void
11335 gen_typedef_die (tree decl, dw_die_ref context_die)
11337 dw_die_ref type_die;
11338 tree origin;
11340 if (TREE_ASM_WRITTEN (decl))
11341 return;
11343 TREE_ASM_WRITTEN (decl) = 1;
11344 type_die = new_die (DW_TAG_typedef, context_die, decl);
11345 origin = decl_ultimate_origin (decl);
11346 if (origin != NULL)
11347 add_abstract_origin_attribute (type_die, origin);
11348 else
11350 tree type;
11352 add_name_and_src_coords_attributes (type_die, decl);
11353 if (DECL_ORIGINAL_TYPE (decl))
11355 type = DECL_ORIGINAL_TYPE (decl);
11357 if (type == TREE_TYPE (decl))
11358 abort ();
11359 else
11360 equate_type_number_to_die (TREE_TYPE (decl), type_die);
11362 else
11363 type = TREE_TYPE (decl);
11365 add_type_attribute (type_die, type, TREE_READONLY (decl),
11366 TREE_THIS_VOLATILE (decl), context_die);
11369 if (DECL_ABSTRACT (decl))
11370 equate_decl_number_to_die (decl, type_die);
11373 /* Generate a type description DIE. */
11375 static void
11376 gen_type_die (tree type, dw_die_ref context_die)
11378 int need_pop;
11380 if (type == NULL_TREE || type == error_mark_node)
11381 return;
11383 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11384 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
11386 if (TREE_ASM_WRITTEN (type))
11387 return;
11389 /* Prevent broken recursion; we can't hand off to the same type. */
11390 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type)
11391 abort ();
11393 TREE_ASM_WRITTEN (type) = 1;
11394 gen_decl_die (TYPE_NAME (type), context_die);
11395 return;
11398 /* We are going to output a DIE to represent the unqualified version
11399 of this type (i.e. without any const or volatile qualifiers) so
11400 get the main variant (i.e. the unqualified version) of this type
11401 now. (Vectors are special because the debugging info is in the
11402 cloned type itself). */
11403 if (TREE_CODE (type) != VECTOR_TYPE)
11404 type = type_main_variant (type);
11406 if (TREE_ASM_WRITTEN (type))
11407 return;
11409 switch (TREE_CODE (type))
11411 case ERROR_MARK:
11412 break;
11414 case POINTER_TYPE:
11415 case REFERENCE_TYPE:
11416 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11417 ensures that the gen_type_die recursion will terminate even if the
11418 type is recursive. Recursive types are possible in Ada. */
11419 /* ??? We could perhaps do this for all types before the switch
11420 statement. */
11421 TREE_ASM_WRITTEN (type) = 1;
11423 /* For these types, all that is required is that we output a DIE (or a
11424 set of DIEs) to represent the "basis" type. */
11425 gen_type_die (TREE_TYPE (type), context_die);
11426 break;
11428 case OFFSET_TYPE:
11429 /* This code is used for C++ pointer-to-data-member types.
11430 Output a description of the relevant class type. */
11431 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
11433 /* Output a description of the type of the object pointed to. */
11434 gen_type_die (TREE_TYPE (type), context_die);
11436 /* Now output a DIE to represent this pointer-to-data-member type
11437 itself. */
11438 gen_ptr_to_mbr_type_die (type, context_die);
11439 break;
11441 case SET_TYPE:
11442 gen_type_die (TYPE_DOMAIN (type), context_die);
11443 gen_set_type_die (type, context_die);
11444 break;
11446 case FILE_TYPE:
11447 gen_type_die (TREE_TYPE (type), context_die);
11448 abort (); /* No way to represent these in Dwarf yet! */
11449 break;
11451 case FUNCTION_TYPE:
11452 /* Force out return type (in case it wasn't forced out already). */
11453 gen_type_die (TREE_TYPE (type), context_die);
11454 gen_subroutine_type_die (type, context_die);
11455 break;
11457 case METHOD_TYPE:
11458 /* Force out return type (in case it wasn't forced out already). */
11459 gen_type_die (TREE_TYPE (type), context_die);
11460 gen_subroutine_type_die (type, context_die);
11461 break;
11463 case ARRAY_TYPE:
11464 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
11466 gen_type_die (TREE_TYPE (type), context_die);
11467 gen_string_type_die (type, context_die);
11469 else
11470 gen_array_type_die (type, context_die);
11471 break;
11473 case VECTOR_TYPE:
11474 gen_array_type_die (type, context_die);
11475 break;
11477 case ENUMERAL_TYPE:
11478 case RECORD_TYPE:
11479 case UNION_TYPE:
11480 case QUAL_UNION_TYPE:
11481 /* If this is a nested type whose containing class hasn't been written
11482 out yet, writing it out will cover this one, too. This does not apply
11483 to instantiations of member class templates; they need to be added to
11484 the containing class as they are generated. FIXME: This hurts the
11485 idea of combining type decls from multiple TUs, since we can't predict
11486 what set of template instantiations we'll get. */
11487 if (TYPE_CONTEXT (type)
11488 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
11489 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
11491 gen_type_die (TYPE_CONTEXT (type), context_die);
11493 if (TREE_ASM_WRITTEN (type))
11494 return;
11496 /* If that failed, attach ourselves to the stub. */
11497 push_decl_scope (TYPE_CONTEXT (type));
11498 context_die = lookup_type_die (TYPE_CONTEXT (type));
11499 need_pop = 1;
11501 else
11502 need_pop = 0;
11504 if (TREE_CODE (type) == ENUMERAL_TYPE)
11505 gen_enumeration_type_die (type, context_die);
11506 else
11507 gen_struct_or_union_type_die (type, context_die);
11509 if (need_pop)
11510 pop_decl_scope ();
11512 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11513 it up if it is ever completed. gen_*_type_die will set it for us
11514 when appropriate. */
11515 return;
11517 case VOID_TYPE:
11518 case INTEGER_TYPE:
11519 case REAL_TYPE:
11520 case COMPLEX_TYPE:
11521 case BOOLEAN_TYPE:
11522 case CHAR_TYPE:
11523 /* No DIEs needed for fundamental types. */
11524 break;
11526 case LANG_TYPE:
11527 /* No Dwarf representation currently defined. */
11528 break;
11530 default:
11531 abort ();
11534 TREE_ASM_WRITTEN (type) = 1;
11537 /* Generate a DIE for a tagged type instantiation. */
11539 static void
11540 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
11542 if (type == NULL_TREE || type == error_mark_node)
11543 return;
11545 /* We are going to output a DIE to represent the unqualified version of
11546 this type (i.e. without any const or volatile qualifiers) so make sure
11547 that we have the main variant (i.e. the unqualified version) of this
11548 type now. */
11549 if (type != type_main_variant (type))
11550 abort ();
11552 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11553 an instance of an unresolved type. */
11555 switch (TREE_CODE (type))
11557 case ERROR_MARK:
11558 break;
11560 case ENUMERAL_TYPE:
11561 gen_inlined_enumeration_type_die (type, context_die);
11562 break;
11564 case RECORD_TYPE:
11565 gen_inlined_structure_type_die (type, context_die);
11566 break;
11568 case UNION_TYPE:
11569 case QUAL_UNION_TYPE:
11570 gen_inlined_union_type_die (type, context_die);
11571 break;
11573 default:
11574 abort ();
11578 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11579 things which are local to the given block. */
11581 static void
11582 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
11584 int must_output_die = 0;
11585 tree origin;
11586 tree decl;
11587 enum tree_code origin_code;
11589 /* Ignore blocks never really used to make RTL. */
11590 if (stmt == NULL_TREE || !TREE_USED (stmt)
11591 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11592 return;
11594 /* If the block is one fragment of a non-contiguous block, do not
11595 process the variables, since they will have been done by the
11596 origin block. Do process subblocks. */
11597 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11599 tree sub;
11601 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
11602 gen_block_die (sub, context_die, depth + 1);
11604 return;
11607 /* Determine the "ultimate origin" of this block. This block may be an
11608 inlined instance of an inlined instance of inline function, so we have
11609 to trace all of the way back through the origin chain to find out what
11610 sort of node actually served as the original seed for the creation of
11611 the current block. */
11612 origin = block_ultimate_origin (stmt);
11613 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11615 /* Determine if we need to output any Dwarf DIEs at all to represent this
11616 block. */
11617 if (origin_code == FUNCTION_DECL)
11618 /* The outer scopes for inlinings *must* always be represented. We
11619 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11620 must_output_die = 1;
11621 else
11623 /* In the case where the current block represents an inlining of the
11624 "body block" of an inline function, we must *NOT* output any DIE for
11625 this block because we have already output a DIE to represent the whole
11626 inlined function scope and the "body block" of any function doesn't
11627 really represent a different scope according to ANSI C rules. So we
11628 check here to make sure that this block does not represent a "body
11629 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11630 if (! is_body_block (origin ? origin : stmt))
11632 /* Determine if this block directly contains any "significant"
11633 local declarations which we will need to output DIEs for. */
11634 if (debug_info_level > DINFO_LEVEL_TERSE)
11635 /* We are not in terse mode so *any* local declaration counts
11636 as being a "significant" one. */
11637 must_output_die = (BLOCK_VARS (stmt) != NULL);
11638 else
11639 /* We are in terse mode, so only local (nested) function
11640 definitions count as "significant" local declarations. */
11641 for (decl = BLOCK_VARS (stmt);
11642 decl != NULL; decl = TREE_CHAIN (decl))
11643 if (TREE_CODE (decl) == FUNCTION_DECL
11644 && DECL_INITIAL (decl))
11646 must_output_die = 1;
11647 break;
11652 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11653 DIE for any block which contains no significant local declarations at
11654 all. Rather, in such cases we just call `decls_for_scope' so that any
11655 needed Dwarf info for any sub-blocks will get properly generated. Note
11656 that in terse mode, our definition of what constitutes a "significant"
11657 local declaration gets restricted to include only inlined function
11658 instances and local (nested) function definitions. */
11659 if (must_output_die)
11661 if (origin_code == FUNCTION_DECL)
11662 gen_inlined_subroutine_die (stmt, context_die, depth);
11663 else
11664 gen_lexical_block_die (stmt, context_die, depth);
11666 else
11667 decls_for_scope (stmt, context_die, depth);
11670 /* Generate all of the decls declared within a given scope and (recursively)
11671 all of its sub-blocks. */
11673 static void
11674 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
11676 tree decl;
11677 tree subblocks;
11679 /* Ignore blocks never really used to make RTL. */
11680 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11681 return;
11683 /* Output the DIEs to represent all of the data objects and typedefs
11684 declared directly within this block but not within any nested
11685 sub-blocks. Also, nested function and tag DIEs have been
11686 generated with a parent of NULL; fix that up now. */
11687 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
11689 dw_die_ref die;
11691 if (TREE_CODE (decl) == FUNCTION_DECL)
11692 die = lookup_decl_die (decl);
11693 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11694 die = lookup_type_die (TREE_TYPE (decl));
11695 else
11696 die = NULL;
11698 if (die != NULL && die->die_parent == NULL)
11699 add_child_die (context_die, die);
11700 else
11701 gen_decl_die (decl, context_die);
11704 /* If we're at -g1, we're not interested in subblocks. */
11705 if (debug_info_level <= DINFO_LEVEL_TERSE)
11706 return;
11708 /* Output the DIEs to represent all sub-blocks (and the items declared
11709 therein) of this block. */
11710 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11711 subblocks != NULL;
11712 subblocks = BLOCK_CHAIN (subblocks))
11713 gen_block_die (subblocks, context_die, depth + 1);
11716 /* Is this a typedef we can avoid emitting? */
11718 static inline int
11719 is_redundant_typedef (tree decl)
11721 if (TYPE_DECL_IS_STUB (decl))
11722 return 1;
11724 if (DECL_ARTIFICIAL (decl)
11725 && DECL_CONTEXT (decl)
11726 && is_tagged_type (DECL_CONTEXT (decl))
11727 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11728 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11729 /* Also ignore the artificial member typedef for the class name. */
11730 return 1;
11732 return 0;
11735 /* Generate Dwarf debug information for a decl described by DECL. */
11737 static void
11738 gen_decl_die (tree decl, dw_die_ref context_die)
11740 tree origin;
11742 if (DECL_P (decl) && DECL_IGNORED_P (decl))
11743 return;
11745 switch (TREE_CODE (decl))
11747 case ERROR_MARK:
11748 break;
11750 case CONST_DECL:
11751 /* The individual enumerators of an enum type get output when we output
11752 the Dwarf representation of the relevant enum type itself. */
11753 break;
11755 case FUNCTION_DECL:
11756 /* Don't output any DIEs to represent mere function declarations,
11757 unless they are class members or explicit block externs. */
11758 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11759 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11760 break;
11762 /* If we're emitting a clone, emit info for the abstract instance. */
11763 if (DECL_ORIGIN (decl) != decl)
11764 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11766 /* If we're emitting an out-of-line copy of an inline function,
11767 emit info for the abstract instance and set up to refer to it. */
11768 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11769 && ! class_scope_p (context_die)
11770 /* dwarf2out_abstract_function won't emit a die if this is just
11771 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11772 that case, because that works only if we have a die. */
11773 && DECL_INITIAL (decl) != NULL_TREE)
11775 dwarf2out_abstract_function (decl);
11776 set_decl_origin_self (decl);
11779 /* Otherwise we're emitting the primary DIE for this decl. */
11780 else if (debug_info_level > DINFO_LEVEL_TERSE)
11782 /* Before we describe the FUNCTION_DECL itself, make sure that we
11783 have described its return type. */
11784 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11786 /* And its virtual context. */
11787 if (DECL_VINDEX (decl) != NULL_TREE)
11788 gen_type_die (DECL_CONTEXT (decl), context_die);
11790 /* And its containing type. */
11791 origin = decl_class_context (decl);
11792 if (origin != NULL_TREE)
11793 gen_type_die_for_member (origin, decl, context_die);
11796 /* Now output a DIE to represent the function itself. */
11797 gen_subprogram_die (decl, context_die);
11798 break;
11800 case TYPE_DECL:
11801 /* If we are in terse mode, don't generate any DIEs to represent any
11802 actual typedefs. */
11803 if (debug_info_level <= DINFO_LEVEL_TERSE)
11804 break;
11806 /* In the special case of a TYPE_DECL node representing the declaration
11807 of some type tag, if the given TYPE_DECL is marked as having been
11808 instantiated from some other (original) TYPE_DECL node (e.g. one which
11809 was generated within the original definition of an inline function) we
11810 have to generate a special (abbreviated) DW_TAG_structure_type,
11811 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11812 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11814 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11815 break;
11818 if (is_redundant_typedef (decl))
11819 gen_type_die (TREE_TYPE (decl), context_die);
11820 else
11821 /* Output a DIE to represent the typedef itself. */
11822 gen_typedef_die (decl, context_die);
11823 break;
11825 case LABEL_DECL:
11826 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11827 gen_label_die (decl, context_die);
11828 break;
11830 case VAR_DECL:
11831 /* If we are in terse mode, don't generate any DIEs to represent any
11832 variable declarations or definitions. */
11833 if (debug_info_level <= DINFO_LEVEL_TERSE)
11834 break;
11836 /* Output any DIEs that are needed to specify the type of this data
11837 object. */
11838 gen_type_die (TREE_TYPE (decl), context_die);
11840 /* And its containing type. */
11841 origin = decl_class_context (decl);
11842 if (origin != NULL_TREE)
11843 gen_type_die_for_member (origin, decl, context_die);
11845 /* Now output the DIE to represent the data object itself. This gets
11846 complicated because of the possibility that the VAR_DECL really
11847 represents an inlined instance of a formal parameter for an inline
11848 function. */
11849 origin = decl_ultimate_origin (decl);
11850 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11851 gen_formal_parameter_die (decl, context_die);
11852 else
11853 gen_variable_die (decl, context_die);
11854 break;
11856 case FIELD_DECL:
11857 /* Ignore the nameless fields that are used to skip bits but handle C++
11858 anonymous unions. */
11859 if (DECL_NAME (decl) != NULL_TREE
11860 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11862 gen_type_die (member_declared_type (decl), context_die);
11863 gen_field_die (decl, context_die);
11865 break;
11867 case PARM_DECL:
11868 gen_type_die (TREE_TYPE (decl), context_die);
11869 gen_formal_parameter_die (decl, context_die);
11870 break;
11872 case NAMESPACE_DECL:
11873 /* Ignore for now. */
11874 break;
11876 default:
11877 if ((int)TREE_CODE (decl) > NUM_TREE_CODES)
11878 /* Probably some frontend-internal decl. Assume we don't care. */
11879 break;
11880 abort ();
11884 /* Add Ada "use" clause information for SGI Workshop debugger. */
11886 void
11887 dwarf2out_add_library_unit_info (const char *filename, const char *context_list)
11889 unsigned int file_index;
11891 if (filename != NULL)
11893 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
11894 tree context_list_decl
11895 = build_decl (LABEL_DECL, get_identifier (context_list),
11896 void_type_node);
11898 TREE_PUBLIC (context_list_decl) = TRUE;
11899 add_name_attribute (unit_die, context_list);
11900 file_index = lookup_filename (filename);
11901 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11902 add_pubname (context_list_decl, unit_die);
11906 /* Output debug information for global decl DECL. Called from toplev.c after
11907 compilation proper has finished. */
11909 static void
11910 dwarf2out_global_decl (tree decl)
11912 /* Output DWARF2 information for file-scope tentative data object
11913 declarations, file-scope (extern) function declarations (which had no
11914 corresponding body) and file-scope tagged type declarations and
11915 definitions which have not yet been forced out. */
11916 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11917 dwarf2out_decl (decl);
11920 /* Write the debugging output for DECL. */
11922 void
11923 dwarf2out_decl (tree decl)
11925 dw_die_ref context_die = comp_unit_die;
11927 switch (TREE_CODE (decl))
11929 case ERROR_MARK:
11930 return;
11932 case FUNCTION_DECL:
11933 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11934 builtin function. Explicit programmer-supplied declarations of
11935 these same functions should NOT be ignored however. */
11936 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11937 return;
11939 /* What we would really like to do here is to filter out all mere
11940 file-scope declarations of file-scope functions which are never
11941 referenced later within this translation unit (and keep all of ones
11942 that *are* referenced later on) but we aren't clairvoyant, so we have
11943 no idea which functions will be referenced in the future (i.e. later
11944 on within the current translation unit). So here we just ignore all
11945 file-scope function declarations which are not also definitions. If
11946 and when the debugger needs to know something about these functions,
11947 it will have to hunt around and find the DWARF information associated
11948 with the definition of the function.
11950 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11951 nodes represent definitions and which ones represent mere
11952 declarations. We have to check DECL_INITIAL instead. That's because
11953 the C front-end supports some weird semantics for "extern inline"
11954 function definitions. These can get inlined within the current
11955 translation unit (an thus, we need to generate Dwarf info for their
11956 abstract instances so that the Dwarf info for the concrete inlined
11957 instances can have something to refer to) but the compiler never
11958 generates any out-of-lines instances of such things (despite the fact
11959 that they *are* definitions).
11961 The important point is that the C front-end marks these "extern
11962 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11963 them anyway. Note that the C++ front-end also plays some similar games
11964 for inline function definitions appearing within include files which
11965 also contain `#pragma interface' pragmas. */
11966 if (DECL_INITIAL (decl) == NULL_TREE)
11967 return;
11969 /* If we're a nested function, initially use a parent of NULL; if we're
11970 a plain function, this will be fixed up in decls_for_scope. If
11971 we're a method, it will be ignored, since we already have a DIE. */
11972 if (decl_function_context (decl)
11973 /* But if we're in terse mode, we don't care about scope. */
11974 && debug_info_level > DINFO_LEVEL_TERSE)
11975 context_die = NULL;
11976 break;
11978 case VAR_DECL:
11979 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11980 declaration and if the declaration was never even referenced from
11981 within this entire compilation unit. We suppress these DIEs in
11982 order to save space in the .debug section (by eliminating entries
11983 which are probably useless). Note that we must not suppress
11984 block-local extern declarations (whether used or not) because that
11985 would screw-up the debugger's name lookup mechanism and cause it to
11986 miss things which really ought to be in scope at a given point. */
11987 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11988 return;
11990 /* If we are in terse mode, don't generate any DIEs to represent any
11991 variable declarations or definitions. */
11992 if (debug_info_level <= DINFO_LEVEL_TERSE)
11993 return;
11994 break;
11996 case TYPE_DECL:
11997 /* Don't emit stubs for types unless they are needed by other DIEs. */
11998 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11999 return;
12001 /* Don't bother trying to generate any DIEs to represent any of the
12002 normal built-in types for the language we are compiling. */
12003 if (DECL_SOURCE_LINE (decl) == 0)
12005 /* OK, we need to generate one for `bool' so GDB knows what type
12006 comparisons have. */
12007 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
12008 == DW_LANG_C_plus_plus)
12009 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
12010 && ! DECL_IGNORED_P (decl))
12011 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
12013 return;
12016 /* If we are in terse mode, don't generate any DIEs for types. */
12017 if (debug_info_level <= DINFO_LEVEL_TERSE)
12018 return;
12020 /* If we're a function-scope tag, initially use a parent of NULL;
12021 this will be fixed up in decls_for_scope. */
12022 if (decl_function_context (decl))
12023 context_die = NULL;
12025 break;
12027 default:
12028 return;
12031 gen_decl_die (decl, context_die);
12034 /* Output a marker (i.e. a label) for the beginning of the generated code for
12035 a lexical block. */
12037 static void
12038 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
12039 unsigned int blocknum)
12041 function_section (current_function_decl);
12042 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
12045 /* Output a marker (i.e. a label) for the end of the generated code for a
12046 lexical block. */
12048 static void
12049 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
12051 function_section (current_function_decl);
12052 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
12055 /* Returns nonzero if it is appropriate not to emit any debugging
12056 information for BLOCK, because it doesn't contain any instructions.
12058 Don't allow this for blocks with nested functions or local classes
12059 as we would end up with orphans, and in the presence of scheduling
12060 we may end up calling them anyway. */
12062 static bool
12063 dwarf2out_ignore_block (tree block)
12065 tree decl;
12067 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
12068 if (TREE_CODE (decl) == FUNCTION_DECL
12069 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
12070 return 0;
12072 return 1;
12075 /* Lookup FILE_NAME (in the list of filenames that we know about here in
12076 dwarf2out.c) and return its "index". The index of each (known) filename is
12077 just a unique number which is associated with only that one filename. We
12078 need such numbers for the sake of generating labels (in the .debug_sfnames
12079 section) and references to those files numbers (in the .debug_srcinfo
12080 and.debug_macinfo sections). If the filename given as an argument is not
12081 found in our current list, add it to the list and assign it the next
12082 available unique index number. In order to speed up searches, we remember
12083 the index of the filename was looked up last. This handles the majority of
12084 all searches. */
12086 static unsigned
12087 lookup_filename (const char *file_name)
12089 size_t i, n;
12090 char *save_file_name;
12092 /* Check to see if the file name that was searched on the previous
12093 call matches this file name. If so, return the index. */
12094 if (file_table_last_lookup_index != 0)
12096 const char *last
12097 = VARRAY_CHAR_PTR (file_table, file_table_last_lookup_index);
12098 if (strcmp (file_name, last) == 0)
12099 return file_table_last_lookup_index;
12102 /* Didn't match the previous lookup, search the table */
12103 n = VARRAY_ACTIVE_SIZE (file_table);
12104 for (i = 1; i < n; i++)
12105 if (strcmp (file_name, VARRAY_CHAR_PTR (file_table, i)) == 0)
12107 file_table_last_lookup_index = i;
12108 return i;
12111 /* Add the new entry to the end of the filename table. */
12112 file_table_last_lookup_index = n;
12113 save_file_name = (char *) ggc_strdup (file_name);
12114 VARRAY_PUSH_CHAR_PTR (file_table, save_file_name);
12115 VARRAY_PUSH_UINT (file_table_emitted, 0);
12117 return i;
12120 static int
12121 maybe_emit_file (int fileno)
12123 if (DWARF2_ASM_LINE_DEBUG_INFO && fileno > 0)
12125 if (!VARRAY_UINT (file_table_emitted, fileno))
12127 VARRAY_UINT (file_table_emitted, fileno) = ++emitcount;
12128 fprintf (asm_out_file, "\t.file %u ",
12129 VARRAY_UINT (file_table_emitted, fileno));
12130 output_quoted_string (asm_out_file,
12131 VARRAY_CHAR_PTR (file_table, fileno));
12132 fputc ('\n', asm_out_file);
12134 return VARRAY_UINT (file_table_emitted, fileno);
12136 else
12137 return fileno;
12140 static void
12141 init_file_table (void)
12143 /* Allocate the initial hunk of the file_table. */
12144 VARRAY_CHAR_PTR_INIT (file_table, 64, "file_table");
12145 VARRAY_UINT_INIT (file_table_emitted, 64, "file_table_emitted");
12147 /* Skip the first entry - file numbers begin at 1. */
12148 VARRAY_PUSH_CHAR_PTR (file_table, NULL);
12149 VARRAY_PUSH_UINT (file_table_emitted, 0);
12150 file_table_last_lookup_index = 0;
12153 /* Output a label to mark the beginning of a source code line entry
12154 and record information relating to this source line, in
12155 'line_info_table' for later output of the .debug_line section. */
12157 static void
12158 dwarf2out_source_line (unsigned int line, const char *filename)
12160 if (debug_info_level >= DINFO_LEVEL_NORMAL
12161 && line != 0)
12163 function_section (current_function_decl);
12165 /* If requested, emit something human-readable. */
12166 if (flag_debug_asm)
12167 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
12168 filename, line);
12170 if (DWARF2_ASM_LINE_DEBUG_INFO)
12172 unsigned file_num = lookup_filename (filename);
12174 file_num = maybe_emit_file (file_num);
12176 /* Emit the .loc directive understood by GNU as. */
12177 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
12179 /* Indicate that line number info exists. */
12180 line_info_table_in_use++;
12182 /* Indicate that multiple line number tables exist. */
12183 if (DECL_SECTION_NAME (current_function_decl))
12184 separate_line_info_table_in_use++;
12186 else if (DECL_SECTION_NAME (current_function_decl))
12188 dw_separate_line_info_ref line_info;
12189 (*targetm.asm_out.internal_label) (asm_out_file, SEPARATE_LINE_CODE_LABEL,
12190 separate_line_info_table_in_use);
12192 /* expand the line info table if necessary */
12193 if (separate_line_info_table_in_use
12194 == separate_line_info_table_allocated)
12196 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
12197 separate_line_info_table
12198 = (dw_separate_line_info_ref)
12199 ggc_realloc (separate_line_info_table,
12200 separate_line_info_table_allocated
12201 * sizeof (dw_separate_line_info_entry));
12202 memset ((separate_line_info_table
12203 + separate_line_info_table_in_use),
12205 (LINE_INFO_TABLE_INCREMENT
12206 * sizeof (dw_separate_line_info_entry)));
12209 /* Add the new entry at the end of the line_info_table. */
12210 line_info
12211 = &separate_line_info_table[separate_line_info_table_in_use++];
12212 line_info->dw_file_num = lookup_filename (filename);
12213 line_info->dw_line_num = line;
12214 line_info->function = current_function_funcdef_no;
12216 else
12218 dw_line_info_ref line_info;
12220 (*targetm.asm_out.internal_label) (asm_out_file, LINE_CODE_LABEL,
12221 line_info_table_in_use);
12223 /* Expand the line info table if necessary. */
12224 if (line_info_table_in_use == line_info_table_allocated)
12226 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
12227 line_info_table
12228 = ggc_realloc (line_info_table,
12229 (line_info_table_allocated
12230 * sizeof (dw_line_info_entry)));
12231 memset (line_info_table + line_info_table_in_use, 0,
12232 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
12235 /* Add the new entry at the end of the line_info_table. */
12236 line_info = &line_info_table[line_info_table_in_use++];
12237 line_info->dw_file_num = lookup_filename (filename);
12238 line_info->dw_line_num = line;
12243 /* Record the beginning of a new source file. */
12245 static void
12246 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
12248 if (flag_eliminate_dwarf2_dups && !is_main_source)
12250 /* Record the beginning of the file for break_out_includes. */
12251 dw_die_ref bincl_die;
12253 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
12254 add_AT_string (bincl_die, DW_AT_name, filename);
12257 is_main_source = 0;
12259 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12261 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12262 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
12263 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
12264 lineno);
12265 maybe_emit_file (lookup_filename (filename));
12266 dw2_asm_output_data_uleb128 (lookup_filename (filename),
12267 "Filename we just started");
12271 /* Record the end of a source file. */
12273 static void
12274 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
12276 if (flag_eliminate_dwarf2_dups)
12277 /* Record the end of the file for break_out_includes. */
12278 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
12280 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12282 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12283 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12287 /* Called from debug_define in toplev.c. The `buffer' parameter contains
12288 the tail part of the directive line, i.e. the part which is past the
12289 initial whitespace, #, whitespace, directive-name, whitespace part. */
12291 static void
12292 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
12293 const char *buffer ATTRIBUTE_UNUSED)
12295 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12297 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12298 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
12299 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12300 dw2_asm_output_nstring (buffer, -1, "The macro");
12304 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
12305 the tail part of the directive line, i.e. the part which is past the
12306 initial whitespace, #, whitespace, directive-name, whitespace part. */
12308 static void
12309 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
12310 const char *buffer ATTRIBUTE_UNUSED)
12312 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12314 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12315 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
12316 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12317 dw2_asm_output_nstring (buffer, -1, "The macro");
12321 /* Set up for Dwarf output at the start of compilation. */
12323 static void
12324 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
12326 init_file_table ();
12328 /* Allocate the initial hunk of the decl_die_table. */
12329 decl_die_table = ggc_alloc_cleared (DECL_DIE_TABLE_INCREMENT
12330 * sizeof (dw_die_ref));
12331 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
12332 decl_die_table_in_use = 0;
12334 /* Allocate the initial hunk of the decl_scope_table. */
12335 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
12337 /* Allocate the initial hunk of the abbrev_die_table. */
12338 abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
12339 * sizeof (dw_die_ref));
12340 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
12341 /* Zero-th entry is allocated, but unused */
12342 abbrev_die_table_in_use = 1;
12344 /* Allocate the initial hunk of the line_info_table. */
12345 line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
12346 * sizeof (dw_line_info_entry));
12347 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
12349 /* Zero-th entry is allocated, but unused */
12350 line_info_table_in_use = 1;
12352 /* Generate the initial DIE for the .debug section. Note that the (string)
12353 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12354 will (typically) be a relative pathname and that this pathname should be
12355 taken as being relative to the directory from which the compiler was
12356 invoked when the given (base) source file was compiled. We will fill
12357 in this value in dwarf2out_finish. */
12358 comp_unit_die = gen_compile_unit_die (NULL);
12359 is_main_source = 1;
12361 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
12363 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
12365 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
12366 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
12367 DEBUG_ABBREV_SECTION_LABEL, 0);
12368 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12369 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
12370 else
12371 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
12373 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
12374 DEBUG_INFO_SECTION_LABEL, 0);
12375 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
12376 DEBUG_LINE_SECTION_LABEL, 0);
12377 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
12378 DEBUG_RANGES_SECTION_LABEL, 0);
12379 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12380 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
12381 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
12382 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
12383 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12384 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
12386 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12388 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12389 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
12390 DEBUG_MACINFO_SECTION_LABEL, 0);
12391 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
12394 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12396 text_section ();
12397 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
12401 /* A helper function for dwarf2out_finish called through
12402 ht_forall. Emit one queued .debug_str string. */
12404 static int
12405 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
12407 struct indirect_string_node *node = (struct indirect_string_node *) *h;
12409 if (node->form == DW_FORM_strp)
12411 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
12412 ASM_OUTPUT_LABEL (asm_out_file, node->label);
12413 assemble_string (node->str, strlen (node->str) + 1);
12416 return 1;
12421 /* Clear the marks for a die and its children.
12422 Be cool if the mark isn't set. */
12424 static void
12425 prune_unmark_dies (dw_die_ref die)
12427 dw_die_ref c;
12428 die->die_mark = 0;
12429 for (c = die->die_child; c; c = c->die_sib)
12430 prune_unmark_dies (c);
12434 /* Given DIE that we're marking as used, find any other dies
12435 it references as attributes and mark them as used. */
12437 static void
12438 prune_unused_types_walk_attribs (dw_die_ref die)
12440 dw_attr_ref a;
12442 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
12444 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
12446 /* A reference to another DIE.
12447 Make sure that it will get emitted. */
12448 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
12450 else if (a->dw_attr == DW_AT_decl_file)
12452 /* A reference to a file. Make sure the file name is emitted. */
12453 a->dw_attr_val.v.val_unsigned =
12454 maybe_emit_file (a->dw_attr_val.v.val_unsigned);
12460 /* Mark DIE as being used. If DOKIDS is true, then walk down
12461 to DIE's children. */
12463 static void
12464 prune_unused_types_mark (dw_die_ref die, int dokids)
12466 dw_die_ref c;
12468 if (die->die_mark == 0)
12470 /* We haven't done this node yet. Mark it as used. */
12471 die->die_mark = 1;
12473 /* We also have to mark its parents as used.
12474 (But we don't want to mark our parents' kids due to this.) */
12475 if (die->die_parent)
12476 prune_unused_types_mark (die->die_parent, 0);
12478 /* Mark any referenced nodes. */
12479 prune_unused_types_walk_attribs (die);
12482 if (dokids && die->die_mark != 2)
12484 /* We need to walk the children, but haven't done so yet.
12485 Remember that we've walked the kids. */
12486 die->die_mark = 2;
12488 /* Walk them. */
12489 for (c = die->die_child; c; c = c->die_sib)
12491 /* If this is an array type, we need to make sure our
12492 kids get marked, even if they're types. */
12493 if (die->die_tag == DW_TAG_array_type)
12494 prune_unused_types_mark (c, 1);
12495 else
12496 prune_unused_types_walk (c);
12502 /* Walk the tree DIE and mark types that we actually use. */
12504 static void
12505 prune_unused_types_walk (dw_die_ref die)
12507 dw_die_ref c;
12509 /* Don't do anything if this node is already marked. */
12510 if (die->die_mark)
12511 return;
12513 switch (die->die_tag) {
12514 case DW_TAG_const_type:
12515 case DW_TAG_packed_type:
12516 case DW_TAG_pointer_type:
12517 case DW_TAG_reference_type:
12518 case DW_TAG_volatile_type:
12519 case DW_TAG_typedef:
12520 case DW_TAG_array_type:
12521 case DW_TAG_structure_type:
12522 case DW_TAG_union_type:
12523 case DW_TAG_class_type:
12524 case DW_TAG_friend:
12525 case DW_TAG_variant_part:
12526 case DW_TAG_enumeration_type:
12527 case DW_TAG_subroutine_type:
12528 case DW_TAG_string_type:
12529 case DW_TAG_set_type:
12530 case DW_TAG_subrange_type:
12531 case DW_TAG_ptr_to_member_type:
12532 case DW_TAG_file_type:
12533 /* It's a type node --- don't mark it. */
12534 return;
12536 default:
12537 /* Mark everything else. */
12538 break;
12541 die->die_mark = 1;
12543 /* Now, mark any dies referenced from here. */
12544 prune_unused_types_walk_attribs (die);
12546 /* Mark children. */
12547 for (c = die->die_child; c; c = c->die_sib)
12548 prune_unused_types_walk (c);
12552 /* Remove from the tree DIE any dies that aren't marked. */
12554 static void
12555 prune_unused_types_prune (dw_die_ref die)
12557 dw_die_ref c, p, n;
12558 if (!die->die_mark)
12559 abort();
12561 p = NULL;
12562 for (c = die->die_child; c; c = n)
12564 n = c->die_sib;
12565 if (c->die_mark)
12567 prune_unused_types_prune (c);
12568 p = c;
12570 else
12572 if (p)
12573 p->die_sib = n;
12574 else
12575 die->die_child = n;
12576 free_die (c);
12582 /* Remove dies representing declarations that we never use. */
12584 static void
12585 prune_unused_types (void)
12587 unsigned int i;
12588 limbo_die_node *node;
12590 /* Clear all the marks. */
12591 prune_unmark_dies (comp_unit_die);
12592 for (node = limbo_die_list; node; node = node->next)
12593 prune_unmark_dies (node->die);
12595 /* Set the mark on nodes that are actually used. */
12596 prune_unused_types_walk (comp_unit_die);
12597 for (node = limbo_die_list; node; node = node->next)
12598 prune_unused_types_walk (node->die);
12600 /* Also set the mark on nodes referenced from the
12601 pubname_table or arange_table. */
12602 for (i = 0; i < pubname_table_in_use; i++)
12603 prune_unused_types_mark (pubname_table[i].die, 1);
12604 for (i = 0; i < arange_table_in_use; i++)
12605 prune_unused_types_mark (arange_table[i], 1);
12607 /* Get rid of nodes that aren't marked. */
12608 prune_unused_types_prune (comp_unit_die);
12609 for (node = limbo_die_list; node; node = node->next)
12610 prune_unused_types_prune (node->die);
12612 /* Leave the marks clear. */
12613 prune_unmark_dies (comp_unit_die);
12614 for (node = limbo_die_list; node; node = node->next)
12615 prune_unmark_dies (node->die);
12618 /* Output stuff that dwarf requires at the end of every file,
12619 and generate the DWARF-2 debugging info. */
12621 static void
12622 dwarf2out_finish (const char *filename)
12624 limbo_die_node *node, *next_node;
12625 dw_die_ref die = 0;
12627 /* Add the name for the main input file now. We delayed this from
12628 dwarf2out_init to avoid complications with PCH. */
12629 add_name_attribute (comp_unit_die, filename);
12630 if (filename[0] != DIR_SEPARATOR)
12631 add_comp_dir_attribute (comp_unit_die);
12632 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
12634 size_t i;
12635 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
12636 if (VARRAY_CHAR_PTR (file_table, i)[0] != DIR_SEPARATOR
12637 /* Don't add cwd for <built-in>. */
12638 && VARRAY_CHAR_PTR (file_table, i)[0] != '<')
12640 add_comp_dir_attribute (comp_unit_die);
12641 break;
12645 /* Traverse the limbo die list, and add parent/child links. The only
12646 dies without parents that should be here are concrete instances of
12647 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12648 For concrete instances, we can get the parent die from the abstract
12649 instance. */
12650 for (node = limbo_die_list; node; node = next_node)
12652 next_node = node->next;
12653 die = node->die;
12655 if (die->die_parent == NULL)
12657 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
12658 tree context;
12660 if (origin)
12661 add_child_die (origin->die_parent, die);
12662 else if (die == comp_unit_die)
12664 /* If this was an expression for a bound involved in a function
12665 return type, it may be a SAVE_EXPR for which we weren't able
12666 to find a DIE previously. So try now. */
12667 else if (node->created_for
12668 && TREE_CODE (node->created_for) == SAVE_EXPR
12669 && 0 != (origin = (lookup_decl_die
12670 (SAVE_EXPR_CONTEXT
12671 (node->created_for)))))
12672 add_child_die (origin, die);
12673 else if (errorcount > 0 || sorrycount > 0)
12674 /* It's OK to be confused by errors in the input. */
12675 add_child_die (comp_unit_die, die);
12676 else if (node->created_for
12677 && ((DECL_P (node->created_for)
12678 && (context = DECL_CONTEXT (node->created_for)))
12679 || (TYPE_P (node->created_for)
12680 && (context = TYPE_CONTEXT (node->created_for))))
12681 && TREE_CODE (context) == FUNCTION_DECL)
12683 /* In certain situations, the lexical block containing a
12684 nested function can be optimized away, which results
12685 in the nested function die being orphaned. Likewise
12686 with the return type of that nested function. Force
12687 this to be a child of the containing function. */
12688 origin = lookup_decl_die (context);
12689 if (! origin)
12690 abort ();
12691 add_child_die (origin, die);
12693 else
12694 abort ();
12698 limbo_die_list = NULL;
12700 /* Walk through the list of incomplete types again, trying once more to
12701 emit full debugging info for them. */
12702 retry_incomplete_types ();
12704 /* We need to reverse all the dies before break_out_includes, or
12705 we'll see the end of an include file before the beginning. */
12706 reverse_all_dies (comp_unit_die);
12708 if (flag_eliminate_unused_debug_types)
12709 prune_unused_types ();
12711 /* Generate separate CUs for each of the include files we've seen.
12712 They will go into limbo_die_list. */
12713 if (flag_eliminate_dwarf2_dups)
12714 break_out_includes (comp_unit_die);
12716 /* Traverse the DIE's and add add sibling attributes to those DIE's
12717 that have children. */
12718 add_sibling_attributes (comp_unit_die);
12719 for (node = limbo_die_list; node; node = node->next)
12720 add_sibling_attributes (node->die);
12722 /* Output a terminator label for the .text section. */
12723 text_section ();
12724 (*targetm.asm_out.internal_label) (asm_out_file, TEXT_END_LABEL, 0);
12726 /* Output the source line correspondence table. We must do this
12727 even if there is no line information. Otherwise, on an empty
12728 translation unit, we will generate a present, but empty,
12729 .debug_info section. IRIX 6.5 `nm' will then complain when
12730 examining the file. */
12731 if (! DWARF2_ASM_LINE_DEBUG_INFO)
12733 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12734 output_line_info ();
12737 /* Output location list section if necessary. */
12738 if (have_location_lists)
12740 /* Output the location lists info. */
12741 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
12742 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
12743 DEBUG_LOC_SECTION_LABEL, 0);
12744 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
12745 output_location_lists (die);
12746 have_location_lists = 0;
12749 /* We can only use the low/high_pc attributes if all of the code was
12750 in .text. */
12751 if (separate_line_info_table_in_use == 0)
12753 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
12754 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
12757 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12758 "base address". Use zero so that these addresses become absolute. */
12759 else if (have_location_lists || ranges_table_in_use)
12760 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
12762 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12763 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
12764 debug_line_section_label);
12766 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12767 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
12769 /* Output all of the compilation units. We put the main one last so that
12770 the offsets are available to output_pubnames. */
12771 for (node = limbo_die_list; node; node = node->next)
12772 output_comp_unit (node->die, 0);
12774 output_comp_unit (comp_unit_die, 0);
12776 /* Output the abbreviation table. */
12777 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12778 output_abbrev_section ();
12780 /* Output public names table if necessary. */
12781 if (pubname_table_in_use)
12783 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
12784 output_pubnames ();
12787 /* Output the address range information. We only put functions in the arange
12788 table, so don't write it out if we don't have any. */
12789 if (fde_table_in_use)
12791 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
12792 output_aranges ();
12795 /* Output ranges section if necessary. */
12796 if (ranges_table_in_use)
12798 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
12799 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12800 output_ranges ();
12803 /* Have to end the primary source file. */
12804 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12806 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12807 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12808 dw2_asm_output_data (1, 0, "End compilation unit");
12811 /* If we emitted any DW_FORM_strp form attribute, output the string
12812 table too. */
12813 if (debug_str_hash)
12814 htab_traverse (debug_str_hash, output_indirect_string, NULL);
12816 #else
12818 /* This should never be used, but its address is needed for comparisons. */
12819 const struct gcc_debug_hooks dwarf2_debug_hooks;
12821 #endif /* DWARF2_DEBUGGING_INFO */
12823 #include "gt-dwarf2out.h"