import of gcc-2.8
[official-gcc.git] / gcc / dwarf2out.c
blobc4b47c85a891bbc88e7b3b58a4835832f3685446
1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* The first part of this file deals with the DWARF 2 frame unwind
24 information, which is also used by the GCC efficient exception handling
25 mechanism. The second part, controlled only by an #ifdef
26 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
27 information. */
29 #include "config.h"
30 #include "defaults.h"
31 #include <stdio.h>
32 #include "tree.h"
33 #include "flags.h"
34 #include "rtl.h"
35 #include "hard-reg-set.h"
36 #include "regs.h"
37 #include "insn-config.h"
38 #include "reload.h"
39 #include "output.h"
40 #include "expr.h"
41 #include "except.h"
42 #include "dwarf2.h"
44 /* #define NDEBUG 1 */
45 #include "assert.h"
47 /* Decide whether we want to emit frame unwind information for the current
48 translation unit. */
50 int
51 dwarf2out_do_frame ()
53 return (write_symbols == DWARF2_DEBUG
54 #ifdef DWARF2_UNWIND_INFO
55 || (flag_exceptions && ! exceptions_via_longjmp)
56 #endif
60 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
62 #ifndef __GNUC__
63 #define inline
64 #endif
66 /* How to start an assembler comment. */
67 #ifndef ASM_COMMENT_START
68 #define ASM_COMMENT_START ";#"
69 #endif
71 typedef struct dw_cfi_struct *dw_cfi_ref;
72 typedef struct dw_fde_struct *dw_fde_ref;
73 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
75 /* Call frames are described using a sequence of Call Frame
76 Information instructions. The register number, offset
77 and address fields are provided as possible operands;
78 their use is selected by the opcode field. */
80 typedef union dw_cfi_oprnd_struct
82 unsigned long dw_cfi_reg_num;
83 long int dw_cfi_offset;
84 char *dw_cfi_addr;
86 dw_cfi_oprnd;
88 typedef struct dw_cfi_struct
90 dw_cfi_ref dw_cfi_next;
91 enum dwarf_call_frame_info dw_cfi_opc;
92 dw_cfi_oprnd dw_cfi_oprnd1;
93 dw_cfi_oprnd dw_cfi_oprnd2;
95 dw_cfi_node;
97 /* All call frame descriptions (FDE's) in the GCC generated DWARF
98 refer to a single Common Information Entry (CIE), defined at
99 the beginning of the .debug_frame section. This used of a single
100 CIE obviates the need to keep track of multiple CIE's
101 in the DWARF generation routines below. */
103 typedef struct dw_fde_struct
105 char *dw_fde_begin;
106 char *dw_fde_current_label;
107 char *dw_fde_end;
108 dw_cfi_ref dw_fde_cfi;
110 dw_fde_node;
112 /* Maximum size (in bytes) of an artificially generated label. */
113 #define MAX_ARTIFICIAL_LABEL_BYTES 30
115 /* Make sure we know the sizes of the various types dwarf can describe. These
116 are only defaults. If the sizes are different for your target, you should
117 override these values by defining the appropriate symbols in your tm.h
118 file. */
120 #ifndef CHAR_TYPE_SIZE
121 #define CHAR_TYPE_SIZE BITS_PER_UNIT
122 #endif
123 #ifndef PTR_SIZE
124 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
125 #endif
127 /* The size in bytes of a DWARF field indicating an offset or length
128 relative to a debug info section, specified to be 4 bytes in the DWARF-2
129 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
131 #ifndef DWARF_OFFSET_SIZE
132 #define DWARF_OFFSET_SIZE 4
133 #endif
135 #define DWARF_VERSION 2
137 /* Round SIZE up to the nearest BOUNDARY. */
138 #define DWARF_ROUND(SIZE,BOUNDARY) \
139 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
141 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
142 #ifdef STACK_GROWS_DOWNWARD
143 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
144 #else
145 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
146 #endif
148 /* A pointer to the base of a table that contains frame description
149 information for each routine. */
150 static dw_fde_ref fde_table;
152 /* Number of elements currently allocated for fde_table. */
153 static unsigned fde_table_allocated;
155 /* Number of elements in fde_table currently in use. */
156 static unsigned fde_table_in_use;
158 /* Size (in elements) of increments by which we may expand the
159 fde_table. */
160 #define FDE_TABLE_INCREMENT 256
162 /* A list of call frame insns for the CIE. */
163 static dw_cfi_ref cie_cfi_head;
165 /* The number of the current function definition for which debugging
166 information is being generated. These numbers range from 1 up to the
167 maximum number of function definitions contained within the current
168 compilation unit. These numbers are used to create unique label id's
169 unique to each function definition. */
170 static unsigned current_funcdef_number = 0;
172 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
173 attribute that accelerates the lookup of the FDE associated
174 with the subprogram. This variable holds the table index of the FDE
175 associated with the current function (body) definition. */
176 static unsigned current_funcdef_fde;
178 /* Forward declarations for functions defined in this file. */
180 static char *stripattributes PROTO((char *));
181 static char *dwarf_cfi_name PROTO((unsigned));
182 static dw_cfi_ref new_cfi PROTO((void));
183 static void add_cfi PROTO((dw_cfi_ref *, dw_cfi_ref));
184 static unsigned long size_of_uleb128 PROTO((unsigned long));
185 static unsigned long size_of_sleb128 PROTO((long));
186 static void output_uleb128 PROTO((unsigned long));
187 static void output_sleb128 PROTO((long));
188 static void add_fde_cfi PROTO((char *, dw_cfi_ref));
189 static void lookup_cfa_1 PROTO((dw_cfi_ref, unsigned long *,
190 long *));
191 static void lookup_cfa PROTO((unsigned long *, long *));
192 static void reg_save PROTO((char *, unsigned, unsigned,
193 long));
194 static void initial_return_save PROTO((rtx));
195 static void output_cfi PROTO((dw_cfi_ref, dw_fde_ref));
196 static void output_call_frame_info PROTO((int));
197 static unsigned reg_number PROTO((rtx));
199 /* Definitions of defaults for assembler-dependent names of various
200 pseudo-ops and section names.
201 Theses may be overridden in the tm.h file (if necessary) for a particular
202 assembler. */
204 #ifdef OBJECT_FORMAT_ELF
205 #ifndef UNALIGNED_SHORT_ASM_OP
206 #define UNALIGNED_SHORT_ASM_OP ".2byte"
207 #endif
208 #ifndef UNALIGNED_INT_ASM_OP
209 #define UNALIGNED_INT_ASM_OP ".4byte"
210 #endif
211 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
212 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
213 #endif
214 #endif /* OBJECT_FORMAT_ELF */
216 #ifndef ASM_BYTE_OP
217 #define ASM_BYTE_OP ".byte"
218 #endif
220 /* Data and reference forms for relocatable data. */
221 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
222 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
224 /* Pseudo-op for defining a new section. */
225 #ifndef SECTION_ASM_OP
226 #define SECTION_ASM_OP ".section"
227 #endif
229 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
230 print the SECTION_ASM_OP and the section name. The default here works for
231 almost all svr4 assemblers, except for the sparc, where the section name
232 must be enclosed in double quotes. (See sparcv4.h). */
233 #ifndef SECTION_FORMAT
234 #ifdef PUSHSECTION_FORMAT
235 #define SECTION_FORMAT PUSHSECTION_FORMAT
236 #else
237 #define SECTION_FORMAT "\t%s\t%s\n"
238 #endif
239 #endif
241 #ifndef FRAME_SECTION
242 #define FRAME_SECTION ".debug_frame"
243 #endif
245 #ifndef FUNC_BEGIN_LABEL
246 #define FUNC_BEGIN_LABEL "LFB"
247 #endif
248 #ifndef FUNC_END_LABEL
249 #define FUNC_END_LABEL "LFE"
250 #endif
251 #define CIE_AFTER_SIZE_LABEL "LSCIE"
252 #define CIE_END_LABEL "LECIE"
253 #define CIE_LENGTH_LABEL "LLCIE"
254 #define FDE_AFTER_SIZE_LABEL "LSFDE"
255 #define FDE_END_LABEL "LEFDE"
256 #define FDE_LENGTH_LABEL "LLFDE"
258 /* Definitions of defaults for various types of primitive assembly language
259 output operations. These may be overridden from within the tm.h file,
260 but typically, that is unnecessary. */
262 #ifndef ASM_OUTPUT_SECTION
263 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
264 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
265 #endif
267 #ifndef ASM_OUTPUT_DWARF_DATA1
268 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
269 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
270 #endif
272 #ifdef UNALIGNED_INT_ASM_OP
274 #ifndef UNALIGNED_OFFSET_ASM_OP
275 #define UNALIGNED_OFFSET_ASM_OP \
276 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
277 #endif
279 #ifndef UNALIGNED_WORD_ASM_OP
280 #define UNALIGNED_WORD_ASM_OP \
281 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
282 #endif
284 #ifndef ASM_OUTPUT_DWARF_DELTA2
285 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
286 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
287 assemble_name (FILE, LABEL1); \
288 fprintf (FILE, "-"); \
289 assemble_name (FILE, LABEL2); \
290 } while (0)
291 #endif
293 #ifndef ASM_OUTPUT_DWARF_DELTA4
294 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
295 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
296 assemble_name (FILE, LABEL1); \
297 fprintf (FILE, "-"); \
298 assemble_name (FILE, LABEL2); \
299 } while (0)
300 #endif
302 #ifndef ASM_OUTPUT_DWARF_DELTA
303 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
304 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
305 assemble_name (FILE, LABEL1); \
306 fprintf (FILE, "-"); \
307 assemble_name (FILE, LABEL2); \
308 } while (0)
309 #endif
311 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
312 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
313 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
314 assemble_name (FILE, LABEL1); \
315 fprintf (FILE, "-"); \
316 assemble_name (FILE, LABEL2); \
317 } while (0)
318 #endif
320 #ifndef ASM_OUTPUT_DWARF_ADDR
321 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
322 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
323 assemble_name (FILE, LABEL); \
324 } while (0)
325 #endif
327 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
328 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
329 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
330 #endif
332 #ifndef ASM_OUTPUT_DWARF_OFFSET
333 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
334 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
335 assemble_name (FILE, LABEL); \
336 } while (0)
337 #endif
339 #ifndef ASM_OUTPUT_DWARF_DATA2
340 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
341 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
342 #endif
344 #ifndef ASM_OUTPUT_DWARF_DATA4
345 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
346 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
347 #endif
349 #ifndef ASM_OUTPUT_DWARF_DATA
350 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
351 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
352 (unsigned long) VALUE)
353 #endif
355 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
356 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
357 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
358 (unsigned long) VALUE)
359 #endif
361 #ifndef ASM_OUTPUT_DWARF_DATA8
362 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
363 do { \
364 if (WORDS_BIG_ENDIAN) \
366 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
367 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
369 else \
371 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
372 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
374 } while (0)
375 #endif
377 #ifndef ASM_OUTPUT_DWARF_VALUE4
378 #define ASM_OUTPUT_DWARF_VALUE4(FILE,LABEL) \
379 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
380 assemble_name (FILE, LABEL); \
381 } while (0)
382 #endif
384 #else /* UNALIGNED_INT_ASM_OP */
386 /* We don't have unaligned support, let's hope the normal output works for
387 .debug_frame. */
389 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
390 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, LABEL), PTR_SIZE, 1)
392 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
393 assemble_integer (gen_rtx (SYMBOL_REF, SImode, LABEL), 4, 1)
395 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
396 assemble_integer (gen_rtx (MINUS, HImode, \
397 gen_rtx (SYMBOL_REF, Pmode, LABEL1), \
398 gen_rtx (SYMBOL_REF, Pmode, LABEL2)), \
399 2, 1)
401 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
402 assemble_integer (gen_rtx (MINUS, SImode, \
403 gen_rtx (SYMBOL_REF, Pmode, LABEL1), \
404 gen_rtx (SYMBOL_REF, Pmode, LABEL2)), \
405 4, 1)
407 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
408 assemble_integer (gen_rtx (MINUS, Pmode, \
409 gen_rtx (SYMBOL_REF, Pmode, LABEL1), \
410 gen_rtx (SYMBOL_REF, Pmode, LABEL2)), \
411 PTR_SIZE, 1)
413 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
414 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
416 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
417 assemble_integer (GEN_INT (VALUE), 4, 1)
419 #define ASM_OUTPUT_DWARF_VALUE4(FILE,LABEL) \
420 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, LABEL), 4, 1)
422 #endif /* UNALIGNED_INT_ASM_OP */
424 #ifdef SET_ASM_OP
425 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
426 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
427 do { fprintf ((FILE), "\t%s\t", SET_ASM_OP); \
428 assemble_name (FILE, SY); \
429 fprintf ((FILE), ","); \
430 assemble_name (FILE, HI); \
431 fprintf ((FILE), "-"); \
432 assemble_name (FILE, LO); \
433 fprintf ((FILE), "\n"); \
434 } while (0)
435 #endif
436 #endif /* SET_ASM_OP */
438 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
439 newline is produced. When flag_debug_asm is asserted, we add commentary
440 at the end of the line, so we must avoid output of a newline here. */
441 #ifndef ASM_OUTPUT_DWARF_STRING
442 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
443 do { \
444 register int slen = strlen(P); \
445 register char *p = (P); \
446 register int i; \
447 fprintf (FILE, "\t.ascii \""); \
448 for (i = 0; i < slen; i++) \
450 register int c = p[i]; \
451 if (c == '\"' || c == '\\') \
452 putc ('\\', FILE); \
453 if (c >= ' ' && c < 0177) \
454 putc (c, FILE); \
455 else \
457 fprintf (FILE, "\\%o", c); \
460 fprintf (FILE, "\\0\""); \
462 while (0)
463 #endif
465 /* The DWARF 2 CFA column which tracks the return address. Normally this
466 is the column for PC, or the first column after all of the hard
467 registers. */
468 #ifndef DWARF_FRAME_RETURN_COLUMN
469 #ifdef PC_REGNUM
470 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
471 #else
472 #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER
473 #endif
474 #endif
476 /* The mapping from gcc register number to DWARF 2 CFA column number. By
477 default, we just provide columns for all registers. */
478 #ifndef DWARF_FRAME_REGNUM
479 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
480 #endif
482 /* Hook used by __throw. */
485 expand_builtin_dwarf_fp_regnum ()
487 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
490 /* The offset from the incoming value of %sp to the top of the stack frame
491 for the current function. */
492 #ifndef INCOMING_FRAME_SP_OFFSET
493 #define INCOMING_FRAME_SP_OFFSET 0
494 #endif
496 /* Return a pointer to a copy of the section string name S with all
497 attributes stripped off. */
499 static inline char *
500 stripattributes (s)
501 char *s;
503 char *stripped = xstrdup (s);
504 char *p = stripped;
506 while (*p && *p != ',')
507 p++;
509 *p = '\0';
510 return stripped;
513 /* Return the register number described by a given RTL node. */
515 static unsigned
516 reg_number (rtl)
517 register rtx rtl;
519 register unsigned regno = REGNO (rtl);
521 if (regno >= FIRST_PSEUDO_REGISTER)
523 warning ("internal regno botch: regno = %d\n", regno);
524 regno = 0;
527 regno = DBX_REGISTER_NUMBER (regno);
528 return regno;
531 struct reg_size_range
533 int beg;
534 int end;
535 int size;
538 /* Given a register number in REG_TREE, return an rtx for its size in bytes.
539 We do this in kind of a roundabout way, by building up a list of
540 register size ranges and seeing where our register falls in one of those
541 ranges. We need to do it this way because REG_TREE is not a constant,
542 and the target macros were not designed to make this task easy. */
545 expand_builtin_dwarf_reg_size (reg_tree, target)
546 tree reg_tree;
547 rtx target;
549 int size;
550 struct reg_size_range ranges[5];
551 tree t, t2;
553 int i = 0;
554 int n_ranges = 0;
555 int last_size = -1;
557 for (; i < FIRST_PSEUDO_REGISTER; ++i)
559 /* The return address is out of order on the MIPS, and we don't use
560 copy_reg for it anyway, so we don't care here how large it is. */
561 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
562 continue;
564 size = GET_MODE_SIZE (reg_raw_mode[i]);
565 if (size != last_size)
567 ranges[n_ranges].beg = i;
568 ranges[n_ranges].size = last_size = GET_MODE_SIZE (reg_raw_mode[i]);
569 ++n_ranges;
570 assert (n_ranges < 5);
572 ranges[n_ranges-1].end = i;
575 /* The usual case: fp regs surrounded by general regs. */
576 if (n_ranges == 3 && ranges[0].size == ranges[2].size)
578 assert ((DWARF_FRAME_REGNUM (ranges[1].end)
579 - DWARF_FRAME_REGNUM (ranges[1].beg))
580 == ranges[1].end - ranges[1].beg);
581 t = fold (build (GE_EXPR, integer_type_node, reg_tree,
582 build_int_2 (DWARF_FRAME_REGNUM (ranges[1].beg), 0)));
583 t2 = fold (build (LE_EXPR, integer_type_node, reg_tree,
584 build_int_2 (DWARF_FRAME_REGNUM (ranges[1].end), 0)));
585 t = fold (build (TRUTH_ANDIF_EXPR, integer_type_node, t, t2));
586 t = fold (build (COND_EXPR, integer_type_node, t,
587 build_int_2 (ranges[1].size, 0),
588 build_int_2 (ranges[0].size, 0)));
590 else
592 --n_ranges;
593 t = build_int_2 (ranges[n_ranges].size, 0);
594 size = DWARF_FRAME_REGNUM (ranges[n_ranges].beg);
595 for (; n_ranges--; )
597 assert ((DWARF_FRAME_REGNUM (ranges[n_ranges].end)
598 - DWARF_FRAME_REGNUM (ranges[n_ranges].beg))
599 == ranges[n_ranges].end - ranges[n_ranges].beg);
600 assert (DWARF_FRAME_REGNUM (ranges[n_ranges].beg) < size);
601 size = DWARF_FRAME_REGNUM (ranges[n_ranges].beg);
602 t2 = fold (build (LE_EXPR, integer_type_node, reg_tree,
603 build_int_2 (DWARF_FRAME_REGNUM
604 (ranges[n_ranges].end), 0)));
605 t = fold (build (COND_EXPR, integer_type_node, t2,
606 build_int_2 (ranges[n_ranges].size, 0), t));
609 return expand_expr (t, target, Pmode, 0);
612 /* Convert a DWARF call frame info. operation to its string name */
614 static char *
615 dwarf_cfi_name (cfi_opc)
616 register unsigned cfi_opc;
618 switch (cfi_opc)
620 case DW_CFA_advance_loc:
621 return "DW_CFA_advance_loc";
622 case DW_CFA_offset:
623 return "DW_CFA_offset";
624 case DW_CFA_restore:
625 return "DW_CFA_restore";
626 case DW_CFA_nop:
627 return "DW_CFA_nop";
628 case DW_CFA_set_loc:
629 return "DW_CFA_set_loc";
630 case DW_CFA_advance_loc1:
631 return "DW_CFA_advance_loc1";
632 case DW_CFA_advance_loc2:
633 return "DW_CFA_advance_loc2";
634 case DW_CFA_advance_loc4:
635 return "DW_CFA_advance_loc4";
636 case DW_CFA_offset_extended:
637 return "DW_CFA_offset_extended";
638 case DW_CFA_restore_extended:
639 return "DW_CFA_restore_extended";
640 case DW_CFA_undefined:
641 return "DW_CFA_undefined";
642 case DW_CFA_same_value:
643 return "DW_CFA_same_value";
644 case DW_CFA_register:
645 return "DW_CFA_register";
646 case DW_CFA_remember_state:
647 return "DW_CFA_remember_state";
648 case DW_CFA_restore_state:
649 return "DW_CFA_restore_state";
650 case DW_CFA_def_cfa:
651 return "DW_CFA_def_cfa";
652 case DW_CFA_def_cfa_register:
653 return "DW_CFA_def_cfa_register";
654 case DW_CFA_def_cfa_offset:
655 return "DW_CFA_def_cfa_offset";
657 /* SGI/MIPS specific */
658 case DW_CFA_MIPS_advance_loc8:
659 return "DW_CFA_MIPS_advance_loc8";
661 /* GNU extensions */
662 case DW_CFA_GNU_window_save:
663 return "DW_CFA_GNU_window_save";
664 case DW_CFA_GNU_args_size:
665 return "DW_CFA_GNU_args_size";
667 default:
668 return "DW_CFA_<unknown>";
672 /* Return a pointer to a newly allocated Call Frame Instruction. */
674 static inline dw_cfi_ref
675 new_cfi ()
677 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
679 cfi->dw_cfi_next = NULL;
680 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
681 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
683 return cfi;
686 /* Add a Call Frame Instruction to list of instructions. */
688 static inline void
689 add_cfi (list_head, cfi)
690 register dw_cfi_ref *list_head;
691 register dw_cfi_ref cfi;
693 register dw_cfi_ref *p;
695 /* Find the end of the chain. */
696 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
699 *p = cfi;
702 /* Generate a new label for the CFI info to refer to. */
704 char *
705 dwarf2out_cfi_label ()
707 static char label[20];
708 static unsigned long label_num = 0;
710 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
711 ASM_OUTPUT_LABEL (asm_out_file, label);
713 return label;
716 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
717 or to the CIE if LABEL is NULL. */
719 static void
720 add_fde_cfi (label, cfi)
721 register char *label;
722 register dw_cfi_ref cfi;
724 if (label)
726 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
728 if (*label == 0)
729 label = dwarf2out_cfi_label ();
731 if (fde->dw_fde_current_label == NULL
732 || strcmp (label, fde->dw_fde_current_label) != 0)
734 register dw_cfi_ref xcfi;
736 fde->dw_fde_current_label = label = xstrdup (label);
738 /* Set the location counter to the new label. */
739 xcfi = new_cfi ();
740 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
741 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
742 add_cfi (&fde->dw_fde_cfi, xcfi);
745 add_cfi (&fde->dw_fde_cfi, cfi);
748 else
749 add_cfi (&cie_cfi_head, cfi);
752 /* Subroutine of lookup_cfa. */
754 static inline void
755 lookup_cfa_1 (cfi, regp, offsetp)
756 register dw_cfi_ref cfi;
757 register unsigned long *regp;
758 register long *offsetp;
760 switch (cfi->dw_cfi_opc)
762 case DW_CFA_def_cfa_offset:
763 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
764 break;
765 case DW_CFA_def_cfa_register:
766 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
767 break;
768 case DW_CFA_def_cfa:
769 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
770 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
771 break;
772 default:
773 break;
777 /* Find the previous value for the CFA. */
779 static void
780 lookup_cfa (regp, offsetp)
781 register unsigned long *regp;
782 register long *offsetp;
784 register dw_cfi_ref cfi;
786 *regp = (unsigned long) -1;
787 *offsetp = 0;
789 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
790 lookup_cfa_1 (cfi, regp, offsetp);
792 if (fde_table_in_use)
794 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
795 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
796 lookup_cfa_1 (cfi, regp, offsetp);
800 /* The current rule for calculating the DWARF2 canonical frame address. */
801 static unsigned long cfa_reg;
802 static long cfa_offset;
804 /* The register used for saving registers to the stack, and its offset
805 from the CFA. */
806 static unsigned cfa_store_reg;
807 static long cfa_store_offset;
809 /* The running total of the size of arguments pushed onto the stack. */
810 static long args_size;
812 /* Entry point to update the canonical frame address (CFA).
813 LABEL is passed to add_fde_cfi. The value of CFA is now to be
814 calculated from REG+OFFSET. */
816 void
817 dwarf2out_def_cfa (label, reg, offset)
818 register char *label;
819 register unsigned reg;
820 register long offset;
822 register dw_cfi_ref cfi;
823 unsigned long old_reg;
824 long old_offset;
826 cfa_reg = reg;
827 cfa_offset = offset;
828 if (cfa_store_reg == reg)
829 cfa_store_offset = offset;
831 reg = DWARF_FRAME_REGNUM (reg);
832 lookup_cfa (&old_reg, &old_offset);
834 if (reg == old_reg && offset == old_offset)
835 return;
837 cfi = new_cfi ();
839 if (reg == old_reg)
841 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
842 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
845 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
846 else if (offset == old_offset && old_reg != (unsigned long) -1)
848 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
849 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
851 #endif
853 else
855 cfi->dw_cfi_opc = DW_CFA_def_cfa;
856 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
857 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
860 add_fde_cfi (label, cfi);
863 /* Add the CFI for saving a register. REG is the CFA column number.
864 LABEL is passed to add_fde_cfi.
865 If SREG is -1, the register is saved at OFFSET from the CFA;
866 otherwise it is saved in SREG. */
868 static void
869 reg_save (label, reg, sreg, offset)
870 register char * label;
871 register unsigned reg;
872 register unsigned sreg;
873 register long offset;
875 register dw_cfi_ref cfi = new_cfi ();
877 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
879 if (sreg == -1)
881 if (reg & ~0x3f)
882 /* The register number won't fit in 6 bits, so we have to use
883 the long form. */
884 cfi->dw_cfi_opc = DW_CFA_offset_extended;
885 else
886 cfi->dw_cfi_opc = DW_CFA_offset;
888 offset /= DWARF_CIE_DATA_ALIGNMENT;
889 assert (offset >= 0);
890 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
892 else
894 cfi->dw_cfi_opc = DW_CFA_register;
895 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
898 add_fde_cfi (label, cfi);
901 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
902 This CFI tells the unwinder that it needs to restore the window registers
903 from the previous frame's window save area.
905 ??? Perhaps we should note in the CIE where windows are saved (instead of
906 assuming 0(cfa)) and what registers are in the window. */
908 void
909 dwarf2out_window_save (label)
910 register char * label;
912 register dw_cfi_ref cfi = new_cfi ();
913 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
914 add_fde_cfi (label, cfi);
917 /* Add a CFI to update the running total of the size of arguments
918 pushed onto the stack. */
920 void
921 dwarf2out_args_size (label, size)
922 char *label;
923 long size;
925 register dw_cfi_ref cfi = new_cfi ();
926 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
927 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
928 add_fde_cfi (label, cfi);
931 /* Entry point for saving a register to the stack. REG is the GCC register
932 number. LABEL and OFFSET are passed to reg_save. */
934 void
935 dwarf2out_reg_save (label, reg, offset)
936 register char * label;
937 register unsigned reg;
938 register long offset;
940 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
943 /* Entry point for saving the return address in the stack.
944 LABEL and OFFSET are passed to reg_save. */
946 void
947 dwarf2out_return_save (label, offset)
948 register char * label;
949 register long offset;
951 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
954 /* Entry point for saving the return address in a register.
955 LABEL and SREG are passed to reg_save. */
957 void
958 dwarf2out_return_reg (label, sreg)
959 register char * label;
960 register unsigned sreg;
962 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
965 /* Record the initial position of the return address. RTL is
966 INCOMING_RETURN_ADDR_RTX. */
968 static void
969 initial_return_save (rtl)
970 register rtx rtl;
972 unsigned reg = -1;
973 long offset = 0;
975 switch (GET_CODE (rtl))
977 case REG:
978 /* RA is in a register. */
979 reg = reg_number (rtl);
980 break;
981 case MEM:
982 /* RA is on the stack. */
983 rtl = XEXP (rtl, 0);
984 switch (GET_CODE (rtl))
986 case REG:
987 assert (REGNO (rtl) == STACK_POINTER_REGNUM);
988 offset = 0;
989 break;
990 case PLUS:
991 assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
992 offset = INTVAL (XEXP (rtl, 1));
993 break;
994 case MINUS:
995 assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
996 offset = -INTVAL (XEXP (rtl, 1));
997 break;
998 default:
999 abort ();
1001 break;
1002 case PLUS:
1003 /* The return address is at some offset from any value we can
1004 actually load. For instance, on the SPARC it is in %i7+8. Just
1005 ignore the offset for now; it doesn't matter for unwinding frames. */
1006 assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1007 initial_return_save (XEXP (rtl, 0));
1008 return;
1009 default:
1010 abort ();
1013 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset);
1016 /* Check INSN to see if it looks like a push or a stack adjustment, and
1017 make a note of it if it does. EH uses this information to find out how
1018 much extra space it needs to pop off the stack. */
1020 static void
1021 dwarf2out_stack_adjust (insn)
1022 rtx insn;
1024 long offset;
1025 char *label;
1027 if (GET_CODE (insn) == BARRIER)
1029 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1030 the compiler will have already emitted a stack adjustment, but
1031 doesn't bother for calls to noreturn functions. */
1032 #ifdef STACK_GROWS_DOWNWARD
1033 offset = -args_size;
1034 #else
1035 offset = args_size;
1036 #endif
1038 else if (GET_CODE (PATTERN (insn)) == SET)
1040 rtx src, dest;
1041 enum rtx_code code;
1043 insn = PATTERN (insn);
1044 src = SET_SRC (insn);
1045 dest = SET_DEST (insn);
1047 if (dest == stack_pointer_rtx)
1049 /* (set (reg sp) (plus (reg sp) (const_int))) */
1050 code = GET_CODE (src);
1051 if (! (code == PLUS || code == MINUS)
1052 || XEXP (src, 0) != stack_pointer_rtx
1053 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1054 return;
1056 offset = INTVAL (XEXP (src, 1));
1058 else if (GET_CODE (dest) == MEM)
1060 /* (set (mem (pre_dec (reg sp))) (foo)) */
1061 src = XEXP (dest, 0);
1062 code = GET_CODE (src);
1064 if (! (code == PRE_DEC || code == PRE_INC)
1065 || XEXP (src, 0) != stack_pointer_rtx)
1066 return;
1068 offset = GET_MODE_SIZE (GET_MODE (dest));
1070 else
1071 return;
1073 if (code == PLUS || code == PRE_INC)
1074 offset = -offset;
1076 else
1077 return;
1079 if (offset == 0)
1080 return;
1082 if (cfa_reg == STACK_POINTER_REGNUM)
1083 cfa_offset += offset;
1085 #ifndef STACK_GROWS_DOWNWARD
1086 offset = -offset;
1087 #endif
1088 args_size += offset;
1089 if (args_size < 0)
1090 args_size = 0;
1092 label = dwarf2out_cfi_label ();
1093 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1094 dwarf2out_args_size (label, args_size);
1097 /* Record call frame debugging information for INSN, which either
1098 sets SP or FP (adjusting how we calculate the frame address) or saves a
1099 register to the stack. If INSN is NULL_RTX, initialize our state. */
1101 void
1102 dwarf2out_frame_debug (insn)
1103 rtx insn;
1105 char *label;
1106 rtx src, dest;
1107 long offset;
1109 /* A temporary register used in adjusting SP or setting up the store_reg. */
1110 static unsigned cfa_temp_reg;
1111 static long cfa_temp_value;
1113 if (insn == NULL_RTX)
1115 /* Set up state for generating call frame debug info. */
1116 lookup_cfa (&cfa_reg, &cfa_offset);
1117 assert (cfa_reg == DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1118 cfa_reg = STACK_POINTER_REGNUM;
1119 cfa_store_reg = cfa_reg;
1120 cfa_store_offset = cfa_offset;
1121 cfa_temp_reg = -1;
1122 cfa_temp_value = 0;
1123 return;
1126 if (! RTX_FRAME_RELATED_P (insn))
1128 dwarf2out_stack_adjust (insn);
1129 return;
1132 label = dwarf2out_cfi_label ();
1134 insn = PATTERN (insn);
1135 /* Assume that in a PARALLEL prologue insn, only the first elt is
1136 significant. Currently this is true. */
1137 if (GET_CODE (insn) == PARALLEL)
1138 insn = XVECEXP (insn, 0, 0);
1139 assert (GET_CODE (insn) == SET);
1141 src = SET_SRC (insn);
1142 dest = SET_DEST (insn);
1144 switch (GET_CODE (dest))
1146 case REG:
1147 /* Update the CFA rule wrt SP or FP. Make sure src is
1148 relative to the current CFA register. */
1149 switch (GET_CODE (src))
1151 /* Setting FP from SP. */
1152 case REG:
1153 assert (cfa_reg == REGNO (src));
1154 assert (REGNO (dest) == STACK_POINTER_REGNUM
1155 || (frame_pointer_needed
1156 && REGNO (dest) == HARD_FRAME_POINTER_REGNUM));
1157 cfa_reg = REGNO (dest);
1158 break;
1160 case PLUS:
1161 case MINUS:
1162 if (dest == stack_pointer_rtx)
1164 /* Adjusting SP. */
1165 switch (GET_CODE (XEXP (src, 1)))
1167 case CONST_INT:
1168 offset = INTVAL (XEXP (src, 1));
1169 break;
1170 case REG:
1171 assert (REGNO (XEXP (src, 1)) == cfa_temp_reg);
1172 offset = cfa_temp_value;
1173 break;
1174 default:
1175 abort ();
1178 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1180 /* Restoring SP from FP in the epilogue. */
1181 assert (cfa_reg == HARD_FRAME_POINTER_REGNUM);
1182 cfa_reg = STACK_POINTER_REGNUM;
1184 else
1185 assert (XEXP (src, 0) == stack_pointer_rtx);
1187 if (GET_CODE (src) == PLUS)
1188 offset = -offset;
1189 if (cfa_reg == STACK_POINTER_REGNUM)
1190 cfa_offset += offset;
1191 if (cfa_store_reg == STACK_POINTER_REGNUM)
1192 cfa_store_offset += offset;
1194 else
1196 /* Initializing the store base register. */
1197 assert (GET_CODE (src) == PLUS);
1198 assert (XEXP (src, 1) == stack_pointer_rtx);
1199 assert (GET_CODE (XEXP (src, 0)) == REG
1200 && REGNO (XEXP (src, 0)) == cfa_temp_reg);
1201 assert (cfa_reg == STACK_POINTER_REGNUM);
1202 cfa_store_reg = REGNO (dest);
1203 cfa_store_offset = cfa_offset - cfa_temp_value;
1205 break;
1207 case CONST_INT:
1208 cfa_temp_reg = REGNO (dest);
1209 cfa_temp_value = INTVAL (src);
1210 break;
1212 case IOR:
1213 assert (GET_CODE (XEXP (src, 0)) == REG
1214 && REGNO (XEXP (src, 0)) == cfa_temp_reg);
1215 assert (REGNO (dest) == cfa_temp_reg);
1216 assert (GET_CODE (XEXP (src, 1)) == CONST_INT);
1217 cfa_temp_value |= INTVAL (XEXP (src, 1));
1218 break;
1220 default:
1221 abort ();
1223 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1224 break;
1226 case MEM:
1227 /* Saving a register to the stack. Make sure dest is relative to the
1228 CFA register. */
1229 assert (GET_CODE (src) == REG);
1230 switch (GET_CODE (XEXP (dest, 0)))
1232 /* With a push. */
1233 case PRE_INC:
1234 case PRE_DEC:
1235 offset = GET_MODE_SIZE (GET_MODE (dest));
1236 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1237 offset = -offset;
1239 assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM);
1240 assert (cfa_store_reg == STACK_POINTER_REGNUM);
1241 cfa_store_offset += offset;
1242 if (cfa_reg == STACK_POINTER_REGNUM)
1243 cfa_offset = cfa_store_offset;
1245 offset = -cfa_store_offset;
1246 break;
1248 /* With an offset. */
1249 case PLUS:
1250 case MINUS:
1251 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1252 if (GET_CODE (src) == MINUS)
1253 offset = -offset;
1255 assert (cfa_store_reg == REGNO (XEXP (XEXP (dest, 0), 0)));
1256 offset -= cfa_store_offset;
1257 break;
1259 default:
1260 abort ();
1262 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1263 dwarf2out_reg_save (label, REGNO (src), offset);
1264 break;
1266 default:
1267 abort ();
1271 /* Return the size of an unsigned LEB128 quantity. */
1273 static inline unsigned long
1274 size_of_uleb128 (value)
1275 register unsigned long value;
1277 register unsigned long size = 0;
1278 register unsigned byte;
1282 byte = (value & 0x7f);
1283 value >>= 7;
1284 size += 1;
1286 while (value != 0);
1288 return size;
1291 /* Return the size of a signed LEB128 quantity. */
1293 static inline unsigned long
1294 size_of_sleb128 (value)
1295 register long value;
1297 register unsigned long size = 0;
1298 register unsigned byte;
1302 byte = (value & 0x7f);
1303 value >>= 7;
1304 size += 1;
1306 while (!(((value == 0) && ((byte & 0x40) == 0))
1307 || ((value == -1) && ((byte & 0x40) != 0))));
1309 return size;
1312 /* Output an unsigned LEB128 quantity. */
1314 static void
1315 output_uleb128 (value)
1316 register unsigned long value;
1318 unsigned long save_value = value;
1320 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1323 register unsigned byte = (value & 0x7f);
1324 value >>= 7;
1325 if (value != 0)
1326 /* More bytes to follow. */
1327 byte |= 0x80;
1329 fprintf (asm_out_file, "0x%x", byte);
1330 if (value != 0)
1331 fprintf (asm_out_file, ",");
1333 while (value != 0);
1335 if (flag_debug_asm)
1336 fprintf (asm_out_file, "\t%s ULEB128 0x%x", ASM_COMMENT_START, save_value);
1339 /* Output an signed LEB128 quantity. */
1341 static void
1342 output_sleb128 (value)
1343 register long value;
1345 register int more;
1346 register unsigned byte;
1347 long save_value = value;
1349 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1352 byte = (value & 0x7f);
1353 /* arithmetic shift */
1354 value >>= 7;
1355 more = !((((value == 0) && ((byte & 0x40) == 0))
1356 || ((value == -1) && ((byte & 0x40) != 0))));
1357 if (more)
1358 byte |= 0x80;
1360 fprintf (asm_out_file, "0x%x", byte);
1361 if (more)
1362 fprintf (asm_out_file, ",");
1365 while (more);
1366 if (flag_debug_asm)
1367 fprintf (asm_out_file, "\t%s SLEB128 %d", ASM_COMMENT_START, save_value);
1370 /* Output a Call Frame Information opcode and its operand(s). */
1372 static void
1373 output_cfi (cfi, fde)
1374 register dw_cfi_ref cfi;
1375 register dw_fde_ref fde;
1377 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1379 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1380 cfi->dw_cfi_opc
1381 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1382 if (flag_debug_asm)
1383 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%x",
1384 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1385 fputc ('\n', asm_out_file);
1388 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1390 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1391 cfi->dw_cfi_opc
1392 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1393 if (flag_debug_asm)
1394 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%x",
1395 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1397 fputc ('\n', asm_out_file);
1398 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1399 fputc ('\n', asm_out_file);
1401 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1403 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1404 cfi->dw_cfi_opc
1405 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1406 if (flag_debug_asm)
1407 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%x",
1408 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1410 fputc ('\n', asm_out_file);
1412 else
1414 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1415 if (flag_debug_asm)
1416 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1417 dwarf_cfi_name (cfi->dw_cfi_opc));
1419 fputc ('\n', asm_out_file);
1420 switch (cfi->dw_cfi_opc)
1422 case DW_CFA_set_loc:
1423 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1424 fputc ('\n', asm_out_file);
1425 break;
1426 case DW_CFA_advance_loc1:
1427 /* TODO: not currently implemented. */
1428 abort ();
1429 break;
1430 case DW_CFA_advance_loc2:
1431 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1432 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1433 fde->dw_fde_current_label);
1434 fputc ('\n', asm_out_file);
1435 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1436 break;
1437 case DW_CFA_advance_loc4:
1438 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1439 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1440 fde->dw_fde_current_label);
1441 fputc ('\n', asm_out_file);
1442 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1443 break;
1444 #ifdef MIPS_DEBUGGING_INFO
1445 case DW_CFA_MIPS_advance_loc8:
1446 /* TODO: not currently implemented. */
1447 abort ();
1448 break;
1449 #endif
1450 case DW_CFA_offset_extended:
1451 case DW_CFA_def_cfa:
1452 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1453 fputc ('\n', asm_out_file);
1454 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1455 fputc ('\n', asm_out_file);
1456 break;
1457 case DW_CFA_restore_extended:
1458 case DW_CFA_undefined:
1459 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1460 fputc ('\n', asm_out_file);
1461 break;
1462 case DW_CFA_same_value:
1463 case DW_CFA_def_cfa_register:
1464 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1465 fputc ('\n', asm_out_file);
1466 break;
1467 case DW_CFA_register:
1468 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1469 fputc ('\n', asm_out_file);
1470 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1471 fputc ('\n', asm_out_file);
1472 break;
1473 case DW_CFA_def_cfa_offset:
1474 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1475 fputc ('\n', asm_out_file);
1476 break;
1477 case DW_CFA_GNU_window_save:
1478 break;
1479 case DW_CFA_GNU_args_size:
1480 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1481 fputc ('\n', asm_out_file);
1482 break;
1483 default:
1484 break;
1489 #if !defined (EH_FRAME_SECTION)
1490 #if defined (EH_FRAME_SECTION_ASM_OP)
1491 #define EH_FRAME_SECTION() eh_frame_section();
1492 #else
1493 #if defined (ASM_OUTPUT_SECTION_NAME)
1494 #define EH_FRAME_SECTION() \
1495 do { \
1496 named_section (NULL_TREE, ".eh_frame", 0); \
1497 } while (0)
1498 #endif
1499 #endif
1500 #endif
1502 /* Output the call frame information used to used to record information
1503 that relates to calculating the frame pointer, and records the
1504 location of saved registers. */
1506 static void
1507 output_call_frame_info (for_eh)
1508 int for_eh;
1510 register unsigned long i, j;
1511 register dw_fde_ref fde;
1512 register unsigned long fde_size;
1513 register dw_cfi_ref cfi;
1514 unsigned long fde_pad;
1515 char l1[20], l2[20];
1516 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1517 char ld[20];
1518 #endif
1520 /* Do we want to include a pointer to the exception table? */
1521 int eh_ptr = for_eh && exception_table_p ();
1523 fputc ('\n', asm_out_file);
1525 /* We're going to be generating comments, so turn on app. */
1526 if (flag_debug_asm)
1527 app_enable ();
1529 if (for_eh)
1531 #ifdef EH_FRAME_SECTION
1532 EH_FRAME_SECTION ();
1533 #else
1534 tree label = get_file_function_name ('F');
1536 data_section ();
1537 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1538 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1539 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1540 #endif
1541 assemble_label ("__FRAME_BEGIN__");
1543 else
1544 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1546 /* Output the CIE. */
1547 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1548 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1549 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1550 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1551 if (for_eh)
1552 ASM_OUTPUT_DWARF_VALUE4 (asm_out_file, ld);
1553 else
1554 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1555 #else
1556 if (for_eh)
1557 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1558 else
1559 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1560 #endif
1561 if (flag_debug_asm)
1562 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1563 ASM_COMMENT_START);
1565 fputc ('\n', asm_out_file);
1566 ASM_OUTPUT_LABEL (asm_out_file, l1);
1568 if (for_eh)
1569 /* Now that the CIE pointer is PC-relative for EH,
1570 use 0 to identify the CIE. */
1571 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1572 else
1573 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1575 if (flag_debug_asm)
1576 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1578 fputc ('\n', asm_out_file);
1579 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1581 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1582 fputc ('\n', asm_out_file);
1585 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1586 if (flag_debug_asm)
1587 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1589 fputc ('\n', asm_out_file);
1590 if (eh_ptr)
1592 /* The CIE contains a pointer to the exception region info for the
1593 frame. Make the augmentation string three bytes (including the
1594 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1595 can't handle unaligned relocs. */
1596 if (flag_debug_asm)
1598 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1599 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1601 else
1603 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1605 fputc ('\n', asm_out_file);
1607 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1608 if (flag_debug_asm)
1609 fprintf (asm_out_file, "\t%s pointer to exception region info",
1610 ASM_COMMENT_START);
1612 else
1614 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1615 if (flag_debug_asm)
1616 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1617 ASM_COMMENT_START);
1620 fputc ('\n', asm_out_file);
1621 output_uleb128 (1);
1622 if (flag_debug_asm)
1623 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1625 fputc ('\n', asm_out_file);
1626 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1627 if (flag_debug_asm)
1628 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1630 fputc ('\n', asm_out_file);
1631 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1632 if (flag_debug_asm)
1633 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1635 fputc ('\n', asm_out_file);
1637 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1638 output_cfi (cfi, NULL);
1640 /* Pad the CIE out to an address sized boundary. */
1641 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1642 ASM_OUTPUT_LABEL (asm_out_file, l2);
1643 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1644 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1645 #endif
1647 /* Loop through all of the FDE's. */
1648 for (i = 0; i < fde_table_in_use; ++i)
1650 fde = &fde_table[i];
1652 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
1653 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
1654 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1655 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2);
1656 if (for_eh)
1657 ASM_OUTPUT_DWARF_VALUE4 (asm_out_file, ld);
1658 else
1659 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1660 #else
1661 if (for_eh)
1662 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1663 else
1664 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1665 #endif
1666 if (flag_debug_asm)
1667 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1668 fputc ('\n', asm_out_file);
1669 ASM_OUTPUT_LABEL (asm_out_file, l1);
1671 if (for_eh)
1672 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l1, "__FRAME_BEGIN__");
1673 else
1674 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1675 if (flag_debug_asm)
1676 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1678 fputc ('\n', asm_out_file);
1679 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1680 if (flag_debug_asm)
1681 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1683 fputc ('\n', asm_out_file);
1684 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1685 fde->dw_fde_end, fde->dw_fde_begin);
1686 if (flag_debug_asm)
1687 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1689 fputc ('\n', asm_out_file);
1691 /* Loop through the Call Frame Instructions associated with
1692 this FDE. */
1693 fde->dw_fde_current_label = fde->dw_fde_begin;
1694 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1695 output_cfi (cfi, fde);
1697 /* Pad the FDE out to an address sized boundary. */
1698 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1699 ASM_OUTPUT_LABEL (asm_out_file, l2);
1700 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1701 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1702 #endif
1704 #ifndef EH_FRAME_SECTION
1705 if (for_eh)
1707 /* Emit terminating zero for table. */
1708 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1709 fputc ('\n', asm_out_file);
1711 #endif
1712 #ifdef MIPS_DEBUGGING_INFO
1713 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1714 get a value of 0. Putting .align 0 after the label fixes it. */
1715 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1716 #endif
1718 /* Turn off app to make assembly quicker. */
1719 if (flag_debug_asm)
1720 app_disable ();
1723 /* Output a marker (i.e. a label) for the beginning of a function, before
1724 the prologue. */
1726 void
1727 dwarf2out_begin_prologue ()
1729 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1730 register dw_fde_ref fde;
1732 ++current_funcdef_number;
1734 function_section (current_function_decl);
1735 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1736 current_funcdef_number);
1737 ASM_OUTPUT_LABEL (asm_out_file, label);
1739 /* Expand the fde table if necessary. */
1740 if (fde_table_in_use == fde_table_allocated)
1742 fde_table_allocated += FDE_TABLE_INCREMENT;
1743 fde_table
1744 = (dw_fde_ref) xrealloc (fde_table,
1745 fde_table_allocated * sizeof (dw_fde_node));
1748 /* Record the FDE associated with this function. */
1749 current_funcdef_fde = fde_table_in_use;
1751 /* Add the new FDE at the end of the fde_table. */
1752 fde = &fde_table[fde_table_in_use++];
1753 fde->dw_fde_begin = xstrdup (label);
1754 fde->dw_fde_current_label = NULL;
1755 fde->dw_fde_end = NULL;
1756 fde->dw_fde_cfi = NULL;
1758 args_size = 0;
1761 /* Output a marker (i.e. a label) for the absolute end of the generated code
1762 for a function definition. This gets called *after* the epilogue code has
1763 been generated. */
1765 void
1766 dwarf2out_end_epilogue ()
1768 dw_fde_ref fde;
1769 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1771 /* Output a label to mark the endpoint of the code generated for this
1772 function. */
1773 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1774 ASM_OUTPUT_LABEL (asm_out_file, label);
1775 fde = &fde_table[fde_table_in_use - 1];
1776 fde->dw_fde_end = xstrdup (label);
1779 void
1780 dwarf2out_frame_init ()
1782 /* Allocate the initial hunk of the fde_table. */
1783 fde_table
1784 = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1785 bzero ((char *) fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1786 fde_table_allocated = FDE_TABLE_INCREMENT;
1787 fde_table_in_use = 0;
1789 /* Generate the CFA instructions common to all FDE's. Do it now for the
1790 sake of lookup_cfa. */
1792 #ifdef DWARF2_UNWIND_INFO
1793 /* On entry, the Canonical Frame Address is at SP. */
1794 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1795 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1796 #endif
1799 void
1800 dwarf2out_frame_finish ()
1802 /* Output call frame information. */
1803 #ifdef MIPS_DEBUGGING_INFO
1804 if (write_symbols == DWARF2_DEBUG)
1805 output_call_frame_info (0);
1806 if (flag_exceptions && ! exceptions_via_longjmp)
1807 output_call_frame_info (1);
1808 #else
1809 if (write_symbols == DWARF2_DEBUG
1810 || (flag_exceptions && ! exceptions_via_longjmp))
1811 output_call_frame_info (1);
1812 #endif
1815 #endif /* .debug_frame support */
1817 /* And now, the support for symbolic debugging information. */
1818 #ifdef DWARF2_DEBUGGING_INFO
1820 extern char *getpwd ();
1822 /* NOTE: In the comments in this file, many references are made to
1823 "Debugging Information Entries". This term is abbreviated as `DIE'
1824 throughout the remainder of this file. */
1826 /* An internal representation of the DWARF output is built, and then
1827 walked to generate the DWARF debugging info. The walk of the internal
1828 representation is done after the entire program has been compiled.
1829 The types below are used to describe the internal representation. */
1831 /* Each DIE may have a series of attribute/value pairs. Values
1832 can take on several forms. The forms that are used in this
1833 implementation are listed below. */
1835 typedef enum
1837 dw_val_class_addr,
1838 dw_val_class_loc,
1839 dw_val_class_const,
1840 dw_val_class_unsigned_const,
1841 dw_val_class_long_long,
1842 dw_val_class_float,
1843 dw_val_class_flag,
1844 dw_val_class_die_ref,
1845 dw_val_class_fde_ref,
1846 dw_val_class_lbl_id,
1847 dw_val_class_section_offset,
1848 dw_val_class_str
1850 dw_val_class;
1852 /* Various DIE's use offsets relative to the beginning of the
1853 .debug_info section to refer to each other. */
1855 typedef long int dw_offset;
1857 /* Define typedefs here to avoid circular dependencies. */
1859 typedef struct die_struct *dw_die_ref;
1860 typedef struct dw_attr_struct *dw_attr_ref;
1861 typedef struct dw_val_struct *dw_val_ref;
1862 typedef struct dw_line_info_struct *dw_line_info_ref;
1863 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1864 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1865 typedef struct pubname_struct *pubname_ref;
1866 typedef dw_die_ref *arange_ref;
1868 /* Describe a double word constant value. */
1870 typedef struct dw_long_long_struct
1872 unsigned long hi;
1873 unsigned long low;
1875 dw_long_long_const;
1877 /* Describe a floating point constant value. */
1879 typedef struct dw_fp_struct
1881 long *array;
1882 unsigned length;
1884 dw_float_const;
1886 /* Each entry in the line_info_table maintains the file and
1887 line number associated with the label generated for that
1888 entry. The label gives the PC value associated with
1889 the line number entry. */
1891 typedef struct dw_line_info_struct
1893 unsigned long dw_file_num;
1894 unsigned long dw_line_num;
1896 dw_line_info_entry;
1898 /* Line information for functions in separate sections; each one gets its
1899 own sequence. */
1900 typedef struct dw_separate_line_info_struct
1902 unsigned long dw_file_num;
1903 unsigned long dw_line_num;
1904 unsigned long function;
1906 dw_separate_line_info_entry;
1908 /* The dw_val_node describes an attribute's value, as it is
1909 represented internally. */
1911 typedef struct dw_val_struct
1913 dw_val_class val_class;
1914 union
1916 char *val_addr;
1917 dw_loc_descr_ref val_loc;
1918 long int val_int;
1919 long unsigned val_unsigned;
1920 dw_long_long_const val_long_long;
1921 dw_float_const val_float;
1922 dw_die_ref val_die_ref;
1923 unsigned val_fde_index;
1924 char *val_str;
1925 char *val_lbl_id;
1926 char *val_section;
1927 unsigned char val_flag;
1931 dw_val_node;
1933 /* Locations in memory are described using a sequence of stack machine
1934 operations. */
1936 typedef struct dw_loc_descr_struct
1938 dw_loc_descr_ref dw_loc_next;
1939 enum dwarf_location_atom dw_loc_opc;
1940 dw_val_node dw_loc_oprnd1;
1941 dw_val_node dw_loc_oprnd2;
1943 dw_loc_descr_node;
1945 /* Each DIE attribute has a field specifying the attribute kind,
1946 a link to the next attribute in the chain, and an attribute value.
1947 Attributes are typically linked below the DIE they modify. */
1949 typedef struct dw_attr_struct
1951 enum dwarf_attribute dw_attr;
1952 dw_attr_ref dw_attr_next;
1953 dw_val_node dw_attr_val;
1955 dw_attr_node;
1957 /* The Debugging Information Entry (DIE) structure */
1959 typedef struct die_struct
1961 enum dwarf_tag die_tag;
1962 dw_attr_ref die_attr;
1963 dw_attr_ref die_attr_last;
1964 dw_die_ref die_parent;
1965 dw_die_ref die_child;
1966 dw_die_ref die_child_last;
1967 dw_die_ref die_sib;
1968 dw_offset die_offset;
1969 unsigned long die_abbrev;
1971 die_node;
1973 /* The pubname structure */
1975 typedef struct pubname_struct
1977 dw_die_ref die;
1978 char * name;
1980 pubname_entry;
1982 /* The limbo die list structure. */
1983 typedef struct limbo_die_struct
1985 dw_die_ref die;
1986 struct limbo_die_struct *next;
1988 limbo_die_node;
1990 /* How to start an assembler comment. */
1991 #ifndef ASM_COMMENT_START
1992 #define ASM_COMMENT_START ";#"
1993 #endif
1995 /* Define a macro which returns non-zero for a TYPE_DECL which was
1996 implicitly generated for a tagged type.
1998 Note that unlike the gcc front end (which generates a NULL named
1999 TYPE_DECL node for each complete tagged type, each array type, and
2000 each function type node created) the g++ front end generates a
2001 _named_ TYPE_DECL node for each tagged type node created.
2002 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2003 generate a DW_TAG_typedef DIE for them. */
2005 #define TYPE_DECL_IS_STUB(decl) \
2006 (DECL_NAME (decl) == NULL_TREE \
2007 || (DECL_ARTIFICIAL (decl) \
2008 && is_tagged_type (TREE_TYPE (decl)) \
2009 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2010 /* This is necessary for stub decls that \
2011 appear in nested inline functions. */ \
2012 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2013 && (decl_ultimate_origin (decl) \
2014 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2016 /* Information concerning the compilation unit's programming
2017 language, and compiler version. */
2019 extern int flag_traditional;
2020 extern char *version_string;
2021 extern char *language_string;
2023 /* Fixed size portion of the DWARF compilation unit header. */
2024 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2026 /* Fixed size portion of debugging line information prolog. */
2027 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2029 /* Fixed size portion of public names info. */
2030 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2032 /* Fixed size portion of the address range info. */
2033 #define DWARF_ARANGES_HEADER_SIZE \
2034 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
2036 /* Define the architecture-dependent minimum instruction length (in bytes).
2037 In this implementation of DWARF, this field is used for information
2038 purposes only. Since GCC generates assembly language, we have
2039 no a priori knowledge of how many instruction bytes are generated
2040 for each source line, and therefore can use only the DW_LNE_set_address
2041 and DW_LNS_fixed_advance_pc line information commands. */
2043 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2044 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2045 #endif
2047 /* Minimum line offset in a special line info. opcode.
2048 This value was chosen to give a reasonable range of values. */
2049 #define DWARF_LINE_BASE -10
2051 /* First special line opcde - leave room for the standard opcodes. */
2052 #define DWARF_LINE_OPCODE_BASE 10
2054 /* Range of line offsets in a special line info. opcode. */
2055 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2057 /* Flag that indicates the initial value of the is_stmt_start flag.
2058 In the present implementation, we do not mark any lines as
2059 the beginning of a source statement, because that information
2060 is not made available by the GCC front-end. */
2061 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2063 /* This location is used by calc_die_sizes() to keep track
2064 the offset of each DIE within the .debug_info section. */
2065 static unsigned long next_die_offset;
2067 /* Record the root of the DIE's built for the current compilation unit. */
2068 static dw_die_ref comp_unit_die;
2070 /* A list of DIEs with a NULL parent waiting to be relocated. */
2071 static limbo_die_node *limbo_die_list = 0;
2073 /* Pointer to an array of filenames referenced by this compilation unit. */
2074 static char **file_table;
2076 /* Total number of entries in the table (i.e. array) pointed to by
2077 `file_table'. This is the *total* and includes both used and unused
2078 slots. */
2079 static unsigned file_table_allocated;
2081 /* Number of entries in the file_table which are actually in use. */
2082 static unsigned file_table_in_use;
2084 /* Size (in elements) of increments by which we may expand the filename
2085 table. */
2086 #define FILE_TABLE_INCREMENT 64
2088 /* Local pointer to the name of the main input file. Initialized in
2089 dwarf2out_init. */
2090 static char *primary_filename;
2092 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
2093 which their beginnings are encountered. We output Dwarf debugging info
2094 that refers to the beginnings and ends of the ranges of code for each
2095 lexical block. The labels themselves are generated in final.c, which
2096 assigns numbers to the blocks in the same way. */
2097 static unsigned next_block_number = 2;
2099 /* A pointer to the base of a table of references to DIE's that describe
2100 declarations. The table is indexed by DECL_UID() which is a unique
2101 number identifying each decl. */
2102 static dw_die_ref *decl_die_table;
2104 /* Number of elements currently allocated for the decl_die_table. */
2105 static unsigned decl_die_table_allocated;
2107 /* Number of elements in decl_die_table currently in use. */
2108 static unsigned decl_die_table_in_use;
2110 /* Size (in elements) of increments by which we may expand the
2111 decl_die_table. */
2112 #define DECL_DIE_TABLE_INCREMENT 256
2114 /* A pointer to the base of a table of references to declaration
2115 scopes. This table is a display which tracks the nesting
2116 of declaration scopes at the current scope and containing
2117 scopes. This table is used to find the proper place to
2118 define type declaration DIE's. */
2119 static tree *decl_scope_table;
2121 /* Number of elements currently allocated for the decl_scope_table. */
2122 static unsigned decl_scope_table_allocated;
2124 /* Current level of nesting of declaration scopes. */
2125 static unsigned decl_scope_depth;
2127 /* Size (in elements) of increments by which we may expand the
2128 decl_scope_table. */
2129 #define DECL_SCOPE_TABLE_INCREMENT 64
2131 /* A pointer to the base of a list of references to DIE's that
2132 are uniquely identified by their tag, presence/absence of
2133 children DIE's, and list of attribute/value pairs. */
2134 static dw_die_ref *abbrev_die_table;
2136 /* Number of elements currently allocated for abbrev_die_table. */
2137 static unsigned abbrev_die_table_allocated;
2139 /* Number of elements in type_die_table currently in use. */
2140 static unsigned abbrev_die_table_in_use;
2142 /* Size (in elements) of increments by which we may expand the
2143 abbrev_die_table. */
2144 #define ABBREV_DIE_TABLE_INCREMENT 256
2146 /* A pointer to the base of a table that contains line information
2147 for each source code line in .text in the compilation unit. */
2148 static dw_line_info_ref line_info_table;
2150 /* Number of elements currently allocated for line_info_table. */
2151 static unsigned line_info_table_allocated;
2153 /* Number of elements in separate_line_info_table currently in use. */
2154 static unsigned separate_line_info_table_in_use;
2156 /* A pointer to the base of a table that contains line information
2157 for each source code line outside of .text in the compilation unit. */
2158 static dw_separate_line_info_ref separate_line_info_table;
2160 /* Number of elements currently allocated for separate_line_info_table. */
2161 static unsigned separate_line_info_table_allocated;
2163 /* Number of elements in line_info_table currently in use. */
2164 static unsigned line_info_table_in_use;
2166 /* Size (in elements) of increments by which we may expand the
2167 line_info_table. */
2168 #define LINE_INFO_TABLE_INCREMENT 1024
2170 /* A pointer to the base of a table that contains a list of publicly
2171 accessible names. */
2172 static pubname_ref pubname_table;
2174 /* Number of elements currently allocated for pubname_table. */
2175 static unsigned pubname_table_allocated;
2177 /* Number of elements in pubname_table currently in use. */
2178 static unsigned pubname_table_in_use;
2180 /* Size (in elements) of increments by which we may expand the
2181 pubname_table. */
2182 #define PUBNAME_TABLE_INCREMENT 64
2184 /* A pointer to the base of a table that contains a list of publicly
2185 accessible names. */
2186 static arange_ref arange_table;
2188 /* Number of elements currently allocated for arange_table. */
2189 static unsigned arange_table_allocated;
2191 /* Number of elements in arange_table currently in use. */
2192 static unsigned arange_table_in_use;
2194 /* Size (in elements) of increments by which we may expand the
2195 arange_table. */
2196 #define ARANGE_TABLE_INCREMENT 64
2198 /* A pointer to the base of a list of pending types which we haven't
2199 generated DIEs for yet, but which we will have to come back to
2200 later on. */
2202 static tree *pending_types_list;
2204 /* Number of elements currently allocated for the pending_types_list. */
2205 static unsigned pending_types_allocated;
2207 /* Number of elements of pending_types_list currently in use. */
2208 static unsigned pending_types;
2210 /* Size (in elements) of increments by which we may expand the pending
2211 types list. Actually, a single hunk of space of this size should
2212 be enough for most typical programs. */
2213 #define PENDING_TYPES_INCREMENT 64
2215 /* Record whether the function being analyzed contains inlined functions. */
2216 static int current_function_has_inlines;
2217 static int comp_unit_has_inlines;
2219 /* A pointer to the ..._DECL node which we have most recently been working
2220 on. We keep this around just in case something about it looks screwy and
2221 we want to tell the user what the source coordinates for the actual
2222 declaration are. */
2223 static tree dwarf_last_decl;
2225 /* Forward declarations for functions defined in this file. */
2227 static void addr_const_to_string PROTO((char *, rtx));
2228 static char *addr_to_string PROTO((rtx));
2229 static int is_pseudo_reg PROTO((rtx));
2230 static tree type_main_variant PROTO((tree));
2231 static int is_tagged_type PROTO((tree));
2232 static char *dwarf_tag_name PROTO((unsigned));
2233 static char *dwarf_attr_name PROTO((unsigned));
2234 static char *dwarf_form_name PROTO((unsigned));
2235 static char *dwarf_stack_op_name PROTO((unsigned));
2236 static char *dwarf_type_encoding_name PROTO((unsigned));
2237 static tree decl_ultimate_origin PROTO((tree));
2238 static tree block_ultimate_origin PROTO((tree));
2239 static tree decl_class_context PROTO((tree));
2240 static void add_dwarf_attr PROTO((dw_die_ref, dw_attr_ref));
2241 static void add_AT_flag PROTO((dw_die_ref,
2242 enum dwarf_attribute,
2243 unsigned));
2244 static void add_AT_int PROTO((dw_die_ref,
2245 enum dwarf_attribute, long));
2246 static void add_AT_unsigned PROTO((dw_die_ref,
2247 enum dwarf_attribute,
2248 unsigned long));
2249 static void add_AT_long_long PROTO((dw_die_ref,
2250 enum dwarf_attribute,
2251 unsigned long, unsigned long));
2252 static void add_AT_float PROTO((dw_die_ref,
2253 enum dwarf_attribute,
2254 unsigned, long *));
2255 static void add_AT_string PROTO((dw_die_ref,
2256 enum dwarf_attribute, char *));
2257 static void add_AT_die_ref PROTO((dw_die_ref,
2258 enum dwarf_attribute,
2259 dw_die_ref));
2260 static void add_AT_fde_ref PROTO((dw_die_ref,
2261 enum dwarf_attribute,
2262 unsigned));
2263 static void add_AT_loc PROTO((dw_die_ref,
2264 enum dwarf_attribute,
2265 dw_loc_descr_ref));
2266 static void add_AT_addr PROTO((dw_die_ref,
2267 enum dwarf_attribute, char *));
2268 static void add_AT_lbl_id PROTO((dw_die_ref,
2269 enum dwarf_attribute, char *));
2270 static void add_AT_section_offset PROTO((dw_die_ref,
2271 enum dwarf_attribute, char *));
2272 static int is_extern_subr_die PROTO((dw_die_ref));
2273 static dw_attr_ref get_AT PROTO((dw_die_ref,
2274 enum dwarf_attribute));
2275 static char *get_AT_low_pc PROTO((dw_die_ref));
2276 static char *get_AT_hi_pc PROTO((dw_die_ref));
2277 static char *get_AT_string PROTO((dw_die_ref,
2278 enum dwarf_attribute));
2279 static int get_AT_flag PROTO((dw_die_ref,
2280 enum dwarf_attribute));
2281 static unsigned get_AT_unsigned PROTO((dw_die_ref,
2282 enum dwarf_attribute));
2283 static int is_c_family PROTO((void));
2284 static int is_fortran PROTO((void));
2285 static void remove_AT PROTO((dw_die_ref,
2286 enum dwarf_attribute));
2287 static void remove_children PROTO((dw_die_ref));
2288 static void add_child_die PROTO((dw_die_ref, dw_die_ref));
2289 static dw_die_ref new_die PROTO((enum dwarf_tag, dw_die_ref));
2290 static dw_die_ref lookup_type_die PROTO((tree));
2291 static void equate_type_number_to_die PROTO((tree, dw_die_ref));
2292 static dw_die_ref lookup_decl_die PROTO((tree));
2293 static void equate_decl_number_to_die PROTO((tree, dw_die_ref));
2294 static dw_loc_descr_ref new_loc_descr PROTO((enum dwarf_location_atom,
2295 unsigned long, unsigned long));
2296 static void add_loc_descr PROTO((dw_loc_descr_ref *,
2297 dw_loc_descr_ref));
2298 static void print_spaces PROTO((FILE *));
2299 static void print_die PROTO((dw_die_ref, FILE *));
2300 static void print_dwarf_line_table PROTO((FILE *));
2301 static void add_sibling_attributes PROTO((dw_die_ref));
2302 static void build_abbrev_table PROTO((dw_die_ref));
2303 static unsigned long size_of_string PROTO((char *));
2304 static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref));
2305 static unsigned long size_of_locs PROTO((dw_loc_descr_ref));
2306 static int constant_size PROTO((long unsigned));
2307 static unsigned long size_of_die PROTO((dw_die_ref));
2308 static void calc_die_sizes PROTO((dw_die_ref));
2309 static unsigned long size_of_prolog PROTO((void));
2310 static unsigned long size_of_line_info PROTO((void));
2311 static unsigned long size_of_pubnames PROTO((void));
2312 static unsigned long size_of_aranges PROTO((void));
2313 static enum dwarf_form value_format PROTO((dw_val_ref));
2314 static void output_value_format PROTO((dw_val_ref));
2315 static void output_abbrev_section PROTO((void));
2316 static void output_loc_operands PROTO((dw_loc_descr_ref));
2317 static unsigned long sibling_offset PROTO((dw_die_ref));
2318 static void output_die PROTO((dw_die_ref));
2319 static void output_compilation_unit_header PROTO((void));
2320 static char *dwarf2_name PROTO((tree, int));
2321 static void add_pubname PROTO((tree, dw_die_ref));
2322 static void output_pubnames PROTO((void));
2323 static void add_arrange PROTO((tree, dw_die_ref));
2324 static void output_arranges PROTO((void));
2325 static void output_line_info PROTO((void));
2326 static int is_body_block PROTO((tree));
2327 static dw_die_ref base_type_die PROTO((tree));
2328 static tree root_type PROTO((tree));
2329 static int is_base_type PROTO((tree));
2330 static dw_die_ref modified_type_die PROTO((tree, int, int, dw_die_ref));
2331 static int type_is_enum PROTO((tree));
2332 static dw_loc_descr_ref reg_loc_descriptor PROTO((rtx));
2333 static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long));
2334 static int is_based_loc PROTO((rtx));
2335 static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx));
2336 static dw_loc_descr_ref concat_loc_descriptor PROTO((rtx, rtx));
2337 static dw_loc_descr_ref loc_descriptor PROTO((rtx));
2338 static unsigned ceiling PROTO((unsigned, unsigned));
2339 static tree field_type PROTO((tree));
2340 static unsigned simple_type_align_in_bits PROTO((tree));
2341 static unsigned simple_type_size_in_bits PROTO((tree));
2342 static unsigned field_byte_offset PROTO((tree));
2343 static void add_AT_location_description PROTO((dw_die_ref,
2344 enum dwarf_attribute, rtx));
2345 static void add_data_member_location_attribute PROTO((dw_die_ref, tree));
2346 static void add_const_value_attribute PROTO((dw_die_ref, rtx));
2347 static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree));
2348 static void add_name_attribute PROTO((dw_die_ref, char *));
2349 static void add_bound_info PROTO((dw_die_ref,
2350 enum dwarf_attribute, tree));
2351 static void add_subscript_info PROTO((dw_die_ref, tree));
2352 static void add_byte_size_attribute PROTO((dw_die_ref, tree));
2353 static void add_bit_offset_attribute PROTO((dw_die_ref, tree));
2354 static void add_bit_size_attribute PROTO((dw_die_ref, tree));
2355 static void add_prototyped_attribute PROTO((dw_die_ref, tree));
2356 static void add_abstract_origin_attribute PROTO((dw_die_ref, tree));
2357 static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree));
2358 static void add_src_coords_attributes PROTO((dw_die_ref, tree));
2359 static void ad_name_and_src_coords_attributes PROTO((dw_die_ref, tree));
2360 static void push_decl_scope PROTO((tree));
2361 static dw_die_ref scope_die_for PROTO((tree, dw_die_ref));
2362 static void pop_decl_scope PROTO((void));
2363 static void add_type_attribute PROTO((dw_die_ref, tree, int, int,
2364 dw_die_ref));
2365 static char *type_tag PROTO((tree));
2366 static tree member_declared_type PROTO((tree));
2367 static char *decl_start_label PROTO((tree));
2368 static void gen_arrqay_type_die PROTO((tree, dw_die_ref));
2369 static void gen_set_type_die PROTO((tree, dw_die_ref));
2370 static void gen_entry_point_die PROTO((tree, dw_die_ref));
2371 static void pend_type PROTO((tree));
2372 static void output_pending_types_for_scope PROTO((dw_die_ref));
2373 static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref));
2374 static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref));
2375 static void gen_inlined_union_type_die PROTO((tree, dw_die_ref));
2376 static void gen_enumeration_type_die PROTO((tree, dw_die_ref));
2377 static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref));
2378 static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref));
2379 static void gen_formal_types_die PROTO((tree, dw_die_ref));
2380 static void gen_subprogram_die PROTO((tree, dw_die_ref));
2381 static void gen_variable_die PROTO((tree, dw_die_ref));
2382 static void gen_label_die PROTO((tree, dw_die_ref));
2383 static void gen_lexical_block_die PROTO((tree, dw_die_ref, int));
2384 static void gen_inlined_subprogram_die PROTO((tree, dw_die_ref, int));
2385 static void gen_field_die PROTO((tree, dw_die_ref));
2386 static void gen_ptr_to_mbr_type_die PROTO((tree, dw_die_ref));
2387 static void gen_compile_unit_die PROTO((char *));
2388 static void gen_string_type_die PROTO((tree, dw_die_ref));
2389 static void gen_inheritance_die PROTO((tree, dw_die_ref));
2390 static void gen_member_die PROTO((tree, dw_die_ref));
2391 static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref));
2392 static void gen_subroutine_type_die PROTO((tree, dw_die_ref));
2393 static void gen_typedef_die PROTO((tree, dw_die_ref));
2394 static void gen_type_die PROTO((tree, dw_die_ref));
2395 static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref));
2396 static void gen_block_die PROTO((tree, dw_die_ref, int));
2397 static void decls_for_scope PROTO((tree, dw_die_ref, int));
2398 static int is_redundant_typedef PROTO((tree));
2399 static void gen_decl_die PROTO((tree, dw_die_ref));
2400 static unsigned lookup_filename PROTO((char *));
2402 /* Section names used to hold DWARF debugging information. */
2403 #ifndef DEBUG_INFO_SECTION
2404 #define DEBUG_INFO_SECTION ".debug_info"
2405 #endif
2406 #ifndef ABBREV_SECTION
2407 #define ABBREV_SECTION ".debug_abbrev"
2408 #endif
2409 #ifndef ARANGES_SECTION
2410 #define ARANGES_SECTION ".debug_aranges"
2411 #endif
2412 #ifndef DW_MACINFO_SECTION
2413 #define DW_MACINFO_SECTION ".debug_macinfo"
2414 #endif
2415 #ifndef DEBUG_LINE_SECTION
2416 #define DEBUG_LINE_SECTION ".debug_line"
2417 #endif
2418 #ifndef LOC_SECTION
2419 #define LOC_SECTION ".debug_loc"
2420 #endif
2421 #ifndef PUBNAMES_SECTION
2422 #define PUBNAMES_SECTION ".debug_pubnames"
2423 #endif
2424 #ifndef STR_SECTION
2425 #define STR_SECTION ".debug_str"
2426 #endif
2428 /* Standard ELF section names for compiled code and data. */
2429 #ifndef TEXT_SECTION
2430 #define TEXT_SECTION ".text"
2431 #endif
2432 #ifndef DATA_SECTION
2433 #define DATA_SECTION ".data"
2434 #endif
2435 #ifndef BSS_SECTION
2436 #define BSS_SECTION ".bss"
2437 #endif
2440 /* Definitions of defaults for formats and names of various special
2441 (artificial) labels which may be generated within this file (when the -g
2442 options is used and DWARF_DEBUGGING_INFO is in effect.
2443 If necessary, these may be overridden from within the tm.h file, but
2444 typically, overriding these defaults is unnecessary. */
2446 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2448 #ifndef TEXT_END_LABEL
2449 #define TEXT_END_LABEL "Letext"
2450 #endif
2451 #ifndef DATA_END_LABEL
2452 #define DATA_END_LABEL "Ledata"
2453 #endif
2454 #ifndef BSS_END_LABEL
2455 #define BSS_END_LABEL "Lebss"
2456 #endif
2457 #ifndef INSN_LABEL_FMT
2458 #define INSN_LABEL_FMT "LI%u_"
2459 #endif
2460 #ifndef BLOCK_BEGIN_LABEL
2461 #define BLOCK_BEGIN_LABEL "LBB"
2462 #endif
2463 #ifndef BLOCK_END_LABEL
2464 #define BLOCK_END_LABEL "LBE"
2465 #endif
2466 #ifndef BODY_BEGIN_LABEL
2467 #define BODY_BEGIN_LABEL "Lbb"
2468 #endif
2469 #ifndef BODY_END_LABEL
2470 #define BODY_END_LABEL "Lbe"
2471 #endif
2472 #ifndef LINE_CODE_LABEL
2473 #define LINE_CODE_LABEL "LM"
2474 #endif
2475 #ifndef SEPARATE_LINE_CODE_LABEL
2476 #define SEPARATE_LINE_CODE_LABEL "LSM"
2477 #endif
2479 /* Convert a reference to the assembler name of a C-level name. This
2480 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
2481 a string rather than writing to a file. */
2482 #ifndef ASM_NAME_TO_STRING
2483 #define ASM_NAME_TO_STRING(STR, NAME) \
2484 do { \
2485 if ((NAME)[0] == '*') \
2486 strcpy (STR, NAME+1); \
2487 else \
2488 strcpy (STR, NAME); \
2490 while (0)
2491 #endif
2493 /* Convert an integer constant expression into assembler syntax. Addition
2494 and subtraction are the only arithmetic that may appear in these
2495 expressions. This is an adaptation of output_addr_const in final.c.
2496 Here, the target of the conversion is a string buffer. We can't use
2497 output_addr_const directly, because it writes to a file. */
2499 static void
2500 addr_const_to_string (str, x)
2501 char *str;
2502 rtx x;
2504 char buf1[256];
2505 char buf2[256];
2507 restart:
2508 str[0] = '\0';
2509 switch (GET_CODE (x))
2511 case PC:
2512 if (flag_pic)
2513 strcat (str, ",");
2514 else
2515 abort ();
2516 break;
2518 case SYMBOL_REF:
2519 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
2520 strcat (str, buf1);
2521 break;
2523 case LABEL_REF:
2524 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2525 ASM_NAME_TO_STRING (buf2, buf1);
2526 strcat (str, buf2);
2527 break;
2529 case CODE_LABEL:
2530 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
2531 ASM_NAME_TO_STRING (buf2, buf1);
2532 strcat (str, buf2);
2533 break;
2535 case CONST_INT:
2536 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
2537 strcat (str, buf1);
2538 break;
2540 case CONST:
2541 /* This used to output parentheses around the expression, but that does
2542 not work on the 386 (either ATT or BSD assembler). */
2543 addr_const_to_string (buf1, XEXP (x, 0));
2544 strcat (str, buf1);
2545 break;
2547 case CONST_DOUBLE:
2548 if (GET_MODE (x) == VOIDmode)
2550 /* We can use %d if the number is one word and positive. */
2551 if (CONST_DOUBLE_HIGH (x))
2552 sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
2553 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2554 else if (CONST_DOUBLE_LOW (x) < 0)
2555 sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
2556 else
2557 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
2558 CONST_DOUBLE_LOW (x));
2559 strcat (str, buf1);
2561 else
2562 /* We can't handle floating point constants; PRINT_OPERAND must
2563 handle them. */
2564 output_operand_lossage ("floating constant misused");
2565 break;
2567 case PLUS:
2568 /* Some assemblers need integer constants to appear last (eg masm). */
2569 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2571 addr_const_to_string (buf1, XEXP (x, 1));
2572 strcat (str, buf1);
2573 if (INTVAL (XEXP (x, 0)) >= 0)
2574 strcat (str, "+");
2576 addr_const_to_string (buf1, XEXP (x, 0));
2577 strcat (str, buf1);
2579 else
2581 addr_const_to_string (buf1, XEXP (x, 0));
2582 strcat (str, buf1);
2583 if (INTVAL (XEXP (x, 1)) >= 0)
2584 strcat (str, "+");
2586 addr_const_to_string (buf1, XEXP (x, 1));
2587 strcat (str, buf1);
2589 break;
2591 case MINUS:
2592 /* Avoid outputting things like x-x or x+5-x, since some assemblers
2593 can't handle that. */
2594 x = simplify_subtraction (x);
2595 if (GET_CODE (x) != MINUS)
2596 goto restart;
2598 addr_const_to_string (buf1, XEXP (x, 0));
2599 strcat (str, buf1);
2600 strcat (str, "-");
2601 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2602 && INTVAL (XEXP (x, 1)) < 0)
2604 strcat (str, ASM_OPEN_PAREN);
2605 addr_const_to_string (buf1, XEXP (x, 1));
2606 strcat (str, buf1);
2607 strcat (str, ASM_CLOSE_PAREN);
2609 else
2611 addr_const_to_string (buf1, XEXP (x, 1));
2612 strcat (str, buf1);
2614 break;
2616 case ZERO_EXTEND:
2617 case SIGN_EXTEND:
2618 addr_const_to_string (buf1, XEXP (x, 0));
2619 strcat (str, buf1);
2620 break;
2622 default:
2623 output_operand_lossage ("invalid expression as operand");
2627 /* Convert an address constant to a string, and return a pointer to
2628 a copy of the result, located on the heap. */
2630 static char *
2631 addr_to_string (x)
2632 rtx x;
2634 char buf[1024];
2635 addr_const_to_string (buf, x);
2636 return xstrdup (buf);
2639 /* Test if rtl node points to a pseudo register. */
2641 static inline int
2642 is_pseudo_reg (rtl)
2643 register rtx rtl;
2645 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
2646 || ((GET_CODE (rtl) == SUBREG)
2647 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
2650 /* Return a reference to a type, with its const and volatile qualifiers
2651 removed. */
2653 static inline tree
2654 type_main_variant (type)
2655 register tree type;
2657 type = TYPE_MAIN_VARIANT (type);
2659 /* There really should be only one main variant among any group of variants
2660 of a given type (and all of the MAIN_VARIANT values for all members of
2661 the group should point to that one type) but sometimes the C front-end
2662 messes this up for array types, so we work around that bug here. */
2664 if (TREE_CODE (type) == ARRAY_TYPE)
2665 while (type != TYPE_MAIN_VARIANT (type))
2666 type = TYPE_MAIN_VARIANT (type);
2668 return type;
2671 /* Return non-zero if the given type node represents a tagged type. */
2673 static inline int
2674 is_tagged_type (type)
2675 register tree type;
2677 register enum tree_code code = TREE_CODE (type);
2679 return (code == RECORD_TYPE || code == UNION_TYPE
2680 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
2683 /* Convert a DIE tag into its string name. */
2685 static char *
2686 dwarf_tag_name (tag)
2687 register unsigned tag;
2689 switch (tag)
2691 case DW_TAG_padding:
2692 return "DW_TAG_padding";
2693 case DW_TAG_array_type:
2694 return "DW_TAG_array_type";
2695 case DW_TAG_class_type:
2696 return "DW_TAG_class_type";
2697 case DW_TAG_entry_point:
2698 return "DW_TAG_entry_point";
2699 case DW_TAG_enumeration_type:
2700 return "DW_TAG_enumeration_type";
2701 case DW_TAG_formal_parameter:
2702 return "DW_TAG_formal_parameter";
2703 case DW_TAG_imported_declaration:
2704 return "DW_TAG_imported_declaration";
2705 case DW_TAG_label:
2706 return "DW_TAG_label";
2707 case DW_TAG_lexical_block:
2708 return "DW_TAG_lexical_block";
2709 case DW_TAG_member:
2710 return "DW_TAG_member";
2711 case DW_TAG_pointer_type:
2712 return "DW_TAG_pointer_type";
2713 case DW_TAG_reference_type:
2714 return "DW_TAG_reference_type";
2715 case DW_TAG_compile_unit:
2716 return "DW_TAG_compile_unit";
2717 case DW_TAG_string_type:
2718 return "DW_TAG_string_type";
2719 case DW_TAG_structure_type:
2720 return "DW_TAG_structure_type";
2721 case DW_TAG_subroutine_type:
2722 return "DW_TAG_subroutine_type";
2723 case DW_TAG_typedef:
2724 return "DW_TAG_typedef";
2725 case DW_TAG_union_type:
2726 return "DW_TAG_union_type";
2727 case DW_TAG_unspecified_parameters:
2728 return "DW_TAG_unspecified_parameters";
2729 case DW_TAG_variant:
2730 return "DW_TAG_variant";
2731 case DW_TAG_common_block:
2732 return "DW_TAG_common_block";
2733 case DW_TAG_common_inclusion:
2734 return "DW_TAG_common_inclusion";
2735 case DW_TAG_inheritance:
2736 return "DW_TAG_inheritance";
2737 case DW_TAG_inlined_subroutine:
2738 return "DW_TAG_inlined_subroutine";
2739 case DW_TAG_module:
2740 return "DW_TAG_module";
2741 case DW_TAG_ptr_to_member_type:
2742 return "DW_TAG_ptr_to_member_type";
2743 case DW_TAG_set_type:
2744 return "DW_TAG_set_type";
2745 case DW_TAG_subrange_type:
2746 return "DW_TAG_subrange_type";
2747 case DW_TAG_with_stmt:
2748 return "DW_TAG_with_stmt";
2749 case DW_TAG_access_declaration:
2750 return "DW_TAG_access_declaration";
2751 case DW_TAG_base_type:
2752 return "DW_TAG_base_type";
2753 case DW_TAG_catch_block:
2754 return "DW_TAG_catch_block";
2755 case DW_TAG_const_type:
2756 return "DW_TAG_const_type";
2757 case DW_TAG_constant:
2758 return "DW_TAG_constant";
2759 case DW_TAG_enumerator:
2760 return "DW_TAG_enumerator";
2761 case DW_TAG_file_type:
2762 return "DW_TAG_file_type";
2763 case DW_TAG_friend:
2764 return "DW_TAG_friend";
2765 case DW_TAG_namelist:
2766 return "DW_TAG_namelist";
2767 case DW_TAG_namelist_item:
2768 return "DW_TAG_namelist_item";
2769 case DW_TAG_packed_type:
2770 return "DW_TAG_packed_type";
2771 case DW_TAG_subprogram:
2772 return "DW_TAG_subprogram";
2773 case DW_TAG_template_type_param:
2774 return "DW_TAG_template_type_param";
2775 case DW_TAG_template_value_param:
2776 return "DW_TAG_template_value_param";
2777 case DW_TAG_thrown_type:
2778 return "DW_TAG_thrown_type";
2779 case DW_TAG_try_block:
2780 return "DW_TAG_try_block";
2781 case DW_TAG_variant_part:
2782 return "DW_TAG_variant_part";
2783 case DW_TAG_variable:
2784 return "DW_TAG_variable";
2785 case DW_TAG_volatile_type:
2786 return "DW_TAG_volatile_type";
2787 case DW_TAG_MIPS_loop:
2788 return "DW_TAG_MIPS_loop";
2789 case DW_TAG_format_label:
2790 return "DW_TAG_format_label";
2791 case DW_TAG_function_template:
2792 return "DW_TAG_function_template";
2793 case DW_TAG_class_template:
2794 return "DW_TAG_class_template";
2795 default:
2796 return "DW_TAG_<unknown>";
2800 /* Convert a DWARF attribute code into its string name. */
2802 static char *
2803 dwarf_attr_name (attr)
2804 register unsigned attr;
2806 switch (attr)
2808 case DW_AT_sibling:
2809 return "DW_AT_sibling";
2810 case DW_AT_location:
2811 return "DW_AT_location";
2812 case DW_AT_name:
2813 return "DW_AT_name";
2814 case DW_AT_ordering:
2815 return "DW_AT_ordering";
2816 case DW_AT_subscr_data:
2817 return "DW_AT_subscr_data";
2818 case DW_AT_byte_size:
2819 return "DW_AT_byte_size";
2820 case DW_AT_bit_offset:
2821 return "DW_AT_bit_offset";
2822 case DW_AT_bit_size:
2823 return "DW_AT_bit_size";
2824 case DW_AT_element_list:
2825 return "DW_AT_element_list";
2826 case DW_AT_stmt_list:
2827 return "DW_AT_stmt_list";
2828 case DW_AT_low_pc:
2829 return "DW_AT_low_pc";
2830 case DW_AT_high_pc:
2831 return "DW_AT_high_pc";
2832 case DW_AT_language:
2833 return "DW_AT_language";
2834 case DW_AT_member:
2835 return "DW_AT_member";
2836 case DW_AT_discr:
2837 return "DW_AT_discr";
2838 case DW_AT_discr_value:
2839 return "DW_AT_discr_value";
2840 case DW_AT_visibility:
2841 return "DW_AT_visibility";
2842 case DW_AT_import:
2843 return "DW_AT_import";
2844 case DW_AT_string_length:
2845 return "DW_AT_string_length";
2846 case DW_AT_common_reference:
2847 return "DW_AT_common_reference";
2848 case DW_AT_comp_dir:
2849 return "DW_AT_comp_dir";
2850 case DW_AT_const_value:
2851 return "DW_AT_const_value";
2852 case DW_AT_containing_type:
2853 return "DW_AT_containing_type";
2854 case DW_AT_default_value:
2855 return "DW_AT_default_value";
2856 case DW_AT_inline:
2857 return "DW_AT_inline";
2858 case DW_AT_is_optional:
2859 return "DW_AT_is_optional";
2860 case DW_AT_lower_bound:
2861 return "DW_AT_lower_bound";
2862 case DW_AT_producer:
2863 return "DW_AT_producer";
2864 case DW_AT_prototyped:
2865 return "DW_AT_prototyped";
2866 case DW_AT_return_addr:
2867 return "DW_AT_return_addr";
2868 case DW_AT_start_scope:
2869 return "DW_AT_start_scope";
2870 case DW_AT_stride_size:
2871 return "DW_AT_stride_size";
2872 case DW_AT_upper_bound:
2873 return "DW_AT_upper_bound";
2874 case DW_AT_abstract_origin:
2875 return "DW_AT_abstract_origin";
2876 case DW_AT_accessibility:
2877 return "DW_AT_accessibility";
2878 case DW_AT_address_class:
2879 return "DW_AT_address_class";
2880 case DW_AT_artificial:
2881 return "DW_AT_artificial";
2882 case DW_AT_base_types:
2883 return "DW_AT_base_types";
2884 case DW_AT_calling_convention:
2885 return "DW_AT_calling_convention";
2886 case DW_AT_count:
2887 return "DW_AT_count";
2888 case DW_AT_data_member_location:
2889 return "DW_AT_data_member_location";
2890 case DW_AT_decl_column:
2891 return "DW_AT_decl_column";
2892 case DW_AT_decl_file:
2893 return "DW_AT_decl_file";
2894 case DW_AT_decl_line:
2895 return "DW_AT_decl_line";
2896 case DW_AT_declaration:
2897 return "DW_AT_declaration";
2898 case DW_AT_discr_list:
2899 return "DW_AT_discr_list";
2900 case DW_AT_encoding:
2901 return "DW_AT_encoding";
2902 case DW_AT_external:
2903 return "DW_AT_external";
2904 case DW_AT_frame_base:
2905 return "DW_AT_frame_base";
2906 case DW_AT_friend:
2907 return "DW_AT_friend";
2908 case DW_AT_identifier_case:
2909 return "DW_AT_identifier_case";
2910 case DW_AT_macro_info:
2911 return "DW_AT_macro_info";
2912 case DW_AT_namelist_items:
2913 return "DW_AT_namelist_items";
2914 case DW_AT_priority:
2915 return "DW_AT_priority";
2916 case DW_AT_segment:
2917 return "DW_AT_segment";
2918 case DW_AT_specification:
2919 return "DW_AT_specification";
2920 case DW_AT_static_link:
2921 return "DW_AT_static_link";
2922 case DW_AT_type:
2923 return "DW_AT_type";
2924 case DW_AT_use_location:
2925 return "DW_AT_use_location";
2926 case DW_AT_variable_parameter:
2927 return "DW_AT_variable_parameter";
2928 case DW_AT_virtuality:
2929 return "DW_AT_virtuality";
2930 case DW_AT_vtable_elem_location:
2931 return "DW_AT_vtable_elem_location";
2933 case DW_AT_MIPS_fde:
2934 return "DW_AT_MIPS_fde";
2935 case DW_AT_MIPS_loop_begin:
2936 return "DW_AT_MIPS_loop_begin";
2937 case DW_AT_MIPS_tail_loop_begin:
2938 return "DW_AT_MIPS_tail_loop_begin";
2939 case DW_AT_MIPS_epilog_begin:
2940 return "DW_AT_MIPS_epilog_begin";
2941 case DW_AT_MIPS_loop_unroll_factor:
2942 return "DW_AT_MIPS_loop_unroll_factor";
2943 case DW_AT_MIPS_software_pipeline_depth:
2944 return "DW_AT_MIPS_software_pipeline_depth";
2945 case DW_AT_MIPS_linkage_name:
2946 return "DW_AT_MIPS_linkage_name";
2947 case DW_AT_MIPS_stride:
2948 return "DW_AT_MIPS_stride";
2949 case DW_AT_MIPS_abstract_name:
2950 return "DW_AT_MIPS_abstract_name";
2951 case DW_AT_MIPS_clone_origin:
2952 return "DW_AT_MIPS_clone_origin";
2953 case DW_AT_MIPS_has_inlines:
2954 return "DW_AT_MIPS_has_inlines";
2956 case DW_AT_sf_names:
2957 return "DW_AT_sf_names";
2958 case DW_AT_src_info:
2959 return "DW_AT_src_info";
2960 case DW_AT_mac_info:
2961 return "DW_AT_mac_info";
2962 case DW_AT_src_coords:
2963 return "DW_AT_src_coords";
2964 case DW_AT_body_begin:
2965 return "DW_AT_body_begin";
2966 case DW_AT_body_end:
2967 return "DW_AT_body_end";
2968 default:
2969 return "DW_AT_<unknown>";
2973 /* Convert a DWARF value form code into its string name. */
2975 static char *
2976 dwarf_form_name (form)
2977 register unsigned form;
2979 switch (form)
2981 case DW_FORM_addr:
2982 return "DW_FORM_addr";
2983 case DW_FORM_block2:
2984 return "DW_FORM_block2";
2985 case DW_FORM_block4:
2986 return "DW_FORM_block4";
2987 case DW_FORM_data2:
2988 return "DW_FORM_data2";
2989 case DW_FORM_data4:
2990 return "DW_FORM_data4";
2991 case DW_FORM_data8:
2992 return "DW_FORM_data8";
2993 case DW_FORM_string:
2994 return "DW_FORM_string";
2995 case DW_FORM_block:
2996 return "DW_FORM_block";
2997 case DW_FORM_block1:
2998 return "DW_FORM_block1";
2999 case DW_FORM_data1:
3000 return "DW_FORM_data1";
3001 case DW_FORM_flag:
3002 return "DW_FORM_flag";
3003 case DW_FORM_sdata:
3004 return "DW_FORM_sdata";
3005 case DW_FORM_strp:
3006 return "DW_FORM_strp";
3007 case DW_FORM_udata:
3008 return "DW_FORM_udata";
3009 case DW_FORM_ref_addr:
3010 return "DW_FORM_ref_addr";
3011 case DW_FORM_ref1:
3012 return "DW_FORM_ref1";
3013 case DW_FORM_ref2:
3014 return "DW_FORM_ref2";
3015 case DW_FORM_ref4:
3016 return "DW_FORM_ref4";
3017 case DW_FORM_ref8:
3018 return "DW_FORM_ref8";
3019 case DW_FORM_ref_udata:
3020 return "DW_FORM_ref_udata";
3021 case DW_FORM_indirect:
3022 return "DW_FORM_indirect";
3023 default:
3024 return "DW_FORM_<unknown>";
3028 /* Convert a DWARF stack opcode into its string name. */
3030 static char *
3031 dwarf_stack_op_name (op)
3032 register unsigned op;
3034 switch (op)
3036 case DW_OP_addr:
3037 return "DW_OP_addr";
3038 case DW_OP_deref:
3039 return "DW_OP_deref";
3040 case DW_OP_const1u:
3041 return "DW_OP_const1u";
3042 case DW_OP_const1s:
3043 return "DW_OP_const1s";
3044 case DW_OP_const2u:
3045 return "DW_OP_const2u";
3046 case DW_OP_const2s:
3047 return "DW_OP_const2s";
3048 case DW_OP_const4u:
3049 return "DW_OP_const4u";
3050 case DW_OP_const4s:
3051 return "DW_OP_const4s";
3052 case DW_OP_const8u:
3053 return "DW_OP_const8u";
3054 case DW_OP_const8s:
3055 return "DW_OP_const8s";
3056 case DW_OP_constu:
3057 return "DW_OP_constu";
3058 case DW_OP_consts:
3059 return "DW_OP_consts";
3060 case DW_OP_dup:
3061 return "DW_OP_dup";
3062 case DW_OP_drop:
3063 return "DW_OP_drop";
3064 case DW_OP_over:
3065 return "DW_OP_over";
3066 case DW_OP_pick:
3067 return "DW_OP_pick";
3068 case DW_OP_swap:
3069 return "DW_OP_swap";
3070 case DW_OP_rot:
3071 return "DW_OP_rot";
3072 case DW_OP_xderef:
3073 return "DW_OP_xderef";
3074 case DW_OP_abs:
3075 return "DW_OP_abs";
3076 case DW_OP_and:
3077 return "DW_OP_and";
3078 case DW_OP_div:
3079 return "DW_OP_div";
3080 case DW_OP_minus:
3081 return "DW_OP_minus";
3082 case DW_OP_mod:
3083 return "DW_OP_mod";
3084 case DW_OP_mul:
3085 return "DW_OP_mul";
3086 case DW_OP_neg:
3087 return "DW_OP_neg";
3088 case DW_OP_not:
3089 return "DW_OP_not";
3090 case DW_OP_or:
3091 return "DW_OP_or";
3092 case DW_OP_plus:
3093 return "DW_OP_plus";
3094 case DW_OP_plus_uconst:
3095 return "DW_OP_plus_uconst";
3096 case DW_OP_shl:
3097 return "DW_OP_shl";
3098 case DW_OP_shr:
3099 return "DW_OP_shr";
3100 case DW_OP_shra:
3101 return "DW_OP_shra";
3102 case DW_OP_xor:
3103 return "DW_OP_xor";
3104 case DW_OP_bra:
3105 return "DW_OP_bra";
3106 case DW_OP_eq:
3107 return "DW_OP_eq";
3108 case DW_OP_ge:
3109 return "DW_OP_ge";
3110 case DW_OP_gt:
3111 return "DW_OP_gt";
3112 case DW_OP_le:
3113 return "DW_OP_le";
3114 case DW_OP_lt:
3115 return "DW_OP_lt";
3116 case DW_OP_ne:
3117 return "DW_OP_ne";
3118 case DW_OP_skip:
3119 return "DW_OP_skip";
3120 case DW_OP_lit0:
3121 return "DW_OP_lit0";
3122 case DW_OP_lit1:
3123 return "DW_OP_lit1";
3124 case DW_OP_lit2:
3125 return "DW_OP_lit2";
3126 case DW_OP_lit3:
3127 return "DW_OP_lit3";
3128 case DW_OP_lit4:
3129 return "DW_OP_lit4";
3130 case DW_OP_lit5:
3131 return "DW_OP_lit5";
3132 case DW_OP_lit6:
3133 return "DW_OP_lit6";
3134 case DW_OP_lit7:
3135 return "DW_OP_lit7";
3136 case DW_OP_lit8:
3137 return "DW_OP_lit8";
3138 case DW_OP_lit9:
3139 return "DW_OP_lit9";
3140 case DW_OP_lit10:
3141 return "DW_OP_lit10";
3142 case DW_OP_lit11:
3143 return "DW_OP_lit11";
3144 case DW_OP_lit12:
3145 return "DW_OP_lit12";
3146 case DW_OP_lit13:
3147 return "DW_OP_lit13";
3148 case DW_OP_lit14:
3149 return "DW_OP_lit14";
3150 case DW_OP_lit15:
3151 return "DW_OP_lit15";
3152 case DW_OP_lit16:
3153 return "DW_OP_lit16";
3154 case DW_OP_lit17:
3155 return "DW_OP_lit17";
3156 case DW_OP_lit18:
3157 return "DW_OP_lit18";
3158 case DW_OP_lit19:
3159 return "DW_OP_lit19";
3160 case DW_OP_lit20:
3161 return "DW_OP_lit20";
3162 case DW_OP_lit21:
3163 return "DW_OP_lit21";
3164 case DW_OP_lit22:
3165 return "DW_OP_lit22";
3166 case DW_OP_lit23:
3167 return "DW_OP_lit23";
3168 case DW_OP_lit24:
3169 return "DW_OP_lit24";
3170 case DW_OP_lit25:
3171 return "DW_OP_lit25";
3172 case DW_OP_lit26:
3173 return "DW_OP_lit26";
3174 case DW_OP_lit27:
3175 return "DW_OP_lit27";
3176 case DW_OP_lit28:
3177 return "DW_OP_lit28";
3178 case DW_OP_lit29:
3179 return "DW_OP_lit29";
3180 case DW_OP_lit30:
3181 return "DW_OP_lit30";
3182 case DW_OP_lit31:
3183 return "DW_OP_lit31";
3184 case DW_OP_reg0:
3185 return "DW_OP_reg0";
3186 case DW_OP_reg1:
3187 return "DW_OP_reg1";
3188 case DW_OP_reg2:
3189 return "DW_OP_reg2";
3190 case DW_OP_reg3:
3191 return "DW_OP_reg3";
3192 case DW_OP_reg4:
3193 return "DW_OP_reg4";
3194 case DW_OP_reg5:
3195 return "DW_OP_reg5";
3196 case DW_OP_reg6:
3197 return "DW_OP_reg6";
3198 case DW_OP_reg7:
3199 return "DW_OP_reg7";
3200 case DW_OP_reg8:
3201 return "DW_OP_reg8";
3202 case DW_OP_reg9:
3203 return "DW_OP_reg9";
3204 case DW_OP_reg10:
3205 return "DW_OP_reg10";
3206 case DW_OP_reg11:
3207 return "DW_OP_reg11";
3208 case DW_OP_reg12:
3209 return "DW_OP_reg12";
3210 case DW_OP_reg13:
3211 return "DW_OP_reg13";
3212 case DW_OP_reg14:
3213 return "DW_OP_reg14";
3214 case DW_OP_reg15:
3215 return "DW_OP_reg15";
3216 case DW_OP_reg16:
3217 return "DW_OP_reg16";
3218 case DW_OP_reg17:
3219 return "DW_OP_reg17";
3220 case DW_OP_reg18:
3221 return "DW_OP_reg18";
3222 case DW_OP_reg19:
3223 return "DW_OP_reg19";
3224 case DW_OP_reg20:
3225 return "DW_OP_reg20";
3226 case DW_OP_reg21:
3227 return "DW_OP_reg21";
3228 case DW_OP_reg22:
3229 return "DW_OP_reg22";
3230 case DW_OP_reg23:
3231 return "DW_OP_reg23";
3232 case DW_OP_reg24:
3233 return "DW_OP_reg24";
3234 case DW_OP_reg25:
3235 return "DW_OP_reg25";
3236 case DW_OP_reg26:
3237 return "DW_OP_reg26";
3238 case DW_OP_reg27:
3239 return "DW_OP_reg27";
3240 case DW_OP_reg28:
3241 return "DW_OP_reg28";
3242 case DW_OP_reg29:
3243 return "DW_OP_reg29";
3244 case DW_OP_reg30:
3245 return "DW_OP_reg30";
3246 case DW_OP_reg31:
3247 return "DW_OP_reg31";
3248 case DW_OP_breg0:
3249 return "DW_OP_breg0";
3250 case DW_OP_breg1:
3251 return "DW_OP_breg1";
3252 case DW_OP_breg2:
3253 return "DW_OP_breg2";
3254 case DW_OP_breg3:
3255 return "DW_OP_breg3";
3256 case DW_OP_breg4:
3257 return "DW_OP_breg4";
3258 case DW_OP_breg5:
3259 return "DW_OP_breg5";
3260 case DW_OP_breg6:
3261 return "DW_OP_breg6";
3262 case DW_OP_breg7:
3263 return "DW_OP_breg7";
3264 case DW_OP_breg8:
3265 return "DW_OP_breg8";
3266 case DW_OP_breg9:
3267 return "DW_OP_breg9";
3268 case DW_OP_breg10:
3269 return "DW_OP_breg10";
3270 case DW_OP_breg11:
3271 return "DW_OP_breg11";
3272 case DW_OP_breg12:
3273 return "DW_OP_breg12";
3274 case DW_OP_breg13:
3275 return "DW_OP_breg13";
3276 case DW_OP_breg14:
3277 return "DW_OP_breg14";
3278 case DW_OP_breg15:
3279 return "DW_OP_breg15";
3280 case DW_OP_breg16:
3281 return "DW_OP_breg16";
3282 case DW_OP_breg17:
3283 return "DW_OP_breg17";
3284 case DW_OP_breg18:
3285 return "DW_OP_breg18";
3286 case DW_OP_breg19:
3287 return "DW_OP_breg19";
3288 case DW_OP_breg20:
3289 return "DW_OP_breg20";
3290 case DW_OP_breg21:
3291 return "DW_OP_breg21";
3292 case DW_OP_breg22:
3293 return "DW_OP_breg22";
3294 case DW_OP_breg23:
3295 return "DW_OP_breg23";
3296 case DW_OP_breg24:
3297 return "DW_OP_breg24";
3298 case DW_OP_breg25:
3299 return "DW_OP_breg25";
3300 case DW_OP_breg26:
3301 return "DW_OP_breg26";
3302 case DW_OP_breg27:
3303 return "DW_OP_breg27";
3304 case DW_OP_breg28:
3305 return "DW_OP_breg28";
3306 case DW_OP_breg29:
3307 return "DW_OP_breg29";
3308 case DW_OP_breg30:
3309 return "DW_OP_breg30";
3310 case DW_OP_breg31:
3311 return "DW_OP_breg31";
3312 case DW_OP_regx:
3313 return "DW_OP_regx";
3314 case DW_OP_fbreg:
3315 return "DW_OP_fbreg";
3316 case DW_OP_bregx:
3317 return "DW_OP_bregx";
3318 case DW_OP_piece:
3319 return "DW_OP_piece";
3320 case DW_OP_deref_size:
3321 return "DW_OP_deref_size";
3322 case DW_OP_xderef_size:
3323 return "DW_OP_xderef_size";
3324 case DW_OP_nop:
3325 return "DW_OP_nop";
3326 default:
3327 return "OP_<unknown>";
3331 /* Convert a DWARF type code into its string name. */
3333 static char *
3334 dwarf_type_encoding_name (enc)
3335 register unsigned enc;
3337 switch (enc)
3339 case DW_ATE_address:
3340 return "DW_ATE_address";
3341 case DW_ATE_boolean:
3342 return "DW_ATE_boolean";
3343 case DW_ATE_complex_float:
3344 return "DW_ATE_complex_float";
3345 case DW_ATE_float:
3346 return "DW_ATE_float";
3347 case DW_ATE_signed:
3348 return "DW_ATE_signed";
3349 case DW_ATE_signed_char:
3350 return "DW_ATE_signed_char";
3351 case DW_ATE_unsigned:
3352 return "DW_ATE_unsigned";
3353 case DW_ATE_unsigned_char:
3354 return "DW_ATE_unsigned_char";
3355 default:
3356 return "DW_ATE_<unknown>";
3360 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3361 instance of an inlined instance of a decl which is local to an inline
3362 function, so we have to trace all of the way back through the origin chain
3363 to find out what sort of node actually served as the original seed for the
3364 given block. */
3366 static tree
3367 decl_ultimate_origin (decl)
3368 register tree decl;
3370 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
3372 if (immediate_origin == NULL_TREE)
3373 return NULL_TREE;
3374 else
3376 register tree ret_val;
3377 register tree lookahead = immediate_origin;
3381 ret_val = lookahead;
3382 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
3384 while (lookahead != NULL && lookahead != ret_val);
3386 return ret_val;
3390 /* Determine the "ultimate origin" of a block. The block may be an inlined
3391 instance of an inlined instance of a block which is local to an inline
3392 function, so we have to trace all of the way back through the origin chain
3393 to find out what sort of node actually served as the original seed for the
3394 given block. */
3396 static tree
3397 block_ultimate_origin (block)
3398 register tree block;
3400 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3402 if (immediate_origin == NULL_TREE)
3403 return NULL_TREE;
3404 else
3406 register tree ret_val;
3407 register tree lookahead = immediate_origin;
3411 ret_val = lookahead;
3412 lookahead = (TREE_CODE (ret_val) == BLOCK)
3413 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3414 : NULL;
3416 while (lookahead != NULL && lookahead != ret_val);
3418 return ret_val;
3422 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3423 of a virtual function may refer to a base class, so we check the 'this'
3424 parameter. */
3426 static tree
3427 decl_class_context (decl)
3428 tree decl;
3430 tree context = NULL_TREE;
3432 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3433 context = DECL_CONTEXT (decl);
3434 else
3435 context = TYPE_MAIN_VARIANT
3436 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3438 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
3439 context = NULL_TREE;
3441 return context;
3444 /* Add an attribute/value pair to a DIE */
3446 static inline void
3447 add_dwarf_attr (die, attr)
3448 register dw_die_ref die;
3449 register dw_attr_ref attr;
3451 if (die != NULL && attr != NULL)
3453 if (die->die_attr == NULL)
3455 die->die_attr = attr;
3456 die->die_attr_last = attr;
3458 else
3460 die->die_attr_last->dw_attr_next = attr;
3461 die->die_attr_last = attr;
3466 /* Add a flag value attribute to a DIE. */
3468 static inline void
3469 add_AT_flag (die, attr_kind, flag)
3470 register dw_die_ref die;
3471 register enum dwarf_attribute attr_kind;
3472 register unsigned flag;
3474 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3476 attr->dw_attr_next = NULL;
3477 attr->dw_attr = attr_kind;
3478 attr->dw_attr_val.val_class = dw_val_class_flag;
3479 attr->dw_attr_val.v.val_flag = flag;
3480 add_dwarf_attr (die, attr);
3483 /* Add a signed integer attribute value to a DIE. */
3485 static inline void
3486 add_AT_int (die, attr_kind, int_val)
3487 register dw_die_ref die;
3488 register enum dwarf_attribute attr_kind;
3489 register long int int_val;
3491 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3493 attr->dw_attr_next = NULL;
3494 attr->dw_attr = attr_kind;
3495 attr->dw_attr_val.val_class = dw_val_class_const;
3496 attr->dw_attr_val.v.val_int = int_val;
3497 add_dwarf_attr (die, attr);
3500 /* Add an unsigned integer attribute value to a DIE. */
3502 static inline void
3503 add_AT_unsigned (die, attr_kind, unsigned_val)
3504 register dw_die_ref die;
3505 register enum dwarf_attribute attr_kind;
3506 register unsigned long unsigned_val;
3508 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3510 attr->dw_attr_next = NULL;
3511 attr->dw_attr = attr_kind;
3512 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
3513 attr->dw_attr_val.v.val_unsigned = unsigned_val;
3514 add_dwarf_attr (die, attr);
3517 /* Add an unsigned double integer attribute value to a DIE. */
3519 static inline void
3520 add_AT_long_long (die, attr_kind, val_hi, val_low)
3521 register dw_die_ref die;
3522 register enum dwarf_attribute attr_kind;
3523 register unsigned long val_hi;
3524 register unsigned long val_low;
3526 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3528 attr->dw_attr_next = NULL;
3529 attr->dw_attr = attr_kind;
3530 attr->dw_attr_val.val_class = dw_val_class_long_long;
3531 attr->dw_attr_val.v.val_long_long.hi = val_hi;
3532 attr->dw_attr_val.v.val_long_long.low = val_low;
3533 add_dwarf_attr (die, attr);
3536 /* Add a floating point attribute value to a DIE and return it. */
3538 static inline void
3539 add_AT_float (die, attr_kind, length, array)
3540 register dw_die_ref die;
3541 register enum dwarf_attribute attr_kind;
3542 register unsigned length;
3543 register long *array;
3545 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3547 attr->dw_attr_next = NULL;
3548 attr->dw_attr = attr_kind;
3549 attr->dw_attr_val.val_class = dw_val_class_float;
3550 attr->dw_attr_val.v.val_float.length = length;
3551 attr->dw_attr_val.v.val_float.array = array;
3552 add_dwarf_attr (die, attr);
3555 /* Add a string attribute value to a DIE. */
3557 static inline void
3558 add_AT_string (die, attr_kind, str)
3559 register dw_die_ref die;
3560 register enum dwarf_attribute attr_kind;
3561 register char *str;
3563 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3565 attr->dw_attr_next = NULL;
3566 attr->dw_attr = attr_kind;
3567 attr->dw_attr_val.val_class = dw_val_class_str;
3568 attr->dw_attr_val.v.val_str = xstrdup (str);
3569 add_dwarf_attr (die, attr);
3572 /* Add a DIE reference attribute value to a DIE. */
3574 static inline void
3575 add_AT_die_ref (die, attr_kind, targ_die)
3576 register dw_die_ref die;
3577 register enum dwarf_attribute attr_kind;
3578 register dw_die_ref targ_die;
3580 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3582 attr->dw_attr_next = NULL;
3583 attr->dw_attr = attr_kind;
3584 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3585 attr->dw_attr_val.v.val_die_ref = targ_die;
3586 add_dwarf_attr (die, attr);
3589 /* Add an FDE reference attribute value to a DIE. */
3591 static inline void
3592 add_AT_fde_ref (die, attr_kind, targ_fde)
3593 register dw_die_ref die;
3594 register enum dwarf_attribute attr_kind;
3595 register unsigned targ_fde;
3597 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3599 attr->dw_attr_next = NULL;
3600 attr->dw_attr = attr_kind;
3601 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
3602 attr->dw_attr_val.v.val_fde_index = targ_fde;
3603 add_dwarf_attr (die, attr);
3606 /* Add a location description attribute value to a DIE. */
3608 static inline void
3609 add_AT_loc (die, attr_kind, loc)
3610 register dw_die_ref die;
3611 register enum dwarf_attribute attr_kind;
3612 register dw_loc_descr_ref loc;
3614 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3616 attr->dw_attr_next = NULL;
3617 attr->dw_attr = attr_kind;
3618 attr->dw_attr_val.val_class = dw_val_class_loc;
3619 attr->dw_attr_val.v.val_loc = loc;
3620 add_dwarf_attr (die, attr);
3623 /* Add an address constant attribute value to a DIE. */
3625 static inline void
3626 add_AT_addr (die, attr_kind, addr)
3627 register dw_die_ref die;
3628 register enum dwarf_attribute attr_kind;
3629 char *addr;
3631 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3633 attr->dw_attr_next = NULL;
3634 attr->dw_attr = attr_kind;
3635 attr->dw_attr_val.val_class = dw_val_class_addr;
3636 attr->dw_attr_val.v.val_addr = addr;
3637 add_dwarf_attr (die, attr);
3640 /* Add a label identifier attribute value to a DIE. */
3642 static inline void
3643 add_AT_lbl_id (die, attr_kind, lbl_id)
3644 register dw_die_ref die;
3645 register enum dwarf_attribute attr_kind;
3646 register char *lbl_id;
3648 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3650 attr->dw_attr_next = NULL;
3651 attr->dw_attr = attr_kind;
3652 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
3653 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
3654 add_dwarf_attr (die, attr);
3657 /* Add a section offset attribute value to a DIE. */
3659 static inline void
3660 add_AT_section_offset (die, attr_kind, section)
3661 register dw_die_ref die;
3662 register enum dwarf_attribute attr_kind;
3663 register char *section;
3665 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3667 attr->dw_attr_next = NULL;
3668 attr->dw_attr = attr_kind;
3669 attr->dw_attr_val.val_class = dw_val_class_section_offset;
3670 attr->dw_attr_val.v.val_section = section;
3671 add_dwarf_attr (die, attr);
3675 /* Test if die refers to an external subroutine. */
3677 static inline int
3678 is_extern_subr_die (die)
3679 register dw_die_ref die;
3681 register dw_attr_ref a;
3682 register int is_subr = FALSE;
3683 register int is_extern = FALSE;
3685 if (die != NULL && die->die_tag == DW_TAG_subprogram)
3687 is_subr = TRUE;
3688 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3690 if (a->dw_attr == DW_AT_external
3691 && a->dw_attr_val.val_class == dw_val_class_flag
3692 && a->dw_attr_val.v.val_flag != 0)
3694 is_extern = TRUE;
3695 break;
3700 return is_subr && is_extern;
3703 /* Get the attribute of type attr_kind. */
3705 static inline dw_attr_ref
3706 get_AT (die, attr_kind)
3707 register dw_die_ref die;
3708 register enum dwarf_attribute attr_kind;
3710 register dw_attr_ref a;
3711 register dw_die_ref spec = NULL;
3713 if (die != NULL)
3715 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3717 if (a->dw_attr == attr_kind)
3718 return a;
3720 if (a->dw_attr == DW_AT_specification
3721 || a->dw_attr == DW_AT_abstract_origin)
3722 spec = a->dw_attr_val.v.val_die_ref;
3725 if (spec)
3726 return get_AT (spec, attr_kind);
3729 return NULL;
3732 /* Return the "low pc" attribute value, typically associated with
3733 a subprogram DIE. Return null if the "low pc" attribute is
3734 either not prsent, or if it cannot be represented as an
3735 assembler label identifier. */
3737 static inline char *
3738 get_AT_low_pc (die)
3739 register dw_die_ref die;
3741 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
3743 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3744 return a->dw_attr_val.v.val_lbl_id;
3746 return NULL;
3749 /* Return the "high pc" attribute value, typically associated with
3750 a subprogram DIE. Return null if the "high pc" attribute is
3751 either not prsent, or if it cannot be represented as an
3752 assembler label identifier. */
3754 static inline char *
3755 get_AT_hi_pc (die)
3756 register dw_die_ref die;
3758 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
3760 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3761 return a->dw_attr_val.v.val_lbl_id;
3763 return NULL;
3766 /* Return the value of the string attribute designated by ATTR_KIND, or
3767 NULL if it is not present. */
3769 static inline char *
3770 get_AT_string (die, attr_kind)
3771 register dw_die_ref die;
3772 register enum dwarf_attribute attr_kind;
3774 register dw_attr_ref a = get_AT (die, attr_kind);
3776 if (a && a->dw_attr_val.val_class == dw_val_class_str)
3777 return a->dw_attr_val.v.val_str;
3779 return NULL;
3782 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3783 if it is not present. */
3785 static inline int
3786 get_AT_flag (die, attr_kind)
3787 register dw_die_ref die;
3788 register enum dwarf_attribute attr_kind;
3790 register dw_attr_ref a = get_AT (die, attr_kind);
3792 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
3793 return a->dw_attr_val.v.val_flag;
3795 return -1;
3798 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3799 if it is not present. */
3801 static inline unsigned
3802 get_AT_unsigned (die, attr_kind)
3803 register dw_die_ref die;
3804 register enum dwarf_attribute attr_kind;
3806 register dw_attr_ref a = get_AT (die, attr_kind);
3808 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
3809 return a->dw_attr_val.v.val_unsigned;
3811 return 0;
3814 static inline int
3815 is_c_family ()
3817 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3819 return (lang == DW_LANG_C || lang == DW_LANG_C89
3820 || lang == DW_LANG_C_plus_plus);
3823 static inline int
3824 is_fortran ()
3826 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3828 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3831 /* Remove the specified attribute if present. */
3833 static inline void
3834 remove_AT (die, attr_kind)
3835 register dw_die_ref die;
3836 register enum dwarf_attribute attr_kind;
3838 register dw_attr_ref a;
3839 register dw_attr_ref removed = NULL;;
3841 if (die != NULL)
3843 if (die->die_attr->dw_attr == attr_kind)
3845 removed = die->die_attr;
3846 if (die->die_attr_last == die->die_attr)
3847 die->die_attr_last = NULL;
3849 die->die_attr = die->die_attr->dw_attr_next;
3852 else
3853 for (a = die->die_attr; a->dw_attr_next != NULL;
3854 a = a->dw_attr_next)
3855 if (a->dw_attr_next->dw_attr == attr_kind)
3857 removed = a->dw_attr_next;
3858 if (die->die_attr_last == a->dw_attr_next)
3859 die->die_attr_last = a;
3861 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
3862 break;
3865 if (removed != 0)
3866 free (removed);
3870 /* Discard the children of this DIE. */
3872 static inline void
3873 remove_children (die)
3874 register dw_die_ref die;
3876 register dw_die_ref child_die = die->die_child;
3878 die->die_child = NULL;
3879 die->die_child_last = NULL;
3881 while (child_die != NULL)
3883 register dw_die_ref tmp_die = child_die;
3884 register dw_attr_ref a;
3886 child_die = child_die->die_sib;
3888 for (a = tmp_die->die_attr; a != NULL; )
3890 register dw_attr_ref tmp_a = a;
3892 a = a->dw_attr_next;
3893 free (tmp_a);
3896 free (tmp_die);
3900 /* Add a child DIE below its parent. */
3902 static inline void
3903 add_child_die (die, child_die)
3904 register dw_die_ref die;
3905 register dw_die_ref child_die;
3907 if (die != NULL && child_die != NULL)
3909 assert (die != child_die);
3910 child_die->die_parent = die;
3911 child_die->die_sib = NULL;
3913 if (die->die_child == NULL)
3915 die->die_child = child_die;
3916 die->die_child_last = child_die;
3918 else
3920 die->die_child_last->die_sib = child_die;
3921 die->die_child_last = child_die;
3926 /* Return a pointer to a newly created DIE node. */
3928 static inline dw_die_ref
3929 new_die (tag_value, parent_die)
3930 register enum dwarf_tag tag_value;
3931 register dw_die_ref parent_die;
3933 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
3935 die->die_tag = tag_value;
3936 die->die_abbrev = 0;
3937 die->die_offset = 0;
3938 die->die_child = NULL;
3939 die->die_parent = NULL;
3940 die->die_sib = NULL;
3941 die->die_child_last = NULL;
3942 die->die_attr = NULL;
3943 die->die_attr_last = NULL;
3945 if (parent_die != NULL)
3946 add_child_die (parent_die, die);
3947 else
3949 limbo_die_node *limbo_node;
3951 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
3952 limbo_node->die = die;
3953 limbo_node->next = limbo_die_list;
3954 limbo_die_list = limbo_node;
3957 return die;
3960 /* Return the DIE associated with the given type specifier. */
3962 static inline dw_die_ref
3963 lookup_type_die (type)
3964 register tree type;
3966 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
3969 /* Equate a DIE to a given type specifier. */
3971 static void
3972 equate_type_number_to_die (type, type_die)
3973 register tree type;
3974 register dw_die_ref type_die;
3976 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
3979 /* Return the DIE associated with a given declaration. */
3981 static inline dw_die_ref
3982 lookup_decl_die (decl)
3983 register tree decl;
3985 register unsigned decl_id = DECL_UID (decl);
3987 return (decl_id < decl_die_table_in_use
3988 ? decl_die_table[decl_id] : NULL);
3991 /* Equate a DIE to a particular declaration. */
3993 static void
3994 equate_decl_number_to_die (decl, decl_die)
3995 register tree decl;
3996 register dw_die_ref decl_die;
3998 register unsigned decl_id = DECL_UID (decl);
3999 register unsigned i;
4000 register unsigned num_allocated;
4002 if (decl_id >= decl_die_table_allocated)
4004 num_allocated
4005 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4006 / DECL_DIE_TABLE_INCREMENT)
4007 * DECL_DIE_TABLE_INCREMENT;
4009 decl_die_table
4010 = (dw_die_ref *) xrealloc (decl_die_table,
4011 sizeof (dw_die_ref) * num_allocated);
4013 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4014 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4015 decl_die_table_allocated = num_allocated;
4018 if (decl_id >= decl_die_table_in_use)
4019 decl_die_table_in_use = (decl_id + 1);
4021 decl_die_table[decl_id] = decl_die;
4024 /* Return a pointer to a newly allocated location description. Location
4025 descriptions are simple expression terms that can be strung
4026 together to form more complicated location (address) descriptions. */
4028 static inline dw_loc_descr_ref
4029 new_loc_descr (op, oprnd1, oprnd2)
4030 register enum dwarf_location_atom op;
4031 register unsigned long oprnd1;
4032 register unsigned long oprnd2;
4034 register dw_loc_descr_ref descr
4035 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
4037 descr->dw_loc_next = NULL;
4038 descr->dw_loc_opc = op;
4039 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4040 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4041 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4042 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4044 return descr;
4047 /* Add a location description term to a location description expression. */
4049 static inline void
4050 add_loc_descr (list_head, descr)
4051 register dw_loc_descr_ref *list_head;
4052 register dw_loc_descr_ref descr;
4054 register dw_loc_descr_ref *d;
4056 /* Find the end of the chain. */
4057 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4060 *d = descr;
4063 /* Keep track of the number of spaces used to indent the
4064 output of the debugging routines that print the structure of
4065 the DIE internal representation. */
4066 static int print_indent;
4068 /* Indent the line the number of spaces given by print_indent. */
4070 static inline void
4071 print_spaces (outfile)
4072 FILE *outfile;
4074 fprintf (outfile, "%*s", print_indent, "");
4077 /* Print the information associated with a given DIE, and its children.
4078 This routine is a debugging aid only. */
4080 static void
4081 print_die (die, outfile)
4082 dw_die_ref die;
4083 FILE *outfile;
4085 register dw_attr_ref a;
4086 register dw_die_ref c;
4088 print_spaces (outfile);
4089 fprintf (outfile, "DIE %4u: %s\n",
4090 die->die_offset, dwarf_tag_name (die->die_tag));
4091 print_spaces (outfile);
4092 fprintf (outfile, " abbrev id: %u", die->die_abbrev);
4093 fprintf (outfile, " offset: %u\n", die->die_offset);
4095 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4097 print_spaces (outfile);
4098 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4100 switch (a->dw_attr_val.val_class)
4102 case dw_val_class_addr:
4103 fprintf (outfile, "address");
4104 break;
4105 case dw_val_class_loc:
4106 fprintf (outfile, "location descriptor");
4107 break;
4108 case dw_val_class_const:
4109 fprintf (outfile, "%d", a->dw_attr_val.v.val_int);
4110 break;
4111 case dw_val_class_unsigned_const:
4112 fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned);
4113 break;
4114 case dw_val_class_long_long:
4115 fprintf (outfile, "constant (%u,%u)",
4116 a->dw_attr_val.v.val_long_long.hi,
4117 a->dw_attr_val.v.val_long_long.low);
4118 break;
4119 case dw_val_class_float:
4120 fprintf (outfile, "floating-point constant");
4121 break;
4122 case dw_val_class_flag:
4123 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
4124 break;
4125 case dw_val_class_die_ref:
4126 if (a->dw_attr_val.v.val_die_ref != NULL)
4127 fprintf (outfile, "die -> %u",
4128 a->dw_attr_val.v.val_die_ref->die_offset);
4129 else
4130 fprintf (outfile, "die -> <null>");
4131 break;
4132 case dw_val_class_lbl_id:
4133 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
4134 break;
4135 case dw_val_class_section_offset:
4136 fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
4137 break;
4138 case dw_val_class_str:
4139 if (a->dw_attr_val.v.val_str != NULL)
4140 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
4141 else
4142 fprintf (outfile, "<null>");
4143 break;
4144 default:
4145 break;
4148 fprintf (outfile, "\n");
4151 if (die->die_child != NULL)
4153 print_indent += 4;
4154 for (c = die->die_child; c != NULL; c = c->die_sib)
4155 print_die (c, outfile);
4157 print_indent -= 4;
4161 /* Print the contents of the source code line number correspondence table.
4162 This routine is a debugging aid only. */
4164 static void
4165 print_dwarf_line_table (outfile)
4166 FILE *outfile;
4168 register unsigned i;
4169 register dw_line_info_ref line_info;
4171 fprintf (outfile, "\n\nDWARF source line information\n");
4172 for (i = 1; i < line_info_table_in_use; ++i)
4174 line_info = &line_info_table[i];
4175 fprintf (outfile, "%5d: ", i);
4176 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4177 fprintf (outfile, "%6d", line_info->dw_line_num);
4178 fprintf (outfile, "\n");
4181 fprintf (outfile, "\n\n");
4184 /* Print the information collected for a given DIE. */
4186 void
4187 debug_dwarf_die (die)
4188 dw_die_ref die;
4190 print_die (die, stderr);
4193 /* Print all DWARF information collected for the compilation unit.
4194 This routine is a debugging aid only. */
4196 void
4197 debug_dwarf ()
4199 print_indent = 0;
4200 print_die (comp_unit_die, stderr);
4201 print_dwarf_line_table (stderr);
4204 /* Traverse the DIE, and add a sibling attribute if it may have the
4205 effect of speeding up access to siblings. To save some space,
4206 avoid generating sibling attributes for DIE's without children. */
4208 static void
4209 add_sibling_attributes(die)
4210 register dw_die_ref die;
4212 register dw_die_ref c;
4213 register dw_attr_ref attr;
4214 if (die != comp_unit_die && die->die_child != NULL)
4216 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4217 attr->dw_attr_next = NULL;
4218 attr->dw_attr = DW_AT_sibling;
4219 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4220 attr->dw_attr_val.v.val_die_ref = die->die_sib;
4222 /* Add the sibling link to the front of the attribute list. */
4223 attr->dw_attr_next = die->die_attr;
4224 if (die->die_attr == NULL)
4225 die->die_attr_last = attr;
4227 die->die_attr = attr;
4230 for (c = die->die_child; c != NULL; c = c->die_sib)
4231 add_sibling_attributes (c);
4234 /* The format of each DIE (and its attribute value pairs)
4235 is encoded in an abbreviation table. This routine builds the
4236 abbreviation table and assigns a unique abbreviation id for
4237 each abbreviation entry. The children of each die are visited
4238 recursively. */
4240 static void
4241 build_abbrev_table (die)
4242 register dw_die_ref die;
4244 register unsigned long abbrev_id;
4245 register unsigned long n_alloc;
4246 register dw_die_ref c;
4247 register dw_attr_ref d_attr, a_attr;
4248 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4250 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4252 if (abbrev->die_tag == die->die_tag)
4254 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
4256 a_attr = abbrev->die_attr;
4257 d_attr = die->die_attr;
4259 while (a_attr != NULL && d_attr != NULL)
4261 if ((a_attr->dw_attr != d_attr->dw_attr)
4262 || (value_format (&a_attr->dw_attr_val)
4263 != value_format (&d_attr->dw_attr_val)))
4264 break;
4266 a_attr = a_attr->dw_attr_next;
4267 d_attr = d_attr->dw_attr_next;
4270 if (a_attr == NULL && d_attr == NULL)
4271 break;
4276 if (abbrev_id >= abbrev_die_table_in_use)
4278 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
4280 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
4281 abbrev_die_table
4282 = (dw_die_ref *) xrealloc (abbrev_die_table,
4283 sizeof (dw_die_ref) * n_alloc);
4285 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
4286 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
4287 abbrev_die_table_allocated = n_alloc;
4290 ++abbrev_die_table_in_use;
4291 abbrev_die_table[abbrev_id] = die;
4294 die->die_abbrev = abbrev_id;
4295 for (c = die->die_child; c != NULL; c = c->die_sib)
4296 build_abbrev_table (c);
4299 /* Return the size of a string, including the null byte. */
4301 static unsigned long
4302 size_of_string (str)
4303 register char *str;
4305 register unsigned long size = 0;
4306 register unsigned long slen = strlen (str);
4307 register unsigned long i;
4308 register unsigned c;
4310 for (i = 0; i < slen; ++i)
4312 c = str[i];
4313 if (c == '\\')
4314 ++i;
4316 size += 1;
4319 /* Null terminator. */
4320 size += 1;
4321 return size;
4324 /* Return the size of a location descriptor. */
4326 static unsigned long
4327 size_of_loc_descr (loc)
4328 register dw_loc_descr_ref loc;
4330 register unsigned long size = 1;
4332 switch (loc->dw_loc_opc)
4334 case DW_OP_addr:
4335 size += PTR_SIZE;
4336 break;
4337 case DW_OP_const1u:
4338 case DW_OP_const1s:
4339 size += 1;
4340 break;
4341 case DW_OP_const2u:
4342 case DW_OP_const2s:
4343 size += 2;
4344 break;
4345 case DW_OP_const4u:
4346 case DW_OP_const4s:
4347 size += 4;
4348 break;
4349 case DW_OP_const8u:
4350 case DW_OP_const8s:
4351 size += 8;
4352 break;
4353 case DW_OP_constu:
4354 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4355 break;
4356 case DW_OP_consts:
4357 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4358 break;
4359 case DW_OP_pick:
4360 size += 1;
4361 break;
4362 case DW_OP_plus_uconst:
4363 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4364 break;
4365 case DW_OP_skip:
4366 case DW_OP_bra:
4367 size += 2;
4368 break;
4369 case DW_OP_breg0:
4370 case DW_OP_breg1:
4371 case DW_OP_breg2:
4372 case DW_OP_breg3:
4373 case DW_OP_breg4:
4374 case DW_OP_breg5:
4375 case DW_OP_breg6:
4376 case DW_OP_breg7:
4377 case DW_OP_breg8:
4378 case DW_OP_breg9:
4379 case DW_OP_breg10:
4380 case DW_OP_breg11:
4381 case DW_OP_breg12:
4382 case DW_OP_breg13:
4383 case DW_OP_breg14:
4384 case DW_OP_breg15:
4385 case DW_OP_breg16:
4386 case DW_OP_breg17:
4387 case DW_OP_breg18:
4388 case DW_OP_breg19:
4389 case DW_OP_breg20:
4390 case DW_OP_breg21:
4391 case DW_OP_breg22:
4392 case DW_OP_breg23:
4393 case DW_OP_breg24:
4394 case DW_OP_breg25:
4395 case DW_OP_breg26:
4396 case DW_OP_breg27:
4397 case DW_OP_breg28:
4398 case DW_OP_breg29:
4399 case DW_OP_breg30:
4400 case DW_OP_breg31:
4401 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4402 break;
4403 case DW_OP_regx:
4404 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4405 break;
4406 case DW_OP_fbreg:
4407 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4408 break;
4409 case DW_OP_bregx:
4410 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4411 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4412 break;
4413 case DW_OP_piece:
4414 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4415 break;
4416 case DW_OP_deref_size:
4417 case DW_OP_xderef_size:
4418 size += 1;
4419 break;
4420 default:
4421 break;
4424 return size;
4427 /* Return the size of a series of location descriptors. */
4429 static unsigned long
4430 size_of_locs (loc)
4431 register dw_loc_descr_ref loc;
4433 register unsigned long size = 0;
4435 for (; loc != NULL; loc = loc->dw_loc_next)
4436 size += size_of_loc_descr (loc);
4438 return size;
4441 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4443 static int
4444 constant_size (value)
4445 long unsigned value;
4447 int log;
4449 if (value == 0)
4450 log = 0;
4451 else
4452 log = floor_log2 (value);
4454 log = log / 8;
4455 log = 1 << (floor_log2 (log) + 1);
4457 return log;
4460 /* Return the size of a DIE, as it is represented in the
4461 .debug_info section. */
4463 static unsigned long
4464 size_of_die (die)
4465 register dw_die_ref die;
4467 register unsigned long size = 0;
4468 register dw_attr_ref a;
4470 size += size_of_uleb128 (die->die_abbrev);
4471 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4473 switch (a->dw_attr_val.val_class)
4475 case dw_val_class_addr:
4476 size += PTR_SIZE;
4477 break;
4478 case dw_val_class_loc:
4480 register unsigned long lsize
4481 = size_of_locs (a->dw_attr_val.v.val_loc);
4483 /* Block length. */
4484 size += constant_size (lsize);
4485 size += lsize;
4487 break;
4488 case dw_val_class_const:
4489 size += 4;
4490 break;
4491 case dw_val_class_unsigned_const:
4492 size += constant_size (a->dw_attr_val.v.val_unsigned);
4493 break;
4494 case dw_val_class_long_long:
4495 size += 1 + 8; /* block */
4496 break;
4497 case dw_val_class_float:
4498 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
4499 break;
4500 case dw_val_class_flag:
4501 size += 1;
4502 break;
4503 case dw_val_class_die_ref:
4504 size += DWARF_OFFSET_SIZE;
4505 break;
4506 case dw_val_class_fde_ref:
4507 size += DWARF_OFFSET_SIZE;
4508 break;
4509 case dw_val_class_lbl_id:
4510 size += PTR_SIZE;
4511 break;
4512 case dw_val_class_section_offset:
4513 size += DWARF_OFFSET_SIZE;
4514 break;
4515 case dw_val_class_str:
4516 size += size_of_string (a->dw_attr_val.v.val_str);
4517 break;
4518 default:
4519 abort ();
4523 return size;
4526 /* Size the debugging information associated with a given DIE.
4527 Visits the DIE's children recursively. Updates the global
4528 variable next_die_offset, on each time through. Uses the
4529 current value of next_die_offset to update the die_offset
4530 field in each DIE. */
4532 static void
4533 calc_die_sizes (die)
4534 dw_die_ref die;
4536 register dw_die_ref c;
4537 die->die_offset = next_die_offset;
4538 next_die_offset += size_of_die (die);
4540 for (c = die->die_child; c != NULL; c = c->die_sib)
4541 calc_die_sizes (c);
4543 if (die->die_child != NULL)
4544 /* Count the null byte used to terminate sibling lists. */
4545 next_die_offset += 1;
4548 /* Return the size of the line information prolog generated for the
4549 compilation unit. */
4551 static unsigned long
4552 size_of_line_prolog ()
4554 register unsigned long size;
4555 register unsigned long ft_index;
4557 size = DWARF_LINE_PROLOG_HEADER_SIZE;
4559 /* Count the size of the table giving number of args for each
4560 standard opcode. */
4561 size += DWARF_LINE_OPCODE_BASE - 1;
4563 /* Include directory table is empty (at present). Count only the
4564 the null byte used to terminate the table. */
4565 size += 1;
4567 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4569 /* File name entry. */
4570 size += size_of_string (file_table[ft_index]);
4572 /* Include directory index. */
4573 size += size_of_uleb128 (0);
4575 /* Modification time. */
4576 size += size_of_uleb128 (0);
4578 /* File length in bytes. */
4579 size += size_of_uleb128 (0);
4582 /* Count the file table terminator. */
4583 size += 1;
4584 return size;
4587 /* Return the size of the line information generated for this
4588 compilation unit. */
4590 static unsigned long
4591 size_of_line_info ()
4593 register unsigned long size;
4594 register unsigned long lt_index;
4595 register unsigned long current_line;
4596 register long line_offset;
4597 register long line_delta;
4598 register unsigned long current_file;
4599 register unsigned long function;
4600 unsigned long size_of_set_address;
4602 /* Size of a DW_LNE_set_address instruction. */
4603 size_of_set_address = 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
4605 /* Version number. */
4606 size = 2;
4608 /* Prolog length specifier. */
4609 size += DWARF_OFFSET_SIZE;
4611 /* Prolog. */
4612 size += size_of_line_prolog ();
4614 /* Set address register instruction. */
4615 size += size_of_set_address;
4617 current_file = 1;
4618 current_line = 1;
4619 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
4621 register dw_line_info_ref line_info;
4623 /* Advance pc instruction. */
4624 /* ??? See the DW_LNS_advance_pc comment in output_line_info. */
4625 if (0)
4626 size += 1 + 2;
4627 else
4628 size += size_of_set_address;
4630 line_info = &line_info_table[lt_index];
4631 if (line_info->dw_file_num != current_file)
4633 /* Set file number instruction. */
4634 size += 1;
4635 current_file = line_info->dw_file_num;
4636 size += size_of_uleb128 (current_file);
4639 if (line_info->dw_line_num != current_line)
4641 line_offset = line_info->dw_line_num - current_line;
4642 line_delta = line_offset - DWARF_LINE_BASE;
4643 current_line = line_info->dw_line_num;
4644 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4645 /* 1-byte special line number instruction. */
4646 size += 1;
4647 else
4649 /* Advance line instruction. */
4650 size += 1;
4651 size += size_of_sleb128 (line_offset);
4652 /* Generate line entry instruction. */
4653 size += 1;
4658 /* Advance pc instruction. */
4659 if (0)
4660 size += 1 + 2;
4661 else
4662 size += size_of_set_address;
4664 /* End of line number info. marker. */
4665 size += 1 + size_of_uleb128 (1) + 1;
4667 function = 0;
4668 current_file = 1;
4669 current_line = 1;
4670 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
4672 register dw_separate_line_info_ref line_info
4673 = &separate_line_info_table[lt_index];
4674 if (function != line_info->function)
4676 function = line_info->function;
4677 /* Set address register instruction. */
4678 size += size_of_set_address;
4680 else
4682 /* Advance pc instruction. */
4683 if (0)
4684 size += 1 + 2;
4685 else
4686 size += size_of_set_address;
4689 if (line_info->dw_file_num != current_file)
4691 /* Set file number instruction. */
4692 size += 1;
4693 current_file = line_info->dw_file_num;
4694 size += size_of_uleb128 (current_file);
4697 if (line_info->dw_line_num != current_line)
4699 line_offset = line_info->dw_line_num - current_line;
4700 line_delta = line_offset - DWARF_LINE_BASE;
4701 current_line = line_info->dw_line_num;
4702 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4703 /* 1-byte special line number instruction. */
4704 size += 1;
4705 else
4707 /* Advance line instruction. */
4708 size += 1;
4709 size += size_of_sleb128 (line_offset);
4711 /* Generate line entry instruction. */
4712 size += 1;
4716 ++lt_index;
4718 /* If we're done with a function, end its sequence. */
4719 if (lt_index == separate_line_info_table_in_use
4720 || separate_line_info_table[lt_index].function != function)
4722 current_file = 1;
4723 current_line = 1;
4725 /* Advance pc instruction. */
4726 if (0)
4727 size += 1 + 2;
4728 else
4729 size += size_of_set_address;
4731 /* End of line number info. marker. */
4732 size += 1 + size_of_uleb128 (1) + 1;
4736 return size;
4739 /* Return the size of the .debug_pubnames table generated for the
4740 compilation unit. */
4742 static unsigned long
4743 size_of_pubnames ()
4745 register unsigned long size;
4746 register unsigned i;
4748 size = DWARF_PUBNAMES_HEADER_SIZE;
4749 for (i = 0; i < pubname_table_in_use; ++i)
4751 register pubname_ref p = &pubname_table[i];
4752 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
4755 size += DWARF_OFFSET_SIZE;
4756 return size;
4759 /* Return the size of the information in the .debug_aranges section. */
4761 static unsigned long
4762 size_of_aranges ()
4764 register unsigned long size;
4766 size = DWARF_ARANGES_HEADER_SIZE;
4768 /* Count the address/length pair for this compilation unit. */
4769 size += 2 * PTR_SIZE;
4770 size += 2 * PTR_SIZE * arange_table_in_use;
4772 /* Count the two zero words used to terminated the address range table. */
4773 size += 2 * PTR_SIZE;
4774 return size;
4777 /* Select the encoding of an attribute value. */
4779 static enum dwarf_form
4780 value_format (v)
4781 dw_val_ref v;
4783 switch (v->val_class)
4785 case dw_val_class_addr:
4786 return DW_FORM_addr;
4787 case dw_val_class_loc:
4788 switch (constant_size (size_of_locs (v->v.val_loc)))
4790 case 1:
4791 return DW_FORM_block1;
4792 case 2:
4793 return DW_FORM_block2;
4794 default:
4795 abort ();
4797 case dw_val_class_const:
4798 return DW_FORM_data4;
4799 case dw_val_class_unsigned_const:
4800 switch (constant_size (v->v.val_unsigned))
4802 case 1:
4803 return DW_FORM_data1;
4804 case 2:
4805 return DW_FORM_data2;
4806 case 4:
4807 return DW_FORM_data4;
4808 case 8:
4809 return DW_FORM_data8;
4810 default:
4811 abort ();
4813 case dw_val_class_long_long:
4814 return DW_FORM_block1;
4815 case dw_val_class_float:
4816 return DW_FORM_block1;
4817 case dw_val_class_flag:
4818 return DW_FORM_flag;
4819 case dw_val_class_die_ref:
4820 return DW_FORM_ref;
4821 case dw_val_class_fde_ref:
4822 return DW_FORM_data;
4823 case dw_val_class_lbl_id:
4824 return DW_FORM_addr;
4825 case dw_val_class_section_offset:
4826 return DW_FORM_data;
4827 case dw_val_class_str:
4828 return DW_FORM_string;
4829 default:
4830 abort ();
4834 /* Output the encoding of an attribute value. */
4836 static void
4837 output_value_format (v)
4838 dw_val_ref v;
4840 enum dwarf_form form = value_format (v);
4842 output_uleb128 (form);
4843 if (flag_debug_asm)
4844 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
4846 fputc ('\n', asm_out_file);
4849 /* Output the .debug_abbrev section which defines the DIE abbreviation
4850 table. */
4852 static void
4853 output_abbrev_section ()
4855 unsigned long abbrev_id;
4857 dw_attr_ref a_attr;
4858 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4860 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4862 output_uleb128 (abbrev_id);
4863 if (flag_debug_asm)
4864 fprintf (asm_out_file, " (abbrev code)");
4866 fputc ('\n', asm_out_file);
4867 output_uleb128 (abbrev->die_tag);
4868 if (flag_debug_asm)
4869 fprintf (asm_out_file, " (TAG: %s)",
4870 dwarf_tag_name (abbrev->die_tag));
4872 fputc ('\n', asm_out_file);
4873 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
4874 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
4876 if (flag_debug_asm)
4877 fprintf (asm_out_file, "\t%s %s",
4878 ASM_COMMENT_START,
4879 (abbrev->die_child != NULL
4880 ? "DW_children_yes" : "DW_children_no"));
4882 fputc ('\n', asm_out_file);
4884 for (a_attr = abbrev->die_attr; a_attr != NULL;
4885 a_attr = a_attr->dw_attr_next)
4887 output_uleb128 (a_attr->dw_attr);
4888 if (flag_debug_asm)
4889 fprintf (asm_out_file, " (%s)",
4890 dwarf_attr_name (a_attr->dw_attr));
4892 fputc ('\n', asm_out_file);
4893 output_value_format (&a_attr->dw_attr_val);
4896 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
4900 /* Output location description stack opcode's operands (if any). */
4902 static void
4903 output_loc_operands (loc)
4904 register dw_loc_descr_ref loc;
4906 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
4907 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
4909 switch (loc->dw_loc_opc)
4911 case DW_OP_addr:
4912 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
4913 fputc ('\n', asm_out_file);
4914 break;
4915 case DW_OP_const1u:
4916 case DW_OP_const1s:
4917 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4918 fputc ('\n', asm_out_file);
4919 break;
4920 case DW_OP_const2u:
4921 case DW_OP_const2s:
4922 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4923 fputc ('\n', asm_out_file);
4924 break;
4925 case DW_OP_const4u:
4926 case DW_OP_const4s:
4927 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
4928 fputc ('\n', asm_out_file);
4929 break;
4930 case DW_OP_const8u:
4931 case DW_OP_const8s:
4932 abort ();
4933 fputc ('\n', asm_out_file);
4934 break;
4935 case DW_OP_constu:
4936 output_uleb128 (val1->v.val_unsigned);
4937 fputc ('\n', asm_out_file);
4938 break;
4939 case DW_OP_consts:
4940 output_sleb128 (val1->v.val_int);
4941 fputc ('\n', asm_out_file);
4942 break;
4943 case DW_OP_pick:
4944 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
4945 fputc ('\n', asm_out_file);
4946 break;
4947 case DW_OP_plus_uconst:
4948 output_uleb128 (val1->v.val_unsigned);
4949 fputc ('\n', asm_out_file);
4950 break;
4951 case DW_OP_skip:
4952 case DW_OP_bra:
4953 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4954 fputc ('\n', asm_out_file);
4955 break;
4956 case DW_OP_breg0:
4957 case DW_OP_breg1:
4958 case DW_OP_breg2:
4959 case DW_OP_breg3:
4960 case DW_OP_breg4:
4961 case DW_OP_breg5:
4962 case DW_OP_breg6:
4963 case DW_OP_breg7:
4964 case DW_OP_breg8:
4965 case DW_OP_breg9:
4966 case DW_OP_breg10:
4967 case DW_OP_breg11:
4968 case DW_OP_breg12:
4969 case DW_OP_breg13:
4970 case DW_OP_breg14:
4971 case DW_OP_breg15:
4972 case DW_OP_breg16:
4973 case DW_OP_breg17:
4974 case DW_OP_breg18:
4975 case DW_OP_breg19:
4976 case DW_OP_breg20:
4977 case DW_OP_breg21:
4978 case DW_OP_breg22:
4979 case DW_OP_breg23:
4980 case DW_OP_breg24:
4981 case DW_OP_breg25:
4982 case DW_OP_breg26:
4983 case DW_OP_breg27:
4984 case DW_OP_breg28:
4985 case DW_OP_breg29:
4986 case DW_OP_breg30:
4987 case DW_OP_breg31:
4988 output_sleb128 (val1->v.val_int);
4989 fputc ('\n', asm_out_file);
4990 break;
4991 case DW_OP_regx:
4992 output_uleb128 (val1->v.val_unsigned);
4993 fputc ('\n', asm_out_file);
4994 break;
4995 case DW_OP_fbreg:
4996 output_sleb128 (val1->v.val_int);
4997 fputc ('\n', asm_out_file);
4998 break;
4999 case DW_OP_bregx:
5000 output_uleb128 (val1->v.val_unsigned);
5001 fputc ('\n', asm_out_file);
5002 output_sleb128 (val2->v.val_int);
5003 fputc ('\n', asm_out_file);
5004 break;
5005 case DW_OP_piece:
5006 output_uleb128 (val1->v.val_unsigned);
5007 fputc ('\n', asm_out_file);
5008 break;
5009 case DW_OP_deref_size:
5010 case DW_OP_xderef_size:
5011 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
5012 fputc ('\n', asm_out_file);
5013 break;
5014 default:
5015 break;
5019 /* Compute the offset of a sibling. */
5021 static unsigned long
5022 sibling_offset (die)
5023 dw_die_ref die;
5025 unsigned long offset;
5027 if (die->die_child_last == NULL)
5028 offset = die->die_offset + size_of_die (die);
5029 else
5030 offset = sibling_offset (die->die_child_last) + 1;
5032 return offset;
5035 /* Output the DIE and its attributes. Called recursively to generate
5036 the definitions of each child DIE. */
5038 static void
5039 output_die (die)
5040 register dw_die_ref die;
5042 register dw_attr_ref a;
5043 register dw_die_ref c;
5044 register unsigned long ref_offset;
5045 register unsigned long size;
5046 register dw_loc_descr_ref loc;
5047 register int i;
5049 output_uleb128 (die->die_abbrev);
5050 if (flag_debug_asm)
5051 fprintf (asm_out_file, " (DIE (0x%x) %s)",
5052 die->die_offset, dwarf_tag_name (die->die_tag));
5054 fputc ('\n', asm_out_file);
5056 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5058 switch (a->dw_attr_val.val_class)
5060 case dw_val_class_addr:
5061 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
5062 a->dw_attr_val.v.val_addr);
5063 break;
5065 case dw_val_class_loc:
5066 size = size_of_locs (a->dw_attr_val.v.val_loc);
5068 /* Output the block length for this list of location operations. */
5069 switch (constant_size (size))
5071 case 1:
5072 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5073 break;
5074 case 2:
5075 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5076 break;
5077 default:
5078 abort ();
5081 if (flag_debug_asm)
5082 fprintf (asm_out_file, "\t%s %s",
5083 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5085 fputc ('\n', asm_out_file);
5086 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
5087 loc = loc->dw_loc_next)
5089 /* Output the opcode. */
5090 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
5091 if (flag_debug_asm)
5092 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
5093 dwarf_stack_op_name (loc->dw_loc_opc));
5095 fputc ('\n', asm_out_file);
5097 /* Output the operand(s) (if any). */
5098 output_loc_operands (loc);
5100 break;
5102 case dw_val_class_const:
5103 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
5104 break;
5106 case dw_val_class_unsigned_const:
5107 switch (constant_size (a->dw_attr_val.v.val_unsigned))
5109 case 1:
5110 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5111 a->dw_attr_val.v.val_unsigned);
5112 break;
5113 case 2:
5114 ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
5115 a->dw_attr_val.v.val_unsigned);
5116 break;
5117 case 4:
5118 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5119 a->dw_attr_val.v.val_unsigned);
5120 break;
5121 case 8:
5122 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5123 a->dw_attr_val.v.val_long_long.hi,
5124 a->dw_attr_val.v.val_long_long.low);
5125 break;
5126 default:
5127 abort ();
5129 break;
5131 case dw_val_class_long_long:
5132 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5133 if (flag_debug_asm)
5134 fprintf (asm_out_file, "\t%s %s",
5135 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5137 fputc ('\n', asm_out_file);
5138 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5139 a->dw_attr_val.v.val_long_long.hi,
5140 a->dw_attr_val.v.val_long_long.low);
5142 if (flag_debug_asm)
5143 fprintf (asm_out_file,
5144 "\t%s long long constant", ASM_COMMENT_START);
5146 fputc ('\n', asm_out_file);
5147 break;
5149 case dw_val_class_float:
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 %d",
5163 ASM_COMMENT_START, i);
5165 fputc ('\n', asm_out_file);
5167 break;
5169 case dw_val_class_flag:
5170 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
5171 break;
5173 case dw_val_class_die_ref:
5174 if (a->dw_attr_val.v.val_die_ref != NULL)
5175 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
5176 else if (a->dw_attr == DW_AT_sibling)
5177 ref_offset = sibling_offset(die);
5178 else
5179 abort ();
5181 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
5182 break;
5184 case dw_val_class_fde_ref:
5186 char l1[20];
5187 ASM_GENERATE_INTERNAL_LABEL
5188 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5189 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5190 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5192 break;
5194 case dw_val_class_lbl_id:
5195 ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
5196 break;
5198 case dw_val_class_section_offset:
5199 ASM_OUTPUT_DWARF_OFFSET (asm_out_file,
5200 stripattributes
5201 (a->dw_attr_val.v.val_section));
5202 break;
5204 case dw_val_class_str:
5205 if (flag_debug_asm)
5206 ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
5207 else
5208 ASM_OUTPUT_ASCII (asm_out_file,
5209 a->dw_attr_val.v.val_str,
5210 strlen (a->dw_attr_val.v.val_str) + 1);
5211 break;
5213 default:
5214 abort ();
5217 if (a->dw_attr_val.val_class != dw_val_class_loc
5218 && a->dw_attr_val.val_class != dw_val_class_long_long
5219 && a->dw_attr_val.val_class != dw_val_class_float)
5221 if (flag_debug_asm)
5222 fprintf (asm_out_file, "\t%s %s",
5223 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5225 fputc ('\n', asm_out_file);
5229 for (c = die->die_child; c != NULL; c = c->die_sib)
5230 output_die (c);
5232 if (die->die_child != NULL)
5234 /* Add null byte to terminate sibling list. */
5235 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5236 if (flag_debug_asm)
5237 fprintf (asm_out_file, "\t%s end of children of DIE 0x%x",
5238 ASM_COMMENT_START, die->die_offset);
5240 fputc ('\n', asm_out_file);
5244 /* Output the compilation unit that appears at the beginning of the
5245 .debug_info section, and precedes the DIE descriptions. */
5247 static void
5248 output_compilation_unit_header ()
5250 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
5251 if (flag_debug_asm)
5252 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
5253 ASM_COMMENT_START);
5255 fputc ('\n', asm_out_file);
5256 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5257 if (flag_debug_asm)
5258 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
5260 fputc ('\n', asm_out_file);
5261 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION));
5262 if (flag_debug_asm)
5263 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
5264 ASM_COMMENT_START);
5266 fputc ('\n', asm_out_file);
5267 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5268 if (flag_debug_asm)
5269 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
5271 fputc ('\n', asm_out_file);
5274 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5275 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5276 argument list, and maybe the scope. */
5278 static char *
5279 dwarf2_name (decl, scope)
5280 tree decl;
5281 int scope;
5283 return (*decl_printable_name) (decl, scope ? 1 : 0);
5286 /* Add a new entry to .debug_pubnames if appropriate. */
5288 static void
5289 add_pubname (decl, die)
5290 tree decl;
5291 dw_die_ref die;
5293 pubname_ref p;
5295 if (! TREE_PUBLIC (decl))
5296 return;
5298 if (pubname_table_in_use == pubname_table_allocated)
5300 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5301 pubname_table = (pubname_ref) xrealloc
5302 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5305 p = &pubname_table[pubname_table_in_use++];
5306 p->die = die;
5308 p->name = xstrdup (dwarf2_name (decl, 1));
5311 /* Output the public names table used to speed up access to externally
5312 visible names. For now, only generate entries for externally
5313 visible procedures. */
5315 static void
5316 output_pubnames ()
5318 register unsigned i;
5319 register unsigned long pubnames_length = size_of_pubnames ();
5321 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
5323 if (flag_debug_asm)
5324 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
5325 ASM_COMMENT_START);
5327 fputc ('\n', asm_out_file);
5328 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5330 if (flag_debug_asm)
5331 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5333 fputc ('\n', asm_out_file);
5334 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION));
5335 if (flag_debug_asm)
5336 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5337 ASM_COMMENT_START);
5339 fputc ('\n', asm_out_file);
5340 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
5341 if (flag_debug_asm)
5342 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
5344 fputc ('\n', asm_out_file);
5345 for (i = 0; i < pubname_table_in_use; ++i)
5347 register pubname_ref pub = &pubname_table[i];
5349 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
5350 if (flag_debug_asm)
5351 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
5353 fputc ('\n', asm_out_file);
5355 if (flag_debug_asm)
5357 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5358 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5360 else
5362 ASM_OUTPUT_ASCII (asm_out_file, pub->name, 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, stripattributes (DEBUG_INFO_SECTION));
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 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
5432 if (PTR_SIZE == 8)
5433 fprintf (asm_out_file, ",0,0");
5435 if (flag_debug_asm)
5436 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5437 ASM_COMMENT_START, 2 * PTR_SIZE);
5439 fputc ('\n', asm_out_file);
5440 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
5441 if (flag_debug_asm)
5442 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5444 fputc ('\n', asm_out_file);
5445 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, TEXT_SECTION);
5446 if (flag_debug_asm)
5447 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5449 fputc ('\n', asm_out_file);
5450 for (i = 0; i < arange_table_in_use; ++i)
5452 dw_die_ref a = arange_table[i];
5454 if (a->die_tag == DW_TAG_subprogram)
5455 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a));
5456 else
5458 char *name = get_AT_string (a, DW_AT_MIPS_linkage_name);
5459 if (! name)
5460 name = get_AT_string (a, DW_AT_name);
5462 ASM_OUTPUT_DWARF_ADDR (asm_out_file, name);
5465 if (flag_debug_asm)
5466 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5468 fputc ('\n', asm_out_file);
5469 if (a->die_tag == DW_TAG_subprogram)
5470 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a),
5471 get_AT_low_pc (a));
5472 else
5473 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5474 get_AT_unsigned (a, DW_AT_byte_size));
5476 if (flag_debug_asm)
5477 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5479 fputc ('\n', asm_out_file);
5482 /* Output the terminator words. */
5483 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5484 fputc ('\n', asm_out_file);
5485 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5486 fputc ('\n', asm_out_file);
5489 /* Output the source line number correspondence information. This
5490 information goes into the .debug_line section.
5492 If the format of this data changes, then the function size_of_line_info
5493 must also be adjusted the same way. */
5495 static void
5496 output_line_info ()
5498 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5499 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5500 register unsigned opc;
5501 register unsigned n_op_args;
5502 register unsigned long ft_index;
5503 register unsigned long lt_index;
5504 register unsigned long current_line;
5505 register long line_offset;
5506 register long line_delta;
5507 register unsigned long current_file;
5508 register unsigned long function;
5510 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
5511 if (flag_debug_asm)
5512 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5513 ASM_COMMENT_START);
5515 fputc ('\n', asm_out_file);
5516 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5517 if (flag_debug_asm)
5518 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5520 fputc ('\n', asm_out_file);
5521 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5522 if (flag_debug_asm)
5523 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5525 fputc ('\n', asm_out_file);
5526 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5527 if (flag_debug_asm)
5528 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5529 ASM_COMMENT_START);
5531 fputc ('\n', asm_out_file);
5532 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5533 if (flag_debug_asm)
5534 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5535 ASM_COMMENT_START);
5537 fputc ('\n', asm_out_file);
5538 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5539 if (flag_debug_asm)
5540 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5541 ASM_COMMENT_START);
5543 fputc ('\n', asm_out_file);
5544 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5545 if (flag_debug_asm)
5546 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5547 ASM_COMMENT_START);
5549 fputc ('\n', asm_out_file);
5550 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5551 if (flag_debug_asm)
5552 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5554 fputc ('\n', asm_out_file);
5555 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5557 switch (opc)
5559 case DW_LNS_advance_pc:
5560 case DW_LNS_advance_line:
5561 case DW_LNS_set_file:
5562 case DW_LNS_set_column:
5563 case DW_LNS_fixed_advance_pc:
5564 n_op_args = 1;
5565 break;
5566 default:
5567 n_op_args = 0;
5568 break;
5570 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5571 if (flag_debug_asm)
5572 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5573 ASM_COMMENT_START, opc, n_op_args);
5574 fputc ('\n', asm_out_file);
5577 if (flag_debug_asm)
5578 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5580 /* Include directory table is empty, at present */
5581 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5582 fputc ('\n', asm_out_file);
5583 if (flag_debug_asm)
5584 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5586 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5588 if (flag_debug_asm)
5590 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5591 fprintf (asm_out_file, "%s File Entry: 0x%x",
5592 ASM_COMMENT_START, ft_index);
5594 else
5596 ASM_OUTPUT_ASCII (asm_out_file,
5597 file_table[ft_index],
5598 strlen (file_table[ft_index]) + 1);
5601 fputc ('\n', asm_out_file);
5603 /* Include directory index */
5604 output_uleb128 (0);
5605 fputc ('\n', asm_out_file);
5607 /* Modification time */
5608 output_uleb128 (0);
5609 fputc ('\n', asm_out_file);
5611 /* File length in bytes */
5612 output_uleb128 (0);
5613 fputc ('\n', asm_out_file);
5616 /* Terminate the file name table */
5617 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5618 fputc ('\n', asm_out_file);
5620 /* Set the address register to the first location in the text section */
5621 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5622 if (flag_debug_asm)
5623 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5625 fputc ('\n', asm_out_file);
5626 output_uleb128 (1 + PTR_SIZE);
5627 fputc ('\n', asm_out_file);
5628 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5629 fputc ('\n', asm_out_file);
5630 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
5631 fputc ('\n', asm_out_file);
5633 /* Generate the line number to PC correspondence table, encoded as
5634 a series of state machine operations. */
5635 current_file = 1;
5636 current_line = 1;
5637 strcpy (prev_line_label, TEXT_SECTION);
5638 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5640 register dw_line_info_ref line_info;
5642 /* Emit debug info for the address of the current line, choosing
5643 the encoding that uses the least amount of space. */
5644 /* ??? Unfortunately, we have little choice here currently, and must
5645 always use the most general form. Gcc does not know the address
5646 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5647 dwarf2 aware assemblers at this time, so we can't use any special
5648 pseudo ops that would allow the assembler to optimally encode this for
5649 us. Many ports do have length attributes which will give an upper
5650 bound on the address range. We could perhaps use length attributes
5651 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5652 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5653 if (0)
5655 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5656 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5657 if (flag_debug_asm)
5658 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5659 ASM_COMMENT_START);
5661 fputc ('\n', asm_out_file);
5662 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5663 fputc ('\n', asm_out_file);
5665 else
5667 /* This can handle any delta. This takes 4+PTR_SIZE bytes. */
5668 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5669 if (flag_debug_asm)
5670 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5671 ASM_COMMENT_START);
5672 fputc ('\n', asm_out_file);
5673 output_uleb128 (1 + PTR_SIZE);
5674 fputc ('\n', asm_out_file);
5675 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5676 fputc ('\n', asm_out_file);
5677 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5678 fputc ('\n', asm_out_file);
5680 strcpy (prev_line_label, line_label);
5682 /* Emit debug info for the source file of the current line, if
5683 different from the previous line. */
5684 line_info = &line_info_table[lt_index];
5685 if (line_info->dw_file_num != current_file)
5687 current_file = line_info->dw_file_num;
5688 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5689 if (flag_debug_asm)
5690 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5692 fputc ('\n', asm_out_file);
5693 output_uleb128 (current_file);
5694 if (flag_debug_asm)
5695 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5697 fputc ('\n', asm_out_file);
5700 /* Emit debug info for the current line number, choosing the encoding
5701 that uses the least amount of space. */
5702 line_offset = line_info->dw_line_num - current_line;
5703 line_delta = line_offset - DWARF_LINE_BASE;
5704 current_line = line_info->dw_line_num;
5705 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5707 /* This can handle deltas from -10 to 234, using the current
5708 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5709 takes 1 byte. */
5710 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5711 DWARF_LINE_OPCODE_BASE + line_delta);
5712 if (flag_debug_asm)
5713 fprintf (asm_out_file,
5714 "\t%s line %d", ASM_COMMENT_START, current_line);
5716 fputc ('\n', asm_out_file);
5718 else
5720 /* This can handle any delta. This takes at least 4 bytes, depending
5721 on the value being encoded. */
5722 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5723 if (flag_debug_asm)
5724 fprintf (asm_out_file, "\t%s advance to line %d",
5725 ASM_COMMENT_START, current_line);
5727 fputc ('\n', asm_out_file);
5728 output_sleb128 (line_offset);
5729 fputc ('\n', asm_out_file);
5730 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5731 fputc ('\n', asm_out_file);
5735 /* Emit debug info for the address of the end of the function. */
5736 if (0)
5738 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5739 if (flag_debug_asm)
5740 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5741 ASM_COMMENT_START);
5743 fputc ('\n', asm_out_file);
5744 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5745 fputc ('\n', asm_out_file);
5747 else
5749 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5750 if (flag_debug_asm)
5751 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5752 fputc ('\n', asm_out_file);
5753 output_uleb128 (1 + PTR_SIZE);
5754 fputc ('\n', asm_out_file);
5755 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5756 fputc ('\n', asm_out_file);
5757 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
5758 fputc ('\n', asm_out_file);
5761 /* Output the marker for the end of the line number info. */
5762 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5763 if (flag_debug_asm)
5764 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5766 fputc ('\n', asm_out_file);
5767 output_uleb128 (1);
5768 fputc ('\n', asm_out_file);
5769 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5770 fputc ('\n', asm_out_file);
5772 function = 0;
5773 current_file = 1;
5774 current_line = 1;
5775 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5777 register dw_separate_line_info_ref line_info
5778 = &separate_line_info_table[lt_index];
5780 /* Emit debug info for the address of the current line. If this is
5781 a new function, or the first line of a function, then we need
5782 to handle it differently. */
5783 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5784 lt_index);
5785 if (function != line_info->function)
5787 function = line_info->function;
5789 /* Set the address register to the first line in the function */
5790 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5791 if (flag_debug_asm)
5792 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5793 ASM_COMMENT_START);
5795 fputc ('\n', asm_out_file);
5796 output_uleb128 (1 + PTR_SIZE);
5797 fputc ('\n', asm_out_file);
5798 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5799 fputc ('\n', asm_out_file);
5800 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5801 fputc ('\n', asm_out_file);
5803 else
5805 /* ??? See the DW_LNS_advance_pc comment above. */
5806 if (0)
5808 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5809 if (flag_debug_asm)
5810 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5811 ASM_COMMENT_START);
5813 fputc ('\n', asm_out_file);
5814 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5815 prev_line_label);
5816 fputc ('\n', asm_out_file);
5818 else
5820 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5821 if (flag_debug_asm)
5822 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5823 ASM_COMMENT_START);
5824 fputc ('\n', asm_out_file);
5825 output_uleb128 (1 + PTR_SIZE);
5826 fputc ('\n', asm_out_file);
5827 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5828 fputc ('\n', asm_out_file);
5829 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5830 fputc ('\n', asm_out_file);
5833 strcpy (prev_line_label, line_label);
5835 /* Emit debug info for the source file of the current line, if
5836 different from the previous line. */
5837 if (line_info->dw_file_num != current_file)
5839 current_file = line_info->dw_file_num;
5840 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5841 if (flag_debug_asm)
5842 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5844 fputc ('\n', asm_out_file);
5845 output_uleb128 (current_file);
5846 if (flag_debug_asm)
5847 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5849 fputc ('\n', asm_out_file);
5852 /* Emit debug info for the current line number, choosing the encoding
5853 that uses the least amount of space. */
5854 if (line_info->dw_line_num != current_line)
5856 line_offset = line_info->dw_line_num - current_line;
5857 line_delta = line_offset - DWARF_LINE_BASE;
5858 current_line = line_info->dw_line_num;
5859 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5861 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5862 DWARF_LINE_OPCODE_BASE + line_delta);
5863 if (flag_debug_asm)
5864 fprintf (asm_out_file,
5865 "\t%s line %d", ASM_COMMENT_START, current_line);
5867 fputc ('\n', asm_out_file);
5869 else
5871 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5872 if (flag_debug_asm)
5873 fprintf (asm_out_file, "\t%s advance to line %d",
5874 ASM_COMMENT_START, current_line);
5876 fputc ('\n', asm_out_file);
5877 output_sleb128 (line_offset);
5878 fputc ('\n', asm_out_file);
5879 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5880 fputc ('\n', asm_out_file);
5884 ++lt_index;
5886 /* If we're done with a function, end its sequence. */
5887 if (lt_index == separate_line_info_table_in_use
5888 || separate_line_info_table[lt_index].function != function)
5890 current_file = 1;
5891 current_line = 1;
5893 /* Emit debug info for the address of the end of the function. */
5894 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
5895 if (0)
5897 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5898 if (flag_debug_asm)
5899 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5900 ASM_COMMENT_START);
5902 fputc ('\n', asm_out_file);
5903 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5904 prev_line_label);
5905 fputc ('\n', asm_out_file);
5907 else
5909 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5910 if (flag_debug_asm)
5911 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5912 ASM_COMMENT_START);
5913 fputc ('\n', asm_out_file);
5914 output_uleb128 (1 + PTR_SIZE);
5915 fputc ('\n', asm_out_file);
5916 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5917 fputc ('\n', asm_out_file);
5918 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5919 fputc ('\n', asm_out_file);
5922 /* Output the marker for the end of this sequence. */
5923 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5924 if (flag_debug_asm)
5925 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
5926 ASM_COMMENT_START);
5928 fputc ('\n', asm_out_file);
5929 output_uleb128 (1);
5930 fputc ('\n', asm_out_file);
5931 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5932 fputc ('\n', asm_out_file);
5937 /* Given a pointer to a BLOCK node return non-zero if (and only if) the node
5938 in question represents the outermost pair of curly braces (i.e. the "body
5939 block") of a function or method.
5941 For any BLOCK node representing a "body block" of a function or method, the
5942 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
5943 represents the outermost (function) scope for the function or method (i.e.
5944 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
5945 *that* node in turn will point to the relevant FUNCTION_DECL node. */
5947 static inline int
5948 is_body_block (stmt)
5949 register tree stmt;
5951 if (TREE_CODE (stmt) == BLOCK)
5953 register tree parent = BLOCK_SUPERCONTEXT (stmt);
5955 if (TREE_CODE (parent) == BLOCK)
5957 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
5959 if (TREE_CODE (grandparent) == FUNCTION_DECL)
5960 return 1;
5964 return 0;
5967 /* Given a pointer to a tree node for some base type, return a pointer to
5968 a DIE that describes the given type.
5970 This routine must only be called for GCC type nodes that correspond to
5971 Dwarf base (fundamental) types. */
5973 static dw_die_ref
5974 base_type_die (type)
5975 register tree type;
5977 register dw_die_ref base_type_result;
5978 register char *type_name;
5979 register enum dwarf_type encoding;
5980 register tree name = TYPE_NAME (type);
5982 if (TREE_CODE (type) == ERROR_MARK
5983 || TREE_CODE (type) == VOID_TYPE)
5984 return 0;
5986 if (TREE_CODE (name) == TYPE_DECL)
5987 name = DECL_NAME (name);
5988 type_name = IDENTIFIER_POINTER (name);
5990 switch (TREE_CODE (type))
5992 case INTEGER_TYPE:
5993 /* Carefully distinguish the C character types, without messing
5994 up if the language is not C. Note that we check only for the names
5995 that contain spaces; other names might occur by coincidence in other
5996 languages. */
5997 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
5998 && (type == char_type_node
5999 || ! strcmp (type_name, "signed char")
6000 || ! strcmp (type_name, "unsigned char"))))
6002 if (TREE_UNSIGNED (type))
6003 encoding = DW_ATE_unsigned;
6004 else
6005 encoding = DW_ATE_signed;
6006 break;
6008 /* else fall through */
6010 case CHAR_TYPE:
6011 /* GNU Pascal/Ada CHAR type. Not used in C. */
6012 if (TREE_UNSIGNED (type))
6013 encoding = DW_ATE_unsigned_char;
6014 else
6015 encoding = DW_ATE_signed_char;
6016 break;
6018 case REAL_TYPE:
6019 encoding = DW_ATE_float;
6020 break;
6022 case COMPLEX_TYPE:
6023 encoding = DW_ATE_complex_float;
6024 break;
6026 case BOOLEAN_TYPE:
6027 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6028 encoding = DW_ATE_boolean;
6029 break;
6031 default:
6032 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6035 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6036 add_AT_string (base_type_result, DW_AT_name, type_name);
6037 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6038 TYPE_PRECISION (type) / BITS_PER_UNIT);
6039 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6041 return base_type_result;
6044 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6045 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6046 a given type is generally the same as the given type, except that if the
6047 given type is a pointer or reference type, then the root type of the given
6048 type is the root type of the "basis" type for the pointer or reference
6049 type. (This definition of the "root" type is recursive.) Also, the root
6050 type of a `const' qualified type or a `volatile' qualified type is the
6051 root type of the given type without the qualifiers. */
6053 static tree
6054 root_type (type)
6055 register tree type;
6057 if (TREE_CODE (type) == ERROR_MARK)
6058 return error_mark_node;
6060 switch (TREE_CODE (type))
6062 case ERROR_MARK:
6063 return error_mark_node;
6065 case POINTER_TYPE:
6066 case REFERENCE_TYPE:
6067 return type_main_variant (root_type (TREE_TYPE (type)));
6069 default:
6070 return type_main_variant (type);
6074 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6075 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6077 static inline int
6078 is_base_type (type)
6079 register tree type;
6081 switch (TREE_CODE (type))
6083 case ERROR_MARK:
6084 case VOID_TYPE:
6085 case INTEGER_TYPE:
6086 case REAL_TYPE:
6087 case COMPLEX_TYPE:
6088 case BOOLEAN_TYPE:
6089 case CHAR_TYPE:
6090 return 1;
6092 case SET_TYPE:
6093 case ARRAY_TYPE:
6094 case RECORD_TYPE:
6095 case UNION_TYPE:
6096 case QUAL_UNION_TYPE:
6097 case ENUMERAL_TYPE:
6098 case FUNCTION_TYPE:
6099 case METHOD_TYPE:
6100 case POINTER_TYPE:
6101 case REFERENCE_TYPE:
6102 case FILE_TYPE:
6103 case OFFSET_TYPE:
6104 case LANG_TYPE:
6105 return 0;
6107 default:
6108 abort ();
6111 return 0;
6114 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6115 entry that chains various modifiers in front of the given type. */
6117 static dw_die_ref
6118 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6119 register tree type;
6120 register int is_const_type;
6121 register int is_volatile_type;
6122 register dw_die_ref context_die;
6124 register enum tree_code code = TREE_CODE (type);
6125 register dw_die_ref mod_type_die = NULL;
6126 register dw_die_ref sub_die = NULL;
6127 register tree item_type = NULL;
6129 if (code != ERROR_MARK)
6131 type = build_type_variant (type, is_const_type, is_volatile_type);
6133 mod_type_die = lookup_type_die (type);
6134 if (mod_type_die)
6135 return mod_type_die;
6137 /* Handle C typedef types. */
6138 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6139 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6141 tree dtype = TREE_TYPE (TYPE_NAME (type));
6142 if (type == dtype)
6144 /* For a named type, use the typedef. */
6145 gen_type_die (type, context_die);
6146 mod_type_die = lookup_type_die (type);
6149 else if (is_const_type < TYPE_READONLY (dtype)
6150 || is_volatile_type < TYPE_VOLATILE (dtype))
6151 /* cv-unqualified version of named type. Just use the unnamed
6152 type to which it refers. */
6153 mod_type_die
6154 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6155 is_const_type, is_volatile_type,
6156 context_die);
6157 /* Else cv-qualified version of named type; fall through. */
6160 if (mod_type_die)
6161 /* OK */;
6162 else if (is_const_type)
6164 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6165 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6167 else if (is_volatile_type)
6169 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6170 sub_die = modified_type_die (type, 0, 0, context_die);
6172 else if (code == POINTER_TYPE)
6174 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6175 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6176 #if 0
6177 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6178 #endif
6179 item_type = TREE_TYPE (type);
6181 else if (code == REFERENCE_TYPE)
6183 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6184 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6185 #if 0
6186 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6187 #endif
6188 item_type = TREE_TYPE (type);
6190 else if (is_base_type (type))
6191 mod_type_die = base_type_die (type);
6192 else
6194 gen_type_die (type, context_die);
6196 /* We have to get the type_main_variant here (and pass that to the
6197 `lookup_type_die' routine) because the ..._TYPE node we have
6198 might simply be a *copy* of some original type node (where the
6199 copy was created to help us keep track of typedef names) and
6200 that copy might have a different TYPE_UID from the original
6201 ..._TYPE node. */
6202 mod_type_die = lookup_type_die (type_main_variant (type));
6203 assert (mod_type_die != NULL);
6207 equate_type_number_to_die (type, mod_type_die);
6208 if (item_type)
6209 /* We must do this after the equate_type_number_to_die call, in case
6210 this is a recursive type. This ensures that the modified_type_die
6211 recursion will terminate even if the type is recursive. Recursive
6212 types are possible in Ada. */
6213 sub_die = modified_type_die (item_type,
6214 TYPE_READONLY (item_type),
6215 TYPE_VOLATILE (item_type),
6216 context_die);
6218 if (sub_die != NULL)
6219 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6221 return mod_type_die;
6224 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6225 an enumerated type. */
6227 static inline int
6228 type_is_enum (type)
6229 register tree type;
6231 return TREE_CODE (type) == ENUMERAL_TYPE;
6234 /* Return a location descriptor that designates a machine register. */
6236 static dw_loc_descr_ref
6237 reg_loc_descriptor (rtl)
6238 register rtx rtl;
6240 register dw_loc_descr_ref loc_result = NULL;
6241 register unsigned reg = reg_number (rtl);
6243 if (reg >= 0 && reg <= 31)
6244 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6245 else
6246 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6248 return loc_result;
6251 /* Return a location descriptor that designates a base+offset location. */
6253 static dw_loc_descr_ref
6254 based_loc_descr (reg, offset)
6255 unsigned reg;
6256 long int offset;
6258 register dw_loc_descr_ref loc_result;
6259 /* For the "frame base", we use the frame pointer or stack pointer
6260 registers, since the RTL for local variables is relative to one of
6261 them. */
6262 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6263 ? HARD_FRAME_POINTER_REGNUM
6264 : STACK_POINTER_REGNUM);
6266 if (reg == fp_reg)
6267 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
6268 else if (reg >= 0 && reg <= 31)
6269 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
6270 else
6271 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6273 return loc_result;
6276 /* Return true if this RTL expression describes a base+offset calculation. */
6278 static inline int
6279 is_based_loc (rtl)
6280 register rtx rtl;
6282 return (GET_CODE (rtl) == PLUS
6283 && ((GET_CODE (XEXP (rtl, 0)) == REG
6284 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6287 /* The following routine converts the RTL for a variable or parameter
6288 (resident in memory) into an equivalent Dwarf representation of a
6289 mechanism for getting the address of that same variable onto the top of a
6290 hypothetical "address evaluation" stack.
6292 When creating memory location descriptors, we are effectively transforming
6293 the RTL for a memory-resident object into its Dwarf postfix expression
6294 equivalent. This routine recursively descends an RTL tree, turning
6295 it into Dwarf postfix code as it goes. */
6297 static dw_loc_descr_ref
6298 mem_loc_descriptor (rtl)
6299 register rtx rtl;
6301 dw_loc_descr_ref mem_loc_result = NULL;
6302 /* Note that for a dynamically sized array, the location we will generate a
6303 description of here will be the lowest numbered location which is
6304 actually within the array. That's *not* necessarily the same as the
6305 zeroth element of the array. */
6307 switch (GET_CODE (rtl))
6309 case SUBREG:
6310 /* The case of a subreg may arise when we have a local (register)
6311 variable or a formal (register) parameter which doesn't quite fill
6312 up an entire register. For now, just assume that it is
6313 legitimate to make the Dwarf info refer to the whole register which
6314 contains the given subreg. */
6315 rtl = XEXP (rtl, 0);
6317 /* ... fall through ... */
6319 case REG:
6320 /* Whenever a register number forms a part of the description of the
6321 method for calculating the (dynamic) address of a memory resident
6322 object, DWARF rules require the register number be referred to as
6323 a "base register". This distinction is not based in any way upon
6324 what category of register the hardware believes the given register
6325 belongs to. This is strictly DWARF terminology we're dealing with
6326 here. Note that in cases where the location of a memory-resident
6327 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6328 OP_CONST (0)) the actual DWARF location descriptor that we generate
6329 may just be OP_BASEREG (basereg). This may look deceptively like
6330 the object in question was allocated to a register (rather than in
6331 memory) so DWARF consumers need to be aware of the subtle
6332 distinction between OP_REG and OP_BASEREG. */
6333 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6334 break;
6336 case MEM:
6337 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0));
6338 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6339 break;
6341 case CONST:
6342 case SYMBOL_REF:
6343 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6344 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6345 mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
6346 break;
6348 case PLUS:
6349 if (is_based_loc (rtl))
6350 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6351 INTVAL (XEXP (rtl, 1)));
6352 else
6354 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
6355 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
6356 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6358 break;
6360 case MULT:
6361 /* If a pseudo-reg is optimized away, it is possible for it to
6362 be replaced with a MEM containing a multiply. */
6363 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
6364 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
6365 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6366 break;
6368 case CONST_INT:
6369 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6370 break;
6372 default:
6373 abort ();
6376 return mem_loc_result;
6379 /* Return a descriptor that describes the concatenation of two locations.
6380 This is typically a complex variable. */
6382 static dw_loc_descr_ref
6383 concat_loc_descriptor (x0, x1)
6384 register rtx x0, x1;
6386 dw_loc_descr_ref cc_loc_result = NULL;
6388 if (!is_pseudo_reg (x0)
6389 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
6390 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
6391 add_loc_descr (&cc_loc_result,
6392 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
6394 if (!is_pseudo_reg (x1)
6395 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
6396 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
6397 add_loc_descr (&cc_loc_result,
6398 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
6400 return cc_loc_result;
6403 /* Output a proper Dwarf location descriptor for a variable or parameter
6404 which is either allocated in a register or in a memory location. For a
6405 register, we just generate an OP_REG and the register number. For a
6406 memory location we provide a Dwarf postfix expression describing how to
6407 generate the (dynamic) address of the object onto the address stack. */
6409 static dw_loc_descr_ref
6410 loc_descriptor (rtl)
6411 register rtx rtl;
6413 dw_loc_descr_ref loc_result = NULL;
6414 switch (GET_CODE (rtl))
6416 case SUBREG:
6417 /* The case of a subreg may arise when we have a local (register)
6418 variable or a formal (register) parameter which doesn't quite fill
6419 up an entire register. For now, just assume that it is
6420 legitimate to make the Dwarf info refer to the whole register which
6421 contains the given subreg. */
6422 rtl = XEXP (rtl, 0);
6424 /* ... fall through ... */
6426 case REG:
6427 loc_result = reg_loc_descriptor (rtl);
6428 break;
6430 case MEM:
6431 loc_result = mem_loc_descriptor (XEXP (rtl, 0));
6432 break;
6434 case CONCAT:
6435 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6436 break;
6438 default:
6439 abort ();
6442 return loc_result;
6445 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
6446 which is not less than the value itself. */
6448 static inline unsigned
6449 ceiling (value, boundary)
6450 register unsigned value;
6451 register unsigned boundary;
6453 return (((value + boundary - 1) / boundary) * boundary);
6456 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6457 pointer to the declared type for the relevant field variable, or return
6458 `integer_type_node' if the given node turns out to be an
6459 ERROR_MARK node. */
6461 static inline tree
6462 field_type (decl)
6463 register tree decl;
6465 register tree type;
6467 if (TREE_CODE (decl) == ERROR_MARK)
6468 return integer_type_node;
6470 type = DECL_BIT_FIELD_TYPE (decl);
6471 if (type == NULL_TREE)
6472 type = TREE_TYPE (decl);
6474 return type;
6477 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6478 node, return the alignment in bits for the type, or else return
6479 BITS_PER_WORD if the node actually turns out to be an
6480 ERROR_MARK node. */
6482 static inline unsigned
6483 simple_type_align_in_bits (type)
6484 register tree type;
6486 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6489 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6490 node, return the size in bits for the type if it is a constant, or else
6491 return the alignment for the type if the type's size is not constant, or
6492 else return BITS_PER_WORD if the type actually turns out to be an
6493 ERROR_MARK node. */
6495 static inline unsigned
6496 simple_type_size_in_bits (type)
6497 register tree type;
6499 if (TREE_CODE (type) == ERROR_MARK)
6500 return BITS_PER_WORD;
6501 else
6503 register tree type_size_tree = TYPE_SIZE (type);
6505 if (TREE_CODE (type_size_tree) != INTEGER_CST)
6506 return TYPE_ALIGN (type);
6508 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
6512 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6513 return the byte offset of the lowest addressed byte of the "containing
6514 object" for the given FIELD_DECL, or return 0 if we are unable to
6515 determine what that offset is, either because the argument turns out to
6516 be a pointer to an ERROR_MARK node, or because the offset is actually
6517 variable. (We can't handle the latter case just yet). */
6519 static unsigned
6520 field_byte_offset (decl)
6521 register tree decl;
6523 register unsigned type_align_in_bytes;
6524 register unsigned type_align_in_bits;
6525 register unsigned type_size_in_bits;
6526 register unsigned object_offset_in_align_units;
6527 register unsigned object_offset_in_bits;
6528 register unsigned object_offset_in_bytes;
6529 register tree type;
6530 register tree bitpos_tree;
6531 register tree field_size_tree;
6532 register unsigned bitpos_int;
6533 register unsigned deepest_bitpos;
6534 register unsigned field_size_in_bits;
6536 if (TREE_CODE (decl) == ERROR_MARK)
6537 return 0;
6539 if (TREE_CODE (decl) != FIELD_DECL)
6540 abort ();
6542 type = field_type (decl);
6544 bitpos_tree = DECL_FIELD_BITPOS (decl);
6545 field_size_tree = DECL_SIZE (decl);
6547 /* We cannot yet cope with fields whose positions or sizes are variable, so
6548 for now, when we see such things, we simply return 0. Someday, we may
6549 be able to handle such cases, but it will be damn difficult. */
6550 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6551 return 0;
6552 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6554 if (TREE_CODE (field_size_tree) != INTEGER_CST)
6555 return 0;
6557 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
6558 type_size_in_bits = simple_type_size_in_bits (type);
6559 type_align_in_bits = simple_type_align_in_bits (type);
6560 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6562 /* Note that the GCC front-end doesn't make any attempt to keep track of
6563 the starting bit offset (relative to the start of the containing
6564 structure type) of the hypothetical "containing object" for a bit-
6565 field. Thus, when computing the byte offset value for the start of the
6566 "containing object" of a bit-field, we must deduce this information on
6567 our own. This can be rather tricky to do in some cases. For example,
6568 handling the following structure type definition when compiling for an
6569 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6570 can be very tricky:
6572 struct S { int field1; long long field2:31; };
6574 Fortunately, there is a simple rule-of-thumb which can be
6575 used in such cases. When compiling for an i386/i486, GCC will allocate
6576 8 bytes for the structure shown above. It decides to do this based upon
6577 one simple rule for bit-field allocation. Quite simply, GCC allocates
6578 each "containing object" for each bit-field at the first (i.e. lowest
6579 addressed) legitimate alignment boundary (based upon the required
6580 minimum alignment for the declared type of the field) which it can
6581 possibly use, subject to the condition that there is still enough
6582 available space remaining in the containing object (when allocated at
6583 the selected point) to fully accommodate all of the bits of the
6584 bit-field itself. This simple rule makes it obvious why GCC allocates
6585 8 bytes for each object of the structure type shown above. When looking
6586 for a place to allocate the "containing object" for `field2', the
6587 compiler simply tries to allocate a 64-bit "containing object" at each
6588 successive 32-bit boundary (starting at zero) until it finds a place to
6589 allocate that 64- bit field such that at least 31 contiguous (and
6590 previously unallocated) bits remain within that selected 64 bit field.
6591 (As it turns out, for the example above, the compiler finds that it is
6592 OK to allocate the "containing object" 64-bit field at bit-offset zero
6593 within the structure type.) Here we attempt to work backwards from the
6594 limited set of facts we're given, and we try to deduce from those facts,
6595 where GCC must have believed that the containing object started (within
6596 the structure type). The value we deduce is then used (by the callers of
6597 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6598 for fields (both bit-fields and, in the case of DW_AT_location, regular
6599 fields as well). */
6601 /* Figure out the bit-distance from the start of the structure to the
6602 "deepest" bit of the bit-field. */
6603 deepest_bitpos = bitpos_int + field_size_in_bits;
6605 /* This is the tricky part. Use some fancy footwork to deduce where the
6606 lowest addressed bit of the containing object must be. */
6607 object_offset_in_bits
6608 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6610 /* Compute the offset of the containing object in "alignment units". */
6611 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6613 /* Compute the offset of the containing object in bytes. */
6614 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6616 return object_offset_in_bytes;
6619 /* The following routines define various Dwarf attributes and any data
6620 associated with them. */
6622 /* Add a location description attribute value to a DIE.
6624 This emits location attributes suitable for whole variables and
6625 whole parameters. Note that the location attributes for struct fields are
6626 generated by the routine `data_member_location_attribute' below. */
6628 static void
6629 add_AT_location_description (die, attr_kind, rtl)
6630 dw_die_ref die;
6631 enum dwarf_attribute attr_kind;
6632 register rtx rtl;
6634 /* Handle a special case. If we are about to output a location descriptor
6635 for a variable or parameter which has been optimized out of existence,
6636 don't do that. A variable which has been optimized out
6637 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6638 Currently, in some rare cases, variables can have DECL_RTL values which
6639 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6640 elsewhere in the compiler. We treat such cases as if the variable(s) in
6641 question had been optimized out of existence. */
6643 if (is_pseudo_reg (rtl)
6644 || (GET_CODE (rtl) == MEM
6645 && is_pseudo_reg (XEXP (rtl, 0)))
6646 || (GET_CODE (rtl) == CONCAT
6647 && is_pseudo_reg (XEXP (rtl, 0))
6648 && is_pseudo_reg (XEXP (rtl, 1))))
6649 return;
6651 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
6654 /* Attach the specialized form of location attribute used for data
6655 members of struct and union types. In the special case of a
6656 FIELD_DECL node which represents a bit-field, the "offset" part
6657 of this special location descriptor must indicate the distance
6658 in bytes from the lowest-addressed byte of the containing struct
6659 or union type to the lowest-addressed byte of the "containing
6660 object" for the bit-field. (See the `field_byte_offset' function
6661 above).. For any given bit-field, the "containing object" is a
6662 hypothetical object (of some integral or enum type) within which
6663 the given bit-field lives. The type of this hypothetical
6664 "containing object" is always the same as the declared type of
6665 the individual bit-field itself (for GCC anyway... the DWARF
6666 spec doesn't actually mandate this). Note that it is the size
6667 (in bytes) of the hypothetical "containing object" which will
6668 be given in the DW_AT_byte_size attribute for this bit-field.
6669 (See the `byte_size_attribute' function below.) It is also used
6670 when calculating the value of the DW_AT_bit_offset attribute.
6671 (See the `bit_offset_attribute' function below). */
6673 static void
6674 add_data_member_location_attribute (die, decl)
6675 register dw_die_ref die;
6676 register tree decl;
6678 register unsigned long offset;
6679 register dw_loc_descr_ref loc_descr;
6680 register enum dwarf_location_atom op;
6682 if (TREE_CODE (decl) == TREE_VEC)
6683 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
6684 else
6685 offset = field_byte_offset (decl);
6687 /* The DWARF2 standard says that we should assume that the structure address
6688 is already on the stack, so we can specify a structure field address
6689 by using DW_OP_plus_uconst. */
6691 #ifdef MIPS_DEBUGGING_INFO
6692 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6693 correctly. It works only if we leave the offset on the stack. */
6694 op = DW_OP_constu;
6695 #else
6696 op = DW_OP_plus_uconst;
6697 #endif
6699 loc_descr = new_loc_descr (op, offset, 0);
6700 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6703 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6704 does not have a "location" either in memory or in a register. These
6705 things can arise in GNU C when a constant is passed as an actual parameter
6706 to an inlined function. They can also arise in C++ where declared
6707 constants do not necessarily get memory "homes". */
6709 static void
6710 add_const_value_attribute (die, rtl)
6711 register dw_die_ref die;
6712 register rtx rtl;
6714 switch (GET_CODE (rtl))
6716 case CONST_INT:
6717 /* Note that a CONST_INT rtx could represent either an integer or a
6718 floating-point constant. A CONST_INT is used whenever the constant
6719 will fit into a single word. In all such cases, the original mode
6720 of the constant value is wiped out, and the CONST_INT rtx is
6721 assigned VOIDmode. */
6722 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6723 break;
6725 case CONST_DOUBLE:
6726 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6727 floating-point constant. A CONST_DOUBLE is used whenever the
6728 constant requires more than one word in order to be adequately
6729 represented. We output CONST_DOUBLEs as blocks. */
6731 register enum machine_mode mode = GET_MODE (rtl);
6733 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6735 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6736 long array[4];
6737 REAL_VALUE_TYPE rv;
6739 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6740 switch (mode)
6742 case SFmode:
6743 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6744 break;
6746 case DFmode:
6747 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6748 break;
6750 case XFmode:
6751 case TFmode:
6752 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6753 break;
6755 default:
6756 abort ();
6759 add_AT_float (die, DW_AT_const_value, length, array);
6761 else
6762 add_AT_long_long (die, DW_AT_const_value,
6763 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6765 break;
6767 case CONST_STRING:
6768 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6769 break;
6771 case SYMBOL_REF:
6772 case LABEL_REF:
6773 case CONST:
6774 add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
6775 break;
6777 case PLUS:
6778 /* In cases where an inlined instance of an inline function is passed
6779 the address of an `auto' variable (which is local to the caller) we
6780 can get a situation where the DECL_RTL of the artificial local
6781 variable (for the inlining) which acts as a stand-in for the
6782 corresponding formal parameter (of the inline function) will look
6783 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6784 exactly a compile-time constant expression, but it isn't the address
6785 of the (artificial) local variable either. Rather, it represents the
6786 *value* which the artificial local variable always has during its
6787 lifetime. We currently have no way to represent such quasi-constant
6788 values in Dwarf, so for now we just punt and generate nothing. */
6789 break;
6791 default:
6792 /* No other kinds of rtx should be possible here. */
6793 abort ();
6798 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6799 data attribute for a variable or a parameter. We generate the
6800 DW_AT_const_value attribute only in those cases where the given variable
6801 or parameter does not have a true "location" either in memory or in a
6802 register. This can happen (for example) when a constant is passed as an
6803 actual argument in a call to an inline function. (It's possible that
6804 these things can crop up in other ways also.) Note that one type of
6805 constant value which can be passed into an inlined function is a constant
6806 pointer. This can happen for example if an actual argument in an inlined
6807 function call evaluates to a compile-time constant address. */
6809 static void
6810 add_location_or_const_value_attribute (die, decl)
6811 register dw_die_ref die;
6812 register tree decl;
6814 register rtx rtl;
6815 register tree declared_type;
6816 register tree passed_type;
6818 if (TREE_CODE (decl) == ERROR_MARK)
6819 return;
6821 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6822 abort ();
6824 /* Here we have to decide where we are going to say the parameter "lives"
6825 (as far as the debugger is concerned). We only have a couple of
6826 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6828 DECL_RTL normally indicates where the parameter lives during most of the
6829 activation of the function. If optimization is enabled however, this
6830 could be either NULL or else a pseudo-reg. Both of those cases indicate
6831 that the parameter doesn't really live anywhere (as far as the code
6832 generation parts of GCC are concerned) during most of the function's
6833 activation. That will happen (for example) if the parameter is never
6834 referenced within the function.
6836 We could just generate a location descriptor here for all non-NULL
6837 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6838 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6839 where DECL_RTL is NULL or is a pseudo-reg.
6841 Note however that we can only get away with using DECL_INCOMING_RTL as
6842 a backup substitute for DECL_RTL in certain limited cases. In cases
6843 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6844 we can be sure that the parameter was passed using the same type as it is
6845 declared to have within the function, and that its DECL_INCOMING_RTL
6846 points us to a place where a value of that type is passed.
6848 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6849 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6850 because in these cases DECL_INCOMING_RTL points us to a value of some
6851 type which is *different* from the type of the parameter itself. Thus,
6852 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6853 such cases, the debugger would end up (for example) trying to fetch a
6854 `float' from a place which actually contains the first part of a
6855 `double'. That would lead to really incorrect and confusing
6856 output at debug-time.
6858 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6859 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6860 are a couple of exceptions however. On little-endian machines we can
6861 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6862 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6863 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6864 when (on a little-endian machine) a non-prototyped function has a
6865 parameter declared to be of type `short' or `char'. In such cases,
6866 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6867 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6868 passed `int' value. If the debugger then uses that address to fetch
6869 a `short' or a `char' (on a little-endian machine) the result will be
6870 the correct data, so we allow for such exceptional cases below.
6872 Note that our goal here is to describe the place where the given formal
6873 parameter lives during most of the function's activation (i.e. between
6874 the end of the prologue and the start of the epilogue). We'll do that
6875 as best as we can. Note however that if the given formal parameter is
6876 modified sometime during the execution of the function, then a stack
6877 backtrace (at debug-time) will show the function as having been
6878 called with the *new* value rather than the value which was
6879 originally passed in. This happens rarely enough that it is not
6880 a major problem, but it *is* a problem, and I'd like to fix it.
6882 A future version of dwarf2out.c may generate two additional
6883 attributes for any given DW_TAG_formal_parameter DIE which will
6884 describe the "passed type" and the "passed location" for the
6885 given formal parameter in addition to the attributes we now
6886 generate to indicate the "declared type" and the "active
6887 location" for each parameter. This additional set of attributes
6888 could be used by debuggers for stack backtraces. Separately, note
6889 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6890 NULL also. This happens (for example) for inlined-instances of
6891 inline function formal parameters which are never referenced.
6892 This really shouldn't be happening. All PARM_DECL nodes should
6893 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6894 doesn't currently generate these values for inlined instances of
6895 inline function parameters, so when we see such cases, we are
6896 just out-of-luck for the time being (until integrate.c
6897 gets fixed). */
6899 /* Use DECL_RTL as the "location" unless we find something better. */
6900 rtl = DECL_RTL (decl);
6902 if (TREE_CODE (decl) == PARM_DECL)
6904 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
6906 declared_type = type_main_variant (TREE_TYPE (decl));
6907 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
6909 /* This decl represents a formal parameter which was optimized out.
6910 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
6911 all* cases where (rtl == NULL_RTX) just below. */
6912 if (declared_type == passed_type)
6913 rtl = DECL_INCOMING_RTL (decl);
6914 else if (! BYTES_BIG_ENDIAN
6915 && TREE_CODE (declared_type) == INTEGER_TYPE
6916 && TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
6917 rtl = DECL_INCOMING_RTL (decl);
6921 if (rtl == NULL_RTX)
6922 return;
6924 rtl = eliminate_regs (rtl, 0, NULL_RTX, 0);
6925 #ifdef LEAF_REG_REMAP
6926 if (leaf_function)
6927 leaf_renumber_regs_insn (rtl);
6928 #endif
6930 switch (GET_CODE (rtl))
6932 case ADDRESSOF:
6933 /* The address of a variable that was optimized away; don't emit
6934 anything. */
6935 break;
6937 case CONST_INT:
6938 case CONST_DOUBLE:
6939 case CONST_STRING:
6940 case SYMBOL_REF:
6941 case LABEL_REF:
6942 case CONST:
6943 case PLUS:
6944 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
6945 add_const_value_attribute (die, rtl);
6946 break;
6948 case MEM:
6949 case REG:
6950 case SUBREG:
6951 case CONCAT:
6952 add_AT_location_description (die, DW_AT_location, rtl);
6953 break;
6955 default:
6956 abort ();
6960 /* Generate an DW_AT_name attribute given some string value to be included as
6961 the value of the attribute. */
6963 static inline void
6964 add_name_attribute (die, name_string)
6965 register dw_die_ref die;
6966 register char *name_string;
6968 if (name_string != NULL && *name_string != 0)
6969 add_AT_string (die, DW_AT_name, name_string);
6972 /* Given a tree node describing an array bound (either lower or upper) output
6973 a representation for that bound. */
6975 static void
6976 add_bound_info (subrange_die, bound_attr, bound)
6977 register dw_die_ref subrange_die;
6978 register enum dwarf_attribute bound_attr;
6979 register tree bound;
6981 register unsigned bound_value = 0;
6983 /* If this is an Ada unconstrained array type, then don't emit any debug
6984 info because the array bounds are unknown. They are parameterized when
6985 the type is instantiated. */
6986 if (contains_placeholder_p (bound))
6987 return;
6989 switch (TREE_CODE (bound))
6991 case ERROR_MARK:
6992 return;
6994 /* All fixed-bounds are represented by INTEGER_CST nodes. */
6995 case INTEGER_CST:
6996 bound_value = TREE_INT_CST_LOW (bound);
6997 if (bound_attr == DW_AT_lower_bound
6998 && ((is_c_family () && bound_value == 0)
6999 || (is_fortran () && bound_value == 1)))
7000 /* use the default */;
7001 else
7002 add_AT_unsigned (subrange_die, bound_attr, bound_value);
7003 break;
7005 case CONVERT_EXPR:
7006 case NOP_EXPR:
7007 case NON_LVALUE_EXPR:
7008 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7009 break;
7011 case SAVE_EXPR:
7012 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7013 access the upper bound values may be bogus. If they refer to a
7014 register, they may only describe how to get at these values at the
7015 points in the generated code right after they have just been
7016 computed. Worse yet, in the typical case, the upper bound values
7017 will not even *be* computed in the optimized code (though the
7018 number of elements will), so these SAVE_EXPRs are entirely
7019 bogus. In order to compensate for this fact, we check here to see
7020 if optimization is enabled, and if so, we don't add an attribute
7021 for the (unknown and unknowable) upper bound. This should not
7022 cause too much trouble for existing (stupid?) debuggers because
7023 they have to deal with empty upper bounds location descriptions
7024 anyway in order to be able to deal with incomplete array types.
7025 Of course an intelligent debugger (GDB?) should be able to
7026 comprehend that a missing upper bound specification in a array
7027 type used for a storage class `auto' local array variable
7028 indicates that the upper bound is both unknown (at compile- time)
7029 and unknowable (at run-time) due to optimization.
7031 We assume that a MEM rtx is safe because gcc wouldn't put the
7032 value there unless it was going to be used repeatedly in the
7033 function, i.e. for cleanups. */
7034 if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
7036 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7037 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7038 add_AT_flag (decl_die, DW_AT_artificial, 1);
7039 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
7040 add_AT_location_description (decl_die, DW_AT_location,
7041 SAVE_EXPR_RTL (bound));
7042 add_AT_die_ref (subrange_die, bound_attr, decl_die);
7045 /* Else leave out the attribute. */
7046 break;
7048 case MAX_EXPR:
7049 case VAR_DECL:
7050 /* ??? These types of bounds can be created by the Ada front end,
7051 and it isn't clear how to emit debug info for them. */
7052 break;
7054 default:
7055 abort ();
7059 /* Note that the block of subscript information for an array type also
7060 includes information about the element type of type given array type. */
7062 static void
7063 add_subscript_info (type_die, type)
7064 register dw_die_ref type_die;
7065 register tree type;
7067 register unsigned dimension_number;
7068 register tree lower, upper;
7069 register dw_die_ref subrange_die;
7071 /* The GNU compilers represent multidimensional array types as sequences of
7072 one dimensional array types whose element types are themselves array
7073 types. Here we squish that down, so that each multidimensional array
7074 type gets only one array_type DIE in the Dwarf debugging info. The draft
7075 Dwarf specification say that we are allowed to do this kind of
7076 compression in C (because there is no difference between an array or
7077 arrays and a multidimensional array in C) but for other source languages
7078 (e.g. Ada) we probably shouldn't do this. */
7080 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7081 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7082 We work around this by disabling this feature. See also
7083 gen_array_type_die. */
7084 #ifndef MIPS_DEBUGGING_INFO
7085 for (dimension_number = 0;
7086 TREE_CODE (type) == ARRAY_TYPE;
7087 type = TREE_TYPE (type), dimension_number++)
7089 #endif
7090 register tree domain = TYPE_DOMAIN (type);
7092 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7093 and (in GNU C only) variable bounds. Handle all three forms
7094 here. */
7095 subrange_die = new_die (DW_TAG_subrange_type, type_die);
7096 if (domain)
7098 /* We have an array type with specified bounds. */
7099 lower = TYPE_MIN_VALUE (domain);
7100 upper = TYPE_MAX_VALUE (domain);
7102 /* define the index type. */
7103 if (TREE_TYPE (domain))
7105 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7106 TREE_TYPE field. We can't emit debug info for this
7107 because it is an unnamed integral type. */
7108 if (TREE_CODE (domain) == INTEGER_TYPE
7109 && TYPE_NAME (domain) == NULL_TREE
7110 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
7111 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
7113 else
7114 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7115 type_die);
7118 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
7119 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
7121 else
7122 /* We have an array type with an unspecified length. The DWARF-2
7123 spec does not say how to handle this; let's just leave out the
7124 bounds. */
7127 #ifndef MIPS_DEBUGGING_INFO
7129 #endif
7132 static void
7133 add_byte_size_attribute (die, tree_node)
7134 dw_die_ref die;
7135 register tree tree_node;
7137 register unsigned size;
7139 switch (TREE_CODE (tree_node))
7141 case ERROR_MARK:
7142 size = 0;
7143 break;
7144 case ENUMERAL_TYPE:
7145 case RECORD_TYPE:
7146 case UNION_TYPE:
7147 case QUAL_UNION_TYPE:
7148 size = int_size_in_bytes (tree_node);
7149 break;
7150 case FIELD_DECL:
7151 /* For a data member of a struct or union, the DW_AT_byte_size is
7152 generally given as the number of bytes normally allocated for an
7153 object of the *declared* type of the member itself. This is true
7154 even for bit-fields. */
7155 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
7156 break;
7157 default:
7158 abort ();
7161 /* Note that `size' might be -1 when we get to this point. If it is, that
7162 indicates that the byte size of the entity in question is variable. We
7163 have no good way of expressing this fact in Dwarf at the present time,
7164 so just let the -1 pass on through. */
7166 add_AT_unsigned (die, DW_AT_byte_size, size);
7169 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7170 which specifies the distance in bits from the highest order bit of the
7171 "containing object" for the bit-field to the highest order bit of the
7172 bit-field itself.
7174 For any given bit-field, the "containing object" is a hypothetical
7175 object (of some integral or enum type) within which the given bit-field
7176 lives. The type of this hypothetical "containing object" is always the
7177 same as the declared type of the individual bit-field itself. The
7178 determination of the exact location of the "containing object" for a
7179 bit-field is rather complicated. It's handled by the
7180 `field_byte_offset' function (above).
7182 Note that it is the size (in bytes) of the hypothetical "containing object"
7183 which will be given in the DW_AT_byte_size attribute for this bit-field.
7184 (See `byte_size_attribute' above). */
7186 static inline void
7187 add_bit_offset_attribute (die, decl)
7188 register dw_die_ref die;
7189 register tree decl;
7191 register unsigned object_offset_in_bytes = field_byte_offset (decl);
7192 register tree type = DECL_BIT_FIELD_TYPE (decl);
7193 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
7194 register unsigned bitpos_int;
7195 register unsigned highest_order_object_bit_offset;
7196 register unsigned highest_order_field_bit_offset;
7197 register unsigned bit_offset;
7199 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
7200 assert (type); /* Must be a bit field. */
7202 /* We can't yet handle bit-fields whose offsets are variable, so if we
7203 encounter such things, just return without generating any attribute
7204 whatsoever. */
7205 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
7206 return;
7208 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
7210 /* Note that the bit offset is always the distance (in bits) from the
7211 highest-order bit of the "containing object" to the highest-order bit of
7212 the bit-field itself. Since the "high-order end" of any object or field
7213 is different on big-endian and little-endian machines, the computation
7214 below must take account of these differences. */
7215 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
7216 highest_order_field_bit_offset = bitpos_int;
7218 if (! BYTES_BIG_ENDIAN)
7220 highest_order_field_bit_offset
7221 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
7223 highest_order_object_bit_offset += simple_type_size_in_bits (type);
7226 bit_offset
7227 = (! BYTES_BIG_ENDIAN
7228 ? highest_order_object_bit_offset - highest_order_field_bit_offset
7229 : highest_order_field_bit_offset - highest_order_object_bit_offset);
7231 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7234 /* For a FIELD_DECL node which represents a bit field, output an attribute
7235 which specifies the length in bits of the given field. */
7237 static inline void
7238 add_bit_size_attribute (die, decl)
7239 register dw_die_ref die;
7240 register tree decl;
7242 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
7243 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
7244 add_AT_unsigned (die, DW_AT_bit_size,
7245 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
7248 /* If the compiled language is ANSI C, then add a 'prototyped'
7249 attribute, if arg types are given for the parameters of a function. */
7251 static inline void
7252 add_prototyped_attribute (die, func_type)
7253 register dw_die_ref die;
7254 register tree func_type;
7256 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
7257 && TYPE_ARG_TYPES (func_type) != NULL)
7258 add_AT_flag (die, DW_AT_prototyped, 1);
7262 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7263 by looking in either the type declaration or object declaration
7264 equate table. */
7266 static inline void
7267 add_abstract_origin_attribute (die, origin)
7268 register dw_die_ref die;
7269 register tree origin;
7271 dw_die_ref origin_die = NULL;
7272 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
7273 origin_die = lookup_decl_die (origin);
7274 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
7275 origin_die = lookup_type_die (origin);
7277 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7280 /* We do not currently support the pure_virtual attribute. */
7282 static inline void
7283 add_pure_or_virtual_attribute (die, func_decl)
7284 register dw_die_ref die;
7285 register tree func_decl;
7287 if (DECL_VINDEX (func_decl))
7289 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7290 add_AT_loc (die, DW_AT_vtable_elem_location,
7291 new_loc_descr (DW_OP_constu,
7292 TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
7293 0));
7295 /* GNU extension: Record what type this method came from originally. */
7296 if (debug_info_level > DINFO_LEVEL_TERSE)
7297 add_AT_die_ref (die, DW_AT_containing_type,
7298 lookup_type_die (DECL_CONTEXT (func_decl)));
7302 /* Add source coordinate attributes for the given decl. */
7304 static void
7305 add_src_coords_attributes (die, decl)
7306 register dw_die_ref die;
7307 register tree decl;
7309 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
7311 add_AT_unsigned (die, DW_AT_decl_file, file_index);
7312 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7315 /* Add an DW_AT_name attribute and source coordinate attribute for the
7316 given decl, but only if it actually has a name. */
7318 static void
7319 add_name_and_src_coords_attributes (die, decl)
7320 register dw_die_ref die;
7321 register tree decl;
7323 register tree decl_name;
7325 decl_name = DECL_NAME (decl);
7326 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
7328 add_name_attribute (die, dwarf2_name (decl, 0));
7329 add_src_coords_attributes (die, decl);
7330 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
7331 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
7332 add_AT_string (die, DW_AT_MIPS_linkage_name,
7333 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7337 /* Push a new declaration scope. */
7339 static void
7340 push_decl_scope (scope)
7341 tree scope;
7343 /* Make room in the decl_scope_table, if necessary. */
7344 if (decl_scope_table_allocated == decl_scope_depth)
7346 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
7347 decl_scope_table
7348 = (tree *) xrealloc (decl_scope_table,
7349 decl_scope_table_allocated * sizeof (tree));
7352 decl_scope_table[decl_scope_depth++] = scope;
7355 /* Return the DIE for the scope the immediately contains this declaration. */
7357 static dw_die_ref
7358 scope_die_for (t, context_die)
7359 register tree t;
7360 register dw_die_ref context_die;
7362 register dw_die_ref scope_die = NULL;
7363 register tree containing_scope;
7364 register unsigned long i;
7366 /* Walk back up the declaration tree looking for a place to define
7367 this type. */
7368 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
7369 containing_scope = TYPE_CONTEXT (t);
7370 else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t))
7371 containing_scope = decl_class_context (t);
7372 else
7373 containing_scope = DECL_CONTEXT (t);
7375 /* Function-local tags and functions get stuck in limbo until they are
7376 fixed up by decls_for_scope. */
7377 if (context_die == NULL && containing_scope != NULL_TREE
7378 && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t)))
7379 return NULL;
7381 if (containing_scope == NULL_TREE)
7382 scope_die = comp_unit_die;
7383 else
7385 for (i = decl_scope_depth, scope_die = context_die;
7386 i > 0 && decl_scope_table[i - 1] != containing_scope;
7387 scope_die = scope_die->die_parent, --i)
7390 if (i == 0)
7392 assert (scope_die == comp_unit_die);
7393 assert (TREE_CODE_CLASS (TREE_CODE (containing_scope)) == 't');
7394 if (debug_info_level > DINFO_LEVEL_TERSE)
7395 assert (TREE_ASM_WRITTEN (containing_scope));
7399 return scope_die;
7402 /* Pop a declaration scope. */
7403 static inline void
7404 pop_decl_scope ()
7406 assert (decl_scope_depth > 0);
7407 --decl_scope_depth;
7410 /* Many forms of DIEs require a "type description" attribute. This
7411 routine locates the proper "type descriptor" die for the type given
7412 by 'type', and adds an DW_AT_type attribute below the given die. */
7414 static void
7415 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7416 register dw_die_ref object_die;
7417 register tree type;
7418 register int decl_const;
7419 register int decl_volatile;
7420 register dw_die_ref context_die;
7422 register enum tree_code code = TREE_CODE (type);
7423 register dw_die_ref type_die = NULL;
7425 /* ??? If this type is an unnamed subrange type of an integral or
7426 floating-point type, use the inner type. This is because we have no
7427 support for unnamed types in base_type_die. This can happen if this is
7428 an Ada subrange type. Correct solution is emit a subrange type die. */
7429 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7430 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7431 type = TREE_TYPE (type), code = TREE_CODE (type);
7433 if (code == ERROR_MARK)
7434 return;
7436 /* Handle a special case. For functions whose return type is void, we
7437 generate *no* type attribute. (Note that no object may have type
7438 `void', so this only applies to function return types). */
7439 if (code == VOID_TYPE)
7440 return;
7442 type_die = modified_type_die (type,
7443 decl_const || TYPE_READONLY (type),
7444 decl_volatile || TYPE_VOLATILE (type),
7445 context_die);
7446 if (type_die != NULL)
7447 add_AT_die_ref (object_die, DW_AT_type, type_die);
7450 /* Given a tree pointer to a struct, class, union, or enum type node, return
7451 a pointer to the (string) tag name for the given type, or zero if the type
7452 was declared without a tag. */
7454 static char *
7455 type_tag (type)
7456 register tree type;
7458 register char *name = 0;
7460 if (TYPE_NAME (type) != 0)
7462 register tree t = 0;
7464 /* Find the IDENTIFIER_NODE for the type name. */
7465 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7466 t = TYPE_NAME (type);
7468 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7469 a TYPE_DECL node, regardless of whether or not a `typedef' was
7470 involved. */
7471 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7472 && ! DECL_IGNORED_P (TYPE_NAME (type)))
7473 t = DECL_NAME (TYPE_NAME (type));
7475 /* Now get the name as a string, or invent one. */
7476 if (t != 0)
7477 name = IDENTIFIER_POINTER (t);
7480 return (name == 0 || *name == '\0') ? 0 : name;
7483 /* Return the type associated with a data member, make a special check
7484 for bit field types. */
7486 static inline tree
7487 member_declared_type (member)
7488 register tree member;
7490 return (DECL_BIT_FIELD_TYPE (member)
7491 ? DECL_BIT_FIELD_TYPE (member)
7492 : TREE_TYPE (member));
7495 /* Get the decl's label, as described by its RTL. This may be different
7496 from the DECL_NAME name used in the source file. */
7498 static char *
7499 decl_start_label (decl)
7500 register tree decl;
7502 rtx x;
7503 char *fnname;
7504 x = DECL_RTL (decl);
7505 if (GET_CODE (x) != MEM)
7506 abort ();
7508 x = XEXP (x, 0);
7509 if (GET_CODE (x) != SYMBOL_REF)
7510 abort ();
7512 fnname = XSTR (x, 0);
7513 return fnname;
7516 /* These routines generate the internal representation of the DIE's for
7517 the compilation unit. Debugging information is collected by walking
7518 the declaration trees passed in from dwarf2out_decl(). */
7520 static void
7521 gen_array_type_die (type, context_die)
7522 register tree type;
7523 register dw_die_ref context_die;
7525 register dw_die_ref scope_die = scope_die_for (type, context_die);
7526 register dw_die_ref array_die;
7527 register tree element_type;
7529 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7530 the inner array type comes before the outer array type. Thus we must
7531 call gen_type_die before we call new_die. See below also. */
7532 #ifdef MIPS_DEBUGGING_INFO
7533 gen_type_die (TREE_TYPE (type), context_die);
7534 #endif
7536 array_die = new_die (DW_TAG_array_type, scope_die);
7538 #if 0
7539 /* We default the array ordering. SDB will probably do
7540 the right things even if DW_AT_ordering is not present. It's not even
7541 an issue until we start to get into multidimensional arrays anyway. If
7542 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7543 then we'll have to put the DW_AT_ordering attribute back in. (But if
7544 and when we find out that we need to put these in, we will only do so
7545 for multidimensional arrays. */
7546 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
7547 #endif
7549 #ifdef MIPS_DEBUGGING_INFO
7550 /* The SGI compilers handle arrays of unknown bound by setting
7551 AT_declaration and not emitting any subrange DIEs. */
7552 if (! TYPE_DOMAIN (type))
7553 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7554 else
7555 #endif
7556 add_subscript_info (array_die, type);
7558 equate_type_number_to_die (type, array_die);
7560 /* Add representation of the type of the elements of this array type. */
7561 element_type = TREE_TYPE (type);
7563 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7564 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7565 We work around this by disabling this feature. See also
7566 add_subscript_info. */
7567 #ifndef MIPS_DEBUGGING_INFO
7568 while (TREE_CODE (element_type) == ARRAY_TYPE)
7569 element_type = TREE_TYPE (element_type);
7571 gen_type_die (element_type, context_die);
7572 #endif
7574 add_type_attribute (array_die, element_type, 0, 0, context_die);
7577 static void
7578 gen_set_type_die (type, context_die)
7579 register tree type;
7580 register dw_die_ref context_die;
7582 register dw_die_ref type_die
7583 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7585 equate_type_number_to_die (type, type_die);
7586 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7589 static void
7590 gen_entry_point_die (decl, context_die)
7591 register tree decl;
7592 register dw_die_ref context_die;
7594 register tree origin = decl_ultimate_origin (decl);
7595 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7596 if (origin != NULL)
7597 add_abstract_origin_attribute (decl_die, origin);
7598 else
7600 add_name_and_src_coords_attributes (decl_die, decl);
7601 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7602 0, 0, context_die);
7605 if (DECL_ABSTRACT (decl))
7606 equate_decl_number_to_die (decl, decl_die);
7607 else
7608 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
7611 /* Remember a type in the pending_types_list. */
7613 static void
7614 pend_type (type)
7615 register tree type;
7617 if (pending_types == pending_types_allocated)
7619 pending_types_allocated += PENDING_TYPES_INCREMENT;
7620 pending_types_list
7621 = (tree *) xrealloc (pending_types_list,
7622 sizeof (tree) * pending_types_allocated);
7625 pending_types_list[pending_types++] = type;
7628 /* Output any pending types (from the pending_types list) which we can output
7629 now (taking into account the scope that we are working on now).
7631 For each type output, remove the given type from the pending_types_list
7632 *before* we try to output it. */
7634 static void
7635 output_pending_types_for_scope (context_die)
7636 register dw_die_ref context_die;
7638 register tree type;
7640 while (pending_types)
7642 --pending_types;
7643 type = pending_types_list[pending_types];
7644 gen_type_die (type, context_die);
7645 assert (TREE_ASM_WRITTEN (type));
7649 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7651 static void
7652 gen_inlined_enumeration_type_die (type, context_die)
7653 register tree type;
7654 register dw_die_ref context_die;
7656 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
7657 scope_die_for (type, context_die));
7659 assert (TREE_ASM_WRITTEN (type));
7660 add_abstract_origin_attribute (type_die, type);
7663 /* Generate a DIE to represent an inlined instance of a structure type. */
7665 static void
7666 gen_inlined_structure_type_die (type, context_die)
7667 register tree type;
7668 register dw_die_ref context_die;
7670 register dw_die_ref type_die = new_die (DW_TAG_structure_type,
7671 scope_die_for (type, context_die));
7673 assert (TREE_ASM_WRITTEN (type));
7674 add_abstract_origin_attribute (type_die, type);
7677 /* Generate a DIE to represent an inlined instance of a union type. */
7679 static void
7680 gen_inlined_union_type_die (type, context_die)
7681 register tree type;
7682 register dw_die_ref context_die;
7684 register dw_die_ref type_die = new_die (DW_TAG_union_type,
7685 scope_die_for (type, context_die));
7687 assert (TREE_ASM_WRITTEN (type));
7688 add_abstract_origin_attribute (type_die, type);
7691 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7692 include all of the information about the enumeration values also. Each
7693 enumerated type name/value is listed as a child of the enumerated type
7694 DIE. */
7696 static void
7697 gen_enumeration_type_die (type, context_die)
7698 register tree type;
7699 register dw_die_ref context_die;
7701 register dw_die_ref type_die = lookup_type_die (type);
7703 if (type_die == NULL)
7705 type_die = new_die (DW_TAG_enumeration_type,
7706 scope_die_for (type, context_die));
7707 equate_type_number_to_die (type, type_die);
7708 add_name_attribute (type_die, type_tag (type));
7710 else if (! TYPE_SIZE (type))
7711 return;
7712 else
7713 remove_AT (type_die, DW_AT_declaration);
7715 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7716 given enum type is incomplete, do not generate the DW_AT_byte_size
7717 attribute or the DW_AT_element_list attribute. */
7718 if (TYPE_SIZE (type))
7720 register tree link;
7722 TREE_ASM_WRITTEN (type) = 1;
7723 add_byte_size_attribute (type_die, type);
7724 if (TYPE_STUB_DECL (type) != NULL_TREE)
7725 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7727 /* If the first reference to this type was as the return type of an
7728 inline function, then it may not have a parent. Fix this now. */
7729 if (type_die->die_parent == NULL)
7730 add_child_die (scope_die_for (type, context_die), type_die);
7732 for (link = TYPE_FIELDS (type);
7733 link != NULL; link = TREE_CHAIN (link))
7735 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
7737 add_name_attribute (enum_die,
7738 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
7739 add_AT_unsigned (enum_die, DW_AT_const_value,
7740 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
7743 else
7744 add_AT_flag (type_die, DW_AT_declaration, 1);
7748 /* Generate a DIE to represent either a real live formal parameter decl or to
7749 represent just the type of some formal parameter position in some function
7750 type.
7752 Note that this routine is a bit unusual because its argument may be a
7753 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7754 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7755 node. If it's the former then this function is being called to output a
7756 DIE to represent a formal parameter object (or some inlining thereof). If
7757 it's the latter, then this function is only being called to output a
7758 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7759 argument type of some subprogram type. */
7761 static dw_die_ref
7762 gen_formal_parameter_die (node, context_die)
7763 register tree node;
7764 register dw_die_ref context_die;
7766 register dw_die_ref parm_die
7767 = new_die (DW_TAG_formal_parameter, context_die);
7768 register tree origin;
7770 switch (TREE_CODE_CLASS (TREE_CODE (node)))
7772 case 'd':
7773 origin = decl_ultimate_origin (node);
7774 if (origin != NULL)
7775 add_abstract_origin_attribute (parm_die, origin);
7776 else
7778 add_name_and_src_coords_attributes (parm_die, node);
7779 add_type_attribute (parm_die, TREE_TYPE (node),
7780 TREE_READONLY (node),
7781 TREE_THIS_VOLATILE (node),
7782 context_die);
7783 if (DECL_ARTIFICIAL (node))
7784 add_AT_flag (parm_die, DW_AT_artificial, 1);
7787 equate_decl_number_to_die (node, parm_die);
7788 if (! DECL_ABSTRACT (node))
7789 add_location_or_const_value_attribute (parm_die, node);
7791 break;
7793 case 't':
7794 /* We were called with some kind of a ..._TYPE node. */
7795 add_type_attribute (parm_die, node, 0, 0, context_die);
7796 break;
7798 default:
7799 abort ();
7802 return parm_die;
7805 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7806 at the end of an (ANSI prototyped) formal parameters list. */
7808 static void
7809 gen_unspecified_parameters_die (decl_or_type, context_die)
7810 register tree decl_or_type;
7811 register dw_die_ref context_die;
7813 register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters,
7814 context_die);
7817 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
7818 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
7819 parameters as specified in some function type specification (except for
7820 those which appear as part of a function *definition*).
7822 Note we must be careful here to output all of the parameter DIEs before*
7823 we output any DIEs needed to represent the types of the formal parameters.
7824 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
7825 non-parameter DIE it sees ends the formal parameter list. */
7827 static void
7828 gen_formal_types_die (function_or_method_type, context_die)
7829 register tree function_or_method_type;
7830 register dw_die_ref context_die;
7832 register tree link;
7833 register tree formal_type = NULL;
7834 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
7836 #if 0
7837 /* In the case where we are generating a formal types list for a C++
7838 non-static member function type, skip over the first thing on the
7839 TYPE_ARG_TYPES list because it only represents the type of the hidden
7840 `this pointer'. The debugger should be able to figure out (without
7841 being explicitly told) that this non-static member function type takes a
7842 `this pointer' and should be able to figure what the type of that hidden
7843 parameter is from the DW_AT_member attribute of the parent
7844 DW_TAG_subroutine_type DIE. */
7845 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
7846 first_parm_type = TREE_CHAIN (first_parm_type);
7847 #endif
7849 /* Make our first pass over the list of formal parameter types and output a
7850 DW_TAG_formal_parameter DIE for each one. */
7851 for (link = first_parm_type; link; link = TREE_CHAIN (link))
7853 register dw_die_ref parm_die;
7855 formal_type = TREE_VALUE (link);
7856 if (formal_type == void_type_node)
7857 break;
7859 /* Output a (nameless) DIE to represent the formal parameter itself. */
7860 parm_die = gen_formal_parameter_die (formal_type, context_die);
7861 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
7862 && link == first_parm_type)
7863 add_AT_flag (parm_die, DW_AT_artificial, 1);
7866 /* If this function type has an ellipsis, add a
7867 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
7868 if (formal_type != void_type_node)
7869 gen_unspecified_parameters_die (function_or_method_type, context_die);
7871 /* Make our second (and final) pass over the list of formal parameter types
7872 and output DIEs to represent those types (as necessary). */
7873 for (link = TYPE_ARG_TYPES (function_or_method_type);
7874 link;
7875 link = TREE_CHAIN (link))
7877 formal_type = TREE_VALUE (link);
7878 if (formal_type == void_type_node)
7879 break;
7881 gen_type_die (formal_type, context_die);
7885 /* Generate a DIE to represent a declared function (either file-scope or
7886 block-local). */
7888 static void
7889 gen_subprogram_die (decl, context_die)
7890 register tree decl;
7891 register dw_die_ref context_die;
7893 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
7894 register tree origin = decl_ultimate_origin (decl);
7895 register dw_die_ref subr_die;
7896 register dw_loc_descr_ref fp_loc = NULL;
7897 register rtx fp_reg;
7898 register tree fn_arg_types;
7899 register tree outer_scope;
7900 register dw_die_ref old_die = lookup_decl_die (decl);
7901 register int declaration
7902 = (current_function_decl != decl
7903 || (context_die
7904 && (context_die->die_tag == DW_TAG_structure_type
7905 || context_die->die_tag == DW_TAG_union_type)));
7907 if (origin != NULL)
7909 subr_die = new_die (DW_TAG_subprogram, context_die);
7910 add_abstract_origin_attribute (subr_die, origin);
7912 else if (old_die && DECL_ABSTRACT (decl)
7913 && get_AT_unsigned (old_die, DW_AT_inline))
7915 /* This must be a redefinition of an extern inline function.
7916 We can just reuse the old die here. */
7917 subr_die = old_die;
7919 /* Clear out the inlined attribute and parm types. */
7920 remove_AT (subr_die, DW_AT_inline);
7921 remove_children (subr_die);
7923 else if (old_die)
7925 register unsigned file_index
7926 = lookup_filename (DECL_SOURCE_FILE (decl));
7928 assert (get_AT_flag (old_die, DW_AT_declaration) == 1);
7930 /* If the definition comes from the same place as the declaration,
7931 maybe use the old DIE. We always want the DIE for this function
7932 that has the *_pc attributes to be under comp_unit_die so the
7933 debugger can find it. For inlines, that is the concrete instance,
7934 so we can use the old DIE here. For non-inline methods, we want a
7935 specification DIE at toplevel, so we need a new DIE. For local
7936 class methods, this does not apply. */
7937 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
7938 || context_die == NULL)
7939 && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
7940 && (get_AT_unsigned (old_die, DW_AT_decl_line)
7941 == DECL_SOURCE_LINE (decl)))
7943 subr_die = old_die;
7945 /* Clear out the declaration attribute and the parm types. */
7946 remove_AT (subr_die, DW_AT_declaration);
7947 remove_children (subr_die);
7949 else
7951 subr_die = new_die (DW_TAG_subprogram, context_die);
7952 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
7953 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
7954 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
7955 if (get_AT_unsigned (old_die, DW_AT_decl_line)
7956 != DECL_SOURCE_LINE (decl))
7957 add_AT_unsigned
7958 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7961 else
7963 register dw_die_ref scope_die;
7965 if (DECL_CONTEXT (decl))
7966 scope_die = scope_die_for (decl, context_die);
7967 else
7968 /* Don't put block extern declarations under comp_unit_die. */
7969 scope_die = context_die;
7971 subr_die = new_die (DW_TAG_subprogram, scope_die);
7973 if (TREE_PUBLIC (decl))
7974 add_AT_flag (subr_die, DW_AT_external, 1);
7976 add_name_and_src_coords_attributes (subr_die, decl);
7977 if (debug_info_level > DINFO_LEVEL_TERSE)
7979 register tree type = TREE_TYPE (decl);
7981 add_prototyped_attribute (subr_die, type);
7982 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
7985 add_pure_or_virtual_attribute (subr_die, decl);
7986 if (DECL_ARTIFICIAL (decl))
7987 add_AT_flag (subr_die, DW_AT_artificial, 1);
7988 if (TREE_PROTECTED (decl))
7989 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
7990 else if (TREE_PRIVATE (decl))
7991 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
7994 if (declaration)
7996 add_AT_flag (subr_die, DW_AT_declaration, 1);
7998 /* The first time we see a member function, it is in the context of
7999 the class to which it belongs. We make sure of this by emitting
8000 the class first. The next time is the definition, which is
8001 handled above. The two may come from the same source text. */
8002 if (DECL_CONTEXT (decl))
8003 equate_decl_number_to_die (decl, subr_die);
8005 else if (DECL_ABSTRACT (decl))
8007 /* ??? Checking DECL_DEFER_OUTPUT is correct for static inline functions,
8008 but not for extern inline functions. We can't get this completely
8009 correct because information about whether the function was declared
8010 inline is not saved anywhere. */
8011 if (DECL_DEFER_OUTPUT (decl))
8013 if (DECL_INLINE (decl))
8014 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8015 else
8016 add_AT_unsigned (subr_die, DW_AT_inline,
8017 DW_INL_declared_not_inlined);
8019 else if (DECL_INLINE (decl))
8020 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8021 else
8022 abort ();
8024 equate_decl_number_to_die (decl, subr_die);
8026 else if (!DECL_EXTERNAL (decl))
8028 if (origin == NULL_TREE)
8029 equate_decl_number_to_die (decl, subr_die);
8031 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8032 current_funcdef_number);
8033 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
8034 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8035 current_funcdef_number);
8036 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8038 add_pubname (decl, subr_die);
8039 add_arange (decl, subr_die);
8041 #ifdef MIPS_DEBUGGING_INFO
8042 /* Add a reference to the FDE for this routine. */
8043 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8044 #endif
8046 /* Define the "frame base" location for this routine. We use the
8047 frame pointer or stack pointer registers, since the RTL for local
8048 variables is relative to one of them. */
8049 fp_reg
8050 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8051 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
8053 #if 0
8054 /* ??? This fails for nested inline functions, because context_display
8055 is not part of the state saved/restored for inline functions. */
8056 if (current_function_needs_context)
8057 add_AT_location_description (subr_die, DW_AT_static_link,
8058 lookup_static_chain (decl));
8059 #endif
8062 /* Now output descriptions of the arguments for this function. This gets
8063 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8064 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8065 `...' at the end of the formal parameter list. In order to find out if
8066 there was a trailing ellipsis or not, we must instead look at the type
8067 associated with the FUNCTION_DECL. This will be a node of type
8068 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8069 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8070 an ellipsis at the end. */
8071 push_decl_scope (decl);
8073 /* In the case where we are describing a mere function declaration, all we
8074 need to do here (and all we *can* do here) is to describe the *types* of
8075 its formal parameters. */
8076 if (debug_info_level <= DINFO_LEVEL_TERSE)
8078 else if (declaration)
8079 gen_formal_types_die (TREE_TYPE (decl), subr_die);
8080 else
8082 /* Generate DIEs to represent all known formal parameters */
8083 register tree arg_decls = DECL_ARGUMENTS (decl);
8084 register tree parm;
8086 /* When generating DIEs, generate the unspecified_parameters DIE
8087 instead if we come across the arg "__builtin_va_alist" */
8088 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
8089 if (TREE_CODE (parm) == PARM_DECL)
8091 if (DECL_NAME (parm)
8092 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8093 "__builtin_va_alist"))
8094 gen_unspecified_parameters_die (parm, subr_die);
8095 else
8096 gen_decl_die (parm, subr_die);
8099 /* Decide whether we need a unspecified_parameters DIE at the end.
8100 There are 2 more cases to do this for: 1) the ansi ... declaration -
8101 this is detectable when the end of the arg list is not a
8102 void_type_node 2) an unprototyped function declaration (not a
8103 definition). This just means that we have no info about the
8104 parameters at all. */
8105 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
8106 if (fn_arg_types != NULL)
8108 /* this is the prototyped case, check for ... */
8109 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
8110 gen_unspecified_parameters_die (decl, subr_die);
8112 else if (DECL_INITIAL (decl) == NULL_TREE)
8113 gen_unspecified_parameters_die (decl, subr_die);
8116 /* Output Dwarf info for all of the stuff within the body of the function
8117 (if it has one - it may be just a declaration). */
8118 outer_scope = DECL_INITIAL (decl);
8120 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8121 node created to represent a function. This outermost BLOCK actually
8122 represents the outermost binding contour for the function, i.e. the
8123 contour in which the function's formal parameters and labels get
8124 declared. Curiously, it appears that the front end doesn't actually
8125 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8126 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8127 list for the function instead.) The BLOCK_VARS list for the
8128 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8129 the function however, and we output DWARF info for those in
8130 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8131 node representing the function's outermost pair of curly braces, and
8132 any blocks used for the base and member initializers of a C++
8133 constructor function. */
8134 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
8136 current_function_has_inlines = 0;
8137 decls_for_scope (outer_scope, subr_die, 0);
8139 #if 0 && defined (MIPS_DEBUGGING_INFO)
8140 if (current_function_has_inlines)
8142 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8143 if (! comp_unit_has_inlines)
8145 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8146 comp_unit_has_inlines = 1;
8149 #endif
8152 pop_decl_scope ();
8155 /* Generate a DIE to represent a declared data object. */
8157 static void
8158 gen_variable_die (decl, context_die)
8159 register tree decl;
8160 register dw_die_ref context_die;
8162 register tree origin = decl_ultimate_origin (decl);
8163 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
8165 dw_die_ref old_die = lookup_decl_die (decl);
8166 int declaration
8167 = (DECL_EXTERNAL (decl)
8168 || current_function_decl != decl_function_context (decl)
8169 || context_die->die_tag == DW_TAG_structure_type
8170 || context_die->die_tag == DW_TAG_union_type);
8172 if (origin != NULL)
8173 add_abstract_origin_attribute (var_die, origin);
8174 /* Loop unrolling can create multiple blocks that refer to the same
8175 static variable, so we must test for the DW_AT_declaration flag. */
8176 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8177 copy decls and set the DECL_ABSTRACT flag on them instead of
8178 sharing them. */
8179 else if (old_die && TREE_STATIC (decl)
8180 && get_AT_flag (old_die, DW_AT_declaration) == 1)
8182 /* ??? This is an instantiation of a C++ class level static. */
8183 add_AT_die_ref (var_die, DW_AT_specification, old_die);
8184 if (DECL_NAME (decl))
8186 register unsigned file_index
8187 = lookup_filename (DECL_SOURCE_FILE (decl));
8189 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8190 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
8192 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8193 != DECL_SOURCE_LINE (decl))
8195 add_AT_unsigned (var_die, DW_AT_decl_line,
8196 DECL_SOURCE_LINE (decl));
8199 else
8201 add_name_and_src_coords_attributes (var_die, decl);
8202 add_type_attribute (var_die, TREE_TYPE (decl),
8203 TREE_READONLY (decl),
8204 TREE_THIS_VOLATILE (decl), context_die);
8206 if (TREE_PUBLIC (decl))
8207 add_AT_flag (var_die, DW_AT_external, 1);
8209 if (DECL_ARTIFICIAL (decl))
8210 add_AT_flag (var_die, DW_AT_artificial, 1);
8212 if (TREE_PROTECTED (decl))
8213 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
8215 else if (TREE_PRIVATE (decl))
8216 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
8219 if (declaration)
8220 add_AT_flag (var_die, DW_AT_declaration, 1);
8222 if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl))
8223 equate_decl_number_to_die (decl, var_die);
8225 if (! declaration && ! DECL_ABSTRACT (decl))
8227 equate_decl_number_to_die (decl, var_die);
8228 add_location_or_const_value_attribute (var_die, decl);
8229 add_pubname (decl, var_die);
8233 /* Generate a DIE to represent a label identifier. */
8235 static void
8236 gen_label_die (decl, context_die)
8237 register tree decl;
8238 register dw_die_ref context_die;
8240 register tree origin = decl_ultimate_origin (decl);
8241 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8242 register rtx insn;
8243 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8244 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
8246 if (origin != NULL)
8247 add_abstract_origin_attribute (lbl_die, origin);
8248 else
8249 add_name_and_src_coords_attributes (lbl_die, decl);
8251 if (DECL_ABSTRACT (decl))
8252 equate_decl_number_to_die (decl, lbl_die);
8253 else
8255 insn = DECL_RTL (decl);
8256 if (GET_CODE (insn) == CODE_LABEL)
8258 /* When optimization is enabled (via -O) some parts of the compiler
8259 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8260 represent source-level labels which were explicitly declared by
8261 the user. This really shouldn't be happening though, so catch
8262 it if it ever does happen. */
8263 if (INSN_DELETED_P (insn))
8264 abort ();
8266 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8267 ASM_GENERATE_INTERNAL_LABEL (label, label2,
8268 (unsigned) INSN_UID (insn));
8269 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8274 /* Generate a DIE for a lexical block. */
8276 static void
8277 gen_lexical_block_die (stmt, context_die, depth)
8278 register tree stmt;
8279 register dw_die_ref context_die;
8280 int depth;
8282 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8283 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8285 if (! BLOCK_ABSTRACT (stmt))
8287 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8288 next_block_number);
8289 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
8290 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
8291 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8294 push_decl_scope (stmt);
8295 decls_for_scope (stmt, stmt_die, depth);
8296 pop_decl_scope ();
8299 /* Generate a DIE for an inlined subprogram. */
8301 static void
8302 gen_inlined_subroutine_die (stmt, context_die, depth)
8303 register tree stmt;
8304 register dw_die_ref context_die;
8305 int depth;
8307 if (! BLOCK_ABSTRACT (stmt))
8309 register dw_die_ref subr_die
8310 = new_die (DW_TAG_inlined_subroutine, context_die);
8311 register tree decl = block_ultimate_origin (stmt);
8312 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8314 add_abstract_origin_attribute (subr_die, decl);
8315 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8316 next_block_number);
8317 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
8318 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
8319 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
8320 push_decl_scope (decl);
8321 decls_for_scope (stmt, subr_die, depth);
8322 pop_decl_scope ();
8323 current_function_has_inlines = 1;
8327 /* Generate a DIE for a field in a record, or structure. */
8329 static void
8330 gen_field_die (decl, context_die)
8331 register tree decl;
8332 register dw_die_ref context_die;
8334 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
8336 add_name_and_src_coords_attributes (decl_die, decl);
8337 add_type_attribute (decl_die, member_declared_type (decl),
8338 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8339 context_die);
8341 /* If this is a bit field... */
8342 if (DECL_BIT_FIELD_TYPE (decl))
8344 add_byte_size_attribute (decl_die, decl);
8345 add_bit_size_attribute (decl_die, decl);
8346 add_bit_offset_attribute (decl_die, decl);
8349 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8350 add_data_member_location_attribute (decl_die, decl);
8352 if (DECL_ARTIFICIAL (decl))
8353 add_AT_flag (decl_die, DW_AT_artificial, 1);
8355 if (TREE_PROTECTED (decl))
8356 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
8358 else if (TREE_PRIVATE (decl))
8359 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
8362 #if 0
8363 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8364 Use modified_type_die instead.
8365 We keep this code here just in case these types of DIEs may be needed to
8366 represent certain things in other languages (e.g. Pascal) someday. */
8367 static void
8368 gen_pointer_type_die (type, context_die)
8369 register tree type;
8370 register dw_die_ref context_die;
8372 register dw_die_ref ptr_die
8373 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8375 equate_type_number_to_die (type, ptr_die);
8376 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8377 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8380 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8381 Use modified_type_die instead.
8382 We keep this code here just in case these types of DIEs may be needed to
8383 represent certain things in other languages (e.g. Pascal) someday. */
8384 static void
8385 gen_reference_type_die (type, context_die)
8386 register tree type;
8387 register dw_die_ref context_die;
8389 register dw_die_ref ref_die
8390 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8392 equate_type_number_to_die (type, ref_die);
8393 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
8394 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8396 #endif
8398 /* Generate a DIE for a pointer to a member type. */
8399 static void
8400 gen_ptr_to_mbr_type_die (type, context_die)
8401 register tree type;
8402 register dw_die_ref context_die;
8404 register dw_die_ref ptr_die
8405 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8407 equate_type_number_to_die (type, ptr_die);
8408 add_AT_die_ref (ptr_die, DW_AT_containing_type,
8409 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8410 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8413 /* Generate the DIE for the compilation unit. */
8415 static void
8416 gen_compile_unit_die (main_input_filename)
8417 register char *main_input_filename;
8419 char producer[250];
8420 char *wd = getpwd ();
8422 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
8423 add_name_attribute (comp_unit_die, main_input_filename);
8425 if (wd != NULL)
8426 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
8428 sprintf (producer, "%s %s", language_string, version_string);
8430 #ifdef MIPS_DEBUGGING_INFO
8431 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8432 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8433 not appear in the producer string, the debugger reaches the conclusion
8434 that the object file is stripped and has no debugging information.
8435 To get the MIPS/SGI debugger to believe that there is debugging
8436 information in the object file, we add a -g to the producer string. */
8437 if (debug_info_level > DINFO_LEVEL_TERSE)
8438 strcat (producer, " -g");
8439 #endif
8441 add_AT_string (comp_unit_die, DW_AT_producer, producer);
8443 if (strcmp (language_string, "GNU C++") == 0)
8444 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
8446 else if (strcmp (language_string, "GNU Ada") == 0)
8447 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
8449 else if (strcmp (language_string, "GNU F77") == 0)
8450 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77);
8452 else if (strcmp (language_string, "GNU Pascal") == 0)
8453 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Pascal83);
8455 else if (flag_traditional)
8456 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
8458 else
8459 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
8461 #if 0 /* unimplemented */
8462 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
8463 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
8464 #endif
8467 /* Generate a DIE for a string type. */
8469 static void
8470 gen_string_type_die (type, context_die)
8471 register tree type;
8472 register dw_die_ref context_die;
8474 register dw_die_ref type_die
8475 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
8477 equate_type_number_to_die (type, type_die);
8479 /* Fudge the string length attribute for now. */
8481 /* TODO: add string length info.
8482 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8483 bound_representation (upper_bound, 0, 'u'); */
8486 /* Generate the DIE for a base class. */
8488 static void
8489 gen_inheritance_die (binfo, context_die)
8490 register tree binfo;
8491 register dw_die_ref context_die;
8493 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
8495 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
8496 add_data_member_location_attribute (die, binfo);
8498 if (TREE_VIA_VIRTUAL (binfo))
8499 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8500 if (TREE_VIA_PUBLIC (binfo))
8501 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
8502 else if (TREE_VIA_PROTECTED (binfo))
8503 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
8506 /* Generate a DIE for a class member. */
8508 static void
8509 gen_member_die (type, context_die)
8510 register tree type;
8511 register dw_die_ref context_die;
8513 register tree member;
8515 /* If this is not an incomplete type, output descriptions of each of its
8516 members. Note that as we output the DIEs necessary to represent the
8517 members of this record or union type, we will also be trying to output
8518 DIEs to represent the *types* of those members. However the `type'
8519 function (above) will specifically avoid generating type DIEs for member
8520 types *within* the list of member DIEs for this (containing) type execpt
8521 for those types (of members) which are explicitly marked as also being
8522 members of this (containing) type themselves. The g++ front- end can
8523 force any given type to be treated as a member of some other
8524 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8525 to point to the TREE node representing the appropriate (containing)
8526 type. */
8528 /* First output info about the base classes. */
8529 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
8531 register tree bases = TYPE_BINFO_BASETYPES (type);
8532 register int n_bases = TREE_VEC_LENGTH (bases);
8533 register int i;
8535 for (i = 0; i < n_bases; i++)
8536 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
8539 /* Now output info about the data members and type members. */
8540 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
8541 gen_decl_die (member, context_die);
8543 /* Now output info about the function members (if any). */
8544 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
8545 gen_decl_die (member, context_die);
8548 /* Generate a DIE for a structure or union type. */
8550 static void
8551 gen_struct_or_union_type_die (type, context_die)
8552 register tree type;
8553 register dw_die_ref context_die;
8555 register dw_die_ref type_die = lookup_type_die (type);
8556 register dw_die_ref scope_die = 0;
8557 register int nested = 0;
8559 if (type_die && ! TYPE_SIZE (type))
8560 return;
8562 if (TYPE_CONTEXT (type) != NULL_TREE
8563 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't')
8564 nested = 1;
8566 scope_die = scope_die_for (type, context_die);
8568 if (! type_die || (nested && scope_die == comp_unit_die))
8569 /* First occurrence of type or toplevel definition of nested class. */
8571 register dw_die_ref old_die = type_die;
8573 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8574 ? DW_TAG_structure_type : DW_TAG_union_type,
8575 scope_die);
8576 equate_type_number_to_die (type, type_die);
8577 add_name_attribute (type_die, type_tag (type));
8578 if (old_die)
8579 add_AT_die_ref (type_die, DW_AT_specification, old_die);
8581 else
8582 remove_AT (type_die, DW_AT_declaration);
8584 /* If we're not in the right context to be defining this type, defer to
8585 avoid tricky recursion. */
8586 if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die)
8588 add_AT_flag (type_die, DW_AT_declaration, 1);
8589 pend_type (type);
8591 /* If this type has been completed, then give it a byte_size attribute and
8592 then give a list of members. */
8593 else if (TYPE_SIZE (type))
8595 /* Prevent infinite recursion in cases where the type of some member of
8596 this type is expressed in terms of this type itself. */
8597 TREE_ASM_WRITTEN (type) = 1;
8598 add_byte_size_attribute (type_die, type);
8599 if (TYPE_STUB_DECL (type) != NULL_TREE)
8600 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8602 /* If the first reference to this type was as the return type of an
8603 inline function, then it may not have a parent. Fix this now. */
8604 if (type_die->die_parent == NULL)
8605 add_child_die (scope_die, type_die);
8607 push_decl_scope (type);
8608 gen_member_die (type, type_die);
8609 pop_decl_scope ();
8611 /* GNU extension: Record what type our vtable lives in. */
8612 if (TYPE_VFIELD (type))
8614 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
8616 gen_type_die (vtype, context_die);
8617 add_AT_die_ref (type_die, DW_AT_containing_type,
8618 lookup_type_die (vtype));
8621 else
8622 add_AT_flag (type_die, DW_AT_declaration, 1);
8625 /* Generate a DIE for a subroutine _type_. */
8627 static void
8628 gen_subroutine_type_die (type, context_die)
8629 register tree type;
8630 register dw_die_ref context_die;
8632 register tree return_type = TREE_TYPE (type);
8633 register dw_die_ref subr_die
8634 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8636 equate_type_number_to_die (type, subr_die);
8637 add_prototyped_attribute (subr_die, type);
8638 add_type_attribute (subr_die, return_type, 0, 0, context_die);
8639 gen_formal_types_die (type, subr_die);
8642 /* Generate a DIE for a type definition */
8644 static void
8645 gen_typedef_die (decl, context_die)
8646 register tree decl;
8647 register dw_die_ref context_die;
8649 register dw_die_ref type_die;
8650 register tree origin;
8652 if (TREE_ASM_WRITTEN (decl))
8653 return;
8654 TREE_ASM_WRITTEN (decl) = 1;
8656 type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
8657 origin = decl_ultimate_origin (decl);
8658 if (origin != NULL)
8659 add_abstract_origin_attribute (type_die, origin);
8660 else
8662 register tree type;
8663 add_name_and_src_coords_attributes (type_die, decl);
8664 if (DECL_ORIGINAL_TYPE (decl))
8666 type = DECL_ORIGINAL_TYPE (decl);
8667 equate_type_number_to_die (TREE_TYPE (decl), type_die);
8669 else
8670 type = TREE_TYPE (decl);
8671 add_type_attribute (type_die, type, TREE_READONLY (decl),
8672 TREE_THIS_VOLATILE (decl), context_die);
8675 if (DECL_ABSTRACT (decl))
8676 equate_decl_number_to_die (decl, type_die);
8679 /* Generate a type description DIE. */
8681 static void
8682 gen_type_die (type, context_die)
8683 register tree type;
8684 register dw_die_ref context_die;
8686 if (type == NULL_TREE || type == error_mark_node)
8687 return;
8689 /* We are going to output a DIE to represent the unqualified version of of
8690 this type (i.e. without any const or volatile qualifiers) so get the
8691 main variant (i.e. the unqualified version) of this type now. */
8692 type = type_main_variant (type);
8694 if (TREE_ASM_WRITTEN (type))
8695 return;
8697 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8698 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8700 TREE_ASM_WRITTEN (type) = 1;
8701 gen_decl_die (TYPE_NAME (type), context_die);
8702 return;
8705 switch (TREE_CODE (type))
8707 case ERROR_MARK:
8708 break;
8710 case POINTER_TYPE:
8711 case REFERENCE_TYPE:
8712 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
8713 ensures that the gen_type_die recursion will terminate even if the
8714 type is recursive. Recursive types are possible in Ada. */
8715 /* ??? We could perhaps do this for all types before the switch
8716 statement. */
8717 TREE_ASM_WRITTEN (type) = 1;
8719 /* For these types, all that is required is that we output a DIE (or a
8720 set of DIEs) to represent the "basis" type. */
8721 gen_type_die (TREE_TYPE (type), context_die);
8722 break;
8724 case OFFSET_TYPE:
8725 /* This code is used for C++ pointer-to-data-member types.
8726 Output a description of the relevant class type. */
8727 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
8729 /* Output a description of the type of the object pointed to. */
8730 gen_type_die (TREE_TYPE (type), context_die);
8732 /* Now output a DIE to represent this pointer-to-data-member type
8733 itself. */
8734 gen_ptr_to_mbr_type_die (type, context_die);
8735 break;
8737 case SET_TYPE:
8738 gen_type_die (TYPE_DOMAIN (type), context_die);
8739 gen_set_type_die (type, context_die);
8740 break;
8742 case FILE_TYPE:
8743 gen_type_die (TREE_TYPE (type), context_die);
8744 abort (); /* No way to represent these in Dwarf yet! */
8745 break;
8747 case FUNCTION_TYPE:
8748 /* Force out return type (in case it wasn't forced out already). */
8749 gen_type_die (TREE_TYPE (type), context_die);
8750 gen_subroutine_type_die (type, context_die);
8751 break;
8753 case METHOD_TYPE:
8754 /* Force out return type (in case it wasn't forced out already). */
8755 gen_type_die (TREE_TYPE (type), context_die);
8756 gen_subroutine_type_die (type, context_die);
8757 break;
8759 case ARRAY_TYPE:
8760 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
8762 gen_type_die (TREE_TYPE (type), context_die);
8763 gen_string_type_die (type, context_die);
8765 else
8766 gen_array_type_die (type, context_die);
8767 break;
8769 case ENUMERAL_TYPE:
8770 case RECORD_TYPE:
8771 case UNION_TYPE:
8772 case QUAL_UNION_TYPE:
8773 /* If this is a nested type whose containing class hasn't been
8774 written out yet, writing it out will cover this one, too. */
8775 if (TYPE_CONTEXT (type)
8776 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8777 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8779 gen_type_die (TYPE_CONTEXT (type), context_die);
8781 if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8782 return;
8784 /* If that failed, attach ourselves to the stub. */
8785 push_decl_scope (TYPE_CONTEXT (type));
8786 context_die = lookup_type_die (TYPE_CONTEXT (type));
8789 if (TREE_CODE (type) == ENUMERAL_TYPE)
8790 gen_enumeration_type_die (type, context_die);
8791 else
8792 gen_struct_or_union_type_die (type, context_die);
8794 if (TYPE_CONTEXT (type)
8795 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8796 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8797 pop_decl_scope ();
8799 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
8800 it up if it is ever completed. gen_*_type_die will set it for us
8801 when appropriate. */
8802 return;
8804 case VOID_TYPE:
8805 case INTEGER_TYPE:
8806 case REAL_TYPE:
8807 case COMPLEX_TYPE:
8808 case BOOLEAN_TYPE:
8809 case CHAR_TYPE:
8810 /* No DIEs needed for fundamental types. */
8811 break;
8813 case LANG_TYPE:
8814 /* No Dwarf representation currently defined. */
8815 break;
8817 default:
8818 abort ();
8821 TREE_ASM_WRITTEN (type) = 1;
8824 /* Generate a DIE for a tagged type instantiation. */
8826 static void
8827 gen_tagged_type_instantiation_die (type, context_die)
8828 register tree type;
8829 register dw_die_ref context_die;
8831 if (type == NULL_TREE || type == error_mark_node)
8832 return;
8834 /* We are going to output a DIE to represent the unqualified version of of
8835 this type (i.e. without any const or volatile qualifiers) so make sure
8836 that we have the main variant (i.e. the unqualified version) of this
8837 type now. */
8838 assert (type == type_main_variant (type));
8839 assert (TREE_ASM_WRITTEN (type));
8841 switch (TREE_CODE (type))
8843 case ERROR_MARK:
8844 break;
8846 case ENUMERAL_TYPE:
8847 gen_inlined_enumeration_type_die (type, context_die);
8848 break;
8850 case RECORD_TYPE:
8851 gen_inlined_structure_type_die (type, context_die);
8852 break;
8854 case UNION_TYPE:
8855 case QUAL_UNION_TYPE:
8856 gen_inlined_union_type_die (type, context_die);
8857 break;
8859 default:
8860 abort ();
8864 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
8865 things which are local to the given block. */
8867 static void
8868 gen_block_die (stmt, context_die, depth)
8869 register tree stmt;
8870 register dw_die_ref context_die;
8871 int depth;
8873 register int must_output_die = 0;
8874 register tree origin;
8875 register tree decl;
8876 register enum tree_code origin_code;
8878 /* Ignore blocks never really used to make RTL. */
8880 if (stmt == NULL_TREE || !TREE_USED (stmt))
8881 return;
8883 /* Determine the "ultimate origin" of this block. This block may be an
8884 inlined instance of an inlined instance of inline function, so we have
8885 to trace all of the way back through the origin chain to find out what
8886 sort of node actually served as the original seed for the creation of
8887 the current block. */
8888 origin = block_ultimate_origin (stmt);
8889 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
8891 /* Determine if we need to output any Dwarf DIEs at all to represent this
8892 block. */
8893 if (origin_code == FUNCTION_DECL)
8894 /* The outer scopes for inlinings *must* always be represented. We
8895 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
8896 must_output_die = 1;
8897 else
8899 /* In the case where the current block represents an inlining of the
8900 "body block" of an inline function, we must *NOT* output any DIE for
8901 this block because we have already output a DIE to represent the
8902 whole inlined function scope and the "body block" of any function
8903 doesn't really represent a different scope according to ANSI C
8904 rules. So we check here to make sure that this block does not
8905 represent a "body block inlining" before trying to set the
8906 `must_output_die' flag. */
8907 if (! is_body_block (origin ? origin : stmt))
8909 /* Determine if this block directly contains any "significant"
8910 local declarations which we will need to output DIEs for. */
8911 if (debug_info_level > DINFO_LEVEL_TERSE)
8912 /* We are not in terse mode so *any* local declaration counts
8913 as being a "significant" one. */
8914 must_output_die = (BLOCK_VARS (stmt) != NULL);
8915 else
8916 /* We are in terse mode, so only local (nested) function
8917 definitions count as "significant" local declarations. */
8918 for (decl = BLOCK_VARS (stmt);
8919 decl != NULL; decl = TREE_CHAIN (decl))
8920 if (TREE_CODE (decl) == FUNCTION_DECL
8921 && DECL_INITIAL (decl))
8923 must_output_die = 1;
8924 break;
8929 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
8930 DIE for any block which contains no significant local declarations at
8931 all. Rather, in such cases we just call `decls_for_scope' so that any
8932 needed Dwarf info for any sub-blocks will get properly generated. Note
8933 that in terse mode, our definition of what constitutes a "significant"
8934 local declaration gets restricted to include only inlined function
8935 instances and local (nested) function definitions. */
8936 if (must_output_die)
8938 if (origin_code == FUNCTION_DECL)
8939 gen_inlined_subroutine_die (stmt, context_die, depth);
8940 else
8941 gen_lexical_block_die (stmt, context_die, depth);
8943 else
8944 decls_for_scope (stmt, context_die, depth);
8947 /* Generate all of the decls declared within a given scope and (recursively)
8948 all of it's sub-blocks. */
8950 static void
8951 decls_for_scope (stmt, context_die, depth)
8952 register tree stmt;
8953 register dw_die_ref context_die;
8954 int depth;
8956 register tree decl;
8957 register tree subblocks;
8959 /* Ignore blocks never really used to make RTL. */
8960 if (stmt == NULL_TREE || ! TREE_USED (stmt))
8961 return;
8963 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
8964 next_block_number++;
8966 /* Output the DIEs to represent all of the data objects and typedefs
8967 declared directly within this block but not within any nested
8968 sub-blocks. Also, nested function and tag DIEs have been
8969 generated with a parent of NULL; fix that up now. */
8970 for (decl = BLOCK_VARS (stmt);
8971 decl != NULL; decl = TREE_CHAIN (decl))
8973 register dw_die_ref die;
8975 if (TREE_CODE (decl) == FUNCTION_DECL)
8976 die = lookup_decl_die (decl);
8977 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
8978 die = lookup_type_die (TREE_TYPE (decl));
8979 else
8980 die = NULL;
8982 if (die != NULL && die->die_parent == NULL)
8983 add_child_die (context_die, die);
8984 else
8985 gen_decl_die (decl, context_die);
8988 /* Output the DIEs to represent all sub-blocks (and the items declared
8989 therein) of this block. */
8990 for (subblocks = BLOCK_SUBBLOCKS (stmt);
8991 subblocks != NULL;
8992 subblocks = BLOCK_CHAIN (subblocks))
8993 gen_block_die (subblocks, context_die, depth + 1);
8996 /* Is this a typedef we can avoid emitting? */
8998 static inline int
8999 is_redundant_typedef (decl)
9000 register tree decl;
9002 if (TYPE_DECL_IS_STUB (decl))
9003 return 1;
9005 if (DECL_ARTIFICIAL (decl)
9006 && DECL_CONTEXT (decl)
9007 && is_tagged_type (DECL_CONTEXT (decl))
9008 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9009 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9010 /* Also ignore the artificial member typedef for the class name. */
9011 return 1;
9013 return 0;
9016 /* Generate Dwarf debug information for a decl described by DECL. */
9018 static void
9019 gen_decl_die (decl, context_die)
9020 register tree decl;
9021 register dw_die_ref context_die;
9023 register tree origin;
9025 /* Make a note of the decl node we are going to be working on. We may need
9026 to give the user the source coordinates of where it appeared in case we
9027 notice (later on) that something about it looks screwy. */
9028 dwarf_last_decl = decl;
9030 if (TREE_CODE (decl) == ERROR_MARK)
9031 return;
9033 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
9034 ignore a function definition, since that would screw up our count of
9035 blocks, and that it turn will completely screw up the the labels we will
9036 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9037 subsequent blocks). */
9038 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
9039 return;
9041 switch (TREE_CODE (decl))
9043 case CONST_DECL:
9044 /* The individual enumerators of an enum type get output when we output
9045 the Dwarf representation of the relevant enum type itself. */
9046 break;
9048 case FUNCTION_DECL:
9049 /* Don't output any DIEs to represent mere function declarations,
9050 unless they are class members or explicit block externs. */
9051 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9052 && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl)))
9053 break;
9055 if (debug_info_level > DINFO_LEVEL_TERSE)
9057 /* Before we describe the FUNCTION_DECL itself, make sure that we
9058 have described its return type. */
9059 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9061 /* And its containing type. */
9062 origin = decl_class_context (decl);
9063 if (origin != NULL_TREE)
9064 gen_type_die (origin, context_die);
9066 /* And its virtual context. */
9067 if (DECL_VINDEX (decl) != NULL_TREE)
9068 gen_type_die (DECL_CONTEXT (decl), context_die);
9071 /* Now output a DIE to represent the function itself. */
9072 gen_subprogram_die (decl, context_die);
9073 break;
9075 case TYPE_DECL:
9076 /* If we are in terse mode, don't generate any DIEs to represent any
9077 actual typedefs. */
9078 if (debug_info_level <= DINFO_LEVEL_TERSE)
9079 break;
9081 /* In the special case of a TYPE_DECL node representing the
9082 declaration of some type tag, if the given TYPE_DECL is marked as
9083 having been instantiated from some other (original) TYPE_DECL node
9084 (e.g. one which was generated within the original definition of an
9085 inline function) we have to generate a special (abbreviated)
9086 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9087 DIE here. */
9088 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
9090 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9091 break;
9094 if (is_redundant_typedef (decl))
9095 gen_type_die (TREE_TYPE (decl), context_die);
9096 else
9097 /* Output a DIE to represent the typedef itself. */
9098 gen_typedef_die (decl, context_die);
9099 break;
9101 case LABEL_DECL:
9102 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9103 gen_label_die (decl, context_die);
9104 break;
9106 case VAR_DECL:
9107 /* If we are in terse mode, don't generate any DIEs to represent any
9108 variable declarations or definitions. */
9109 if (debug_info_level <= DINFO_LEVEL_TERSE)
9110 break;
9112 /* Output any DIEs that are needed to specify the type of this data
9113 object. */
9114 gen_type_die (TREE_TYPE (decl), context_die);
9116 /* And its containing type. */
9117 origin = decl_class_context (decl);
9118 if (origin != NULL_TREE)
9119 gen_type_die (origin, context_die);
9121 /* Now output the DIE to represent the data object itself. This gets
9122 complicated because of the possibility that the VAR_DECL really
9123 represents an inlined instance of a formal parameter for an inline
9124 function. */
9125 origin = decl_ultimate_origin (decl);
9126 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9127 gen_formal_parameter_die (decl, context_die);
9128 else
9129 gen_variable_die (decl, context_die);
9130 break;
9132 case FIELD_DECL:
9133 /* Ignore the nameless fields that are used to skip bits, but
9134 handle C++ anonymous unions. */
9135 if (DECL_NAME (decl) != NULL_TREE
9136 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
9138 gen_type_die (member_declared_type (decl), context_die);
9139 gen_field_die (decl, context_die);
9141 break;
9143 case PARM_DECL:
9144 gen_type_die (TREE_TYPE (decl), context_die);
9145 gen_formal_parameter_die (decl, context_die);
9146 break;
9148 default:
9149 abort ();
9153 /* Write the debugging output for DECL. */
9155 void
9156 dwarf2out_decl (decl)
9157 register tree decl;
9159 register dw_die_ref context_die = comp_unit_die;
9161 if (TREE_CODE (decl) == ERROR_MARK)
9162 return;
9164 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
9165 hope that the node in question doesn't represent a function definition.
9166 If it does, then totally ignoring it is bound to screw up our count of
9167 blocks, and that it turn will completely screw up the the labels we will
9168 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9169 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
9170 own sequence numbers with them!) */
9171 if (DECL_IGNORED_P (decl))
9173 if (TREE_CODE (decl) == FUNCTION_DECL
9174 && DECL_INITIAL (decl) != NULL)
9175 abort ();
9177 return;
9180 switch (TREE_CODE (decl))
9182 case FUNCTION_DECL:
9183 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9184 builtin function. Explicit programmer-supplied declarations of
9185 these same functions should NOT be ignored however. */
9186 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
9187 return;
9189 /* What we would really like to do here is to filter out all mere
9190 file-scope declarations of file-scope functions which are never
9191 referenced later within this translation unit (and keep all of ones
9192 that *are* referenced later on) but we aren't clairvoyant, so we have
9193 no idea which functions will be referenced in the future (i.e. later
9194 on within the current translation unit). So here we just ignore all
9195 file-scope function declarations which are not also definitions. If
9196 and when the debugger needs to know something about these functions,
9197 it wil have to hunt around and find the DWARF information associated
9198 with the definition of the function. Note that we can't just check
9199 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9200 definitions and which ones represent mere declarations. We have to
9201 check `DECL_INITIAL' instead. That's because the C front-end
9202 supports some weird semantics for "extern inline" function
9203 definitions. These can get inlined within the current translation
9204 unit (an thus, we need to generate DWARF info for their abstract
9205 instances so that the DWARF info for the concrete inlined instances
9206 can have something to refer to) but the compiler never generates any
9207 out-of-lines instances of such things (despite the fact that they
9208 *are* definitions). The important point is that the C front-end
9209 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9210 to generate DWARF for them anyway. Note that the C++ front-end also
9211 plays some similar games for inline function definitions appearing
9212 within include files which also contain
9213 `#pragma interface' pragmas. */
9214 if (DECL_INITIAL (decl) == NULL_TREE)
9215 return;
9217 /* If we're a nested function, initially use a parent of NULL; if we're
9218 a plain function, this will be fixed up in decls_for_scope. If
9219 we're a method, it will be ignored, since we already have a DIE. */
9220 if (decl_function_context (decl))
9221 context_die = NULL;
9223 break;
9225 case VAR_DECL:
9226 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9227 declaration and if the declaration was never even referenced from
9228 within this entire compilation unit. We suppress these DIEs in
9229 order to save space in the .debug section (by eliminating entries
9230 which are probably useless). Note that we must not suppress
9231 block-local extern declarations (whether used or not) because that
9232 would screw-up the debugger's name lookup mechanism and cause it to
9233 miss things which really ought to be in scope at a given point. */
9234 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
9235 return;
9237 /* If we are in terse mode, don't generate any DIEs to represent any
9238 variable declarations or definitions. */
9239 if (debug_info_level <= DINFO_LEVEL_TERSE)
9240 return;
9241 break;
9243 case TYPE_DECL:
9244 /* Don't bother trying to generate any DIEs to represent any of the
9245 normal built-in types for the language we are compiling. */
9246 if (DECL_SOURCE_LINE (decl) == 0)
9248 /* OK, we need to generate one for `bool' so GDB knows what type
9249 comparisons have. */
9250 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9251 == DW_LANG_C_plus_plus)
9252 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9253 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
9255 return;
9258 /* If we are in terse mode, don't generate any DIEs for types. */
9259 if (debug_info_level <= DINFO_LEVEL_TERSE)
9260 return;
9262 /* If we're a function-scope tag, initially use a parent of NULL;
9263 this will be fixed up in decls_for_scope. */
9264 if (decl_function_context (decl))
9265 context_die = NULL;
9267 break;
9269 default:
9270 return;
9273 gen_decl_die (decl, context_die);
9274 output_pending_types_for_scope (comp_unit_die);
9277 /* Output a marker (i.e. a label) for the beginning of the generated code for
9278 a lexical block. */
9280 void
9281 dwarf2out_begin_block (blocknum)
9282 register unsigned blocknum;
9284 function_section (current_function_decl);
9285 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
9288 /* Output a marker (i.e. a label) for the end of the generated code for a
9289 lexical block. */
9291 void
9292 dwarf2out_end_block (blocknum)
9293 register unsigned blocknum;
9295 function_section (current_function_decl);
9296 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
9299 /* Output a marker (i.e. a label) at a point in the assembly code which
9300 corresponds to a given source level label. */
9302 void
9303 dwarf2out_label (insn)
9304 register rtx insn;
9306 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9308 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9310 function_section (current_function_decl);
9311 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9312 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9313 (unsigned) INSN_UID (insn));
9317 /* Lookup a filename (in the list of filenames that we know about here in
9318 dwarf2out.c) and return its "index". The index of each (known) filename is
9319 just a unique number which is associated with only that one filename.
9320 We need such numbers for the sake of generating labels
9321 (in the .debug_sfnames section) and references to those
9322 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9323 If the filename given as an argument is not found in our current list,
9324 add it to the list and assign it the next available unique index number.
9325 In order to speed up searches, we remember the index of the filename
9326 was looked up last. This handles the majority of all searches. */
9328 static unsigned
9329 lookup_filename (file_name)
9330 char *file_name;
9332 static unsigned last_file_lookup_index = 0;
9333 register unsigned i;
9335 /* Check to see if the file name that was searched on the previous call
9336 matches this file name. If so, return the index. */
9337 if (last_file_lookup_index != 0)
9338 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
9339 return last_file_lookup_index;
9341 /* Didn't match the previous lookup, search the table */
9342 for (i = 1; i < file_table_in_use; ++i)
9343 if (strcmp (file_name, file_table[i]) == 0)
9345 last_file_lookup_index = i;
9346 return i;
9349 /* Prepare to add a new table entry by making sure there is enough space in
9350 the table to do so. If not, expand the current table. */
9351 if (file_table_in_use == file_table_allocated)
9353 file_table_allocated += FILE_TABLE_INCREMENT;
9354 file_table
9355 = (char **) xrealloc (file_table,
9356 file_table_allocated * sizeof (char *));
9359 /* Add the new entry to the end of the filename table. */
9360 file_table[file_table_in_use] = xstrdup (file_name);
9361 last_file_lookup_index = file_table_in_use++;
9363 return last_file_lookup_index;
9366 /* Output a label to mark the beginning of a source code line entry
9367 and record information relating to this source line, in
9368 'line_info_table' for later output of the .debug_line section. */
9370 void
9371 dwarf2out_line (filename, line)
9372 register char *filename;
9373 register unsigned line;
9375 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9377 function_section (current_function_decl);
9379 if (DECL_SECTION_NAME (current_function_decl))
9381 register dw_separate_line_info_ref line_info;
9382 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
9383 separate_line_info_table_in_use);
9384 fputc ('\n', asm_out_file);
9386 /* expand the line info table if necessary */
9387 if (separate_line_info_table_in_use
9388 == separate_line_info_table_allocated)
9390 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9391 separate_line_info_table
9392 = (dw_separate_line_info_ref)
9393 xrealloc (separate_line_info_table,
9394 separate_line_info_table_allocated
9395 * sizeof (dw_separate_line_info_entry));
9398 /* Add the new entry at the end of the line_info_table. */
9399 line_info
9400 = &separate_line_info_table[separate_line_info_table_in_use++];
9401 line_info->dw_file_num = lookup_filename (filename);
9402 line_info->dw_line_num = line;
9403 line_info->function = current_funcdef_number;
9405 else
9407 register dw_line_info_ref line_info;
9409 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
9410 line_info_table_in_use);
9411 fputc ('\n', asm_out_file);
9413 /* Expand the line info table if necessary. */
9414 if (line_info_table_in_use == line_info_table_allocated)
9416 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9417 line_info_table
9418 = (dw_line_info_ref)
9419 xrealloc (line_info_table,
9420 (line_info_table_allocated
9421 * sizeof (dw_line_info_entry)));
9424 /* Add the new entry at the end of the line_info_table. */
9425 line_info = &line_info_table[line_info_table_in_use++];
9426 line_info->dw_file_num = lookup_filename (filename);
9427 line_info->dw_line_num = line;
9432 /* Record the beginning of a new source file, for later output
9433 of the .debug_macinfo section. At present, unimplemented. */
9435 void
9436 dwarf2out_start_source_file (filename)
9437 register char *filename;
9441 /* Record the end of a source file, for later output
9442 of the .debug_macinfo section. At present, unimplemented. */
9444 void
9445 dwarf2out_end_source_file ()
9449 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9450 the tail part of the directive line, i.e. the part which is past the
9451 initial whitespace, #, whitespace, directive-name, whitespace part. */
9453 void
9454 dwarf2out_define (lineno, buffer)
9455 register unsigned lineno;
9456 register char *buffer;
9458 static int initialized = 0;
9459 if (!initialized)
9461 dwarf2out_start_source_file (primary_filename);
9462 initialized = 1;
9466 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9467 the tail part of the directive line, i.e. the part which is past the
9468 initial whitespace, #, whitespace, directive-name, whitespace part. */
9470 void
9471 dwarf2out_undef (lineno, buffer)
9472 register unsigned lineno;
9473 register char *buffer;
9477 /* Set up for Dwarf output at the start of compilation. */
9479 void
9480 dwarf2out_init (asm_out_file, main_input_filename)
9481 register FILE *asm_out_file;
9482 register char *main_input_filename;
9484 /* Remember the name of the primary input file. */
9485 primary_filename = main_input_filename;
9487 /* Allocate the initial hunk of the file_table. */
9488 file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
9489 bzero ((char *) file_table, FILE_TABLE_INCREMENT * sizeof (char *));
9490 file_table_allocated = FILE_TABLE_INCREMENT;
9492 /* Skip the first entry - file numbers begin at 1. */
9493 file_table_in_use = 1;
9495 /* Allocate the initial hunk of the decl_die_table. */
9496 decl_die_table
9497 = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
9498 bzero ((char *) decl_die_table,
9499 DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
9500 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
9501 decl_die_table_in_use = 0;
9503 /* Allocate the initial hunk of the decl_scope_table. */
9504 decl_scope_table
9505 = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
9506 bzero ((char *) decl_scope_table,
9507 DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
9508 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
9509 decl_scope_depth = 0;
9511 /* Allocate the initial hunk of the abbrev_die_table. */
9512 abbrev_die_table
9513 = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
9514 * sizeof (dw_die_ref));
9515 bzero ((char *) abbrev_die_table,
9516 ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
9517 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
9518 /* Zero-th entry is allocated, but unused */
9519 abbrev_die_table_in_use = 1;
9521 /* Allocate the initial hunk of the line_info_table. */
9522 line_info_table
9523 = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
9524 * sizeof (dw_line_info_entry));
9525 bzero ((char *) line_info_table,
9526 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
9527 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
9528 /* Zero-th entry is allocated, but unused */
9529 line_info_table_in_use = 1;
9531 /* Generate the initial DIE for the .debug section. Note that the (string)
9532 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9533 will (typically) be a relative pathname and that this pathname should be
9534 taken as being relative to the directory from which the compiler was
9535 invoked when the given (base) source file was compiled. */
9536 gen_compile_unit_die (main_input_filename);
9538 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
9541 /* Output stuff that dwarf requires at the end of every file,
9542 and generate the DWARF-2 debugging info. */
9544 void
9545 dwarf2out_finish ()
9547 limbo_die_node *node, *next_node;
9548 dw_die_ref die;
9549 dw_attr_ref a;
9551 /* Traverse the limbo die list, and add parent/child links. The only
9552 dies without parents that should be here are concrete instances of
9553 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9554 For concrete instances, we can get the parent die from the abstract
9555 instance. */
9556 for (node = limbo_die_list; node; node = next_node)
9558 next_node = node->next;
9559 die = node->die;
9561 if (die->die_parent == NULL)
9563 a = get_AT (die, DW_AT_abstract_origin);
9564 if (a)
9565 add_child_die (a->dw_attr_val.v.val_die_ref->die_parent, die);
9566 else if (die == comp_unit_die)
9568 else
9569 abort ();
9571 free (node);
9574 /* Traverse the DIE tree and add sibling attributes to those DIE's
9575 that have children. */
9576 add_sibling_attributes (comp_unit_die);
9578 /* Output a terminator label for the .text section. */
9579 fputc ('\n', asm_out_file);
9580 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9581 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
9583 #if 0
9584 /* Output a terminator label for the .data section. */
9585 fputc ('\n', asm_out_file);
9586 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
9587 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
9589 /* Output a terminator label for the .bss section. */
9590 fputc ('\n', asm_out_file);
9591 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
9592 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
9593 #endif
9595 /* Output the source line correspondence table. */
9596 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
9598 fputc ('\n', asm_out_file);
9599 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9600 output_line_info ();
9602 /* We can only use the low/high_pc attributes if all of the code
9603 was in .text. */
9604 if (separate_line_info_table_in_use == 0)
9606 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION);
9607 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
9610 add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, DEBUG_LINE_SECTION);
9613 /* Output the abbreviation table. */
9614 fputc ('\n', asm_out_file);
9615 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9616 build_abbrev_table (comp_unit_die);
9617 output_abbrev_section ();
9619 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9620 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9621 calc_die_sizes (comp_unit_die);
9623 /* Output debugging information. */
9624 fputc ('\n', asm_out_file);
9625 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9626 output_compilation_unit_header ();
9627 output_die (comp_unit_die);
9629 if (pubname_table_in_use)
9631 /* Output public names table. */
9632 fputc ('\n', asm_out_file);
9633 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
9634 output_pubnames ();
9637 if (fde_table_in_use)
9639 /* Output the address range information. */
9640 fputc ('\n', asm_out_file);
9641 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
9642 output_aranges ();
9645 #endif /* DWARF2_DEBUGGING_INFO */