* flags.h (flag_renumber_insns): Declare.
[official-gcc.git] / gcc / dwarf2out.c
blob41fe6cb174dff797b006e8d5de1a0d8973ea6ed1
1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 93, 95-98, 1999 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
24 /* The first part of this file deals with the DWARF 2 frame unwind
25 information, which is also used by the GCC efficient exception handling
26 mechanism. The second part, controlled only by an #ifdef
27 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
28 information. */
30 #include "config.h"
31 #include "system.h"
32 #include "defaults.h"
33 #include "tree.h"
34 #include "flags.h"
35 #include "rtl.h"
36 #include "hard-reg-set.h"
37 #include "regs.h"
38 #include "insn-config.h"
39 #include "reload.h"
40 #include "output.h"
41 #include "expr.h"
42 #include "except.h"
43 #include "dwarf2.h"
44 #include "dwarf2out.h"
45 #include "toplev.h"
46 #include "dyn-string.h"
48 /* We cannot use <assert.h> in GCC source, since that would include
49 GCC's assert.h, which may not be compatible with the host compiler. */
50 #undef assert
51 #ifdef NDEBUG
52 # define assert(e)
53 #else
54 # define assert(e) do { if (! (e)) abort (); } while (0)
55 #endif
57 /* Decide whether we want to emit frame unwind information for the current
58 translation unit. */
60 int
61 dwarf2out_do_frame ()
63 return (write_symbols == DWARF2_DEBUG
64 #ifdef DWARF2_FRAME_INFO
65 || DWARF2_FRAME_INFO
66 #endif
67 #ifdef DWARF2_UNWIND_INFO
68 || flag_unwind_tables
69 || (flag_exceptions && ! exceptions_via_longjmp)
70 #endif
74 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
76 /* How to start an assembler comment. */
77 #ifndef ASM_COMMENT_START
78 #define ASM_COMMENT_START ";#"
79 #endif
81 typedef struct dw_cfi_struct *dw_cfi_ref;
82 typedef struct dw_fde_struct *dw_fde_ref;
83 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
85 /* Call frames are described using a sequence of Call Frame
86 Information instructions. The register number, offset
87 and address fields are provided as possible operands;
88 their use is selected by the opcode field. */
90 typedef union dw_cfi_oprnd_struct
92 unsigned long dw_cfi_reg_num;
93 long int dw_cfi_offset;
94 char *dw_cfi_addr;
96 dw_cfi_oprnd;
98 typedef struct dw_cfi_struct
100 dw_cfi_ref dw_cfi_next;
101 enum dwarf_call_frame_info dw_cfi_opc;
102 dw_cfi_oprnd dw_cfi_oprnd1;
103 dw_cfi_oprnd dw_cfi_oprnd2;
105 dw_cfi_node;
107 /* All call frame descriptions (FDE's) in the GCC generated DWARF
108 refer to a single Common Information Entry (CIE), defined at
109 the beginning of the .debug_frame section. This used of a single
110 CIE obviates the need to keep track of multiple CIE's
111 in the DWARF generation routines below. */
113 typedef struct dw_fde_struct
115 char *dw_fde_begin;
116 char *dw_fde_current_label;
117 char *dw_fde_end;
118 dw_cfi_ref dw_fde_cfi;
120 dw_fde_node;
122 /* Maximum size (in bytes) of an artificially generated label. */
123 #define MAX_ARTIFICIAL_LABEL_BYTES 30
125 /* Make sure we know the sizes of the various types dwarf can describe. These
126 are only defaults. If the sizes are different for your target, you should
127 override these values by defining the appropriate symbols in your tm.h
128 file. */
130 #ifndef CHAR_TYPE_SIZE
131 #define CHAR_TYPE_SIZE BITS_PER_UNIT
132 #endif
133 #ifndef PTR_SIZE
134 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
135 #endif
137 /* The size in bytes of a DWARF field indicating an offset or length
138 relative to a debug info section, specified to be 4 bytes in the DWARF-2
139 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
141 #ifndef DWARF_OFFSET_SIZE
142 #define DWARF_OFFSET_SIZE 4
143 #endif
145 #define DWARF_VERSION 2
147 /* Round SIZE up to the nearest BOUNDARY. */
148 #define DWARF_ROUND(SIZE,BOUNDARY) \
149 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
151 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
152 #ifdef STACK_GROWS_DOWNWARD
153 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
154 #else
155 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
156 #endif
158 /* A pointer to the base of a table that contains frame description
159 information for each routine. */
160 static dw_fde_ref fde_table;
162 /* Number of elements currently allocated for fde_table. */
163 static unsigned fde_table_allocated;
165 /* Number of elements in fde_table currently in use. */
166 static unsigned fde_table_in_use;
168 /* Size (in elements) of increments by which we may expand the
169 fde_table. */
170 #define FDE_TABLE_INCREMENT 256
172 /* A list of call frame insns for the CIE. */
173 static dw_cfi_ref cie_cfi_head;
175 /* The number of the current function definition for which debugging
176 information is being generated. These numbers range from 1 up to the
177 maximum number of function definitions contained within the current
178 compilation unit. These numbers are used to create unique label id's
179 unique to each function definition. */
180 static unsigned current_funcdef_number = 0;
182 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
183 attribute that accelerates the lookup of the FDE associated
184 with the subprogram. This variable holds the table index of the FDE
185 associated with the current function (body) definition. */
186 static unsigned current_funcdef_fde;
188 /* Forward declarations for functions defined in this file. */
190 static char *stripattributes PROTO((const char *));
191 static const char *dwarf_cfi_name PROTO((unsigned));
192 static dw_cfi_ref new_cfi PROTO((void));
193 static void add_cfi PROTO((dw_cfi_ref *, dw_cfi_ref));
194 static unsigned long size_of_uleb128 PROTO((unsigned long));
195 static unsigned long size_of_sleb128 PROTO((long));
196 static void output_uleb128 PROTO((unsigned long));
197 static void output_sleb128 PROTO((long));
198 static void add_fde_cfi PROTO((char *, dw_cfi_ref));
199 static void lookup_cfa_1 PROTO((dw_cfi_ref, unsigned long *,
200 long *));
201 static void lookup_cfa PROTO((unsigned long *, long *));
202 static void reg_save PROTO((char *, unsigned, unsigned,
203 long));
204 static void initial_return_save PROTO((rtx));
205 static void output_cfi PROTO((dw_cfi_ref, dw_fde_ref));
206 static void output_call_frame_info PROTO((int));
207 static unsigned reg_number PROTO((rtx));
208 static void dwarf2out_stack_adjust PROTO((rtx));
209 static void dwarf2out_frame_debug_expr PROTO((rtx, char *));
211 /* Definitions of defaults for assembler-dependent names of various
212 pseudo-ops and section names.
213 Theses may be overridden in the tm.h file (if necessary) for a particular
214 assembler. */
216 #ifdef OBJECT_FORMAT_ELF
217 #ifndef UNALIGNED_SHORT_ASM_OP
218 #define UNALIGNED_SHORT_ASM_OP ".2byte"
219 #endif
220 #ifndef UNALIGNED_INT_ASM_OP
221 #define UNALIGNED_INT_ASM_OP ".4byte"
222 #endif
223 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
224 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
225 #endif
226 #endif /* OBJECT_FORMAT_ELF */
228 #ifndef ASM_BYTE_OP
229 #define ASM_BYTE_OP ".byte"
230 #endif
232 /* Data and reference forms for relocatable data. */
233 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
234 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
236 /* Pseudo-op for defining a new section. */
237 #ifndef SECTION_ASM_OP
238 #define SECTION_ASM_OP ".section"
239 #endif
241 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
242 print the SECTION_ASM_OP and the section name. The default here works for
243 almost all svr4 assemblers, except for the sparc, where the section name
244 must be enclosed in double quotes. (See sparcv4.h). */
245 #ifndef SECTION_FORMAT
246 #ifdef PUSHSECTION_FORMAT
247 #define SECTION_FORMAT PUSHSECTION_FORMAT
248 #else
249 #define SECTION_FORMAT "\t%s\t%s\n"
250 #endif
251 #endif
253 #ifndef FRAME_SECTION
254 #define FRAME_SECTION ".debug_frame"
255 #endif
257 #ifndef FUNC_BEGIN_LABEL
258 #define FUNC_BEGIN_LABEL "LFB"
259 #endif
260 #ifndef FUNC_END_LABEL
261 #define FUNC_END_LABEL "LFE"
262 #endif
263 #define CIE_AFTER_SIZE_LABEL "LSCIE"
264 #define CIE_END_LABEL "LECIE"
265 #define CIE_LENGTH_LABEL "LLCIE"
266 #define FDE_AFTER_SIZE_LABEL "LSFDE"
267 #define FDE_END_LABEL "LEFDE"
268 #define FDE_LENGTH_LABEL "LLFDE"
270 /* Definitions of defaults for various types of primitive assembly language
271 output operations. These may be overridden from within the tm.h file,
272 but typically, that is unnecessary. */
274 #ifndef ASM_OUTPUT_SECTION
275 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
276 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
277 #endif
279 #ifndef ASM_OUTPUT_DWARF_DATA1
280 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
281 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
282 #endif
284 #ifndef ASM_OUTPUT_DWARF_DELTA1
285 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
286 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
287 assemble_name (FILE, LABEL1); \
288 fprintf (FILE, "-"); \
289 assemble_name (FILE, LABEL2); \
290 } while (0)
291 #endif
293 #ifdef UNALIGNED_INT_ASM_OP
295 #ifndef UNALIGNED_OFFSET_ASM_OP
296 #define UNALIGNED_OFFSET_ASM_OP \
297 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
298 #endif
300 #ifndef UNALIGNED_WORD_ASM_OP
301 #define UNALIGNED_WORD_ASM_OP \
302 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
303 #endif
305 #ifndef ASM_OUTPUT_DWARF_DELTA2
306 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
307 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
308 assemble_name (FILE, LABEL1); \
309 fprintf (FILE, "-"); \
310 assemble_name (FILE, LABEL2); \
311 } while (0)
312 #endif
314 #ifndef ASM_OUTPUT_DWARF_DELTA4
315 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
316 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
317 assemble_name (FILE, LABEL1); \
318 fprintf (FILE, "-"); \
319 assemble_name (FILE, LABEL2); \
320 } while (0)
321 #endif
323 #ifndef ASM_OUTPUT_DWARF_DELTA
324 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
325 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
326 assemble_name (FILE, LABEL1); \
327 fprintf (FILE, "-"); \
328 assemble_name (FILE, LABEL2); \
329 } while (0)
330 #endif
332 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
333 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
334 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
335 assemble_name (FILE, LABEL1); \
336 fprintf (FILE, "-"); \
337 assemble_name (FILE, LABEL2); \
338 } while (0)
339 #endif
341 #ifndef ASM_OUTPUT_DWARF_ADDR
342 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
343 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
344 assemble_name (FILE, LABEL); \
345 } while (0)
346 #endif
348 /* ??? This macro takes an RTX in dwarfout.c and a string in dwarf2out.c.
349 We resolve the conflict by creating a new macro ASM_OUTPUT_DWARF2_ADDR_CONST
350 for ports that want to support both DWARF1 and DWARF2. This needs a better
351 solution. See also the comments in sparc/sp64-elf.h. */
352 #ifdef ASM_OUTPUT_DWARF2_ADDR_CONST
353 #undef ASM_OUTPUT_DWARF_ADDR_CONST
354 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
355 ASM_OUTPUT_DWARF2_ADDR_CONST (FILE, ADDR)
356 #endif
358 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
359 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
360 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
361 #endif
363 #ifndef ASM_OUTPUT_DWARF_OFFSET4
364 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
365 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
366 assemble_name (FILE, LABEL); \
367 } while (0)
368 #endif
370 #ifndef ASM_OUTPUT_DWARF_OFFSET
371 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
372 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
373 assemble_name (FILE, LABEL); \
374 } while (0)
375 #endif
377 #ifndef ASM_OUTPUT_DWARF_DATA2
378 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
379 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
380 #endif
382 #ifndef ASM_OUTPUT_DWARF_DATA4
383 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
384 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
385 #endif
387 #ifndef ASM_OUTPUT_DWARF_DATA
388 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
389 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
390 (unsigned long) (VALUE))
391 #endif
393 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
394 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
395 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
396 (unsigned long) (VALUE))
397 #endif
399 #ifndef ASM_OUTPUT_DWARF_DATA8
400 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
401 do { \
402 if (WORDS_BIG_ENDIAN) \
404 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
405 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
407 else \
409 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
410 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
412 } while (0)
413 #endif
415 #else /* UNALIGNED_INT_ASM_OP */
417 /* We don't have unaligned support, let's hope the normal output works for
418 .debug_frame. */
420 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
421 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), PTR_SIZE, 1)
423 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
424 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
426 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
427 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
429 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
430 assemble_integer (gen_rtx_MINUS (HImode, \
431 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
432 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
433 2, 1)
435 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
436 assemble_integer (gen_rtx_MINUS (SImode, \
437 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
438 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
439 4, 1)
441 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
442 assemble_integer (gen_rtx_MINUS (Pmode, \
443 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
444 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
445 PTR_SIZE, 1)
447 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
448 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
450 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
451 assemble_integer (GEN_INT (VALUE), 4, 1)
453 #endif /* UNALIGNED_INT_ASM_OP */
455 #ifdef SET_ASM_OP
456 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
457 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
458 do { \
459 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
460 assemble_name (FILE, SY); \
461 fputc (',', FILE); \
462 assemble_name (FILE, HI); \
463 fputc ('-', FILE); \
464 assemble_name (FILE, LO); \
465 } while (0)
466 #endif
467 #endif /* SET_ASM_OP */
469 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
470 newline is produced. When flag_debug_asm is asserted, we add commentary
471 at the end of the line, so we must avoid output of a newline here. */
472 #ifndef ASM_OUTPUT_DWARF_STRING
473 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
474 do { \
475 register int slen = strlen(P); \
476 register const char *p = (P); \
477 register int i; \
478 fprintf (FILE, "\t.ascii \""); \
479 for (i = 0; i < slen; i++) \
481 register int c = p[i]; \
482 if (c == '\"' || c == '\\') \
483 putc ('\\', FILE); \
484 if (ISPRINT(c)) \
485 putc (c, FILE); \
486 else \
488 fprintf (FILE, "\\%o", c); \
491 fprintf (FILE, "\\0\""); \
493 while (0)
494 #endif
496 /* The DWARF 2 CFA column which tracks the return address. Normally this
497 is the column for PC, or the first column after all of the hard
498 registers. */
499 #ifndef DWARF_FRAME_RETURN_COLUMN
500 #ifdef PC_REGNUM
501 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
502 #else
503 #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER
504 #endif
505 #endif
507 /* The mapping from gcc register number to DWARF 2 CFA column number. By
508 default, we just provide columns for all registers. */
509 #ifndef DWARF_FRAME_REGNUM
510 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
511 #endif
513 /* Hook used by __throw. */
516 expand_builtin_dwarf_fp_regnum ()
518 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
521 /* The offset from the incoming value of %sp to the top of the stack frame
522 for the current function. */
523 #ifndef INCOMING_FRAME_SP_OFFSET
524 #define INCOMING_FRAME_SP_OFFSET 0
525 #endif
527 /* Return a pointer to a copy of the section string name S with all
528 attributes stripped off, and an asterisk prepended (for assemble_name). */
530 static inline char *
531 stripattributes (s)
532 const char *s;
534 char *stripped = xmalloc (strlen (s) + 2);
535 char *p = stripped;
537 *p++ = '*';
539 while (*s && *s != ',')
540 *p++ = *s++;
542 *p = '\0';
543 return stripped;
546 /* Return the register number described by a given RTL node. */
548 static unsigned
549 reg_number (rtl)
550 register rtx rtl;
552 register unsigned regno = REGNO (rtl);
554 if (regno >= FIRST_PSEUDO_REGISTER)
556 warning ("internal regno botch: regno = %d\n", regno);
557 regno = 0;
560 regno = DBX_REGISTER_NUMBER (regno);
561 return regno;
564 /* Generate code to initialize the register size table. */
566 void
567 expand_builtin_init_dwarf_reg_sizes (address)
568 tree address;
570 int i;
571 enum machine_mode mode = TYPE_MODE (char_type_node);
572 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
573 rtx mem = gen_rtx_MEM (mode, addr);
575 for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
577 int offset = i * GET_MODE_SIZE (mode);
578 int size = GET_MODE_SIZE (reg_raw_mode[i]);
580 emit_move_insn (change_address (mem, mode,
581 plus_constant (addr, offset)),
582 GEN_INT (size));
586 /* Convert a DWARF call frame info. operation to its string name */
588 static const char *
589 dwarf_cfi_name (cfi_opc)
590 register unsigned cfi_opc;
592 switch (cfi_opc)
594 case DW_CFA_advance_loc:
595 return "DW_CFA_advance_loc";
596 case DW_CFA_offset:
597 return "DW_CFA_offset";
598 case DW_CFA_restore:
599 return "DW_CFA_restore";
600 case DW_CFA_nop:
601 return "DW_CFA_nop";
602 case DW_CFA_set_loc:
603 return "DW_CFA_set_loc";
604 case DW_CFA_advance_loc1:
605 return "DW_CFA_advance_loc1";
606 case DW_CFA_advance_loc2:
607 return "DW_CFA_advance_loc2";
608 case DW_CFA_advance_loc4:
609 return "DW_CFA_advance_loc4";
610 case DW_CFA_offset_extended:
611 return "DW_CFA_offset_extended";
612 case DW_CFA_restore_extended:
613 return "DW_CFA_restore_extended";
614 case DW_CFA_undefined:
615 return "DW_CFA_undefined";
616 case DW_CFA_same_value:
617 return "DW_CFA_same_value";
618 case DW_CFA_register:
619 return "DW_CFA_register";
620 case DW_CFA_remember_state:
621 return "DW_CFA_remember_state";
622 case DW_CFA_restore_state:
623 return "DW_CFA_restore_state";
624 case DW_CFA_def_cfa:
625 return "DW_CFA_def_cfa";
626 case DW_CFA_def_cfa_register:
627 return "DW_CFA_def_cfa_register";
628 case DW_CFA_def_cfa_offset:
629 return "DW_CFA_def_cfa_offset";
631 /* SGI/MIPS specific */
632 case DW_CFA_MIPS_advance_loc8:
633 return "DW_CFA_MIPS_advance_loc8";
635 /* GNU extensions */
636 case DW_CFA_GNU_window_save:
637 return "DW_CFA_GNU_window_save";
638 case DW_CFA_GNU_args_size:
639 return "DW_CFA_GNU_args_size";
641 default:
642 return "DW_CFA_<unknown>";
646 /* Return a pointer to a newly allocated Call Frame Instruction. */
648 static inline dw_cfi_ref
649 new_cfi ()
651 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
653 cfi->dw_cfi_next = NULL;
654 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
655 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
657 return cfi;
660 /* Add a Call Frame Instruction to list of instructions. */
662 static inline void
663 add_cfi (list_head, cfi)
664 register dw_cfi_ref *list_head;
665 register dw_cfi_ref cfi;
667 register dw_cfi_ref *p;
669 /* Find the end of the chain. */
670 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
673 *p = cfi;
676 /* Generate a new label for the CFI info to refer to. */
678 char *
679 dwarf2out_cfi_label ()
681 static char label[20];
682 static unsigned long label_num = 0;
684 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
685 ASM_OUTPUT_LABEL (asm_out_file, label);
687 return label;
690 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
691 or to the CIE if LABEL is NULL. */
693 static void
694 add_fde_cfi (label, cfi)
695 register char *label;
696 register dw_cfi_ref cfi;
698 if (label)
700 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
702 if (*label == 0)
703 label = dwarf2out_cfi_label ();
705 if (fde->dw_fde_current_label == NULL
706 || strcmp (label, fde->dw_fde_current_label) != 0)
708 register dw_cfi_ref xcfi;
710 fde->dw_fde_current_label = label = xstrdup (label);
712 /* Set the location counter to the new label. */
713 xcfi = new_cfi ();
714 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
715 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
716 add_cfi (&fde->dw_fde_cfi, xcfi);
719 add_cfi (&fde->dw_fde_cfi, cfi);
722 else
723 add_cfi (&cie_cfi_head, cfi);
726 /* Subroutine of lookup_cfa. */
728 static inline void
729 lookup_cfa_1 (cfi, regp, offsetp)
730 register dw_cfi_ref cfi;
731 register unsigned long *regp;
732 register long *offsetp;
734 switch (cfi->dw_cfi_opc)
736 case DW_CFA_def_cfa_offset:
737 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
738 break;
739 case DW_CFA_def_cfa_register:
740 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
741 break;
742 case DW_CFA_def_cfa:
743 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
744 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
745 break;
746 default:
747 break;
751 /* Find the previous value for the CFA. */
753 static void
754 lookup_cfa (regp, offsetp)
755 register unsigned long *regp;
756 register long *offsetp;
758 register dw_cfi_ref cfi;
760 *regp = (unsigned long) -1;
761 *offsetp = 0;
763 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
764 lookup_cfa_1 (cfi, regp, offsetp);
766 if (fde_table_in_use)
768 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
769 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
770 lookup_cfa_1 (cfi, regp, offsetp);
774 /* The current rule for calculating the DWARF2 canonical frame address. */
775 static unsigned long cfa_reg;
776 static long cfa_offset;
778 /* The register used for saving registers to the stack, and its offset
779 from the CFA. */
780 static unsigned cfa_store_reg;
781 static long cfa_store_offset;
783 /* The running total of the size of arguments pushed onto the stack. */
784 static long args_size;
786 /* The last args_size we actually output. */
787 static long old_args_size;
789 /* Entry point to update the canonical frame address (CFA).
790 LABEL is passed to add_fde_cfi. The value of CFA is now to be
791 calculated from REG+OFFSET. */
793 void
794 dwarf2out_def_cfa (label, reg, offset)
795 register char *label;
796 register unsigned reg;
797 register long offset;
799 register dw_cfi_ref cfi;
800 unsigned long old_reg;
801 long old_offset;
803 cfa_reg = reg;
804 cfa_offset = offset;
805 if (cfa_store_reg == reg)
806 cfa_store_offset = offset;
808 reg = DWARF_FRAME_REGNUM (reg);
809 lookup_cfa (&old_reg, &old_offset);
811 if (reg == old_reg && offset == old_offset)
812 return;
814 cfi = new_cfi ();
816 if (reg == old_reg)
818 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
819 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
822 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
823 else if (offset == old_offset && old_reg != (unsigned long) -1)
825 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
826 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
828 #endif
830 else
832 cfi->dw_cfi_opc = DW_CFA_def_cfa;
833 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
834 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
837 add_fde_cfi (label, cfi);
840 /* Add the CFI for saving a register. REG is the CFA column number.
841 LABEL is passed to add_fde_cfi.
842 If SREG is -1, the register is saved at OFFSET from the CFA;
843 otherwise it is saved in SREG. */
845 static void
846 reg_save (label, reg, sreg, offset)
847 register char * label;
848 register unsigned reg;
849 register unsigned sreg;
850 register long offset;
852 register dw_cfi_ref cfi = new_cfi ();
854 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
856 /* The following comparison is correct. -1 is used to indicate that
857 the value isn't a register number. */
858 if (sreg == (unsigned int) -1)
860 if (reg & ~0x3f)
861 /* The register number won't fit in 6 bits, so we have to use
862 the long form. */
863 cfi->dw_cfi_opc = DW_CFA_offset_extended;
864 else
865 cfi->dw_cfi_opc = DW_CFA_offset;
867 offset /= DWARF_CIE_DATA_ALIGNMENT;
868 if (offset < 0)
869 abort ();
870 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
872 else
874 cfi->dw_cfi_opc = DW_CFA_register;
875 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
878 add_fde_cfi (label, cfi);
881 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
882 This CFI tells the unwinder that it needs to restore the window registers
883 from the previous frame's window save area.
885 ??? Perhaps we should note in the CIE where windows are saved (instead of
886 assuming 0(cfa)) and what registers are in the window. */
888 void
889 dwarf2out_window_save (label)
890 register char * label;
892 register dw_cfi_ref cfi = new_cfi ();
893 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
894 add_fde_cfi (label, cfi);
897 /* Add a CFI to update the running total of the size of arguments
898 pushed onto the stack. */
900 void
901 dwarf2out_args_size (label, size)
902 char *label;
903 long size;
905 register dw_cfi_ref cfi;
907 if (size == old_args_size)
908 return;
909 old_args_size = size;
911 cfi = new_cfi ();
912 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
913 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
914 add_fde_cfi (label, cfi);
917 /* Entry point for saving a register to the stack. REG is the GCC register
918 number. LABEL and OFFSET are passed to reg_save. */
920 void
921 dwarf2out_reg_save (label, reg, offset)
922 register char * label;
923 register unsigned reg;
924 register long offset;
926 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
929 /* Entry point for saving the return address in the stack.
930 LABEL and OFFSET are passed to reg_save. */
932 void
933 dwarf2out_return_save (label, offset)
934 register char * label;
935 register long offset;
937 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
940 /* Entry point for saving the return address in a register.
941 LABEL and SREG are passed to reg_save. */
943 void
944 dwarf2out_return_reg (label, sreg)
945 register char * label;
946 register unsigned sreg;
948 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
951 /* Record the initial position of the return address. RTL is
952 INCOMING_RETURN_ADDR_RTX. */
954 static void
955 initial_return_save (rtl)
956 register rtx rtl;
958 unsigned int reg = (unsigned int) -1;
959 long offset = 0;
961 switch (GET_CODE (rtl))
963 case REG:
964 /* RA is in a register. */
965 reg = reg_number (rtl);
966 break;
967 case MEM:
968 /* RA is on the stack. */
969 rtl = XEXP (rtl, 0);
970 switch (GET_CODE (rtl))
972 case REG:
973 if (REGNO (rtl) != STACK_POINTER_REGNUM)
974 abort ();
975 offset = 0;
976 break;
977 case PLUS:
978 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
979 abort ();
980 offset = INTVAL (XEXP (rtl, 1));
981 break;
982 case MINUS:
983 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
984 abort ();
985 offset = -INTVAL (XEXP (rtl, 1));
986 break;
987 default:
988 abort ();
990 break;
991 case PLUS:
992 /* The return address is at some offset from any value we can
993 actually load. For instance, on the SPARC it is in %i7+8. Just
994 ignore the offset for now; it doesn't matter for unwinding frames. */
995 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
996 abort ();
997 initial_return_save (XEXP (rtl, 0));
998 return;
999 default:
1000 abort ();
1003 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset);
1006 /* Check INSN to see if it looks like a push or a stack adjustment, and
1007 make a note of it if it does. EH uses this information to find out how
1008 much extra space it needs to pop off the stack. */
1010 static void
1011 dwarf2out_stack_adjust (insn)
1012 rtx insn;
1014 long offset;
1015 char *label;
1017 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1019 /* Extract the size of the args from the CALL rtx itself. */
1021 insn = PATTERN (insn);
1022 if (GET_CODE (insn) == PARALLEL)
1023 insn = XVECEXP (insn, 0, 0);
1024 if (GET_CODE (insn) == SET)
1025 insn = SET_SRC (insn);
1026 assert (GET_CODE (insn) == CALL);
1027 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1028 return;
1031 /* If only calls can throw, and we have a frame pointer,
1032 save up adjustments until we see the CALL_INSN. */
1033 else if (! asynchronous_exceptions
1034 && cfa_reg != STACK_POINTER_REGNUM)
1035 return;
1037 if (GET_CODE (insn) == BARRIER)
1039 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1040 the compiler will have already emitted a stack adjustment, but
1041 doesn't bother for calls to noreturn functions. */
1042 #ifdef STACK_GROWS_DOWNWARD
1043 offset = -args_size;
1044 #else
1045 offset = args_size;
1046 #endif
1048 else if (GET_CODE (PATTERN (insn)) == SET)
1050 rtx src, dest;
1051 enum rtx_code code;
1053 insn = PATTERN (insn);
1054 src = SET_SRC (insn);
1055 dest = SET_DEST (insn);
1057 if (dest == stack_pointer_rtx)
1059 /* (set (reg sp) (plus (reg sp) (const_int))) */
1060 code = GET_CODE (src);
1061 if (! (code == PLUS || code == MINUS)
1062 || XEXP (src, 0) != stack_pointer_rtx
1063 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1064 return;
1066 offset = INTVAL (XEXP (src, 1));
1068 else if (GET_CODE (dest) == MEM)
1070 /* (set (mem (pre_dec (reg sp))) (foo)) */
1071 src = XEXP (dest, 0);
1072 code = GET_CODE (src);
1074 if (! (code == PRE_DEC || code == PRE_INC)
1075 || XEXP (src, 0) != stack_pointer_rtx)
1076 return;
1078 offset = GET_MODE_SIZE (GET_MODE (dest));
1080 else
1081 return;
1083 if (code == PLUS || code == PRE_INC)
1084 offset = -offset;
1086 else
1087 return;
1089 if (offset == 0)
1090 return;
1092 if (cfa_reg == STACK_POINTER_REGNUM)
1093 cfa_offset += offset;
1095 #ifndef STACK_GROWS_DOWNWARD
1096 offset = -offset;
1097 #endif
1098 args_size += offset;
1099 if (args_size < 0)
1100 args_size = 0;
1102 label = dwarf2out_cfi_label ();
1103 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1104 dwarf2out_args_size (label, args_size);
1107 /* A temporary register used in adjusting SP or setting up the store_reg. */
1108 static unsigned cfa_temp_reg;
1110 /* A temporary value used in adjusting SP or setting up the store_reg. */
1111 static long cfa_temp_value;
1113 /* Record call frame debugging information for an expression, which either
1114 sets SP or FP (adjusting how we calculate the frame address) or saves a
1115 register to the stack. */
1117 static void
1118 dwarf2out_frame_debug_expr (expr, label)
1119 rtx expr;
1120 char *label;
1122 rtx src, dest;
1123 long offset;
1125 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1126 the PARALLEL independantly. The first element is always processed if
1127 it is a SET. This is for backward compatability. Other elements
1128 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1129 flag is set in them. */
1131 if (GET_CODE (expr) == PARALLEL)
1133 int par_index;
1134 int limit = XVECLEN (expr, 0);
1136 for (par_index = 0; par_index < limit; par_index++)
1138 rtx x = XVECEXP (expr, 0, par_index);
1140 if (GET_CODE (x) == SET &&
1141 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1142 dwarf2out_frame_debug_expr (x, label);
1144 return;
1147 if (GET_CODE (expr) != SET)
1148 abort ();
1150 src = SET_SRC (expr);
1151 dest = SET_DEST (expr);
1153 switch (GET_CODE (dest))
1155 case REG:
1156 /* Update the CFA rule wrt SP or FP. Make sure src is
1157 relative to the current CFA register. */
1158 switch (GET_CODE (src))
1160 /* Setting FP from SP. */
1161 case REG:
1162 if (cfa_reg != (unsigned) REGNO (src))
1163 abort ();
1164 if (REGNO (dest) != STACK_POINTER_REGNUM
1165 && !(frame_pointer_needed
1166 && REGNO (dest) == HARD_FRAME_POINTER_REGNUM))
1167 abort ();
1168 cfa_reg = REGNO (dest);
1169 break;
1171 case PLUS:
1172 case MINUS:
1173 if (dest == stack_pointer_rtx)
1175 /* Adjusting SP. */
1176 switch (GET_CODE (XEXP (src, 1)))
1178 case CONST_INT:
1179 offset = INTVAL (XEXP (src, 1));
1180 break;
1181 case REG:
1182 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1183 abort ();
1184 offset = cfa_temp_value;
1185 break;
1186 default:
1187 abort ();
1190 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1192 /* Restoring SP from FP in the epilogue. */
1193 if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1194 abort ();
1195 cfa_reg = STACK_POINTER_REGNUM;
1197 else if (XEXP (src, 0) != stack_pointer_rtx)
1198 abort ();
1200 if (GET_CODE (src) == PLUS)
1201 offset = -offset;
1202 if (cfa_reg == STACK_POINTER_REGNUM)
1203 cfa_offset += offset;
1204 if (cfa_store_reg == STACK_POINTER_REGNUM)
1205 cfa_store_offset += offset;
1207 else if (dest == hard_frame_pointer_rtx)
1209 /* Either setting the FP from an offset of the SP,
1210 or adjusting the FP */
1211 if (! frame_pointer_needed
1212 || REGNO (dest) != HARD_FRAME_POINTER_REGNUM)
1213 abort ();
1215 if (XEXP (src, 0) == stack_pointer_rtx
1216 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1218 if (cfa_reg != STACK_POINTER_REGNUM)
1219 abort ();
1220 offset = INTVAL (XEXP (src, 1));
1221 if (GET_CODE (src) == PLUS)
1222 offset = -offset;
1223 cfa_offset += offset;
1224 cfa_reg = HARD_FRAME_POINTER_REGNUM;
1226 else if (XEXP (src, 0) == hard_frame_pointer_rtx
1227 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1229 if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1230 abort ();
1231 offset = INTVAL (XEXP (src, 1));
1232 if (GET_CODE (src) == PLUS)
1233 offset = -offset;
1234 cfa_offset += offset;
1237 else
1238 abort();
1240 else
1242 if (GET_CODE (src) != PLUS
1243 || XEXP (src, 1) != stack_pointer_rtx)
1244 abort ();
1245 if (GET_CODE (XEXP (src, 0)) != REG
1246 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1247 abort ();
1248 if (cfa_reg != STACK_POINTER_REGNUM)
1249 abort ();
1250 cfa_store_reg = REGNO (dest);
1251 cfa_store_offset = cfa_offset - cfa_temp_value;
1253 break;
1255 case CONST_INT:
1256 cfa_temp_reg = REGNO (dest);
1257 cfa_temp_value = INTVAL (src);
1258 break;
1260 case IOR:
1261 if (GET_CODE (XEXP (src, 0)) != REG
1262 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1263 || (unsigned) REGNO (dest) != cfa_temp_reg
1264 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1265 abort ();
1266 cfa_temp_value |= INTVAL (XEXP (src, 1));
1267 break;
1269 default:
1270 abort ();
1272 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1273 break;
1275 case MEM:
1276 /* Saving a register to the stack. Make sure dest is relative to the
1277 CFA register. */
1278 if (GET_CODE (src) != REG)
1279 abort ();
1280 switch (GET_CODE (XEXP (dest, 0)))
1282 /* With a push. */
1283 case PRE_INC:
1284 case PRE_DEC:
1285 offset = GET_MODE_SIZE (GET_MODE (dest));
1286 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1287 offset = -offset;
1289 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1290 || cfa_store_reg != STACK_POINTER_REGNUM)
1291 abort ();
1292 cfa_store_offset += offset;
1293 if (cfa_reg == STACK_POINTER_REGNUM)
1294 cfa_offset = cfa_store_offset;
1296 offset = -cfa_store_offset;
1297 break;
1299 /* With an offset. */
1300 case PLUS:
1301 case MINUS:
1302 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1303 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1304 offset = -offset;
1306 if (cfa_store_reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1307 abort ();
1308 offset -= cfa_store_offset;
1309 break;
1311 /* Without an offset. */
1312 case REG:
1313 if (cfa_store_reg != (unsigned) REGNO (XEXP (dest, 0)))
1314 abort();
1315 offset = -cfa_store_offset;
1316 break;
1318 default:
1319 abort ();
1321 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1322 dwarf2out_reg_save (label, REGNO (src), offset);
1323 break;
1325 default:
1326 abort ();
1331 /* Record call frame debugging information for INSN, which either
1332 sets SP or FP (adjusting how we calculate the frame address) or saves a
1333 register to the stack. If INSN is NULL_RTX, initialize our state. */
1335 void
1336 dwarf2out_frame_debug (insn)
1337 rtx insn;
1339 char *label;
1340 rtx src;
1342 if (insn == NULL_RTX)
1344 /* Set up state for generating call frame debug info. */
1345 lookup_cfa (&cfa_reg, &cfa_offset);
1346 if (cfa_reg != DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1347 abort ();
1348 cfa_reg = STACK_POINTER_REGNUM;
1349 cfa_store_reg = cfa_reg;
1350 cfa_store_offset = cfa_offset;
1351 cfa_temp_reg = -1;
1352 cfa_temp_value = 0;
1353 return;
1356 if (! RTX_FRAME_RELATED_P (insn))
1358 dwarf2out_stack_adjust (insn);
1359 return;
1362 label = dwarf2out_cfi_label ();
1364 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1365 if (src)
1366 insn = XEXP (src, 0);
1367 else
1368 insn = PATTERN (insn);
1370 dwarf2out_frame_debug_expr (insn, label);
1373 /* Return the size of an unsigned LEB128 quantity. */
1375 static inline unsigned long
1376 size_of_uleb128 (value)
1377 register unsigned long value;
1379 register unsigned long size = 0;
1380 register unsigned byte;
1384 byte = (value & 0x7f);
1385 value >>= 7;
1386 size += 1;
1388 while (value != 0);
1390 return size;
1393 /* Return the size of a signed LEB128 quantity. */
1395 static inline unsigned long
1396 size_of_sleb128 (value)
1397 register long value;
1399 register unsigned long size = 0;
1400 register unsigned byte;
1404 byte = (value & 0x7f);
1405 value >>= 7;
1406 size += 1;
1408 while (!(((value == 0) && ((byte & 0x40) == 0))
1409 || ((value == -1) && ((byte & 0x40) != 0))));
1411 return size;
1414 /* Output an unsigned LEB128 quantity. */
1416 static void
1417 output_uleb128 (value)
1418 register unsigned long value;
1420 unsigned long save_value = value;
1422 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1425 register unsigned byte = (value & 0x7f);
1426 value >>= 7;
1427 if (value != 0)
1428 /* More bytes to follow. */
1429 byte |= 0x80;
1431 fprintf (asm_out_file, "0x%x", byte);
1432 if (value != 0)
1433 fprintf (asm_out_file, ",");
1435 while (value != 0);
1437 if (flag_debug_asm)
1438 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1441 /* Output an signed LEB128 quantity. */
1443 static void
1444 output_sleb128 (value)
1445 register long value;
1447 register int more;
1448 register unsigned byte;
1449 long save_value = value;
1451 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1454 byte = (value & 0x7f);
1455 /* arithmetic shift */
1456 value >>= 7;
1457 more = !((((value == 0) && ((byte & 0x40) == 0))
1458 || ((value == -1) && ((byte & 0x40) != 0))));
1459 if (more)
1460 byte |= 0x80;
1462 fprintf (asm_out_file, "0x%x", byte);
1463 if (more)
1464 fprintf (asm_out_file, ",");
1467 while (more);
1468 if (flag_debug_asm)
1469 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1472 /* Output a Call Frame Information opcode and its operand(s). */
1474 static void
1475 output_cfi (cfi, fde)
1476 register dw_cfi_ref cfi;
1477 register dw_fde_ref fde;
1479 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1481 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1482 cfi->dw_cfi_opc
1483 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1484 if (flag_debug_asm)
1485 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1486 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1487 fputc ('\n', asm_out_file);
1490 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1492 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1493 cfi->dw_cfi_opc
1494 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1495 if (flag_debug_asm)
1496 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1497 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1499 fputc ('\n', asm_out_file);
1500 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1501 fputc ('\n', asm_out_file);
1503 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1505 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1506 cfi->dw_cfi_opc
1507 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1508 if (flag_debug_asm)
1509 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1510 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1512 fputc ('\n', asm_out_file);
1514 else
1516 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1517 if (flag_debug_asm)
1518 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1519 dwarf_cfi_name (cfi->dw_cfi_opc));
1521 fputc ('\n', asm_out_file);
1522 switch (cfi->dw_cfi_opc)
1524 case DW_CFA_set_loc:
1525 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1526 fputc ('\n', asm_out_file);
1527 break;
1528 case DW_CFA_advance_loc1:
1529 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1530 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1531 fde->dw_fde_current_label);
1532 fputc ('\n', asm_out_file);
1533 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1534 break;
1535 case DW_CFA_advance_loc2:
1536 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1537 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1538 fde->dw_fde_current_label);
1539 fputc ('\n', asm_out_file);
1540 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1541 break;
1542 case DW_CFA_advance_loc4:
1543 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1544 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1545 fde->dw_fde_current_label);
1546 fputc ('\n', asm_out_file);
1547 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1548 break;
1549 #ifdef MIPS_DEBUGGING_INFO
1550 case DW_CFA_MIPS_advance_loc8:
1551 /* TODO: not currently implemented. */
1552 abort ();
1553 break;
1554 #endif
1555 case DW_CFA_offset_extended:
1556 case DW_CFA_def_cfa:
1557 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1558 fputc ('\n', asm_out_file);
1559 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1560 fputc ('\n', asm_out_file);
1561 break;
1562 case DW_CFA_restore_extended:
1563 case DW_CFA_undefined:
1564 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1565 fputc ('\n', asm_out_file);
1566 break;
1567 case DW_CFA_same_value:
1568 case DW_CFA_def_cfa_register:
1569 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1570 fputc ('\n', asm_out_file);
1571 break;
1572 case DW_CFA_register:
1573 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1574 fputc ('\n', asm_out_file);
1575 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1576 fputc ('\n', asm_out_file);
1577 break;
1578 case DW_CFA_def_cfa_offset:
1579 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1580 fputc ('\n', asm_out_file);
1581 break;
1582 case DW_CFA_GNU_window_save:
1583 break;
1584 case DW_CFA_GNU_args_size:
1585 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1586 fputc ('\n', asm_out_file);
1587 break;
1588 default:
1589 break;
1594 /* Output the call frame information used to used to record information
1595 that relates to calculating the frame pointer, and records the
1596 location of saved registers. */
1598 static void
1599 output_call_frame_info (for_eh)
1600 int for_eh;
1602 register unsigned long i;
1603 register dw_fde_ref fde;
1604 register dw_cfi_ref cfi;
1605 char l1[20], l2[20];
1606 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1607 char ld[20];
1608 #endif
1610 /* Do we want to include a pointer to the exception table? */
1611 int eh_ptr = for_eh && exception_table_p ();
1613 fputc ('\n', asm_out_file);
1615 /* We're going to be generating comments, so turn on app. */
1616 if (flag_debug_asm)
1617 app_enable ();
1619 if (for_eh)
1621 #ifdef EH_FRAME_SECTION
1622 EH_FRAME_SECTION ();
1623 #else
1624 tree label = get_file_function_name ('F');
1626 force_data_section ();
1627 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1628 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1629 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1630 #endif
1631 assemble_label ("__FRAME_BEGIN__");
1633 else
1634 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1636 /* Output the CIE. */
1637 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1638 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1639 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1640 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1641 if (for_eh)
1642 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1643 else
1644 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1645 #else
1646 if (for_eh)
1647 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1648 else
1649 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1650 #endif
1651 if (flag_debug_asm)
1652 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1653 ASM_COMMENT_START);
1655 fputc ('\n', asm_out_file);
1656 ASM_OUTPUT_LABEL (asm_out_file, l1);
1658 if (for_eh)
1659 /* Now that the CIE pointer is PC-relative for EH,
1660 use 0 to identify the CIE. */
1661 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1662 else
1663 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1665 if (flag_debug_asm)
1666 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1668 fputc ('\n', asm_out_file);
1669 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1671 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1672 fputc ('\n', asm_out_file);
1675 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1676 if (flag_debug_asm)
1677 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1679 fputc ('\n', asm_out_file);
1680 if (eh_ptr)
1682 /* The CIE contains a pointer to the exception region info for the
1683 frame. Make the augmentation string three bytes (including the
1684 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1685 can't handle unaligned relocs. */
1686 if (flag_debug_asm)
1688 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1689 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1691 else
1693 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1695 fputc ('\n', asm_out_file);
1697 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1698 if (flag_debug_asm)
1699 fprintf (asm_out_file, "\t%s pointer to exception region info",
1700 ASM_COMMENT_START);
1702 else
1704 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1705 if (flag_debug_asm)
1706 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1707 ASM_COMMENT_START);
1710 fputc ('\n', asm_out_file);
1711 output_uleb128 (1);
1712 if (flag_debug_asm)
1713 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1715 fputc ('\n', asm_out_file);
1716 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1717 if (flag_debug_asm)
1718 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1720 fputc ('\n', asm_out_file);
1721 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1722 if (flag_debug_asm)
1723 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1725 fputc ('\n', asm_out_file);
1727 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1728 output_cfi (cfi, NULL);
1730 /* Pad the CIE out to an address sized boundary. */
1731 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1732 ASM_OUTPUT_LABEL (asm_out_file, l2);
1733 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1734 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1735 if (flag_debug_asm)
1736 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1737 fputc ('\n', asm_out_file);
1738 #endif
1740 /* Loop through all of the FDE's. */
1741 for (i = 0; i < fde_table_in_use; ++i)
1743 fde = &fde_table[i];
1745 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
1746 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
1747 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1748 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2);
1749 if (for_eh)
1750 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1751 else
1752 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1753 #else
1754 if (for_eh)
1755 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1756 else
1757 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1758 #endif
1759 if (flag_debug_asm)
1760 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1761 fputc ('\n', asm_out_file);
1762 ASM_OUTPUT_LABEL (asm_out_file, l1);
1764 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1765 emits a target dependent sized offset when for_eh is not true.
1766 This inconsistency may confuse gdb. The only case where we need a
1767 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1768 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1769 though in order to be compatible with the dwarf_fde struct in frame.c.
1770 If the for_eh case is changed, then the struct in frame.c has
1771 to be adjusted appropriately. */
1772 if (for_eh)
1773 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1774 else
1775 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1776 if (flag_debug_asm)
1777 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1779 fputc ('\n', asm_out_file);
1780 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1781 if (flag_debug_asm)
1782 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1784 fputc ('\n', asm_out_file);
1785 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1786 fde->dw_fde_end, fde->dw_fde_begin);
1787 if (flag_debug_asm)
1788 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1790 fputc ('\n', asm_out_file);
1792 /* Loop through the Call Frame Instructions associated with
1793 this FDE. */
1794 fde->dw_fde_current_label = fde->dw_fde_begin;
1795 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1796 output_cfi (cfi, fde);
1798 /* Pad the FDE out to an address sized boundary. */
1799 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1800 ASM_OUTPUT_LABEL (asm_out_file, l2);
1801 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1802 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1803 if (flag_debug_asm)
1804 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1805 fputc ('\n', asm_out_file);
1806 #endif
1808 #ifndef EH_FRAME_SECTION
1809 if (for_eh)
1811 /* Emit terminating zero for table. */
1812 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1813 fputc ('\n', asm_out_file);
1815 #endif
1816 #ifdef MIPS_DEBUGGING_INFO
1817 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1818 get a value of 0. Putting .align 0 after the label fixes it. */
1819 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1820 #endif
1822 /* Turn off app to make assembly quicker. */
1823 if (flag_debug_asm)
1824 app_disable ();
1827 /* Output a marker (i.e. a label) for the beginning of a function, before
1828 the prologue. */
1830 void
1831 dwarf2out_begin_prologue ()
1833 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1834 register dw_fde_ref fde;
1836 ++current_funcdef_number;
1838 function_section (current_function_decl);
1839 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1840 current_funcdef_number);
1841 ASM_OUTPUT_LABEL (asm_out_file, label);
1843 /* Expand the fde table if necessary. */
1844 if (fde_table_in_use == fde_table_allocated)
1846 fde_table_allocated += FDE_TABLE_INCREMENT;
1847 fde_table
1848 = (dw_fde_ref) xrealloc (fde_table,
1849 fde_table_allocated * sizeof (dw_fde_node));
1852 /* Record the FDE associated with this function. */
1853 current_funcdef_fde = fde_table_in_use;
1855 /* Add the new FDE at the end of the fde_table. */
1856 fde = &fde_table[fde_table_in_use++];
1857 fde->dw_fde_begin = xstrdup (label);
1858 fde->dw_fde_current_label = NULL;
1859 fde->dw_fde_end = NULL;
1860 fde->dw_fde_cfi = NULL;
1862 args_size = old_args_size = 0;
1865 /* Output a marker (i.e. a label) for the absolute end of the generated code
1866 for a function definition. This gets called *after* the epilogue code has
1867 been generated. */
1869 void
1870 dwarf2out_end_epilogue ()
1872 dw_fde_ref fde;
1873 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1875 /* Output a label to mark the endpoint of the code generated for this
1876 function. */
1877 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1878 ASM_OUTPUT_LABEL (asm_out_file, label);
1879 fde = &fde_table[fde_table_in_use - 1];
1880 fde->dw_fde_end = xstrdup (label);
1883 void
1884 dwarf2out_frame_init ()
1886 /* Allocate the initial hunk of the fde_table. */
1887 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
1888 fde_table_allocated = FDE_TABLE_INCREMENT;
1889 fde_table_in_use = 0;
1891 /* Generate the CFA instructions common to all FDE's. Do it now for the
1892 sake of lookup_cfa. */
1894 #ifdef DWARF2_UNWIND_INFO
1895 /* On entry, the Canonical Frame Address is at SP. */
1896 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1897 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1898 #endif
1901 void
1902 dwarf2out_frame_finish ()
1904 /* Output call frame information. */
1905 #ifdef MIPS_DEBUGGING_INFO
1906 if (write_symbols == DWARF2_DEBUG)
1907 output_call_frame_info (0);
1908 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1909 output_call_frame_info (1);
1910 #else
1911 if (write_symbols == DWARF2_DEBUG
1912 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1913 output_call_frame_info (1);
1914 #endif
1917 #endif /* .debug_frame support */
1919 /* And now, the support for symbolic debugging information. */
1920 #ifdef DWARF2_DEBUGGING_INFO
1922 /* NOTE: In the comments in this file, many references are made to
1923 "Debugging Information Entries". This term is abbreviated as `DIE'
1924 throughout the remainder of this file. */
1926 /* An internal representation of the DWARF output is built, and then
1927 walked to generate the DWARF debugging info. The walk of the internal
1928 representation is done after the entire program has been compiled.
1929 The types below are used to describe the internal representation. */
1931 /* Each DIE may have a series of attribute/value pairs. Values
1932 can take on several forms. The forms that are used in this
1933 implementation are listed below. */
1935 typedef enum
1937 dw_val_class_addr,
1938 dw_val_class_loc,
1939 dw_val_class_const,
1940 dw_val_class_unsigned_const,
1941 dw_val_class_long_long,
1942 dw_val_class_float,
1943 dw_val_class_flag,
1944 dw_val_class_die_ref,
1945 dw_val_class_fde_ref,
1946 dw_val_class_lbl_id,
1947 dw_val_class_lbl_offset,
1948 dw_val_class_str
1950 dw_val_class;
1952 /* Various DIE's use offsets relative to the beginning of the
1953 .debug_info section to refer to each other. */
1955 typedef long int dw_offset;
1957 /* Define typedefs here to avoid circular dependencies. */
1959 typedef struct die_struct *dw_die_ref;
1960 typedef struct dw_attr_struct *dw_attr_ref;
1961 typedef struct dw_val_struct *dw_val_ref;
1962 typedef struct dw_line_info_struct *dw_line_info_ref;
1963 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1964 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1965 typedef struct pubname_struct *pubname_ref;
1966 typedef dw_die_ref *arange_ref;
1968 /* Describe a double word constant value. */
1970 typedef struct dw_long_long_struct
1972 unsigned long hi;
1973 unsigned long low;
1975 dw_long_long_const;
1977 /* Describe a floating point constant value. */
1979 typedef struct dw_fp_struct
1981 long *array;
1982 unsigned length;
1984 dw_float_const;
1986 /* Each entry in the line_info_table maintains the file and
1987 line number associated with the label generated for that
1988 entry. The label gives the PC value associated with
1989 the line number entry. */
1991 typedef struct dw_line_info_struct
1993 unsigned long dw_file_num;
1994 unsigned long dw_line_num;
1996 dw_line_info_entry;
1998 /* Line information for functions in separate sections; each one gets its
1999 own sequence. */
2000 typedef struct dw_separate_line_info_struct
2002 unsigned long dw_file_num;
2003 unsigned long dw_line_num;
2004 unsigned long function;
2006 dw_separate_line_info_entry;
2008 /* The dw_val_node describes an attribute's value, as it is
2009 represented internally. */
2011 typedef struct dw_val_struct
2013 dw_val_class val_class;
2014 union
2016 char *val_addr;
2017 dw_loc_descr_ref val_loc;
2018 long int val_int;
2019 long unsigned val_unsigned;
2020 dw_long_long_const val_long_long;
2021 dw_float_const val_float;
2022 dw_die_ref val_die_ref;
2023 unsigned val_fde_index;
2024 char *val_str;
2025 char *val_lbl_id;
2026 unsigned char val_flag;
2030 dw_val_node;
2032 /* Locations in memory are described using a sequence of stack machine
2033 operations. */
2035 typedef struct dw_loc_descr_struct
2037 dw_loc_descr_ref dw_loc_next;
2038 enum dwarf_location_atom dw_loc_opc;
2039 dw_val_node dw_loc_oprnd1;
2040 dw_val_node dw_loc_oprnd2;
2042 dw_loc_descr_node;
2044 /* Each DIE attribute has a field specifying the attribute kind,
2045 a link to the next attribute in the chain, and an attribute value.
2046 Attributes are typically linked below the DIE they modify. */
2048 typedef struct dw_attr_struct
2050 enum dwarf_attribute dw_attr;
2051 dw_attr_ref dw_attr_next;
2052 dw_val_node dw_attr_val;
2054 dw_attr_node;
2056 /* The Debugging Information Entry (DIE) structure */
2058 typedef struct die_struct
2060 enum dwarf_tag die_tag;
2061 dw_attr_ref die_attr;
2062 dw_attr_ref die_attr_last;
2063 dw_die_ref die_parent;
2064 dw_die_ref die_child;
2065 dw_die_ref die_child_last;
2066 dw_die_ref die_sib;
2067 dw_offset die_offset;
2068 unsigned long die_abbrev;
2070 die_node;
2072 /* The pubname structure */
2074 typedef struct pubname_struct
2076 dw_die_ref die;
2077 char * name;
2079 pubname_entry;
2081 /* The limbo die list structure. */
2082 typedef struct limbo_die_struct
2084 dw_die_ref die;
2085 struct limbo_die_struct *next;
2087 limbo_die_node;
2089 /* How to start an assembler comment. */
2090 #ifndef ASM_COMMENT_START
2091 #define ASM_COMMENT_START ";#"
2092 #endif
2094 /* Define a macro which returns non-zero for a TYPE_DECL which was
2095 implicitly generated for a tagged type.
2097 Note that unlike the gcc front end (which generates a NULL named
2098 TYPE_DECL node for each complete tagged type, each array type, and
2099 each function type node created) the g++ front end generates a
2100 _named_ TYPE_DECL node for each tagged type node created.
2101 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2102 generate a DW_TAG_typedef DIE for them. */
2104 #define TYPE_DECL_IS_STUB(decl) \
2105 (DECL_NAME (decl) == NULL_TREE \
2106 || (DECL_ARTIFICIAL (decl) \
2107 && is_tagged_type (TREE_TYPE (decl)) \
2108 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2109 /* This is necessary for stub decls that \
2110 appear in nested inline functions. */ \
2111 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2112 && (decl_ultimate_origin (decl) \
2113 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2115 /* Information concerning the compilation unit's programming
2116 language, and compiler version. */
2118 extern int flag_traditional;
2119 extern char *version_string;
2121 /* Fixed size portion of the DWARF compilation unit header. */
2122 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2124 /* Fixed size portion of debugging line information prolog. */
2125 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2127 /* Fixed size portion of public names info. */
2128 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2130 /* Fixed size portion of the address range info. */
2131 #define DWARF_ARANGES_HEADER_SIZE \
2132 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
2134 /* The default is to have gcc emit the line number tables. */
2135 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2136 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2137 #endif
2139 /* Define the architecture-dependent minimum instruction length (in bytes).
2140 In this implementation of DWARF, this field is used for information
2141 purposes only. Since GCC generates assembly language, we have
2142 no a priori knowledge of how many instruction bytes are generated
2143 for each source line, and therefore can use only the DW_LNE_set_address
2144 and DW_LNS_fixed_advance_pc line information commands. */
2146 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2147 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2148 #endif
2150 /* Minimum line offset in a special line info. opcode.
2151 This value was chosen to give a reasonable range of values. */
2152 #define DWARF_LINE_BASE -10
2154 /* First special line opcde - leave room for the standard opcodes. */
2155 #define DWARF_LINE_OPCODE_BASE 10
2157 /* Range of line offsets in a special line info. opcode. */
2158 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2160 /* Flag that indicates the initial value of the is_stmt_start flag.
2161 In the present implementation, we do not mark any lines as
2162 the beginning of a source statement, because that information
2163 is not made available by the GCC front-end. */
2164 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2166 /* This location is used by calc_die_sizes() to keep track
2167 the offset of each DIE within the .debug_info section. */
2168 static unsigned long next_die_offset;
2170 /* Record the root of the DIE's built for the current compilation unit. */
2171 static dw_die_ref comp_unit_die;
2173 /* A list of DIEs with a NULL parent waiting to be relocated. */
2174 static limbo_die_node *limbo_die_list = 0;
2176 /* Pointer to an array of filenames referenced by this compilation unit. */
2177 static char **file_table;
2179 /* Total number of entries in the table (i.e. array) pointed to by
2180 `file_table'. This is the *total* and includes both used and unused
2181 slots. */
2182 static unsigned file_table_allocated;
2184 /* Number of entries in the file_table which are actually in use. */
2185 static unsigned file_table_in_use;
2187 /* Size (in elements) of increments by which we may expand the filename
2188 table. */
2189 #define FILE_TABLE_INCREMENT 64
2191 /* Local pointer to the name of the main input file. Initialized in
2192 dwarf2out_init. */
2193 static char *primary_filename;
2195 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
2196 which their beginnings are encountered. We output Dwarf debugging info
2197 that refers to the beginnings and ends of the ranges of code for each
2198 lexical block. The labels themselves are generated in final.c, which
2199 assigns numbers to the blocks in the same way. */
2200 static unsigned next_block_number = 2;
2202 /* A pointer to the base of a table of references to DIE's that describe
2203 declarations. The table is indexed by DECL_UID() which is a unique
2204 number identifying each decl. */
2205 static dw_die_ref *decl_die_table;
2207 /* Number of elements currently allocated for the decl_die_table. */
2208 static unsigned decl_die_table_allocated;
2210 /* Number of elements in decl_die_table currently in use. */
2211 static unsigned decl_die_table_in_use;
2213 /* Size (in elements) of increments by which we may expand the
2214 decl_die_table. */
2215 #define DECL_DIE_TABLE_INCREMENT 256
2217 /* Structure used for the decl_scope table. scope is the current declaration
2218 scope, and previous is the entry that is the parent of this scope. This
2219 is usually but not always the immediately preceeding entry. */
2221 typedef struct decl_scope_struct
2223 tree scope;
2224 int previous;
2226 decl_scope_node;
2228 /* A pointer to the base of a table of references to declaration
2229 scopes. This table is a display which tracks the nesting
2230 of declaration scopes at the current scope and containing
2231 scopes. This table is used to find the proper place to
2232 define type declaration DIE's. */
2233 static decl_scope_node *decl_scope_table;
2235 /* Number of elements currently allocated for the decl_scope_table. */
2236 static int decl_scope_table_allocated;
2238 /* Current level of nesting of declaration scopes. */
2239 static int decl_scope_depth;
2241 /* Size (in elements) of increments by which we may expand the
2242 decl_scope_table. */
2243 #define DECL_SCOPE_TABLE_INCREMENT 64
2245 /* A pointer to the base of a list of references to DIE's that
2246 are uniquely identified by their tag, presence/absence of
2247 children DIE's, and list of attribute/value pairs. */
2248 static dw_die_ref *abbrev_die_table;
2250 /* Number of elements currently allocated for abbrev_die_table. */
2251 static unsigned abbrev_die_table_allocated;
2253 /* Number of elements in type_die_table currently in use. */
2254 static unsigned abbrev_die_table_in_use;
2256 /* Size (in elements) of increments by which we may expand the
2257 abbrev_die_table. */
2258 #define ABBREV_DIE_TABLE_INCREMENT 256
2260 /* A pointer to the base of a table that contains line information
2261 for each source code line in .text in the compilation unit. */
2262 static dw_line_info_ref line_info_table;
2264 /* Number of elements currently allocated for line_info_table. */
2265 static unsigned line_info_table_allocated;
2267 /* Number of elements in separate_line_info_table currently in use. */
2268 static unsigned separate_line_info_table_in_use;
2270 /* A pointer to the base of a table that contains line information
2271 for each source code line outside of .text in the compilation unit. */
2272 static dw_separate_line_info_ref separate_line_info_table;
2274 /* Number of elements currently allocated for separate_line_info_table. */
2275 static unsigned separate_line_info_table_allocated;
2277 /* Number of elements in line_info_table currently in use. */
2278 static unsigned line_info_table_in_use;
2280 /* Size (in elements) of increments by which we may expand the
2281 line_info_table. */
2282 #define LINE_INFO_TABLE_INCREMENT 1024
2284 /* A pointer to the base of a table that contains a list of publicly
2285 accessible names. */
2286 static pubname_ref pubname_table;
2288 /* Number of elements currently allocated for pubname_table. */
2289 static unsigned pubname_table_allocated;
2291 /* Number of elements in pubname_table currently in use. */
2292 static unsigned pubname_table_in_use;
2294 /* Size (in elements) of increments by which we may expand the
2295 pubname_table. */
2296 #define PUBNAME_TABLE_INCREMENT 64
2298 /* A pointer to the base of a table that contains a list of publicly
2299 accessible names. */
2300 static arange_ref arange_table;
2302 /* Number of elements currently allocated for arange_table. */
2303 static unsigned arange_table_allocated;
2305 /* Number of elements in arange_table currently in use. */
2306 static unsigned arange_table_in_use;
2308 /* Size (in elements) of increments by which we may expand the
2309 arange_table. */
2310 #define ARANGE_TABLE_INCREMENT 64
2312 /* A pointer to the base of a list of pending types which we haven't
2313 generated DIEs for yet, but which we will have to come back to
2314 later on. */
2316 static tree *pending_types_list;
2318 /* Number of elements currently allocated for the pending_types_list. */
2319 static unsigned pending_types_allocated;
2321 /* Number of elements of pending_types_list currently in use. */
2322 static unsigned pending_types;
2324 /* Size (in elements) of increments by which we may expand the pending
2325 types list. Actually, a single hunk of space of this size should
2326 be enough for most typical programs. */
2327 #define PENDING_TYPES_INCREMENT 64
2329 /* A pointer to the base of a list of incomplete types which might be
2330 completed at some later time. */
2332 static tree *incomplete_types_list;
2334 /* Number of elements currently allocated for the incomplete_types_list. */
2335 static unsigned incomplete_types_allocated;
2337 /* Number of elements of incomplete_types_list currently in use. */
2338 static unsigned incomplete_types;
2340 /* Size (in elements) of increments by which we may expand the incomplete
2341 types list. Actually, a single hunk of space of this size should
2342 be enough for most typical programs. */
2343 #define INCOMPLETE_TYPES_INCREMENT 64
2345 /* Record whether the function being analyzed contains inlined functions. */
2346 static int current_function_has_inlines;
2347 #if 0 && defined (MIPS_DEBUGGING_INFO)
2348 static int comp_unit_has_inlines;
2349 #endif
2351 /* A pointer to the ..._DECL node which we have most recently been working
2352 on. We keep this around just in case something about it looks screwy and
2353 we want to tell the user what the source coordinates for the actual
2354 declaration are. */
2355 static tree dwarf_last_decl;
2357 /* Forward declarations for functions defined in this file. */
2359 static void addr_const_to_string PROTO((dyn_string_t, rtx));
2360 static char *addr_to_string PROTO((rtx));
2361 static int is_pseudo_reg PROTO((rtx));
2362 static tree type_main_variant PROTO((tree));
2363 static int is_tagged_type PROTO((tree));
2364 static const char *dwarf_tag_name PROTO((unsigned));
2365 static const char *dwarf_attr_name PROTO((unsigned));
2366 static const char *dwarf_form_name PROTO((unsigned));
2367 static const char *dwarf_stack_op_name PROTO((unsigned));
2368 #if 0
2369 static const char *dwarf_type_encoding_name PROTO((unsigned));
2370 #endif
2371 static tree decl_ultimate_origin PROTO((tree));
2372 static tree block_ultimate_origin PROTO((tree));
2373 static tree decl_class_context PROTO((tree));
2374 static void add_dwarf_attr PROTO((dw_die_ref, dw_attr_ref));
2375 static void add_AT_flag PROTO((dw_die_ref,
2376 enum dwarf_attribute,
2377 unsigned));
2378 static void add_AT_int PROTO((dw_die_ref,
2379 enum dwarf_attribute, long));
2380 static void add_AT_unsigned PROTO((dw_die_ref,
2381 enum dwarf_attribute,
2382 unsigned long));
2383 static void add_AT_long_long PROTO((dw_die_ref,
2384 enum dwarf_attribute,
2385 unsigned long, unsigned long));
2386 static void add_AT_float PROTO((dw_die_ref,
2387 enum dwarf_attribute,
2388 unsigned, long *));
2389 static void add_AT_string PROTO((dw_die_ref,
2390 enum dwarf_attribute,
2391 const char *));
2392 static void add_AT_die_ref PROTO((dw_die_ref,
2393 enum dwarf_attribute,
2394 dw_die_ref));
2395 static void add_AT_fde_ref PROTO((dw_die_ref,
2396 enum dwarf_attribute,
2397 unsigned));
2398 static void add_AT_loc PROTO((dw_die_ref,
2399 enum dwarf_attribute,
2400 dw_loc_descr_ref));
2401 static void add_AT_addr PROTO((dw_die_ref,
2402 enum dwarf_attribute, char *));
2403 static void add_AT_lbl_id PROTO((dw_die_ref,
2404 enum dwarf_attribute, char *));
2405 static void add_AT_lbl_offset PROTO((dw_die_ref,
2406 enum dwarf_attribute, char *));
2407 static int is_extern_subr_die PROTO((dw_die_ref));
2408 static dw_attr_ref get_AT PROTO((dw_die_ref,
2409 enum dwarf_attribute));
2410 static char *get_AT_low_pc PROTO((dw_die_ref));
2411 static char *get_AT_hi_pc PROTO((dw_die_ref));
2412 static char *get_AT_string PROTO((dw_die_ref,
2413 enum dwarf_attribute));
2414 static int get_AT_flag PROTO((dw_die_ref,
2415 enum dwarf_attribute));
2416 static unsigned get_AT_unsigned PROTO((dw_die_ref,
2417 enum dwarf_attribute));
2418 static int is_c_family PROTO((void));
2419 static int is_fortran PROTO((void));
2420 static void remove_AT PROTO((dw_die_ref,
2421 enum dwarf_attribute));
2422 static void remove_children PROTO((dw_die_ref));
2423 static void add_child_die PROTO((dw_die_ref, dw_die_ref));
2424 static dw_die_ref new_die PROTO((enum dwarf_tag, dw_die_ref));
2425 static dw_die_ref lookup_type_die PROTO((tree));
2426 static void equate_type_number_to_die PROTO((tree, dw_die_ref));
2427 static dw_die_ref lookup_decl_die PROTO((tree));
2428 static void equate_decl_number_to_die PROTO((tree, dw_die_ref));
2429 static dw_loc_descr_ref new_loc_descr PROTO((enum dwarf_location_atom,
2430 unsigned long, unsigned long));
2431 static void add_loc_descr PROTO((dw_loc_descr_ref *,
2432 dw_loc_descr_ref));
2433 static void print_spaces PROTO((FILE *));
2434 static void print_die PROTO((dw_die_ref, FILE *));
2435 static void print_dwarf_line_table PROTO((FILE *));
2436 static void add_sibling_attributes PROTO((dw_die_ref));
2437 static void build_abbrev_table PROTO((dw_die_ref));
2438 static unsigned long size_of_string PROTO((char *));
2439 static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref));
2440 static unsigned long size_of_locs PROTO((dw_loc_descr_ref));
2441 static int constant_size PROTO((long unsigned));
2442 static unsigned long size_of_die PROTO((dw_die_ref));
2443 static void calc_die_sizes PROTO((dw_die_ref));
2444 static unsigned long size_of_line_prolog PROTO((void));
2445 static unsigned long size_of_pubnames PROTO((void));
2446 static unsigned long size_of_aranges PROTO((void));
2447 static enum dwarf_form value_format PROTO((dw_val_ref));
2448 static void output_value_format PROTO((dw_val_ref));
2449 static void output_abbrev_section PROTO((void));
2450 static void output_loc_operands PROTO((dw_loc_descr_ref));
2451 static unsigned long sibling_offset PROTO((dw_die_ref));
2452 static void output_die PROTO((dw_die_ref));
2453 static void output_compilation_unit_header PROTO((void));
2454 static const char *dwarf2_name PROTO((tree, int));
2455 static void add_pubname PROTO((tree, dw_die_ref));
2456 static void output_pubnames PROTO((void));
2457 static void add_arange PROTO((tree, dw_die_ref));
2458 static void output_aranges PROTO((void));
2459 static void output_line_info PROTO((void));
2460 static int is_body_block PROTO((tree));
2461 static dw_die_ref base_type_die PROTO((tree));
2462 static tree root_type PROTO((tree));
2463 static int is_base_type PROTO((tree));
2464 static dw_die_ref modified_type_die PROTO((tree, int, int, dw_die_ref));
2465 static int type_is_enum PROTO((tree));
2466 static dw_loc_descr_ref reg_loc_descriptor PROTO((rtx));
2467 static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long));
2468 static int is_based_loc PROTO((rtx));
2469 static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx, enum machine_mode mode));
2470 static dw_loc_descr_ref concat_loc_descriptor PROTO((rtx, rtx));
2471 static dw_loc_descr_ref loc_descriptor PROTO((rtx));
2472 static unsigned ceiling PROTO((unsigned, unsigned));
2473 static tree field_type PROTO((tree));
2474 static unsigned simple_type_align_in_bits PROTO((tree));
2475 static unsigned simple_type_size_in_bits PROTO((tree));
2476 static unsigned field_byte_offset PROTO((tree));
2477 static void add_AT_location_description PROTO((dw_die_ref,
2478 enum dwarf_attribute, rtx));
2479 static void add_data_member_location_attribute PROTO((dw_die_ref, tree));
2480 static void add_const_value_attribute PROTO((dw_die_ref, rtx));
2481 static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree));
2482 static void add_name_attribute PROTO((dw_die_ref, const char *));
2483 static void add_bound_info PROTO((dw_die_ref,
2484 enum dwarf_attribute, tree));
2485 static void add_subscript_info PROTO((dw_die_ref, tree));
2486 static void add_byte_size_attribute PROTO((dw_die_ref, tree));
2487 static void add_bit_offset_attribute PROTO((dw_die_ref, tree));
2488 static void add_bit_size_attribute PROTO((dw_die_ref, tree));
2489 static void add_prototyped_attribute PROTO((dw_die_ref, tree));
2490 static void add_abstract_origin_attribute PROTO((dw_die_ref, tree));
2491 static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree));
2492 static void add_src_coords_attributes PROTO((dw_die_ref, tree));
2493 static void add_name_and_src_coords_attributes PROTO((dw_die_ref, tree));
2494 static void push_decl_scope PROTO((tree));
2495 static dw_die_ref scope_die_for PROTO((tree, dw_die_ref));
2496 static void pop_decl_scope PROTO((void));
2497 static void add_type_attribute PROTO((dw_die_ref, tree, int, int,
2498 dw_die_ref));
2499 static char *type_tag PROTO((tree));
2500 static tree member_declared_type PROTO((tree));
2501 #if 0
2502 static char *decl_start_label PROTO((tree));
2503 #endif
2504 static void gen_array_type_die PROTO((tree, dw_die_ref));
2505 static void gen_set_type_die PROTO((tree, dw_die_ref));
2506 #if 0
2507 static void gen_entry_point_die PROTO((tree, dw_die_ref));
2508 #endif
2509 static void pend_type PROTO((tree));
2510 static void output_pending_types_for_scope PROTO((dw_die_ref));
2511 static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref));
2512 static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref));
2513 static void gen_inlined_union_type_die PROTO((tree, dw_die_ref));
2514 static void gen_enumeration_type_die PROTO((tree, dw_die_ref));
2515 static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref));
2516 static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref));
2517 static void gen_formal_types_die PROTO((tree, dw_die_ref));
2518 static void gen_subprogram_die PROTO((tree, dw_die_ref));
2519 static void gen_variable_die PROTO((tree, dw_die_ref));
2520 static void gen_label_die PROTO((tree, dw_die_ref));
2521 static void gen_lexical_block_die PROTO((tree, dw_die_ref, int));
2522 static void gen_inlined_subroutine_die PROTO((tree, dw_die_ref, int));
2523 static void gen_field_die PROTO((tree, dw_die_ref));
2524 static void gen_ptr_to_mbr_type_die PROTO((tree, dw_die_ref));
2525 static void gen_compile_unit_die PROTO((char *));
2526 static void gen_string_type_die PROTO((tree, dw_die_ref));
2527 static void gen_inheritance_die PROTO((tree, dw_die_ref));
2528 static void gen_member_die PROTO((tree, dw_die_ref));
2529 static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref));
2530 static void gen_subroutine_type_die PROTO((tree, dw_die_ref));
2531 static void gen_typedef_die PROTO((tree, dw_die_ref));
2532 static void gen_type_die PROTO((tree, dw_die_ref));
2533 static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref));
2534 static void gen_block_die PROTO((tree, dw_die_ref, int));
2535 static void decls_for_scope PROTO((tree, dw_die_ref, int));
2536 static int is_redundant_typedef PROTO((tree));
2537 static void gen_decl_die PROTO((tree, dw_die_ref));
2538 static unsigned lookup_filename PROTO((const char *));
2539 static void add_incomplete_type PROTO((tree));
2540 static void retry_incomplete_types PROTO((void));
2542 /* Section names used to hold DWARF debugging information. */
2543 #ifndef DEBUG_INFO_SECTION
2544 #define DEBUG_INFO_SECTION ".debug_info"
2545 #endif
2546 #ifndef ABBREV_SECTION
2547 #define ABBREV_SECTION ".debug_abbrev"
2548 #endif
2549 #ifndef ARANGES_SECTION
2550 #define ARANGES_SECTION ".debug_aranges"
2551 #endif
2552 #ifndef DW_MACINFO_SECTION
2553 #define DW_MACINFO_SECTION ".debug_macinfo"
2554 #endif
2555 #ifndef DEBUG_LINE_SECTION
2556 #define DEBUG_LINE_SECTION ".debug_line"
2557 #endif
2558 #ifndef LOC_SECTION
2559 #define LOC_SECTION ".debug_loc"
2560 #endif
2561 #ifndef PUBNAMES_SECTION
2562 #define PUBNAMES_SECTION ".debug_pubnames"
2563 #endif
2564 #ifndef STR_SECTION
2565 #define STR_SECTION ".debug_str"
2566 #endif
2568 /* Standard ELF section names for compiled code and data. */
2569 #ifndef TEXT_SECTION
2570 #define TEXT_SECTION ".text"
2571 #endif
2572 #ifndef DATA_SECTION
2573 #define DATA_SECTION ".data"
2574 #endif
2575 #ifndef BSS_SECTION
2576 #define BSS_SECTION ".bss"
2577 #endif
2579 /* Labels we insert at beginning sections we can reference instead of
2580 the section names themselves. */
2582 #ifndef TEXT_SECTION_LABEL
2583 #define TEXT_SECTION_LABEL "Ltext"
2584 #endif
2585 #ifndef DEBUG_LINE_SECTION_LABEL
2586 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
2587 #endif
2588 #ifndef DEBUG_INFO_SECTION_LABEL
2589 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
2590 #endif
2591 #ifndef ABBREV_SECTION_LABEL
2592 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
2593 #endif
2596 /* Definitions of defaults for formats and names of various special
2597 (artificial) labels which may be generated within this file (when the -g
2598 options is used and DWARF_DEBUGGING_INFO is in effect.
2599 If necessary, these may be overridden from within the tm.h file, but
2600 typically, overriding these defaults is unnecessary. */
2602 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2603 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2604 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2605 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2606 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2608 #ifndef TEXT_END_LABEL
2609 #define TEXT_END_LABEL "Letext"
2610 #endif
2611 #ifndef DATA_END_LABEL
2612 #define DATA_END_LABEL "Ledata"
2613 #endif
2614 #ifndef BSS_END_LABEL
2615 #define BSS_END_LABEL "Lebss"
2616 #endif
2617 #ifndef INSN_LABEL_FMT
2618 #define INSN_LABEL_FMT "LI%u_"
2619 #endif
2620 #ifndef BLOCK_BEGIN_LABEL
2621 #define BLOCK_BEGIN_LABEL "LBB"
2622 #endif
2623 #ifndef BLOCK_END_LABEL
2624 #define BLOCK_END_LABEL "LBE"
2625 #endif
2626 #ifndef BODY_BEGIN_LABEL
2627 #define BODY_BEGIN_LABEL "Lbb"
2628 #endif
2629 #ifndef BODY_END_LABEL
2630 #define BODY_END_LABEL "Lbe"
2631 #endif
2632 #ifndef LINE_CODE_LABEL
2633 #define LINE_CODE_LABEL "LM"
2634 #endif
2635 #ifndef SEPARATE_LINE_CODE_LABEL
2636 #define SEPARATE_LINE_CODE_LABEL "LSM"
2637 #endif
2639 /* Convert a reference to the assembler name of a C-level name. This
2640 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
2641 a string rather than writing to a file. */
2642 #ifndef ASM_NAME_TO_STRING
2643 #define ASM_NAME_TO_STRING(STR, NAME) \
2644 do { \
2645 if ((NAME)[0] == '*') \
2646 dyn_string_append (STR, NAME + 1); \
2647 else \
2649 const char *newstr; \
2650 STRIP_NAME_ENCODING (newstr, NAME); \
2651 dyn_string_append (STR, user_label_prefix); \
2652 dyn_string_append (STR, newstr); \
2655 while (0)
2656 #endif
2658 /* We allow a language front-end to designate a function that is to be
2659 called to "demangle" any name before it it put into a DIE. */
2661 static char *(*demangle_name_func) PROTO((char *));
2663 void
2664 dwarf2out_set_demangle_name_func (func)
2665 char *(*func) PROTO((char *));
2667 demangle_name_func = func;
2670 /* Convert an integer constant expression into assembler syntax. Addition
2671 and subtraction are the only arithmetic that may appear in these
2672 expressions. This is an adaptation of output_addr_const in final.c.
2673 Here, the target of the conversion is a string buffer. We can't use
2674 output_addr_const directly, because it writes to a file. */
2676 static void
2677 addr_const_to_string (str, x)
2678 dyn_string_t str;
2679 rtx x;
2681 char buf1[256];
2683 restart:
2684 switch (GET_CODE (x))
2686 case PC:
2687 if (flag_pic)
2688 dyn_string_append (str, ",");
2689 else
2690 abort ();
2691 break;
2693 case SYMBOL_REF:
2694 ASM_NAME_TO_STRING (str, XSTR (x, 0));
2695 break;
2697 case LABEL_REF:
2698 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2699 ASM_NAME_TO_STRING (str, buf1);
2700 break;
2702 case CODE_LABEL:
2703 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
2704 ASM_NAME_TO_STRING (str, buf1);
2705 break;
2707 case CONST_INT:
2708 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
2709 dyn_string_append (str, buf1);
2710 break;
2712 case CONST:
2713 /* This used to output parentheses around the expression, but that does
2714 not work on the 386 (either ATT or BSD assembler). */
2715 addr_const_to_string (str, XEXP (x, 0));
2716 break;
2718 case CONST_DOUBLE:
2719 if (GET_MODE (x) == VOIDmode)
2721 /* We can use %d if the number is one word and positive. */
2722 if (CONST_DOUBLE_HIGH (x))
2723 sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
2724 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2725 else if (CONST_DOUBLE_LOW (x) < 0)
2726 sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
2727 else
2728 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
2729 CONST_DOUBLE_LOW (x));
2730 dyn_string_append (str, buf1);
2732 else
2733 /* We can't handle floating point constants; PRINT_OPERAND must
2734 handle them. */
2735 output_operand_lossage ("floating constant misused");
2736 break;
2738 case PLUS:
2739 /* Some assemblers need integer constants to appear last (eg masm). */
2740 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2742 addr_const_to_string (str, XEXP (x, 1));
2743 if (INTVAL (XEXP (x, 0)) >= 0)
2744 dyn_string_append (str, "+");
2746 addr_const_to_string (str, XEXP (x, 0));
2748 else
2750 addr_const_to_string (str, XEXP (x, 0));
2751 if (INTVAL (XEXP (x, 1)) >= 0)
2752 dyn_string_append (str, "+");
2754 addr_const_to_string (str, XEXP (x, 1));
2756 break;
2758 case MINUS:
2759 /* Avoid outputting things like x-x or x+5-x, since some assemblers
2760 can't handle that. */
2761 x = simplify_subtraction (x);
2762 if (GET_CODE (x) != MINUS)
2763 goto restart;
2765 addr_const_to_string (str, XEXP (x, 0));
2766 dyn_string_append (str, "-");
2767 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2768 && INTVAL (XEXP (x, 1)) < 0)
2770 dyn_string_append (str, ASM_OPEN_PAREN);
2771 addr_const_to_string (str, XEXP (x, 1));
2772 dyn_string_append (str, ASM_CLOSE_PAREN);
2774 else
2775 addr_const_to_string (str, XEXP (x, 1));
2776 break;
2778 case ZERO_EXTEND:
2779 case SIGN_EXTEND:
2780 addr_const_to_string (str, XEXP (x, 0));
2781 break;
2783 default:
2784 output_operand_lossage ("invalid expression as operand");
2788 /* Convert an address constant to a string, and return a pointer to
2789 a copy of the result, located on the heap. */
2791 static char *
2792 addr_to_string (x)
2793 rtx x;
2795 dyn_string_t ds = dyn_string_new (256);
2796 char *s;
2798 addr_const_to_string (ds, x);
2800 /* Return the dynamically allocated string, but free the
2801 dyn_string_t itself. */
2802 s = ds->s;
2803 free (ds);
2804 return s;
2807 /* Test if rtl node points to a pseudo register. */
2809 static inline int
2810 is_pseudo_reg (rtl)
2811 register rtx rtl;
2813 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
2814 || ((GET_CODE (rtl) == SUBREG)
2815 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
2818 /* Return a reference to a type, with its const and volatile qualifiers
2819 removed. */
2821 static inline tree
2822 type_main_variant (type)
2823 register tree type;
2825 type = TYPE_MAIN_VARIANT (type);
2827 /* There really should be only one main variant among any group of variants
2828 of a given type (and all of the MAIN_VARIANT values for all members of
2829 the group should point to that one type) but sometimes the C front-end
2830 messes this up for array types, so we work around that bug here. */
2832 if (TREE_CODE (type) == ARRAY_TYPE)
2833 while (type != TYPE_MAIN_VARIANT (type))
2834 type = TYPE_MAIN_VARIANT (type);
2836 return type;
2839 /* Return non-zero if the given type node represents a tagged type. */
2841 static inline int
2842 is_tagged_type (type)
2843 register tree type;
2845 register enum tree_code code = TREE_CODE (type);
2847 return (code == RECORD_TYPE || code == UNION_TYPE
2848 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
2851 /* Convert a DIE tag into its string name. */
2853 static const char *
2854 dwarf_tag_name (tag)
2855 register unsigned tag;
2857 switch (tag)
2859 case DW_TAG_padding:
2860 return "DW_TAG_padding";
2861 case DW_TAG_array_type:
2862 return "DW_TAG_array_type";
2863 case DW_TAG_class_type:
2864 return "DW_TAG_class_type";
2865 case DW_TAG_entry_point:
2866 return "DW_TAG_entry_point";
2867 case DW_TAG_enumeration_type:
2868 return "DW_TAG_enumeration_type";
2869 case DW_TAG_formal_parameter:
2870 return "DW_TAG_formal_parameter";
2871 case DW_TAG_imported_declaration:
2872 return "DW_TAG_imported_declaration";
2873 case DW_TAG_label:
2874 return "DW_TAG_label";
2875 case DW_TAG_lexical_block:
2876 return "DW_TAG_lexical_block";
2877 case DW_TAG_member:
2878 return "DW_TAG_member";
2879 case DW_TAG_pointer_type:
2880 return "DW_TAG_pointer_type";
2881 case DW_TAG_reference_type:
2882 return "DW_TAG_reference_type";
2883 case DW_TAG_compile_unit:
2884 return "DW_TAG_compile_unit";
2885 case DW_TAG_string_type:
2886 return "DW_TAG_string_type";
2887 case DW_TAG_structure_type:
2888 return "DW_TAG_structure_type";
2889 case DW_TAG_subroutine_type:
2890 return "DW_TAG_subroutine_type";
2891 case DW_TAG_typedef:
2892 return "DW_TAG_typedef";
2893 case DW_TAG_union_type:
2894 return "DW_TAG_union_type";
2895 case DW_TAG_unspecified_parameters:
2896 return "DW_TAG_unspecified_parameters";
2897 case DW_TAG_variant:
2898 return "DW_TAG_variant";
2899 case DW_TAG_common_block:
2900 return "DW_TAG_common_block";
2901 case DW_TAG_common_inclusion:
2902 return "DW_TAG_common_inclusion";
2903 case DW_TAG_inheritance:
2904 return "DW_TAG_inheritance";
2905 case DW_TAG_inlined_subroutine:
2906 return "DW_TAG_inlined_subroutine";
2907 case DW_TAG_module:
2908 return "DW_TAG_module";
2909 case DW_TAG_ptr_to_member_type:
2910 return "DW_TAG_ptr_to_member_type";
2911 case DW_TAG_set_type:
2912 return "DW_TAG_set_type";
2913 case DW_TAG_subrange_type:
2914 return "DW_TAG_subrange_type";
2915 case DW_TAG_with_stmt:
2916 return "DW_TAG_with_stmt";
2917 case DW_TAG_access_declaration:
2918 return "DW_TAG_access_declaration";
2919 case DW_TAG_base_type:
2920 return "DW_TAG_base_type";
2921 case DW_TAG_catch_block:
2922 return "DW_TAG_catch_block";
2923 case DW_TAG_const_type:
2924 return "DW_TAG_const_type";
2925 case DW_TAG_constant:
2926 return "DW_TAG_constant";
2927 case DW_TAG_enumerator:
2928 return "DW_TAG_enumerator";
2929 case DW_TAG_file_type:
2930 return "DW_TAG_file_type";
2931 case DW_TAG_friend:
2932 return "DW_TAG_friend";
2933 case DW_TAG_namelist:
2934 return "DW_TAG_namelist";
2935 case DW_TAG_namelist_item:
2936 return "DW_TAG_namelist_item";
2937 case DW_TAG_packed_type:
2938 return "DW_TAG_packed_type";
2939 case DW_TAG_subprogram:
2940 return "DW_TAG_subprogram";
2941 case DW_TAG_template_type_param:
2942 return "DW_TAG_template_type_param";
2943 case DW_TAG_template_value_param:
2944 return "DW_TAG_template_value_param";
2945 case DW_TAG_thrown_type:
2946 return "DW_TAG_thrown_type";
2947 case DW_TAG_try_block:
2948 return "DW_TAG_try_block";
2949 case DW_TAG_variant_part:
2950 return "DW_TAG_variant_part";
2951 case DW_TAG_variable:
2952 return "DW_TAG_variable";
2953 case DW_TAG_volatile_type:
2954 return "DW_TAG_volatile_type";
2955 case DW_TAG_MIPS_loop:
2956 return "DW_TAG_MIPS_loop";
2957 case DW_TAG_format_label:
2958 return "DW_TAG_format_label";
2959 case DW_TAG_function_template:
2960 return "DW_TAG_function_template";
2961 case DW_TAG_class_template:
2962 return "DW_TAG_class_template";
2963 default:
2964 return "DW_TAG_<unknown>";
2968 /* Convert a DWARF attribute code into its string name. */
2970 static const char *
2971 dwarf_attr_name (attr)
2972 register unsigned attr;
2974 switch (attr)
2976 case DW_AT_sibling:
2977 return "DW_AT_sibling";
2978 case DW_AT_location:
2979 return "DW_AT_location";
2980 case DW_AT_name:
2981 return "DW_AT_name";
2982 case DW_AT_ordering:
2983 return "DW_AT_ordering";
2984 case DW_AT_subscr_data:
2985 return "DW_AT_subscr_data";
2986 case DW_AT_byte_size:
2987 return "DW_AT_byte_size";
2988 case DW_AT_bit_offset:
2989 return "DW_AT_bit_offset";
2990 case DW_AT_bit_size:
2991 return "DW_AT_bit_size";
2992 case DW_AT_element_list:
2993 return "DW_AT_element_list";
2994 case DW_AT_stmt_list:
2995 return "DW_AT_stmt_list";
2996 case DW_AT_low_pc:
2997 return "DW_AT_low_pc";
2998 case DW_AT_high_pc:
2999 return "DW_AT_high_pc";
3000 case DW_AT_language:
3001 return "DW_AT_language";
3002 case DW_AT_member:
3003 return "DW_AT_member";
3004 case DW_AT_discr:
3005 return "DW_AT_discr";
3006 case DW_AT_discr_value:
3007 return "DW_AT_discr_value";
3008 case DW_AT_visibility:
3009 return "DW_AT_visibility";
3010 case DW_AT_import:
3011 return "DW_AT_import";
3012 case DW_AT_string_length:
3013 return "DW_AT_string_length";
3014 case DW_AT_common_reference:
3015 return "DW_AT_common_reference";
3016 case DW_AT_comp_dir:
3017 return "DW_AT_comp_dir";
3018 case DW_AT_const_value:
3019 return "DW_AT_const_value";
3020 case DW_AT_containing_type:
3021 return "DW_AT_containing_type";
3022 case DW_AT_default_value:
3023 return "DW_AT_default_value";
3024 case DW_AT_inline:
3025 return "DW_AT_inline";
3026 case DW_AT_is_optional:
3027 return "DW_AT_is_optional";
3028 case DW_AT_lower_bound:
3029 return "DW_AT_lower_bound";
3030 case DW_AT_producer:
3031 return "DW_AT_producer";
3032 case DW_AT_prototyped:
3033 return "DW_AT_prototyped";
3034 case DW_AT_return_addr:
3035 return "DW_AT_return_addr";
3036 case DW_AT_start_scope:
3037 return "DW_AT_start_scope";
3038 case DW_AT_stride_size:
3039 return "DW_AT_stride_size";
3040 case DW_AT_upper_bound:
3041 return "DW_AT_upper_bound";
3042 case DW_AT_abstract_origin:
3043 return "DW_AT_abstract_origin";
3044 case DW_AT_accessibility:
3045 return "DW_AT_accessibility";
3046 case DW_AT_address_class:
3047 return "DW_AT_address_class";
3048 case DW_AT_artificial:
3049 return "DW_AT_artificial";
3050 case DW_AT_base_types:
3051 return "DW_AT_base_types";
3052 case DW_AT_calling_convention:
3053 return "DW_AT_calling_convention";
3054 case DW_AT_count:
3055 return "DW_AT_count";
3056 case DW_AT_data_member_location:
3057 return "DW_AT_data_member_location";
3058 case DW_AT_decl_column:
3059 return "DW_AT_decl_column";
3060 case DW_AT_decl_file:
3061 return "DW_AT_decl_file";
3062 case DW_AT_decl_line:
3063 return "DW_AT_decl_line";
3064 case DW_AT_declaration:
3065 return "DW_AT_declaration";
3066 case DW_AT_discr_list:
3067 return "DW_AT_discr_list";
3068 case DW_AT_encoding:
3069 return "DW_AT_encoding";
3070 case DW_AT_external:
3071 return "DW_AT_external";
3072 case DW_AT_frame_base:
3073 return "DW_AT_frame_base";
3074 case DW_AT_friend:
3075 return "DW_AT_friend";
3076 case DW_AT_identifier_case:
3077 return "DW_AT_identifier_case";
3078 case DW_AT_macro_info:
3079 return "DW_AT_macro_info";
3080 case DW_AT_namelist_items:
3081 return "DW_AT_namelist_items";
3082 case DW_AT_priority:
3083 return "DW_AT_priority";
3084 case DW_AT_segment:
3085 return "DW_AT_segment";
3086 case DW_AT_specification:
3087 return "DW_AT_specification";
3088 case DW_AT_static_link:
3089 return "DW_AT_static_link";
3090 case DW_AT_type:
3091 return "DW_AT_type";
3092 case DW_AT_use_location:
3093 return "DW_AT_use_location";
3094 case DW_AT_variable_parameter:
3095 return "DW_AT_variable_parameter";
3096 case DW_AT_virtuality:
3097 return "DW_AT_virtuality";
3098 case DW_AT_vtable_elem_location:
3099 return "DW_AT_vtable_elem_location";
3101 case DW_AT_MIPS_fde:
3102 return "DW_AT_MIPS_fde";
3103 case DW_AT_MIPS_loop_begin:
3104 return "DW_AT_MIPS_loop_begin";
3105 case DW_AT_MIPS_tail_loop_begin:
3106 return "DW_AT_MIPS_tail_loop_begin";
3107 case DW_AT_MIPS_epilog_begin:
3108 return "DW_AT_MIPS_epilog_begin";
3109 case DW_AT_MIPS_loop_unroll_factor:
3110 return "DW_AT_MIPS_loop_unroll_factor";
3111 case DW_AT_MIPS_software_pipeline_depth:
3112 return "DW_AT_MIPS_software_pipeline_depth";
3113 case DW_AT_MIPS_linkage_name:
3114 return "DW_AT_MIPS_linkage_name";
3115 case DW_AT_MIPS_stride:
3116 return "DW_AT_MIPS_stride";
3117 case DW_AT_MIPS_abstract_name:
3118 return "DW_AT_MIPS_abstract_name";
3119 case DW_AT_MIPS_clone_origin:
3120 return "DW_AT_MIPS_clone_origin";
3121 case DW_AT_MIPS_has_inlines:
3122 return "DW_AT_MIPS_has_inlines";
3124 case DW_AT_sf_names:
3125 return "DW_AT_sf_names";
3126 case DW_AT_src_info:
3127 return "DW_AT_src_info";
3128 case DW_AT_mac_info:
3129 return "DW_AT_mac_info";
3130 case DW_AT_src_coords:
3131 return "DW_AT_src_coords";
3132 case DW_AT_body_begin:
3133 return "DW_AT_body_begin";
3134 case DW_AT_body_end:
3135 return "DW_AT_body_end";
3136 default:
3137 return "DW_AT_<unknown>";
3141 /* Convert a DWARF value form code into its string name. */
3143 static const char *
3144 dwarf_form_name (form)
3145 register unsigned form;
3147 switch (form)
3149 case DW_FORM_addr:
3150 return "DW_FORM_addr";
3151 case DW_FORM_block2:
3152 return "DW_FORM_block2";
3153 case DW_FORM_block4:
3154 return "DW_FORM_block4";
3155 case DW_FORM_data2:
3156 return "DW_FORM_data2";
3157 case DW_FORM_data4:
3158 return "DW_FORM_data4";
3159 case DW_FORM_data8:
3160 return "DW_FORM_data8";
3161 case DW_FORM_string:
3162 return "DW_FORM_string";
3163 case DW_FORM_block:
3164 return "DW_FORM_block";
3165 case DW_FORM_block1:
3166 return "DW_FORM_block1";
3167 case DW_FORM_data1:
3168 return "DW_FORM_data1";
3169 case DW_FORM_flag:
3170 return "DW_FORM_flag";
3171 case DW_FORM_sdata:
3172 return "DW_FORM_sdata";
3173 case DW_FORM_strp:
3174 return "DW_FORM_strp";
3175 case DW_FORM_udata:
3176 return "DW_FORM_udata";
3177 case DW_FORM_ref_addr:
3178 return "DW_FORM_ref_addr";
3179 case DW_FORM_ref1:
3180 return "DW_FORM_ref1";
3181 case DW_FORM_ref2:
3182 return "DW_FORM_ref2";
3183 case DW_FORM_ref4:
3184 return "DW_FORM_ref4";
3185 case DW_FORM_ref8:
3186 return "DW_FORM_ref8";
3187 case DW_FORM_ref_udata:
3188 return "DW_FORM_ref_udata";
3189 case DW_FORM_indirect:
3190 return "DW_FORM_indirect";
3191 default:
3192 return "DW_FORM_<unknown>";
3196 /* Convert a DWARF stack opcode into its string name. */
3198 static const char *
3199 dwarf_stack_op_name (op)
3200 register unsigned op;
3202 switch (op)
3204 case DW_OP_addr:
3205 return "DW_OP_addr";
3206 case DW_OP_deref:
3207 return "DW_OP_deref";
3208 case DW_OP_const1u:
3209 return "DW_OP_const1u";
3210 case DW_OP_const1s:
3211 return "DW_OP_const1s";
3212 case DW_OP_const2u:
3213 return "DW_OP_const2u";
3214 case DW_OP_const2s:
3215 return "DW_OP_const2s";
3216 case DW_OP_const4u:
3217 return "DW_OP_const4u";
3218 case DW_OP_const4s:
3219 return "DW_OP_const4s";
3220 case DW_OP_const8u:
3221 return "DW_OP_const8u";
3222 case DW_OP_const8s:
3223 return "DW_OP_const8s";
3224 case DW_OP_constu:
3225 return "DW_OP_constu";
3226 case DW_OP_consts:
3227 return "DW_OP_consts";
3228 case DW_OP_dup:
3229 return "DW_OP_dup";
3230 case DW_OP_drop:
3231 return "DW_OP_drop";
3232 case DW_OP_over:
3233 return "DW_OP_over";
3234 case DW_OP_pick:
3235 return "DW_OP_pick";
3236 case DW_OP_swap:
3237 return "DW_OP_swap";
3238 case DW_OP_rot:
3239 return "DW_OP_rot";
3240 case DW_OP_xderef:
3241 return "DW_OP_xderef";
3242 case DW_OP_abs:
3243 return "DW_OP_abs";
3244 case DW_OP_and:
3245 return "DW_OP_and";
3246 case DW_OP_div:
3247 return "DW_OP_div";
3248 case DW_OP_minus:
3249 return "DW_OP_minus";
3250 case DW_OP_mod:
3251 return "DW_OP_mod";
3252 case DW_OP_mul:
3253 return "DW_OP_mul";
3254 case DW_OP_neg:
3255 return "DW_OP_neg";
3256 case DW_OP_not:
3257 return "DW_OP_not";
3258 case DW_OP_or:
3259 return "DW_OP_or";
3260 case DW_OP_plus:
3261 return "DW_OP_plus";
3262 case DW_OP_plus_uconst:
3263 return "DW_OP_plus_uconst";
3264 case DW_OP_shl:
3265 return "DW_OP_shl";
3266 case DW_OP_shr:
3267 return "DW_OP_shr";
3268 case DW_OP_shra:
3269 return "DW_OP_shra";
3270 case DW_OP_xor:
3271 return "DW_OP_xor";
3272 case DW_OP_bra:
3273 return "DW_OP_bra";
3274 case DW_OP_eq:
3275 return "DW_OP_eq";
3276 case DW_OP_ge:
3277 return "DW_OP_ge";
3278 case DW_OP_gt:
3279 return "DW_OP_gt";
3280 case DW_OP_le:
3281 return "DW_OP_le";
3282 case DW_OP_lt:
3283 return "DW_OP_lt";
3284 case DW_OP_ne:
3285 return "DW_OP_ne";
3286 case DW_OP_skip:
3287 return "DW_OP_skip";
3288 case DW_OP_lit0:
3289 return "DW_OP_lit0";
3290 case DW_OP_lit1:
3291 return "DW_OP_lit1";
3292 case DW_OP_lit2:
3293 return "DW_OP_lit2";
3294 case DW_OP_lit3:
3295 return "DW_OP_lit3";
3296 case DW_OP_lit4:
3297 return "DW_OP_lit4";
3298 case DW_OP_lit5:
3299 return "DW_OP_lit5";
3300 case DW_OP_lit6:
3301 return "DW_OP_lit6";
3302 case DW_OP_lit7:
3303 return "DW_OP_lit7";
3304 case DW_OP_lit8:
3305 return "DW_OP_lit8";
3306 case DW_OP_lit9:
3307 return "DW_OP_lit9";
3308 case DW_OP_lit10:
3309 return "DW_OP_lit10";
3310 case DW_OP_lit11:
3311 return "DW_OP_lit11";
3312 case DW_OP_lit12:
3313 return "DW_OP_lit12";
3314 case DW_OP_lit13:
3315 return "DW_OP_lit13";
3316 case DW_OP_lit14:
3317 return "DW_OP_lit14";
3318 case DW_OP_lit15:
3319 return "DW_OP_lit15";
3320 case DW_OP_lit16:
3321 return "DW_OP_lit16";
3322 case DW_OP_lit17:
3323 return "DW_OP_lit17";
3324 case DW_OP_lit18:
3325 return "DW_OP_lit18";
3326 case DW_OP_lit19:
3327 return "DW_OP_lit19";
3328 case DW_OP_lit20:
3329 return "DW_OP_lit20";
3330 case DW_OP_lit21:
3331 return "DW_OP_lit21";
3332 case DW_OP_lit22:
3333 return "DW_OP_lit22";
3334 case DW_OP_lit23:
3335 return "DW_OP_lit23";
3336 case DW_OP_lit24:
3337 return "DW_OP_lit24";
3338 case DW_OP_lit25:
3339 return "DW_OP_lit25";
3340 case DW_OP_lit26:
3341 return "DW_OP_lit26";
3342 case DW_OP_lit27:
3343 return "DW_OP_lit27";
3344 case DW_OP_lit28:
3345 return "DW_OP_lit28";
3346 case DW_OP_lit29:
3347 return "DW_OP_lit29";
3348 case DW_OP_lit30:
3349 return "DW_OP_lit30";
3350 case DW_OP_lit31:
3351 return "DW_OP_lit31";
3352 case DW_OP_reg0:
3353 return "DW_OP_reg0";
3354 case DW_OP_reg1:
3355 return "DW_OP_reg1";
3356 case DW_OP_reg2:
3357 return "DW_OP_reg2";
3358 case DW_OP_reg3:
3359 return "DW_OP_reg3";
3360 case DW_OP_reg4:
3361 return "DW_OP_reg4";
3362 case DW_OP_reg5:
3363 return "DW_OP_reg5";
3364 case DW_OP_reg6:
3365 return "DW_OP_reg6";
3366 case DW_OP_reg7:
3367 return "DW_OP_reg7";
3368 case DW_OP_reg8:
3369 return "DW_OP_reg8";
3370 case DW_OP_reg9:
3371 return "DW_OP_reg9";
3372 case DW_OP_reg10:
3373 return "DW_OP_reg10";
3374 case DW_OP_reg11:
3375 return "DW_OP_reg11";
3376 case DW_OP_reg12:
3377 return "DW_OP_reg12";
3378 case DW_OP_reg13:
3379 return "DW_OP_reg13";
3380 case DW_OP_reg14:
3381 return "DW_OP_reg14";
3382 case DW_OP_reg15:
3383 return "DW_OP_reg15";
3384 case DW_OP_reg16:
3385 return "DW_OP_reg16";
3386 case DW_OP_reg17:
3387 return "DW_OP_reg17";
3388 case DW_OP_reg18:
3389 return "DW_OP_reg18";
3390 case DW_OP_reg19:
3391 return "DW_OP_reg19";
3392 case DW_OP_reg20:
3393 return "DW_OP_reg20";
3394 case DW_OP_reg21:
3395 return "DW_OP_reg21";
3396 case DW_OP_reg22:
3397 return "DW_OP_reg22";
3398 case DW_OP_reg23:
3399 return "DW_OP_reg23";
3400 case DW_OP_reg24:
3401 return "DW_OP_reg24";
3402 case DW_OP_reg25:
3403 return "DW_OP_reg25";
3404 case DW_OP_reg26:
3405 return "DW_OP_reg26";
3406 case DW_OP_reg27:
3407 return "DW_OP_reg27";
3408 case DW_OP_reg28:
3409 return "DW_OP_reg28";
3410 case DW_OP_reg29:
3411 return "DW_OP_reg29";
3412 case DW_OP_reg30:
3413 return "DW_OP_reg30";
3414 case DW_OP_reg31:
3415 return "DW_OP_reg31";
3416 case DW_OP_breg0:
3417 return "DW_OP_breg0";
3418 case DW_OP_breg1:
3419 return "DW_OP_breg1";
3420 case DW_OP_breg2:
3421 return "DW_OP_breg2";
3422 case DW_OP_breg3:
3423 return "DW_OP_breg3";
3424 case DW_OP_breg4:
3425 return "DW_OP_breg4";
3426 case DW_OP_breg5:
3427 return "DW_OP_breg5";
3428 case DW_OP_breg6:
3429 return "DW_OP_breg6";
3430 case DW_OP_breg7:
3431 return "DW_OP_breg7";
3432 case DW_OP_breg8:
3433 return "DW_OP_breg8";
3434 case DW_OP_breg9:
3435 return "DW_OP_breg9";
3436 case DW_OP_breg10:
3437 return "DW_OP_breg10";
3438 case DW_OP_breg11:
3439 return "DW_OP_breg11";
3440 case DW_OP_breg12:
3441 return "DW_OP_breg12";
3442 case DW_OP_breg13:
3443 return "DW_OP_breg13";
3444 case DW_OP_breg14:
3445 return "DW_OP_breg14";
3446 case DW_OP_breg15:
3447 return "DW_OP_breg15";
3448 case DW_OP_breg16:
3449 return "DW_OP_breg16";
3450 case DW_OP_breg17:
3451 return "DW_OP_breg17";
3452 case DW_OP_breg18:
3453 return "DW_OP_breg18";
3454 case DW_OP_breg19:
3455 return "DW_OP_breg19";
3456 case DW_OP_breg20:
3457 return "DW_OP_breg20";
3458 case DW_OP_breg21:
3459 return "DW_OP_breg21";
3460 case DW_OP_breg22:
3461 return "DW_OP_breg22";
3462 case DW_OP_breg23:
3463 return "DW_OP_breg23";
3464 case DW_OP_breg24:
3465 return "DW_OP_breg24";
3466 case DW_OP_breg25:
3467 return "DW_OP_breg25";
3468 case DW_OP_breg26:
3469 return "DW_OP_breg26";
3470 case DW_OP_breg27:
3471 return "DW_OP_breg27";
3472 case DW_OP_breg28:
3473 return "DW_OP_breg28";
3474 case DW_OP_breg29:
3475 return "DW_OP_breg29";
3476 case DW_OP_breg30:
3477 return "DW_OP_breg30";
3478 case DW_OP_breg31:
3479 return "DW_OP_breg31";
3480 case DW_OP_regx:
3481 return "DW_OP_regx";
3482 case DW_OP_fbreg:
3483 return "DW_OP_fbreg";
3484 case DW_OP_bregx:
3485 return "DW_OP_bregx";
3486 case DW_OP_piece:
3487 return "DW_OP_piece";
3488 case DW_OP_deref_size:
3489 return "DW_OP_deref_size";
3490 case DW_OP_xderef_size:
3491 return "DW_OP_xderef_size";
3492 case DW_OP_nop:
3493 return "DW_OP_nop";
3494 default:
3495 return "OP_<unknown>";
3499 /* Convert a DWARF type code into its string name. */
3501 #if 0
3502 static const char *
3503 dwarf_type_encoding_name (enc)
3504 register unsigned enc;
3506 switch (enc)
3508 case DW_ATE_address:
3509 return "DW_ATE_address";
3510 case DW_ATE_boolean:
3511 return "DW_ATE_boolean";
3512 case DW_ATE_complex_float:
3513 return "DW_ATE_complex_float";
3514 case DW_ATE_float:
3515 return "DW_ATE_float";
3516 case DW_ATE_signed:
3517 return "DW_ATE_signed";
3518 case DW_ATE_signed_char:
3519 return "DW_ATE_signed_char";
3520 case DW_ATE_unsigned:
3521 return "DW_ATE_unsigned";
3522 case DW_ATE_unsigned_char:
3523 return "DW_ATE_unsigned_char";
3524 default:
3525 return "DW_ATE_<unknown>";
3528 #endif
3530 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3531 instance of an inlined instance of a decl which is local to an inline
3532 function, so we have to trace all of the way back through the origin chain
3533 to find out what sort of node actually served as the original seed for the
3534 given block. */
3536 static tree
3537 decl_ultimate_origin (decl)
3538 register tree decl;
3540 #ifdef ENABLE_CHECKING
3541 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
3542 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3543 most distant ancestor, this should never happen. */
3544 abort ();
3545 #endif
3547 return DECL_ABSTRACT_ORIGIN (decl);
3550 /* Determine the "ultimate origin" of a block. The block may be an inlined
3551 instance of an inlined instance of a block which is local to an inline
3552 function, so we have to trace all of the way back through the origin chain
3553 to find out what sort of node actually served as the original seed for the
3554 given block. */
3556 static tree
3557 block_ultimate_origin (block)
3558 register tree block;
3560 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3562 if (immediate_origin == NULL_TREE)
3563 return NULL_TREE;
3564 else
3566 register tree ret_val;
3567 register tree lookahead = immediate_origin;
3571 ret_val = lookahead;
3572 lookahead = (TREE_CODE (ret_val) == BLOCK)
3573 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3574 : NULL;
3576 while (lookahead != NULL && lookahead != ret_val);
3578 return ret_val;
3582 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3583 of a virtual function may refer to a base class, so we check the 'this'
3584 parameter. */
3586 static tree
3587 decl_class_context (decl)
3588 tree decl;
3590 tree context = NULL_TREE;
3592 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3593 context = DECL_CONTEXT (decl);
3594 else
3595 context = TYPE_MAIN_VARIANT
3596 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3598 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
3599 context = NULL_TREE;
3601 return context;
3604 /* Add an attribute/value pair to a DIE */
3606 static inline void
3607 add_dwarf_attr (die, attr)
3608 register dw_die_ref die;
3609 register dw_attr_ref attr;
3611 if (die != NULL && attr != NULL)
3613 if (die->die_attr == NULL)
3615 die->die_attr = attr;
3616 die->die_attr_last = attr;
3618 else
3620 die->die_attr_last->dw_attr_next = attr;
3621 die->die_attr_last = attr;
3626 /* Add a flag value attribute to a DIE. */
3628 static inline void
3629 add_AT_flag (die, attr_kind, flag)
3630 register dw_die_ref die;
3631 register enum dwarf_attribute attr_kind;
3632 register unsigned flag;
3634 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3636 attr->dw_attr_next = NULL;
3637 attr->dw_attr = attr_kind;
3638 attr->dw_attr_val.val_class = dw_val_class_flag;
3639 attr->dw_attr_val.v.val_flag = flag;
3640 add_dwarf_attr (die, attr);
3643 /* Add a signed integer attribute value to a DIE. */
3645 static inline void
3646 add_AT_int (die, attr_kind, int_val)
3647 register dw_die_ref die;
3648 register enum dwarf_attribute attr_kind;
3649 register long int int_val;
3651 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3653 attr->dw_attr_next = NULL;
3654 attr->dw_attr = attr_kind;
3655 attr->dw_attr_val.val_class = dw_val_class_const;
3656 attr->dw_attr_val.v.val_int = int_val;
3657 add_dwarf_attr (die, attr);
3660 /* Add an unsigned integer attribute value to a DIE. */
3662 static inline void
3663 add_AT_unsigned (die, attr_kind, unsigned_val)
3664 register dw_die_ref die;
3665 register enum dwarf_attribute attr_kind;
3666 register unsigned long unsigned_val;
3668 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3670 attr->dw_attr_next = NULL;
3671 attr->dw_attr = attr_kind;
3672 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
3673 attr->dw_attr_val.v.val_unsigned = unsigned_val;
3674 add_dwarf_attr (die, attr);
3677 /* Add an unsigned double integer attribute value to a DIE. */
3679 static inline void
3680 add_AT_long_long (die, attr_kind, val_hi, val_low)
3681 register dw_die_ref die;
3682 register enum dwarf_attribute attr_kind;
3683 register unsigned long val_hi;
3684 register unsigned long val_low;
3686 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3688 attr->dw_attr_next = NULL;
3689 attr->dw_attr = attr_kind;
3690 attr->dw_attr_val.val_class = dw_val_class_long_long;
3691 attr->dw_attr_val.v.val_long_long.hi = val_hi;
3692 attr->dw_attr_val.v.val_long_long.low = val_low;
3693 add_dwarf_attr (die, attr);
3696 /* Add a floating point attribute value to a DIE and return it. */
3698 static inline void
3699 add_AT_float (die, attr_kind, length, array)
3700 register dw_die_ref die;
3701 register enum dwarf_attribute attr_kind;
3702 register unsigned length;
3703 register long *array;
3705 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3707 attr->dw_attr_next = NULL;
3708 attr->dw_attr = attr_kind;
3709 attr->dw_attr_val.val_class = dw_val_class_float;
3710 attr->dw_attr_val.v.val_float.length = length;
3711 attr->dw_attr_val.v.val_float.array = array;
3712 add_dwarf_attr (die, attr);
3715 /* Add a string attribute value to a DIE. */
3717 static inline void
3718 add_AT_string (die, attr_kind, str)
3719 register dw_die_ref die;
3720 register enum dwarf_attribute attr_kind;
3721 register const char *str;
3723 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3725 attr->dw_attr_next = NULL;
3726 attr->dw_attr = attr_kind;
3727 attr->dw_attr_val.val_class = dw_val_class_str;
3728 attr->dw_attr_val.v.val_str = xstrdup (str);
3729 add_dwarf_attr (die, attr);
3732 /* Add a DIE reference attribute value to a DIE. */
3734 static inline void
3735 add_AT_die_ref (die, attr_kind, targ_die)
3736 register dw_die_ref die;
3737 register enum dwarf_attribute attr_kind;
3738 register dw_die_ref targ_die;
3740 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3742 attr->dw_attr_next = NULL;
3743 attr->dw_attr = attr_kind;
3744 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3745 attr->dw_attr_val.v.val_die_ref = targ_die;
3746 add_dwarf_attr (die, attr);
3749 /* Add an FDE reference attribute value to a DIE. */
3751 static inline void
3752 add_AT_fde_ref (die, attr_kind, targ_fde)
3753 register dw_die_ref die;
3754 register enum dwarf_attribute attr_kind;
3755 register unsigned targ_fde;
3757 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3759 attr->dw_attr_next = NULL;
3760 attr->dw_attr = attr_kind;
3761 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
3762 attr->dw_attr_val.v.val_fde_index = targ_fde;
3763 add_dwarf_attr (die, attr);
3766 /* Add a location description attribute value to a DIE. */
3768 static inline void
3769 add_AT_loc (die, attr_kind, loc)
3770 register dw_die_ref die;
3771 register enum dwarf_attribute attr_kind;
3772 register dw_loc_descr_ref loc;
3774 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3776 attr->dw_attr_next = NULL;
3777 attr->dw_attr = attr_kind;
3778 attr->dw_attr_val.val_class = dw_val_class_loc;
3779 attr->dw_attr_val.v.val_loc = loc;
3780 add_dwarf_attr (die, attr);
3783 /* Add an address constant attribute value to a DIE. */
3785 static inline void
3786 add_AT_addr (die, attr_kind, addr)
3787 register dw_die_ref die;
3788 register enum dwarf_attribute attr_kind;
3789 char *addr;
3791 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3793 attr->dw_attr_next = NULL;
3794 attr->dw_attr = attr_kind;
3795 attr->dw_attr_val.val_class = dw_val_class_addr;
3796 attr->dw_attr_val.v.val_addr = addr;
3797 add_dwarf_attr (die, attr);
3800 /* Add a label identifier attribute value to a DIE. */
3802 static inline void
3803 add_AT_lbl_id (die, attr_kind, lbl_id)
3804 register dw_die_ref die;
3805 register enum dwarf_attribute attr_kind;
3806 register char *lbl_id;
3808 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3810 attr->dw_attr_next = NULL;
3811 attr->dw_attr = attr_kind;
3812 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
3813 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
3814 add_dwarf_attr (die, attr);
3817 /* Add a section offset attribute value to a DIE. */
3819 static inline void
3820 add_AT_lbl_offset (die, attr_kind, label)
3821 register dw_die_ref die;
3822 register enum dwarf_attribute attr_kind;
3823 register char *label;
3825 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3827 attr->dw_attr_next = NULL;
3828 attr->dw_attr = attr_kind;
3829 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
3830 attr->dw_attr_val.v.val_lbl_id = label;
3831 add_dwarf_attr (die, attr);
3835 /* Test if die refers to an external subroutine. */
3837 static inline int
3838 is_extern_subr_die (die)
3839 register dw_die_ref die;
3841 register dw_attr_ref a;
3842 register int is_subr = FALSE;
3843 register int is_extern = FALSE;
3845 if (die != NULL && die->die_tag == DW_TAG_subprogram)
3847 is_subr = TRUE;
3848 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3850 if (a->dw_attr == DW_AT_external
3851 && a->dw_attr_val.val_class == dw_val_class_flag
3852 && a->dw_attr_val.v.val_flag != 0)
3854 is_extern = TRUE;
3855 break;
3860 return is_subr && is_extern;
3863 /* Get the attribute of type attr_kind. */
3865 static inline dw_attr_ref
3866 get_AT (die, attr_kind)
3867 register dw_die_ref die;
3868 register enum dwarf_attribute attr_kind;
3870 register dw_attr_ref a;
3871 register dw_die_ref spec = NULL;
3873 if (die != NULL)
3875 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3877 if (a->dw_attr == attr_kind)
3878 return a;
3880 if (a->dw_attr == DW_AT_specification
3881 || a->dw_attr == DW_AT_abstract_origin)
3882 spec = a->dw_attr_val.v.val_die_ref;
3885 if (spec)
3886 return get_AT (spec, attr_kind);
3889 return NULL;
3892 /* Return the "low pc" attribute value, typically associated with
3893 a subprogram DIE. Return null if the "low pc" attribute is
3894 either not prsent, or if it cannot be represented as an
3895 assembler label identifier. */
3897 static inline char *
3898 get_AT_low_pc (die)
3899 register dw_die_ref die;
3901 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
3903 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3904 return a->dw_attr_val.v.val_lbl_id;
3906 return NULL;
3909 /* Return the "high pc" attribute value, typically associated with
3910 a subprogram DIE. Return null if the "high pc" attribute is
3911 either not prsent, or if it cannot be represented as an
3912 assembler label identifier. */
3914 static inline char *
3915 get_AT_hi_pc (die)
3916 register dw_die_ref die;
3918 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
3920 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3921 return a->dw_attr_val.v.val_lbl_id;
3923 return NULL;
3926 /* Return the value of the string attribute designated by ATTR_KIND, or
3927 NULL if it is not present. */
3929 static inline char *
3930 get_AT_string (die, attr_kind)
3931 register dw_die_ref die;
3932 register enum dwarf_attribute attr_kind;
3934 register dw_attr_ref a = get_AT (die, attr_kind);
3936 if (a && a->dw_attr_val.val_class == dw_val_class_str)
3937 return a->dw_attr_val.v.val_str;
3939 return NULL;
3942 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3943 if it is not present. */
3945 static inline int
3946 get_AT_flag (die, attr_kind)
3947 register dw_die_ref die;
3948 register enum dwarf_attribute attr_kind;
3950 register dw_attr_ref a = get_AT (die, attr_kind);
3952 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
3953 return a->dw_attr_val.v.val_flag;
3955 return -1;
3958 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3959 if it is not present. */
3961 static inline unsigned
3962 get_AT_unsigned (die, attr_kind)
3963 register dw_die_ref die;
3964 register enum dwarf_attribute attr_kind;
3966 register dw_attr_ref a = get_AT (die, attr_kind);
3968 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
3969 return a->dw_attr_val.v.val_unsigned;
3971 return 0;
3974 static inline int
3975 is_c_family ()
3977 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3979 return (lang == DW_LANG_C || lang == DW_LANG_C89
3980 || lang == DW_LANG_C_plus_plus);
3983 static inline int
3984 is_fortran ()
3986 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3988 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3991 /* Remove the specified attribute if present. */
3993 static inline void
3994 remove_AT (die, attr_kind)
3995 register dw_die_ref die;
3996 register enum dwarf_attribute attr_kind;
3998 register dw_attr_ref a;
3999 register dw_attr_ref removed = NULL;
4001 if (die != NULL)
4003 if (die->die_attr->dw_attr == attr_kind)
4005 removed = die->die_attr;
4006 if (die->die_attr_last == die->die_attr)
4007 die->die_attr_last = NULL;
4009 die->die_attr = die->die_attr->dw_attr_next;
4012 else
4013 for (a = die->die_attr; a->dw_attr_next != NULL;
4014 a = a->dw_attr_next)
4015 if (a->dw_attr_next->dw_attr == attr_kind)
4017 removed = a->dw_attr_next;
4018 if (die->die_attr_last == a->dw_attr_next)
4019 die->die_attr_last = a;
4021 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
4022 break;
4025 if (removed != 0)
4026 free (removed);
4030 /* Discard the children of this DIE. */
4032 static inline void
4033 remove_children (die)
4034 register dw_die_ref die;
4036 register dw_die_ref child_die = die->die_child;
4038 die->die_child = NULL;
4039 die->die_child_last = NULL;
4041 while (child_die != NULL)
4043 register dw_die_ref tmp_die = child_die;
4044 register dw_attr_ref a;
4046 child_die = child_die->die_sib;
4048 for (a = tmp_die->die_attr; a != NULL; )
4050 register dw_attr_ref tmp_a = a;
4052 a = a->dw_attr_next;
4053 free (tmp_a);
4056 free (tmp_die);
4060 /* Add a child DIE below its parent. */
4062 static inline void
4063 add_child_die (die, child_die)
4064 register dw_die_ref die;
4065 register dw_die_ref child_die;
4067 if (die != NULL && child_die != NULL)
4069 if (die == child_die)
4070 abort ();
4071 child_die->die_parent = die;
4072 child_die->die_sib = NULL;
4074 if (die->die_child == NULL)
4076 die->die_child = child_die;
4077 die->die_child_last = child_die;
4079 else
4081 die->die_child_last->die_sib = child_die;
4082 die->die_child_last = child_die;
4087 /* Return a pointer to a newly created DIE node. */
4089 static inline dw_die_ref
4090 new_die (tag_value, parent_die)
4091 register enum dwarf_tag tag_value;
4092 register dw_die_ref parent_die;
4094 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4096 die->die_tag = tag_value;
4097 die->die_abbrev = 0;
4098 die->die_offset = 0;
4099 die->die_child = NULL;
4100 die->die_parent = NULL;
4101 die->die_sib = NULL;
4102 die->die_child_last = NULL;
4103 die->die_attr = NULL;
4104 die->die_attr_last = NULL;
4106 if (parent_die != NULL)
4107 add_child_die (parent_die, die);
4108 else
4110 limbo_die_node *limbo_node;
4112 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4113 limbo_node->die = die;
4114 limbo_node->next = limbo_die_list;
4115 limbo_die_list = limbo_node;
4118 return die;
4121 /* Return the DIE associated with the given type specifier. */
4123 static inline dw_die_ref
4124 lookup_type_die (type)
4125 register tree type;
4127 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4130 /* Equate a DIE to a given type specifier. */
4132 static void
4133 equate_type_number_to_die (type, type_die)
4134 register tree type;
4135 register dw_die_ref type_die;
4137 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4140 /* Return the DIE associated with a given declaration. */
4142 static inline dw_die_ref
4143 lookup_decl_die (decl)
4144 register tree decl;
4146 register unsigned decl_id = DECL_UID (decl);
4148 return (decl_id < decl_die_table_in_use
4149 ? decl_die_table[decl_id] : NULL);
4152 /* Equate a DIE to a particular declaration. */
4154 static void
4155 equate_decl_number_to_die (decl, decl_die)
4156 register tree decl;
4157 register dw_die_ref decl_die;
4159 register unsigned decl_id = DECL_UID (decl);
4160 register unsigned num_allocated;
4162 if (decl_id >= decl_die_table_allocated)
4164 num_allocated
4165 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4166 / DECL_DIE_TABLE_INCREMENT)
4167 * DECL_DIE_TABLE_INCREMENT;
4169 decl_die_table
4170 = (dw_die_ref *) xrealloc (decl_die_table,
4171 sizeof (dw_die_ref) * num_allocated);
4173 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4174 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4175 decl_die_table_allocated = num_allocated;
4178 if (decl_id >= decl_die_table_in_use)
4179 decl_die_table_in_use = (decl_id + 1);
4181 decl_die_table[decl_id] = decl_die;
4184 /* Return a pointer to a newly allocated location description. Location
4185 descriptions are simple expression terms that can be strung
4186 together to form more complicated location (address) descriptions. */
4188 static inline dw_loc_descr_ref
4189 new_loc_descr (op, oprnd1, oprnd2)
4190 register enum dwarf_location_atom op;
4191 register unsigned long oprnd1;
4192 register unsigned long oprnd2;
4194 register dw_loc_descr_ref descr
4195 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
4197 descr->dw_loc_next = NULL;
4198 descr->dw_loc_opc = op;
4199 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4200 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4201 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4202 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4204 return descr;
4207 /* Add a location description term to a location description expression. */
4209 static inline void
4210 add_loc_descr (list_head, descr)
4211 register dw_loc_descr_ref *list_head;
4212 register dw_loc_descr_ref descr;
4214 register dw_loc_descr_ref *d;
4216 /* Find the end of the chain. */
4217 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4220 *d = descr;
4223 /* Keep track of the number of spaces used to indent the
4224 output of the debugging routines that print the structure of
4225 the DIE internal representation. */
4226 static int print_indent;
4228 /* Indent the line the number of spaces given by print_indent. */
4230 static inline void
4231 print_spaces (outfile)
4232 FILE *outfile;
4234 fprintf (outfile, "%*s", print_indent, "");
4237 /* Print the information associated with a given DIE, and its children.
4238 This routine is a debugging aid only. */
4240 static void
4241 print_die (die, outfile)
4242 dw_die_ref die;
4243 FILE *outfile;
4245 register dw_attr_ref a;
4246 register dw_die_ref c;
4248 print_spaces (outfile);
4249 fprintf (outfile, "DIE %4lu: %s\n",
4250 die->die_offset, dwarf_tag_name (die->die_tag));
4251 print_spaces (outfile);
4252 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4253 fprintf (outfile, " offset: %lu\n", die->die_offset);
4255 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4257 print_spaces (outfile);
4258 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4260 switch (a->dw_attr_val.val_class)
4262 case dw_val_class_addr:
4263 fprintf (outfile, "address");
4264 break;
4265 case dw_val_class_loc:
4266 fprintf (outfile, "location descriptor");
4267 break;
4268 case dw_val_class_const:
4269 fprintf (outfile, "%ld", a->dw_attr_val.v.val_int);
4270 break;
4271 case dw_val_class_unsigned_const:
4272 fprintf (outfile, "%lu", a->dw_attr_val.v.val_unsigned);
4273 break;
4274 case dw_val_class_long_long:
4275 fprintf (outfile, "constant (%lu,%lu)",
4276 a->dw_attr_val.v.val_long_long.hi,
4277 a->dw_attr_val.v.val_long_long.low);
4278 break;
4279 case dw_val_class_float:
4280 fprintf (outfile, "floating-point constant");
4281 break;
4282 case dw_val_class_flag:
4283 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
4284 break;
4285 case dw_val_class_die_ref:
4286 if (a->dw_attr_val.v.val_die_ref != NULL)
4287 fprintf (outfile, "die -> %lu",
4288 a->dw_attr_val.v.val_die_ref->die_offset);
4289 else
4290 fprintf (outfile, "die -> <null>");
4291 break;
4292 case dw_val_class_lbl_id:
4293 case dw_val_class_lbl_offset:
4294 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
4295 break;
4296 case dw_val_class_str:
4297 if (a->dw_attr_val.v.val_str != NULL)
4298 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
4299 else
4300 fprintf (outfile, "<null>");
4301 break;
4302 default:
4303 break;
4306 fprintf (outfile, "\n");
4309 if (die->die_child != NULL)
4311 print_indent += 4;
4312 for (c = die->die_child; c != NULL; c = c->die_sib)
4313 print_die (c, outfile);
4315 print_indent -= 4;
4319 /* Print the contents of the source code line number correspondence table.
4320 This routine is a debugging aid only. */
4322 static void
4323 print_dwarf_line_table (outfile)
4324 FILE *outfile;
4326 register unsigned i;
4327 register dw_line_info_ref line_info;
4329 fprintf (outfile, "\n\nDWARF source line information\n");
4330 for (i = 1; i < line_info_table_in_use; ++i)
4332 line_info = &line_info_table[i];
4333 fprintf (outfile, "%5d: ", i);
4334 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4335 fprintf (outfile, "%6ld", line_info->dw_line_num);
4336 fprintf (outfile, "\n");
4339 fprintf (outfile, "\n\n");
4342 /* Print the information collected for a given DIE. */
4344 void
4345 debug_dwarf_die (die)
4346 dw_die_ref die;
4348 print_die (die, stderr);
4351 /* Print all DWARF information collected for the compilation unit.
4352 This routine is a debugging aid only. */
4354 void
4355 debug_dwarf ()
4357 print_indent = 0;
4358 print_die (comp_unit_die, stderr);
4359 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4360 print_dwarf_line_table (stderr);
4363 /* Traverse the DIE, and add a sibling attribute if it may have the
4364 effect of speeding up access to siblings. To save some space,
4365 avoid generating sibling attributes for DIE's without children. */
4367 static void
4368 add_sibling_attributes(die)
4369 register dw_die_ref die;
4371 register dw_die_ref c;
4372 register dw_attr_ref attr;
4373 if (die != comp_unit_die && die->die_child != NULL)
4375 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4376 attr->dw_attr_next = NULL;
4377 attr->dw_attr = DW_AT_sibling;
4378 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4379 attr->dw_attr_val.v.val_die_ref = die->die_sib;
4381 /* Add the sibling link to the front of the attribute list. */
4382 attr->dw_attr_next = die->die_attr;
4383 if (die->die_attr == NULL)
4384 die->die_attr_last = attr;
4386 die->die_attr = attr;
4389 for (c = die->die_child; c != NULL; c = c->die_sib)
4390 add_sibling_attributes (c);
4393 /* The format of each DIE (and its attribute value pairs)
4394 is encoded in an abbreviation table. This routine builds the
4395 abbreviation table and assigns a unique abbreviation id for
4396 each abbreviation entry. The children of each die are visited
4397 recursively. */
4399 static void
4400 build_abbrev_table (die)
4401 register dw_die_ref die;
4403 register unsigned long abbrev_id;
4404 register unsigned long n_alloc;
4405 register dw_die_ref c;
4406 register dw_attr_ref d_attr, a_attr;
4407 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4409 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4411 if (abbrev->die_tag == die->die_tag)
4413 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
4415 a_attr = abbrev->die_attr;
4416 d_attr = die->die_attr;
4418 while (a_attr != NULL && d_attr != NULL)
4420 if ((a_attr->dw_attr != d_attr->dw_attr)
4421 || (value_format (&a_attr->dw_attr_val)
4422 != value_format (&d_attr->dw_attr_val)))
4423 break;
4425 a_attr = a_attr->dw_attr_next;
4426 d_attr = d_attr->dw_attr_next;
4429 if (a_attr == NULL && d_attr == NULL)
4430 break;
4435 if (abbrev_id >= abbrev_die_table_in_use)
4437 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
4439 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
4440 abbrev_die_table
4441 = (dw_die_ref *) xrealloc (abbrev_die_table,
4442 sizeof (dw_die_ref) * n_alloc);
4444 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
4445 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
4446 abbrev_die_table_allocated = n_alloc;
4449 ++abbrev_die_table_in_use;
4450 abbrev_die_table[abbrev_id] = die;
4453 die->die_abbrev = abbrev_id;
4454 for (c = die->die_child; c != NULL; c = c->die_sib)
4455 build_abbrev_table (c);
4458 /* Return the size of a string, including the null byte.
4460 This used to treat backslashes as escapes, and hence they were not included
4461 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
4462 which treats a backslash as a backslash, escaping it if necessary, and hence
4463 we must include them in the count. */
4465 static unsigned long
4466 size_of_string (str)
4467 register char *str;
4469 return strlen (str) + 1;
4472 /* Return the size of a location descriptor. */
4474 static unsigned long
4475 size_of_loc_descr (loc)
4476 register dw_loc_descr_ref loc;
4478 register unsigned long size = 1;
4480 switch (loc->dw_loc_opc)
4482 case DW_OP_addr:
4483 size += PTR_SIZE;
4484 break;
4485 case DW_OP_const1u:
4486 case DW_OP_const1s:
4487 size += 1;
4488 break;
4489 case DW_OP_const2u:
4490 case DW_OP_const2s:
4491 size += 2;
4492 break;
4493 case DW_OP_const4u:
4494 case DW_OP_const4s:
4495 size += 4;
4496 break;
4497 case DW_OP_const8u:
4498 case DW_OP_const8s:
4499 size += 8;
4500 break;
4501 case DW_OP_constu:
4502 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4503 break;
4504 case DW_OP_consts:
4505 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4506 break;
4507 case DW_OP_pick:
4508 size += 1;
4509 break;
4510 case DW_OP_plus_uconst:
4511 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4512 break;
4513 case DW_OP_skip:
4514 case DW_OP_bra:
4515 size += 2;
4516 break;
4517 case DW_OP_breg0:
4518 case DW_OP_breg1:
4519 case DW_OP_breg2:
4520 case DW_OP_breg3:
4521 case DW_OP_breg4:
4522 case DW_OP_breg5:
4523 case DW_OP_breg6:
4524 case DW_OP_breg7:
4525 case DW_OP_breg8:
4526 case DW_OP_breg9:
4527 case DW_OP_breg10:
4528 case DW_OP_breg11:
4529 case DW_OP_breg12:
4530 case DW_OP_breg13:
4531 case DW_OP_breg14:
4532 case DW_OP_breg15:
4533 case DW_OP_breg16:
4534 case DW_OP_breg17:
4535 case DW_OP_breg18:
4536 case DW_OP_breg19:
4537 case DW_OP_breg20:
4538 case DW_OP_breg21:
4539 case DW_OP_breg22:
4540 case DW_OP_breg23:
4541 case DW_OP_breg24:
4542 case DW_OP_breg25:
4543 case DW_OP_breg26:
4544 case DW_OP_breg27:
4545 case DW_OP_breg28:
4546 case DW_OP_breg29:
4547 case DW_OP_breg30:
4548 case DW_OP_breg31:
4549 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4550 break;
4551 case DW_OP_regx:
4552 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4553 break;
4554 case DW_OP_fbreg:
4555 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4556 break;
4557 case DW_OP_bregx:
4558 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4559 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4560 break;
4561 case DW_OP_piece:
4562 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4563 break;
4564 case DW_OP_deref_size:
4565 case DW_OP_xderef_size:
4566 size += 1;
4567 break;
4568 default:
4569 break;
4572 return size;
4575 /* Return the size of a series of location descriptors. */
4577 static unsigned long
4578 size_of_locs (loc)
4579 register dw_loc_descr_ref loc;
4581 register unsigned long size = 0;
4583 for (; loc != NULL; loc = loc->dw_loc_next)
4584 size += size_of_loc_descr (loc);
4586 return size;
4589 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4591 static int
4592 constant_size (value)
4593 long unsigned value;
4595 int log;
4597 if (value == 0)
4598 log = 0;
4599 else
4600 log = floor_log2 (value);
4602 log = log / 8;
4603 log = 1 << (floor_log2 (log) + 1);
4605 return log;
4608 /* Return the size of a DIE, as it is represented in the
4609 .debug_info section. */
4611 static unsigned long
4612 size_of_die (die)
4613 register dw_die_ref die;
4615 register unsigned long size = 0;
4616 register dw_attr_ref a;
4618 size += size_of_uleb128 (die->die_abbrev);
4619 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4621 switch (a->dw_attr_val.val_class)
4623 case dw_val_class_addr:
4624 size += PTR_SIZE;
4625 break;
4626 case dw_val_class_loc:
4628 register unsigned long lsize
4629 = size_of_locs (a->dw_attr_val.v.val_loc);
4631 /* Block length. */
4632 size += constant_size (lsize);
4633 size += lsize;
4635 break;
4636 case dw_val_class_const:
4637 size += 4;
4638 break;
4639 case dw_val_class_unsigned_const:
4640 size += constant_size (a->dw_attr_val.v.val_unsigned);
4641 break;
4642 case dw_val_class_long_long:
4643 size += 1 + 8; /* block */
4644 break;
4645 case dw_val_class_float:
4646 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
4647 break;
4648 case dw_val_class_flag:
4649 size += 1;
4650 break;
4651 case dw_val_class_die_ref:
4652 size += DWARF_OFFSET_SIZE;
4653 break;
4654 case dw_val_class_fde_ref:
4655 size += DWARF_OFFSET_SIZE;
4656 break;
4657 case dw_val_class_lbl_id:
4658 size += PTR_SIZE;
4659 break;
4660 case dw_val_class_lbl_offset:
4661 size += DWARF_OFFSET_SIZE;
4662 break;
4663 case dw_val_class_str:
4664 size += size_of_string (a->dw_attr_val.v.val_str);
4665 break;
4666 default:
4667 abort ();
4671 return size;
4674 /* Size the debugging information associated with a given DIE.
4675 Visits the DIE's children recursively. Updates the global
4676 variable next_die_offset, on each time through. Uses the
4677 current value of next_die_offset to update the die_offset
4678 field in each DIE. */
4680 static void
4681 calc_die_sizes (die)
4682 dw_die_ref die;
4684 register dw_die_ref c;
4685 die->die_offset = next_die_offset;
4686 next_die_offset += size_of_die (die);
4688 for (c = die->die_child; c != NULL; c = c->die_sib)
4689 calc_die_sizes (c);
4691 if (die->die_child != NULL)
4692 /* Count the null byte used to terminate sibling lists. */
4693 next_die_offset += 1;
4696 /* Return the size of the line information prolog generated for the
4697 compilation unit. */
4699 static unsigned long
4700 size_of_line_prolog ()
4702 register unsigned long size;
4703 register unsigned long ft_index;
4705 size = DWARF_LINE_PROLOG_HEADER_SIZE;
4707 /* Count the size of the table giving number of args for each
4708 standard opcode. */
4709 size += DWARF_LINE_OPCODE_BASE - 1;
4711 /* Include directory table is empty (at present). Count only the
4712 null byte used to terminate the table. */
4713 size += 1;
4715 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4717 /* File name entry. */
4718 size += size_of_string (file_table[ft_index]);
4720 /* Include directory index. */
4721 size += size_of_uleb128 (0);
4723 /* Modification time. */
4724 size += size_of_uleb128 (0);
4726 /* File length in bytes. */
4727 size += size_of_uleb128 (0);
4730 /* Count the file table terminator. */
4731 size += 1;
4732 return size;
4735 /* Return the size of the .debug_pubnames table generated for the
4736 compilation unit. */
4738 static unsigned long
4739 size_of_pubnames ()
4741 register unsigned long size;
4742 register unsigned i;
4744 size = DWARF_PUBNAMES_HEADER_SIZE;
4745 for (i = 0; i < pubname_table_in_use; ++i)
4747 register pubname_ref p = &pubname_table[i];
4748 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
4751 size += DWARF_OFFSET_SIZE;
4752 return size;
4755 /* Return the size of the information in the .debug_aranges section. */
4757 static unsigned long
4758 size_of_aranges ()
4760 register unsigned long size;
4762 size = DWARF_ARANGES_HEADER_SIZE;
4764 /* Count the address/length pair for this compilation unit. */
4765 size += 2 * PTR_SIZE;
4766 size += 2 * PTR_SIZE * arange_table_in_use;
4768 /* Count the two zero words used to terminated the address range table. */
4769 size += 2 * PTR_SIZE;
4770 return size;
4773 /* Select the encoding of an attribute value. */
4775 static enum dwarf_form
4776 value_format (v)
4777 dw_val_ref v;
4779 switch (v->val_class)
4781 case dw_val_class_addr:
4782 return DW_FORM_addr;
4783 case dw_val_class_loc:
4784 switch (constant_size (size_of_locs (v->v.val_loc)))
4786 case 1:
4787 return DW_FORM_block1;
4788 case 2:
4789 return DW_FORM_block2;
4790 default:
4791 abort ();
4793 case dw_val_class_const:
4794 return DW_FORM_data4;
4795 case dw_val_class_unsigned_const:
4796 switch (constant_size (v->v.val_unsigned))
4798 case 1:
4799 return DW_FORM_data1;
4800 case 2:
4801 return DW_FORM_data2;
4802 case 4:
4803 return DW_FORM_data4;
4804 case 8:
4805 return DW_FORM_data8;
4806 default:
4807 abort ();
4809 case dw_val_class_long_long:
4810 return DW_FORM_block1;
4811 case dw_val_class_float:
4812 return DW_FORM_block1;
4813 case dw_val_class_flag:
4814 return DW_FORM_flag;
4815 case dw_val_class_die_ref:
4816 return DW_FORM_ref;
4817 case dw_val_class_fde_ref:
4818 return DW_FORM_data;
4819 case dw_val_class_lbl_id:
4820 return DW_FORM_addr;
4821 case dw_val_class_lbl_offset:
4822 return DW_FORM_data;
4823 case dw_val_class_str:
4824 return DW_FORM_string;
4825 default:
4826 abort ();
4830 /* Output the encoding of an attribute value. */
4832 static void
4833 output_value_format (v)
4834 dw_val_ref v;
4836 enum dwarf_form form = value_format (v);
4838 output_uleb128 (form);
4839 if (flag_debug_asm)
4840 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
4842 fputc ('\n', asm_out_file);
4845 /* Output the .debug_abbrev section which defines the DIE abbreviation
4846 table. */
4848 static void
4849 output_abbrev_section ()
4851 unsigned long abbrev_id;
4853 dw_attr_ref a_attr;
4854 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4856 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4858 output_uleb128 (abbrev_id);
4859 if (flag_debug_asm)
4860 fprintf (asm_out_file, " (abbrev code)");
4862 fputc ('\n', asm_out_file);
4863 output_uleb128 (abbrev->die_tag);
4864 if (flag_debug_asm)
4865 fprintf (asm_out_file, " (TAG: %s)",
4866 dwarf_tag_name (abbrev->die_tag));
4868 fputc ('\n', asm_out_file);
4869 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
4870 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
4872 if (flag_debug_asm)
4873 fprintf (asm_out_file, "\t%s %s",
4874 ASM_COMMENT_START,
4875 (abbrev->die_child != NULL
4876 ? "DW_children_yes" : "DW_children_no"));
4878 fputc ('\n', asm_out_file);
4880 for (a_attr = abbrev->die_attr; a_attr != NULL;
4881 a_attr = a_attr->dw_attr_next)
4883 output_uleb128 (a_attr->dw_attr);
4884 if (flag_debug_asm)
4885 fprintf (asm_out_file, " (%s)",
4886 dwarf_attr_name (a_attr->dw_attr));
4888 fputc ('\n', asm_out_file);
4889 output_value_format (&a_attr->dw_attr_val);
4892 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
4895 /* Terminate the table. */
4896 fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP);
4899 /* Output location description stack opcode's operands (if any). */
4901 static void
4902 output_loc_operands (loc)
4903 register dw_loc_descr_ref loc;
4905 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
4906 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
4908 switch (loc->dw_loc_opc)
4910 case DW_OP_addr:
4911 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
4912 fputc ('\n', asm_out_file);
4913 break;
4914 case DW_OP_const1u:
4915 case DW_OP_const1s:
4916 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4917 fputc ('\n', asm_out_file);
4918 break;
4919 case DW_OP_const2u:
4920 case DW_OP_const2s:
4921 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4922 fputc ('\n', asm_out_file);
4923 break;
4924 case DW_OP_const4u:
4925 case DW_OP_const4s:
4926 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
4927 fputc ('\n', asm_out_file);
4928 break;
4929 case DW_OP_const8u:
4930 case DW_OP_const8s:
4931 abort ();
4932 fputc ('\n', asm_out_file);
4933 break;
4934 case DW_OP_constu:
4935 output_uleb128 (val1->v.val_unsigned);
4936 fputc ('\n', asm_out_file);
4937 break;
4938 case DW_OP_consts:
4939 output_sleb128 (val1->v.val_int);
4940 fputc ('\n', asm_out_file);
4941 break;
4942 case DW_OP_pick:
4943 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
4944 fputc ('\n', asm_out_file);
4945 break;
4946 case DW_OP_plus_uconst:
4947 output_uleb128 (val1->v.val_unsigned);
4948 fputc ('\n', asm_out_file);
4949 break;
4950 case DW_OP_skip:
4951 case DW_OP_bra:
4952 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4953 fputc ('\n', asm_out_file);
4954 break;
4955 case DW_OP_breg0:
4956 case DW_OP_breg1:
4957 case DW_OP_breg2:
4958 case DW_OP_breg3:
4959 case DW_OP_breg4:
4960 case DW_OP_breg5:
4961 case DW_OP_breg6:
4962 case DW_OP_breg7:
4963 case DW_OP_breg8:
4964 case DW_OP_breg9:
4965 case DW_OP_breg10:
4966 case DW_OP_breg11:
4967 case DW_OP_breg12:
4968 case DW_OP_breg13:
4969 case DW_OP_breg14:
4970 case DW_OP_breg15:
4971 case DW_OP_breg16:
4972 case DW_OP_breg17:
4973 case DW_OP_breg18:
4974 case DW_OP_breg19:
4975 case DW_OP_breg20:
4976 case DW_OP_breg21:
4977 case DW_OP_breg22:
4978 case DW_OP_breg23:
4979 case DW_OP_breg24:
4980 case DW_OP_breg25:
4981 case DW_OP_breg26:
4982 case DW_OP_breg27:
4983 case DW_OP_breg28:
4984 case DW_OP_breg29:
4985 case DW_OP_breg30:
4986 case DW_OP_breg31:
4987 output_sleb128 (val1->v.val_int);
4988 fputc ('\n', asm_out_file);
4989 break;
4990 case DW_OP_regx:
4991 output_uleb128 (val1->v.val_unsigned);
4992 fputc ('\n', asm_out_file);
4993 break;
4994 case DW_OP_fbreg:
4995 output_sleb128 (val1->v.val_int);
4996 fputc ('\n', asm_out_file);
4997 break;
4998 case DW_OP_bregx:
4999 output_uleb128 (val1->v.val_unsigned);
5000 fputc ('\n', asm_out_file);
5001 output_sleb128 (val2->v.val_int);
5002 fputc ('\n', asm_out_file);
5003 break;
5004 case DW_OP_piece:
5005 output_uleb128 (val1->v.val_unsigned);
5006 fputc ('\n', asm_out_file);
5007 break;
5008 case DW_OP_deref_size:
5009 case DW_OP_xderef_size:
5010 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
5011 fputc ('\n', asm_out_file);
5012 break;
5013 default:
5014 break;
5018 /* Compute the offset of a sibling. */
5020 static unsigned long
5021 sibling_offset (die)
5022 dw_die_ref die;
5024 unsigned long offset;
5026 if (die->die_child_last == NULL)
5027 offset = die->die_offset + size_of_die (die);
5028 else
5029 offset = sibling_offset (die->die_child_last) + 1;
5031 return offset;
5034 /* Output the DIE and its attributes. Called recursively to generate
5035 the definitions of each child DIE. */
5037 static void
5038 output_die (die)
5039 register dw_die_ref die;
5041 register dw_attr_ref a;
5042 register dw_die_ref c;
5043 register unsigned long ref_offset;
5044 register unsigned long size;
5045 register dw_loc_descr_ref loc;
5047 output_uleb128 (die->die_abbrev);
5048 if (flag_debug_asm)
5049 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5050 die->die_offset, dwarf_tag_name (die->die_tag));
5052 fputc ('\n', asm_out_file);
5054 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5056 switch (a->dw_attr_val.val_class)
5058 case dw_val_class_addr:
5059 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
5060 a->dw_attr_val.v.val_addr);
5061 break;
5063 case dw_val_class_loc:
5064 size = size_of_locs (a->dw_attr_val.v.val_loc);
5066 /* Output the block length for this list of location operations. */
5067 switch (constant_size (size))
5069 case 1:
5070 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5071 break;
5072 case 2:
5073 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5074 break;
5075 default:
5076 abort ();
5079 if (flag_debug_asm)
5080 fprintf (asm_out_file, "\t%s %s",
5081 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5083 fputc ('\n', asm_out_file);
5084 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
5085 loc = loc->dw_loc_next)
5087 /* Output the opcode. */
5088 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
5089 if (flag_debug_asm)
5090 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
5091 dwarf_stack_op_name (loc->dw_loc_opc));
5093 fputc ('\n', asm_out_file);
5095 /* Output the operand(s) (if any). */
5096 output_loc_operands (loc);
5098 break;
5100 case dw_val_class_const:
5101 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
5102 break;
5104 case dw_val_class_unsigned_const:
5105 switch (constant_size (a->dw_attr_val.v.val_unsigned))
5107 case 1:
5108 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5109 a->dw_attr_val.v.val_unsigned);
5110 break;
5111 case 2:
5112 ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
5113 a->dw_attr_val.v.val_unsigned);
5114 break;
5115 case 4:
5116 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5117 a->dw_attr_val.v.val_unsigned);
5118 break;
5119 case 8:
5120 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5121 a->dw_attr_val.v.val_long_long.hi,
5122 a->dw_attr_val.v.val_long_long.low);
5123 break;
5124 default:
5125 abort ();
5127 break;
5129 case dw_val_class_long_long:
5130 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5131 if (flag_debug_asm)
5132 fprintf (asm_out_file, "\t%s %s",
5133 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5135 fputc ('\n', asm_out_file);
5136 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5137 a->dw_attr_val.v.val_long_long.hi,
5138 a->dw_attr_val.v.val_long_long.low);
5140 if (flag_debug_asm)
5141 fprintf (asm_out_file,
5142 "\t%s long long constant", ASM_COMMENT_START);
5144 fputc ('\n', asm_out_file);
5145 break;
5147 case dw_val_class_float:
5149 register unsigned int i;
5150 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5151 a->dw_attr_val.v.val_float.length * 4);
5152 if (flag_debug_asm)
5153 fprintf (asm_out_file, "\t%s %s",
5154 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5156 fputc ('\n', asm_out_file);
5157 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5159 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5160 a->dw_attr_val.v.val_float.array[i]);
5161 if (flag_debug_asm)
5162 fprintf (asm_out_file, "\t%s fp constant word %u",
5163 ASM_COMMENT_START, i);
5165 fputc ('\n', asm_out_file);
5167 break;
5170 case dw_val_class_flag:
5171 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
5172 break;
5174 case dw_val_class_die_ref:
5175 if (a->dw_attr_val.v.val_die_ref != NULL)
5176 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
5177 else if (a->dw_attr == DW_AT_sibling)
5178 ref_offset = sibling_offset(die);
5179 else
5180 abort ();
5182 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
5183 break;
5185 case dw_val_class_fde_ref:
5187 char l1[20];
5188 ASM_GENERATE_INTERNAL_LABEL
5189 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5190 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5191 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5193 break;
5195 case dw_val_class_lbl_id:
5196 ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
5197 break;
5199 case dw_val_class_lbl_offset:
5200 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, a->dw_attr_val.v.val_lbl_id);
5201 break;
5203 case dw_val_class_str:
5204 if (flag_debug_asm)
5205 ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
5206 else
5207 ASM_OUTPUT_ASCII (asm_out_file,
5208 a->dw_attr_val.v.val_str,
5209 (int) strlen (a->dw_attr_val.v.val_str) + 1);
5210 break;
5212 default:
5213 abort ();
5216 if (a->dw_attr_val.val_class != dw_val_class_loc
5217 && a->dw_attr_val.val_class != dw_val_class_long_long
5218 && a->dw_attr_val.val_class != dw_val_class_float)
5220 if (flag_debug_asm)
5221 fprintf (asm_out_file, "\t%s %s",
5222 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5224 fputc ('\n', asm_out_file);
5228 for (c = die->die_child; c != NULL; c = c->die_sib)
5229 output_die (c);
5231 if (die->die_child != NULL)
5233 /* Add null byte to terminate sibling list. */
5234 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5235 if (flag_debug_asm)
5236 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
5237 ASM_COMMENT_START, die->die_offset);
5239 fputc ('\n', asm_out_file);
5243 /* Output the compilation unit that appears at the beginning of the
5244 .debug_info section, and precedes the DIE descriptions. */
5246 static void
5247 output_compilation_unit_header ()
5249 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
5250 if (flag_debug_asm)
5251 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
5252 ASM_COMMENT_START);
5254 fputc ('\n', asm_out_file);
5255 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5256 if (flag_debug_asm)
5257 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
5259 fputc ('\n', asm_out_file);
5260 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
5261 if (flag_debug_asm)
5262 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
5263 ASM_COMMENT_START);
5265 fputc ('\n', asm_out_file);
5266 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5267 if (flag_debug_asm)
5268 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
5270 fputc ('\n', asm_out_file);
5273 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5274 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5275 argument list, and maybe the scope. */
5277 static const char *
5278 dwarf2_name (decl, scope)
5279 tree decl;
5280 int scope;
5282 return (*decl_printable_name) (decl, scope ? 1 : 0);
5285 /* Add a new entry to .debug_pubnames if appropriate. */
5287 static void
5288 add_pubname (decl, die)
5289 tree decl;
5290 dw_die_ref die;
5292 pubname_ref p;
5294 if (! TREE_PUBLIC (decl))
5295 return;
5297 if (pubname_table_in_use == pubname_table_allocated)
5299 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5300 pubname_table = (pubname_ref) xrealloc
5301 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5304 p = &pubname_table[pubname_table_in_use++];
5305 p->die = die;
5307 p->name = xstrdup (dwarf2_name (decl, 1));
5310 /* Output the public names table used to speed up access to externally
5311 visible names. For now, only generate entries for externally
5312 visible procedures. */
5314 static void
5315 output_pubnames ()
5317 register unsigned i;
5318 register unsigned long pubnames_length = size_of_pubnames ();
5320 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
5322 if (flag_debug_asm)
5323 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
5324 ASM_COMMENT_START);
5326 fputc ('\n', asm_out_file);
5327 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5329 if (flag_debug_asm)
5330 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5332 fputc ('\n', asm_out_file);
5333 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5334 if (flag_debug_asm)
5335 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5336 ASM_COMMENT_START);
5338 fputc ('\n', asm_out_file);
5339 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
5340 if (flag_debug_asm)
5341 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
5343 fputc ('\n', asm_out_file);
5344 for (i = 0; i < pubname_table_in_use; ++i)
5346 register pubname_ref pub = &pubname_table[i];
5348 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
5349 if (flag_debug_asm)
5350 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
5352 fputc ('\n', asm_out_file);
5354 if (flag_debug_asm)
5356 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5357 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5359 else
5361 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
5362 (int) strlen (pub->name) + 1);
5365 fputc ('\n', asm_out_file);
5368 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
5369 fputc ('\n', asm_out_file);
5372 /* Add a new entry to .debug_aranges if appropriate. */
5374 static void
5375 add_arange (decl, die)
5376 tree decl;
5377 dw_die_ref die;
5379 if (! DECL_SECTION_NAME (decl))
5380 return;
5382 if (arange_table_in_use == arange_table_allocated)
5384 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5385 arange_table
5386 = (arange_ref) xrealloc (arange_table,
5387 arange_table_allocated * sizeof (dw_die_ref));
5390 arange_table[arange_table_in_use++] = die;
5393 /* Output the information that goes into the .debug_aranges table.
5394 Namely, define the beginning and ending address range of the
5395 text section generated for this compilation unit. */
5397 static void
5398 output_aranges ()
5400 register unsigned i;
5401 register unsigned long aranges_length = size_of_aranges ();
5403 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
5404 if (flag_debug_asm)
5405 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
5406 ASM_COMMENT_START);
5408 fputc ('\n', asm_out_file);
5409 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5410 if (flag_debug_asm)
5411 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5413 fputc ('\n', asm_out_file);
5414 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5415 if (flag_debug_asm)
5416 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5417 ASM_COMMENT_START);
5419 fputc ('\n', asm_out_file);
5420 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5421 if (flag_debug_asm)
5422 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5424 fputc ('\n', asm_out_file);
5425 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5426 if (flag_debug_asm)
5427 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5428 ASM_COMMENT_START);
5430 fputc ('\n', asm_out_file);
5431 /* We need to align to twice the pointer size here.
5432 If DWARF_OFFSET_SIZE == 4, then we have emitted 12 bytes, and need 4
5433 bytes of padding to align for either 4 or 8 byte pointers. */
5434 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5435 /* If DWARF_OFFSET_SIZE == 8, then we have emitted 20 bytes, and need 12
5436 bytes of padding to align for 8 byte pointers. We have already emitted
5437 4 bytes of padding, so emit 8 more here. */
5438 if (DWARF_OFFSET_SIZE == 8)
5439 fprintf (asm_out_file, ",0,0");
5441 if (flag_debug_asm)
5442 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5443 ASM_COMMENT_START, 2 * PTR_SIZE);
5445 fputc ('\n', asm_out_file);
5446 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
5447 if (flag_debug_asm)
5448 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5450 fputc ('\n', asm_out_file);
5451 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
5452 text_section_label);
5453 if (flag_debug_asm)
5454 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5456 fputc ('\n', asm_out_file);
5457 for (i = 0; i < arange_table_in_use; ++i)
5459 dw_die_ref die = arange_table[i];
5461 if (die->die_tag == DW_TAG_subprogram)
5462 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
5463 else
5465 /* A static variable; extract the symbol from DW_AT_location.
5466 Note that this code isn't currently hit, as we only emit
5467 aranges for functions (jason 9/23/99). */
5469 dw_attr_ref a = get_AT (die, DW_AT_location);
5470 dw_loc_descr_ref loc;
5471 if (! a || a->dw_attr_val.val_class != dw_val_class_loc)
5472 abort ();
5474 loc = a->dw_attr_val.v.val_loc;
5475 if (loc->dw_loc_opc != DW_OP_addr)
5476 abort ();
5478 ASM_OUTPUT_DWARF_ADDR (asm_out_file, loc->dw_loc_oprnd1.v.val_addr);
5481 if (flag_debug_asm)
5482 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5484 fputc ('\n', asm_out_file);
5485 if (die->die_tag == DW_TAG_subprogram)
5486 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
5487 get_AT_low_pc (die));
5488 else
5489 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5490 get_AT_unsigned (die, DW_AT_byte_size));
5492 if (flag_debug_asm)
5493 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5495 fputc ('\n', asm_out_file);
5498 /* Output the terminator words. */
5499 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5500 fputc ('\n', asm_out_file);
5501 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5502 fputc ('\n', asm_out_file);
5505 /* Output the source line number correspondence information. This
5506 information goes into the .debug_line section. */
5508 static void
5509 output_line_info ()
5511 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5512 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5513 register unsigned opc;
5514 register unsigned n_op_args;
5515 register unsigned long ft_index;
5516 register unsigned long lt_index;
5517 register unsigned long current_line;
5518 register long line_offset;
5519 register long line_delta;
5520 register unsigned long current_file;
5521 register unsigned long function;
5523 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
5524 if (flag_debug_asm)
5525 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5526 ASM_COMMENT_START);
5528 fputc ('\n', asm_out_file);
5529 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
5530 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5531 if (flag_debug_asm)
5532 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5534 fputc ('\n', asm_out_file);
5535 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5536 if (flag_debug_asm)
5537 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5539 fputc ('\n', asm_out_file);
5540 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5541 if (flag_debug_asm)
5542 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5543 ASM_COMMENT_START);
5545 fputc ('\n', asm_out_file);
5546 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5547 if (flag_debug_asm)
5548 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5549 ASM_COMMENT_START);
5551 fputc ('\n', asm_out_file);
5552 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5553 if (flag_debug_asm)
5554 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5555 ASM_COMMENT_START);
5557 fputc ('\n', asm_out_file);
5558 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5559 if (flag_debug_asm)
5560 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5561 ASM_COMMENT_START);
5563 fputc ('\n', asm_out_file);
5564 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5565 if (flag_debug_asm)
5566 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5568 fputc ('\n', asm_out_file);
5569 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5571 switch (opc)
5573 case DW_LNS_advance_pc:
5574 case DW_LNS_advance_line:
5575 case DW_LNS_set_file:
5576 case DW_LNS_set_column:
5577 case DW_LNS_fixed_advance_pc:
5578 n_op_args = 1;
5579 break;
5580 default:
5581 n_op_args = 0;
5582 break;
5584 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5585 if (flag_debug_asm)
5586 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5587 ASM_COMMENT_START, opc, n_op_args);
5588 fputc ('\n', asm_out_file);
5591 if (flag_debug_asm)
5592 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5594 /* Include directory table is empty, at present */
5595 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5596 fputc ('\n', asm_out_file);
5597 if (flag_debug_asm)
5598 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5600 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5602 if (flag_debug_asm)
5604 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5605 fprintf (asm_out_file, "%s File Entry: 0x%lx",
5606 ASM_COMMENT_START, ft_index);
5608 else
5610 ASM_OUTPUT_ASCII (asm_out_file,
5611 file_table[ft_index],
5612 (int) strlen (file_table[ft_index]) + 1);
5615 fputc ('\n', asm_out_file);
5617 /* Include directory index */
5618 output_uleb128 (0);
5619 fputc ('\n', asm_out_file);
5621 /* Modification time */
5622 output_uleb128 (0);
5623 fputc ('\n', asm_out_file);
5625 /* File length in bytes */
5626 output_uleb128 (0);
5627 fputc ('\n', asm_out_file);
5630 /* Terminate the file name table */
5631 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5632 fputc ('\n', asm_out_file);
5634 /* We used to set the address register to the first location in the text
5635 section here, but that didn't accomplish anything since we already
5636 have a line note for the opening brace of the first function. */
5638 /* Generate the line number to PC correspondence table, encoded as
5639 a series of state machine operations. */
5640 current_file = 1;
5641 current_line = 1;
5642 strcpy (prev_line_label, text_section_label);
5643 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5645 register dw_line_info_ref line_info = &line_info_table[lt_index];
5647 /* Don't emit anything for redundant notes. Just updating the
5648 address doesn't accomplish anything, because we already assume
5649 that anything after the last address is this line. */
5650 if (line_info->dw_line_num == current_line
5651 && line_info->dw_file_num == current_file)
5652 continue;
5654 /* Emit debug info for the address of the current line, choosing
5655 the encoding that uses the least amount of space. */
5656 /* ??? Unfortunately, we have little choice here currently, and must
5657 always use the most general form. Gcc does not know the address
5658 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5659 dwarf2 aware assemblers at this time, so we can't use any special
5660 pseudo ops that would allow the assembler to optimally encode this for
5661 us. Many ports do have length attributes which will give an upper
5662 bound on the address range. We could perhaps use length attributes
5663 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5664 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5665 if (0)
5667 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5668 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5669 if (flag_debug_asm)
5670 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5671 ASM_COMMENT_START);
5673 fputc ('\n', asm_out_file);
5674 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5675 fputc ('\n', asm_out_file);
5677 else
5679 /* This can handle any delta. This takes 4+PTR_SIZE bytes. */
5680 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5681 if (flag_debug_asm)
5682 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5683 ASM_COMMENT_START);
5684 fputc ('\n', asm_out_file);
5685 output_uleb128 (1 + PTR_SIZE);
5686 fputc ('\n', asm_out_file);
5687 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5688 fputc ('\n', asm_out_file);
5689 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5690 fputc ('\n', asm_out_file);
5692 strcpy (prev_line_label, line_label);
5694 /* Emit debug info for the source file of the current line, if
5695 different from the previous line. */
5696 if (line_info->dw_file_num != current_file)
5698 current_file = line_info->dw_file_num;
5699 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5700 if (flag_debug_asm)
5701 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5703 fputc ('\n', asm_out_file);
5704 output_uleb128 (current_file);
5705 if (flag_debug_asm)
5706 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5708 fputc ('\n', asm_out_file);
5711 /* Emit debug info for the current line number, choosing the encoding
5712 that uses the least amount of space. */
5713 if (line_info->dw_line_num != current_line)
5715 line_offset = line_info->dw_line_num - current_line;
5716 line_delta = line_offset - DWARF_LINE_BASE;
5717 current_line = line_info->dw_line_num;
5718 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5720 /* This can handle deltas from -10 to 234, using the current
5721 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5722 takes 1 byte. */
5723 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5724 DWARF_LINE_OPCODE_BASE + line_delta);
5725 if (flag_debug_asm)
5726 fprintf (asm_out_file,
5727 "\t%s line %ld", ASM_COMMENT_START, current_line);
5729 fputc ('\n', asm_out_file);
5731 else
5733 /* This can handle any delta. This takes at least 4 bytes,
5734 depending on the value being encoded. */
5735 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5736 if (flag_debug_asm)
5737 fprintf (asm_out_file, "\t%s advance to line %ld",
5738 ASM_COMMENT_START, current_line);
5740 fputc ('\n', asm_out_file);
5741 output_sleb128 (line_offset);
5742 fputc ('\n', asm_out_file);
5743 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5744 if (flag_debug_asm)
5745 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5746 fputc ('\n', asm_out_file);
5749 else
5751 /* We still need to start a new row, so output a copy insn. */
5752 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5753 if (flag_debug_asm)
5754 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5755 fputc ('\n', asm_out_file);
5759 /* Emit debug info for the address of the end of the function. */
5760 if (0)
5762 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5763 if (flag_debug_asm)
5764 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5765 ASM_COMMENT_START);
5767 fputc ('\n', asm_out_file);
5768 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5769 fputc ('\n', asm_out_file);
5771 else
5773 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5774 if (flag_debug_asm)
5775 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5776 fputc ('\n', asm_out_file);
5777 output_uleb128 (1 + PTR_SIZE);
5778 fputc ('\n', asm_out_file);
5779 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5780 fputc ('\n', asm_out_file);
5781 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
5782 fputc ('\n', asm_out_file);
5785 /* Output the marker for the end of the line number info. */
5786 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
5787 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5788 if (flag_debug_asm)
5789 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5791 fputc ('\n', asm_out_file);
5792 output_uleb128 (1);
5793 fputc ('\n', asm_out_file);
5794 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5795 fputc ('\n', asm_out_file);
5797 function = 0;
5798 current_file = 1;
5799 current_line = 1;
5800 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5802 register dw_separate_line_info_ref line_info
5803 = &separate_line_info_table[lt_index];
5805 /* Don't emit anything for redundant notes. */
5806 if (line_info->dw_line_num == current_line
5807 && line_info->dw_file_num == current_file
5808 && line_info->function == function)
5809 goto cont;
5811 /* Emit debug info for the address of the current line. If this is
5812 a new function, or the first line of a function, then we need
5813 to handle it differently. */
5814 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5815 lt_index);
5816 if (function != line_info->function)
5818 function = line_info->function;
5820 /* Set the address register to the first line in the function */
5821 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5822 if (flag_debug_asm)
5823 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5824 ASM_COMMENT_START);
5826 fputc ('\n', asm_out_file);
5827 output_uleb128 (1 + PTR_SIZE);
5828 fputc ('\n', asm_out_file);
5829 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5830 fputc ('\n', asm_out_file);
5831 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5832 fputc ('\n', asm_out_file);
5834 else
5836 /* ??? See the DW_LNS_advance_pc comment above. */
5837 if (0)
5839 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5840 if (flag_debug_asm)
5841 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5842 ASM_COMMENT_START);
5844 fputc ('\n', asm_out_file);
5845 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5846 prev_line_label);
5847 fputc ('\n', asm_out_file);
5849 else
5851 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5852 if (flag_debug_asm)
5853 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5854 ASM_COMMENT_START);
5855 fputc ('\n', asm_out_file);
5856 output_uleb128 (1 + PTR_SIZE);
5857 fputc ('\n', asm_out_file);
5858 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5859 fputc ('\n', asm_out_file);
5860 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5861 fputc ('\n', asm_out_file);
5864 strcpy (prev_line_label, line_label);
5866 /* Emit debug info for the source file of the current line, if
5867 different from the previous line. */
5868 if (line_info->dw_file_num != current_file)
5870 current_file = line_info->dw_file_num;
5871 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5872 if (flag_debug_asm)
5873 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5875 fputc ('\n', asm_out_file);
5876 output_uleb128 (current_file);
5877 if (flag_debug_asm)
5878 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5880 fputc ('\n', asm_out_file);
5883 /* Emit debug info for the current line number, choosing the encoding
5884 that uses the least amount of space. */
5885 if (line_info->dw_line_num != current_line)
5887 line_offset = line_info->dw_line_num - current_line;
5888 line_delta = line_offset - DWARF_LINE_BASE;
5889 current_line = line_info->dw_line_num;
5890 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5892 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5893 DWARF_LINE_OPCODE_BASE + line_delta);
5894 if (flag_debug_asm)
5895 fprintf (asm_out_file,
5896 "\t%s line %ld", ASM_COMMENT_START, current_line);
5898 fputc ('\n', asm_out_file);
5900 else
5902 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5903 if (flag_debug_asm)
5904 fprintf (asm_out_file, "\t%s advance to line %ld",
5905 ASM_COMMENT_START, current_line);
5907 fputc ('\n', asm_out_file);
5908 output_sleb128 (line_offset);
5909 fputc ('\n', asm_out_file);
5910 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5911 if (flag_debug_asm)
5912 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5913 fputc ('\n', asm_out_file);
5916 else
5918 /* We still need to start a new row, so output a copy insn. */
5919 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5920 if (flag_debug_asm)
5921 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5922 fputc ('\n', asm_out_file);
5925 cont:
5926 ++lt_index;
5928 /* If we're done with a function, end its sequence. */
5929 if (lt_index == separate_line_info_table_in_use
5930 || separate_line_info_table[lt_index].function != function)
5932 current_file = 1;
5933 current_line = 1;
5935 /* Emit debug info for the address of the end of the function. */
5936 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
5937 if (0)
5939 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5940 if (flag_debug_asm)
5941 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5942 ASM_COMMENT_START);
5944 fputc ('\n', asm_out_file);
5945 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5946 prev_line_label);
5947 fputc ('\n', asm_out_file);
5949 else
5951 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5952 if (flag_debug_asm)
5953 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5954 ASM_COMMENT_START);
5955 fputc ('\n', asm_out_file);
5956 output_uleb128 (1 + PTR_SIZE);
5957 fputc ('\n', asm_out_file);
5958 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5959 fputc ('\n', asm_out_file);
5960 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5961 fputc ('\n', asm_out_file);
5964 /* Output the marker for the end of this sequence. */
5965 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5966 if (flag_debug_asm)
5967 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
5968 ASM_COMMENT_START);
5970 fputc ('\n', asm_out_file);
5971 output_uleb128 (1);
5972 fputc ('\n', asm_out_file);
5973 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5974 fputc ('\n', asm_out_file);
5979 /* Given a pointer to a BLOCK node return non-zero if (and only if) the node
5980 in question represents the outermost pair of curly braces (i.e. the "body
5981 block") of a function or method.
5983 For any BLOCK node representing a "body block" of a function or method, the
5984 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
5985 represents the outermost (function) scope for the function or method (i.e.
5986 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
5987 *that* node in turn will point to the relevant FUNCTION_DECL node. */
5989 static inline int
5990 is_body_block (stmt)
5991 register tree stmt;
5993 if (TREE_CODE (stmt) == BLOCK)
5995 register tree parent = BLOCK_SUPERCONTEXT (stmt);
5997 if (TREE_CODE (parent) == BLOCK)
5999 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
6001 if (TREE_CODE (grandparent) == FUNCTION_DECL)
6002 return 1;
6006 return 0;
6009 /* Given a pointer to a tree node for some base type, return a pointer to
6010 a DIE that describes the given type.
6012 This routine must only be called for GCC type nodes that correspond to
6013 Dwarf base (fundamental) types. */
6015 static dw_die_ref
6016 base_type_die (type)
6017 register tree type;
6019 register dw_die_ref base_type_result;
6020 register const char *type_name;
6021 register enum dwarf_type encoding;
6022 register tree name = TYPE_NAME (type);
6024 if (TREE_CODE (type) == ERROR_MARK
6025 || TREE_CODE (type) == VOID_TYPE)
6026 return 0;
6028 if (name)
6030 if (TREE_CODE (name) == TYPE_DECL)
6031 name = DECL_NAME (name);
6033 type_name = IDENTIFIER_POINTER (name);
6035 else
6036 type_name = "__unknown__";
6038 switch (TREE_CODE (type))
6040 case INTEGER_TYPE:
6041 /* Carefully distinguish the C character types, without messing
6042 up if the language is not C. Note that we check only for the names
6043 that contain spaces; other names might occur by coincidence in other
6044 languages. */
6045 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6046 && (type == char_type_node
6047 || ! strcmp (type_name, "signed char")
6048 || ! strcmp (type_name, "unsigned char"))))
6050 if (TREE_UNSIGNED (type))
6051 encoding = DW_ATE_unsigned;
6052 else
6053 encoding = DW_ATE_signed;
6054 break;
6056 /* else fall through */
6058 case CHAR_TYPE:
6059 /* GNU Pascal/Ada CHAR type. Not used in C. */
6060 if (TREE_UNSIGNED (type))
6061 encoding = DW_ATE_unsigned_char;
6062 else
6063 encoding = DW_ATE_signed_char;
6064 break;
6066 case REAL_TYPE:
6067 encoding = DW_ATE_float;
6068 break;
6070 /* Dwarf2 doesn't know anything about complex ints, so use
6071 a user defined type for it. */
6072 case COMPLEX_TYPE:
6073 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6074 encoding = DW_ATE_complex_float;
6075 else
6076 encoding = DW_ATE_lo_user;
6077 break;
6079 case BOOLEAN_TYPE:
6080 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6081 encoding = DW_ATE_boolean;
6082 break;
6084 default:
6085 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6088 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6089 if (demangle_name_func)
6090 type_name = (*demangle_name_func) (type_name);
6092 add_AT_string (base_type_result, DW_AT_name, type_name);
6093 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6094 int_size_in_bytes (type));
6095 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6097 return base_type_result;
6100 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6101 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6102 a given type is generally the same as the given type, except that if the
6103 given type is a pointer or reference type, then the root type of the given
6104 type is the root type of the "basis" type for the pointer or reference
6105 type. (This definition of the "root" type is recursive.) Also, the root
6106 type of a `const' qualified type or a `volatile' qualified type is the
6107 root type of the given type without the qualifiers. */
6109 static tree
6110 root_type (type)
6111 register tree type;
6113 if (TREE_CODE (type) == ERROR_MARK)
6114 return error_mark_node;
6116 switch (TREE_CODE (type))
6118 case ERROR_MARK:
6119 return error_mark_node;
6121 case POINTER_TYPE:
6122 case REFERENCE_TYPE:
6123 return type_main_variant (root_type (TREE_TYPE (type)));
6125 default:
6126 return type_main_variant (type);
6130 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6131 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6133 static inline int
6134 is_base_type (type)
6135 register tree type;
6137 switch (TREE_CODE (type))
6139 case ERROR_MARK:
6140 case VOID_TYPE:
6141 case INTEGER_TYPE:
6142 case REAL_TYPE:
6143 case COMPLEX_TYPE:
6144 case BOOLEAN_TYPE:
6145 case CHAR_TYPE:
6146 return 1;
6148 case SET_TYPE:
6149 case ARRAY_TYPE:
6150 case RECORD_TYPE:
6151 case UNION_TYPE:
6152 case QUAL_UNION_TYPE:
6153 case ENUMERAL_TYPE:
6154 case FUNCTION_TYPE:
6155 case METHOD_TYPE:
6156 case POINTER_TYPE:
6157 case REFERENCE_TYPE:
6158 case FILE_TYPE:
6159 case OFFSET_TYPE:
6160 case LANG_TYPE:
6161 return 0;
6163 default:
6164 abort ();
6167 return 0;
6170 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6171 entry that chains various modifiers in front of the given type. */
6173 static dw_die_ref
6174 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6175 register tree type;
6176 register int is_const_type;
6177 register int is_volatile_type;
6178 register dw_die_ref context_die;
6180 register enum tree_code code = TREE_CODE (type);
6181 register dw_die_ref mod_type_die = NULL;
6182 register dw_die_ref sub_die = NULL;
6183 register tree item_type = NULL;
6185 if (code != ERROR_MARK)
6187 type = build_type_variant (type, is_const_type, is_volatile_type);
6189 mod_type_die = lookup_type_die (type);
6190 if (mod_type_die)
6191 return mod_type_die;
6193 /* Handle C typedef types. */
6194 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6195 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6197 tree dtype = TREE_TYPE (TYPE_NAME (type));
6198 if (type == dtype)
6200 /* For a named type, use the typedef. */
6201 gen_type_die (type, context_die);
6202 mod_type_die = lookup_type_die (type);
6205 else if (is_const_type < TYPE_READONLY (dtype)
6206 || is_volatile_type < TYPE_VOLATILE (dtype))
6207 /* cv-unqualified version of named type. Just use the unnamed
6208 type to which it refers. */
6209 mod_type_die
6210 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6211 is_const_type, is_volatile_type,
6212 context_die);
6213 /* Else cv-qualified version of named type; fall through. */
6216 if (mod_type_die)
6217 /* OK */;
6218 else if (is_const_type)
6220 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6221 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6223 else if (is_volatile_type)
6225 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6226 sub_die = modified_type_die (type, 0, 0, context_die);
6228 else if (code == POINTER_TYPE)
6230 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6231 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6232 #if 0
6233 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6234 #endif
6235 item_type = TREE_TYPE (type);
6237 else if (code == REFERENCE_TYPE)
6239 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6240 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6241 #if 0
6242 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6243 #endif
6244 item_type = TREE_TYPE (type);
6246 else if (is_base_type (type))
6247 mod_type_die = base_type_die (type);
6248 else
6250 gen_type_die (type, context_die);
6252 /* We have to get the type_main_variant here (and pass that to the
6253 `lookup_type_die' routine) because the ..._TYPE node we have
6254 might simply be a *copy* of some original type node (where the
6255 copy was created to help us keep track of typedef names) and
6256 that copy might have a different TYPE_UID from the original
6257 ..._TYPE node. */
6258 mod_type_die = lookup_type_die (type_main_variant (type));
6259 if (mod_type_die == NULL)
6260 abort ();
6264 equate_type_number_to_die (type, mod_type_die);
6265 if (item_type)
6266 /* We must do this after the equate_type_number_to_die call, in case
6267 this is a recursive type. This ensures that the modified_type_die
6268 recursion will terminate even if the type is recursive. Recursive
6269 types are possible in Ada. */
6270 sub_die = modified_type_die (item_type,
6271 TYPE_READONLY (item_type),
6272 TYPE_VOLATILE (item_type),
6273 context_die);
6275 if (sub_die != NULL)
6276 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6278 return mod_type_die;
6281 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6282 an enumerated type. */
6284 static inline int
6285 type_is_enum (type)
6286 register tree type;
6288 return TREE_CODE (type) == ENUMERAL_TYPE;
6291 /* Return a location descriptor that designates a machine register. */
6293 static dw_loc_descr_ref
6294 reg_loc_descriptor (rtl)
6295 register rtx rtl;
6297 register dw_loc_descr_ref loc_result = NULL;
6298 register unsigned reg = reg_number (rtl);
6300 if (reg <= 31)
6301 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6302 else
6303 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6305 return loc_result;
6308 /* Return a location descriptor that designates a base+offset location. */
6310 static dw_loc_descr_ref
6311 based_loc_descr (reg, offset)
6312 unsigned reg;
6313 long int offset;
6315 register dw_loc_descr_ref loc_result;
6316 /* For the "frame base", we use the frame pointer or stack pointer
6317 registers, since the RTL for local variables is relative to one of
6318 them. */
6319 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6320 ? HARD_FRAME_POINTER_REGNUM
6321 : STACK_POINTER_REGNUM);
6323 if (reg == fp_reg)
6324 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
6325 else if (reg <= 31)
6326 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
6327 else
6328 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6330 return loc_result;
6333 /* Return true if this RTL expression describes a base+offset calculation. */
6335 static inline int
6336 is_based_loc (rtl)
6337 register rtx rtl;
6339 return (GET_CODE (rtl) == PLUS
6340 && ((GET_CODE (XEXP (rtl, 0)) == REG
6341 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6344 /* The following routine converts the RTL for a variable or parameter
6345 (resident in memory) into an equivalent Dwarf representation of a
6346 mechanism for getting the address of that same variable onto the top of a
6347 hypothetical "address evaluation" stack.
6349 When creating memory location descriptors, we are effectively transforming
6350 the RTL for a memory-resident object into its Dwarf postfix expression
6351 equivalent. This routine recursively descends an RTL tree, turning
6352 it into Dwarf postfix code as it goes.
6354 MODE is the mode of the memory reference, needed to handle some
6355 autoincrement addressing modes. */
6357 static dw_loc_descr_ref
6358 mem_loc_descriptor (rtl, mode)
6359 register rtx rtl;
6360 enum machine_mode mode;
6362 dw_loc_descr_ref mem_loc_result = NULL;
6363 /* Note that for a dynamically sized array, the location we will generate a
6364 description of here will be the lowest numbered location which is
6365 actually within the array. That's *not* necessarily the same as the
6366 zeroth element of the array. */
6368 switch (GET_CODE (rtl))
6370 case POST_INC:
6371 case POST_DEC:
6372 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
6373 just fall into the SUBREG code. */
6375 /* ... fall through ... */
6377 case SUBREG:
6378 /* The case of a subreg may arise when we have a local (register)
6379 variable or a formal (register) parameter which doesn't quite fill
6380 up an entire register. For now, just assume that it is
6381 legitimate to make the Dwarf info refer to the whole register which
6382 contains the given subreg. */
6383 rtl = XEXP (rtl, 0);
6385 /* ... fall through ... */
6387 case REG:
6388 /* Whenever a register number forms a part of the description of the
6389 method for calculating the (dynamic) address of a memory resident
6390 object, DWARF rules require the register number be referred to as
6391 a "base register". This distinction is not based in any way upon
6392 what category of register the hardware believes the given register
6393 belongs to. This is strictly DWARF terminology we're dealing with
6394 here. Note that in cases where the location of a memory-resident
6395 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6396 OP_CONST (0)) the actual DWARF location descriptor that we generate
6397 may just be OP_BASEREG (basereg). This may look deceptively like
6398 the object in question was allocated to a register (rather than in
6399 memory) so DWARF consumers need to be aware of the subtle
6400 distinction between OP_REG and OP_BASEREG. */
6401 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6402 break;
6404 case MEM:
6405 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
6406 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6407 break;
6409 case LABEL_REF:
6410 /* Some ports can transform a symbol ref into a label ref, because
6411 the symbol ref is too far away and has to be dumped into a constant
6412 pool. */
6413 case CONST:
6414 case SYMBOL_REF:
6415 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6416 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6417 mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
6418 break;
6420 case PRE_INC:
6421 case PRE_DEC:
6422 /* Turn these into a PLUS expression and fall into the PLUS code
6423 below. */
6424 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
6425 GEN_INT (GET_CODE (rtl) == PRE_INC
6426 ? GET_MODE_UNIT_SIZE (mode)
6427 : - GET_MODE_UNIT_SIZE (mode)));
6429 /* ... fall through ... */
6431 case PLUS:
6432 if (is_based_loc (rtl))
6433 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6434 INTVAL (XEXP (rtl, 1)));
6435 else
6437 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
6438 mode));
6439 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
6440 mode));
6441 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6443 break;
6445 case MULT:
6446 /* If a pseudo-reg is optimized away, it is possible for it to
6447 be replaced with a MEM containing a multiply. */
6448 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
6449 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
6450 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6451 break;
6453 case CONST_INT:
6454 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6455 break;
6457 default:
6458 abort ();
6461 return mem_loc_result;
6464 /* Return a descriptor that describes the concatenation of two locations.
6465 This is typically a complex variable. */
6467 static dw_loc_descr_ref
6468 concat_loc_descriptor (x0, x1)
6469 register rtx x0, x1;
6471 dw_loc_descr_ref cc_loc_result = NULL;
6473 if (!is_pseudo_reg (x0)
6474 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
6475 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
6476 add_loc_descr (&cc_loc_result,
6477 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
6479 if (!is_pseudo_reg (x1)
6480 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
6481 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
6482 add_loc_descr (&cc_loc_result,
6483 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
6485 return cc_loc_result;
6488 /* Output a proper Dwarf location descriptor for a variable or parameter
6489 which is either allocated in a register or in a memory location. For a
6490 register, we just generate an OP_REG and the register number. For a
6491 memory location we provide a Dwarf postfix expression describing how to
6492 generate the (dynamic) address of the object onto the address stack. */
6494 static dw_loc_descr_ref
6495 loc_descriptor (rtl)
6496 register rtx rtl;
6498 dw_loc_descr_ref loc_result = NULL;
6499 switch (GET_CODE (rtl))
6501 case SUBREG:
6502 /* The case of a subreg may arise when we have a local (register)
6503 variable or a formal (register) parameter which doesn't quite fill
6504 up an entire register. For now, just assume that it is
6505 legitimate to make the Dwarf info refer to the whole register which
6506 contains the given subreg. */
6507 rtl = XEXP (rtl, 0);
6509 /* ... fall through ... */
6511 case REG:
6512 loc_result = reg_loc_descriptor (rtl);
6513 break;
6515 case MEM:
6516 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
6517 break;
6519 case CONCAT:
6520 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6521 break;
6523 default:
6524 abort ();
6527 return loc_result;
6530 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
6531 which is not less than the value itself. */
6533 static inline unsigned
6534 ceiling (value, boundary)
6535 register unsigned value;
6536 register unsigned boundary;
6538 return (((value + boundary - 1) / boundary) * boundary);
6541 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6542 pointer to the declared type for the relevant field variable, or return
6543 `integer_type_node' if the given node turns out to be an
6544 ERROR_MARK node. */
6546 static inline tree
6547 field_type (decl)
6548 register tree decl;
6550 register tree type;
6552 if (TREE_CODE (decl) == ERROR_MARK)
6553 return integer_type_node;
6555 type = DECL_BIT_FIELD_TYPE (decl);
6556 if (type == NULL_TREE)
6557 type = TREE_TYPE (decl);
6559 return type;
6562 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6563 node, return the alignment in bits for the type, or else return
6564 BITS_PER_WORD if the node actually turns out to be an
6565 ERROR_MARK node. */
6567 static inline unsigned
6568 simple_type_align_in_bits (type)
6569 register tree type;
6571 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6574 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6575 node, return the size in bits for the type if it is a constant, or else
6576 return the alignment for the type if the type's size is not constant, or
6577 else return BITS_PER_WORD if the type actually turns out to be an
6578 ERROR_MARK node. */
6580 static inline unsigned
6581 simple_type_size_in_bits (type)
6582 register tree type;
6584 if (TREE_CODE (type) == ERROR_MARK)
6585 return BITS_PER_WORD;
6586 else
6588 register tree type_size_tree = TYPE_SIZE (type);
6590 if (TREE_CODE (type_size_tree) != INTEGER_CST)
6591 return TYPE_ALIGN (type);
6593 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
6597 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6598 return the byte offset of the lowest addressed byte of the "containing
6599 object" for the given FIELD_DECL, or return 0 if we are unable to
6600 determine what that offset is, either because the argument turns out to
6601 be a pointer to an ERROR_MARK node, or because the offset is actually
6602 variable. (We can't handle the latter case just yet). */
6604 static unsigned
6605 field_byte_offset (decl)
6606 register tree decl;
6608 register unsigned type_align_in_bytes;
6609 register unsigned type_align_in_bits;
6610 register unsigned type_size_in_bits;
6611 register unsigned object_offset_in_align_units;
6612 register unsigned object_offset_in_bits;
6613 register unsigned object_offset_in_bytes;
6614 register tree type;
6615 register tree bitpos_tree;
6616 register tree field_size_tree;
6617 register unsigned bitpos_int;
6618 register unsigned deepest_bitpos;
6619 register unsigned field_size_in_bits;
6621 if (TREE_CODE (decl) == ERROR_MARK)
6622 return 0;
6624 if (TREE_CODE (decl) != FIELD_DECL)
6625 abort ();
6627 type = field_type (decl);
6629 bitpos_tree = DECL_FIELD_BITPOS (decl);
6630 field_size_tree = DECL_SIZE (decl);
6632 /* We cannot yet cope with fields whose positions are variable, so
6633 for now, when we see such things, we simply return 0. Someday, we may
6634 be able to handle such cases, but it will be damn difficult. */
6635 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6636 return 0;
6638 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6640 /* If we don't know the size of the field, pretend it's a full word. */
6641 if (TREE_CODE (field_size_tree) == INTEGER_CST)
6642 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
6643 else
6644 field_size_in_bits = BITS_PER_WORD;
6646 type_size_in_bits = simple_type_size_in_bits (type);
6647 type_align_in_bits = simple_type_align_in_bits (type);
6648 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6650 /* Note that the GCC front-end doesn't make any attempt to keep track of
6651 the starting bit offset (relative to the start of the containing
6652 structure type) of the hypothetical "containing object" for a bit-
6653 field. Thus, when computing the byte offset value for the start of the
6654 "containing object" of a bit-field, we must deduce this information on
6655 our own. This can be rather tricky to do in some cases. For example,
6656 handling the following structure type definition when compiling for an
6657 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6658 can be very tricky:
6660 struct S { int field1; long long field2:31; };
6662 Fortunately, there is a simple rule-of-thumb which can be
6663 used in such cases. When compiling for an i386/i486, GCC will allocate
6664 8 bytes for the structure shown above. It decides to do this based upon
6665 one simple rule for bit-field allocation. Quite simply, GCC allocates
6666 each "containing object" for each bit-field at the first (i.e. lowest
6667 addressed) legitimate alignment boundary (based upon the required
6668 minimum alignment for the declared type of the field) which it can
6669 possibly use, subject to the condition that there is still enough
6670 available space remaining in the containing object (when allocated at
6671 the selected point) to fully accommodate all of the bits of the
6672 bit-field itself. This simple rule makes it obvious why GCC allocates
6673 8 bytes for each object of the structure type shown above. When looking
6674 for a place to allocate the "containing object" for `field2', the
6675 compiler simply tries to allocate a 64-bit "containing object" at each
6676 successive 32-bit boundary (starting at zero) until it finds a place to
6677 allocate that 64- bit field such that at least 31 contiguous (and
6678 previously unallocated) bits remain within that selected 64 bit field.
6679 (As it turns out, for the example above, the compiler finds that it is
6680 OK to allocate the "containing object" 64-bit field at bit-offset zero
6681 within the structure type.) Here we attempt to work backwards from the
6682 limited set of facts we're given, and we try to deduce from those facts,
6683 where GCC must have believed that the containing object started (within
6684 the structure type). The value we deduce is then used (by the callers of
6685 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6686 for fields (both bit-fields and, in the case of DW_AT_location, regular
6687 fields as well). */
6689 /* Figure out the bit-distance from the start of the structure to the
6690 "deepest" bit of the bit-field. */
6691 deepest_bitpos = bitpos_int + field_size_in_bits;
6693 /* This is the tricky part. Use some fancy footwork to deduce where the
6694 lowest addressed bit of the containing object must be. */
6695 object_offset_in_bits
6696 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6698 /* Compute the offset of the containing object in "alignment units". */
6699 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6701 /* Compute the offset of the containing object in bytes. */
6702 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6704 return object_offset_in_bytes;
6707 /* The following routines define various Dwarf attributes and any data
6708 associated with them. */
6710 /* Add a location description attribute value to a DIE.
6712 This emits location attributes suitable for whole variables and
6713 whole parameters. Note that the location attributes for struct fields are
6714 generated by the routine `data_member_location_attribute' below. */
6716 static void
6717 add_AT_location_description (die, attr_kind, rtl)
6718 dw_die_ref die;
6719 enum dwarf_attribute attr_kind;
6720 register rtx rtl;
6722 /* Handle a special case. If we are about to output a location descriptor
6723 for a variable or parameter which has been optimized out of existence,
6724 don't do that. A variable which has been optimized out
6725 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6726 Currently, in some rare cases, variables can have DECL_RTL values which
6727 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6728 elsewhere in the compiler. We treat such cases as if the variable(s) in
6729 question had been optimized out of existence. */
6731 if (is_pseudo_reg (rtl)
6732 || (GET_CODE (rtl) == MEM
6733 && is_pseudo_reg (XEXP (rtl, 0)))
6734 || (GET_CODE (rtl) == CONCAT
6735 && is_pseudo_reg (XEXP (rtl, 0))
6736 && is_pseudo_reg (XEXP (rtl, 1))))
6737 return;
6739 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
6742 /* Attach the specialized form of location attribute used for data
6743 members of struct and union types. In the special case of a
6744 FIELD_DECL node which represents a bit-field, the "offset" part
6745 of this special location descriptor must indicate the distance
6746 in bytes from the lowest-addressed byte of the containing struct
6747 or union type to the lowest-addressed byte of the "containing
6748 object" for the bit-field. (See the `field_byte_offset' function
6749 above).. For any given bit-field, the "containing object" is a
6750 hypothetical object (of some integral or enum type) within which
6751 the given bit-field lives. The type of this hypothetical
6752 "containing object" is always the same as the declared type of
6753 the individual bit-field itself (for GCC anyway... the DWARF
6754 spec doesn't actually mandate this). Note that it is the size
6755 (in bytes) of the hypothetical "containing object" which will
6756 be given in the DW_AT_byte_size attribute for this bit-field.
6757 (See the `byte_size_attribute' function below.) It is also used
6758 when calculating the value of the DW_AT_bit_offset attribute.
6759 (See the `bit_offset_attribute' function below). */
6761 static void
6762 add_data_member_location_attribute (die, decl)
6763 register dw_die_ref die;
6764 register tree decl;
6766 register unsigned long offset;
6767 register dw_loc_descr_ref loc_descr;
6768 register enum dwarf_location_atom op;
6770 if (TREE_CODE (decl) == TREE_VEC)
6771 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
6772 else
6773 offset = field_byte_offset (decl);
6775 /* The DWARF2 standard says that we should assume that the structure address
6776 is already on the stack, so we can specify a structure field address
6777 by using DW_OP_plus_uconst. */
6779 #ifdef MIPS_DEBUGGING_INFO
6780 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6781 correctly. It works only if we leave the offset on the stack. */
6782 op = DW_OP_constu;
6783 #else
6784 op = DW_OP_plus_uconst;
6785 #endif
6787 loc_descr = new_loc_descr (op, offset, 0);
6788 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6791 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6792 does not have a "location" either in memory or in a register. These
6793 things can arise in GNU C when a constant is passed as an actual parameter
6794 to an inlined function. They can also arise in C++ where declared
6795 constants do not necessarily get memory "homes". */
6797 static void
6798 add_const_value_attribute (die, rtl)
6799 register dw_die_ref die;
6800 register rtx rtl;
6802 switch (GET_CODE (rtl))
6804 case CONST_INT:
6805 /* Note that a CONST_INT rtx could represent either an integer or a
6806 floating-point constant. A CONST_INT is used whenever the constant
6807 will fit into a single word. In all such cases, the original mode
6808 of the constant value is wiped out, and the CONST_INT rtx is
6809 assigned VOIDmode. */
6810 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6811 break;
6813 case CONST_DOUBLE:
6814 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6815 floating-point constant. A CONST_DOUBLE is used whenever the
6816 constant requires more than one word in order to be adequately
6817 represented. We output CONST_DOUBLEs as blocks. */
6819 register enum machine_mode mode = GET_MODE (rtl);
6821 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6823 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6824 long array[4];
6825 REAL_VALUE_TYPE rv;
6827 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6828 switch (mode)
6830 case SFmode:
6831 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6832 break;
6834 case DFmode:
6835 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6836 break;
6838 case XFmode:
6839 case TFmode:
6840 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6841 break;
6843 default:
6844 abort ();
6847 add_AT_float (die, DW_AT_const_value, length, array);
6849 else
6850 add_AT_long_long (die, DW_AT_const_value,
6851 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6853 break;
6855 case CONST_STRING:
6856 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6857 break;
6859 case SYMBOL_REF:
6860 case LABEL_REF:
6861 case CONST:
6862 add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
6863 break;
6865 case PLUS:
6866 /* In cases where an inlined instance of an inline function is passed
6867 the address of an `auto' variable (which is local to the caller) we
6868 can get a situation where the DECL_RTL of the artificial local
6869 variable (for the inlining) which acts as a stand-in for the
6870 corresponding formal parameter (of the inline function) will look
6871 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6872 exactly a compile-time constant expression, but it isn't the address
6873 of the (artificial) local variable either. Rather, it represents the
6874 *value* which the artificial local variable always has during its
6875 lifetime. We currently have no way to represent such quasi-constant
6876 values in Dwarf, so for now we just punt and generate nothing. */
6877 break;
6879 default:
6880 /* No other kinds of rtx should be possible here. */
6881 abort ();
6886 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6887 data attribute for a variable or a parameter. We generate the
6888 DW_AT_const_value attribute only in those cases where the given variable
6889 or parameter does not have a true "location" either in memory or in a
6890 register. This can happen (for example) when a constant is passed as an
6891 actual argument in a call to an inline function. (It's possible that
6892 these things can crop up in other ways also.) Note that one type of
6893 constant value which can be passed into an inlined function is a constant
6894 pointer. This can happen for example if an actual argument in an inlined
6895 function call evaluates to a compile-time constant address. */
6897 static void
6898 add_location_or_const_value_attribute (die, decl)
6899 register dw_die_ref die;
6900 register tree decl;
6902 register rtx rtl;
6903 register tree declared_type;
6904 register tree passed_type;
6906 if (TREE_CODE (decl) == ERROR_MARK)
6907 return;
6909 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6910 abort ();
6912 /* Here we have to decide where we are going to say the parameter "lives"
6913 (as far as the debugger is concerned). We only have a couple of
6914 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6916 DECL_RTL normally indicates where the parameter lives during most of the
6917 activation of the function. If optimization is enabled however, this
6918 could be either NULL or else a pseudo-reg. Both of those cases indicate
6919 that the parameter doesn't really live anywhere (as far as the code
6920 generation parts of GCC are concerned) during most of the function's
6921 activation. That will happen (for example) if the parameter is never
6922 referenced within the function.
6924 We could just generate a location descriptor here for all non-NULL
6925 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6926 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6927 where DECL_RTL is NULL or is a pseudo-reg.
6929 Note however that we can only get away with using DECL_INCOMING_RTL as
6930 a backup substitute for DECL_RTL in certain limited cases. In cases
6931 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6932 we can be sure that the parameter was passed using the same type as it is
6933 declared to have within the function, and that its DECL_INCOMING_RTL
6934 points us to a place where a value of that type is passed.
6936 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6937 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6938 because in these cases DECL_INCOMING_RTL points us to a value of some
6939 type which is *different* from the type of the parameter itself. Thus,
6940 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6941 such cases, the debugger would end up (for example) trying to fetch a
6942 `float' from a place which actually contains the first part of a
6943 `double'. That would lead to really incorrect and confusing
6944 output at debug-time.
6946 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6947 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6948 are a couple of exceptions however. On little-endian machines we can
6949 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6950 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6951 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6952 when (on a little-endian machine) a non-prototyped function has a
6953 parameter declared to be of type `short' or `char'. In such cases,
6954 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6955 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6956 passed `int' value. If the debugger then uses that address to fetch
6957 a `short' or a `char' (on a little-endian machine) the result will be
6958 the correct data, so we allow for such exceptional cases below.
6960 Note that our goal here is to describe the place where the given formal
6961 parameter lives during most of the function's activation (i.e. between
6962 the end of the prologue and the start of the epilogue). We'll do that
6963 as best as we can. Note however that if the given formal parameter is
6964 modified sometime during the execution of the function, then a stack
6965 backtrace (at debug-time) will show the function as having been
6966 called with the *new* value rather than the value which was
6967 originally passed in. This happens rarely enough that it is not
6968 a major problem, but it *is* a problem, and I'd like to fix it.
6970 A future version of dwarf2out.c may generate two additional
6971 attributes for any given DW_TAG_formal_parameter DIE which will
6972 describe the "passed type" and the "passed location" for the
6973 given formal parameter in addition to the attributes we now
6974 generate to indicate the "declared type" and the "active
6975 location" for each parameter. This additional set of attributes
6976 could be used by debuggers for stack backtraces. Separately, note
6977 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6978 NULL also. This happens (for example) for inlined-instances of
6979 inline function formal parameters which are never referenced.
6980 This really shouldn't be happening. All PARM_DECL nodes should
6981 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6982 doesn't currently generate these values for inlined instances of
6983 inline function parameters, so when we see such cases, we are
6984 just out-of-luck for the time being (until integrate.c
6985 gets fixed). */
6987 /* Use DECL_RTL as the "location" unless we find something better. */
6988 rtl = DECL_RTL (decl);
6990 if (TREE_CODE (decl) == PARM_DECL)
6992 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
6994 declared_type = type_main_variant (TREE_TYPE (decl));
6995 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
6997 /* This decl represents a formal parameter which was optimized out.
6998 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
6999 all* cases where (rtl == NULL_RTX) just below. */
7000 if (declared_type == passed_type)
7001 rtl = DECL_INCOMING_RTL (decl);
7002 else if (! BYTES_BIG_ENDIAN
7003 && TREE_CODE (declared_type) == INTEGER_TYPE
7004 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
7005 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
7006 rtl = DECL_INCOMING_RTL (decl);
7009 /* If the parm was passed in registers, but lives on the stack, then
7010 make a big endian correction if the mode of the type of the
7011 parameter is not the same as the mode of the rtl. */
7012 /* ??? This is the same series of checks that are made in dbxout.c before
7013 we reach the big endian correction code there. It isn't clear if all
7014 of these checks are necessary here, but keeping them all is the safe
7015 thing to do. */
7016 else if (GET_CODE (rtl) == MEM
7017 && XEXP (rtl, 0) != const0_rtx
7018 && ! CONSTANT_P (XEXP (rtl, 0))
7019 /* Not passed in memory. */
7020 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
7021 /* Not passed by invisible reference. */
7022 && (GET_CODE (XEXP (rtl, 0)) != REG
7023 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
7024 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
7025 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
7026 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
7027 #endif
7029 /* Big endian correction check. */
7030 && BYTES_BIG_ENDIAN
7031 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
7032 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
7033 < UNITS_PER_WORD))
7035 int offset = (UNITS_PER_WORD
7036 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
7037 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
7038 plus_constant (XEXP (rtl, 0), offset));
7042 if (rtl == NULL_RTX)
7043 return;
7045 rtl = eliminate_regs (rtl, 0, NULL_RTX);
7046 #ifdef LEAF_REG_REMAP
7047 if (current_function_uses_only_leaf_regs)
7048 leaf_renumber_regs_insn (rtl);
7049 #endif
7051 switch (GET_CODE (rtl))
7053 case ADDRESSOF:
7054 /* The address of a variable that was optimized away; don't emit
7055 anything. */
7056 break;
7058 case CONST_INT:
7059 case CONST_DOUBLE:
7060 case CONST_STRING:
7061 case SYMBOL_REF:
7062 case LABEL_REF:
7063 case CONST:
7064 case PLUS:
7065 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7066 add_const_value_attribute (die, rtl);
7067 break;
7069 case MEM:
7070 case REG:
7071 case SUBREG:
7072 case CONCAT:
7073 add_AT_location_description (die, DW_AT_location, rtl);
7074 break;
7076 default:
7077 abort ();
7081 /* Generate an DW_AT_name attribute given some string value to be included as
7082 the value of the attribute. */
7084 static inline void
7085 add_name_attribute (die, name_string)
7086 register dw_die_ref die;
7087 register const char *name_string;
7089 if (name_string != NULL && *name_string != 0)
7091 if (demangle_name_func)
7092 name_string = (*demangle_name_func) (name_string);
7094 add_AT_string (die, DW_AT_name, name_string);
7098 /* Given a tree node describing an array bound (either lower or upper) output
7099 a representation for that bound. */
7101 static void
7102 add_bound_info (subrange_die, bound_attr, bound)
7103 register dw_die_ref subrange_die;
7104 register enum dwarf_attribute bound_attr;
7105 register tree bound;
7107 register unsigned bound_value = 0;
7109 /* If this is an Ada unconstrained array type, then don't emit any debug
7110 info because the array bounds are unknown. They are parameterized when
7111 the type is instantiated. */
7112 if (contains_placeholder_p (bound))
7113 return;
7115 switch (TREE_CODE (bound))
7117 case ERROR_MARK:
7118 return;
7120 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7121 case INTEGER_CST:
7122 bound_value = TREE_INT_CST_LOW (bound);
7123 if (bound_attr == DW_AT_lower_bound
7124 && ((is_c_family () && bound_value == 0)
7125 || (is_fortran () && bound_value == 1)))
7126 /* use the default */;
7127 else
7128 add_AT_unsigned (subrange_die, bound_attr, bound_value);
7129 break;
7131 case CONVERT_EXPR:
7132 case NOP_EXPR:
7133 case NON_LVALUE_EXPR:
7134 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7135 break;
7137 case SAVE_EXPR:
7138 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7139 access the upper bound values may be bogus. If they refer to a
7140 register, they may only describe how to get at these values at the
7141 points in the generated code right after they have just been
7142 computed. Worse yet, in the typical case, the upper bound values
7143 will not even *be* computed in the optimized code (though the
7144 number of elements will), so these SAVE_EXPRs are entirely
7145 bogus. In order to compensate for this fact, we check here to see
7146 if optimization is enabled, and if so, we don't add an attribute
7147 for the (unknown and unknowable) upper bound. This should not
7148 cause too much trouble for existing (stupid?) debuggers because
7149 they have to deal with empty upper bounds location descriptions
7150 anyway in order to be able to deal with incomplete array types.
7151 Of course an intelligent debugger (GDB?) should be able to
7152 comprehend that a missing upper bound specification in a array
7153 type used for a storage class `auto' local array variable
7154 indicates that the upper bound is both unknown (at compile- time)
7155 and unknowable (at run-time) due to optimization.
7157 We assume that a MEM rtx is safe because gcc wouldn't put the
7158 value there unless it was going to be used repeatedly in the
7159 function, i.e. for cleanups. */
7160 if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
7162 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7163 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7164 register rtx loc = SAVE_EXPR_RTL (bound);
7166 /* If the RTL for the SAVE_EXPR is memory, handle the case where
7167 it references an outer function's frame. */
7169 if (GET_CODE (loc) == MEM)
7171 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
7173 if (XEXP (loc, 0) != new_addr)
7174 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
7177 add_AT_flag (decl_die, DW_AT_artificial, 1);
7178 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
7179 add_AT_location_description (decl_die, DW_AT_location, loc);
7180 add_AT_die_ref (subrange_die, bound_attr, decl_die);
7183 /* Else leave out the attribute. */
7184 break;
7186 case MAX_EXPR:
7187 case VAR_DECL:
7188 case COMPONENT_REF:
7189 /* ??? These types of bounds can be created by the Ada front end,
7190 and it isn't clear how to emit debug info for them. */
7191 break;
7193 default:
7194 abort ();
7198 /* Note that the block of subscript information for an array type also
7199 includes information about the element type of type given array type. */
7201 static void
7202 add_subscript_info (type_die, type)
7203 register dw_die_ref type_die;
7204 register tree type;
7206 #ifndef MIPS_DEBUGGING_INFO
7207 register unsigned dimension_number;
7208 #endif
7209 register tree lower, upper;
7210 register dw_die_ref subrange_die;
7212 /* The GNU compilers represent multidimensional array types as sequences of
7213 one dimensional array types whose element types are themselves array
7214 types. Here we squish that down, so that each multidimensional array
7215 type gets only one array_type DIE in the Dwarf debugging info. The draft
7216 Dwarf specification say that we are allowed to do this kind of
7217 compression in C (because there is no difference between an array or
7218 arrays and a multidimensional array in C) but for other source languages
7219 (e.g. Ada) we probably shouldn't do this. */
7221 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7222 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7223 We work around this by disabling this feature. See also
7224 gen_array_type_die. */
7225 #ifndef MIPS_DEBUGGING_INFO
7226 for (dimension_number = 0;
7227 TREE_CODE (type) == ARRAY_TYPE;
7228 type = TREE_TYPE (type), dimension_number++)
7230 #endif
7231 register tree domain = TYPE_DOMAIN (type);
7233 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7234 and (in GNU C only) variable bounds. Handle all three forms
7235 here. */
7236 subrange_die = new_die (DW_TAG_subrange_type, type_die);
7237 if (domain)
7239 /* We have an array type with specified bounds. */
7240 lower = TYPE_MIN_VALUE (domain);
7241 upper = TYPE_MAX_VALUE (domain);
7243 /* define the index type. */
7244 if (TREE_TYPE (domain))
7246 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7247 TREE_TYPE field. We can't emit debug info for this
7248 because it is an unnamed integral type. */
7249 if (TREE_CODE (domain) == INTEGER_TYPE
7250 && TYPE_NAME (domain) == NULL_TREE
7251 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
7252 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
7254 else
7255 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7256 type_die);
7259 /* ??? If upper is NULL, the array has unspecified length,
7260 but it does have a lower bound. This happens with Fortran
7261 dimension arr(N:*)
7262 Since the debugger is definitely going to need to know N
7263 to produce useful results, go ahead and output the lower
7264 bound solo, and hope the debugger can cope. */
7266 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
7267 if (upper)
7268 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
7270 else
7271 /* We have an array type with an unspecified length. The DWARF-2
7272 spec does not say how to handle this; let's just leave out the
7273 bounds. */
7277 #ifndef MIPS_DEBUGGING_INFO
7279 #endif
7282 static void
7283 add_byte_size_attribute (die, tree_node)
7284 dw_die_ref die;
7285 register tree tree_node;
7287 register unsigned size;
7289 switch (TREE_CODE (tree_node))
7291 case ERROR_MARK:
7292 size = 0;
7293 break;
7294 case ENUMERAL_TYPE:
7295 case RECORD_TYPE:
7296 case UNION_TYPE:
7297 case QUAL_UNION_TYPE:
7298 size = int_size_in_bytes (tree_node);
7299 break;
7300 case FIELD_DECL:
7301 /* For a data member of a struct or union, the DW_AT_byte_size is
7302 generally given as the number of bytes normally allocated for an
7303 object of the *declared* type of the member itself. This is true
7304 even for bit-fields. */
7305 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
7306 break;
7307 default:
7308 abort ();
7311 /* Note that `size' might be -1 when we get to this point. If it is, that
7312 indicates that the byte size of the entity in question is variable. We
7313 have no good way of expressing this fact in Dwarf at the present time,
7314 so just let the -1 pass on through. */
7316 add_AT_unsigned (die, DW_AT_byte_size, size);
7319 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7320 which specifies the distance in bits from the highest order bit of the
7321 "containing object" for the bit-field to the highest order bit of the
7322 bit-field itself.
7324 For any given bit-field, the "containing object" is a hypothetical
7325 object (of some integral or enum type) within which the given bit-field
7326 lives. The type of this hypothetical "containing object" is always the
7327 same as the declared type of the individual bit-field itself. The
7328 determination of the exact location of the "containing object" for a
7329 bit-field is rather complicated. It's handled by the
7330 `field_byte_offset' function (above).
7332 Note that it is the size (in bytes) of the hypothetical "containing object"
7333 which will be given in the DW_AT_byte_size attribute for this bit-field.
7334 (See `byte_size_attribute' above). */
7336 static inline void
7337 add_bit_offset_attribute (die, decl)
7338 register dw_die_ref die;
7339 register tree decl;
7341 register unsigned object_offset_in_bytes = field_byte_offset (decl);
7342 register tree type = DECL_BIT_FIELD_TYPE (decl);
7343 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
7344 register unsigned bitpos_int;
7345 register unsigned highest_order_object_bit_offset;
7346 register unsigned highest_order_field_bit_offset;
7347 register unsigned bit_offset;
7349 /* Must be a field and a bit field. */
7350 if (!type
7351 || TREE_CODE (decl) != FIELD_DECL)
7352 abort ();
7354 /* We can't yet handle bit-fields whose offsets are variable, so if we
7355 encounter such things, just return without generating any attribute
7356 whatsoever. */
7357 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
7358 return;
7360 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
7362 /* Note that the bit offset is always the distance (in bits) from the
7363 highest-order bit of the "containing object" to the highest-order bit of
7364 the bit-field itself. Since the "high-order end" of any object or field
7365 is different on big-endian and little-endian machines, the computation
7366 below must take account of these differences. */
7367 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
7368 highest_order_field_bit_offset = bitpos_int;
7370 if (! BYTES_BIG_ENDIAN)
7372 highest_order_field_bit_offset
7373 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
7375 highest_order_object_bit_offset += simple_type_size_in_bits (type);
7378 bit_offset
7379 = (! BYTES_BIG_ENDIAN
7380 ? highest_order_object_bit_offset - highest_order_field_bit_offset
7381 : highest_order_field_bit_offset - highest_order_object_bit_offset);
7383 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7386 /* For a FIELD_DECL node which represents a bit field, output an attribute
7387 which specifies the length in bits of the given field. */
7389 static inline void
7390 add_bit_size_attribute (die, decl)
7391 register dw_die_ref die;
7392 register tree decl;
7394 /* Must be a field and a bit field. */
7395 if (TREE_CODE (decl) != FIELD_DECL
7396 || ! DECL_BIT_FIELD_TYPE (decl))
7397 abort ();
7398 add_AT_unsigned (die, DW_AT_bit_size,
7399 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
7402 /* If the compiled language is ANSI C, then add a 'prototyped'
7403 attribute, if arg types are given for the parameters of a function. */
7405 static inline void
7406 add_prototyped_attribute (die, func_type)
7407 register dw_die_ref die;
7408 register tree func_type;
7410 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
7411 && TYPE_ARG_TYPES (func_type) != NULL)
7412 add_AT_flag (die, DW_AT_prototyped, 1);
7416 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7417 by looking in either the type declaration or object declaration
7418 equate table. */
7420 static inline void
7421 add_abstract_origin_attribute (die, origin)
7422 register dw_die_ref die;
7423 register tree origin;
7425 dw_die_ref origin_die = NULL;
7427 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
7428 origin_die = lookup_decl_die (origin);
7429 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
7430 origin_die = lookup_type_die (origin);
7432 if (origin_die == NULL)
7433 abort ();
7435 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7438 /* We do not currently support the pure_virtual attribute. */
7440 static inline void
7441 add_pure_or_virtual_attribute (die, func_decl)
7442 register dw_die_ref die;
7443 register tree func_decl;
7445 if (DECL_VINDEX (func_decl))
7447 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7448 add_AT_loc (die, DW_AT_vtable_elem_location,
7449 new_loc_descr (DW_OP_constu,
7450 TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
7451 0));
7453 /* GNU extension: Record what type this method came from originally. */
7454 if (debug_info_level > DINFO_LEVEL_TERSE)
7455 add_AT_die_ref (die, DW_AT_containing_type,
7456 lookup_type_die (DECL_CONTEXT (func_decl)));
7460 /* Add source coordinate attributes for the given decl. */
7462 static void
7463 add_src_coords_attributes (die, decl)
7464 register dw_die_ref die;
7465 register tree decl;
7467 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
7469 add_AT_unsigned (die, DW_AT_decl_file, file_index);
7470 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7473 /* Add an DW_AT_name attribute and source coordinate attribute for the
7474 given decl, but only if it actually has a name. */
7476 static void
7477 add_name_and_src_coords_attributes (die, decl)
7478 register dw_die_ref die;
7479 register tree decl;
7481 register tree decl_name;
7483 decl_name = DECL_NAME (decl);
7484 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
7486 add_name_attribute (die, dwarf2_name (decl, 0));
7487 add_src_coords_attributes (die, decl);
7489 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
7490 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
7491 add_AT_string (die, DW_AT_MIPS_linkage_name,
7492 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7496 /* Push a new declaration scope. */
7498 static void
7499 push_decl_scope (scope)
7500 tree scope;
7502 tree containing_scope;
7503 int i;
7505 /* Make room in the decl_scope_table, if necessary. */
7506 if (decl_scope_table_allocated == decl_scope_depth)
7508 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
7509 decl_scope_table
7510 = (decl_scope_node *) xrealloc (decl_scope_table,
7511 (decl_scope_table_allocated
7512 * sizeof (decl_scope_node)));
7515 decl_scope_table[decl_scope_depth].scope = scope;
7517 /* Sometimes, while recursively emitting subtypes within a class type,
7518 we end up recuring on a subtype at a higher level then the current
7519 subtype. In such a case, we need to search the decl_scope_table to
7520 find the parent of this subtype. */
7522 if (AGGREGATE_TYPE_P (scope))
7523 containing_scope = TYPE_CONTEXT (scope);
7524 else
7525 containing_scope = NULL_TREE;
7527 /* The normal case. */
7528 if (decl_scope_depth == 0
7529 || containing_scope == NULL_TREE
7530 /* Ignore namespaces for the moment. */
7531 || TREE_CODE (containing_scope) == NAMESPACE_DECL
7532 || containing_scope == decl_scope_table[decl_scope_depth - 1].scope)
7533 decl_scope_table[decl_scope_depth].previous = decl_scope_depth - 1;
7534 else
7536 /* We need to search for the containing_scope. */
7537 for (i = 0; i < decl_scope_depth; i++)
7538 if (decl_scope_table[i].scope == containing_scope)
7539 break;
7541 if (i == decl_scope_depth)
7542 abort ();
7543 else
7544 decl_scope_table[decl_scope_depth].previous = i;
7547 decl_scope_depth++;
7550 /* Return the DIE for the scope that immediately contains this declaration. */
7552 static dw_die_ref
7553 scope_die_for (t, context_die)
7554 register tree t;
7555 register dw_die_ref context_die;
7557 register dw_die_ref scope_die = NULL;
7558 register tree containing_scope;
7559 register int i;
7561 /* Walk back up the declaration tree looking for a place to define
7562 this type. */
7563 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
7564 containing_scope = TYPE_CONTEXT (t);
7565 else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t))
7566 containing_scope = decl_class_context (t);
7567 else
7568 containing_scope = DECL_CONTEXT (t);
7570 /* Ignore namespaces for the moment. */
7571 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
7572 containing_scope = NULL_TREE;
7574 /* Ignore function type "scopes" from the C frontend. They mean that
7575 a tagged type is local to a parmlist of a function declarator, but
7576 that isn't useful to DWARF. */
7577 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
7578 containing_scope = NULL_TREE;
7580 /* Function-local tags and functions get stuck in limbo until they are
7581 fixed up by decls_for_scope. */
7582 if (context_die == NULL && containing_scope != NULL_TREE
7583 && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t)))
7584 return NULL;
7586 if (containing_scope == NULL_TREE)
7587 scope_die = comp_unit_die;
7588 else
7590 for (i = decl_scope_depth - 1, scope_die = context_die;
7591 i >= 0 && decl_scope_table[i].scope != containing_scope;
7592 (scope_die = scope_die->die_parent,
7593 i = decl_scope_table[i].previous))
7596 /* ??? Integrate_decl_tree does not handle BLOCK_TYPE_TAGS, nor
7597 does it try to handle types defined by TYPE_DECLs. Such types
7598 thus have an incorrect TYPE_CONTEXT, which points to the block
7599 they were originally defined in, instead of the current block
7600 created by function inlining. We try to detect that here and
7601 work around it. */
7603 if (i < 0 && scope_die == comp_unit_die
7604 && TREE_CODE (containing_scope) == BLOCK
7605 && is_tagged_type (t)
7606 && (block_ultimate_origin (decl_scope_table[decl_scope_depth - 1].scope)
7607 == containing_scope))
7609 scope_die = context_die;
7610 /* Since the checks below are no longer applicable. */
7611 i = 0;
7614 if (i < 0)
7616 if (TREE_CODE_CLASS (TREE_CODE (containing_scope)) != 't')
7617 abort ();
7618 if (debug_info_level > DINFO_LEVEL_TERSE
7619 && !TREE_ASM_WRITTEN (containing_scope))
7620 abort ();
7622 /* If none of the current dies are suitable, we get file scope. */
7623 scope_die = comp_unit_die;
7627 return scope_die;
7630 /* Pop a declaration scope. */
7631 static inline void
7632 pop_decl_scope ()
7634 if (decl_scope_depth <= 0)
7635 abort ();
7636 --decl_scope_depth;
7639 /* Many forms of DIEs require a "type description" attribute. This
7640 routine locates the proper "type descriptor" die for the type given
7641 by 'type', and adds an DW_AT_type attribute below the given die. */
7643 static void
7644 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7645 register dw_die_ref object_die;
7646 register tree type;
7647 register int decl_const;
7648 register int decl_volatile;
7649 register dw_die_ref context_die;
7651 register enum tree_code code = TREE_CODE (type);
7652 register dw_die_ref type_die = NULL;
7654 /* ??? If this type is an unnamed subrange type of an integral or
7655 floating-point type, use the inner type. This is because we have no
7656 support for unnamed types in base_type_die. This can happen if this is
7657 an Ada subrange type. Correct solution is emit a subrange type die. */
7658 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7659 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7660 type = TREE_TYPE (type), code = TREE_CODE (type);
7662 if (code == ERROR_MARK)
7663 return;
7665 /* Handle a special case. For functions whose return type is void, we
7666 generate *no* type attribute. (Note that no object may have type
7667 `void', so this only applies to function return types). */
7668 if (code == VOID_TYPE)
7669 return;
7671 type_die = modified_type_die (type,
7672 decl_const || TYPE_READONLY (type),
7673 decl_volatile || TYPE_VOLATILE (type),
7674 context_die);
7675 if (type_die != NULL)
7676 add_AT_die_ref (object_die, DW_AT_type, type_die);
7679 /* Given a tree pointer to a struct, class, union, or enum type node, return
7680 a pointer to the (string) tag name for the given type, or zero if the type
7681 was declared without a tag. */
7683 static char *
7684 type_tag (type)
7685 register tree type;
7687 register char *name = 0;
7689 if (TYPE_NAME (type) != 0)
7691 register tree t = 0;
7693 /* Find the IDENTIFIER_NODE for the type name. */
7694 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7695 t = TYPE_NAME (type);
7697 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7698 a TYPE_DECL node, regardless of whether or not a `typedef' was
7699 involved. */
7700 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7701 && ! DECL_IGNORED_P (TYPE_NAME (type)))
7702 t = DECL_NAME (TYPE_NAME (type));
7704 /* Now get the name as a string, or invent one. */
7705 if (t != 0)
7706 name = IDENTIFIER_POINTER (t);
7709 return (name == 0 || *name == '\0') ? 0 : name;
7712 /* Return the type associated with a data member, make a special check
7713 for bit field types. */
7715 static inline tree
7716 member_declared_type (member)
7717 register tree member;
7719 return (DECL_BIT_FIELD_TYPE (member)
7720 ? DECL_BIT_FIELD_TYPE (member)
7721 : TREE_TYPE (member));
7724 /* Get the decl's label, as described by its RTL. This may be different
7725 from the DECL_NAME name used in the source file. */
7727 #if 0
7728 static char *
7729 decl_start_label (decl)
7730 register tree decl;
7732 rtx x;
7733 char *fnname;
7734 x = DECL_RTL (decl);
7735 if (GET_CODE (x) != MEM)
7736 abort ();
7738 x = XEXP (x, 0);
7739 if (GET_CODE (x) != SYMBOL_REF)
7740 abort ();
7742 fnname = XSTR (x, 0);
7743 return fnname;
7745 #endif
7747 /* These routines generate the internal representation of the DIE's for
7748 the compilation unit. Debugging information is collected by walking
7749 the declaration trees passed in from dwarf2out_decl(). */
7751 static void
7752 gen_array_type_die (type, context_die)
7753 register tree type;
7754 register dw_die_ref context_die;
7756 register dw_die_ref scope_die = scope_die_for (type, context_die);
7757 register dw_die_ref array_die;
7758 register tree element_type;
7760 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7761 the inner array type comes before the outer array type. Thus we must
7762 call gen_type_die before we call new_die. See below also. */
7763 #ifdef MIPS_DEBUGGING_INFO
7764 gen_type_die (TREE_TYPE (type), context_die);
7765 #endif
7767 array_die = new_die (DW_TAG_array_type, scope_die);
7769 #if 0
7770 /* We default the array ordering. SDB will probably do
7771 the right things even if DW_AT_ordering is not present. It's not even
7772 an issue until we start to get into multidimensional arrays anyway. If
7773 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7774 then we'll have to put the DW_AT_ordering attribute back in. (But if
7775 and when we find out that we need to put these in, we will only do so
7776 for multidimensional arrays. */
7777 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
7778 #endif
7780 #ifdef MIPS_DEBUGGING_INFO
7781 /* The SGI compilers handle arrays of unknown bound by setting
7782 AT_declaration and not emitting any subrange DIEs. */
7783 if (! TYPE_DOMAIN (type))
7784 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7785 else
7786 #endif
7787 add_subscript_info (array_die, type);
7789 add_name_attribute (array_die, type_tag (type));
7790 equate_type_number_to_die (type, array_die);
7792 /* Add representation of the type of the elements of this array type. */
7793 element_type = TREE_TYPE (type);
7795 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7796 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7797 We work around this by disabling this feature. See also
7798 add_subscript_info. */
7799 #ifndef MIPS_DEBUGGING_INFO
7800 while (TREE_CODE (element_type) == ARRAY_TYPE)
7801 element_type = TREE_TYPE (element_type);
7803 gen_type_die (element_type, context_die);
7804 #endif
7806 add_type_attribute (array_die, element_type, 0, 0, context_die);
7809 static void
7810 gen_set_type_die (type, context_die)
7811 register tree type;
7812 register dw_die_ref context_die;
7814 register dw_die_ref type_die
7815 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7817 equate_type_number_to_die (type, type_die);
7818 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7821 #if 0
7822 static void
7823 gen_entry_point_die (decl, context_die)
7824 register tree decl;
7825 register dw_die_ref context_die;
7827 register tree origin = decl_ultimate_origin (decl);
7828 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7829 if (origin != NULL)
7830 add_abstract_origin_attribute (decl_die, origin);
7831 else
7833 add_name_and_src_coords_attributes (decl_die, decl);
7834 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7835 0, 0, context_die);
7838 if (DECL_ABSTRACT (decl))
7839 equate_decl_number_to_die (decl, decl_die);
7840 else
7841 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
7843 #endif
7845 /* Remember a type in the pending_types_list. */
7847 static void
7848 pend_type (type)
7849 register tree type;
7851 if (pending_types == pending_types_allocated)
7853 pending_types_allocated += PENDING_TYPES_INCREMENT;
7854 pending_types_list
7855 = (tree *) xrealloc (pending_types_list,
7856 sizeof (tree) * pending_types_allocated);
7859 pending_types_list[pending_types++] = type;
7862 /* Output any pending types (from the pending_types list) which we can output
7863 now (taking into account the scope that we are working on now).
7865 For each type output, remove the given type from the pending_types_list
7866 *before* we try to output it. */
7868 static void
7869 output_pending_types_for_scope (context_die)
7870 register dw_die_ref context_die;
7872 register tree type;
7874 while (pending_types)
7876 --pending_types;
7877 type = pending_types_list[pending_types];
7878 gen_type_die (type, context_die);
7879 if (!TREE_ASM_WRITTEN (type))
7880 abort ();
7884 /* Remember a type in the incomplete_types_list. */
7886 static void
7887 add_incomplete_type (type)
7888 tree type;
7890 if (incomplete_types == incomplete_types_allocated)
7892 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
7893 incomplete_types_list
7894 = (tree *) xrealloc (incomplete_types_list,
7895 sizeof (tree) * incomplete_types_allocated);
7898 incomplete_types_list[incomplete_types++] = type;
7901 /* Walk through the list of incomplete types again, trying once more to
7902 emit full debugging info for them. */
7904 static void
7905 retry_incomplete_types ()
7907 register tree type;
7909 while (incomplete_types)
7911 --incomplete_types;
7912 type = incomplete_types_list[incomplete_types];
7913 gen_type_die (type, comp_unit_die);
7917 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7919 static void
7920 gen_inlined_enumeration_type_die (type, context_die)
7921 register tree type;
7922 register dw_die_ref context_die;
7924 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
7925 scope_die_for (type, context_die));
7926 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7927 be incomplete and such types are not marked. */
7928 add_abstract_origin_attribute (type_die, type);
7931 /* Generate a DIE to represent an inlined instance of a structure type. */
7933 static void
7934 gen_inlined_structure_type_die (type, context_die)
7935 register tree type;
7936 register dw_die_ref context_die;
7938 register dw_die_ref type_die = new_die (DW_TAG_structure_type,
7939 scope_die_for (type, context_die));
7940 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7941 be incomplete and such types are not marked. */
7942 add_abstract_origin_attribute (type_die, type);
7945 /* Generate a DIE to represent an inlined instance of a union type. */
7947 static void
7948 gen_inlined_union_type_die (type, context_die)
7949 register tree type;
7950 register dw_die_ref context_die;
7952 register dw_die_ref type_die = new_die (DW_TAG_union_type,
7953 scope_die_for (type, context_die));
7954 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7955 be incomplete and such types are not marked. */
7956 add_abstract_origin_attribute (type_die, type);
7959 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7960 include all of the information about the enumeration values also. Each
7961 enumerated type name/value is listed as a child of the enumerated type
7962 DIE. */
7964 static void
7965 gen_enumeration_type_die (type, context_die)
7966 register tree type;
7967 register dw_die_ref context_die;
7969 register dw_die_ref type_die = lookup_type_die (type);
7971 if (type_die == NULL)
7973 type_die = new_die (DW_TAG_enumeration_type,
7974 scope_die_for (type, context_die));
7975 equate_type_number_to_die (type, type_die);
7976 add_name_attribute (type_die, type_tag (type));
7978 else if (! TYPE_SIZE (type))
7979 return;
7980 else
7981 remove_AT (type_die, DW_AT_declaration);
7983 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7984 given enum type is incomplete, do not generate the DW_AT_byte_size
7985 attribute or the DW_AT_element_list attribute. */
7986 if (TYPE_SIZE (type))
7988 register tree link;
7990 TREE_ASM_WRITTEN (type) = 1;
7991 add_byte_size_attribute (type_die, type);
7992 if (TYPE_STUB_DECL (type) != NULL_TREE)
7993 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7995 /* If the first reference to this type was as the return type of an
7996 inline function, then it may not have a parent. Fix this now. */
7997 if (type_die->die_parent == NULL)
7998 add_child_die (scope_die_for (type, context_die), type_die);
8000 for (link = TYPE_FIELDS (type);
8001 link != NULL; link = TREE_CHAIN (link))
8003 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
8005 add_name_attribute (enum_die,
8006 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
8007 add_AT_unsigned (enum_die, DW_AT_const_value,
8008 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
8011 else
8012 add_AT_flag (type_die, DW_AT_declaration, 1);
8016 /* Generate a DIE to represent either a real live formal parameter decl or to
8017 represent just the type of some formal parameter position in some function
8018 type.
8020 Note that this routine is a bit unusual because its argument may be a
8021 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
8022 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
8023 node. If it's the former then this function is being called to output a
8024 DIE to represent a formal parameter object (or some inlining thereof). If
8025 it's the latter, then this function is only being called to output a
8026 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
8027 argument type of some subprogram type. */
8029 static dw_die_ref
8030 gen_formal_parameter_die (node, context_die)
8031 register tree node;
8032 register dw_die_ref context_die;
8034 register dw_die_ref parm_die
8035 = new_die (DW_TAG_formal_parameter, context_die);
8036 register tree origin;
8038 switch (TREE_CODE_CLASS (TREE_CODE (node)))
8040 case 'd':
8041 origin = decl_ultimate_origin (node);
8042 if (origin != NULL)
8043 add_abstract_origin_attribute (parm_die, origin);
8044 else
8046 add_name_and_src_coords_attributes (parm_die, node);
8047 add_type_attribute (parm_die, TREE_TYPE (node),
8048 TREE_READONLY (node),
8049 TREE_THIS_VOLATILE (node),
8050 context_die);
8051 if (DECL_ARTIFICIAL (node))
8052 add_AT_flag (parm_die, DW_AT_artificial, 1);
8055 equate_decl_number_to_die (node, parm_die);
8056 if (! DECL_ABSTRACT (node))
8057 add_location_or_const_value_attribute (parm_die, node);
8059 break;
8061 case 't':
8062 /* We were called with some kind of a ..._TYPE node. */
8063 add_type_attribute (parm_die, node, 0, 0, context_die);
8064 break;
8066 default:
8067 abort ();
8070 return parm_die;
8073 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
8074 at the end of an (ANSI prototyped) formal parameters list. */
8076 static void
8077 gen_unspecified_parameters_die (decl_or_type, context_die)
8078 register tree decl_or_type ATTRIBUTE_UNUSED;
8079 register dw_die_ref context_die;
8081 new_die (DW_TAG_unspecified_parameters, context_die);
8084 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
8085 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
8086 parameters as specified in some function type specification (except for
8087 those which appear as part of a function *definition*).
8089 Note we must be careful here to output all of the parameter DIEs before*
8090 we output any DIEs needed to represent the types of the formal parameters.
8091 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
8092 non-parameter DIE it sees ends the formal parameter list. */
8094 static void
8095 gen_formal_types_die (function_or_method_type, context_die)
8096 register tree function_or_method_type;
8097 register dw_die_ref context_die;
8099 register tree link;
8100 register tree formal_type = NULL;
8101 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
8103 #if 0
8104 /* In the case where we are generating a formal types list for a C++
8105 non-static member function type, skip over the first thing on the
8106 TYPE_ARG_TYPES list because it only represents the type of the hidden
8107 `this pointer'. The debugger should be able to figure out (without
8108 being explicitly told) that this non-static member function type takes a
8109 `this pointer' and should be able to figure what the type of that hidden
8110 parameter is from the DW_AT_member attribute of the parent
8111 DW_TAG_subroutine_type DIE. */
8112 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8113 first_parm_type = TREE_CHAIN (first_parm_type);
8114 #endif
8116 /* Make our first pass over the list of formal parameter types and output a
8117 DW_TAG_formal_parameter DIE for each one. */
8118 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8120 register dw_die_ref parm_die;
8122 formal_type = TREE_VALUE (link);
8123 if (formal_type == void_type_node)
8124 break;
8126 /* Output a (nameless) DIE to represent the formal parameter itself. */
8127 parm_die = gen_formal_parameter_die (formal_type, context_die);
8128 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8129 && link == first_parm_type)
8130 add_AT_flag (parm_die, DW_AT_artificial, 1);
8133 /* If this function type has an ellipsis, add a
8134 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8135 if (formal_type != void_type_node)
8136 gen_unspecified_parameters_die (function_or_method_type, context_die);
8138 /* Make our second (and final) pass over the list of formal parameter types
8139 and output DIEs to represent those types (as necessary). */
8140 for (link = TYPE_ARG_TYPES (function_or_method_type);
8141 link;
8142 link = TREE_CHAIN (link))
8144 formal_type = TREE_VALUE (link);
8145 if (formal_type == void_type_node)
8146 break;
8148 gen_type_die (formal_type, context_die);
8152 /* Generate a DIE to represent a declared function (either file-scope or
8153 block-local). */
8155 static void
8156 gen_subprogram_die (decl, context_die)
8157 register tree decl;
8158 register dw_die_ref context_die;
8160 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
8161 register tree origin = decl_ultimate_origin (decl);
8162 register dw_die_ref subr_die;
8163 register rtx fp_reg;
8164 register tree fn_arg_types;
8165 register tree outer_scope;
8166 register dw_die_ref old_die = lookup_decl_die (decl);
8167 register int declaration
8168 = (current_function_decl != decl
8169 || (context_die
8170 && (context_die->die_tag == DW_TAG_structure_type
8171 || context_die->die_tag == DW_TAG_union_type)));
8173 if (origin != NULL)
8175 subr_die = new_die (DW_TAG_subprogram, context_die);
8176 add_abstract_origin_attribute (subr_die, origin);
8178 else if (old_die && DECL_ABSTRACT (decl)
8179 && get_AT_unsigned (old_die, DW_AT_inline))
8181 /* This must be a redefinition of an extern inline function.
8182 We can just reuse the old die here. */
8183 subr_die = old_die;
8185 /* Clear out the inlined attribute and parm types. */
8186 remove_AT (subr_die, DW_AT_inline);
8187 remove_children (subr_die);
8189 else if (old_die)
8191 register unsigned file_index
8192 = lookup_filename (DECL_SOURCE_FILE (decl));
8194 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
8196 /* ??? This can happen if there is a bug in the program, for
8197 instance, if it has duplicate function definitions. Ideally,
8198 we should detect this case and ignore it. For now, if we have
8199 already reported an error, any error at all, then assume that
8200 we got here because of a input error, not a dwarf2 bug. */
8201 if (errorcount)
8202 return;
8203 abort ();
8206 /* If the definition comes from the same place as the declaration,
8207 maybe use the old DIE. We always want the DIE for this function
8208 that has the *_pc attributes to be under comp_unit_die so the
8209 debugger can find it. For inlines, that is the concrete instance,
8210 so we can use the old DIE here. For non-inline methods, we want a
8211 specification DIE at toplevel, so we need a new DIE. For local
8212 class methods, this does not apply. */
8213 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
8214 || context_die == NULL)
8215 && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
8216 && (get_AT_unsigned (old_die, DW_AT_decl_line)
8217 == (unsigned)DECL_SOURCE_LINE (decl)))
8219 subr_die = old_die;
8221 /* Clear out the declaration attribute and the parm types. */
8222 remove_AT (subr_die, DW_AT_declaration);
8223 remove_children (subr_die);
8225 else
8227 subr_die = new_die (DW_TAG_subprogram, context_die);
8228 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
8229 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8230 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
8231 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8232 != (unsigned)DECL_SOURCE_LINE (decl))
8233 add_AT_unsigned
8234 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8237 else
8239 register dw_die_ref scope_die;
8241 if (DECL_CONTEXT (decl))
8242 scope_die = scope_die_for (decl, context_die);
8243 else
8244 /* Don't put block extern declarations under comp_unit_die. */
8245 scope_die = context_die;
8247 subr_die = new_die (DW_TAG_subprogram, scope_die);
8249 if (TREE_PUBLIC (decl))
8250 add_AT_flag (subr_die, DW_AT_external, 1);
8252 add_name_and_src_coords_attributes (subr_die, decl);
8253 if (debug_info_level > DINFO_LEVEL_TERSE)
8255 register tree type = TREE_TYPE (decl);
8257 add_prototyped_attribute (subr_die, type);
8258 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
8261 add_pure_or_virtual_attribute (subr_die, decl);
8262 if (DECL_ARTIFICIAL (decl))
8263 add_AT_flag (subr_die, DW_AT_artificial, 1);
8264 if (TREE_PROTECTED (decl))
8265 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
8266 else if (TREE_PRIVATE (decl))
8267 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
8270 if (declaration)
8272 add_AT_flag (subr_die, DW_AT_declaration, 1);
8274 /* The first time we see a member function, it is in the context of
8275 the class to which it belongs. We make sure of this by emitting
8276 the class first. The next time is the definition, which is
8277 handled above. The two may come from the same source text. */
8278 if (DECL_CONTEXT (decl))
8279 equate_decl_number_to_die (decl, subr_die);
8281 else if (DECL_ABSTRACT (decl))
8283 /* ??? Checking DECL_DEFER_OUTPUT is correct for static inline functions,
8284 but not for extern inline functions. We can't get this completely
8285 correct because information about whether the function was declared
8286 inline is not saved anywhere. */
8287 if (DECL_DEFER_OUTPUT (decl))
8289 if (DECL_INLINE (decl) && !flag_no_inline)
8290 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8291 else
8292 add_AT_unsigned (subr_die, DW_AT_inline,
8293 DW_INL_declared_not_inlined);
8295 else if (DECL_INLINE (decl) && !flag_no_inline)
8296 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8297 else
8298 abort ();
8300 equate_decl_number_to_die (decl, subr_die);
8302 else if (!DECL_EXTERNAL (decl))
8304 if (origin == NULL_TREE)
8305 equate_decl_number_to_die (decl, subr_die);
8307 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8308 current_funcdef_number);
8309 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
8310 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8311 current_funcdef_number);
8312 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8314 add_pubname (decl, subr_die);
8315 add_arange (decl, subr_die);
8317 #ifdef MIPS_DEBUGGING_INFO
8318 /* Add a reference to the FDE for this routine. */
8319 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8320 #endif
8322 /* Define the "frame base" location for this routine. We use the
8323 frame pointer or stack pointer registers, since the RTL for local
8324 variables is relative to one of them. */
8325 fp_reg
8326 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8327 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
8329 #if 0
8330 /* ??? This fails for nested inline functions, because context_display
8331 is not part of the state saved/restored for inline functions. */
8332 if (current_function_needs_context)
8333 add_AT_location_description (subr_die, DW_AT_static_link,
8334 lookup_static_chain (decl));
8335 #endif
8338 /* Now output descriptions of the arguments for this function. This gets
8339 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8340 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8341 `...' at the end of the formal parameter list. In order to find out if
8342 there was a trailing ellipsis or not, we must instead look at the type
8343 associated with the FUNCTION_DECL. This will be a node of type
8344 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8345 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8346 an ellipsis at the end. */
8347 push_decl_scope (decl);
8349 /* In the case where we are describing a mere function declaration, all we
8350 need to do here (and all we *can* do here) is to describe the *types* of
8351 its formal parameters. */
8352 if (debug_info_level <= DINFO_LEVEL_TERSE)
8354 else if (declaration)
8355 gen_formal_types_die (TREE_TYPE (decl), subr_die);
8356 else
8358 /* Generate DIEs to represent all known formal parameters */
8359 register tree arg_decls = DECL_ARGUMENTS (decl);
8360 register tree parm;
8362 /* When generating DIEs, generate the unspecified_parameters DIE
8363 instead if we come across the arg "__builtin_va_alist" */
8364 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
8365 if (TREE_CODE (parm) == PARM_DECL)
8367 if (DECL_NAME (parm)
8368 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8369 "__builtin_va_alist"))
8370 gen_unspecified_parameters_die (parm, subr_die);
8371 else
8372 gen_decl_die (parm, subr_die);
8375 /* Decide whether we need a unspecified_parameters DIE at the end.
8376 There are 2 more cases to do this for: 1) the ansi ... declaration -
8377 this is detectable when the end of the arg list is not a
8378 void_type_node 2) an unprototyped function declaration (not a
8379 definition). This just means that we have no info about the
8380 parameters at all. */
8381 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
8382 if (fn_arg_types != NULL)
8384 /* this is the prototyped case, check for ... */
8385 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
8386 gen_unspecified_parameters_die (decl, subr_die);
8388 else if (DECL_INITIAL (decl) == NULL_TREE)
8389 gen_unspecified_parameters_die (decl, subr_die);
8392 /* Output Dwarf info for all of the stuff within the body of the function
8393 (if it has one - it may be just a declaration). */
8394 outer_scope = DECL_INITIAL (decl);
8396 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8397 node created to represent a function. This outermost BLOCK actually
8398 represents the outermost binding contour for the function, i.e. the
8399 contour in which the function's formal parameters and labels get
8400 declared. Curiously, it appears that the front end doesn't actually
8401 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8402 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8403 list for the function instead.) The BLOCK_VARS list for the
8404 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8405 the function however, and we output DWARF info for those in
8406 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8407 node representing the function's outermost pair of curly braces, and
8408 any blocks used for the base and member initializers of a C++
8409 constructor function. */
8410 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
8412 current_function_has_inlines = 0;
8413 decls_for_scope (outer_scope, subr_die, 0);
8415 #if 0 && defined (MIPS_DEBUGGING_INFO)
8416 if (current_function_has_inlines)
8418 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8419 if (! comp_unit_has_inlines)
8421 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8422 comp_unit_has_inlines = 1;
8425 #endif
8428 pop_decl_scope ();
8431 /* Generate a DIE to represent a declared data object. */
8433 static void
8434 gen_variable_die (decl, context_die)
8435 register tree decl;
8436 register dw_die_ref context_die;
8438 register tree origin = decl_ultimate_origin (decl);
8439 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
8441 dw_die_ref old_die = lookup_decl_die (decl);
8442 int declaration
8443 = (DECL_EXTERNAL (decl)
8444 || current_function_decl != decl_function_context (decl)
8445 || context_die->die_tag == DW_TAG_structure_type
8446 || context_die->die_tag == DW_TAG_union_type);
8448 if (origin != NULL)
8449 add_abstract_origin_attribute (var_die, origin);
8450 /* Loop unrolling can create multiple blocks that refer to the same
8451 static variable, so we must test for the DW_AT_declaration flag. */
8452 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8453 copy decls and set the DECL_ABSTRACT flag on them instead of
8454 sharing them. */
8455 else if (old_die && TREE_STATIC (decl)
8456 && get_AT_flag (old_die, DW_AT_declaration) == 1)
8458 /* This is a definition of a C++ class level static. */
8459 add_AT_die_ref (var_die, DW_AT_specification, old_die);
8460 if (DECL_NAME (decl))
8462 register unsigned file_index
8463 = lookup_filename (DECL_SOURCE_FILE (decl));
8465 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8466 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
8468 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8469 != (unsigned)DECL_SOURCE_LINE (decl))
8471 add_AT_unsigned (var_die, DW_AT_decl_line,
8472 DECL_SOURCE_LINE (decl));
8475 else
8477 add_name_and_src_coords_attributes (var_die, decl);
8478 add_type_attribute (var_die, TREE_TYPE (decl),
8479 TREE_READONLY (decl),
8480 TREE_THIS_VOLATILE (decl), context_die);
8482 if (TREE_PUBLIC (decl))
8483 add_AT_flag (var_die, DW_AT_external, 1);
8485 if (DECL_ARTIFICIAL (decl))
8486 add_AT_flag (var_die, DW_AT_artificial, 1);
8488 if (TREE_PROTECTED (decl))
8489 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
8491 else if (TREE_PRIVATE (decl))
8492 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
8495 if (declaration)
8496 add_AT_flag (var_die, DW_AT_declaration, 1);
8498 if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl))
8499 equate_decl_number_to_die (decl, var_die);
8501 if (! declaration && ! DECL_ABSTRACT (decl))
8503 equate_decl_number_to_die (decl, var_die);
8504 add_location_or_const_value_attribute (var_die, decl);
8505 add_pubname (decl, var_die);
8509 /* Generate a DIE to represent a label identifier. */
8511 static void
8512 gen_label_die (decl, context_die)
8513 register tree decl;
8514 register dw_die_ref context_die;
8516 register tree origin = decl_ultimate_origin (decl);
8517 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8518 register rtx insn;
8519 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8520 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
8522 if (origin != NULL)
8523 add_abstract_origin_attribute (lbl_die, origin);
8524 else
8525 add_name_and_src_coords_attributes (lbl_die, decl);
8527 if (DECL_ABSTRACT (decl))
8528 equate_decl_number_to_die (decl, lbl_die);
8529 else
8531 insn = DECL_RTL (decl);
8533 /* Deleted labels are programmer specified labels which have been
8534 eliminated because of various optimisations. We still emit them
8535 here so that it is possible to put breakpoints on them. */
8536 if (GET_CODE (insn) == CODE_LABEL
8537 || ((GET_CODE (insn) == NOTE
8538 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
8540 /* When optimization is enabled (via -O) some parts of the compiler
8541 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8542 represent source-level labels which were explicitly declared by
8543 the user. This really shouldn't be happening though, so catch
8544 it if it ever does happen. */
8545 if (INSN_DELETED_P (insn))
8546 abort ();
8548 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8549 ASM_GENERATE_INTERNAL_LABEL (label, label2,
8550 (unsigned) INSN_UID (insn));
8551 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8556 /* Generate a DIE for a lexical block. */
8558 static void
8559 gen_lexical_block_die (stmt, context_die, depth)
8560 register tree stmt;
8561 register dw_die_ref context_die;
8562 int depth;
8564 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8565 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8567 if (! BLOCK_ABSTRACT (stmt))
8569 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8570 next_block_number);
8571 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
8572 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
8573 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8576 push_decl_scope (stmt);
8577 decls_for_scope (stmt, stmt_die, depth);
8578 pop_decl_scope ();
8581 /* Generate a DIE for an inlined subprogram. */
8583 static void
8584 gen_inlined_subroutine_die (stmt, context_die, depth)
8585 register tree stmt;
8586 register dw_die_ref context_die;
8587 int depth;
8589 if (! BLOCK_ABSTRACT (stmt))
8591 register dw_die_ref subr_die
8592 = new_die (DW_TAG_inlined_subroutine, context_die);
8593 register tree decl = block_ultimate_origin (stmt);
8594 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8596 add_abstract_origin_attribute (subr_die, decl);
8597 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8598 next_block_number);
8599 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
8600 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
8601 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
8602 push_decl_scope (decl);
8603 decls_for_scope (stmt, subr_die, depth);
8604 pop_decl_scope ();
8605 current_function_has_inlines = 1;
8609 /* Generate a DIE for a field in a record, or structure. */
8611 static void
8612 gen_field_die (decl, context_die)
8613 register tree decl;
8614 register dw_die_ref context_die;
8616 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
8618 add_name_and_src_coords_attributes (decl_die, decl);
8619 add_type_attribute (decl_die, member_declared_type (decl),
8620 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8621 context_die);
8623 /* If this is a bit field... */
8624 if (DECL_BIT_FIELD_TYPE (decl))
8626 add_byte_size_attribute (decl_die, decl);
8627 add_bit_size_attribute (decl_die, decl);
8628 add_bit_offset_attribute (decl_die, decl);
8631 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8632 add_data_member_location_attribute (decl_die, decl);
8634 if (DECL_ARTIFICIAL (decl))
8635 add_AT_flag (decl_die, DW_AT_artificial, 1);
8637 if (TREE_PROTECTED (decl))
8638 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
8640 else if (TREE_PRIVATE (decl))
8641 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
8644 #if 0
8645 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8646 Use modified_type_die instead.
8647 We keep this code here just in case these types of DIEs may be needed to
8648 represent certain things in other languages (e.g. Pascal) someday. */
8649 static void
8650 gen_pointer_type_die (type, context_die)
8651 register tree type;
8652 register dw_die_ref context_die;
8654 register dw_die_ref ptr_die
8655 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8657 equate_type_number_to_die (type, ptr_die);
8658 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8659 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8662 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8663 Use modified_type_die instead.
8664 We keep this code here just in case these types of DIEs may be needed to
8665 represent certain things in other languages (e.g. Pascal) someday. */
8666 static void
8667 gen_reference_type_die (type, context_die)
8668 register tree type;
8669 register dw_die_ref context_die;
8671 register dw_die_ref ref_die
8672 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8674 equate_type_number_to_die (type, ref_die);
8675 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
8676 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8678 #endif
8680 /* Generate a DIE for a pointer to a member type. */
8681 static void
8682 gen_ptr_to_mbr_type_die (type, context_die)
8683 register tree type;
8684 register dw_die_ref context_die;
8686 register dw_die_ref ptr_die
8687 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8689 equate_type_number_to_die (type, ptr_die);
8690 add_AT_die_ref (ptr_die, DW_AT_containing_type,
8691 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8692 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8695 /* Generate the DIE for the compilation unit. */
8697 static void
8698 gen_compile_unit_die (main_input_filename)
8699 register char *main_input_filename;
8701 char producer[250];
8702 char *wd = getpwd ();
8704 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
8705 add_name_attribute (comp_unit_die, main_input_filename);
8707 if (wd != NULL)
8708 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
8710 sprintf (producer, "%s %s", language_string, version_string);
8712 #ifdef MIPS_DEBUGGING_INFO
8713 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8714 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8715 not appear in the producer string, the debugger reaches the conclusion
8716 that the object file is stripped and has no debugging information.
8717 To get the MIPS/SGI debugger to believe that there is debugging
8718 information in the object file, we add a -g to the producer string. */
8719 if (debug_info_level > DINFO_LEVEL_TERSE)
8720 strcat (producer, " -g");
8721 #endif
8723 add_AT_string (comp_unit_die, DW_AT_producer, producer);
8725 if (strcmp (language_string, "GNU C++") == 0)
8726 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
8728 else if (strcmp (language_string, "GNU Ada") == 0)
8729 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
8731 else if (strcmp (language_string, "GNU F77") == 0)
8732 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77);
8734 else if (strcmp (language_string, "GNU Pascal") == 0)
8735 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Pascal83);
8737 else if (flag_traditional)
8738 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
8740 else
8741 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
8743 #if 0 /* unimplemented */
8744 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
8745 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
8746 #endif
8749 /* Generate a DIE for a string type. */
8751 static void
8752 gen_string_type_die (type, context_die)
8753 register tree type;
8754 register dw_die_ref context_die;
8756 register dw_die_ref type_die
8757 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
8759 equate_type_number_to_die (type, type_die);
8761 /* Fudge the string length attribute for now. */
8763 /* TODO: add string length info.
8764 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8765 bound_representation (upper_bound, 0, 'u'); */
8768 /* Generate the DIE for a base class. */
8770 static void
8771 gen_inheritance_die (binfo, context_die)
8772 register tree binfo;
8773 register dw_die_ref context_die;
8775 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
8777 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
8778 add_data_member_location_attribute (die, binfo);
8780 if (TREE_VIA_VIRTUAL (binfo))
8781 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8782 if (TREE_VIA_PUBLIC (binfo))
8783 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
8784 else if (TREE_VIA_PROTECTED (binfo))
8785 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
8788 /* Generate a DIE for a class member. */
8790 static void
8791 gen_member_die (type, context_die)
8792 register tree type;
8793 register dw_die_ref context_die;
8795 register tree member;
8797 /* If this is not an incomplete type, output descriptions of each of its
8798 members. Note that as we output the DIEs necessary to represent the
8799 members of this record or union type, we will also be trying to output
8800 DIEs to represent the *types* of those members. However the `type'
8801 function (above) will specifically avoid generating type DIEs for member
8802 types *within* the list of member DIEs for this (containing) type execpt
8803 for those types (of members) which are explicitly marked as also being
8804 members of this (containing) type themselves. The g++ front- end can
8805 force any given type to be treated as a member of some other
8806 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8807 to point to the TREE node representing the appropriate (containing)
8808 type. */
8810 /* First output info about the base classes. */
8811 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
8813 register tree bases = TYPE_BINFO_BASETYPES (type);
8814 register int n_bases = TREE_VEC_LENGTH (bases);
8815 register int i;
8817 for (i = 0; i < n_bases; i++)
8818 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
8821 /* Now output info about the data members and type members. */
8822 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
8823 gen_decl_die (member, context_die);
8825 /* Now output info about the function members (if any). */
8826 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
8827 gen_decl_die (member, context_die);
8830 /* Generate a DIE for a structure or union type. */
8832 static void
8833 gen_struct_or_union_type_die (type, context_die)
8834 register tree type;
8835 register dw_die_ref context_die;
8837 register dw_die_ref type_die = lookup_type_die (type);
8838 register dw_die_ref scope_die = 0;
8839 register int nested = 0;
8841 if (type_die && ! TYPE_SIZE (type))
8842 return;
8844 if (TYPE_CONTEXT (type) != NULL_TREE
8845 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
8846 nested = 1;
8848 scope_die = scope_die_for (type, context_die);
8850 if (! type_die || (nested && scope_die == comp_unit_die))
8851 /* First occurrence of type or toplevel definition of nested class. */
8853 register dw_die_ref old_die = type_die;
8855 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8856 ? DW_TAG_structure_type : DW_TAG_union_type,
8857 scope_die);
8858 equate_type_number_to_die (type, type_die);
8859 add_name_attribute (type_die, type_tag (type));
8860 if (old_die)
8861 add_AT_die_ref (type_die, DW_AT_specification, old_die);
8863 else
8864 remove_AT (type_die, DW_AT_declaration);
8866 /* If we're not in the right context to be defining this type, defer to
8867 avoid tricky recursion. */
8868 if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die)
8870 add_AT_flag (type_die, DW_AT_declaration, 1);
8871 pend_type (type);
8873 /* If this type has been completed, then give it a byte_size attribute and
8874 then give a list of members. */
8875 else if (TYPE_SIZE (type))
8877 /* Prevent infinite recursion in cases where the type of some member of
8878 this type is expressed in terms of this type itself. */
8879 TREE_ASM_WRITTEN (type) = 1;
8880 add_byte_size_attribute (type_die, type);
8881 if (TYPE_STUB_DECL (type) != NULL_TREE)
8882 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8884 /* If the first reference to this type was as the return type of an
8885 inline function, then it may not have a parent. Fix this now. */
8886 if (type_die->die_parent == NULL)
8887 add_child_die (scope_die, type_die);
8889 push_decl_scope (type);
8890 gen_member_die (type, type_die);
8891 pop_decl_scope ();
8893 /* GNU extension: Record what type our vtable lives in. */
8894 if (TYPE_VFIELD (type))
8896 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
8898 gen_type_die (vtype, context_die);
8899 add_AT_die_ref (type_die, DW_AT_containing_type,
8900 lookup_type_die (vtype));
8903 else
8905 add_AT_flag (type_die, DW_AT_declaration, 1);
8907 /* We can't do this for function-local types, and we don't need to. */
8908 if (TREE_PERMANENT (type))
8909 add_incomplete_type (type);
8913 /* Generate a DIE for a subroutine _type_. */
8915 static void
8916 gen_subroutine_type_die (type, context_die)
8917 register tree type;
8918 register dw_die_ref context_die;
8920 register tree return_type = TREE_TYPE (type);
8921 register dw_die_ref subr_die
8922 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8924 equate_type_number_to_die (type, subr_die);
8925 add_prototyped_attribute (subr_die, type);
8926 add_type_attribute (subr_die, return_type, 0, 0, context_die);
8927 gen_formal_types_die (type, subr_die);
8930 /* Generate a DIE for a type definition */
8932 static void
8933 gen_typedef_die (decl, context_die)
8934 register tree decl;
8935 register dw_die_ref context_die;
8937 register dw_die_ref type_die;
8938 register tree origin;
8940 if (TREE_ASM_WRITTEN (decl))
8941 return;
8942 TREE_ASM_WRITTEN (decl) = 1;
8944 type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
8945 origin = decl_ultimate_origin (decl);
8946 if (origin != NULL)
8947 add_abstract_origin_attribute (type_die, origin);
8948 else
8950 register tree type;
8951 add_name_and_src_coords_attributes (type_die, decl);
8952 if (DECL_ORIGINAL_TYPE (decl))
8954 type = DECL_ORIGINAL_TYPE (decl);
8955 equate_type_number_to_die (TREE_TYPE (decl), type_die);
8957 else
8958 type = TREE_TYPE (decl);
8959 add_type_attribute (type_die, type, TREE_READONLY (decl),
8960 TREE_THIS_VOLATILE (decl), context_die);
8963 if (DECL_ABSTRACT (decl))
8964 equate_decl_number_to_die (decl, type_die);
8967 /* Generate a type description DIE. */
8969 static void
8970 gen_type_die (type, context_die)
8971 register tree type;
8972 register dw_die_ref context_die;
8974 if (type == NULL_TREE || type == error_mark_node)
8975 return;
8977 /* We are going to output a DIE to represent the unqualified version of
8978 this type (i.e. without any const or volatile qualifiers) so get the
8979 main variant (i.e. the unqualified version) of this type now. */
8980 type = type_main_variant (type);
8982 if (TREE_ASM_WRITTEN (type))
8983 return;
8985 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8986 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8988 TREE_ASM_WRITTEN (type) = 1;
8989 gen_decl_die (TYPE_NAME (type), context_die);
8990 return;
8993 switch (TREE_CODE (type))
8995 case ERROR_MARK:
8996 break;
8998 case POINTER_TYPE:
8999 case REFERENCE_TYPE:
9000 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
9001 ensures that the gen_type_die recursion will terminate even if the
9002 type is recursive. Recursive types are possible in Ada. */
9003 /* ??? We could perhaps do this for all types before the switch
9004 statement. */
9005 TREE_ASM_WRITTEN (type) = 1;
9007 /* For these types, all that is required is that we output a DIE (or a
9008 set of DIEs) to represent the "basis" type. */
9009 gen_type_die (TREE_TYPE (type), context_die);
9010 break;
9012 case OFFSET_TYPE:
9013 /* This code is used for C++ pointer-to-data-member types.
9014 Output a description of the relevant class type. */
9015 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
9017 /* Output a description of the type of the object pointed to. */
9018 gen_type_die (TREE_TYPE (type), context_die);
9020 /* Now output a DIE to represent this pointer-to-data-member type
9021 itself. */
9022 gen_ptr_to_mbr_type_die (type, context_die);
9023 break;
9025 case SET_TYPE:
9026 gen_type_die (TYPE_DOMAIN (type), context_die);
9027 gen_set_type_die (type, context_die);
9028 break;
9030 case FILE_TYPE:
9031 gen_type_die (TREE_TYPE (type), context_die);
9032 abort (); /* No way to represent these in Dwarf yet! */
9033 break;
9035 case FUNCTION_TYPE:
9036 /* Force out return type (in case it wasn't forced out already). */
9037 gen_type_die (TREE_TYPE (type), context_die);
9038 gen_subroutine_type_die (type, context_die);
9039 break;
9041 case METHOD_TYPE:
9042 /* Force out return type (in case it wasn't forced out already). */
9043 gen_type_die (TREE_TYPE (type), context_die);
9044 gen_subroutine_type_die (type, context_die);
9045 break;
9047 case ARRAY_TYPE:
9048 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
9050 gen_type_die (TREE_TYPE (type), context_die);
9051 gen_string_type_die (type, context_die);
9053 else
9054 gen_array_type_die (type, context_die);
9055 break;
9057 case ENUMERAL_TYPE:
9058 case RECORD_TYPE:
9059 case UNION_TYPE:
9060 case QUAL_UNION_TYPE:
9061 /* If this is a nested type whose containing class hasn't been
9062 written out yet, writing it out will cover this one, too. */
9063 if (TYPE_CONTEXT (type)
9064 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9065 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9067 gen_type_die (TYPE_CONTEXT (type), context_die);
9069 if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9070 return;
9072 /* If that failed, attach ourselves to the stub. */
9073 push_decl_scope (TYPE_CONTEXT (type));
9074 context_die = lookup_type_die (TYPE_CONTEXT (type));
9077 if (TREE_CODE (type) == ENUMERAL_TYPE)
9078 gen_enumeration_type_die (type, context_die);
9079 else
9080 gen_struct_or_union_type_die (type, context_die);
9082 if (TYPE_CONTEXT (type)
9083 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9084 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9085 pop_decl_scope ();
9087 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9088 it up if it is ever completed. gen_*_type_die will set it for us
9089 when appropriate. */
9090 return;
9092 case VOID_TYPE:
9093 case INTEGER_TYPE:
9094 case REAL_TYPE:
9095 case COMPLEX_TYPE:
9096 case BOOLEAN_TYPE:
9097 case CHAR_TYPE:
9098 /* No DIEs needed for fundamental types. */
9099 break;
9101 case LANG_TYPE:
9102 /* No Dwarf representation currently defined. */
9103 break;
9105 default:
9106 abort ();
9109 TREE_ASM_WRITTEN (type) = 1;
9112 /* Generate a DIE for a tagged type instantiation. */
9114 static void
9115 gen_tagged_type_instantiation_die (type, context_die)
9116 register tree type;
9117 register dw_die_ref context_die;
9119 if (type == NULL_TREE || type == error_mark_node)
9120 return;
9122 /* We are going to output a DIE to represent the unqualified version of
9123 this type (i.e. without any const or volatile qualifiers) so make sure
9124 that we have the main variant (i.e. the unqualified version) of this
9125 type now. */
9126 if (type != type_main_variant (type))
9127 abort ();
9129 /* Do not check TREE_ASM_WRITTEN(type) as it may not be set if this is
9130 an instance of an unresolved type. */
9132 switch (TREE_CODE (type))
9134 case ERROR_MARK:
9135 break;
9137 case ENUMERAL_TYPE:
9138 gen_inlined_enumeration_type_die (type, context_die);
9139 break;
9141 case RECORD_TYPE:
9142 gen_inlined_structure_type_die (type, context_die);
9143 break;
9145 case UNION_TYPE:
9146 case QUAL_UNION_TYPE:
9147 gen_inlined_union_type_die (type, context_die);
9148 break;
9150 default:
9151 abort ();
9155 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9156 things which are local to the given block. */
9158 static void
9159 gen_block_die (stmt, context_die, depth)
9160 register tree stmt;
9161 register dw_die_ref context_die;
9162 int depth;
9164 register int must_output_die = 0;
9165 register tree origin;
9166 register tree decl;
9167 register enum tree_code origin_code;
9169 /* Ignore blocks never really used to make RTL. */
9171 if (stmt == NULL_TREE || !TREE_USED (stmt))
9172 return;
9174 /* Determine the "ultimate origin" of this block. This block may be an
9175 inlined instance of an inlined instance of inline function, so we have
9176 to trace all of the way back through the origin chain to find out what
9177 sort of node actually served as the original seed for the creation of
9178 the current block. */
9179 origin = block_ultimate_origin (stmt);
9180 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
9182 /* Determine if we need to output any Dwarf DIEs at all to represent this
9183 block. */
9184 if (origin_code == FUNCTION_DECL)
9185 /* The outer scopes for inlinings *must* always be represented. We
9186 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9187 must_output_die = 1;
9188 else
9190 /* In the case where the current block represents an inlining of the
9191 "body block" of an inline function, we must *NOT* output any DIE for
9192 this block because we have already output a DIE to represent the
9193 whole inlined function scope and the "body block" of any function
9194 doesn't really represent a different scope according to ANSI C
9195 rules. So we check here to make sure that this block does not
9196 represent a "body block inlining" before trying to set the
9197 `must_output_die' flag. */
9198 if (! is_body_block (origin ? origin : stmt))
9200 /* Determine if this block directly contains any "significant"
9201 local declarations which we will need to output DIEs for. */
9202 if (debug_info_level > DINFO_LEVEL_TERSE)
9203 /* We are not in terse mode so *any* local declaration counts
9204 as being a "significant" one. */
9205 must_output_die = (BLOCK_VARS (stmt) != NULL);
9206 else
9207 /* We are in terse mode, so only local (nested) function
9208 definitions count as "significant" local declarations. */
9209 for (decl = BLOCK_VARS (stmt);
9210 decl != NULL; decl = TREE_CHAIN (decl))
9211 if (TREE_CODE (decl) == FUNCTION_DECL
9212 && DECL_INITIAL (decl))
9214 must_output_die = 1;
9215 break;
9220 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9221 DIE for any block which contains no significant local declarations at
9222 all. Rather, in such cases we just call `decls_for_scope' so that any
9223 needed Dwarf info for any sub-blocks will get properly generated. Note
9224 that in terse mode, our definition of what constitutes a "significant"
9225 local declaration gets restricted to include only inlined function
9226 instances and local (nested) function definitions. */
9227 if (must_output_die)
9229 if (origin_code == FUNCTION_DECL)
9230 gen_inlined_subroutine_die (stmt, context_die, depth);
9231 else
9232 gen_lexical_block_die (stmt, context_die, depth);
9234 else
9235 decls_for_scope (stmt, context_die, depth);
9238 /* Generate all of the decls declared within a given scope and (recursively)
9239 all of its sub-blocks. */
9241 static void
9242 decls_for_scope (stmt, context_die, depth)
9243 register tree stmt;
9244 register dw_die_ref context_die;
9245 int depth;
9247 register tree decl;
9248 register tree subblocks;
9250 /* Ignore blocks never really used to make RTL. */
9251 if (stmt == NULL_TREE || ! TREE_USED (stmt))
9252 return;
9254 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
9255 next_block_number++;
9257 /* Output the DIEs to represent all of the data objects and typedefs
9258 declared directly within this block but not within any nested
9259 sub-blocks. Also, nested function and tag DIEs have been
9260 generated with a parent of NULL; fix that up now. */
9261 for (decl = BLOCK_VARS (stmt);
9262 decl != NULL; decl = TREE_CHAIN (decl))
9264 register dw_die_ref die;
9266 if (TREE_CODE (decl) == FUNCTION_DECL)
9267 die = lookup_decl_die (decl);
9268 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9269 die = lookup_type_die (TREE_TYPE (decl));
9270 else
9271 die = NULL;
9273 if (die != NULL && die->die_parent == NULL)
9274 add_child_die (context_die, die);
9275 else
9276 gen_decl_die (decl, context_die);
9279 /* Output the DIEs to represent all sub-blocks (and the items declared
9280 therein) of this block. */
9281 for (subblocks = BLOCK_SUBBLOCKS (stmt);
9282 subblocks != NULL;
9283 subblocks = BLOCK_CHAIN (subblocks))
9284 gen_block_die (subblocks, context_die, depth + 1);
9287 /* Is this a typedef we can avoid emitting? */
9289 static inline int
9290 is_redundant_typedef (decl)
9291 register tree decl;
9293 if (TYPE_DECL_IS_STUB (decl))
9294 return 1;
9296 if (DECL_ARTIFICIAL (decl)
9297 && DECL_CONTEXT (decl)
9298 && is_tagged_type (DECL_CONTEXT (decl))
9299 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9300 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9301 /* Also ignore the artificial member typedef for the class name. */
9302 return 1;
9304 return 0;
9307 /* Generate Dwarf debug information for a decl described by DECL. */
9309 static void
9310 gen_decl_die (decl, context_die)
9311 register tree decl;
9312 register dw_die_ref context_die;
9314 register tree origin;
9316 /* Make a note of the decl node we are going to be working on. We may need
9317 to give the user the source coordinates of where it appeared in case we
9318 notice (later on) that something about it looks screwy. */
9319 dwarf_last_decl = decl;
9321 if (TREE_CODE (decl) == ERROR_MARK)
9322 return;
9324 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
9325 ignore a function definition, since that would screw up our count of
9326 blocks, and that in turn will completely screw up the labels we will
9327 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9328 subsequent blocks). */
9329 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
9330 return;
9332 switch (TREE_CODE (decl))
9334 case CONST_DECL:
9335 /* The individual enumerators of an enum type get output when we output
9336 the Dwarf representation of the relevant enum type itself. */
9337 break;
9339 case FUNCTION_DECL:
9340 /* Don't output any DIEs to represent mere function declarations,
9341 unless they are class members or explicit block externs. */
9342 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9343 && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl)))
9344 break;
9346 if (debug_info_level > DINFO_LEVEL_TERSE)
9348 /* Before we describe the FUNCTION_DECL itself, make sure that we
9349 have described its return type. */
9350 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9352 /* And its containing type. */
9353 origin = decl_class_context (decl);
9354 if (origin != NULL_TREE)
9355 gen_type_die (origin, context_die);
9357 /* And its virtual context. */
9358 if (DECL_VINDEX (decl) != NULL_TREE)
9359 gen_type_die (DECL_CONTEXT (decl), context_die);
9362 /* Now output a DIE to represent the function itself. */
9363 gen_subprogram_die (decl, context_die);
9364 break;
9366 case TYPE_DECL:
9367 /* If we are in terse mode, don't generate any DIEs to represent any
9368 actual typedefs. */
9369 if (debug_info_level <= DINFO_LEVEL_TERSE)
9370 break;
9372 /* In the special case of a TYPE_DECL node representing the
9373 declaration of some type tag, if the given TYPE_DECL is marked as
9374 having been instantiated from some other (original) TYPE_DECL node
9375 (e.g. one which was generated within the original definition of an
9376 inline function) we have to generate a special (abbreviated)
9377 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9378 DIE here. */
9379 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
9381 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9382 break;
9385 if (is_redundant_typedef (decl))
9386 gen_type_die (TREE_TYPE (decl), context_die);
9387 else
9388 /* Output a DIE to represent the typedef itself. */
9389 gen_typedef_die (decl, context_die);
9390 break;
9392 case LABEL_DECL:
9393 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9394 gen_label_die (decl, context_die);
9395 break;
9397 case VAR_DECL:
9398 /* If we are in terse mode, don't generate any DIEs to represent any
9399 variable declarations or definitions. */
9400 if (debug_info_level <= DINFO_LEVEL_TERSE)
9401 break;
9403 /* Output any DIEs that are needed to specify the type of this data
9404 object. */
9405 gen_type_die (TREE_TYPE (decl), context_die);
9407 /* And its containing type. */
9408 origin = decl_class_context (decl);
9409 if (origin != NULL_TREE)
9410 gen_type_die (origin, context_die);
9412 /* Now output the DIE to represent the data object itself. This gets
9413 complicated because of the possibility that the VAR_DECL really
9414 represents an inlined instance of a formal parameter for an inline
9415 function. */
9416 origin = decl_ultimate_origin (decl);
9417 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9418 gen_formal_parameter_die (decl, context_die);
9419 else
9420 gen_variable_die (decl, context_die);
9421 break;
9423 case FIELD_DECL:
9424 /* Ignore the nameless fields that are used to skip bits, but
9425 handle C++ anonymous unions. */
9426 if (DECL_NAME (decl) != NULL_TREE
9427 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
9429 gen_type_die (member_declared_type (decl), context_die);
9430 gen_field_die (decl, context_die);
9432 break;
9434 case PARM_DECL:
9435 gen_type_die (TREE_TYPE (decl), context_die);
9436 gen_formal_parameter_die (decl, context_die);
9437 break;
9439 default:
9440 abort ();
9444 /* Add Ada "use" clause information for SGI Workshop debugger. */
9446 void
9447 dwarf2out_add_library_unit_info (filename, context_list)
9448 char *filename;
9449 char *context_list;
9451 unsigned int file_index;
9453 if (filename != NULL)
9455 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
9456 tree context_list_decl
9457 = build_decl (LABEL_DECL, get_identifier (context_list),
9458 void_type_node);
9460 TREE_PUBLIC (context_list_decl) = TRUE;
9461 add_name_attribute (unit_die, context_list);
9462 file_index = lookup_filename (filename);
9463 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
9464 add_pubname (context_list_decl, unit_die);
9468 /* Write the debugging output for DECL. */
9470 void
9471 dwarf2out_decl (decl)
9472 register tree decl;
9474 register dw_die_ref context_die = comp_unit_die;
9476 if (TREE_CODE (decl) == ERROR_MARK)
9477 return;
9479 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
9480 hope that the node in question doesn't represent a function definition.
9481 If it does, then totally ignoring it is bound to screw up our count of
9482 blocks, and that in turn will completely screw up the labels we will
9483 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9484 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
9485 own sequence numbers with them!) */
9486 if (DECL_IGNORED_P (decl))
9488 if (TREE_CODE (decl) == FUNCTION_DECL
9489 && DECL_INITIAL (decl) != NULL)
9490 abort ();
9492 return;
9495 switch (TREE_CODE (decl))
9497 case FUNCTION_DECL:
9498 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9499 builtin function. Explicit programmer-supplied declarations of
9500 these same functions should NOT be ignored however. */
9501 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
9502 return;
9504 /* What we would really like to do here is to filter out all mere
9505 file-scope declarations of file-scope functions which are never
9506 referenced later within this translation unit (and keep all of ones
9507 that *are* referenced later on) but we aren't clairvoyant, so we have
9508 no idea which functions will be referenced in the future (i.e. later
9509 on within the current translation unit). So here we just ignore all
9510 file-scope function declarations which are not also definitions. If
9511 and when the debugger needs to know something about these functions,
9512 it will have to hunt around and find the DWARF information associated
9513 with the definition of the function. Note that we can't just check
9514 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9515 definitions and which ones represent mere declarations. We have to
9516 check `DECL_INITIAL' instead. That's because the C front-end
9517 supports some weird semantics for "extern inline" function
9518 definitions. These can get inlined within the current translation
9519 unit (an thus, we need to generate DWARF info for their abstract
9520 instances so that the DWARF info for the concrete inlined instances
9521 can have something to refer to) but the compiler never generates any
9522 out-of-lines instances of such things (despite the fact that they
9523 *are* definitions). The important point is that the C front-end
9524 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9525 to generate DWARF for them anyway. Note that the C++ front-end also
9526 plays some similar games for inline function definitions appearing
9527 within include files which also contain
9528 `#pragma interface' pragmas. */
9529 if (DECL_INITIAL (decl) == NULL_TREE)
9530 return;
9532 /* If we're a nested function, initially use a parent of NULL; if we're
9533 a plain function, this will be fixed up in decls_for_scope. If
9534 we're a method, it will be ignored, since we already have a DIE. */
9535 if (decl_function_context (decl))
9536 context_die = NULL;
9538 break;
9540 case VAR_DECL:
9541 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9542 declaration and if the declaration was never even referenced from
9543 within this entire compilation unit. We suppress these DIEs in
9544 order to save space in the .debug section (by eliminating entries
9545 which are probably useless). Note that we must not suppress
9546 block-local extern declarations (whether used or not) because that
9547 would screw-up the debugger's name lookup mechanism and cause it to
9548 miss things which really ought to be in scope at a given point. */
9549 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
9550 return;
9552 /* If we are in terse mode, don't generate any DIEs to represent any
9553 variable declarations or definitions. */
9554 if (debug_info_level <= DINFO_LEVEL_TERSE)
9555 return;
9556 break;
9558 case TYPE_DECL:
9559 /* Don't bother trying to generate any DIEs to represent any of the
9560 normal built-in types for the language we are compiling. */
9561 if (DECL_SOURCE_LINE (decl) == 0)
9563 /* OK, we need to generate one for `bool' so GDB knows what type
9564 comparisons have. */
9565 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9566 == DW_LANG_C_plus_plus)
9567 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9568 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
9570 return;
9573 /* If we are in terse mode, don't generate any DIEs for types. */
9574 if (debug_info_level <= DINFO_LEVEL_TERSE)
9575 return;
9577 /* If we're a function-scope tag, initially use a parent of NULL;
9578 this will be fixed up in decls_for_scope. */
9579 if (decl_function_context (decl))
9580 context_die = NULL;
9582 break;
9584 default:
9585 return;
9588 gen_decl_die (decl, context_die);
9589 output_pending_types_for_scope (comp_unit_die);
9592 /* Output a marker (i.e. a label) for the beginning of the generated code for
9593 a lexical block. */
9595 void
9596 dwarf2out_begin_block (blocknum)
9597 register unsigned blocknum;
9599 function_section (current_function_decl);
9600 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
9603 /* Output a marker (i.e. a label) for the end of the generated code for a
9604 lexical block. */
9606 void
9607 dwarf2out_end_block (blocknum)
9608 register unsigned blocknum;
9610 function_section (current_function_decl);
9611 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
9614 /* Output a marker (i.e. a label) at a point in the assembly code which
9615 corresponds to a given source level label. */
9617 void
9618 dwarf2out_label (insn)
9619 register rtx insn;
9621 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9623 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9625 function_section (current_function_decl);
9626 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9627 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9628 (unsigned) INSN_UID (insn));
9632 /* Lookup a filename (in the list of filenames that we know about here in
9633 dwarf2out.c) and return its "index". The index of each (known) filename is
9634 just a unique number which is associated with only that one filename.
9635 We need such numbers for the sake of generating labels
9636 (in the .debug_sfnames section) and references to those
9637 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9638 If the filename given as an argument is not found in our current list,
9639 add it to the list and assign it the next available unique index number.
9640 In order to speed up searches, we remember the index of the filename
9641 was looked up last. This handles the majority of all searches. */
9643 static unsigned
9644 lookup_filename (file_name)
9645 const char *file_name;
9647 static unsigned last_file_lookup_index = 0;
9648 register unsigned i;
9650 /* Check to see if the file name that was searched on the previous call
9651 matches this file name. If so, return the index. */
9652 if (last_file_lookup_index != 0)
9653 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
9654 return last_file_lookup_index;
9656 /* Didn't match the previous lookup, search the table */
9657 for (i = 1; i < file_table_in_use; ++i)
9658 if (strcmp (file_name, file_table[i]) == 0)
9660 last_file_lookup_index = i;
9661 return i;
9664 /* Prepare to add a new table entry by making sure there is enough space in
9665 the table to do so. If not, expand the current table. */
9666 if (file_table_in_use == file_table_allocated)
9668 file_table_allocated += FILE_TABLE_INCREMENT;
9669 file_table
9670 = (char **) xrealloc (file_table,
9671 file_table_allocated * sizeof (char *));
9674 /* Add the new entry to the end of the filename table. */
9675 file_table[file_table_in_use] = xstrdup (file_name);
9676 last_file_lookup_index = file_table_in_use++;
9678 return last_file_lookup_index;
9681 /* Output a label to mark the beginning of a source code line entry
9682 and record information relating to this source line, in
9683 'line_info_table' for later output of the .debug_line section. */
9685 void
9686 dwarf2out_line (filename, line)
9687 register const char *filename;
9688 register unsigned line;
9690 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9692 function_section (current_function_decl);
9694 if (DWARF2_ASM_LINE_DEBUG_INFO)
9696 static const char *lastfile;
9698 /* Emit the .file and .loc directives understood by GNU as. */
9699 if (lastfile == 0 || strcmp (filename, lastfile))
9701 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
9702 lastfile = filename;
9705 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
9707 /* Indicate that line number info exists. */
9708 ++line_info_table_in_use;
9710 /* Indicate that multiple line number tables exist. */
9711 if (DECL_SECTION_NAME (current_function_decl))
9712 ++separate_line_info_table_in_use;
9714 else if (DECL_SECTION_NAME (current_function_decl))
9716 register dw_separate_line_info_ref line_info;
9717 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
9718 separate_line_info_table_in_use);
9719 if (flag_debug_asm)
9720 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9721 fputc ('\n', asm_out_file);
9723 /* expand the line info table if necessary */
9724 if (separate_line_info_table_in_use
9725 == separate_line_info_table_allocated)
9727 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9728 separate_line_info_table
9729 = (dw_separate_line_info_ref)
9730 xrealloc (separate_line_info_table,
9731 separate_line_info_table_allocated
9732 * sizeof (dw_separate_line_info_entry));
9735 /* Add the new entry at the end of the line_info_table. */
9736 line_info
9737 = &separate_line_info_table[separate_line_info_table_in_use++];
9738 line_info->dw_file_num = lookup_filename (filename);
9739 line_info->dw_line_num = line;
9740 line_info->function = current_funcdef_number;
9742 else
9744 register dw_line_info_ref line_info;
9746 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
9747 line_info_table_in_use);
9748 if (flag_debug_asm)
9749 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9750 fputc ('\n', asm_out_file);
9752 /* Expand the line info table if necessary. */
9753 if (line_info_table_in_use == line_info_table_allocated)
9755 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9756 line_info_table
9757 = (dw_line_info_ref)
9758 xrealloc (line_info_table,
9759 (line_info_table_allocated
9760 * sizeof (dw_line_info_entry)));
9763 /* Add the new entry at the end of the line_info_table. */
9764 line_info = &line_info_table[line_info_table_in_use++];
9765 line_info->dw_file_num = lookup_filename (filename);
9766 line_info->dw_line_num = line;
9771 /* Record the beginning of a new source file, for later output
9772 of the .debug_macinfo section. At present, unimplemented. */
9774 void
9775 dwarf2out_start_source_file (filename)
9776 register const char *filename ATTRIBUTE_UNUSED;
9780 /* Record the end of a source file, for later output
9781 of the .debug_macinfo section. At present, unimplemented. */
9783 void
9784 dwarf2out_end_source_file ()
9788 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9789 the tail part of the directive line, i.e. the part which is past the
9790 initial whitespace, #, whitespace, directive-name, whitespace part. */
9792 void
9793 dwarf2out_define (lineno, buffer)
9794 register unsigned lineno ATTRIBUTE_UNUSED;
9795 register const char *buffer ATTRIBUTE_UNUSED;
9797 static int initialized = 0;
9798 if (!initialized)
9800 dwarf2out_start_source_file (primary_filename);
9801 initialized = 1;
9805 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9806 the tail part of the directive line, i.e. the part which is past the
9807 initial whitespace, #, whitespace, directive-name, whitespace part. */
9809 void
9810 dwarf2out_undef (lineno, buffer)
9811 register unsigned lineno ATTRIBUTE_UNUSED;
9812 register const char *buffer ATTRIBUTE_UNUSED;
9816 /* Set up for Dwarf output at the start of compilation. */
9818 void
9819 dwarf2out_init (asm_out_file, main_input_filename)
9820 register FILE *asm_out_file;
9821 register char *main_input_filename;
9823 /* Remember the name of the primary input file. */
9824 primary_filename = main_input_filename;
9826 /* Allocate the initial hunk of the file_table. */
9827 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
9828 file_table_allocated = FILE_TABLE_INCREMENT;
9830 /* Skip the first entry - file numbers begin at 1. */
9831 file_table_in_use = 1;
9833 /* Allocate the initial hunk of the decl_die_table. */
9834 decl_die_table
9835 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
9836 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
9837 decl_die_table_in_use = 0;
9839 /* Allocate the initial hunk of the decl_scope_table. */
9840 decl_scope_table
9841 = (decl_scope_node *) xcalloc (DECL_SCOPE_TABLE_INCREMENT,
9842 sizeof (decl_scope_node));
9843 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
9844 decl_scope_depth = 0;
9846 /* Allocate the initial hunk of the abbrev_die_table. */
9847 abbrev_die_table
9848 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
9849 sizeof (dw_die_ref));
9850 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
9851 /* Zero-th entry is allocated, but unused */
9852 abbrev_die_table_in_use = 1;
9854 /* Allocate the initial hunk of the line_info_table. */
9855 line_info_table
9856 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
9857 sizeof (dw_line_info_entry));
9858 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
9859 /* Zero-th entry is allocated, but unused */
9860 line_info_table_in_use = 1;
9862 /* Generate the initial DIE for the .debug section. Note that the (string)
9863 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9864 will (typically) be a relative pathname and that this pathname should be
9865 taken as being relative to the directory from which the compiler was
9866 invoked when the given (base) source file was compiled. */
9867 gen_compile_unit_die (main_input_filename);
9869 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
9870 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
9871 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9872 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
9873 else
9874 strcpy (text_section_label, stripattributes (TEXT_SECTION));
9875 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
9876 DEBUG_INFO_SECTION_LABEL, 0);
9877 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
9878 DEBUG_LINE_SECTION_LABEL, 0);
9880 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9881 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
9882 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9883 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9884 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
9885 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9886 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
9887 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9888 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
9891 /* Output stuff that dwarf requires at the end of every file,
9892 and generate the DWARF-2 debugging info. */
9894 void
9895 dwarf2out_finish ()
9897 limbo_die_node *node, *next_node;
9898 dw_die_ref die;
9899 dw_attr_ref a;
9901 /* Traverse the limbo die list, and add parent/child links. The only
9902 dies without parents that should be here are concrete instances of
9903 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9904 For concrete instances, we can get the parent die from the abstract
9905 instance. */
9906 for (node = limbo_die_list; node; node = next_node)
9908 next_node = node->next;
9909 die = node->die;
9911 if (die->die_parent == NULL)
9913 a = get_AT (die, DW_AT_abstract_origin);
9914 if (a)
9915 add_child_die (a->dw_attr_val.v.val_die_ref->die_parent, die);
9916 else if (die == comp_unit_die)
9918 else
9919 abort ();
9921 free (node);
9924 /* Walk through the list of incomplete types again, trying once more to
9925 emit full debugging info for them. */
9926 retry_incomplete_types ();
9928 /* Traverse the DIE tree and add sibling attributes to those DIE's
9929 that have children. */
9930 add_sibling_attributes (comp_unit_die);
9932 /* Output a terminator label for the .text section. */
9933 fputc ('\n', asm_out_file);
9934 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9935 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
9937 #if 0
9938 /* Output a terminator label for the .data section. */
9939 fputc ('\n', asm_out_file);
9940 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
9941 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
9943 /* Output a terminator label for the .bss section. */
9944 fputc ('\n', asm_out_file);
9945 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
9946 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
9947 #endif
9949 /* Output the source line correspondence table. */
9950 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
9952 if (! DWARF2_ASM_LINE_DEBUG_INFO)
9954 fputc ('\n', asm_out_file);
9955 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9956 output_line_info ();
9959 /* We can only use the low/high_pc attributes if all of the code
9960 was in .text. */
9961 if (separate_line_info_table_in_use == 0)
9963 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
9964 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
9967 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
9968 debug_line_section_label);
9971 /* Output the abbreviation table. */
9972 fputc ('\n', asm_out_file);
9973 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9974 build_abbrev_table (comp_unit_die);
9975 output_abbrev_section ();
9977 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9978 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9979 calc_die_sizes (comp_unit_die);
9981 /* Output debugging information. */
9982 fputc ('\n', asm_out_file);
9983 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9984 output_compilation_unit_header ();
9985 output_die (comp_unit_die);
9987 if (pubname_table_in_use)
9989 /* Output public names table. */
9990 fputc ('\n', asm_out_file);
9991 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
9992 output_pubnames ();
9995 /* We only put functions in the arange table, so don't write it out if
9996 we don't have any. */
9997 if (fde_table_in_use)
9999 /* Output the address range information. */
10000 fputc ('\n', asm_out_file);
10001 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
10002 output_aranges ();
10005 #endif /* DWARF2_DEBUGGING_INFO */