* sh.h (STRUCT_VALUE): Just 0 for TARGET_HITACHI.
[official-gcc.git] / gcc / dwarf2out.c
blobc493d54f572624d3eff7a9a689eb41fba27e9a9f
1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Eliminate duplicates by putting common info in a separate section
27 to be collected by the linker and referring to it with
28 DW_FORM_ref_addr.
29 Emit .debug_line header even when there are no functions, since
30 the file numbers are used by .debug_info. Alternately, leave
31 out locations for types and decls.
32 Avoid talking about ctors and op= for PODs.
33 Factor out common prologue sequences into multiple CIEs. */
35 /* The first part of this file deals with the DWARF 2 frame unwind
36 information, which is also used by the GCC efficient exception handling
37 mechanism. The second part, controlled only by an #ifdef
38 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
39 information. */
41 #include "config.h"
42 #include "system.h"
43 #include "defaults.h"
44 #include "tree.h"
45 #include "flags.h"
46 #include "rtl.h"
47 #include "hard-reg-set.h"
48 #include "regs.h"
49 #include "insn-config.h"
50 #include "reload.h"
51 #include "output.h"
52 #include "expr.h"
53 #include "except.h"
54 #include "dwarf2.h"
55 #include "dwarf2out.h"
56 #include "toplev.h"
57 #include "varray.h"
58 #include "ggc.h"
59 #include "tm_p.h"
61 /* We cannot use <assert.h> in GCC source, since that would include
62 GCC's assert.h, which may not be compatible with the host compiler. */
63 #undef assert
64 #ifdef NDEBUG
65 # define assert(e)
66 #else
67 # define assert(e) do { if (! (e)) abort (); } while (0)
68 #endif
70 /* Decide whether we want to emit frame unwind information for the current
71 translation unit. */
73 int
74 dwarf2out_do_frame ()
76 return (write_symbols == DWARF2_DEBUG
77 #ifdef DWARF2_FRAME_INFO
78 || DWARF2_FRAME_INFO
79 #endif
80 #ifdef DWARF2_UNWIND_INFO
81 || flag_unwind_tables
82 || (flag_exceptions && ! exceptions_via_longjmp)
83 #endif
87 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
89 /* How to start an assembler comment. */
90 #ifndef ASM_COMMENT_START
91 #define ASM_COMMENT_START ";#"
92 #endif
94 typedef struct dw_cfi_struct *dw_cfi_ref;
95 typedef struct dw_fde_struct *dw_fde_ref;
96 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
98 /* Call frames are described using a sequence of Call Frame
99 Information instructions. The register number, offset
100 and address fields are provided as possible operands;
101 their use is selected by the opcode field. */
103 typedef union dw_cfi_oprnd_struct
105 unsigned long dw_cfi_reg_num;
106 long int dw_cfi_offset;
107 char *dw_cfi_addr;
109 dw_cfi_oprnd;
111 typedef struct dw_cfi_struct
113 dw_cfi_ref dw_cfi_next;
114 enum dwarf_call_frame_info dw_cfi_opc;
115 dw_cfi_oprnd dw_cfi_oprnd1;
116 dw_cfi_oprnd dw_cfi_oprnd2;
118 dw_cfi_node;
120 /* All call frame descriptions (FDE's) in the GCC generated DWARF
121 refer to a single Common Information Entry (CIE), defined at
122 the beginning of the .debug_frame section. This used of a single
123 CIE obviates the need to keep track of multiple CIE's
124 in the DWARF generation routines below. */
126 typedef struct dw_fde_struct
128 char *dw_fde_begin;
129 char *dw_fde_current_label;
130 char *dw_fde_end;
131 dw_cfi_ref dw_fde_cfi;
132 int nothrow;
134 dw_fde_node;
136 /* Maximum size (in bytes) of an artificially generated label. */
137 #define MAX_ARTIFICIAL_LABEL_BYTES 30
139 /* Make sure we know the sizes of the various types dwarf can describe. These
140 are only defaults. If the sizes are different for your target, you should
141 override these values by defining the appropriate symbols in your tm.h
142 file. */
144 #ifndef CHAR_TYPE_SIZE
145 #define CHAR_TYPE_SIZE BITS_PER_UNIT
146 #endif
147 #ifndef PTR_SIZE
148 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
149 #endif
151 /* The size in bytes of a DWARF field indicating an offset or length
152 relative to a debug info section, specified to be 4 bytes in the DWARF-2
153 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
155 #ifndef DWARF_OFFSET_SIZE
156 #define DWARF_OFFSET_SIZE 4
157 #endif
159 #define DWARF_VERSION 2
161 /* Round SIZE up to the nearest BOUNDARY. */
162 #define DWARF_ROUND(SIZE,BOUNDARY) \
163 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
165 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
166 #ifdef STACK_GROWS_DOWNWARD
167 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
168 #else
169 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
170 #endif
172 /* A pointer to the base of a table that contains frame description
173 information for each routine. */
174 static dw_fde_ref fde_table;
176 /* Number of elements currently allocated for fde_table. */
177 static unsigned fde_table_allocated;
179 /* Number of elements in fde_table currently in use. */
180 static unsigned fde_table_in_use;
182 /* Size (in elements) of increments by which we may expand the
183 fde_table. */
184 #define FDE_TABLE_INCREMENT 256
186 /* A list of call frame insns for the CIE. */
187 static dw_cfi_ref cie_cfi_head;
189 /* The number of the current function definition for which debugging
190 information is being generated. These numbers range from 1 up to the
191 maximum number of function definitions contained within the current
192 compilation unit. These numbers are used to create unique label id's
193 unique to each function definition. */
194 static unsigned current_funcdef_number = 0;
196 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
197 attribute that accelerates the lookup of the FDE associated
198 with the subprogram. This variable holds the table index of the FDE
199 associated with the current function (body) definition. */
200 static unsigned current_funcdef_fde;
202 /* Forward declarations for functions defined in this file. */
204 static char *stripattributes PARAMS ((const char *));
205 static const char *dwarf_cfi_name PARAMS ((unsigned));
206 static dw_cfi_ref new_cfi PARAMS ((void));
207 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
208 static unsigned long size_of_uleb128 PARAMS ((unsigned long));
209 static unsigned long size_of_sleb128 PARAMS ((long));
210 static void output_uleb128 PARAMS ((unsigned long));
211 static void output_sleb128 PARAMS ((long));
212 static void add_fde_cfi PARAMS ((char *, dw_cfi_ref));
213 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, unsigned long *,
214 long *));
215 static void lookup_cfa PARAMS ((unsigned long *, long *));
216 static void reg_save PARAMS ((char *, unsigned, unsigned,
217 long));
218 static void initial_return_save PARAMS ((rtx));
219 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
220 static void output_call_frame_info PARAMS ((int));
221 static unsigned int reg_number PARAMS ((rtx));
222 static void dwarf2out_stack_adjust PARAMS ((rtx));
223 static void dwarf2out_frame_debug_expr PARAMS ((rtx, char *));
225 /* Definitions of defaults for assembler-dependent names of various
226 pseudo-ops and section names.
227 Theses may be overridden in the tm.h file (if necessary) for a particular
228 assembler. */
230 #ifdef OBJECT_FORMAT_ELF
231 #ifndef UNALIGNED_SHORT_ASM_OP
232 #define UNALIGNED_SHORT_ASM_OP ".2byte"
233 #endif
234 #ifndef UNALIGNED_INT_ASM_OP
235 #define UNALIGNED_INT_ASM_OP ".4byte"
236 #endif
237 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
238 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
239 #endif
240 #endif /* OBJECT_FORMAT_ELF */
242 #ifndef ASM_BYTE_OP
243 #define ASM_BYTE_OP ".byte"
244 #endif
246 /* Data and reference forms for relocatable data. */
247 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
248 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
250 /* Pseudo-op for defining a new section. */
251 #ifndef SECTION_ASM_OP
252 #define SECTION_ASM_OP ".section"
253 #endif
255 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
256 print the SECTION_ASM_OP and the section name. The default here works for
257 almost all svr4 assemblers, except for the sparc, where the section name
258 must be enclosed in double quotes. (See sparcv4.h). */
259 #ifndef SECTION_FORMAT
260 #ifdef PUSHSECTION_FORMAT
261 #define SECTION_FORMAT PUSHSECTION_FORMAT
262 #else
263 #define SECTION_FORMAT "\t%s\t%s\n"
264 #endif
265 #endif
267 #ifndef FRAME_SECTION
268 #define FRAME_SECTION ".debug_frame"
269 #endif
271 #ifndef FUNC_BEGIN_LABEL
272 #define FUNC_BEGIN_LABEL "LFB"
273 #endif
274 #ifndef FUNC_END_LABEL
275 #define FUNC_END_LABEL "LFE"
276 #endif
277 #define CIE_AFTER_SIZE_LABEL "LSCIE"
278 #define CIE_END_LABEL "LECIE"
279 #define CIE_LENGTH_LABEL "LLCIE"
280 #define FDE_AFTER_SIZE_LABEL "LSFDE"
281 #define FDE_END_LABEL "LEFDE"
282 #define FDE_LENGTH_LABEL "LLFDE"
284 /* Definitions of defaults for various types of primitive assembly language
285 output operations. These may be overridden from within the tm.h file,
286 but typically, that is unnecessary. */
288 #ifndef ASM_OUTPUT_SECTION
289 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
290 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
291 #endif
293 #ifndef ASM_OUTPUT_DWARF_DATA1
294 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
295 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
296 #endif
298 #ifndef ASM_OUTPUT_DWARF_DELTA1
299 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
300 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
301 assemble_name (FILE, LABEL1); \
302 fprintf (FILE, "-"); \
303 assemble_name (FILE, LABEL2); \
304 } while (0)
305 #endif
307 #ifdef UNALIGNED_INT_ASM_OP
309 #ifndef UNALIGNED_OFFSET_ASM_OP
310 #define UNALIGNED_OFFSET_ASM_OP \
311 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
312 #endif
314 #ifndef UNALIGNED_WORD_ASM_OP
315 #define UNALIGNED_WORD_ASM_OP \
316 ((PTR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : \
317 ((PTR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP : UNALIGNED_INT_ASM_OP))
318 #endif
320 #ifndef ASM_OUTPUT_DWARF_DELTA2
321 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
322 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
323 assemble_name (FILE, LABEL1); \
324 fprintf (FILE, "-"); \
325 assemble_name (FILE, LABEL2); \
326 } while (0)
327 #endif
329 #ifndef ASM_OUTPUT_DWARF_DELTA4
330 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
331 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
332 assemble_name (FILE, LABEL1); \
333 fprintf (FILE, "-"); \
334 assemble_name (FILE, LABEL2); \
335 } while (0)
336 #endif
338 #ifndef ASM_OUTPUT_DWARF_DELTA
339 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
340 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
341 assemble_name (FILE, LABEL1); \
342 fprintf (FILE, "-"); \
343 assemble_name (FILE, LABEL2); \
344 } while (0)
345 #endif
347 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
348 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
349 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
350 assemble_name (FILE, LABEL1); \
351 fprintf (FILE, "-"); \
352 assemble_name (FILE, LABEL2); \
353 } while (0)
354 #endif
356 #ifndef ASM_OUTPUT_DWARF_ADDR
357 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
358 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
359 assemble_name (FILE, LABEL); \
360 } while (0)
361 #endif
363 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
364 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
365 do { \
366 fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
367 output_addr_const ((FILE), (RTX)); \
368 } while (0)
369 #endif
371 #ifndef ASM_OUTPUT_DWARF_OFFSET4
372 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
373 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
374 assemble_name (FILE, LABEL); \
375 } while (0)
376 #endif
378 #ifndef ASM_OUTPUT_DWARF_OFFSET
379 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
380 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
381 assemble_name (FILE, LABEL); \
382 } while (0)
383 #endif
385 #ifndef ASM_OUTPUT_DWARF_DATA2
386 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
387 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
388 #endif
390 #ifndef ASM_OUTPUT_DWARF_DATA4
391 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
392 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
393 #endif
395 #ifndef ASM_OUTPUT_DWARF_DATA
396 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
397 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
398 (unsigned long) (VALUE))
399 #endif
401 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
402 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
403 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
404 (unsigned long) (VALUE))
405 #endif
407 #ifndef ASM_OUTPUT_DWARF_DATA8
408 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
409 do { \
410 if (WORDS_BIG_ENDIAN) \
412 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
413 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
415 else \
417 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
418 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
420 } while (0)
421 #endif
423 #else /* UNALIGNED_INT_ASM_OP */
425 /* We don't have unaligned support, let's hope the normal output works for
426 .debug_frame. */
428 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
429 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), PTR_SIZE, 1)
431 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
432 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
434 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
435 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
437 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
438 assemble_integer (gen_rtx_MINUS (HImode, \
439 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
440 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
441 2, 1)
443 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
444 assemble_integer (gen_rtx_MINUS (SImode, \
445 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
446 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
447 4, 1)
449 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
450 assemble_integer (gen_rtx_MINUS (Pmode, \
451 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
452 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
453 PTR_SIZE, 1)
455 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
456 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
458 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
459 assemble_integer (GEN_INT (VALUE), 4, 1)
461 #endif /* UNALIGNED_INT_ASM_OP */
463 #ifdef SET_ASM_OP
464 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
465 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
466 do { \
467 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
468 assemble_name (FILE, SY); \
469 fputc (',', FILE); \
470 assemble_name (FILE, HI); \
471 fputc ('-', FILE); \
472 assemble_name (FILE, LO); \
473 } while (0)
474 #endif
475 #endif /* SET_ASM_OP */
477 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
478 newline is produced. When flag_debug_asm is asserted, we add commentary
479 at the end of the line, so we must avoid output of a newline here. */
480 #ifndef ASM_OUTPUT_DWARF_STRING
481 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
482 do { \
483 register int slen = strlen(P); \
484 register const char *p = (P); \
485 register int i; \
486 fprintf (FILE, "\t.ascii \""); \
487 for (i = 0; i < slen; i++) \
489 register int c = p[i]; \
490 if (c == '\"' || c == '\\') \
491 putc ('\\', FILE); \
492 if (ISPRINT(c)) \
493 putc (c, FILE); \
494 else \
496 fprintf (FILE, "\\%o", c); \
499 fprintf (FILE, "\\0\""); \
501 while (0)
502 #endif
504 /* The DWARF 2 CFA column which tracks the return address. Normally this
505 is the column for PC, or the first column after all of the hard
506 registers. */
507 #ifndef DWARF_FRAME_RETURN_COLUMN
508 #ifdef PC_REGNUM
509 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
510 #else
511 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
512 #endif
513 #endif
515 /* The mapping from gcc register number to DWARF 2 CFA column number. By
516 default, we just provide columns for all registers. */
517 #ifndef DWARF_FRAME_REGNUM
518 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
519 #endif
521 /* Hook used by __throw. */
524 expand_builtin_dwarf_fp_regnum ()
526 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
529 /* The offset from the incoming value of %sp to the top of the stack frame
530 for the current function. */
531 #ifndef INCOMING_FRAME_SP_OFFSET
532 #define INCOMING_FRAME_SP_OFFSET 0
533 #endif
535 /* Return a pointer to a copy of the section string name S with all
536 attributes stripped off, and an asterisk prepended (for assemble_name). */
538 static inline char *
539 stripattributes (s)
540 const char *s;
542 char *stripped = xmalloc (strlen (s) + 2);
543 char *p = stripped;
545 *p++ = '*';
547 while (*s && *s != ',')
548 *p++ = *s++;
550 *p = '\0';
551 return stripped;
554 /* Return the register number described by a given RTL node. */
556 static unsigned int
557 reg_number (rtl)
558 register rtx rtl;
560 register unsigned regno = REGNO (rtl);
562 if (regno >= FIRST_PSEUDO_REGISTER)
564 warning ("internal regno botch: regno = %d\n", regno);
565 regno = 0;
568 regno = DBX_REGISTER_NUMBER (regno);
569 return regno;
572 /* Generate code to initialize the register size table. */
574 void
575 expand_builtin_init_dwarf_reg_sizes (address)
576 tree address;
578 int i;
579 enum machine_mode mode = TYPE_MODE (char_type_node);
580 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
581 rtx mem = gen_rtx_MEM (mode, addr);
583 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
585 int offset = i * GET_MODE_SIZE (mode);
586 int size = GET_MODE_SIZE (reg_raw_mode[i]);
588 emit_move_insn (change_address (mem, mode,
589 plus_constant (addr, offset)),
590 GEN_INT (size));
594 /* Convert a DWARF call frame info. operation to its string name */
596 static const char *
597 dwarf_cfi_name (cfi_opc)
598 register unsigned cfi_opc;
600 switch (cfi_opc)
602 case DW_CFA_advance_loc:
603 return "DW_CFA_advance_loc";
604 case DW_CFA_offset:
605 return "DW_CFA_offset";
606 case DW_CFA_restore:
607 return "DW_CFA_restore";
608 case DW_CFA_nop:
609 return "DW_CFA_nop";
610 case DW_CFA_set_loc:
611 return "DW_CFA_set_loc";
612 case DW_CFA_advance_loc1:
613 return "DW_CFA_advance_loc1";
614 case DW_CFA_advance_loc2:
615 return "DW_CFA_advance_loc2";
616 case DW_CFA_advance_loc4:
617 return "DW_CFA_advance_loc4";
618 case DW_CFA_offset_extended:
619 return "DW_CFA_offset_extended";
620 case DW_CFA_restore_extended:
621 return "DW_CFA_restore_extended";
622 case DW_CFA_undefined:
623 return "DW_CFA_undefined";
624 case DW_CFA_same_value:
625 return "DW_CFA_same_value";
626 case DW_CFA_register:
627 return "DW_CFA_register";
628 case DW_CFA_remember_state:
629 return "DW_CFA_remember_state";
630 case DW_CFA_restore_state:
631 return "DW_CFA_restore_state";
632 case DW_CFA_def_cfa:
633 return "DW_CFA_def_cfa";
634 case DW_CFA_def_cfa_register:
635 return "DW_CFA_def_cfa_register";
636 case DW_CFA_def_cfa_offset:
637 return "DW_CFA_def_cfa_offset";
639 /* SGI/MIPS specific */
640 case DW_CFA_MIPS_advance_loc8:
641 return "DW_CFA_MIPS_advance_loc8";
643 /* GNU extensions */
644 case DW_CFA_GNU_window_save:
645 return "DW_CFA_GNU_window_save";
646 case DW_CFA_GNU_args_size:
647 return "DW_CFA_GNU_args_size";
648 case DW_CFA_GNU_negative_offset_extended:
649 return "DW_CFA_GNU_negative_offset_extended";
651 default:
652 return "DW_CFA_<unknown>";
656 /* Return a pointer to a newly allocated Call Frame Instruction. */
658 static inline dw_cfi_ref
659 new_cfi ()
661 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
663 cfi->dw_cfi_next = NULL;
664 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
665 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
667 return cfi;
670 /* Add a Call Frame Instruction to list of instructions. */
672 static inline void
673 add_cfi (list_head, cfi)
674 register dw_cfi_ref *list_head;
675 register dw_cfi_ref cfi;
677 register dw_cfi_ref *p;
679 /* Find the end of the chain. */
680 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
683 *p = cfi;
686 /* Generate a new label for the CFI info to refer to. */
688 char *
689 dwarf2out_cfi_label ()
691 static char label[20];
692 static unsigned long label_num = 0;
694 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
695 ASM_OUTPUT_LABEL (asm_out_file, label);
697 return label;
700 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
701 or to the CIE if LABEL is NULL. */
703 static void
704 add_fde_cfi (label, cfi)
705 register char *label;
706 register dw_cfi_ref cfi;
708 if (label)
710 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
712 if (*label == 0)
713 label = dwarf2out_cfi_label ();
715 if (fde->dw_fde_current_label == NULL
716 || strcmp (label, fde->dw_fde_current_label) != 0)
718 register dw_cfi_ref xcfi;
720 fde->dw_fde_current_label = label = xstrdup (label);
722 /* Set the location counter to the new label. */
723 xcfi = new_cfi ();
724 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
725 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
726 add_cfi (&fde->dw_fde_cfi, xcfi);
729 add_cfi (&fde->dw_fde_cfi, cfi);
732 else
733 add_cfi (&cie_cfi_head, cfi);
736 /* Subroutine of lookup_cfa. */
738 static inline void
739 lookup_cfa_1 (cfi, regp, offsetp)
740 register dw_cfi_ref cfi;
741 register unsigned long *regp;
742 register long *offsetp;
744 switch (cfi->dw_cfi_opc)
746 case DW_CFA_def_cfa_offset:
747 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
748 break;
749 case DW_CFA_def_cfa_register:
750 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
751 break;
752 case DW_CFA_def_cfa:
753 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
754 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
755 break;
756 default:
757 break;
761 /* Find the previous value for the CFA. */
763 static void
764 lookup_cfa (regp, offsetp)
765 register unsigned long *regp;
766 register long *offsetp;
768 register dw_cfi_ref cfi;
770 *regp = (unsigned long) -1;
771 *offsetp = 0;
773 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
774 lookup_cfa_1 (cfi, regp, offsetp);
776 if (fde_table_in_use)
778 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
779 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
780 lookup_cfa_1 (cfi, regp, offsetp);
784 /* The current rule for calculating the DWARF2 canonical frame address. */
785 static unsigned long cfa_reg;
786 static long cfa_offset;
788 /* The register used for saving registers to the stack, and its offset
789 from the CFA. */
790 static unsigned cfa_store_reg;
791 static long cfa_store_offset;
793 /* The running total of the size of arguments pushed onto the stack. */
794 static long args_size;
796 /* The last args_size we actually output. */
797 static long old_args_size;
799 /* Entry point to update the canonical frame address (CFA).
800 LABEL is passed to add_fde_cfi. The value of CFA is now to be
801 calculated from REG+OFFSET. */
803 void
804 dwarf2out_def_cfa (label, reg, offset)
805 register char *label;
806 register unsigned reg;
807 register long offset;
809 register dw_cfi_ref cfi;
810 unsigned long old_reg;
811 long old_offset;
813 cfa_reg = reg;
814 cfa_offset = offset;
815 if (cfa_store_reg == reg)
816 cfa_store_offset = offset;
818 reg = DWARF_FRAME_REGNUM (reg);
819 lookup_cfa (&old_reg, &old_offset);
821 if (reg == old_reg && offset == old_offset)
822 return;
824 cfi = new_cfi ();
826 if (reg == old_reg)
828 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
829 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
832 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
833 else if (offset == old_offset && old_reg != (unsigned long) -1)
835 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
836 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
838 #endif
840 else
842 cfi->dw_cfi_opc = DW_CFA_def_cfa;
843 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
844 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
847 add_fde_cfi (label, cfi);
850 /* Add the CFI for saving a register. REG is the CFA column number.
851 LABEL is passed to add_fde_cfi.
852 If SREG is -1, the register is saved at OFFSET from the CFA;
853 otherwise it is saved in SREG. */
855 static void
856 reg_save (label, reg, sreg, offset)
857 register char * label;
858 register unsigned reg;
859 register unsigned sreg;
860 register long offset;
862 register dw_cfi_ref cfi = new_cfi ();
864 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
866 /* The following comparison is correct. -1 is used to indicate that
867 the value isn't a register number. */
868 if (sreg == (unsigned int) -1)
870 if (reg & ~0x3f)
871 /* The register number won't fit in 6 bits, so we have to use
872 the long form. */
873 cfi->dw_cfi_opc = DW_CFA_offset_extended;
874 else
875 cfi->dw_cfi_opc = DW_CFA_offset;
877 offset /= DWARF_CIE_DATA_ALIGNMENT;
878 if (offset < 0)
880 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
881 offset = -offset;
883 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
885 else if (sreg == reg)
886 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
887 return;
888 else
890 cfi->dw_cfi_opc = DW_CFA_register;
891 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
894 add_fde_cfi (label, cfi);
897 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
898 This CFI tells the unwinder that it needs to restore the window registers
899 from the previous frame's window save area.
901 ??? Perhaps we should note in the CIE where windows are saved (instead of
902 assuming 0(cfa)) and what registers are in the window. */
904 void
905 dwarf2out_window_save (label)
906 register char * label;
908 register dw_cfi_ref cfi = new_cfi ();
909 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
910 add_fde_cfi (label, cfi);
913 /* Add a CFI to update the running total of the size of arguments
914 pushed onto the stack. */
916 void
917 dwarf2out_args_size (label, size)
918 char *label;
919 long size;
921 register dw_cfi_ref cfi;
923 if (size == old_args_size)
924 return;
925 old_args_size = size;
927 cfi = new_cfi ();
928 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
929 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
930 add_fde_cfi (label, cfi);
933 /* Entry point for saving a register to the stack. REG is the GCC register
934 number. LABEL and OFFSET are passed to reg_save. */
936 void
937 dwarf2out_reg_save (label, reg, offset)
938 register char * label;
939 register unsigned reg;
940 register long offset;
942 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
945 /* Entry point for saving the return address in the stack.
946 LABEL and OFFSET are passed to reg_save. */
948 void
949 dwarf2out_return_save (label, offset)
950 register char * label;
951 register long offset;
953 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
956 /* Entry point for saving the return address in a register.
957 LABEL and SREG are passed to reg_save. */
959 void
960 dwarf2out_return_reg (label, sreg)
961 register char * label;
962 register unsigned sreg;
964 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
967 /* Record the initial position of the return address. RTL is
968 INCOMING_RETURN_ADDR_RTX. */
970 static void
971 initial_return_save (rtl)
972 register rtx rtl;
974 unsigned int reg = (unsigned int) -1;
975 long offset = 0;
977 switch (GET_CODE (rtl))
979 case REG:
980 /* RA is in a register. */
981 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
982 break;
983 case MEM:
984 /* RA is on the stack. */
985 rtl = XEXP (rtl, 0);
986 switch (GET_CODE (rtl))
988 case REG:
989 if (REGNO (rtl) != STACK_POINTER_REGNUM)
990 abort ();
991 offset = 0;
992 break;
993 case PLUS:
994 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
995 abort ();
996 offset = INTVAL (XEXP (rtl, 1));
997 break;
998 case MINUS:
999 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1000 abort ();
1001 offset = -INTVAL (XEXP (rtl, 1));
1002 break;
1003 default:
1004 abort ();
1006 break;
1007 case PLUS:
1008 /* The return address is at some offset from any value we can
1009 actually load. For instance, on the SPARC it is in %i7+8. Just
1010 ignore the offset for now; it doesn't matter for unwinding frames. */
1011 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1012 abort ();
1013 initial_return_save (XEXP (rtl, 0));
1014 return;
1015 default:
1016 abort ();
1019 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset);
1022 /* Check INSN to see if it looks like a push or a stack adjustment, and
1023 make a note of it if it does. EH uses this information to find out how
1024 much extra space it needs to pop off the stack. */
1026 static void
1027 dwarf2out_stack_adjust (insn)
1028 rtx insn;
1030 long offset;
1031 char *label;
1033 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1035 /* Extract the size of the args from the CALL rtx itself. */
1037 insn = PATTERN (insn);
1038 if (GET_CODE (insn) == PARALLEL)
1039 insn = XVECEXP (insn, 0, 0);
1040 if (GET_CODE (insn) == SET)
1041 insn = SET_SRC (insn);
1042 assert (GET_CODE (insn) == CALL);
1043 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1044 return;
1047 /* If only calls can throw, and we have a frame pointer,
1048 save up adjustments until we see the CALL_INSN. */
1049 else if (! asynchronous_exceptions
1050 && cfa_reg != STACK_POINTER_REGNUM)
1051 return;
1053 if (GET_CODE (insn) == BARRIER)
1055 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1056 the compiler will have already emitted a stack adjustment, but
1057 doesn't bother for calls to noreturn functions. */
1058 #ifdef STACK_GROWS_DOWNWARD
1059 offset = -args_size;
1060 #else
1061 offset = args_size;
1062 #endif
1064 else if (GET_CODE (PATTERN (insn)) == SET)
1066 rtx src, dest;
1067 enum rtx_code code;
1069 insn = PATTERN (insn);
1070 src = SET_SRC (insn);
1071 dest = SET_DEST (insn);
1073 if (dest == stack_pointer_rtx)
1075 /* (set (reg sp) (plus (reg sp) (const_int))) */
1076 code = GET_CODE (src);
1077 if (! (code == PLUS || code == MINUS)
1078 || XEXP (src, 0) != stack_pointer_rtx
1079 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1080 return;
1082 offset = INTVAL (XEXP (src, 1));
1084 else if (GET_CODE (dest) == MEM)
1086 /* (set (mem (pre_dec (reg sp))) (foo)) */
1087 src = XEXP (dest, 0);
1088 code = GET_CODE (src);
1090 if (! (code == PRE_DEC || code == PRE_INC)
1091 || XEXP (src, 0) != stack_pointer_rtx)
1092 return;
1094 offset = GET_MODE_SIZE (GET_MODE (dest));
1096 else
1097 return;
1099 if (code == PLUS || code == PRE_INC)
1100 offset = -offset;
1102 else
1103 return;
1105 if (offset == 0)
1106 return;
1108 if (cfa_reg == STACK_POINTER_REGNUM)
1109 cfa_offset += offset;
1111 #ifndef STACK_GROWS_DOWNWARD
1112 offset = -offset;
1113 #endif
1114 args_size += offset;
1115 if (args_size < 0)
1116 args_size = 0;
1118 label = dwarf2out_cfi_label ();
1119 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1120 dwarf2out_args_size (label, args_size);
1123 /* A temporary register used in adjusting SP or setting up the store_reg. */
1124 static unsigned cfa_temp_reg;
1126 /* A temporary value used in adjusting SP or setting up the store_reg. */
1127 static long cfa_temp_value;
1129 /* Record call frame debugging information for an expression, which either
1130 sets SP or FP (adjusting how we calculate the frame address) or saves a
1131 register to the stack. */
1133 static void
1134 dwarf2out_frame_debug_expr (expr, label)
1135 rtx expr;
1136 char *label;
1138 rtx src, dest;
1139 long offset;
1141 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1142 the PARALLEL independantly. The first element is always processed if
1143 it is a SET. This is for backward compatability. Other elements
1144 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1145 flag is set in them. */
1147 if (GET_CODE (expr) == PARALLEL)
1149 int par_index;
1150 int limit = XVECLEN (expr, 0);
1152 for (par_index = 0; par_index < limit; par_index++)
1154 rtx x = XVECEXP (expr, 0, par_index);
1156 if (GET_CODE (x) == SET &&
1157 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1158 dwarf2out_frame_debug_expr (x, label);
1160 return;
1163 if (GET_CODE (expr) != SET)
1164 abort ();
1166 src = SET_SRC (expr);
1167 dest = SET_DEST (expr);
1169 switch (GET_CODE (dest))
1171 case REG:
1172 /* Update the CFA rule wrt SP or FP. Make sure src is
1173 relative to the current CFA register. */
1174 switch (GET_CODE (src))
1176 /* Setting FP from SP. */
1177 case REG:
1178 if (cfa_reg != (unsigned) REGNO (src))
1179 abort ();
1181 /* We used to require that dest be either SP or FP, but the
1182 ARM copies SP to a temporary register, and from there to
1183 FP. So we just rely on the backends to only set
1184 RTX_FRAME_RELATED_P on appropriate insns. */
1185 cfa_reg = REGNO (dest);
1186 break;
1188 case PLUS:
1189 case MINUS:
1190 if (dest == stack_pointer_rtx)
1192 /* Adjusting SP. */
1193 switch (GET_CODE (XEXP (src, 1)))
1195 case CONST_INT:
1196 offset = INTVAL (XEXP (src, 1));
1197 break;
1198 case REG:
1199 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1200 abort ();
1201 offset = cfa_temp_value;
1202 break;
1203 default:
1204 abort ();
1207 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1209 /* Restoring SP from FP in the epilogue. */
1210 if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1211 abort ();
1212 cfa_reg = STACK_POINTER_REGNUM;
1214 else if (XEXP (src, 0) != stack_pointer_rtx)
1215 abort ();
1217 if (GET_CODE (src) == PLUS)
1218 offset = -offset;
1219 if (cfa_reg == STACK_POINTER_REGNUM)
1220 cfa_offset += offset;
1221 if (cfa_store_reg == STACK_POINTER_REGNUM)
1222 cfa_store_offset += offset;
1224 else if (dest == hard_frame_pointer_rtx)
1226 /* Either setting the FP from an offset of the SP,
1227 or adjusting the FP */
1228 if (! frame_pointer_needed)
1229 abort ();
1231 if (GET_CODE (XEXP (src, 0)) == REG
1232 && (unsigned) REGNO (XEXP (src, 0)) == cfa_reg
1233 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1235 offset = INTVAL (XEXP (src, 1));
1236 if (GET_CODE (src) == PLUS)
1237 offset = -offset;
1238 cfa_offset += offset;
1239 cfa_reg = HARD_FRAME_POINTER_REGNUM;
1241 else
1242 abort();
1244 else
1246 if (GET_CODE (src) != PLUS
1247 || XEXP (src, 1) != stack_pointer_rtx)
1248 abort ();
1249 if (GET_CODE (XEXP (src, 0)) != REG
1250 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1251 abort ();
1252 if (cfa_reg != STACK_POINTER_REGNUM)
1253 abort ();
1254 cfa_store_reg = REGNO (dest);
1255 cfa_store_offset = cfa_offset - cfa_temp_value;
1257 break;
1259 case CONST_INT:
1260 cfa_temp_reg = REGNO (dest);
1261 cfa_temp_value = INTVAL (src);
1262 break;
1264 case IOR:
1265 if (GET_CODE (XEXP (src, 0)) != REG
1266 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1267 || (unsigned) REGNO (dest) != cfa_temp_reg
1268 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1269 abort ();
1270 cfa_temp_value |= INTVAL (XEXP (src, 1));
1271 break;
1273 default:
1274 abort ();
1276 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1277 break;
1279 case MEM:
1280 /* Saving a register to the stack. Make sure dest is relative to the
1281 CFA register. */
1282 if (GET_CODE (src) != REG)
1283 abort ();
1284 switch (GET_CODE (XEXP (dest, 0)))
1286 /* With a push. */
1287 case PRE_INC:
1288 case PRE_DEC:
1289 offset = GET_MODE_SIZE (GET_MODE (dest));
1290 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1291 offset = -offset;
1293 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1294 || cfa_store_reg != STACK_POINTER_REGNUM)
1295 abort ();
1296 cfa_store_offset += offset;
1297 if (cfa_reg == STACK_POINTER_REGNUM)
1298 cfa_offset = cfa_store_offset;
1300 offset = -cfa_store_offset;
1301 break;
1303 /* With an offset. */
1304 case PLUS:
1305 case MINUS:
1306 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1307 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1308 offset = -offset;
1310 if (cfa_store_reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1311 abort ();
1312 offset -= cfa_store_offset;
1313 break;
1315 /* Without an offset. */
1316 case REG:
1317 if (cfa_store_reg != REGNO (XEXP (dest, 0)))
1318 abort();
1319 offset = -cfa_store_offset;
1320 break;
1322 default:
1323 abort ();
1325 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1326 dwarf2out_reg_save (label, REGNO (src), offset);
1327 break;
1329 default:
1330 abort ();
1335 /* Record call frame debugging information for INSN, which either
1336 sets SP or FP (adjusting how we calculate the frame address) or saves a
1337 register to the stack. If INSN is NULL_RTX, initialize our state. */
1339 void
1340 dwarf2out_frame_debug (insn)
1341 rtx insn;
1343 char *label;
1344 rtx src;
1346 if (insn == NULL_RTX)
1348 /* Set up state for generating call frame debug info. */
1349 lookup_cfa (&cfa_reg, &cfa_offset);
1350 if (cfa_reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1351 abort ();
1352 cfa_reg = STACK_POINTER_REGNUM;
1353 cfa_store_reg = cfa_reg;
1354 cfa_store_offset = cfa_offset;
1355 cfa_temp_reg = -1;
1356 cfa_temp_value = 0;
1357 return;
1360 if (! RTX_FRAME_RELATED_P (insn))
1362 dwarf2out_stack_adjust (insn);
1363 return;
1366 label = dwarf2out_cfi_label ();
1368 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1369 if (src)
1370 insn = XEXP (src, 0);
1371 else
1372 insn = PATTERN (insn);
1374 dwarf2out_frame_debug_expr (insn, label);
1377 /* Return the size of an unsigned LEB128 quantity. */
1379 static inline unsigned long
1380 size_of_uleb128 (value)
1381 register unsigned long value;
1383 register unsigned long size = 0;
1384 register unsigned byte;
1388 byte = (value & 0x7f);
1389 value >>= 7;
1390 size += 1;
1392 while (value != 0);
1394 return size;
1397 /* Return the size of a signed LEB128 quantity. */
1399 static inline unsigned long
1400 size_of_sleb128 (value)
1401 register long value;
1403 register unsigned long size = 0;
1404 register unsigned byte;
1408 byte = (value & 0x7f);
1409 value >>= 7;
1410 size += 1;
1412 while (!(((value == 0) && ((byte & 0x40) == 0))
1413 || ((value == -1) && ((byte & 0x40) != 0))));
1415 return size;
1418 /* Output an unsigned LEB128 quantity. */
1420 static void
1421 output_uleb128 (value)
1422 register unsigned long value;
1424 unsigned long save_value = value;
1426 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1429 register unsigned byte = (value & 0x7f);
1430 value >>= 7;
1431 if (value != 0)
1432 /* More bytes to follow. */
1433 byte |= 0x80;
1435 fprintf (asm_out_file, "0x%x", byte);
1436 if (value != 0)
1437 fprintf (asm_out_file, ",");
1439 while (value != 0);
1441 if (flag_debug_asm)
1442 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1445 /* Output an signed LEB128 quantity. */
1447 static void
1448 output_sleb128 (value)
1449 register long value;
1451 register int more;
1452 register unsigned byte;
1453 long save_value = value;
1455 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1458 byte = (value & 0x7f);
1459 /* arithmetic shift */
1460 value >>= 7;
1461 more = !((((value == 0) && ((byte & 0x40) == 0))
1462 || ((value == -1) && ((byte & 0x40) != 0))));
1463 if (more)
1464 byte |= 0x80;
1466 fprintf (asm_out_file, "0x%x", byte);
1467 if (more)
1468 fprintf (asm_out_file, ",");
1471 while (more);
1472 if (flag_debug_asm)
1473 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1476 /* Output a Call Frame Information opcode and its operand(s). */
1478 static void
1479 output_cfi (cfi, fde)
1480 register dw_cfi_ref cfi;
1481 register dw_fde_ref fde;
1483 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1485 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1486 cfi->dw_cfi_opc
1487 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1488 if (flag_debug_asm)
1489 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1490 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1491 fputc ('\n', asm_out_file);
1494 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1496 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1497 cfi->dw_cfi_opc
1498 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1499 if (flag_debug_asm)
1500 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1501 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1503 fputc ('\n', asm_out_file);
1504 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1505 fputc ('\n', asm_out_file);
1507 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1509 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1510 cfi->dw_cfi_opc
1511 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1512 if (flag_debug_asm)
1513 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1514 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1516 fputc ('\n', asm_out_file);
1518 else
1520 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1521 if (flag_debug_asm)
1522 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1523 dwarf_cfi_name (cfi->dw_cfi_opc));
1525 fputc ('\n', asm_out_file);
1526 switch (cfi->dw_cfi_opc)
1528 case DW_CFA_set_loc:
1529 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1530 fputc ('\n', asm_out_file);
1531 break;
1532 case DW_CFA_advance_loc1:
1533 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1534 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1535 fde->dw_fde_current_label);
1536 fputc ('\n', asm_out_file);
1537 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1538 break;
1539 case DW_CFA_advance_loc2:
1540 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1541 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1542 fde->dw_fde_current_label);
1543 fputc ('\n', asm_out_file);
1544 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1545 break;
1546 case DW_CFA_advance_loc4:
1547 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1548 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1549 fde->dw_fde_current_label);
1550 fputc ('\n', asm_out_file);
1551 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1552 break;
1553 #ifdef MIPS_DEBUGGING_INFO
1554 case DW_CFA_MIPS_advance_loc8:
1555 /* TODO: not currently implemented. */
1556 abort ();
1557 break;
1558 #endif
1559 case DW_CFA_offset_extended:
1560 case DW_CFA_GNU_negative_offset_extended:
1561 case DW_CFA_def_cfa:
1562 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1563 fputc ('\n', asm_out_file);
1564 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1565 fputc ('\n', asm_out_file);
1566 break;
1567 case DW_CFA_restore_extended:
1568 case DW_CFA_undefined:
1569 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1570 fputc ('\n', asm_out_file);
1571 break;
1572 case DW_CFA_same_value:
1573 case DW_CFA_def_cfa_register:
1574 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1575 fputc ('\n', asm_out_file);
1576 break;
1577 case DW_CFA_register:
1578 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1579 fputc ('\n', asm_out_file);
1580 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1581 fputc ('\n', asm_out_file);
1582 break;
1583 case DW_CFA_def_cfa_offset:
1584 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1585 fputc ('\n', asm_out_file);
1586 break;
1587 case DW_CFA_GNU_window_save:
1588 break;
1589 case DW_CFA_GNU_args_size:
1590 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1591 fputc ('\n', asm_out_file);
1592 break;
1593 default:
1594 break;
1599 /* Output the call frame information used to used to record information
1600 that relates to calculating the frame pointer, and records the
1601 location of saved registers. */
1603 static void
1604 output_call_frame_info (for_eh)
1605 int for_eh;
1607 register unsigned long i;
1608 register dw_fde_ref fde;
1609 register dw_cfi_ref cfi;
1610 char l1[20], l2[20];
1611 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1612 char ld[20];
1613 #endif
1615 /* Do we want to include a pointer to the exception table? */
1616 int eh_ptr = for_eh && exception_table_p ();
1618 /* If we don't have any functions we'll want to unwind out of, don't
1619 emit any EH unwind information. */
1620 if (for_eh)
1622 for (i = 0; i < fde_table_in_use; ++i)
1623 if (! fde_table[i].nothrow)
1624 goto found;
1625 return;
1626 found:;
1629 fputc ('\n', asm_out_file);
1631 /* We're going to be generating comments, so turn on app. */
1632 if (flag_debug_asm)
1633 app_enable ();
1635 if (for_eh)
1637 #ifdef EH_FRAME_SECTION
1638 EH_FRAME_SECTION ();
1639 #else
1640 tree label = get_file_function_name ('F');
1642 force_data_section ();
1643 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1644 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1645 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1646 #endif
1647 assemble_label ("__FRAME_BEGIN__");
1649 else
1650 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1652 /* Output the CIE. */
1653 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1654 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1655 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1656 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1657 if (for_eh)
1658 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1659 else
1660 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1661 #else
1662 if (for_eh)
1663 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1664 else
1665 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1666 #endif
1667 if (flag_debug_asm)
1668 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1669 ASM_COMMENT_START);
1671 fputc ('\n', asm_out_file);
1672 ASM_OUTPUT_LABEL (asm_out_file, l1);
1674 if (for_eh)
1675 /* Now that the CIE pointer is PC-relative for EH,
1676 use 0 to identify the CIE. */
1677 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1678 else
1679 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1681 if (flag_debug_asm)
1682 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1684 fputc ('\n', asm_out_file);
1685 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1687 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1688 fputc ('\n', asm_out_file);
1691 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1692 if (flag_debug_asm)
1693 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1695 fputc ('\n', asm_out_file);
1696 if (eh_ptr)
1698 /* The CIE contains a pointer to the exception region info for the
1699 frame. Make the augmentation string three bytes (including the
1700 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1701 can't handle unaligned relocs. */
1702 if (flag_debug_asm)
1704 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1705 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1707 else
1709 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1711 fputc ('\n', asm_out_file);
1713 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1714 if (flag_debug_asm)
1715 fprintf (asm_out_file, "\t%s pointer to exception region info",
1716 ASM_COMMENT_START);
1718 else
1720 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1721 if (flag_debug_asm)
1722 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1723 ASM_COMMENT_START);
1726 fputc ('\n', asm_out_file);
1727 output_uleb128 (1);
1728 if (flag_debug_asm)
1729 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1731 fputc ('\n', asm_out_file);
1732 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1733 if (flag_debug_asm)
1734 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1736 fputc ('\n', asm_out_file);
1737 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1738 if (flag_debug_asm)
1739 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1741 fputc ('\n', asm_out_file);
1743 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1744 output_cfi (cfi, NULL);
1746 /* Pad the CIE out to an address sized boundary. */
1747 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1748 ASM_OUTPUT_LABEL (asm_out_file, l2);
1749 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1750 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1751 if (flag_debug_asm)
1752 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1753 fputc ('\n', asm_out_file);
1754 #endif
1756 /* Loop through all of the FDE's. */
1757 for (i = 0; i < fde_table_in_use; ++i)
1759 fde = &fde_table[i];
1761 /* Don't emit EH unwind info for leaf functions. */
1762 if (for_eh && fde->nothrow)
1763 continue;
1765 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
1766 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
1767 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1768 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2);
1769 if (for_eh)
1770 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1771 else
1772 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1773 #else
1774 if (for_eh)
1775 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1776 else
1777 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1778 #endif
1779 if (flag_debug_asm)
1780 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1781 fputc ('\n', asm_out_file);
1782 ASM_OUTPUT_LABEL (asm_out_file, l1);
1784 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1785 emits a target dependent sized offset when for_eh is not true.
1786 This inconsistency may confuse gdb. The only case where we need a
1787 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1788 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1789 though in order to be compatible with the dwarf_fde struct in frame.c.
1790 If the for_eh case is changed, then the struct in frame.c has
1791 to be adjusted appropriately. */
1792 if (for_eh)
1793 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1794 else
1795 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1796 if (flag_debug_asm)
1797 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1799 fputc ('\n', asm_out_file);
1800 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1801 if (flag_debug_asm)
1802 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1804 fputc ('\n', asm_out_file);
1805 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1806 fde->dw_fde_end, fde->dw_fde_begin);
1807 if (flag_debug_asm)
1808 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1810 fputc ('\n', asm_out_file);
1812 /* Loop through the Call Frame Instructions associated with
1813 this FDE. */
1814 fde->dw_fde_current_label = fde->dw_fde_begin;
1815 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1816 output_cfi (cfi, fde);
1818 /* Pad the FDE out to an address sized boundary. */
1819 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1820 ASM_OUTPUT_LABEL (asm_out_file, l2);
1821 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1822 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1823 if (flag_debug_asm)
1824 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1825 fputc ('\n', asm_out_file);
1826 #endif
1828 #ifndef EH_FRAME_SECTION
1829 if (for_eh)
1831 /* Emit terminating zero for table. */
1832 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1833 fputc ('\n', asm_out_file);
1835 #endif
1836 #ifdef MIPS_DEBUGGING_INFO
1837 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1838 get a value of 0. Putting .align 0 after the label fixes it. */
1839 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1840 #endif
1842 /* Turn off app to make assembly quicker. */
1843 if (flag_debug_asm)
1844 app_disable ();
1847 /* Output a marker (i.e. a label) for the beginning of a function, before
1848 the prologue. */
1850 void
1851 dwarf2out_begin_prologue ()
1853 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1854 register dw_fde_ref fde;
1856 ++current_funcdef_number;
1858 function_section (current_function_decl);
1859 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1860 current_funcdef_number);
1861 ASM_OUTPUT_LABEL (asm_out_file, label);
1862 current_function_func_begin_label = get_identifier (label);
1864 /* Expand the fde table if necessary. */
1865 if (fde_table_in_use == fde_table_allocated)
1867 fde_table_allocated += FDE_TABLE_INCREMENT;
1868 fde_table
1869 = (dw_fde_ref) xrealloc (fde_table,
1870 fde_table_allocated * sizeof (dw_fde_node));
1873 /* Record the FDE associated with this function. */
1874 current_funcdef_fde = fde_table_in_use;
1876 /* Add the new FDE at the end of the fde_table. */
1877 fde = &fde_table[fde_table_in_use++];
1878 fde->dw_fde_begin = xstrdup (label);
1879 fde->dw_fde_current_label = NULL;
1880 fde->dw_fde_end = NULL;
1881 fde->dw_fde_cfi = NULL;
1882 fde->nothrow = current_function_nothrow;
1884 args_size = old_args_size = 0;
1887 /* Output a marker (i.e. a label) for the absolute end of the generated code
1888 for a function definition. This gets called *after* the epilogue code has
1889 been generated. */
1891 void
1892 dwarf2out_end_epilogue ()
1894 dw_fde_ref fde;
1895 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1897 /* Output a label to mark the endpoint of the code generated for this
1898 function. */
1899 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1900 ASM_OUTPUT_LABEL (asm_out_file, label);
1901 fde = &fde_table[fde_table_in_use - 1];
1902 fde->dw_fde_end = xstrdup (label);
1905 void
1906 dwarf2out_frame_init ()
1908 /* Allocate the initial hunk of the fde_table. */
1909 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
1910 fde_table_allocated = FDE_TABLE_INCREMENT;
1911 fde_table_in_use = 0;
1913 /* Generate the CFA instructions common to all FDE's. Do it now for the
1914 sake of lookup_cfa. */
1916 #ifdef DWARF2_UNWIND_INFO
1917 /* On entry, the Canonical Frame Address is at SP. */
1918 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1919 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1920 #endif
1923 void
1924 dwarf2out_frame_finish ()
1926 /* Output call frame information. */
1927 #ifdef MIPS_DEBUGGING_INFO
1928 if (write_symbols == DWARF2_DEBUG)
1929 output_call_frame_info (0);
1930 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1931 output_call_frame_info (1);
1932 #else
1933 if (write_symbols == DWARF2_DEBUG
1934 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1935 output_call_frame_info (1);
1936 #endif
1939 #endif /* .debug_frame support */
1941 /* And now, the support for symbolic debugging information. */
1942 #ifdef DWARF2_DEBUGGING_INFO
1944 /* NOTE: In the comments in this file, many references are made to
1945 "Debugging Information Entries". This term is abbreviated as `DIE'
1946 throughout the remainder of this file. */
1948 /* An internal representation of the DWARF output is built, and then
1949 walked to generate the DWARF debugging info. The walk of the internal
1950 representation is done after the entire program has been compiled.
1951 The types below are used to describe the internal representation. */
1953 /* Each DIE may have a series of attribute/value pairs. Values
1954 can take on several forms. The forms that are used in this
1955 implementation are listed below. */
1957 typedef enum
1959 dw_val_class_addr,
1960 dw_val_class_loc,
1961 dw_val_class_const,
1962 dw_val_class_unsigned_const,
1963 dw_val_class_long_long,
1964 dw_val_class_float,
1965 dw_val_class_flag,
1966 dw_val_class_die_ref,
1967 dw_val_class_fde_ref,
1968 dw_val_class_lbl_id,
1969 dw_val_class_lbl_offset,
1970 dw_val_class_str
1972 dw_val_class;
1974 /* Various DIE's use offsets relative to the beginning of the
1975 .debug_info section to refer to each other. */
1977 typedef long int dw_offset;
1979 /* Define typedefs here to avoid circular dependencies. */
1981 typedef struct die_struct *dw_die_ref;
1982 typedef struct dw_attr_struct *dw_attr_ref;
1983 typedef struct dw_val_struct *dw_val_ref;
1984 typedef struct dw_line_info_struct *dw_line_info_ref;
1985 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1986 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1987 typedef struct pubname_struct *pubname_ref;
1988 typedef dw_die_ref *arange_ref;
1990 /* Describe a double word constant value. */
1992 typedef struct dw_long_long_struct
1994 unsigned long hi;
1995 unsigned long low;
1997 dw_long_long_const;
1999 /* Describe a floating point constant value. */
2001 typedef struct dw_fp_struct
2003 long *array;
2004 unsigned length;
2006 dw_float_const;
2008 /* Each entry in the line_info_table maintains the file and
2009 line number associated with the label generated for that
2010 entry. The label gives the PC value associated with
2011 the line number entry. */
2013 typedef struct dw_line_info_struct
2015 unsigned long dw_file_num;
2016 unsigned long dw_line_num;
2018 dw_line_info_entry;
2020 /* Line information for functions in separate sections; each one gets its
2021 own sequence. */
2022 typedef struct dw_separate_line_info_struct
2024 unsigned long dw_file_num;
2025 unsigned long dw_line_num;
2026 unsigned long function;
2028 dw_separate_line_info_entry;
2030 /* The dw_val_node describes an attribute's value, as it is
2031 represented internally. */
2033 typedef struct dw_val_struct
2035 dw_val_class val_class;
2036 union
2038 rtx val_addr;
2039 dw_loc_descr_ref val_loc;
2040 long int val_int;
2041 long unsigned val_unsigned;
2042 dw_long_long_const val_long_long;
2043 dw_float_const val_float;
2044 dw_die_ref val_die_ref;
2045 unsigned val_fde_index;
2046 char *val_str;
2047 char *val_lbl_id;
2048 unsigned char val_flag;
2052 dw_val_node;
2054 /* Locations in memory are described using a sequence of stack machine
2055 operations. */
2057 typedef struct dw_loc_descr_struct
2059 dw_loc_descr_ref dw_loc_next;
2060 enum dwarf_location_atom dw_loc_opc;
2061 dw_val_node dw_loc_oprnd1;
2062 dw_val_node dw_loc_oprnd2;
2064 dw_loc_descr_node;
2066 /* Each DIE attribute has a field specifying the attribute kind,
2067 a link to the next attribute in the chain, and an attribute value.
2068 Attributes are typically linked below the DIE they modify. */
2070 typedef struct dw_attr_struct
2072 enum dwarf_attribute dw_attr;
2073 dw_attr_ref dw_attr_next;
2074 dw_val_node dw_attr_val;
2076 dw_attr_node;
2078 /* The Debugging Information Entry (DIE) structure */
2080 typedef struct die_struct
2082 enum dwarf_tag die_tag;
2083 dw_attr_ref die_attr;
2084 dw_die_ref die_parent;
2085 dw_die_ref die_child;
2086 dw_die_ref die_sib;
2087 dw_offset die_offset;
2088 unsigned long die_abbrev;
2090 die_node;
2092 /* The pubname structure */
2094 typedef struct pubname_struct
2096 dw_die_ref die;
2097 char * name;
2099 pubname_entry;
2101 /* The limbo die list structure. */
2102 typedef struct limbo_die_struct
2104 dw_die_ref die;
2105 struct limbo_die_struct *next;
2107 limbo_die_node;
2109 /* How to start an assembler comment. */
2110 #ifndef ASM_COMMENT_START
2111 #define ASM_COMMENT_START ";#"
2112 #endif
2114 /* Define a macro which returns non-zero for a TYPE_DECL which was
2115 implicitly generated for a tagged type.
2117 Note that unlike the gcc front end (which generates a NULL named
2118 TYPE_DECL node for each complete tagged type, each array type, and
2119 each function type node created) the g++ front end generates a
2120 _named_ TYPE_DECL node for each tagged type node created.
2121 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2122 generate a DW_TAG_typedef DIE for them. */
2124 #define TYPE_DECL_IS_STUB(decl) \
2125 (DECL_NAME (decl) == NULL_TREE \
2126 || (DECL_ARTIFICIAL (decl) \
2127 && is_tagged_type (TREE_TYPE (decl)) \
2128 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2129 /* This is necessary for stub decls that \
2130 appear in nested inline functions. */ \
2131 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2132 && (decl_ultimate_origin (decl) \
2133 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2135 /* Information concerning the compilation unit's programming
2136 language, and compiler version. */
2138 extern int flag_traditional;
2140 /* Fixed size portion of the DWARF compilation unit header. */
2141 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2143 /* Fixed size portion of debugging line information prolog. */
2144 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2146 /* Fixed size portion of public names info. */
2147 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2149 /* Fixed size portion of the address range info. */
2150 #define DWARF_ARANGES_HEADER_SIZE \
2151 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
2153 /* Size of padding portion in the address range info. It must be
2154 aligned to twice the pointer size. */
2155 #define DWARF_ARANGES_PAD_SIZE \
2156 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) \
2157 - (2 * DWARF_OFFSET_SIZE + 4))
2159 /* The default is to have gcc emit the line number tables. */
2160 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2161 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2162 #endif
2164 /* Define the architecture-dependent minimum instruction length (in bytes).
2165 In this implementation of DWARF, this field is used for information
2166 purposes only. Since GCC generates assembly language, we have
2167 no a priori knowledge of how many instruction bytes are generated
2168 for each source line, and therefore can use only the DW_LNE_set_address
2169 and DW_LNS_fixed_advance_pc line information commands. */
2171 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2172 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2173 #endif
2175 /* Minimum line offset in a special line info. opcode.
2176 This value was chosen to give a reasonable range of values. */
2177 #define DWARF_LINE_BASE -10
2179 /* First special line opcde - leave room for the standard opcodes. */
2180 #define DWARF_LINE_OPCODE_BASE 10
2182 /* Range of line offsets in a special line info. opcode. */
2183 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2185 /* Flag that indicates the initial value of the is_stmt_start flag.
2186 In the present implementation, we do not mark any lines as
2187 the beginning of a source statement, because that information
2188 is not made available by the GCC front-end. */
2189 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2191 /* This location is used by calc_die_sizes() to keep track
2192 the offset of each DIE within the .debug_info section. */
2193 static unsigned long next_die_offset;
2195 /* Record the root of the DIE's built for the current compilation unit. */
2196 static dw_die_ref comp_unit_die;
2198 /* A list of DIEs with a NULL parent waiting to be relocated. */
2199 static limbo_die_node *limbo_die_list = 0;
2201 /* Pointer to an array of filenames referenced by this compilation unit. */
2202 static char **file_table;
2204 /* Total number of entries in the table (i.e. array) pointed to by
2205 `file_table'. This is the *total* and includes both used and unused
2206 slots. */
2207 static unsigned file_table_allocated;
2209 /* Number of entries in the file_table which are actually in use. */
2210 static unsigned file_table_in_use;
2212 /* Size (in elements) of increments by which we may expand the filename
2213 table. */
2214 #define FILE_TABLE_INCREMENT 64
2216 /* Local pointer to the name of the main input file. Initialized in
2217 dwarf2out_init. */
2218 static char *primary_filename;
2220 /* A pointer to the base of a table of references to DIE's that describe
2221 declarations. The table is indexed by DECL_UID() which is a unique
2222 number identifying each decl. */
2223 static dw_die_ref *decl_die_table;
2225 /* Number of elements currently allocated for the decl_die_table. */
2226 static unsigned decl_die_table_allocated;
2228 /* Number of elements in decl_die_table currently in use. */
2229 static unsigned decl_die_table_in_use;
2231 /* Size (in elements) of increments by which we may expand the
2232 decl_die_table. */
2233 #define DECL_DIE_TABLE_INCREMENT 256
2235 /* A pointer to the base of a table of references to declaration
2236 scopes. This table is a display which tracks the nesting
2237 of declaration scopes at the current scope and containing
2238 scopes. This table is used to find the proper place to
2239 define type declaration DIE's. */
2240 static tree *decl_scope_table;
2242 /* Number of elements currently allocated for the decl_scope_table. */
2243 static int decl_scope_table_allocated;
2245 /* Current level of nesting of declaration scopes. */
2246 static int decl_scope_depth;
2248 /* Size (in elements) of increments by which we may expand the
2249 decl_scope_table. */
2250 #define DECL_SCOPE_TABLE_INCREMENT 64
2252 /* A pointer to the base of a list of references to DIE's that
2253 are uniquely identified by their tag, presence/absence of
2254 children DIE's, and list of attribute/value pairs. */
2255 static dw_die_ref *abbrev_die_table;
2257 /* Number of elements currently allocated for abbrev_die_table. */
2258 static unsigned abbrev_die_table_allocated;
2260 /* Number of elements in type_die_table currently in use. */
2261 static unsigned abbrev_die_table_in_use;
2263 /* Size (in elements) of increments by which we may expand the
2264 abbrev_die_table. */
2265 #define ABBREV_DIE_TABLE_INCREMENT 256
2267 /* A pointer to the base of a table that contains line information
2268 for each source code line in .text in the compilation unit. */
2269 static dw_line_info_ref line_info_table;
2271 /* Number of elements currently allocated for line_info_table. */
2272 static unsigned line_info_table_allocated;
2274 /* Number of elements in separate_line_info_table currently in use. */
2275 static unsigned separate_line_info_table_in_use;
2277 /* A pointer to the base of a table that contains line information
2278 for each source code line outside of .text in the compilation unit. */
2279 static dw_separate_line_info_ref separate_line_info_table;
2281 /* Number of elements currently allocated for separate_line_info_table. */
2282 static unsigned separate_line_info_table_allocated;
2284 /* Number of elements in line_info_table currently in use. */
2285 static unsigned line_info_table_in_use;
2287 /* Size (in elements) of increments by which we may expand the
2288 line_info_table. */
2289 #define LINE_INFO_TABLE_INCREMENT 1024
2291 /* A pointer to the base of a table that contains a list of publicly
2292 accessible names. */
2293 static pubname_ref pubname_table;
2295 /* Number of elements currently allocated for pubname_table. */
2296 static unsigned pubname_table_allocated;
2298 /* Number of elements in pubname_table currently in use. */
2299 static unsigned pubname_table_in_use;
2301 /* Size (in elements) of increments by which we may expand the
2302 pubname_table. */
2303 #define PUBNAME_TABLE_INCREMENT 64
2305 /* A pointer to the base of a table that contains a list of publicly
2306 accessible names. */
2307 static arange_ref arange_table;
2309 /* Number of elements currently allocated for arange_table. */
2310 static unsigned arange_table_allocated;
2312 /* Number of elements in arange_table currently in use. */
2313 static unsigned arange_table_in_use;
2315 /* Size (in elements) of increments by which we may expand the
2316 arange_table. */
2317 #define ARANGE_TABLE_INCREMENT 64
2319 /* A pointer to the base of a list of incomplete types which might be
2320 completed at some later time. */
2322 static tree *incomplete_types_list;
2324 /* Number of elements currently allocated for the incomplete_types_list. */
2325 static unsigned incomplete_types_allocated;
2327 /* Number of elements of incomplete_types_list currently in use. */
2328 static unsigned incomplete_types;
2330 /* Size (in elements) of increments by which we may expand the incomplete
2331 types list. Actually, a single hunk of space of this size should
2332 be enough for most typical programs. */
2333 #define INCOMPLETE_TYPES_INCREMENT 64
2335 /* Record whether the function being analyzed contains inlined functions. */
2336 static int current_function_has_inlines;
2337 #if 0 && defined (MIPS_DEBUGGING_INFO)
2338 static int comp_unit_has_inlines;
2339 #endif
2341 /* Array of RTXes referenced by the debugging information, which therefore
2342 must be kept around forever. We do this rather than perform GC on
2343 the dwarf info because almost all of the dwarf info lives forever, and
2344 it's easier to support non-GC frontends this way. */
2345 static varray_type used_rtx_varray;
2347 /* Forward declarations for functions defined in this file. */
2349 static int is_pseudo_reg PARAMS ((rtx));
2350 static tree type_main_variant PARAMS ((tree));
2351 static int is_tagged_type PARAMS ((tree));
2352 static const char *dwarf_tag_name PARAMS ((unsigned));
2353 static const char *dwarf_attr_name PARAMS ((unsigned));
2354 static const char *dwarf_form_name PARAMS ((unsigned));
2355 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2356 #if 0
2357 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
2358 #endif
2359 static tree decl_ultimate_origin PARAMS ((tree));
2360 static tree block_ultimate_origin PARAMS ((tree));
2361 static tree decl_class_context PARAMS ((tree));
2362 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
2363 static void add_AT_flag PARAMS ((dw_die_ref,
2364 enum dwarf_attribute,
2365 unsigned));
2366 static void add_AT_int PARAMS ((dw_die_ref,
2367 enum dwarf_attribute, long));
2368 static void add_AT_unsigned PARAMS ((dw_die_ref,
2369 enum dwarf_attribute,
2370 unsigned long));
2371 static void add_AT_long_long PARAMS ((dw_die_ref,
2372 enum dwarf_attribute,
2373 unsigned long,
2374 unsigned long));
2375 static void add_AT_float PARAMS ((dw_die_ref,
2376 enum dwarf_attribute,
2377 unsigned, long *));
2378 static void add_AT_string PARAMS ((dw_die_ref,
2379 enum dwarf_attribute,
2380 const char *));
2381 static void add_AT_die_ref PARAMS ((dw_die_ref,
2382 enum dwarf_attribute,
2383 dw_die_ref));
2384 static void add_AT_fde_ref PARAMS ((dw_die_ref,
2385 enum dwarf_attribute,
2386 unsigned));
2387 static void add_AT_loc PARAMS ((dw_die_ref,
2388 enum dwarf_attribute,
2389 dw_loc_descr_ref));
2390 static void add_AT_addr PARAMS ((dw_die_ref,
2391 enum dwarf_attribute,
2392 rtx));
2393 static void add_AT_lbl_id PARAMS ((dw_die_ref,
2394 enum dwarf_attribute,
2395 char *));
2396 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
2397 enum dwarf_attribute,
2398 char *));
2399 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
2400 enum dwarf_attribute));
2401 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
2402 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
2403 static const char *get_AT_string PARAMS ((dw_die_ref,
2404 enum dwarf_attribute));
2405 static int get_AT_flag PARAMS ((dw_die_ref,
2406 enum dwarf_attribute));
2407 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
2408 enum dwarf_attribute));
2409 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
2410 enum dwarf_attribute));
2411 static int is_c_family PARAMS ((void));
2412 static int is_fortran PARAMS ((void));
2413 static void remove_AT PARAMS ((dw_die_ref,
2414 enum dwarf_attribute));
2415 static void remove_children PARAMS ((dw_die_ref));
2416 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
2417 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
2418 static dw_die_ref lookup_type_die PARAMS ((tree));
2419 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
2420 static dw_die_ref lookup_decl_die PARAMS ((tree));
2421 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
2422 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2423 unsigned long,
2424 unsigned long));
2425 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2426 dw_loc_descr_ref));
2427 static void print_spaces PARAMS ((FILE *));
2428 static void print_die PARAMS ((dw_die_ref, FILE *));
2429 static void print_dwarf_line_table PARAMS ((FILE *));
2430 static void add_sibling_attributes PARAMS ((dw_die_ref));
2431 static void build_abbrev_table PARAMS ((dw_die_ref));
2432 static unsigned long size_of_string PARAMS ((const char *));
2433 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2434 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2435 static int constant_size PARAMS ((long unsigned));
2436 static unsigned long size_of_die PARAMS ((dw_die_ref));
2437 static void calc_die_sizes PARAMS ((dw_die_ref));
2438 static unsigned long size_of_line_prolog PARAMS ((void));
2439 static unsigned long size_of_pubnames PARAMS ((void));
2440 static unsigned long size_of_aranges PARAMS ((void));
2441 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
2442 static void output_value_format PARAMS ((dw_attr_ref));
2443 static void output_abbrev_section PARAMS ((void));
2444 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2445 static void output_die PARAMS ((dw_die_ref));
2446 static void output_compilation_unit_header PARAMS ((void));
2447 static const char *dwarf2_name PARAMS ((tree, int));
2448 static void add_pubname PARAMS ((tree, dw_die_ref));
2449 static void output_pubnames PARAMS ((void));
2450 static void add_arange PARAMS ((tree, dw_die_ref));
2451 static void output_aranges PARAMS ((void));
2452 static void output_line_info PARAMS ((void));
2453 static dw_die_ref base_type_die PARAMS ((tree));
2454 static tree root_type PARAMS ((tree));
2455 static int is_base_type PARAMS ((tree));
2456 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
2457 static int type_is_enum PARAMS ((tree));
2458 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
2459 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
2460 static int is_based_loc PARAMS ((rtx));
2461 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
2462 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
2463 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
2464 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
2465 static tree field_type PARAMS ((tree));
2466 static unsigned int simple_type_align_in_bits PARAMS ((tree));
2467 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
2468 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
2469 static void add_AT_location_description PARAMS ((dw_die_ref,
2470 enum dwarf_attribute, rtx));
2471 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
2472 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
2473 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
2474 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
2475 static void add_bound_info PARAMS ((dw_die_ref,
2476 enum dwarf_attribute, tree));
2477 static void add_subscript_info PARAMS ((dw_die_ref, tree));
2478 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
2479 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
2480 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
2481 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
2482 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
2483 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
2484 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
2485 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
2486 static void push_decl_scope PARAMS ((tree));
2487 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
2488 static void pop_decl_scope PARAMS ((void));
2489 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
2490 dw_die_ref));
2491 static char *type_tag PARAMS ((tree));
2492 static tree member_declared_type PARAMS ((tree));
2493 #if 0
2494 static char *decl_start_label PARAMS ((tree));
2495 #endif
2496 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
2497 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
2498 #if 0
2499 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
2500 #endif
2501 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
2502 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
2503 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
2504 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
2505 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
2506 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
2507 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
2508 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
2509 static void gen_variable_die PARAMS ((tree, dw_die_ref));
2510 static void gen_label_die PARAMS ((tree, dw_die_ref));
2511 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
2512 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
2513 static void gen_field_die PARAMS ((tree, dw_die_ref));
2514 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
2515 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
2516 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
2517 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
2518 static void gen_member_die PARAMS ((tree, dw_die_ref));
2519 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
2520 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
2521 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
2522 static void gen_type_die PARAMS ((tree, dw_die_ref));
2523 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
2524 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
2525 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
2526 static int is_redundant_typedef PARAMS ((tree));
2527 static void gen_decl_die PARAMS ((tree, dw_die_ref));
2528 static unsigned lookup_filename PARAMS ((const char *));
2529 static void add_incomplete_type PARAMS ((tree));
2530 static void retry_incomplete_types PARAMS ((void));
2531 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
2532 static void gen_abstract_function PARAMS ((tree));
2533 static rtx save_rtx PARAMS ((rtx));
2534 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
2535 static void reverse_die_lists PARAMS ((dw_die_ref));
2537 /* Section names used to hold DWARF debugging information. */
2538 #ifndef DEBUG_INFO_SECTION
2539 #define DEBUG_INFO_SECTION ".debug_info"
2540 #endif
2541 #ifndef ABBREV_SECTION
2542 #define ABBREV_SECTION ".debug_abbrev"
2543 #endif
2544 #ifndef ARANGES_SECTION
2545 #define ARANGES_SECTION ".debug_aranges"
2546 #endif
2547 #ifndef DW_MACINFO_SECTION
2548 #define DW_MACINFO_SECTION ".debug_macinfo"
2549 #endif
2550 #ifndef DEBUG_LINE_SECTION
2551 #define DEBUG_LINE_SECTION ".debug_line"
2552 #endif
2553 #ifndef LOC_SECTION
2554 #define LOC_SECTION ".debug_loc"
2555 #endif
2556 #ifndef PUBNAMES_SECTION
2557 #define PUBNAMES_SECTION ".debug_pubnames"
2558 #endif
2559 #ifndef STR_SECTION
2560 #define STR_SECTION ".debug_str"
2561 #endif
2563 /* Standard ELF section names for compiled code and data. */
2564 #ifndef TEXT_SECTION
2565 #define TEXT_SECTION ".text"
2566 #endif
2567 #ifndef DATA_SECTION
2568 #define DATA_SECTION ".data"
2569 #endif
2570 #ifndef BSS_SECTION
2571 #define BSS_SECTION ".bss"
2572 #endif
2574 /* Labels we insert at beginning sections we can reference instead of
2575 the section names themselves. */
2577 #ifndef TEXT_SECTION_LABEL
2578 #define TEXT_SECTION_LABEL "Ltext"
2579 #endif
2580 #ifndef DEBUG_LINE_SECTION_LABEL
2581 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
2582 #endif
2583 #ifndef DEBUG_INFO_SECTION_LABEL
2584 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
2585 #endif
2586 #ifndef ABBREV_SECTION_LABEL
2587 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
2588 #endif
2591 /* Definitions of defaults for formats and names of various special
2592 (artificial) labels which may be generated within this file (when the -g
2593 options is used and DWARF_DEBUGGING_INFO is in effect.
2594 If necessary, these may be overridden from within the tm.h file, but
2595 typically, overriding these defaults is unnecessary. */
2597 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2598 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2599 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2600 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2601 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2603 #ifndef TEXT_END_LABEL
2604 #define TEXT_END_LABEL "Letext"
2605 #endif
2606 #ifndef DATA_END_LABEL
2607 #define DATA_END_LABEL "Ledata"
2608 #endif
2609 #ifndef BSS_END_LABEL
2610 #define BSS_END_LABEL "Lebss"
2611 #endif
2612 #ifndef INSN_LABEL_FMT
2613 #define INSN_LABEL_FMT "LI%u_"
2614 #endif
2615 #ifndef BLOCK_BEGIN_LABEL
2616 #define BLOCK_BEGIN_LABEL "LBB"
2617 #endif
2618 #ifndef BLOCK_END_LABEL
2619 #define BLOCK_END_LABEL "LBE"
2620 #endif
2621 #ifndef BODY_BEGIN_LABEL
2622 #define BODY_BEGIN_LABEL "Lbb"
2623 #endif
2624 #ifndef BODY_END_LABEL
2625 #define BODY_END_LABEL "Lbe"
2626 #endif
2627 #ifndef LINE_CODE_LABEL
2628 #define LINE_CODE_LABEL "LM"
2629 #endif
2630 #ifndef SEPARATE_LINE_CODE_LABEL
2631 #define SEPARATE_LINE_CODE_LABEL "LSM"
2632 #endif
2634 /* We allow a language front-end to designate a function that is to be
2635 called to "demangle" any name before it it put into a DIE. */
2637 static const char *(*demangle_name_func) PARAMS ((const char *));
2639 void
2640 dwarf2out_set_demangle_name_func (func)
2641 const char *(*func) PARAMS ((const char *));
2643 demangle_name_func = func;
2646 /* Return an rtx like ORIG which lives forever. If we're doing GC,
2647 that means adding it to used_rtx_varray. If not, that means making
2648 a copy on the permanent_obstack. */
2650 static rtx
2651 save_rtx (orig)
2652 register rtx orig;
2654 if (ggc_p)
2655 VARRAY_PUSH_RTX (used_rtx_varray, orig);
2656 else
2658 push_obstacks_nochange ();
2659 end_temporary_allocation ();
2660 orig = copy_rtx (orig);
2661 pop_obstacks ();
2664 return orig;
2667 /* Test if rtl node points to a pseudo register. */
2669 static inline int
2670 is_pseudo_reg (rtl)
2671 register rtx rtl;
2673 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
2674 || (GET_CODE (rtl) == SUBREG
2675 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
2678 /* Return a reference to a type, with its const and volatile qualifiers
2679 removed. */
2681 static inline tree
2682 type_main_variant (type)
2683 register tree type;
2685 type = TYPE_MAIN_VARIANT (type);
2687 /* There really should be only one main variant among any group of variants
2688 of a given type (and all of the MAIN_VARIANT values for all members of
2689 the group should point to that one type) but sometimes the C front-end
2690 messes this up for array types, so we work around that bug here. */
2692 if (TREE_CODE (type) == ARRAY_TYPE)
2693 while (type != TYPE_MAIN_VARIANT (type))
2694 type = TYPE_MAIN_VARIANT (type);
2696 return type;
2699 /* Return non-zero if the given type node represents a tagged type. */
2701 static inline int
2702 is_tagged_type (type)
2703 register tree type;
2705 register enum tree_code code = TREE_CODE (type);
2707 return (code == RECORD_TYPE || code == UNION_TYPE
2708 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
2711 /* Convert a DIE tag into its string name. */
2713 static const char *
2714 dwarf_tag_name (tag)
2715 register unsigned tag;
2717 switch (tag)
2719 case DW_TAG_padding:
2720 return "DW_TAG_padding";
2721 case DW_TAG_array_type:
2722 return "DW_TAG_array_type";
2723 case DW_TAG_class_type:
2724 return "DW_TAG_class_type";
2725 case DW_TAG_entry_point:
2726 return "DW_TAG_entry_point";
2727 case DW_TAG_enumeration_type:
2728 return "DW_TAG_enumeration_type";
2729 case DW_TAG_formal_parameter:
2730 return "DW_TAG_formal_parameter";
2731 case DW_TAG_imported_declaration:
2732 return "DW_TAG_imported_declaration";
2733 case DW_TAG_label:
2734 return "DW_TAG_label";
2735 case DW_TAG_lexical_block:
2736 return "DW_TAG_lexical_block";
2737 case DW_TAG_member:
2738 return "DW_TAG_member";
2739 case DW_TAG_pointer_type:
2740 return "DW_TAG_pointer_type";
2741 case DW_TAG_reference_type:
2742 return "DW_TAG_reference_type";
2743 case DW_TAG_compile_unit:
2744 return "DW_TAG_compile_unit";
2745 case DW_TAG_string_type:
2746 return "DW_TAG_string_type";
2747 case DW_TAG_structure_type:
2748 return "DW_TAG_structure_type";
2749 case DW_TAG_subroutine_type:
2750 return "DW_TAG_subroutine_type";
2751 case DW_TAG_typedef:
2752 return "DW_TAG_typedef";
2753 case DW_TAG_union_type:
2754 return "DW_TAG_union_type";
2755 case DW_TAG_unspecified_parameters:
2756 return "DW_TAG_unspecified_parameters";
2757 case DW_TAG_variant:
2758 return "DW_TAG_variant";
2759 case DW_TAG_common_block:
2760 return "DW_TAG_common_block";
2761 case DW_TAG_common_inclusion:
2762 return "DW_TAG_common_inclusion";
2763 case DW_TAG_inheritance:
2764 return "DW_TAG_inheritance";
2765 case DW_TAG_inlined_subroutine:
2766 return "DW_TAG_inlined_subroutine";
2767 case DW_TAG_module:
2768 return "DW_TAG_module";
2769 case DW_TAG_ptr_to_member_type:
2770 return "DW_TAG_ptr_to_member_type";
2771 case DW_TAG_set_type:
2772 return "DW_TAG_set_type";
2773 case DW_TAG_subrange_type:
2774 return "DW_TAG_subrange_type";
2775 case DW_TAG_with_stmt:
2776 return "DW_TAG_with_stmt";
2777 case DW_TAG_access_declaration:
2778 return "DW_TAG_access_declaration";
2779 case DW_TAG_base_type:
2780 return "DW_TAG_base_type";
2781 case DW_TAG_catch_block:
2782 return "DW_TAG_catch_block";
2783 case DW_TAG_const_type:
2784 return "DW_TAG_const_type";
2785 case DW_TAG_constant:
2786 return "DW_TAG_constant";
2787 case DW_TAG_enumerator:
2788 return "DW_TAG_enumerator";
2789 case DW_TAG_file_type:
2790 return "DW_TAG_file_type";
2791 case DW_TAG_friend:
2792 return "DW_TAG_friend";
2793 case DW_TAG_namelist:
2794 return "DW_TAG_namelist";
2795 case DW_TAG_namelist_item:
2796 return "DW_TAG_namelist_item";
2797 case DW_TAG_packed_type:
2798 return "DW_TAG_packed_type";
2799 case DW_TAG_subprogram:
2800 return "DW_TAG_subprogram";
2801 case DW_TAG_template_type_param:
2802 return "DW_TAG_template_type_param";
2803 case DW_TAG_template_value_param:
2804 return "DW_TAG_template_value_param";
2805 case DW_TAG_thrown_type:
2806 return "DW_TAG_thrown_type";
2807 case DW_TAG_try_block:
2808 return "DW_TAG_try_block";
2809 case DW_TAG_variant_part:
2810 return "DW_TAG_variant_part";
2811 case DW_TAG_variable:
2812 return "DW_TAG_variable";
2813 case DW_TAG_volatile_type:
2814 return "DW_TAG_volatile_type";
2815 case DW_TAG_MIPS_loop:
2816 return "DW_TAG_MIPS_loop";
2817 case DW_TAG_format_label:
2818 return "DW_TAG_format_label";
2819 case DW_TAG_function_template:
2820 return "DW_TAG_function_template";
2821 case DW_TAG_class_template:
2822 return "DW_TAG_class_template";
2823 default:
2824 return "DW_TAG_<unknown>";
2828 /* Convert a DWARF attribute code into its string name. */
2830 static const char *
2831 dwarf_attr_name (attr)
2832 register unsigned attr;
2834 switch (attr)
2836 case DW_AT_sibling:
2837 return "DW_AT_sibling";
2838 case DW_AT_location:
2839 return "DW_AT_location";
2840 case DW_AT_name:
2841 return "DW_AT_name";
2842 case DW_AT_ordering:
2843 return "DW_AT_ordering";
2844 case DW_AT_subscr_data:
2845 return "DW_AT_subscr_data";
2846 case DW_AT_byte_size:
2847 return "DW_AT_byte_size";
2848 case DW_AT_bit_offset:
2849 return "DW_AT_bit_offset";
2850 case DW_AT_bit_size:
2851 return "DW_AT_bit_size";
2852 case DW_AT_element_list:
2853 return "DW_AT_element_list";
2854 case DW_AT_stmt_list:
2855 return "DW_AT_stmt_list";
2856 case DW_AT_low_pc:
2857 return "DW_AT_low_pc";
2858 case DW_AT_high_pc:
2859 return "DW_AT_high_pc";
2860 case DW_AT_language:
2861 return "DW_AT_language";
2862 case DW_AT_member:
2863 return "DW_AT_member";
2864 case DW_AT_discr:
2865 return "DW_AT_discr";
2866 case DW_AT_discr_value:
2867 return "DW_AT_discr_value";
2868 case DW_AT_visibility:
2869 return "DW_AT_visibility";
2870 case DW_AT_import:
2871 return "DW_AT_import";
2872 case DW_AT_string_length:
2873 return "DW_AT_string_length";
2874 case DW_AT_common_reference:
2875 return "DW_AT_common_reference";
2876 case DW_AT_comp_dir:
2877 return "DW_AT_comp_dir";
2878 case DW_AT_const_value:
2879 return "DW_AT_const_value";
2880 case DW_AT_containing_type:
2881 return "DW_AT_containing_type";
2882 case DW_AT_default_value:
2883 return "DW_AT_default_value";
2884 case DW_AT_inline:
2885 return "DW_AT_inline";
2886 case DW_AT_is_optional:
2887 return "DW_AT_is_optional";
2888 case DW_AT_lower_bound:
2889 return "DW_AT_lower_bound";
2890 case DW_AT_producer:
2891 return "DW_AT_producer";
2892 case DW_AT_prototyped:
2893 return "DW_AT_prototyped";
2894 case DW_AT_return_addr:
2895 return "DW_AT_return_addr";
2896 case DW_AT_start_scope:
2897 return "DW_AT_start_scope";
2898 case DW_AT_stride_size:
2899 return "DW_AT_stride_size";
2900 case DW_AT_upper_bound:
2901 return "DW_AT_upper_bound";
2902 case DW_AT_abstract_origin:
2903 return "DW_AT_abstract_origin";
2904 case DW_AT_accessibility:
2905 return "DW_AT_accessibility";
2906 case DW_AT_address_class:
2907 return "DW_AT_address_class";
2908 case DW_AT_artificial:
2909 return "DW_AT_artificial";
2910 case DW_AT_base_types:
2911 return "DW_AT_base_types";
2912 case DW_AT_calling_convention:
2913 return "DW_AT_calling_convention";
2914 case DW_AT_count:
2915 return "DW_AT_count";
2916 case DW_AT_data_member_location:
2917 return "DW_AT_data_member_location";
2918 case DW_AT_decl_column:
2919 return "DW_AT_decl_column";
2920 case DW_AT_decl_file:
2921 return "DW_AT_decl_file";
2922 case DW_AT_decl_line:
2923 return "DW_AT_decl_line";
2924 case DW_AT_declaration:
2925 return "DW_AT_declaration";
2926 case DW_AT_discr_list:
2927 return "DW_AT_discr_list";
2928 case DW_AT_encoding:
2929 return "DW_AT_encoding";
2930 case DW_AT_external:
2931 return "DW_AT_external";
2932 case DW_AT_frame_base:
2933 return "DW_AT_frame_base";
2934 case DW_AT_friend:
2935 return "DW_AT_friend";
2936 case DW_AT_identifier_case:
2937 return "DW_AT_identifier_case";
2938 case DW_AT_macro_info:
2939 return "DW_AT_macro_info";
2940 case DW_AT_namelist_items:
2941 return "DW_AT_namelist_items";
2942 case DW_AT_priority:
2943 return "DW_AT_priority";
2944 case DW_AT_segment:
2945 return "DW_AT_segment";
2946 case DW_AT_specification:
2947 return "DW_AT_specification";
2948 case DW_AT_static_link:
2949 return "DW_AT_static_link";
2950 case DW_AT_type:
2951 return "DW_AT_type";
2952 case DW_AT_use_location:
2953 return "DW_AT_use_location";
2954 case DW_AT_variable_parameter:
2955 return "DW_AT_variable_parameter";
2956 case DW_AT_virtuality:
2957 return "DW_AT_virtuality";
2958 case DW_AT_vtable_elem_location:
2959 return "DW_AT_vtable_elem_location";
2961 case DW_AT_MIPS_fde:
2962 return "DW_AT_MIPS_fde";
2963 case DW_AT_MIPS_loop_begin:
2964 return "DW_AT_MIPS_loop_begin";
2965 case DW_AT_MIPS_tail_loop_begin:
2966 return "DW_AT_MIPS_tail_loop_begin";
2967 case DW_AT_MIPS_epilog_begin:
2968 return "DW_AT_MIPS_epilog_begin";
2969 case DW_AT_MIPS_loop_unroll_factor:
2970 return "DW_AT_MIPS_loop_unroll_factor";
2971 case DW_AT_MIPS_software_pipeline_depth:
2972 return "DW_AT_MIPS_software_pipeline_depth";
2973 case DW_AT_MIPS_linkage_name:
2974 return "DW_AT_MIPS_linkage_name";
2975 case DW_AT_MIPS_stride:
2976 return "DW_AT_MIPS_stride";
2977 case DW_AT_MIPS_abstract_name:
2978 return "DW_AT_MIPS_abstract_name";
2979 case DW_AT_MIPS_clone_origin:
2980 return "DW_AT_MIPS_clone_origin";
2981 case DW_AT_MIPS_has_inlines:
2982 return "DW_AT_MIPS_has_inlines";
2984 case DW_AT_sf_names:
2985 return "DW_AT_sf_names";
2986 case DW_AT_src_info:
2987 return "DW_AT_src_info";
2988 case DW_AT_mac_info:
2989 return "DW_AT_mac_info";
2990 case DW_AT_src_coords:
2991 return "DW_AT_src_coords";
2992 case DW_AT_body_begin:
2993 return "DW_AT_body_begin";
2994 case DW_AT_body_end:
2995 return "DW_AT_body_end";
2996 default:
2997 return "DW_AT_<unknown>";
3001 /* Convert a DWARF value form code into its string name. */
3003 static const char *
3004 dwarf_form_name (form)
3005 register unsigned form;
3007 switch (form)
3009 case DW_FORM_addr:
3010 return "DW_FORM_addr";
3011 case DW_FORM_block2:
3012 return "DW_FORM_block2";
3013 case DW_FORM_block4:
3014 return "DW_FORM_block4";
3015 case DW_FORM_data2:
3016 return "DW_FORM_data2";
3017 case DW_FORM_data4:
3018 return "DW_FORM_data4";
3019 case DW_FORM_data8:
3020 return "DW_FORM_data8";
3021 case DW_FORM_string:
3022 return "DW_FORM_string";
3023 case DW_FORM_block:
3024 return "DW_FORM_block";
3025 case DW_FORM_block1:
3026 return "DW_FORM_block1";
3027 case DW_FORM_data1:
3028 return "DW_FORM_data1";
3029 case DW_FORM_flag:
3030 return "DW_FORM_flag";
3031 case DW_FORM_sdata:
3032 return "DW_FORM_sdata";
3033 case DW_FORM_strp:
3034 return "DW_FORM_strp";
3035 case DW_FORM_udata:
3036 return "DW_FORM_udata";
3037 case DW_FORM_ref_addr:
3038 return "DW_FORM_ref_addr";
3039 case DW_FORM_ref1:
3040 return "DW_FORM_ref1";
3041 case DW_FORM_ref2:
3042 return "DW_FORM_ref2";
3043 case DW_FORM_ref4:
3044 return "DW_FORM_ref4";
3045 case DW_FORM_ref8:
3046 return "DW_FORM_ref8";
3047 case DW_FORM_ref_udata:
3048 return "DW_FORM_ref_udata";
3049 case DW_FORM_indirect:
3050 return "DW_FORM_indirect";
3051 default:
3052 return "DW_FORM_<unknown>";
3056 /* Convert a DWARF stack opcode into its string name. */
3058 static const char *
3059 dwarf_stack_op_name (op)
3060 register unsigned op;
3062 switch (op)
3064 case DW_OP_addr:
3065 return "DW_OP_addr";
3066 case DW_OP_deref:
3067 return "DW_OP_deref";
3068 case DW_OP_const1u:
3069 return "DW_OP_const1u";
3070 case DW_OP_const1s:
3071 return "DW_OP_const1s";
3072 case DW_OP_const2u:
3073 return "DW_OP_const2u";
3074 case DW_OP_const2s:
3075 return "DW_OP_const2s";
3076 case DW_OP_const4u:
3077 return "DW_OP_const4u";
3078 case DW_OP_const4s:
3079 return "DW_OP_const4s";
3080 case DW_OP_const8u:
3081 return "DW_OP_const8u";
3082 case DW_OP_const8s:
3083 return "DW_OP_const8s";
3084 case DW_OP_constu:
3085 return "DW_OP_constu";
3086 case DW_OP_consts:
3087 return "DW_OP_consts";
3088 case DW_OP_dup:
3089 return "DW_OP_dup";
3090 case DW_OP_drop:
3091 return "DW_OP_drop";
3092 case DW_OP_over:
3093 return "DW_OP_over";
3094 case DW_OP_pick:
3095 return "DW_OP_pick";
3096 case DW_OP_swap:
3097 return "DW_OP_swap";
3098 case DW_OP_rot:
3099 return "DW_OP_rot";
3100 case DW_OP_xderef:
3101 return "DW_OP_xderef";
3102 case DW_OP_abs:
3103 return "DW_OP_abs";
3104 case DW_OP_and:
3105 return "DW_OP_and";
3106 case DW_OP_div:
3107 return "DW_OP_div";
3108 case DW_OP_minus:
3109 return "DW_OP_minus";
3110 case DW_OP_mod:
3111 return "DW_OP_mod";
3112 case DW_OP_mul:
3113 return "DW_OP_mul";
3114 case DW_OP_neg:
3115 return "DW_OP_neg";
3116 case DW_OP_not:
3117 return "DW_OP_not";
3118 case DW_OP_or:
3119 return "DW_OP_or";
3120 case DW_OP_plus:
3121 return "DW_OP_plus";
3122 case DW_OP_plus_uconst:
3123 return "DW_OP_plus_uconst";
3124 case DW_OP_shl:
3125 return "DW_OP_shl";
3126 case DW_OP_shr:
3127 return "DW_OP_shr";
3128 case DW_OP_shra:
3129 return "DW_OP_shra";
3130 case DW_OP_xor:
3131 return "DW_OP_xor";
3132 case DW_OP_bra:
3133 return "DW_OP_bra";
3134 case DW_OP_eq:
3135 return "DW_OP_eq";
3136 case DW_OP_ge:
3137 return "DW_OP_ge";
3138 case DW_OP_gt:
3139 return "DW_OP_gt";
3140 case DW_OP_le:
3141 return "DW_OP_le";
3142 case DW_OP_lt:
3143 return "DW_OP_lt";
3144 case DW_OP_ne:
3145 return "DW_OP_ne";
3146 case DW_OP_skip:
3147 return "DW_OP_skip";
3148 case DW_OP_lit0:
3149 return "DW_OP_lit0";
3150 case DW_OP_lit1:
3151 return "DW_OP_lit1";
3152 case DW_OP_lit2:
3153 return "DW_OP_lit2";
3154 case DW_OP_lit3:
3155 return "DW_OP_lit3";
3156 case DW_OP_lit4:
3157 return "DW_OP_lit4";
3158 case DW_OP_lit5:
3159 return "DW_OP_lit5";
3160 case DW_OP_lit6:
3161 return "DW_OP_lit6";
3162 case DW_OP_lit7:
3163 return "DW_OP_lit7";
3164 case DW_OP_lit8:
3165 return "DW_OP_lit8";
3166 case DW_OP_lit9:
3167 return "DW_OP_lit9";
3168 case DW_OP_lit10:
3169 return "DW_OP_lit10";
3170 case DW_OP_lit11:
3171 return "DW_OP_lit11";
3172 case DW_OP_lit12:
3173 return "DW_OP_lit12";
3174 case DW_OP_lit13:
3175 return "DW_OP_lit13";
3176 case DW_OP_lit14:
3177 return "DW_OP_lit14";
3178 case DW_OP_lit15:
3179 return "DW_OP_lit15";
3180 case DW_OP_lit16:
3181 return "DW_OP_lit16";
3182 case DW_OP_lit17:
3183 return "DW_OP_lit17";
3184 case DW_OP_lit18:
3185 return "DW_OP_lit18";
3186 case DW_OP_lit19:
3187 return "DW_OP_lit19";
3188 case DW_OP_lit20:
3189 return "DW_OP_lit20";
3190 case DW_OP_lit21:
3191 return "DW_OP_lit21";
3192 case DW_OP_lit22:
3193 return "DW_OP_lit22";
3194 case DW_OP_lit23:
3195 return "DW_OP_lit23";
3196 case DW_OP_lit24:
3197 return "DW_OP_lit24";
3198 case DW_OP_lit25:
3199 return "DW_OP_lit25";
3200 case DW_OP_lit26:
3201 return "DW_OP_lit26";
3202 case DW_OP_lit27:
3203 return "DW_OP_lit27";
3204 case DW_OP_lit28:
3205 return "DW_OP_lit28";
3206 case DW_OP_lit29:
3207 return "DW_OP_lit29";
3208 case DW_OP_lit30:
3209 return "DW_OP_lit30";
3210 case DW_OP_lit31:
3211 return "DW_OP_lit31";
3212 case DW_OP_reg0:
3213 return "DW_OP_reg0";
3214 case DW_OP_reg1:
3215 return "DW_OP_reg1";
3216 case DW_OP_reg2:
3217 return "DW_OP_reg2";
3218 case DW_OP_reg3:
3219 return "DW_OP_reg3";
3220 case DW_OP_reg4:
3221 return "DW_OP_reg4";
3222 case DW_OP_reg5:
3223 return "DW_OP_reg5";
3224 case DW_OP_reg6:
3225 return "DW_OP_reg6";
3226 case DW_OP_reg7:
3227 return "DW_OP_reg7";
3228 case DW_OP_reg8:
3229 return "DW_OP_reg8";
3230 case DW_OP_reg9:
3231 return "DW_OP_reg9";
3232 case DW_OP_reg10:
3233 return "DW_OP_reg10";
3234 case DW_OP_reg11:
3235 return "DW_OP_reg11";
3236 case DW_OP_reg12:
3237 return "DW_OP_reg12";
3238 case DW_OP_reg13:
3239 return "DW_OP_reg13";
3240 case DW_OP_reg14:
3241 return "DW_OP_reg14";
3242 case DW_OP_reg15:
3243 return "DW_OP_reg15";
3244 case DW_OP_reg16:
3245 return "DW_OP_reg16";
3246 case DW_OP_reg17:
3247 return "DW_OP_reg17";
3248 case DW_OP_reg18:
3249 return "DW_OP_reg18";
3250 case DW_OP_reg19:
3251 return "DW_OP_reg19";
3252 case DW_OP_reg20:
3253 return "DW_OP_reg20";
3254 case DW_OP_reg21:
3255 return "DW_OP_reg21";
3256 case DW_OP_reg22:
3257 return "DW_OP_reg22";
3258 case DW_OP_reg23:
3259 return "DW_OP_reg23";
3260 case DW_OP_reg24:
3261 return "DW_OP_reg24";
3262 case DW_OP_reg25:
3263 return "DW_OP_reg25";
3264 case DW_OP_reg26:
3265 return "DW_OP_reg26";
3266 case DW_OP_reg27:
3267 return "DW_OP_reg27";
3268 case DW_OP_reg28:
3269 return "DW_OP_reg28";
3270 case DW_OP_reg29:
3271 return "DW_OP_reg29";
3272 case DW_OP_reg30:
3273 return "DW_OP_reg30";
3274 case DW_OP_reg31:
3275 return "DW_OP_reg31";
3276 case DW_OP_breg0:
3277 return "DW_OP_breg0";
3278 case DW_OP_breg1:
3279 return "DW_OP_breg1";
3280 case DW_OP_breg2:
3281 return "DW_OP_breg2";
3282 case DW_OP_breg3:
3283 return "DW_OP_breg3";
3284 case DW_OP_breg4:
3285 return "DW_OP_breg4";
3286 case DW_OP_breg5:
3287 return "DW_OP_breg5";
3288 case DW_OP_breg6:
3289 return "DW_OP_breg6";
3290 case DW_OP_breg7:
3291 return "DW_OP_breg7";
3292 case DW_OP_breg8:
3293 return "DW_OP_breg8";
3294 case DW_OP_breg9:
3295 return "DW_OP_breg9";
3296 case DW_OP_breg10:
3297 return "DW_OP_breg10";
3298 case DW_OP_breg11:
3299 return "DW_OP_breg11";
3300 case DW_OP_breg12:
3301 return "DW_OP_breg12";
3302 case DW_OP_breg13:
3303 return "DW_OP_breg13";
3304 case DW_OP_breg14:
3305 return "DW_OP_breg14";
3306 case DW_OP_breg15:
3307 return "DW_OP_breg15";
3308 case DW_OP_breg16:
3309 return "DW_OP_breg16";
3310 case DW_OP_breg17:
3311 return "DW_OP_breg17";
3312 case DW_OP_breg18:
3313 return "DW_OP_breg18";
3314 case DW_OP_breg19:
3315 return "DW_OP_breg19";
3316 case DW_OP_breg20:
3317 return "DW_OP_breg20";
3318 case DW_OP_breg21:
3319 return "DW_OP_breg21";
3320 case DW_OP_breg22:
3321 return "DW_OP_breg22";
3322 case DW_OP_breg23:
3323 return "DW_OP_breg23";
3324 case DW_OP_breg24:
3325 return "DW_OP_breg24";
3326 case DW_OP_breg25:
3327 return "DW_OP_breg25";
3328 case DW_OP_breg26:
3329 return "DW_OP_breg26";
3330 case DW_OP_breg27:
3331 return "DW_OP_breg27";
3332 case DW_OP_breg28:
3333 return "DW_OP_breg28";
3334 case DW_OP_breg29:
3335 return "DW_OP_breg29";
3336 case DW_OP_breg30:
3337 return "DW_OP_breg30";
3338 case DW_OP_breg31:
3339 return "DW_OP_breg31";
3340 case DW_OP_regx:
3341 return "DW_OP_regx";
3342 case DW_OP_fbreg:
3343 return "DW_OP_fbreg";
3344 case DW_OP_bregx:
3345 return "DW_OP_bregx";
3346 case DW_OP_piece:
3347 return "DW_OP_piece";
3348 case DW_OP_deref_size:
3349 return "DW_OP_deref_size";
3350 case DW_OP_xderef_size:
3351 return "DW_OP_xderef_size";
3352 case DW_OP_nop:
3353 return "DW_OP_nop";
3354 default:
3355 return "OP_<unknown>";
3359 /* Convert a DWARF type code into its string name. */
3361 #if 0
3362 static const char *
3363 dwarf_type_encoding_name (enc)
3364 register unsigned enc;
3366 switch (enc)
3368 case DW_ATE_address:
3369 return "DW_ATE_address";
3370 case DW_ATE_boolean:
3371 return "DW_ATE_boolean";
3372 case DW_ATE_complex_float:
3373 return "DW_ATE_complex_float";
3374 case DW_ATE_float:
3375 return "DW_ATE_float";
3376 case DW_ATE_signed:
3377 return "DW_ATE_signed";
3378 case DW_ATE_signed_char:
3379 return "DW_ATE_signed_char";
3380 case DW_ATE_unsigned:
3381 return "DW_ATE_unsigned";
3382 case DW_ATE_unsigned_char:
3383 return "DW_ATE_unsigned_char";
3384 default:
3385 return "DW_ATE_<unknown>";
3388 #endif
3390 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3391 instance of an inlined instance of a decl 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 decl_ultimate_origin (decl)
3398 register tree decl;
3400 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3401 nodes in the function to point to themselves; ignore that if
3402 we're trying to output the abstract instance of this function. */
3403 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
3404 return NULL_TREE;
3406 #ifdef ENABLE_CHECKING
3407 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
3408 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3409 most distant ancestor, this should never happen. */
3410 abort ();
3411 #endif
3413 return DECL_ABSTRACT_ORIGIN (decl);
3416 /* Determine the "ultimate origin" of a block. The block may be an inlined
3417 instance of an inlined instance of a block which is local to an inline
3418 function, so we have to trace all of the way back through the origin chain
3419 to find out what sort of node actually served as the original seed for the
3420 given block. */
3422 static tree
3423 block_ultimate_origin (block)
3424 register tree block;
3426 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3428 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
3429 nodes in the function to point to themselves; ignore that if
3430 we're trying to output the abstract instance of this function. */
3431 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
3432 return NULL_TREE;
3434 if (immediate_origin == NULL_TREE)
3435 return NULL_TREE;
3436 else
3438 register tree ret_val;
3439 register tree lookahead = immediate_origin;
3443 ret_val = lookahead;
3444 lookahead = (TREE_CODE (ret_val) == BLOCK)
3445 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3446 : NULL;
3448 while (lookahead != NULL && lookahead != ret_val);
3450 return ret_val;
3454 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3455 of a virtual function may refer to a base class, so we check the 'this'
3456 parameter. */
3458 static tree
3459 decl_class_context (decl)
3460 tree decl;
3462 tree context = NULL_TREE;
3464 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3465 context = DECL_CONTEXT (decl);
3466 else
3467 context = TYPE_MAIN_VARIANT
3468 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3470 if (context && !TYPE_P (context))
3471 context = NULL_TREE;
3473 return context;
3476 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
3477 addition order, and correct that in add_sibling_attributes. */
3479 static inline void
3480 add_dwarf_attr (die, attr)
3481 register dw_die_ref die;
3482 register dw_attr_ref attr;
3484 if (die != NULL && attr != NULL)
3486 attr->dw_attr_next = die->die_attr;
3487 die->die_attr = attr;
3491 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
3492 static inline dw_val_class
3493 AT_class (a)
3494 dw_attr_ref a;
3496 return a->dw_attr_val.val_class;
3499 /* Add a flag value attribute to a DIE. */
3501 static inline void
3502 add_AT_flag (die, attr_kind, flag)
3503 register dw_die_ref die;
3504 register enum dwarf_attribute attr_kind;
3505 register unsigned flag;
3507 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3509 attr->dw_attr_next = NULL;
3510 attr->dw_attr = attr_kind;
3511 attr->dw_attr_val.val_class = dw_val_class_flag;
3512 attr->dw_attr_val.v.val_flag = flag;
3513 add_dwarf_attr (die, attr);
3516 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3517 static inline unsigned
3518 AT_flag (a)
3519 register dw_attr_ref a;
3521 if (a && AT_class (a) == dw_val_class_flag)
3522 return a->dw_attr_val.v.val_flag;
3524 return 0;
3527 /* Add a signed integer attribute value to a DIE. */
3529 static inline void
3530 add_AT_int (die, attr_kind, int_val)
3531 register dw_die_ref die;
3532 register enum dwarf_attribute attr_kind;
3533 register long int int_val;
3535 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3537 attr->dw_attr_next = NULL;
3538 attr->dw_attr = attr_kind;
3539 attr->dw_attr_val.val_class = dw_val_class_const;
3540 attr->dw_attr_val.v.val_int = int_val;
3541 add_dwarf_attr (die, attr);
3544 static inline long int AT_int PARAMS ((dw_attr_ref));
3545 static inline long int
3546 AT_int (a)
3547 register dw_attr_ref a;
3549 if (a && AT_class (a) == dw_val_class_const)
3550 return a->dw_attr_val.v.val_int;
3552 return 0;
3555 /* Add an unsigned integer attribute value to a DIE. */
3557 static inline void
3558 add_AT_unsigned (die, attr_kind, unsigned_val)
3559 register dw_die_ref die;
3560 register enum dwarf_attribute attr_kind;
3561 register unsigned long unsigned_val;
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_unsigned_const;
3568 attr->dw_attr_val.v.val_unsigned = unsigned_val;
3569 add_dwarf_attr (die, attr);
3572 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
3573 static inline unsigned long
3574 AT_unsigned (a)
3575 register dw_attr_ref a;
3577 if (a && AT_class (a) == dw_val_class_unsigned_const)
3578 return a->dw_attr_val.v.val_unsigned;
3580 return 0;
3583 /* Add an unsigned double integer attribute value to a DIE. */
3585 static inline void
3586 add_AT_long_long (die, attr_kind, val_hi, val_low)
3587 register dw_die_ref die;
3588 register enum dwarf_attribute attr_kind;
3589 register unsigned long val_hi;
3590 register unsigned long val_low;
3592 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3594 attr->dw_attr_next = NULL;
3595 attr->dw_attr = attr_kind;
3596 attr->dw_attr_val.val_class = dw_val_class_long_long;
3597 attr->dw_attr_val.v.val_long_long.hi = val_hi;
3598 attr->dw_attr_val.v.val_long_long.low = val_low;
3599 add_dwarf_attr (die, attr);
3602 /* Add a floating point attribute value to a DIE and return it. */
3604 static inline void
3605 add_AT_float (die, attr_kind, length, array)
3606 register dw_die_ref die;
3607 register enum dwarf_attribute attr_kind;
3608 register unsigned length;
3609 register long *array;
3611 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3613 attr->dw_attr_next = NULL;
3614 attr->dw_attr = attr_kind;
3615 attr->dw_attr_val.val_class = dw_val_class_float;
3616 attr->dw_attr_val.v.val_float.length = length;
3617 attr->dw_attr_val.v.val_float.array = array;
3618 add_dwarf_attr (die, attr);
3621 /* Add a string attribute value to a DIE. */
3623 static inline void
3624 add_AT_string (die, attr_kind, str)
3625 register dw_die_ref die;
3626 register enum dwarf_attribute attr_kind;
3627 register const char *str;
3629 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3631 attr->dw_attr_next = NULL;
3632 attr->dw_attr = attr_kind;
3633 attr->dw_attr_val.val_class = dw_val_class_str;
3634 attr->dw_attr_val.v.val_str = xstrdup (str);
3635 add_dwarf_attr (die, attr);
3638 static inline const char *AT_string PARAMS ((dw_attr_ref));
3639 static inline const char *
3640 AT_string (a)
3641 register dw_attr_ref a;
3643 if (a && AT_class (a) == dw_val_class_str)
3644 return a->dw_attr_val.v.val_str;
3646 return NULL;
3649 /* Add a DIE reference attribute value to a DIE. */
3651 static inline void
3652 add_AT_die_ref (die, attr_kind, targ_die)
3653 register dw_die_ref die;
3654 register enum dwarf_attribute attr_kind;
3655 register dw_die_ref targ_die;
3657 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3659 attr->dw_attr_next = NULL;
3660 attr->dw_attr = attr_kind;
3661 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3662 attr->dw_attr_val.v.val_die_ref = targ_die;
3663 add_dwarf_attr (die, attr);
3666 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
3667 static inline dw_die_ref
3668 AT_ref (a)
3669 register dw_attr_ref a;
3671 if (a && AT_class (a) == dw_val_class_die_ref)
3672 return a->dw_attr_val.v.val_die_ref;
3674 return NULL;
3677 /* Add an FDE reference attribute value to a DIE. */
3679 static inline void
3680 add_AT_fde_ref (die, attr_kind, targ_fde)
3681 register dw_die_ref die;
3682 register enum dwarf_attribute attr_kind;
3683 register unsigned targ_fde;
3685 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3687 attr->dw_attr_next = NULL;
3688 attr->dw_attr = attr_kind;
3689 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
3690 attr->dw_attr_val.v.val_fde_index = targ_fde;
3691 add_dwarf_attr (die, attr);
3694 /* Add a location description attribute value to a DIE. */
3696 static inline void
3697 add_AT_loc (die, attr_kind, loc)
3698 register dw_die_ref die;
3699 register enum dwarf_attribute attr_kind;
3700 register dw_loc_descr_ref loc;
3702 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3704 attr->dw_attr_next = NULL;
3705 attr->dw_attr = attr_kind;
3706 attr->dw_attr_val.val_class = dw_val_class_loc;
3707 attr->dw_attr_val.v.val_loc = loc;
3708 add_dwarf_attr (die, attr);
3711 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
3712 static inline dw_loc_descr_ref
3713 AT_loc (a)
3714 register dw_attr_ref a;
3716 if (a && AT_class (a) == dw_val_class_loc)
3717 return a->dw_attr_val.v.val_loc;
3719 return NULL;
3722 /* Add an address constant attribute value to a DIE. */
3724 static inline void
3725 add_AT_addr (die, attr_kind, addr)
3726 register dw_die_ref die;
3727 register enum dwarf_attribute attr_kind;
3728 rtx addr;
3730 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3732 attr->dw_attr_next = NULL;
3733 attr->dw_attr = attr_kind;
3734 attr->dw_attr_val.val_class = dw_val_class_addr;
3735 attr->dw_attr_val.v.val_addr = addr;
3736 add_dwarf_attr (die, attr);
3739 static inline rtx AT_addr PARAMS ((dw_attr_ref));
3740 static inline rtx
3741 AT_addr (a)
3742 register dw_attr_ref a;
3744 if (a && AT_class (a) == dw_val_class_addr)
3745 return a->dw_attr_val.v.val_addr;
3747 return NULL;
3750 /* Add a label identifier attribute value to a DIE. */
3752 static inline void
3753 add_AT_lbl_id (die, attr_kind, lbl_id)
3754 register dw_die_ref die;
3755 register enum dwarf_attribute attr_kind;
3756 register char *lbl_id;
3758 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3760 attr->dw_attr_next = NULL;
3761 attr->dw_attr = attr_kind;
3762 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
3763 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
3764 add_dwarf_attr (die, attr);
3767 /* Add a section offset attribute value to a DIE. */
3769 static inline void
3770 add_AT_lbl_offset (die, attr_kind, label)
3771 register dw_die_ref die;
3772 register enum dwarf_attribute attr_kind;
3773 register char *label;
3775 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3777 attr->dw_attr_next = NULL;
3778 attr->dw_attr = attr_kind;
3779 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
3780 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
3781 add_dwarf_attr (die, attr);
3785 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
3786 static inline const char *
3787 AT_lbl (a)
3788 register dw_attr_ref a;
3790 if (a && (AT_class (a) == dw_val_class_lbl_id
3791 || AT_class (a) == dw_val_class_lbl_offset))
3792 return a->dw_attr_val.v.val_lbl_id;
3794 return NULL;
3797 /* Get the attribute of type attr_kind. */
3799 static inline dw_attr_ref
3800 get_AT (die, attr_kind)
3801 register dw_die_ref die;
3802 register enum dwarf_attribute attr_kind;
3804 register dw_attr_ref a;
3805 register dw_die_ref spec = NULL;
3807 if (die != NULL)
3809 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3811 if (a->dw_attr == attr_kind)
3812 return a;
3814 if (a->dw_attr == DW_AT_specification
3815 || a->dw_attr == DW_AT_abstract_origin)
3816 spec = AT_ref (a);
3819 if (spec)
3820 return get_AT (spec, attr_kind);
3823 return NULL;
3826 /* Return the "low pc" attribute value, typically associated with
3827 a subprogram DIE. Return null if the "low pc" attribute is
3828 either not prsent, or if it cannot be represented as an
3829 assembler label identifier. */
3831 static inline const char *
3832 get_AT_low_pc (die)
3833 register dw_die_ref die;
3835 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
3836 return AT_lbl (a);
3839 /* Return the "high pc" attribute value, typically associated with
3840 a subprogram DIE. Return null if the "high pc" attribute is
3841 either not prsent, or if it cannot be represented as an
3842 assembler label identifier. */
3844 static inline const char *
3845 get_AT_hi_pc (die)
3846 register dw_die_ref die;
3848 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
3849 return AT_lbl (a);
3852 /* Return the value of the string attribute designated by ATTR_KIND, or
3853 NULL if it is not present. */
3855 static inline const char *
3856 get_AT_string (die, attr_kind)
3857 register dw_die_ref die;
3858 register enum dwarf_attribute attr_kind;
3860 register dw_attr_ref a = get_AT (die, attr_kind);
3861 return AT_string (a);
3864 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3865 if it is not present. */
3867 static inline int
3868 get_AT_flag (die, attr_kind)
3869 register dw_die_ref die;
3870 register enum dwarf_attribute attr_kind;
3872 register dw_attr_ref a = get_AT (die, attr_kind);
3873 return AT_flag (a);
3876 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3877 if it is not present. */
3879 static inline unsigned
3880 get_AT_unsigned (die, attr_kind)
3881 register dw_die_ref die;
3882 register enum dwarf_attribute attr_kind;
3884 register dw_attr_ref a = get_AT (die, attr_kind);
3885 return AT_unsigned (a);
3888 static inline dw_die_ref
3889 get_AT_ref (die, attr_kind)
3890 dw_die_ref die;
3891 register enum dwarf_attribute attr_kind;
3893 register dw_attr_ref a = get_AT (die, attr_kind);
3894 return AT_ref (a);
3897 static inline int
3898 is_c_family ()
3900 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3902 return (lang == DW_LANG_C || lang == DW_LANG_C89
3903 || lang == DW_LANG_C_plus_plus);
3906 static inline int
3907 is_fortran ()
3909 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3911 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3914 /* Free up the memory used by A. */
3916 static inline void free_AT PARAMS ((dw_attr_ref));
3917 static inline void
3918 free_AT (a)
3919 dw_attr_ref a;
3921 switch (AT_class (a))
3923 case dw_val_class_str:
3924 case dw_val_class_lbl_id:
3925 case dw_val_class_lbl_offset:
3926 free (a->dw_attr_val.v.val_str);
3927 break;
3929 default:
3930 break;
3933 free (a);
3936 /* Remove the specified attribute if present. */
3938 static void
3939 remove_AT (die, attr_kind)
3940 register dw_die_ref die;
3941 register enum dwarf_attribute attr_kind;
3943 register dw_attr_ref *p;
3944 register dw_attr_ref removed = NULL;
3946 if (die != NULL)
3948 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
3949 if ((*p)->dw_attr == attr_kind)
3951 removed = *p;
3952 *p = (*p)->dw_attr_next;
3953 break;
3956 if (removed != 0)
3957 free_AT (removed);
3961 /* Free up the memory used by DIE. */
3963 static inline void free_die PARAMS ((dw_die_ref));
3964 static inline void
3965 free_die (die)
3966 dw_die_ref die;
3968 remove_children (die);
3969 free (die);
3972 /* Discard the children of this DIE. */
3974 static void
3975 remove_children (die)
3976 register dw_die_ref die;
3978 register dw_die_ref child_die = die->die_child;
3980 die->die_child = NULL;
3982 while (child_die != NULL)
3984 register dw_die_ref tmp_die = child_die;
3985 register dw_attr_ref a;
3987 child_die = child_die->die_sib;
3989 for (a = tmp_die->die_attr; a != NULL; )
3991 register dw_attr_ref tmp_a = a;
3993 a = a->dw_attr_next;
3994 free_AT (tmp_a);
3997 free_die (tmp_die);
4001 /* Add a child DIE below its parent. We build the lists up in reverse
4002 addition order, and correct that in add_sibling_attributes. */
4004 static inline void
4005 add_child_die (die, child_die)
4006 register dw_die_ref die;
4007 register dw_die_ref child_die;
4009 if (die != NULL && child_die != NULL)
4011 if (die == child_die)
4012 abort ();
4013 child_die->die_parent = die;
4014 child_die->die_sib = die->die_child;
4015 die->die_child = child_die;
4019 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4020 is the specification, to the front of PARENT's list of children. */
4022 static void
4023 splice_child_die (parent, child)
4024 dw_die_ref parent, child;
4026 dw_die_ref *p;
4028 /* We want the declaration DIE from inside the class, not the
4029 specification DIE at toplevel. */
4030 if (child->die_parent != parent)
4032 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4033 if (tmp)
4034 child = tmp;
4037 if (child->die_parent != parent
4038 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4039 abort ();
4041 for (p = &(parent->die_child); *p; p = &((*p)->die_sib))
4042 if (*p == child)
4044 *p = child->die_sib;
4045 break;
4048 child->die_sib = parent->die_child;
4049 parent->die_child = child;
4052 /* Return a pointer to a newly created DIE node. */
4054 static inline dw_die_ref
4055 new_die (tag_value, parent_die)
4056 register enum dwarf_tag tag_value;
4057 register dw_die_ref parent_die;
4059 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4061 die->die_tag = tag_value;
4062 die->die_abbrev = 0;
4063 die->die_offset = 0;
4064 die->die_child = NULL;
4065 die->die_parent = NULL;
4066 die->die_sib = NULL;
4067 die->die_attr = NULL;
4069 if (parent_die != NULL)
4070 add_child_die (parent_die, die);
4071 else
4073 limbo_die_node *limbo_node;
4075 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4076 limbo_node->die = die;
4077 limbo_node->next = limbo_die_list;
4078 limbo_die_list = limbo_node;
4081 return die;
4084 /* Return the DIE associated with the given type specifier. */
4086 static inline dw_die_ref
4087 lookup_type_die (type)
4088 register tree type;
4090 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4093 /* Equate a DIE to a given type specifier. */
4095 static inline void
4096 equate_type_number_to_die (type, type_die)
4097 register tree type;
4098 register dw_die_ref type_die;
4100 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4103 /* Return the DIE associated with a given declaration. */
4105 static inline dw_die_ref
4106 lookup_decl_die (decl)
4107 register tree decl;
4109 register unsigned decl_id = DECL_UID (decl);
4111 return (decl_id < decl_die_table_in_use
4112 ? decl_die_table[decl_id] : NULL);
4115 /* Equate a DIE to a particular declaration. */
4117 static void
4118 equate_decl_number_to_die (decl, decl_die)
4119 register tree decl;
4120 register dw_die_ref decl_die;
4122 register unsigned decl_id = DECL_UID (decl);
4123 register unsigned num_allocated;
4125 if (decl_id >= decl_die_table_allocated)
4127 num_allocated
4128 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4129 / DECL_DIE_TABLE_INCREMENT)
4130 * DECL_DIE_TABLE_INCREMENT;
4132 decl_die_table
4133 = (dw_die_ref *) xrealloc (decl_die_table,
4134 sizeof (dw_die_ref) * num_allocated);
4136 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4137 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4138 decl_die_table_allocated = num_allocated;
4141 if (decl_id >= decl_die_table_in_use)
4142 decl_die_table_in_use = (decl_id + 1);
4144 decl_die_table[decl_id] = decl_die;
4147 /* Return a pointer to a newly allocated location description. Location
4148 descriptions are simple expression terms that can be strung
4149 together to form more complicated location (address) descriptions. */
4151 static inline dw_loc_descr_ref
4152 new_loc_descr (op, oprnd1, oprnd2)
4153 register enum dwarf_location_atom op;
4154 register unsigned long oprnd1;
4155 register unsigned long oprnd2;
4157 register dw_loc_descr_ref descr
4158 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
4160 descr->dw_loc_next = NULL;
4161 descr->dw_loc_opc = op;
4162 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4163 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4164 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4165 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4167 return descr;
4170 /* Add a location description term to a location description expression. */
4172 static inline void
4173 add_loc_descr (list_head, descr)
4174 register dw_loc_descr_ref *list_head;
4175 register dw_loc_descr_ref descr;
4177 register dw_loc_descr_ref *d;
4179 /* Find the end of the chain. */
4180 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4183 *d = descr;
4186 /* Keep track of the number of spaces used to indent the
4187 output of the debugging routines that print the structure of
4188 the DIE internal representation. */
4189 static int print_indent;
4191 /* Indent the line the number of spaces given by print_indent. */
4193 static inline void
4194 print_spaces (outfile)
4195 FILE *outfile;
4197 fprintf (outfile, "%*s", print_indent, "");
4200 /* Print the information associated with a given DIE, and its children.
4201 This routine is a debugging aid only. */
4203 static void
4204 print_die (die, outfile)
4205 dw_die_ref die;
4206 FILE *outfile;
4208 register dw_attr_ref a;
4209 register dw_die_ref c;
4211 print_spaces (outfile);
4212 fprintf (outfile, "DIE %4lu: %s\n",
4213 die->die_offset, dwarf_tag_name (die->die_tag));
4214 print_spaces (outfile);
4215 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4216 fprintf (outfile, " offset: %lu\n", die->die_offset);
4218 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4220 print_spaces (outfile);
4221 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4223 switch (AT_class (a))
4225 case dw_val_class_addr:
4226 fprintf (outfile, "address");
4227 break;
4228 case dw_val_class_loc:
4229 fprintf (outfile, "location descriptor");
4230 break;
4231 case dw_val_class_const:
4232 fprintf (outfile, "%ld", AT_int (a));
4233 break;
4234 case dw_val_class_unsigned_const:
4235 fprintf (outfile, "%lu", AT_unsigned (a));
4236 break;
4237 case dw_val_class_long_long:
4238 fprintf (outfile, "constant (%lu,%lu)",
4239 a->dw_attr_val.v.val_long_long.hi,
4240 a->dw_attr_val.v.val_long_long.low);
4241 break;
4242 case dw_val_class_float:
4243 fprintf (outfile, "floating-point constant");
4244 break;
4245 case dw_val_class_flag:
4246 fprintf (outfile, "%u", AT_flag (a));
4247 break;
4248 case dw_val_class_die_ref:
4249 if (AT_ref (a) != NULL)
4250 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4251 else
4252 fprintf (outfile, "die -> <null>");
4253 break;
4254 case dw_val_class_lbl_id:
4255 case dw_val_class_lbl_offset:
4256 fprintf (outfile, "label: %s", AT_lbl (a));
4257 break;
4258 case dw_val_class_str:
4259 if (AT_string (a) != NULL)
4260 fprintf (outfile, "\"%s\"", AT_string (a));
4261 else
4262 fprintf (outfile, "<null>");
4263 break;
4264 default:
4265 break;
4268 fprintf (outfile, "\n");
4271 if (die->die_child != NULL)
4273 print_indent += 4;
4274 for (c = die->die_child; c != NULL; c = c->die_sib)
4275 print_die (c, outfile);
4277 print_indent -= 4;
4281 /* Print the contents of the source code line number correspondence table.
4282 This routine is a debugging aid only. */
4284 static void
4285 print_dwarf_line_table (outfile)
4286 FILE *outfile;
4288 register unsigned i;
4289 register dw_line_info_ref line_info;
4291 fprintf (outfile, "\n\nDWARF source line information\n");
4292 for (i = 1; i < line_info_table_in_use; ++i)
4294 line_info = &line_info_table[i];
4295 fprintf (outfile, "%5d: ", i);
4296 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4297 fprintf (outfile, "%6ld", line_info->dw_line_num);
4298 fprintf (outfile, "\n");
4301 fprintf (outfile, "\n\n");
4304 /* Print the information collected for a given DIE. */
4306 void
4307 debug_dwarf_die (die)
4308 dw_die_ref die;
4310 print_die (die, stderr);
4313 /* Print all DWARF information collected for the compilation unit.
4314 This routine is a debugging aid only. */
4316 void
4317 debug_dwarf ()
4319 print_indent = 0;
4320 print_die (comp_unit_die, stderr);
4321 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4322 print_dwarf_line_table (stderr);
4325 /* We build up the lists of children and attributes by pushing new ones
4326 onto the beginning of the list. Reverse the lists for DIE so that
4327 they are in order of addition. */
4329 static void
4330 reverse_die_lists (die)
4331 register dw_die_ref die;
4333 register dw_die_ref c, cp, cn;
4334 register dw_attr_ref a, ap, an;
4336 for (a = die->die_attr, ap = 0; a; a = an)
4338 an = a->dw_attr_next;
4339 a->dw_attr_next = ap;
4340 ap = a;
4342 die->die_attr = ap;
4344 for (c = die->die_child, cp = 0; c; c = cn)
4346 cn = c->die_sib;
4347 c->die_sib = cp;
4348 cp = c;
4350 die->die_child = cp;
4353 /* Traverse the DIE, reverse its lists of attributes and children, and
4354 add a sibling attribute if it may have the effect of speeding up
4355 access to siblings. To save some space, avoid generating sibling
4356 attributes for DIE's without children. */
4358 static void
4359 add_sibling_attributes (die)
4360 register dw_die_ref die;
4362 register dw_die_ref c;
4364 reverse_die_lists (die);
4366 if (die != comp_unit_die && die->die_sib && die->die_child != NULL)
4367 /* Add the sibling link to the front of the attribute list. */
4368 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
4370 for (c = die->die_child; c != NULL; c = c->die_sib)
4371 add_sibling_attributes (c);
4374 /* The format of each DIE (and its attribute value pairs)
4375 is encoded in an abbreviation table. This routine builds the
4376 abbreviation table and assigns a unique abbreviation id for
4377 each abbreviation entry. The children of each die are visited
4378 recursively. */
4380 static void
4381 build_abbrev_table (die)
4382 register dw_die_ref die;
4384 register unsigned long abbrev_id;
4385 register unsigned long n_alloc;
4386 register dw_die_ref c;
4387 register dw_attr_ref d_attr, a_attr;
4388 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4390 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4392 if (abbrev->die_tag == die->die_tag)
4394 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
4396 a_attr = abbrev->die_attr;
4397 d_attr = die->die_attr;
4399 while (a_attr != NULL && d_attr != NULL)
4401 if ((a_attr->dw_attr != d_attr->dw_attr)
4402 || (value_format (a_attr) != value_format (d_attr)))
4403 break;
4405 a_attr = a_attr->dw_attr_next;
4406 d_attr = d_attr->dw_attr_next;
4409 if (a_attr == NULL && d_attr == NULL)
4410 break;
4415 if (abbrev_id >= abbrev_die_table_in_use)
4417 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
4419 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
4420 abbrev_die_table
4421 = (dw_die_ref *) xrealloc (abbrev_die_table,
4422 sizeof (dw_die_ref) * n_alloc);
4424 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
4425 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
4426 abbrev_die_table_allocated = n_alloc;
4429 ++abbrev_die_table_in_use;
4430 abbrev_die_table[abbrev_id] = die;
4433 die->die_abbrev = abbrev_id;
4434 for (c = die->die_child; c != NULL; c = c->die_sib)
4435 build_abbrev_table (c);
4438 /* Return the size of a string, including the null byte.
4440 This used to treat backslashes as escapes, and hence they were not included
4441 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
4442 which treats a backslash as a backslash, escaping it if necessary, and hence
4443 we must include them in the count. */
4445 static unsigned long
4446 size_of_string (str)
4447 register const char *str;
4449 return strlen (str) + 1;
4452 /* Return the size of a location descriptor. */
4454 static unsigned long
4455 size_of_loc_descr (loc)
4456 register dw_loc_descr_ref loc;
4458 register unsigned long size = 1;
4460 switch (loc->dw_loc_opc)
4462 case DW_OP_addr:
4463 size += PTR_SIZE;
4464 break;
4465 case DW_OP_const1u:
4466 case DW_OP_const1s:
4467 size += 1;
4468 break;
4469 case DW_OP_const2u:
4470 case DW_OP_const2s:
4471 size += 2;
4472 break;
4473 case DW_OP_const4u:
4474 case DW_OP_const4s:
4475 size += 4;
4476 break;
4477 case DW_OP_const8u:
4478 case DW_OP_const8s:
4479 size += 8;
4480 break;
4481 case DW_OP_constu:
4482 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4483 break;
4484 case DW_OP_consts:
4485 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4486 break;
4487 case DW_OP_pick:
4488 size += 1;
4489 break;
4490 case DW_OP_plus_uconst:
4491 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4492 break;
4493 case DW_OP_skip:
4494 case DW_OP_bra:
4495 size += 2;
4496 break;
4497 case DW_OP_breg0:
4498 case DW_OP_breg1:
4499 case DW_OP_breg2:
4500 case DW_OP_breg3:
4501 case DW_OP_breg4:
4502 case DW_OP_breg5:
4503 case DW_OP_breg6:
4504 case DW_OP_breg7:
4505 case DW_OP_breg8:
4506 case DW_OP_breg9:
4507 case DW_OP_breg10:
4508 case DW_OP_breg11:
4509 case DW_OP_breg12:
4510 case DW_OP_breg13:
4511 case DW_OP_breg14:
4512 case DW_OP_breg15:
4513 case DW_OP_breg16:
4514 case DW_OP_breg17:
4515 case DW_OP_breg18:
4516 case DW_OP_breg19:
4517 case DW_OP_breg20:
4518 case DW_OP_breg21:
4519 case DW_OP_breg22:
4520 case DW_OP_breg23:
4521 case DW_OP_breg24:
4522 case DW_OP_breg25:
4523 case DW_OP_breg26:
4524 case DW_OP_breg27:
4525 case DW_OP_breg28:
4526 case DW_OP_breg29:
4527 case DW_OP_breg30:
4528 case DW_OP_breg31:
4529 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4530 break;
4531 case DW_OP_regx:
4532 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4533 break;
4534 case DW_OP_fbreg:
4535 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4536 break;
4537 case DW_OP_bregx:
4538 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4539 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4540 break;
4541 case DW_OP_piece:
4542 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4543 break;
4544 case DW_OP_deref_size:
4545 case DW_OP_xderef_size:
4546 size += 1;
4547 break;
4548 default:
4549 break;
4552 return size;
4555 /* Return the size of a series of location descriptors. */
4557 static unsigned long
4558 size_of_locs (loc)
4559 register dw_loc_descr_ref loc;
4561 register unsigned long size = 0;
4563 for (; loc != NULL; loc = loc->dw_loc_next)
4564 size += size_of_loc_descr (loc);
4566 return size;
4569 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4571 static int
4572 constant_size (value)
4573 long unsigned value;
4575 int log;
4577 if (value == 0)
4578 log = 0;
4579 else
4580 log = floor_log2 (value);
4582 log = log / 8;
4583 log = 1 << (floor_log2 (log) + 1);
4585 return log;
4588 /* Return the size of a DIE, as it is represented in the
4589 .debug_info section. */
4591 static unsigned long
4592 size_of_die (die)
4593 register dw_die_ref die;
4595 register unsigned long size = 0;
4596 register dw_attr_ref a;
4598 size += size_of_uleb128 (die->die_abbrev);
4599 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4601 switch (AT_class (a))
4603 case dw_val_class_addr:
4604 size += PTR_SIZE;
4605 break;
4606 case dw_val_class_loc:
4608 register unsigned long lsize = size_of_locs (AT_loc (a));
4610 /* Block length. */
4611 size += constant_size (lsize);
4612 size += lsize;
4614 break;
4615 case dw_val_class_const:
4616 size += 4;
4617 break;
4618 case dw_val_class_unsigned_const:
4619 size += constant_size (AT_unsigned (a));
4620 break;
4621 case dw_val_class_long_long:
4622 size += 1 + 8; /* block */
4623 break;
4624 case dw_val_class_float:
4625 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
4626 break;
4627 case dw_val_class_flag:
4628 size += 1;
4629 break;
4630 case dw_val_class_die_ref:
4631 size += DWARF_OFFSET_SIZE;
4632 break;
4633 case dw_val_class_fde_ref:
4634 size += DWARF_OFFSET_SIZE;
4635 break;
4636 case dw_val_class_lbl_id:
4637 size += PTR_SIZE;
4638 break;
4639 case dw_val_class_lbl_offset:
4640 size += DWARF_OFFSET_SIZE;
4641 break;
4642 case dw_val_class_str:
4643 size += size_of_string (AT_string (a));
4644 break;
4645 default:
4646 abort ();
4650 return size;
4653 /* Size the debugging information associated with a given DIE.
4654 Visits the DIE's children recursively. Updates the global
4655 variable next_die_offset, on each time through. Uses the
4656 current value of next_die_offset to update the die_offset
4657 field in each DIE. */
4659 static void
4660 calc_die_sizes (die)
4661 dw_die_ref die;
4663 register dw_die_ref c;
4664 die->die_offset = next_die_offset;
4665 next_die_offset += size_of_die (die);
4667 for (c = die->die_child; c != NULL; c = c->die_sib)
4668 calc_die_sizes (c);
4670 if (die->die_child != NULL)
4671 /* Count the null byte used to terminate sibling lists. */
4672 next_die_offset += 1;
4675 /* Return the size of the line information prolog generated for the
4676 compilation unit. */
4678 static unsigned long
4679 size_of_line_prolog ()
4681 register unsigned long size;
4682 register unsigned long ft_index;
4684 size = DWARF_LINE_PROLOG_HEADER_SIZE;
4686 /* Count the size of the table giving number of args for each
4687 standard opcode. */
4688 size += DWARF_LINE_OPCODE_BASE - 1;
4690 /* Include directory table is empty (at present). Count only the
4691 null byte used to terminate the table. */
4692 size += 1;
4694 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4696 /* File name entry. */
4697 size += size_of_string (file_table[ft_index]);
4699 /* Include directory index. */
4700 size += size_of_uleb128 (0);
4702 /* Modification time. */
4703 size += size_of_uleb128 (0);
4705 /* File length in bytes. */
4706 size += size_of_uleb128 (0);
4709 /* Count the file table terminator. */
4710 size += 1;
4711 return size;
4714 /* Return the size of the .debug_pubnames table generated for the
4715 compilation unit. */
4717 static unsigned long
4718 size_of_pubnames ()
4720 register unsigned long size;
4721 register unsigned i;
4723 size = DWARF_PUBNAMES_HEADER_SIZE;
4724 for (i = 0; i < pubname_table_in_use; ++i)
4726 register pubname_ref p = &pubname_table[i];
4727 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
4730 size += DWARF_OFFSET_SIZE;
4731 return size;
4734 /* Return the size of the information in the .debug_aranges section. */
4736 static unsigned long
4737 size_of_aranges ()
4739 register unsigned long size;
4741 size = DWARF_ARANGES_HEADER_SIZE;
4743 /* Count the address/length pair for this compilation unit. */
4744 size += 2 * PTR_SIZE;
4745 size += 2 * PTR_SIZE * arange_table_in_use;
4747 /* Count the two zero words used to terminated the address range table. */
4748 size += 2 * PTR_SIZE;
4749 return size;
4752 /* Select the encoding of an attribute value. */
4754 static enum dwarf_form
4755 value_format (a)
4756 dw_attr_ref a;
4758 switch (a->dw_attr_val.val_class)
4760 case dw_val_class_addr:
4761 return DW_FORM_addr;
4762 case dw_val_class_loc:
4763 switch (constant_size (size_of_locs (AT_loc (a))))
4765 case 1:
4766 return DW_FORM_block1;
4767 case 2:
4768 return DW_FORM_block2;
4769 default:
4770 abort ();
4772 case dw_val_class_const:
4773 return DW_FORM_data4;
4774 case dw_val_class_unsigned_const:
4775 switch (constant_size (AT_unsigned (a)))
4777 case 1:
4778 return DW_FORM_data1;
4779 case 2:
4780 return DW_FORM_data2;
4781 case 4:
4782 return DW_FORM_data4;
4783 case 8:
4784 return DW_FORM_data8;
4785 default:
4786 abort ();
4788 case dw_val_class_long_long:
4789 return DW_FORM_block1;
4790 case dw_val_class_float:
4791 return DW_FORM_block1;
4792 case dw_val_class_flag:
4793 return DW_FORM_flag;
4794 case dw_val_class_die_ref:
4795 return DW_FORM_ref;
4796 case dw_val_class_fde_ref:
4797 return DW_FORM_data;
4798 case dw_val_class_lbl_id:
4799 return DW_FORM_addr;
4800 case dw_val_class_lbl_offset:
4801 return DW_FORM_data;
4802 case dw_val_class_str:
4803 return DW_FORM_string;
4804 default:
4805 abort ();
4809 /* Output the encoding of an attribute value. */
4811 static void
4812 output_value_format (a)
4813 dw_attr_ref a;
4815 enum dwarf_form form = value_format (a);
4817 output_uleb128 (form);
4818 if (flag_debug_asm)
4819 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
4821 fputc ('\n', asm_out_file);
4824 /* Output the .debug_abbrev section which defines the DIE abbreviation
4825 table. */
4827 static void
4828 output_abbrev_section ()
4830 unsigned long abbrev_id;
4832 dw_attr_ref a_attr;
4833 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4835 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4837 output_uleb128 (abbrev_id);
4838 if (flag_debug_asm)
4839 fprintf (asm_out_file, " (abbrev code)");
4841 fputc ('\n', asm_out_file);
4842 output_uleb128 (abbrev->die_tag);
4843 if (flag_debug_asm)
4844 fprintf (asm_out_file, " (TAG: %s)",
4845 dwarf_tag_name (abbrev->die_tag));
4847 fputc ('\n', asm_out_file);
4848 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
4849 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
4851 if (flag_debug_asm)
4852 fprintf (asm_out_file, "\t%s %s",
4853 ASM_COMMENT_START,
4854 (abbrev->die_child != NULL
4855 ? "DW_children_yes" : "DW_children_no"));
4857 fputc ('\n', asm_out_file);
4859 for (a_attr = abbrev->die_attr; a_attr != NULL;
4860 a_attr = a_attr->dw_attr_next)
4862 output_uleb128 (a_attr->dw_attr);
4863 if (flag_debug_asm)
4864 fprintf (asm_out_file, " (%s)",
4865 dwarf_attr_name (a_attr->dw_attr));
4867 fputc ('\n', asm_out_file);
4868 output_value_format (a_attr);
4871 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
4874 /* Terminate the table. */
4875 fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP);
4878 /* Output location description stack opcode's operands (if any). */
4880 static void
4881 output_loc_operands (loc)
4882 register dw_loc_descr_ref loc;
4884 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
4885 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
4887 switch (loc->dw_loc_opc)
4889 case DW_OP_addr:
4890 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
4891 fputc ('\n', asm_out_file);
4892 break;
4893 case DW_OP_const1u:
4894 case DW_OP_const1s:
4895 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4896 fputc ('\n', asm_out_file);
4897 break;
4898 case DW_OP_const2u:
4899 case DW_OP_const2s:
4900 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4901 fputc ('\n', asm_out_file);
4902 break;
4903 case DW_OP_const4u:
4904 case DW_OP_const4s:
4905 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
4906 fputc ('\n', asm_out_file);
4907 break;
4908 case DW_OP_const8u:
4909 case DW_OP_const8s:
4910 abort ();
4911 fputc ('\n', asm_out_file);
4912 break;
4913 case DW_OP_constu:
4914 output_uleb128 (val1->v.val_unsigned);
4915 fputc ('\n', asm_out_file);
4916 break;
4917 case DW_OP_consts:
4918 output_sleb128 (val1->v.val_int);
4919 fputc ('\n', asm_out_file);
4920 break;
4921 case DW_OP_pick:
4922 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
4923 fputc ('\n', asm_out_file);
4924 break;
4925 case DW_OP_plus_uconst:
4926 output_uleb128 (val1->v.val_unsigned);
4927 fputc ('\n', asm_out_file);
4928 break;
4929 case DW_OP_skip:
4930 case DW_OP_bra:
4931 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4932 fputc ('\n', asm_out_file);
4933 break;
4934 case DW_OP_breg0:
4935 case DW_OP_breg1:
4936 case DW_OP_breg2:
4937 case DW_OP_breg3:
4938 case DW_OP_breg4:
4939 case DW_OP_breg5:
4940 case DW_OP_breg6:
4941 case DW_OP_breg7:
4942 case DW_OP_breg8:
4943 case DW_OP_breg9:
4944 case DW_OP_breg10:
4945 case DW_OP_breg11:
4946 case DW_OP_breg12:
4947 case DW_OP_breg13:
4948 case DW_OP_breg14:
4949 case DW_OP_breg15:
4950 case DW_OP_breg16:
4951 case DW_OP_breg17:
4952 case DW_OP_breg18:
4953 case DW_OP_breg19:
4954 case DW_OP_breg20:
4955 case DW_OP_breg21:
4956 case DW_OP_breg22:
4957 case DW_OP_breg23:
4958 case DW_OP_breg24:
4959 case DW_OP_breg25:
4960 case DW_OP_breg26:
4961 case DW_OP_breg27:
4962 case DW_OP_breg28:
4963 case DW_OP_breg29:
4964 case DW_OP_breg30:
4965 case DW_OP_breg31:
4966 output_sleb128 (val1->v.val_int);
4967 fputc ('\n', asm_out_file);
4968 break;
4969 case DW_OP_regx:
4970 output_uleb128 (val1->v.val_unsigned);
4971 fputc ('\n', asm_out_file);
4972 break;
4973 case DW_OP_fbreg:
4974 output_sleb128 (val1->v.val_int);
4975 fputc ('\n', asm_out_file);
4976 break;
4977 case DW_OP_bregx:
4978 output_uleb128 (val1->v.val_unsigned);
4979 fputc ('\n', asm_out_file);
4980 output_sleb128 (val2->v.val_int);
4981 fputc ('\n', asm_out_file);
4982 break;
4983 case DW_OP_piece:
4984 output_uleb128 (val1->v.val_unsigned);
4985 fputc ('\n', asm_out_file);
4986 break;
4987 case DW_OP_deref_size:
4988 case DW_OP_xderef_size:
4989 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4990 fputc ('\n', asm_out_file);
4991 break;
4992 default:
4993 break;
4997 /* Output the DIE and its attributes. Called recursively to generate
4998 the definitions of each child DIE. */
5000 static void
5001 output_die (die)
5002 register dw_die_ref die;
5004 register dw_attr_ref a;
5005 register dw_die_ref c;
5006 register unsigned long size;
5007 register dw_loc_descr_ref loc;
5009 output_uleb128 (die->die_abbrev);
5010 if (flag_debug_asm)
5011 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5012 die->die_offset, dwarf_tag_name (die->die_tag));
5014 fputc ('\n', asm_out_file);
5016 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5018 switch (AT_class (a))
5020 case dw_val_class_addr:
5021 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
5022 break;
5024 case dw_val_class_loc:
5025 size = size_of_locs (AT_loc (a));
5027 /* Output the block length for this list of location operations. */
5028 switch (constant_size (size))
5030 case 1:
5031 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5032 break;
5033 case 2:
5034 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5035 break;
5036 default:
5037 abort ();
5040 if (flag_debug_asm)
5041 fprintf (asm_out_file, "\t%s %s",
5042 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5044 fputc ('\n', asm_out_file);
5045 for (loc = AT_loc (a); loc != NULL; loc = loc->dw_loc_next)
5047 /* Output the opcode. */
5048 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
5049 if (flag_debug_asm)
5050 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
5051 dwarf_stack_op_name (loc->dw_loc_opc));
5053 fputc ('\n', asm_out_file);
5055 /* Output the operand(s) (if any). */
5056 output_loc_operands (loc);
5058 break;
5060 case dw_val_class_const:
5061 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_int (a));
5062 break;
5064 case dw_val_class_unsigned_const:
5065 switch (constant_size (AT_unsigned (a)))
5067 case 1:
5068 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
5069 break;
5070 case 2:
5071 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
5072 break;
5073 case 4:
5074 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
5075 break;
5076 case 8:
5077 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5078 a->dw_attr_val.v.val_long_long.hi,
5079 a->dw_attr_val.v.val_long_long.low);
5080 break;
5081 default:
5082 abort ();
5084 break;
5086 case dw_val_class_long_long:
5087 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5088 if (flag_debug_asm)
5089 fprintf (asm_out_file, "\t%s %s",
5090 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5092 fputc ('\n', asm_out_file);
5093 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5094 a->dw_attr_val.v.val_long_long.hi,
5095 a->dw_attr_val.v.val_long_long.low);
5097 if (flag_debug_asm)
5098 fprintf (asm_out_file,
5099 "\t%s long long constant", ASM_COMMENT_START);
5101 fputc ('\n', asm_out_file);
5102 break;
5104 case dw_val_class_float:
5106 register unsigned int i;
5107 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5108 a->dw_attr_val.v.val_float.length * 4);
5109 if (flag_debug_asm)
5110 fprintf (asm_out_file, "\t%s %s",
5111 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5113 fputc ('\n', asm_out_file);
5114 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5116 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5117 a->dw_attr_val.v.val_float.array[i]);
5118 if (flag_debug_asm)
5119 fprintf (asm_out_file, "\t%s fp constant word %u",
5120 ASM_COMMENT_START, i);
5122 fputc ('\n', asm_out_file);
5124 break;
5127 case dw_val_class_flag:
5128 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
5129 break;
5131 case dw_val_class_die_ref:
5132 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
5133 break;
5135 case dw_val_class_fde_ref:
5137 char l1[20];
5138 ASM_GENERATE_INTERNAL_LABEL
5139 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5140 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5141 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5143 break;
5145 case dw_val_class_lbl_id:
5146 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
5147 break;
5149 case dw_val_class_lbl_offset:
5150 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
5151 break;
5153 case dw_val_class_str:
5154 if (flag_debug_asm)
5155 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
5156 else
5157 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
5158 (int) strlen (AT_string (a)) + 1);
5159 break;
5161 default:
5162 abort ();
5165 if (AT_class (a) != dw_val_class_loc
5166 && AT_class (a) != dw_val_class_long_long
5167 && AT_class (a) != dw_val_class_float)
5169 if (flag_debug_asm)
5170 fprintf (asm_out_file, "\t%s %s",
5171 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5173 fputc ('\n', asm_out_file);
5177 for (c = die->die_child; c != NULL; c = c->die_sib)
5178 output_die (c);
5180 if (die->die_child != NULL)
5182 /* Add null byte to terminate sibling list. */
5183 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5184 if (flag_debug_asm)
5185 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
5186 ASM_COMMENT_START, die->die_offset);
5188 fputc ('\n', asm_out_file);
5192 /* Output the compilation unit that appears at the beginning of the
5193 .debug_info section, and precedes the DIE descriptions. */
5195 static void
5196 output_compilation_unit_header ()
5198 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
5199 if (flag_debug_asm)
5200 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
5201 ASM_COMMENT_START);
5203 fputc ('\n', asm_out_file);
5204 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5205 if (flag_debug_asm)
5206 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
5208 fputc ('\n', asm_out_file);
5209 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
5210 if (flag_debug_asm)
5211 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
5212 ASM_COMMENT_START);
5214 fputc ('\n', asm_out_file);
5215 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5216 if (flag_debug_asm)
5217 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
5219 fputc ('\n', asm_out_file);
5222 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5223 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5224 argument list, and maybe the scope. */
5226 static const char *
5227 dwarf2_name (decl, scope)
5228 tree decl;
5229 int scope;
5231 return (*decl_printable_name) (decl, scope ? 1 : 0);
5234 /* Add a new entry to .debug_pubnames if appropriate. */
5236 static void
5237 add_pubname (decl, die)
5238 tree decl;
5239 dw_die_ref die;
5241 pubname_ref p;
5243 if (! TREE_PUBLIC (decl))
5244 return;
5246 if (pubname_table_in_use == pubname_table_allocated)
5248 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5249 pubname_table = (pubname_ref) xrealloc
5250 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5253 p = &pubname_table[pubname_table_in_use++];
5254 p->die = die;
5256 p->name = xstrdup (dwarf2_name (decl, 1));
5259 /* Output the public names table used to speed up access to externally
5260 visible names. For now, only generate entries for externally
5261 visible procedures. */
5263 static void
5264 output_pubnames ()
5266 register unsigned i;
5267 register unsigned long pubnames_length = size_of_pubnames ();
5269 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
5271 if (flag_debug_asm)
5272 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
5273 ASM_COMMENT_START);
5275 fputc ('\n', asm_out_file);
5276 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5278 if (flag_debug_asm)
5279 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5281 fputc ('\n', asm_out_file);
5282 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5283 if (flag_debug_asm)
5284 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5285 ASM_COMMENT_START);
5287 fputc ('\n', asm_out_file);
5288 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
5289 if (flag_debug_asm)
5290 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
5292 fputc ('\n', asm_out_file);
5293 for (i = 0; i < pubname_table_in_use; ++i)
5295 register pubname_ref pub = &pubname_table[i];
5297 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
5298 if (flag_debug_asm)
5299 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
5301 fputc ('\n', asm_out_file);
5303 if (flag_debug_asm)
5305 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5306 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5308 else
5310 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
5311 (int) strlen (pub->name) + 1);
5314 fputc ('\n', asm_out_file);
5317 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
5318 fputc ('\n', asm_out_file);
5321 /* Add a new entry to .debug_aranges if appropriate. */
5323 static void
5324 add_arange (decl, die)
5325 tree decl;
5326 dw_die_ref die;
5328 if (! DECL_SECTION_NAME (decl))
5329 return;
5331 if (arange_table_in_use == arange_table_allocated)
5333 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5334 arange_table
5335 = (arange_ref) xrealloc (arange_table,
5336 arange_table_allocated * sizeof (dw_die_ref));
5339 arange_table[arange_table_in_use++] = die;
5342 /* Output the information that goes into the .debug_aranges table.
5343 Namely, define the beginning and ending address range of the
5344 text section generated for this compilation unit. */
5346 static void
5347 output_aranges ()
5349 register unsigned i;
5350 register unsigned long aranges_length = size_of_aranges ();
5352 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
5353 if (flag_debug_asm)
5354 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
5355 ASM_COMMENT_START);
5357 fputc ('\n', asm_out_file);
5358 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5359 if (flag_debug_asm)
5360 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5362 fputc ('\n', asm_out_file);
5363 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5364 if (flag_debug_asm)
5365 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5366 ASM_COMMENT_START);
5368 fputc ('\n', asm_out_file);
5369 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5370 if (flag_debug_asm)
5371 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5373 fputc ('\n', asm_out_file);
5374 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5375 if (flag_debug_asm)
5376 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5377 ASM_COMMENT_START);
5379 fputc ('\n', asm_out_file);
5381 /* We need to align to twice the pointer size here. */
5382 if (DWARF_ARANGES_PAD_SIZE)
5384 /* Pad using a 2 bytes word so that padding is correct
5385 for any pointer size. */
5386 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
5387 for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2)
5388 fprintf (asm_out_file, ",0");
5389 if (flag_debug_asm)
5390 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5391 ASM_COMMENT_START, 2 * PTR_SIZE);
5394 fputc ('\n', asm_out_file);
5395 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
5396 if (flag_debug_asm)
5397 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5399 fputc ('\n', asm_out_file);
5400 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
5401 text_section_label);
5402 if (flag_debug_asm)
5403 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5405 fputc ('\n', asm_out_file);
5406 for (i = 0; i < arange_table_in_use; ++i)
5408 dw_die_ref die = arange_table[i];
5410 if (die->die_tag == DW_TAG_subprogram)
5411 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
5412 else
5414 /* A static variable; extract the symbol from DW_AT_location.
5415 Note that this code isn't currently hit, as we only emit
5416 aranges for functions (jason 9/23/99). */
5418 dw_attr_ref a = get_AT (die, DW_AT_location);
5419 dw_loc_descr_ref loc;
5420 if (! a || AT_class (a) != dw_val_class_loc)
5421 abort ();
5423 loc = AT_loc (a);
5424 if (loc->dw_loc_opc != DW_OP_addr)
5425 abort ();
5427 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
5428 loc->dw_loc_oprnd1.v.val_addr);
5431 if (flag_debug_asm)
5432 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5434 fputc ('\n', asm_out_file);
5435 if (die->die_tag == DW_TAG_subprogram)
5436 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
5437 get_AT_low_pc (die));
5438 else
5439 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5440 get_AT_unsigned (die, DW_AT_byte_size));
5442 if (flag_debug_asm)
5443 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5445 fputc ('\n', asm_out_file);
5448 /* Output the terminator words. */
5449 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5450 fputc ('\n', asm_out_file);
5451 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5452 fputc ('\n', asm_out_file);
5455 /* Output the source line number correspondence information. This
5456 information goes into the .debug_line section. */
5458 static void
5459 output_line_info ()
5461 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5462 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5463 register unsigned opc;
5464 register unsigned n_op_args;
5465 register unsigned long ft_index;
5466 register unsigned long lt_index;
5467 register unsigned long current_line;
5468 register long line_offset;
5469 register long line_delta;
5470 register unsigned long current_file;
5471 register unsigned long function;
5473 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
5474 if (flag_debug_asm)
5475 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5476 ASM_COMMENT_START);
5478 fputc ('\n', asm_out_file);
5479 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
5480 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5481 if (flag_debug_asm)
5482 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5484 fputc ('\n', asm_out_file);
5485 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5486 if (flag_debug_asm)
5487 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5489 fputc ('\n', asm_out_file);
5490 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5491 if (flag_debug_asm)
5492 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5493 ASM_COMMENT_START);
5495 fputc ('\n', asm_out_file);
5496 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5497 if (flag_debug_asm)
5498 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5499 ASM_COMMENT_START);
5501 fputc ('\n', asm_out_file);
5502 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5503 if (flag_debug_asm)
5504 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5505 ASM_COMMENT_START);
5507 fputc ('\n', asm_out_file);
5508 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5509 if (flag_debug_asm)
5510 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5511 ASM_COMMENT_START);
5513 fputc ('\n', asm_out_file);
5514 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5515 if (flag_debug_asm)
5516 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5518 fputc ('\n', asm_out_file);
5519 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5521 switch (opc)
5523 case DW_LNS_advance_pc:
5524 case DW_LNS_advance_line:
5525 case DW_LNS_set_file:
5526 case DW_LNS_set_column:
5527 case DW_LNS_fixed_advance_pc:
5528 n_op_args = 1;
5529 break;
5530 default:
5531 n_op_args = 0;
5532 break;
5534 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5535 if (flag_debug_asm)
5536 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5537 ASM_COMMENT_START, opc, n_op_args);
5538 fputc ('\n', asm_out_file);
5541 if (flag_debug_asm)
5542 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5544 /* Include directory table is empty, at present */
5545 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5546 fputc ('\n', asm_out_file);
5547 if (flag_debug_asm)
5548 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5550 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5552 if (flag_debug_asm)
5554 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5555 fprintf (asm_out_file, "%s File Entry: 0x%lx",
5556 ASM_COMMENT_START, ft_index);
5558 else
5560 ASM_OUTPUT_ASCII (asm_out_file,
5561 file_table[ft_index],
5562 (int) strlen (file_table[ft_index]) + 1);
5565 fputc ('\n', asm_out_file);
5567 /* Include directory index */
5568 output_uleb128 (0);
5569 fputc ('\n', asm_out_file);
5571 /* Modification time */
5572 output_uleb128 (0);
5573 fputc ('\n', asm_out_file);
5575 /* File length in bytes */
5576 output_uleb128 (0);
5577 fputc ('\n', asm_out_file);
5580 /* Terminate the file name table */
5581 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5582 fputc ('\n', asm_out_file);
5584 /* We used to set the address register to the first location in the text
5585 section here, but that didn't accomplish anything since we already
5586 have a line note for the opening brace of the first function. */
5588 /* Generate the line number to PC correspondence table, encoded as
5589 a series of state machine operations. */
5590 current_file = 1;
5591 current_line = 1;
5592 strcpy (prev_line_label, text_section_label);
5593 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5595 register dw_line_info_ref line_info = &line_info_table[lt_index];
5597 #if 0
5598 /* Disable this optimization for now; GDB wants to see two line notes
5599 at the beginning of a function so it can find the end of the
5600 prologue. */
5602 /* Don't emit anything for redundant notes. Just updating the
5603 address doesn't accomplish anything, because we already assume
5604 that anything after the last address is this line. */
5605 if (line_info->dw_line_num == current_line
5606 && line_info->dw_file_num == current_file)
5607 continue;
5608 #endif
5610 /* Emit debug info for the address of the current line, choosing
5611 the encoding that uses the least amount of space. */
5612 /* ??? Unfortunately, we have little choice here currently, and must
5613 always use the most general form. Gcc does not know the address
5614 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5615 dwarf2 aware assemblers at this time, so we can't use any special
5616 pseudo ops that would allow the assembler to optimally encode this for
5617 us. Many ports do have length attributes which will give an upper
5618 bound on the address range. We could perhaps use length attributes
5619 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5620 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5621 if (0)
5623 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5624 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5625 if (flag_debug_asm)
5626 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5627 ASM_COMMENT_START);
5629 fputc ('\n', asm_out_file);
5630 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5631 fputc ('\n', asm_out_file);
5633 else
5635 /* This can handle any delta. This takes 4+PTR_SIZE bytes. */
5636 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5637 if (flag_debug_asm)
5638 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5639 ASM_COMMENT_START);
5640 fputc ('\n', asm_out_file);
5641 output_uleb128 (1 + PTR_SIZE);
5642 fputc ('\n', asm_out_file);
5643 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5644 fputc ('\n', asm_out_file);
5645 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5646 fputc ('\n', asm_out_file);
5648 strcpy (prev_line_label, line_label);
5650 /* Emit debug info for the source file of the current line, if
5651 different from the previous line. */
5652 if (line_info->dw_file_num != current_file)
5654 current_file = line_info->dw_file_num;
5655 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5656 if (flag_debug_asm)
5657 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5659 fputc ('\n', asm_out_file);
5660 output_uleb128 (current_file);
5661 if (flag_debug_asm)
5662 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5664 fputc ('\n', asm_out_file);
5667 /* Emit debug info for the current line number, choosing the encoding
5668 that uses the least amount of space. */
5669 if (line_info->dw_line_num != current_line)
5671 line_offset = line_info->dw_line_num - current_line;
5672 line_delta = line_offset - DWARF_LINE_BASE;
5673 current_line = line_info->dw_line_num;
5674 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5676 /* This can handle deltas from -10 to 234, using the current
5677 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5678 takes 1 byte. */
5679 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5680 DWARF_LINE_OPCODE_BASE + line_delta);
5681 if (flag_debug_asm)
5682 fprintf (asm_out_file,
5683 "\t%s line %ld", ASM_COMMENT_START, current_line);
5685 fputc ('\n', asm_out_file);
5687 else
5689 /* This can handle any delta. This takes at least 4 bytes,
5690 depending on the value being encoded. */
5691 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5692 if (flag_debug_asm)
5693 fprintf (asm_out_file, "\t%s advance to line %ld",
5694 ASM_COMMENT_START, current_line);
5696 fputc ('\n', asm_out_file);
5697 output_sleb128 (line_offset);
5698 fputc ('\n', asm_out_file);
5699 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5700 if (flag_debug_asm)
5701 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5702 fputc ('\n', asm_out_file);
5705 else
5707 /* We still need to start a new row, so output a copy insn. */
5708 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5709 if (flag_debug_asm)
5710 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5711 fputc ('\n', asm_out_file);
5715 /* Emit debug info for the address of the end of the function. */
5716 if (0)
5718 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5719 if (flag_debug_asm)
5720 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5721 ASM_COMMENT_START);
5723 fputc ('\n', asm_out_file);
5724 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5725 fputc ('\n', asm_out_file);
5727 else
5729 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5730 if (flag_debug_asm)
5731 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5732 fputc ('\n', asm_out_file);
5733 output_uleb128 (1 + PTR_SIZE);
5734 fputc ('\n', asm_out_file);
5735 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5736 fputc ('\n', asm_out_file);
5737 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
5738 fputc ('\n', asm_out_file);
5741 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5742 if (flag_debug_asm)
5743 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5745 fputc ('\n', asm_out_file);
5746 output_uleb128 (1);
5747 fputc ('\n', asm_out_file);
5748 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5749 fputc ('\n', asm_out_file);
5751 function = 0;
5752 current_file = 1;
5753 current_line = 1;
5754 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5756 register dw_separate_line_info_ref line_info
5757 = &separate_line_info_table[lt_index];
5759 #if 0
5760 /* Don't emit anything for redundant notes. */
5761 if (line_info->dw_line_num == current_line
5762 && line_info->dw_file_num == current_file
5763 && line_info->function == function)
5764 goto cont;
5765 #endif
5767 /* Emit debug info for the address of the current line. If this is
5768 a new function, or the first line of a function, then we need
5769 to handle it differently. */
5770 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5771 lt_index);
5772 if (function != line_info->function)
5774 function = line_info->function;
5776 /* Set the address register to the first line in the function */
5777 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5778 if (flag_debug_asm)
5779 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5780 ASM_COMMENT_START);
5782 fputc ('\n', asm_out_file);
5783 output_uleb128 (1 + PTR_SIZE);
5784 fputc ('\n', asm_out_file);
5785 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5786 fputc ('\n', asm_out_file);
5787 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5788 fputc ('\n', asm_out_file);
5790 else
5792 /* ??? See the DW_LNS_advance_pc comment above. */
5793 if (0)
5795 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5796 if (flag_debug_asm)
5797 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5798 ASM_COMMENT_START);
5800 fputc ('\n', asm_out_file);
5801 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5802 prev_line_label);
5803 fputc ('\n', asm_out_file);
5805 else
5807 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5808 if (flag_debug_asm)
5809 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5810 ASM_COMMENT_START);
5811 fputc ('\n', asm_out_file);
5812 output_uleb128 (1 + PTR_SIZE);
5813 fputc ('\n', asm_out_file);
5814 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5815 fputc ('\n', asm_out_file);
5816 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5817 fputc ('\n', asm_out_file);
5820 strcpy (prev_line_label, line_label);
5822 /* Emit debug info for the source file of the current line, if
5823 different from the previous line. */
5824 if (line_info->dw_file_num != current_file)
5826 current_file = line_info->dw_file_num;
5827 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5828 if (flag_debug_asm)
5829 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5831 fputc ('\n', asm_out_file);
5832 output_uleb128 (current_file);
5833 if (flag_debug_asm)
5834 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5836 fputc ('\n', asm_out_file);
5839 /* Emit debug info for the current line number, choosing the encoding
5840 that uses the least amount of space. */
5841 if (line_info->dw_line_num != current_line)
5843 line_offset = line_info->dw_line_num - current_line;
5844 line_delta = line_offset - DWARF_LINE_BASE;
5845 current_line = line_info->dw_line_num;
5846 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5848 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5849 DWARF_LINE_OPCODE_BASE + line_delta);
5850 if (flag_debug_asm)
5851 fprintf (asm_out_file,
5852 "\t%s line %ld", ASM_COMMENT_START, current_line);
5854 fputc ('\n', asm_out_file);
5856 else
5858 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5859 if (flag_debug_asm)
5860 fprintf (asm_out_file, "\t%s advance to line %ld",
5861 ASM_COMMENT_START, current_line);
5863 fputc ('\n', asm_out_file);
5864 output_sleb128 (line_offset);
5865 fputc ('\n', asm_out_file);
5866 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5867 if (flag_debug_asm)
5868 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5869 fputc ('\n', asm_out_file);
5872 else
5874 /* We still need to start a new row, so output a copy insn. */
5875 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5876 if (flag_debug_asm)
5877 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5878 fputc ('\n', asm_out_file);
5881 #if 0
5882 cont:
5883 #endif
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);
5936 /* Output the marker for the end of the line number info. */
5937 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
5940 /* Given a pointer to a tree node for some base type, return a pointer to
5941 a DIE that describes the given type.
5943 This routine must only be called for GCC type nodes that correspond to
5944 Dwarf base (fundamental) types. */
5946 static dw_die_ref
5947 base_type_die (type)
5948 register tree type;
5950 register dw_die_ref base_type_result;
5951 register const char *type_name;
5952 register enum dwarf_type encoding;
5953 register tree name = TYPE_NAME (type);
5955 if (TREE_CODE (type) == ERROR_MARK
5956 || TREE_CODE (type) == VOID_TYPE)
5957 return 0;
5959 if (name)
5961 if (TREE_CODE (name) == TYPE_DECL)
5962 name = DECL_NAME (name);
5964 type_name = IDENTIFIER_POINTER (name);
5966 else
5967 type_name = "__unknown__";
5969 switch (TREE_CODE (type))
5971 case INTEGER_TYPE:
5972 /* Carefully distinguish the C character types, without messing
5973 up if the language is not C. Note that we check only for the names
5974 that contain spaces; other names might occur by coincidence in other
5975 languages. */
5976 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
5977 && (type == char_type_node
5978 || ! strcmp (type_name, "signed char")
5979 || ! strcmp (type_name, "unsigned char"))))
5981 if (TREE_UNSIGNED (type))
5982 encoding = DW_ATE_unsigned;
5983 else
5984 encoding = DW_ATE_signed;
5985 break;
5987 /* else fall through */
5989 case CHAR_TYPE:
5990 /* GNU Pascal/Ada CHAR type. Not used in C. */
5991 if (TREE_UNSIGNED (type))
5992 encoding = DW_ATE_unsigned_char;
5993 else
5994 encoding = DW_ATE_signed_char;
5995 break;
5997 case REAL_TYPE:
5998 encoding = DW_ATE_float;
5999 break;
6001 /* Dwarf2 doesn't know anything about complex ints, so use
6002 a user defined type for it. */
6003 case COMPLEX_TYPE:
6004 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6005 encoding = DW_ATE_complex_float;
6006 else
6007 encoding = DW_ATE_lo_user;
6008 break;
6010 case BOOLEAN_TYPE:
6011 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6012 encoding = DW_ATE_boolean;
6013 break;
6015 default:
6016 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6019 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6020 if (demangle_name_func)
6021 type_name = (*demangle_name_func) (type_name);
6023 add_AT_string (base_type_result, DW_AT_name, type_name);
6024 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6025 int_size_in_bytes (type));
6026 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6028 return base_type_result;
6031 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6032 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6033 a given type is generally the same as the given type, except that if the
6034 given type is a pointer or reference type, then the root type of the given
6035 type is the root type of the "basis" type for the pointer or reference
6036 type. (This definition of the "root" type is recursive.) Also, the root
6037 type of a `const' qualified type or a `volatile' qualified type is the
6038 root type of the given type without the qualifiers. */
6040 static tree
6041 root_type (type)
6042 register tree type;
6044 if (TREE_CODE (type) == ERROR_MARK)
6045 return error_mark_node;
6047 switch (TREE_CODE (type))
6049 case ERROR_MARK:
6050 return error_mark_node;
6052 case POINTER_TYPE:
6053 case REFERENCE_TYPE:
6054 return type_main_variant (root_type (TREE_TYPE (type)));
6056 default:
6057 return type_main_variant (type);
6061 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6062 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6064 static inline int
6065 is_base_type (type)
6066 register tree type;
6068 switch (TREE_CODE (type))
6070 case ERROR_MARK:
6071 case VOID_TYPE:
6072 case INTEGER_TYPE:
6073 case REAL_TYPE:
6074 case COMPLEX_TYPE:
6075 case BOOLEAN_TYPE:
6076 case CHAR_TYPE:
6077 return 1;
6079 case SET_TYPE:
6080 case ARRAY_TYPE:
6081 case RECORD_TYPE:
6082 case UNION_TYPE:
6083 case QUAL_UNION_TYPE:
6084 case ENUMERAL_TYPE:
6085 case FUNCTION_TYPE:
6086 case METHOD_TYPE:
6087 case POINTER_TYPE:
6088 case REFERENCE_TYPE:
6089 case FILE_TYPE:
6090 case OFFSET_TYPE:
6091 case LANG_TYPE:
6092 return 0;
6094 default:
6095 abort ();
6098 return 0;
6101 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6102 entry that chains various modifiers in front of the given type. */
6104 static dw_die_ref
6105 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6106 register tree type;
6107 register int is_const_type;
6108 register int is_volatile_type;
6109 register dw_die_ref context_die;
6111 register enum tree_code code = TREE_CODE (type);
6112 register dw_die_ref mod_type_die = NULL;
6113 register dw_die_ref sub_die = NULL;
6114 register tree item_type = NULL;
6116 if (code != ERROR_MARK)
6118 type = build_type_variant (type, is_const_type, is_volatile_type);
6120 mod_type_die = lookup_type_die (type);
6121 if (mod_type_die)
6122 return mod_type_die;
6124 /* Handle C typedef types. */
6125 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6126 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6128 tree dtype = TREE_TYPE (TYPE_NAME (type));
6129 if (type == dtype)
6131 /* For a named type, use the typedef. */
6132 gen_type_die (type, context_die);
6133 mod_type_die = lookup_type_die (type);
6136 else if (is_const_type < TYPE_READONLY (dtype)
6137 || is_volatile_type < TYPE_VOLATILE (dtype))
6138 /* cv-unqualified version of named type. Just use the unnamed
6139 type to which it refers. */
6140 mod_type_die
6141 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6142 is_const_type, is_volatile_type,
6143 context_die);
6144 /* Else cv-qualified version of named type; fall through. */
6147 if (mod_type_die)
6148 /* OK */;
6149 else if (is_const_type)
6151 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6152 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6154 else if (is_volatile_type)
6156 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6157 sub_die = modified_type_die (type, 0, 0, context_die);
6159 else if (code == POINTER_TYPE)
6161 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6162 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6163 #if 0
6164 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6165 #endif
6166 item_type = TREE_TYPE (type);
6168 else if (code == REFERENCE_TYPE)
6170 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6171 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6172 #if 0
6173 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6174 #endif
6175 item_type = TREE_TYPE (type);
6177 else if (is_base_type (type))
6178 mod_type_die = base_type_die (type);
6179 else
6181 gen_type_die (type, context_die);
6183 /* We have to get the type_main_variant here (and pass that to the
6184 `lookup_type_die' routine) because the ..._TYPE node we have
6185 might simply be a *copy* of some original type node (where the
6186 copy was created to help us keep track of typedef names) and
6187 that copy might have a different TYPE_UID from the original
6188 ..._TYPE node. */
6189 mod_type_die = lookup_type_die (type_main_variant (type));
6190 if (mod_type_die == NULL)
6191 abort ();
6195 equate_type_number_to_die (type, mod_type_die);
6196 if (item_type)
6197 /* We must do this after the equate_type_number_to_die call, in case
6198 this is a recursive type. This ensures that the modified_type_die
6199 recursion will terminate even if the type is recursive. Recursive
6200 types are possible in Ada. */
6201 sub_die = modified_type_die (item_type,
6202 TYPE_READONLY (item_type),
6203 TYPE_VOLATILE (item_type),
6204 context_die);
6206 if (sub_die != NULL)
6207 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6209 return mod_type_die;
6212 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6213 an enumerated type. */
6215 static inline int
6216 type_is_enum (type)
6217 register tree type;
6219 return TREE_CODE (type) == ENUMERAL_TYPE;
6222 /* Return a location descriptor that designates a machine register. */
6224 static dw_loc_descr_ref
6225 reg_loc_descriptor (rtl)
6226 register rtx rtl;
6228 register dw_loc_descr_ref loc_result = NULL;
6229 register unsigned reg = reg_number (rtl);
6231 if (reg <= 31)
6232 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6233 else
6234 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6236 return loc_result;
6239 /* Return a location descriptor that designates a base+offset location. */
6241 static dw_loc_descr_ref
6242 based_loc_descr (reg, offset)
6243 unsigned reg;
6244 long int offset;
6246 register dw_loc_descr_ref loc_result;
6247 /* For the "frame base", we use the frame pointer or stack pointer
6248 registers, since the RTL for local variables is relative to one of
6249 them. */
6250 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6251 ? HARD_FRAME_POINTER_REGNUM
6252 : STACK_POINTER_REGNUM);
6254 if (reg == fp_reg)
6255 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
6256 else if (reg <= 31)
6257 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
6258 else
6259 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6261 return loc_result;
6264 /* Return true if this RTL expression describes a base+offset calculation. */
6266 static inline int
6267 is_based_loc (rtl)
6268 register rtx rtl;
6270 return (GET_CODE (rtl) == PLUS
6271 && ((GET_CODE (XEXP (rtl, 0)) == REG
6272 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6275 /* The following routine converts the RTL for a variable or parameter
6276 (resident in memory) into an equivalent Dwarf representation of a
6277 mechanism for getting the address of that same variable onto the top of a
6278 hypothetical "address evaluation" stack.
6280 When creating memory location descriptors, we are effectively transforming
6281 the RTL for a memory-resident object into its Dwarf postfix expression
6282 equivalent. This routine recursively descends an RTL tree, turning
6283 it into Dwarf postfix code as it goes.
6285 MODE is the mode of the memory reference, needed to handle some
6286 autoincrement addressing modes. */
6288 static dw_loc_descr_ref
6289 mem_loc_descriptor (rtl, mode)
6290 register rtx rtl;
6291 enum machine_mode mode;
6293 dw_loc_descr_ref mem_loc_result = NULL;
6294 /* Note that for a dynamically sized array, the location we will generate a
6295 description of here will be the lowest numbered location which is
6296 actually within the array. That's *not* necessarily the same as the
6297 zeroth element of the array. */
6299 #ifdef ASM_SIMPLIFY_DWARF_ADDR
6300 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
6301 #endif
6303 switch (GET_CODE (rtl))
6305 case POST_INC:
6306 case POST_DEC:
6307 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
6308 just fall into the SUBREG code. */
6310 /* ... fall through ... */
6312 case SUBREG:
6313 /* The case of a subreg may arise when we have a local (register)
6314 variable or a formal (register) parameter which doesn't quite fill
6315 up an entire register. For now, just assume that it is
6316 legitimate to make the Dwarf info refer to the whole register which
6317 contains the given subreg. */
6318 rtl = XEXP (rtl, 0);
6320 /* ... fall through ... */
6322 case REG:
6323 /* Whenever a register number forms a part of the description of the
6324 method for calculating the (dynamic) address of a memory resident
6325 object, DWARF rules require the register number be referred to as
6326 a "base register". This distinction is not based in any way upon
6327 what category of register the hardware believes the given register
6328 belongs to. This is strictly DWARF terminology we're dealing with
6329 here. Note that in cases where the location of a memory-resident
6330 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6331 OP_CONST (0)) the actual DWARF location descriptor that we generate
6332 may just be OP_BASEREG (basereg). This may look deceptively like
6333 the object in question was allocated to a register (rather than in
6334 memory) so DWARF consumers need to be aware of the subtle
6335 distinction between OP_REG and OP_BASEREG. */
6336 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6337 break;
6339 case MEM:
6340 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
6341 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6342 break;
6344 case LABEL_REF:
6345 /* Some ports can transform a symbol ref into a label ref, because
6346 the symbol ref is too far away and has to be dumped into a constant
6347 pool. */
6348 case CONST:
6349 case SYMBOL_REF:
6350 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6351 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6352 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
6353 break;
6355 case PRE_INC:
6356 case PRE_DEC:
6357 /* Turn these into a PLUS expression and fall into the PLUS code
6358 below. */
6359 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
6360 GEN_INT (GET_CODE (rtl) == PRE_INC
6361 ? GET_MODE_UNIT_SIZE (mode)
6362 : - GET_MODE_UNIT_SIZE (mode)));
6364 /* ... fall through ... */
6366 case PLUS:
6367 if (is_based_loc (rtl))
6368 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6369 INTVAL (XEXP (rtl, 1)));
6370 else
6372 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
6373 mode));
6374 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
6375 mode));
6376 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6378 break;
6380 case MULT:
6381 /* If a pseudo-reg is optimized away, it is possible for it to
6382 be replaced with a MEM containing a multiply. */
6383 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
6384 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
6385 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6386 break;
6388 case CONST_INT:
6389 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6390 break;
6392 default:
6393 abort ();
6396 return mem_loc_result;
6399 /* Return a descriptor that describes the concatenation of two locations.
6400 This is typically a complex variable. */
6402 static dw_loc_descr_ref
6403 concat_loc_descriptor (x0, x1)
6404 register rtx x0, x1;
6406 dw_loc_descr_ref cc_loc_result = NULL;
6408 if (!is_pseudo_reg (x0)
6409 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
6410 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
6411 add_loc_descr (&cc_loc_result,
6412 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
6414 if (!is_pseudo_reg (x1)
6415 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
6416 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
6417 add_loc_descr (&cc_loc_result,
6418 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
6420 return cc_loc_result;
6423 /* Output a proper Dwarf location descriptor for a variable or parameter
6424 which is either allocated in a register or in a memory location. For a
6425 register, we just generate an OP_REG and the register number. For a
6426 memory location we provide a Dwarf postfix expression describing how to
6427 generate the (dynamic) address of the object onto the address stack. */
6429 static dw_loc_descr_ref
6430 loc_descriptor (rtl)
6431 register rtx rtl;
6433 dw_loc_descr_ref loc_result = NULL;
6434 switch (GET_CODE (rtl))
6436 case SUBREG:
6437 /* The case of a subreg may arise when we have a local (register)
6438 variable or a formal (register) parameter which doesn't quite fill
6439 up an entire register. For now, just assume that it is
6440 legitimate to make the Dwarf info refer to the whole register which
6441 contains the given subreg. */
6442 rtl = XEXP (rtl, 0);
6444 /* ... fall through ... */
6446 case REG:
6447 loc_result = reg_loc_descriptor (rtl);
6448 break;
6450 case MEM:
6451 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
6452 break;
6454 case CONCAT:
6455 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6456 break;
6458 default:
6459 abort ();
6462 return loc_result;
6465 /* Given a value, round it up to the lowest multiple of `boundary'
6466 which is not less than the value itself. */
6468 static inline HOST_WIDE_INT
6469 ceiling (value, boundary)
6470 HOST_WIDE_INT value;
6471 unsigned int boundary;
6473 return (((value + boundary - 1) / boundary) * boundary);
6476 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6477 pointer to the declared type for the relevant field variable, or return
6478 `integer_type_node' if the given node turns out to be an
6479 ERROR_MARK node. */
6481 static inline tree
6482 field_type (decl)
6483 register tree decl;
6485 register tree type;
6487 if (TREE_CODE (decl) == ERROR_MARK)
6488 return integer_type_node;
6490 type = DECL_BIT_FIELD_TYPE (decl);
6491 if (type == NULL_TREE)
6492 type = TREE_TYPE (decl);
6494 return type;
6497 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6498 node, return the alignment in bits for the type, or else return
6499 BITS_PER_WORD if the node actually turns out to be an
6500 ERROR_MARK node. */
6502 static inline unsigned
6503 simple_type_align_in_bits (type)
6504 register tree type;
6506 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6509 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6510 node, return the size in bits for the type if it is a constant, or else
6511 return the alignment for the type if the type's size is not constant, or
6512 else return BITS_PER_WORD if the type actually turns out to be an
6513 ERROR_MARK node. */
6515 static inline unsigned HOST_WIDE_INT
6516 simple_type_size_in_bits (type)
6517 register tree type;
6519 if (TREE_CODE (type) == ERROR_MARK)
6520 return BITS_PER_WORD;
6521 else
6523 register tree type_size_tree = TYPE_SIZE (type);
6525 if (! host_integerp (type_size_tree, 1))
6526 return TYPE_ALIGN (type);
6528 return tree_low_cst (type_size_tree, 1);
6532 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6533 return the byte offset of the lowest addressed byte of the "containing
6534 object" for the given FIELD_DECL, or return 0 if we are unable to
6535 determine what that offset is, either because the argument turns out to
6536 be a pointer to an ERROR_MARK node, or because the offset is actually
6537 variable. (We can't handle the latter case just yet). */
6539 static HOST_WIDE_INT
6540 field_byte_offset (decl)
6541 register tree decl;
6543 unsigned int type_align_in_bytes;
6544 unsigned int type_align_in_bits;
6545 unsigned HOST_WIDE_INT type_size_in_bits;
6546 HOST_WIDE_INT object_offset_in_align_units;
6547 HOST_WIDE_INT object_offset_in_bits;
6548 HOST_WIDE_INT object_offset_in_bytes;
6549 tree type;
6550 tree field_size_tree;
6551 HOST_WIDE_INT bitpos_int;
6552 HOST_WIDE_INT deepest_bitpos;
6553 unsigned HOST_WIDE_INT field_size_in_bits;
6555 if (TREE_CODE (decl) == ERROR_MARK)
6556 return 0;
6558 if (TREE_CODE (decl) != FIELD_DECL)
6559 abort ();
6561 type = field_type (decl);
6562 field_size_tree = DECL_SIZE (decl);
6564 /* If there was an error, the size could be zero. */
6565 if (! field_size_tree)
6567 if (errorcount)
6568 return 0;
6570 abort ();
6573 /* We cannot yet cope with fields whose positions are variable, so
6574 for now, when we see such things, we simply return 0. Someday, we may
6575 be able to handle such cases, but it will be damn difficult. */
6576 if (! host_integerp (bit_position (decl), 0))
6577 return 0;
6579 bitpos_int = int_bit_position (decl);
6581 /* If we don't know the size of the field, pretend it's a full word. */
6582 if (host_integerp (field_size_tree, 1))
6583 field_size_in_bits = tree_low_cst (field_size_tree, 1);
6584 else
6585 field_size_in_bits = BITS_PER_WORD;
6587 type_size_in_bits = simple_type_size_in_bits (type);
6588 type_align_in_bits = simple_type_align_in_bits (type);
6589 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6591 /* Note that the GCC front-end doesn't make any attempt to keep track of
6592 the starting bit offset (relative to the start of the containing
6593 structure type) of the hypothetical "containing object" for a bit-
6594 field. Thus, when computing the byte offset value for the start of the
6595 "containing object" of a bit-field, we must deduce this information on
6596 our own. This can be rather tricky to do in some cases. For example,
6597 handling the following structure type definition when compiling for an
6598 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6599 can be very tricky:
6601 struct S { int field1; long long field2:31; };
6603 Fortunately, there is a simple rule-of-thumb which can be
6604 used in such cases. When compiling for an i386/i486, GCC will allocate
6605 8 bytes for the structure shown above. It decides to do this based upon
6606 one simple rule for bit-field allocation. Quite simply, GCC allocates
6607 each "containing object" for each bit-field at the first (i.e. lowest
6608 addressed) legitimate alignment boundary (based upon the required
6609 minimum alignment for the declared type of the field) which it can
6610 possibly use, subject to the condition that there is still enough
6611 available space remaining in the containing object (when allocated at
6612 the selected point) to fully accommodate all of the bits of the
6613 bit-field itself. This simple rule makes it obvious why GCC allocates
6614 8 bytes for each object of the structure type shown above. When looking
6615 for a place to allocate the "containing object" for `field2', the
6616 compiler simply tries to allocate a 64-bit "containing object" at each
6617 successive 32-bit boundary (starting at zero) until it finds a place to
6618 allocate that 64- bit field such that at least 31 contiguous (and
6619 previously unallocated) bits remain within that selected 64 bit field.
6620 (As it turns out, for the example above, the compiler finds that it is
6621 OK to allocate the "containing object" 64-bit field at bit-offset zero
6622 within the structure type.) Here we attempt to work backwards from the
6623 limited set of facts we're given, and we try to deduce from those facts,
6624 where GCC must have believed that the containing object started (within
6625 the structure type). The value we deduce is then used (by the callers of
6626 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6627 for fields (both bit-fields and, in the case of DW_AT_location, regular
6628 fields as well). */
6630 /* Figure out the bit-distance from the start of the structure to the
6631 "deepest" bit of the bit-field. */
6632 deepest_bitpos = bitpos_int + field_size_in_bits;
6634 /* This is the tricky part. Use some fancy footwork to deduce where the
6635 lowest addressed bit of the containing object must be. */
6636 object_offset_in_bits
6637 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6639 /* Compute the offset of the containing object in "alignment units". */
6640 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6642 /* Compute the offset of the containing object in bytes. */
6643 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6645 return object_offset_in_bytes;
6648 /* The following routines define various Dwarf attributes and any data
6649 associated with them. */
6651 /* Add a location description attribute value to a DIE.
6653 This emits location attributes suitable for whole variables and
6654 whole parameters. Note that the location attributes for struct fields are
6655 generated by the routine `data_member_location_attribute' below. */
6657 static void
6658 add_AT_location_description (die, attr_kind, rtl)
6659 dw_die_ref die;
6660 enum dwarf_attribute attr_kind;
6661 register rtx rtl;
6663 /* Handle a special case. If we are about to output a location descriptor
6664 for a variable or parameter which has been optimized out of existence,
6665 don't do that. A variable which has been optimized out
6666 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6667 Currently, in some rare cases, variables can have DECL_RTL values which
6668 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6669 elsewhere in the compiler. We treat such cases as if the variable(s) in
6670 question had been optimized out of existence. */
6672 if (is_pseudo_reg (rtl)
6673 || (GET_CODE (rtl) == MEM
6674 && is_pseudo_reg (XEXP (rtl, 0)))
6675 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
6676 references the internal argument pointer (a pseudo) in a function
6677 where all references to the internal argument pointer were
6678 eliminated via the optimizers. */
6679 || (GET_CODE (rtl) == MEM
6680 && GET_CODE (XEXP (rtl, 0)) == PLUS
6681 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
6682 || (GET_CODE (rtl) == CONCAT
6683 && is_pseudo_reg (XEXP (rtl, 0))
6684 && is_pseudo_reg (XEXP (rtl, 1))))
6685 return;
6687 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
6690 /* Attach the specialized form of location attribute used for data
6691 members of struct and union types. In the special case of a
6692 FIELD_DECL node which represents a bit-field, the "offset" part
6693 of this special location descriptor must indicate the distance
6694 in bytes from the lowest-addressed byte of the containing struct
6695 or union type to the lowest-addressed byte of the "containing
6696 object" for the bit-field. (See the `field_byte_offset' function
6697 above).. For any given bit-field, the "containing object" is a
6698 hypothetical object (of some integral or enum type) within which
6699 the given bit-field lives. The type of this hypothetical
6700 "containing object" is always the same as the declared type of
6701 the individual bit-field itself (for GCC anyway... the DWARF
6702 spec doesn't actually mandate this). Note that it is the size
6703 (in bytes) of the hypothetical "containing object" which will
6704 be given in the DW_AT_byte_size attribute for this bit-field.
6705 (See the `byte_size_attribute' function below.) It is also used
6706 when calculating the value of the DW_AT_bit_offset attribute.
6707 (See the `bit_offset_attribute' function below). */
6709 static void
6710 add_data_member_location_attribute (die, decl)
6711 register dw_die_ref die;
6712 register tree decl;
6714 register unsigned long offset;
6715 register dw_loc_descr_ref loc_descr;
6716 register enum dwarf_location_atom op;
6718 if (TREE_CODE (decl) == TREE_VEC)
6719 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
6720 else
6721 offset = field_byte_offset (decl);
6723 /* The DWARF2 standard says that we should assume that the structure address
6724 is already on the stack, so we can specify a structure field address
6725 by using DW_OP_plus_uconst. */
6727 #ifdef MIPS_DEBUGGING_INFO
6728 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6729 correctly. It works only if we leave the offset on the stack. */
6730 op = DW_OP_constu;
6731 #else
6732 op = DW_OP_plus_uconst;
6733 #endif
6735 loc_descr = new_loc_descr (op, offset, 0);
6736 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6739 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6740 does not have a "location" either in memory or in a register. These
6741 things can arise in GNU C when a constant is passed as an actual parameter
6742 to an inlined function. They can also arise in C++ where declared
6743 constants do not necessarily get memory "homes". */
6745 static void
6746 add_const_value_attribute (die, rtl)
6747 register dw_die_ref die;
6748 register rtx rtl;
6750 switch (GET_CODE (rtl))
6752 case CONST_INT:
6753 /* Note that a CONST_INT rtx could represent either an integer or a
6754 floating-point constant. A CONST_INT is used whenever the constant
6755 will fit into a single word. In all such cases, the original mode
6756 of the constant value is wiped out, and the CONST_INT rtx is
6757 assigned VOIDmode. */
6758 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6759 break;
6761 case CONST_DOUBLE:
6762 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6763 floating-point constant. A CONST_DOUBLE is used whenever the
6764 constant requires more than one word in order to be adequately
6765 represented. We output CONST_DOUBLEs as blocks. */
6767 register enum machine_mode mode = GET_MODE (rtl);
6769 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6771 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6772 long array[4];
6773 REAL_VALUE_TYPE rv;
6775 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6776 switch (mode)
6778 case SFmode:
6779 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6780 break;
6782 case DFmode:
6783 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6784 break;
6786 case XFmode:
6787 case TFmode:
6788 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6789 break;
6791 default:
6792 abort ();
6795 add_AT_float (die, DW_AT_const_value, length, array);
6797 else
6798 add_AT_long_long (die, DW_AT_const_value,
6799 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6801 break;
6803 case CONST_STRING:
6804 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6805 break;
6807 case SYMBOL_REF:
6808 case LABEL_REF:
6809 case CONST:
6810 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
6811 break;
6813 case PLUS:
6814 /* In cases where an inlined instance of an inline function is passed
6815 the address of an `auto' variable (which is local to the caller) we
6816 can get a situation where the DECL_RTL of the artificial local
6817 variable (for the inlining) which acts as a stand-in for the
6818 corresponding formal parameter (of the inline function) will look
6819 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6820 exactly a compile-time constant expression, but it isn't the address
6821 of the (artificial) local variable either. Rather, it represents the
6822 *value* which the artificial local variable always has during its
6823 lifetime. We currently have no way to represent such quasi-constant
6824 values in Dwarf, so for now we just punt and generate nothing. */
6825 break;
6827 default:
6828 /* No other kinds of rtx should be possible here. */
6829 abort ();
6834 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6835 data attribute for a variable or a parameter. We generate the
6836 DW_AT_const_value attribute only in those cases where the given variable
6837 or parameter does not have a true "location" either in memory or in a
6838 register. This can happen (for example) when a constant is passed as an
6839 actual argument in a call to an inline function. (It's possible that
6840 these things can crop up in other ways also.) Note that one type of
6841 constant value which can be passed into an inlined function is a constant
6842 pointer. This can happen for example if an actual argument in an inlined
6843 function call evaluates to a compile-time constant address. */
6845 static void
6846 add_location_or_const_value_attribute (die, decl)
6847 register dw_die_ref die;
6848 register tree decl;
6850 register rtx rtl;
6851 register tree declared_type;
6852 register tree passed_type;
6854 if (TREE_CODE (decl) == ERROR_MARK)
6855 return;
6857 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6858 abort ();
6860 /* Here we have to decide where we are going to say the parameter "lives"
6861 (as far as the debugger is concerned). We only have a couple of
6862 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6864 DECL_RTL normally indicates where the parameter lives during most of the
6865 activation of the function. If optimization is enabled however, this
6866 could be either NULL or else a pseudo-reg. Both of those cases indicate
6867 that the parameter doesn't really live anywhere (as far as the code
6868 generation parts of GCC are concerned) during most of the function's
6869 activation. That will happen (for example) if the parameter is never
6870 referenced within the function.
6872 We could just generate a location descriptor here for all non-NULL
6873 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6874 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6875 where DECL_RTL is NULL or is a pseudo-reg.
6877 Note however that we can only get away with using DECL_INCOMING_RTL as
6878 a backup substitute for DECL_RTL in certain limited cases. In cases
6879 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6880 we can be sure that the parameter was passed using the same type as it is
6881 declared to have within the function, and that its DECL_INCOMING_RTL
6882 points us to a place where a value of that type is passed.
6884 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6885 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6886 because in these cases DECL_INCOMING_RTL points us to a value of some
6887 type which is *different* from the type of the parameter itself. Thus,
6888 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6889 such cases, the debugger would end up (for example) trying to fetch a
6890 `float' from a place which actually contains the first part of a
6891 `double'. That would lead to really incorrect and confusing
6892 output at debug-time.
6894 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6895 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6896 are a couple of exceptions however. On little-endian machines we can
6897 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6898 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6899 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6900 when (on a little-endian machine) a non-prototyped function has a
6901 parameter declared to be of type `short' or `char'. In such cases,
6902 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6903 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6904 passed `int' value. If the debugger then uses that address to fetch
6905 a `short' or a `char' (on a little-endian machine) the result will be
6906 the correct data, so we allow for such exceptional cases below.
6908 Note that our goal here is to describe the place where the given formal
6909 parameter lives during most of the function's activation (i.e. between
6910 the end of the prologue and the start of the epilogue). We'll do that
6911 as best as we can. Note however that if the given formal parameter is
6912 modified sometime during the execution of the function, then a stack
6913 backtrace (at debug-time) will show the function as having been
6914 called with the *new* value rather than the value which was
6915 originally passed in. This happens rarely enough that it is not
6916 a major problem, but it *is* a problem, and I'd like to fix it.
6918 A future version of dwarf2out.c may generate two additional
6919 attributes for any given DW_TAG_formal_parameter DIE which will
6920 describe the "passed type" and the "passed location" for the
6921 given formal parameter in addition to the attributes we now
6922 generate to indicate the "declared type" and the "active
6923 location" for each parameter. This additional set of attributes
6924 could be used by debuggers for stack backtraces. Separately, note
6925 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6926 NULL also. This happens (for example) for inlined-instances of
6927 inline function formal parameters which are never referenced.
6928 This really shouldn't be happening. All PARM_DECL nodes should
6929 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6930 doesn't currently generate these values for inlined instances of
6931 inline function parameters, so when we see such cases, we are
6932 just out-of-luck for the time being (until integrate.c
6933 gets fixed). */
6935 /* Use DECL_RTL as the "location" unless we find something better. */
6936 rtl = DECL_RTL (decl);
6938 if (TREE_CODE (decl) == PARM_DECL)
6940 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
6942 declared_type = type_main_variant (TREE_TYPE (decl));
6943 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
6945 /* This decl represents a formal parameter which was optimized out.
6946 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
6947 all* cases where (rtl == NULL_RTX) just below. */
6948 if (declared_type == passed_type)
6949 rtl = DECL_INCOMING_RTL (decl);
6950 else if (! BYTES_BIG_ENDIAN
6951 && TREE_CODE (declared_type) == INTEGER_TYPE
6952 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
6953 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
6954 rtl = DECL_INCOMING_RTL (decl);
6957 /* If the parm was passed in registers, but lives on the stack, then
6958 make a big endian correction if the mode of the type of the
6959 parameter is not the same as the mode of the rtl. */
6960 /* ??? This is the same series of checks that are made in dbxout.c before
6961 we reach the big endian correction code there. It isn't clear if all
6962 of these checks are necessary here, but keeping them all is the safe
6963 thing to do. */
6964 else if (GET_CODE (rtl) == MEM
6965 && XEXP (rtl, 0) != const0_rtx
6966 && ! CONSTANT_P (XEXP (rtl, 0))
6967 /* Not passed in memory. */
6968 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
6969 /* Not passed by invisible reference. */
6970 && (GET_CODE (XEXP (rtl, 0)) != REG
6971 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
6972 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
6973 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
6974 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
6975 #endif
6977 /* Big endian correction check. */
6978 && BYTES_BIG_ENDIAN
6979 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
6980 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
6981 < UNITS_PER_WORD))
6983 int offset = (UNITS_PER_WORD
6984 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
6985 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
6986 plus_constant (XEXP (rtl, 0), offset));
6990 if (rtl == NULL_RTX)
6991 return;
6993 rtl = eliminate_regs (rtl, 0, NULL_RTX);
6994 #ifdef LEAF_REG_REMAP
6995 if (current_function_uses_only_leaf_regs)
6996 leaf_renumber_regs_insn (rtl);
6997 #endif
6999 switch (GET_CODE (rtl))
7001 case ADDRESSOF:
7002 /* The address of a variable that was optimized away; don't emit
7003 anything. */
7004 break;
7006 case CONST_INT:
7007 case CONST_DOUBLE:
7008 case CONST_STRING:
7009 case SYMBOL_REF:
7010 case LABEL_REF:
7011 case CONST:
7012 case PLUS:
7013 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7014 add_const_value_attribute (die, rtl);
7015 break;
7017 case MEM:
7018 case REG:
7019 case SUBREG:
7020 case CONCAT:
7021 add_AT_location_description (die, DW_AT_location, rtl);
7022 break;
7024 default:
7025 abort ();
7029 /* Generate an DW_AT_name attribute given some string value to be included as
7030 the value of the attribute. */
7032 static inline void
7033 add_name_attribute (die, name_string)
7034 register dw_die_ref die;
7035 register const char *name_string;
7037 if (name_string != NULL && *name_string != 0)
7039 if (demangle_name_func)
7040 name_string = (*demangle_name_func) (name_string);
7042 add_AT_string (die, DW_AT_name, name_string);
7046 /* Given a tree node describing an array bound (either lower or upper) output
7047 a representation for that bound. */
7049 static void
7050 add_bound_info (subrange_die, bound_attr, bound)
7051 register dw_die_ref subrange_die;
7052 register enum dwarf_attribute bound_attr;
7053 register tree bound;
7055 /* If this is an Ada unconstrained array type, then don't emit any debug
7056 info because the array bounds are unknown. They are parameterized when
7057 the type is instantiated. */
7058 if (contains_placeholder_p (bound))
7059 return;
7061 switch (TREE_CODE (bound))
7063 case ERROR_MARK:
7064 return;
7066 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7067 case INTEGER_CST:
7068 if (! host_integerp (bound, 0)
7069 || (bound_attr == DW_AT_lower_bound
7070 && ((is_c_family () && integer_zerop (bound))
7071 || (is_fortran () && integer_onep (bound)))))
7072 /* use the default */
7074 else
7075 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
7076 break;
7078 case CONVERT_EXPR:
7079 case NOP_EXPR:
7080 case NON_LVALUE_EXPR:
7081 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7082 break;
7084 case SAVE_EXPR:
7085 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7086 access the upper bound values may be bogus. If they refer to a
7087 register, they may only describe how to get at these values at the
7088 points in the generated code right after they have just been
7089 computed. Worse yet, in the typical case, the upper bound values
7090 will not even *be* computed in the optimized code (though the
7091 number of elements will), so these SAVE_EXPRs are entirely
7092 bogus. In order to compensate for this fact, we check here to see
7093 if optimization is enabled, and if so, we don't add an attribute
7094 for the (unknown and unknowable) upper bound. This should not
7095 cause too much trouble for existing (stupid?) debuggers because
7096 they have to deal with empty upper bounds location descriptions
7097 anyway in order to be able to deal with incomplete array types.
7098 Of course an intelligent debugger (GDB?) should be able to
7099 comprehend that a missing upper bound specification in a array
7100 type used for a storage class `auto' local array variable
7101 indicates that the upper bound is both unknown (at compile- time)
7102 and unknowable (at run-time) due to optimization.
7104 We assume that a MEM rtx is safe because gcc wouldn't put the
7105 value there unless it was going to be used repeatedly in the
7106 function, i.e. for cleanups. */
7107 if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
7109 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7110 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7111 register rtx loc = SAVE_EXPR_RTL (bound);
7113 /* If the RTL for the SAVE_EXPR is memory, handle the case where
7114 it references an outer function's frame. */
7116 if (GET_CODE (loc) == MEM)
7118 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
7120 if (XEXP (loc, 0) != new_addr)
7121 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
7124 add_AT_flag (decl_die, DW_AT_artificial, 1);
7125 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
7126 add_AT_location_description (decl_die, DW_AT_location, loc);
7127 add_AT_die_ref (subrange_die, bound_attr, decl_die);
7130 /* Else leave out the attribute. */
7131 break;
7133 case MAX_EXPR:
7134 case VAR_DECL:
7135 case COMPONENT_REF:
7136 /* ??? These types of bounds can be created by the Ada front end,
7137 and it isn't clear how to emit debug info for them. */
7138 break;
7140 default:
7141 abort ();
7145 /* Note that the block of subscript information for an array type also
7146 includes information about the element type of type given array type. */
7148 static void
7149 add_subscript_info (type_die, type)
7150 register dw_die_ref type_die;
7151 register tree type;
7153 #ifndef MIPS_DEBUGGING_INFO
7154 register unsigned dimension_number;
7155 #endif
7156 register tree lower, upper;
7157 register dw_die_ref subrange_die;
7159 /* The GNU compilers represent multidimensional array types as sequences of
7160 one dimensional array types whose element types are themselves array
7161 types. Here we squish that down, so that each multidimensional array
7162 type gets only one array_type DIE in the Dwarf debugging info. The draft
7163 Dwarf specification say that we are allowed to do this kind of
7164 compression in C (because there is no difference between an array or
7165 arrays and a multidimensional array in C) but for other source languages
7166 (e.g. Ada) we probably shouldn't do this. */
7168 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7169 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7170 We work around this by disabling this feature. See also
7171 gen_array_type_die. */
7172 #ifndef MIPS_DEBUGGING_INFO
7173 for (dimension_number = 0;
7174 TREE_CODE (type) == ARRAY_TYPE;
7175 type = TREE_TYPE (type), dimension_number++)
7177 #endif
7178 register tree domain = TYPE_DOMAIN (type);
7180 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7181 and (in GNU C only) variable bounds. Handle all three forms
7182 here. */
7183 subrange_die = new_die (DW_TAG_subrange_type, type_die);
7184 if (domain)
7186 /* We have an array type with specified bounds. */
7187 lower = TYPE_MIN_VALUE (domain);
7188 upper = TYPE_MAX_VALUE (domain);
7190 /* define the index type. */
7191 if (TREE_TYPE (domain))
7193 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7194 TREE_TYPE field. We can't emit debug info for this
7195 because it is an unnamed integral type. */
7196 if (TREE_CODE (domain) == INTEGER_TYPE
7197 && TYPE_NAME (domain) == NULL_TREE
7198 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
7199 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
7201 else
7202 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7203 type_die);
7206 /* ??? If upper is NULL, the array has unspecified length,
7207 but it does have a lower bound. This happens with Fortran
7208 dimension arr(N:*)
7209 Since the debugger is definitely going to need to know N
7210 to produce useful results, go ahead and output the lower
7211 bound solo, and hope the debugger can cope. */
7213 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
7214 if (upper)
7215 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
7217 else
7218 /* We have an array type with an unspecified length. The DWARF-2
7219 spec does not say how to handle this; let's just leave out the
7220 bounds. */
7224 #ifndef MIPS_DEBUGGING_INFO
7226 #endif
7229 static void
7230 add_byte_size_attribute (die, tree_node)
7231 dw_die_ref die;
7232 register tree tree_node;
7234 register unsigned size;
7236 switch (TREE_CODE (tree_node))
7238 case ERROR_MARK:
7239 size = 0;
7240 break;
7241 case ENUMERAL_TYPE:
7242 case RECORD_TYPE:
7243 case UNION_TYPE:
7244 case QUAL_UNION_TYPE:
7245 size = int_size_in_bytes (tree_node);
7246 break;
7247 case FIELD_DECL:
7248 /* For a data member of a struct or union, the DW_AT_byte_size is
7249 generally given as the number of bytes normally allocated for an
7250 object of the *declared* type of the member itself. This is true
7251 even for bit-fields. */
7252 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
7253 break;
7254 default:
7255 abort ();
7258 /* Note that `size' might be -1 when we get to this point. If it is, that
7259 indicates that the byte size of the entity in question is variable. We
7260 have no good way of expressing this fact in Dwarf at the present time,
7261 so just let the -1 pass on through. */
7263 add_AT_unsigned (die, DW_AT_byte_size, size);
7266 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7267 which specifies the distance in bits from the highest order bit of the
7268 "containing object" for the bit-field to the highest order bit of the
7269 bit-field itself.
7271 For any given bit-field, the "containing object" is a hypothetical
7272 object (of some integral or enum type) within which the given bit-field
7273 lives. The type of this hypothetical "containing object" is always the
7274 same as the declared type of the individual bit-field itself. The
7275 determination of the exact location of the "containing object" for a
7276 bit-field is rather complicated. It's handled by the
7277 `field_byte_offset' function (above).
7279 Note that it is the size (in bytes) of the hypothetical "containing object"
7280 which will be given in the DW_AT_byte_size attribute for this bit-field.
7281 (See `byte_size_attribute' above). */
7283 static inline void
7284 add_bit_offset_attribute (die, decl)
7285 register dw_die_ref die;
7286 register tree decl;
7288 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
7289 tree type = DECL_BIT_FIELD_TYPE (decl);
7290 HOST_WIDE_INT bitpos_int;
7291 HOST_WIDE_INT highest_order_object_bit_offset;
7292 HOST_WIDE_INT highest_order_field_bit_offset;
7293 HOST_WIDE_INT unsigned bit_offset;
7295 /* Must be a field and a bit field. */
7296 if (!type
7297 || TREE_CODE (decl) != FIELD_DECL)
7298 abort ();
7300 /* We can't yet handle bit-fields whose offsets are variable, so if we
7301 encounter such things, just return without generating any attribute
7302 whatsoever. Likewise for variable or too large size. */
7303 if (! host_integerp (bit_position (decl), 0)
7304 || ! host_integerp (DECL_SIZE (decl), 1))
7305 return;
7307 bitpos_int = int_bit_position (decl);
7309 /* Note that the bit offset is always the distance (in bits) from the
7310 highest-order bit of the "containing object" to the highest-order bit of
7311 the bit-field itself. Since the "high-order end" of any object or field
7312 is different on big-endian and little-endian machines, the computation
7313 below must take account of these differences. */
7314 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
7315 highest_order_field_bit_offset = bitpos_int;
7317 if (! BYTES_BIG_ENDIAN)
7319 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
7320 highest_order_object_bit_offset += simple_type_size_in_bits (type);
7323 bit_offset
7324 = (! BYTES_BIG_ENDIAN
7325 ? highest_order_object_bit_offset - highest_order_field_bit_offset
7326 : highest_order_field_bit_offset - highest_order_object_bit_offset);
7328 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7331 /* For a FIELD_DECL node which represents a bit field, output an attribute
7332 which specifies the length in bits of the given field. */
7334 static inline void
7335 add_bit_size_attribute (die, decl)
7336 register dw_die_ref die;
7337 register tree decl;
7339 /* Must be a field and a bit field. */
7340 if (TREE_CODE (decl) != FIELD_DECL
7341 || ! DECL_BIT_FIELD_TYPE (decl))
7342 abort ();
7344 if (host_integerp (DECL_SIZE (decl), 1))
7345 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
7348 /* If the compiled language is ANSI C, then add a 'prototyped'
7349 attribute, if arg types are given for the parameters of a function. */
7351 static inline void
7352 add_prototyped_attribute (die, func_type)
7353 register dw_die_ref die;
7354 register tree func_type;
7356 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
7357 && TYPE_ARG_TYPES (func_type) != NULL)
7358 add_AT_flag (die, DW_AT_prototyped, 1);
7362 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7363 by looking in either the type declaration or object declaration
7364 equate table. */
7366 static inline void
7367 add_abstract_origin_attribute (die, origin)
7368 register dw_die_ref die;
7369 register tree origin;
7371 dw_die_ref origin_die = NULL;
7373 if (TREE_CODE (origin) != FUNCTION_DECL)
7375 /* We may have gotten separated from the block for the inlined
7376 function, if we're in an exception handler or some such; make
7377 sure that the abstract function has been written out.
7379 Doing this for nested functions is wrong, however; functions are
7380 distinct units, and our context might not even be inline. */
7381 tree fn = origin;
7382 if (TYPE_P (fn))
7383 fn = TYPE_STUB_DECL (fn);
7384 fn = decl_function_context (fn);
7385 if (fn)
7386 gen_abstract_function (fn);
7389 if (DECL_P (origin))
7390 origin_die = lookup_decl_die (origin);
7391 else if (TYPE_P (origin))
7392 origin_die = lookup_type_die (origin);
7394 if (origin_die == NULL)
7395 abort ();
7397 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7400 /* We do not currently support the pure_virtual attribute. */
7402 static inline void
7403 add_pure_or_virtual_attribute (die, func_decl)
7404 register dw_die_ref die;
7405 register tree func_decl;
7407 if (DECL_VINDEX (func_decl))
7409 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7411 if (host_integerp (DECL_VINDEX (func_decl), 0))
7412 add_AT_loc (die, DW_AT_vtable_elem_location,
7413 new_loc_descr (DW_OP_constu,
7414 tree_low_cst (DECL_VINDEX (func_decl), 0),
7415 0));
7417 /* GNU extension: Record what type this method came from originally. */
7418 if (debug_info_level > DINFO_LEVEL_TERSE)
7419 add_AT_die_ref (die, DW_AT_containing_type,
7420 lookup_type_die (DECL_CONTEXT (func_decl)));
7424 /* Add source coordinate attributes for the given decl. */
7426 static void
7427 add_src_coords_attributes (die, decl)
7428 register dw_die_ref die;
7429 register tree decl;
7431 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
7433 add_AT_unsigned (die, DW_AT_decl_file, file_index);
7434 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7437 /* Add an DW_AT_name attribute and source coordinate attribute for the
7438 given decl, but only if it actually has a name. */
7440 static void
7441 add_name_and_src_coords_attributes (die, decl)
7442 register dw_die_ref die;
7443 register tree decl;
7445 register tree decl_name;
7447 decl_name = DECL_NAME (decl);
7448 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
7450 add_name_attribute (die, dwarf2_name (decl, 0));
7451 if (! DECL_ARTIFICIAL (decl))
7452 add_src_coords_attributes (die, decl);
7454 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
7455 && TREE_PUBLIC (decl)
7456 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
7457 add_AT_string (die, DW_AT_MIPS_linkage_name,
7458 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7462 /* Push a new declaration scope. */
7464 static void
7465 push_decl_scope (scope)
7466 tree scope;
7468 /* Make room in the decl_scope_table, if necessary. */
7469 if (decl_scope_table_allocated == decl_scope_depth)
7471 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
7472 decl_scope_table
7473 = (tree *) xrealloc (decl_scope_table,
7474 decl_scope_table_allocated * sizeof (tree));
7477 decl_scope_table[decl_scope_depth] = scope;
7478 decl_scope_depth++;
7481 /* Pop a declaration scope. */
7482 static inline void
7483 pop_decl_scope ()
7485 if (decl_scope_depth <= 0)
7486 abort ();
7487 --decl_scope_depth;
7490 /* Return the DIE for the scope that immediately contains this type.
7491 Non-named types get global scope. Named types nested in other
7492 types get their containing scope if it's open, or global scope
7493 otherwise. All other types (i.e. function-local named types) get
7494 the current active scope. */
7496 static dw_die_ref
7497 scope_die_for (t, context_die)
7498 register tree t;
7499 register dw_die_ref context_die;
7501 register dw_die_ref scope_die = NULL;
7502 register tree containing_scope;
7503 register int i;
7505 /* Non-types always go in the current scope. */
7506 if (! TYPE_P (t))
7507 abort ();
7509 containing_scope = TYPE_CONTEXT (t);
7511 /* Ignore namespaces for the moment. */
7512 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
7513 containing_scope = NULL_TREE;
7515 /* Ignore function type "scopes" from the C frontend. They mean that
7516 a tagged type is local to a parmlist of a function declarator, but
7517 that isn't useful to DWARF. */
7518 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
7519 containing_scope = NULL_TREE;
7521 if (containing_scope == NULL_TREE)
7522 scope_die = comp_unit_die;
7523 else if (TYPE_P (containing_scope))
7525 /* For types, we can just look up the appropriate DIE. But
7526 first we check to see if we're in the middle of emitting it
7527 so we know where the new DIE should go. */
7529 for (i = decl_scope_depth - 1; i >= 0; --i)
7530 if (decl_scope_table[i] == containing_scope)
7531 break;
7533 if (i < 0)
7535 if (debug_info_level > DINFO_LEVEL_TERSE
7536 && !TREE_ASM_WRITTEN (containing_scope))
7537 abort ();
7539 /* If none of the current dies are suitable, we get file scope. */
7540 scope_die = comp_unit_die;
7542 else
7543 scope_die = lookup_type_die (containing_scope);
7545 else
7546 scope_die = context_die;
7548 return scope_die;
7551 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
7553 static inline int local_scope_p PARAMS ((dw_die_ref));
7554 static inline int
7555 local_scope_p (context_die)
7556 dw_die_ref context_die;
7558 for (; context_die; context_die = context_die->die_parent)
7559 if (context_die->die_tag == DW_TAG_inlined_subroutine
7560 || context_die->die_tag == DW_TAG_subprogram)
7561 return 1;
7562 return 0;
7565 /* Returns nonzero iff CONTEXT_DIE is a class. */
7567 static inline int class_scope_p PARAMS ((dw_die_ref));
7568 static inline int
7569 class_scope_p (context_die)
7570 dw_die_ref context_die;
7572 return (context_die
7573 && (context_die->die_tag == DW_TAG_structure_type
7574 || context_die->die_tag == DW_TAG_union_type));
7577 /* Many forms of DIEs require a "type description" attribute. This
7578 routine locates the proper "type descriptor" die for the type given
7579 by 'type', and adds an DW_AT_type attribute below the given die. */
7581 static void
7582 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7583 register dw_die_ref object_die;
7584 register tree type;
7585 register int decl_const;
7586 register int decl_volatile;
7587 register dw_die_ref context_die;
7589 register enum tree_code code = TREE_CODE (type);
7590 register dw_die_ref type_die = NULL;
7592 /* ??? If this type is an unnamed subrange type of an integral or
7593 floating-point type, use the inner type. This is because we have no
7594 support for unnamed types in base_type_die. This can happen if this is
7595 an Ada subrange type. Correct solution is emit a subrange type die. */
7596 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7597 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7598 type = TREE_TYPE (type), code = TREE_CODE (type);
7600 if (code == ERROR_MARK)
7601 return;
7603 /* Handle a special case. For functions whose return type is void, we
7604 generate *no* type attribute. (Note that no object may have type
7605 `void', so this only applies to function return types). */
7606 if (code == VOID_TYPE)
7607 return;
7609 type_die = modified_type_die (type,
7610 decl_const || TYPE_READONLY (type),
7611 decl_volatile || TYPE_VOLATILE (type),
7612 context_die);
7613 if (type_die != NULL)
7614 add_AT_die_ref (object_die, DW_AT_type, type_die);
7617 /* Given a tree pointer to a struct, class, union, or enum type node, return
7618 a pointer to the (string) tag name for the given type, or zero if the type
7619 was declared without a tag. */
7621 static char *
7622 type_tag (type)
7623 register tree type;
7625 register char *name = 0;
7627 if (TYPE_NAME (type) != 0)
7629 register tree t = 0;
7631 /* Find the IDENTIFIER_NODE for the type name. */
7632 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7633 t = TYPE_NAME (type);
7635 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7636 a TYPE_DECL node, regardless of whether or not a `typedef' was
7637 involved. */
7638 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7639 && ! DECL_IGNORED_P (TYPE_NAME (type)))
7640 t = DECL_NAME (TYPE_NAME (type));
7642 /* Now get the name as a string, or invent one. */
7643 if (t != 0)
7644 name = IDENTIFIER_POINTER (t);
7647 return (name == 0 || *name == '\0') ? 0 : name;
7650 /* Return the type associated with a data member, make a special check
7651 for bit field types. */
7653 static inline tree
7654 member_declared_type (member)
7655 register tree member;
7657 return (DECL_BIT_FIELD_TYPE (member)
7658 ? DECL_BIT_FIELD_TYPE (member)
7659 : TREE_TYPE (member));
7662 /* Get the decl's label, as described by its RTL. This may be different
7663 from the DECL_NAME name used in the source file. */
7665 #if 0
7666 static char *
7667 decl_start_label (decl)
7668 register tree decl;
7670 rtx x;
7671 char *fnname;
7672 x = DECL_RTL (decl);
7673 if (GET_CODE (x) != MEM)
7674 abort ();
7676 x = XEXP (x, 0);
7677 if (GET_CODE (x) != SYMBOL_REF)
7678 abort ();
7680 fnname = XSTR (x, 0);
7681 return fnname;
7683 #endif
7685 /* These routines generate the internal representation of the DIE's for
7686 the compilation unit. Debugging information is collected by walking
7687 the declaration trees passed in from dwarf2out_decl(). */
7689 static void
7690 gen_array_type_die (type, context_die)
7691 register tree type;
7692 register dw_die_ref context_die;
7694 register dw_die_ref scope_die = scope_die_for (type, context_die);
7695 register dw_die_ref array_die;
7696 register tree element_type;
7698 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7699 the inner array type comes before the outer array type. Thus we must
7700 call gen_type_die before we call new_die. See below also. */
7701 #ifdef MIPS_DEBUGGING_INFO
7702 gen_type_die (TREE_TYPE (type), context_die);
7703 #endif
7705 array_die = new_die (DW_TAG_array_type, scope_die);
7707 #if 0
7708 /* We default the array ordering. SDB will probably do
7709 the right things even if DW_AT_ordering is not present. It's not even
7710 an issue until we start to get into multidimensional arrays anyway. If
7711 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7712 then we'll have to put the DW_AT_ordering attribute back in. (But if
7713 and when we find out that we need to put these in, we will only do so
7714 for multidimensional arrays. */
7715 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
7716 #endif
7718 #ifdef MIPS_DEBUGGING_INFO
7719 /* The SGI compilers handle arrays of unknown bound by setting
7720 AT_declaration and not emitting any subrange DIEs. */
7721 if (! TYPE_DOMAIN (type))
7722 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7723 else
7724 #endif
7725 add_subscript_info (array_die, type);
7727 add_name_attribute (array_die, type_tag (type));
7728 equate_type_number_to_die (type, array_die);
7730 /* Add representation of the type of the elements of this array type. */
7731 element_type = TREE_TYPE (type);
7733 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7734 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7735 We work around this by disabling this feature. See also
7736 add_subscript_info. */
7737 #ifndef MIPS_DEBUGGING_INFO
7738 while (TREE_CODE (element_type) == ARRAY_TYPE)
7739 element_type = TREE_TYPE (element_type);
7741 gen_type_die (element_type, context_die);
7742 #endif
7744 add_type_attribute (array_die, element_type, 0, 0, context_die);
7747 static void
7748 gen_set_type_die (type, context_die)
7749 register tree type;
7750 register dw_die_ref context_die;
7752 register dw_die_ref type_die
7753 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7755 equate_type_number_to_die (type, type_die);
7756 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7759 #if 0
7760 static void
7761 gen_entry_point_die (decl, context_die)
7762 register tree decl;
7763 register dw_die_ref context_die;
7765 register tree origin = decl_ultimate_origin (decl);
7766 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7767 if (origin != NULL)
7768 add_abstract_origin_attribute (decl_die, origin);
7769 else
7771 add_name_and_src_coords_attributes (decl_die, decl);
7772 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7773 0, 0, context_die);
7776 if (DECL_ABSTRACT (decl))
7777 equate_decl_number_to_die (decl, decl_die);
7778 else
7779 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
7781 #endif
7783 /* Remember a type in the incomplete_types_list. */
7785 static void
7786 add_incomplete_type (type)
7787 tree type;
7789 if (incomplete_types == incomplete_types_allocated)
7791 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
7792 incomplete_types_list
7793 = (tree *) xrealloc (incomplete_types_list,
7794 sizeof (tree) * incomplete_types_allocated);
7797 incomplete_types_list[incomplete_types++] = type;
7800 /* Walk through the list of incomplete types again, trying once more to
7801 emit full debugging info for them. */
7803 static void
7804 retry_incomplete_types ()
7806 register tree type;
7808 while (incomplete_types)
7810 --incomplete_types;
7811 type = incomplete_types_list[incomplete_types];
7812 gen_type_die (type, comp_unit_die);
7816 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7818 static void
7819 gen_inlined_enumeration_type_die (type, context_die)
7820 register tree type;
7821 register dw_die_ref context_die;
7823 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
7824 context_die);
7825 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7826 be incomplete and such types are not marked. */
7827 add_abstract_origin_attribute (type_die, type);
7830 /* Generate a DIE to represent an inlined instance of a structure type. */
7832 static void
7833 gen_inlined_structure_type_die (type, context_die)
7834 register tree type;
7835 register dw_die_ref context_die;
7837 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
7839 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7840 be incomplete and such types are not marked. */
7841 add_abstract_origin_attribute (type_die, type);
7844 /* Generate a DIE to represent an inlined instance of a union type. */
7846 static void
7847 gen_inlined_union_type_die (type, context_die)
7848 register tree type;
7849 register dw_die_ref context_die;
7851 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
7853 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7854 be incomplete and such types are not marked. */
7855 add_abstract_origin_attribute (type_die, type);
7858 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7859 include all of the information about the enumeration values also. Each
7860 enumerated type name/value is listed as a child of the enumerated type
7861 DIE. */
7863 static void
7864 gen_enumeration_type_die (type, context_die)
7865 register tree type;
7866 register dw_die_ref context_die;
7868 register dw_die_ref type_die = lookup_type_die (type);
7870 if (type_die == NULL)
7872 type_die = new_die (DW_TAG_enumeration_type,
7873 scope_die_for (type, context_die));
7874 equate_type_number_to_die (type, type_die);
7875 add_name_attribute (type_die, type_tag (type));
7877 else if (! TYPE_SIZE (type))
7878 return;
7879 else
7880 remove_AT (type_die, DW_AT_declaration);
7882 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7883 given enum type is incomplete, do not generate the DW_AT_byte_size
7884 attribute or the DW_AT_element_list attribute. */
7885 if (TYPE_SIZE (type))
7887 register tree link;
7889 TREE_ASM_WRITTEN (type) = 1;
7890 add_byte_size_attribute (type_die, type);
7891 if (TYPE_STUB_DECL (type) != NULL_TREE)
7892 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7894 /* If the first reference to this type was as the return type of an
7895 inline function, then it may not have a parent. Fix this now. */
7896 if (type_die->die_parent == NULL)
7897 add_child_die (scope_die_for (type, context_die), type_die);
7899 for (link = TYPE_FIELDS (type);
7900 link != NULL; link = TREE_CHAIN (link))
7902 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
7904 add_name_attribute (enum_die,
7905 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
7907 if (host_integerp (TREE_VALUE (link), 0))
7909 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
7910 add_AT_int (enum_die, DW_AT_const_value,
7911 tree_low_cst (TREE_VALUE (link), 0));
7912 else
7913 add_AT_unsigned (enum_die, DW_AT_const_value,
7914 tree_low_cst (TREE_VALUE (link), 0));
7918 else
7919 add_AT_flag (type_die, DW_AT_declaration, 1);
7923 /* Generate a DIE to represent either a real live formal parameter decl or to
7924 represent just the type of some formal parameter position in some function
7925 type.
7927 Note that this routine is a bit unusual because its argument may be a
7928 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7929 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7930 node. If it's the former then this function is being called to output a
7931 DIE to represent a formal parameter object (or some inlining thereof). If
7932 it's the latter, then this function is only being called to output a
7933 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7934 argument type of some subprogram type. */
7936 static dw_die_ref
7937 gen_formal_parameter_die (node, context_die)
7938 register tree node;
7939 register dw_die_ref context_die;
7941 register dw_die_ref parm_die
7942 = new_die (DW_TAG_formal_parameter, context_die);
7943 register tree origin;
7945 switch (TREE_CODE_CLASS (TREE_CODE (node)))
7947 case 'd':
7948 origin = decl_ultimate_origin (node);
7949 if (origin != NULL)
7950 add_abstract_origin_attribute (parm_die, origin);
7951 else
7953 add_name_and_src_coords_attributes (parm_die, node);
7954 add_type_attribute (parm_die, TREE_TYPE (node),
7955 TREE_READONLY (node),
7956 TREE_THIS_VOLATILE (node),
7957 context_die);
7958 if (DECL_ARTIFICIAL (node))
7959 add_AT_flag (parm_die, DW_AT_artificial, 1);
7962 equate_decl_number_to_die (node, parm_die);
7963 if (! DECL_ABSTRACT (node))
7964 add_location_or_const_value_attribute (parm_die, node);
7966 break;
7968 case 't':
7969 /* We were called with some kind of a ..._TYPE node. */
7970 add_type_attribute (parm_die, node, 0, 0, context_die);
7971 break;
7973 default:
7974 abort ();
7977 return parm_die;
7980 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7981 at the end of an (ANSI prototyped) formal parameters list. */
7983 static void
7984 gen_unspecified_parameters_die (decl_or_type, context_die)
7985 register tree decl_or_type ATTRIBUTE_UNUSED;
7986 register dw_die_ref context_die;
7988 new_die (DW_TAG_unspecified_parameters, context_die);
7991 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
7992 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
7993 parameters as specified in some function type specification (except for
7994 those which appear as part of a function *definition*).
7996 Note we must be careful here to output all of the parameter DIEs before*
7997 we output any DIEs needed to represent the types of the formal parameters.
7998 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
7999 non-parameter DIE it sees ends the formal parameter list. */
8001 static void
8002 gen_formal_types_die (function_or_method_type, context_die)
8003 register tree function_or_method_type;
8004 register dw_die_ref context_die;
8006 register tree link;
8007 register tree formal_type = NULL;
8008 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
8010 #if 0
8011 /* In the case where we are generating a formal types list for a C++
8012 non-static member function type, skip over the first thing on the
8013 TYPE_ARG_TYPES list because it only represents the type of the hidden
8014 `this pointer'. The debugger should be able to figure out (without
8015 being explicitly told) that this non-static member function type takes a
8016 `this pointer' and should be able to figure what the type of that hidden
8017 parameter is from the DW_AT_member attribute of the parent
8018 DW_TAG_subroutine_type DIE. */
8019 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8020 first_parm_type = TREE_CHAIN (first_parm_type);
8021 #endif
8023 /* Make our first pass over the list of formal parameter types and output a
8024 DW_TAG_formal_parameter DIE for each one. */
8025 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8027 register dw_die_ref parm_die;
8029 formal_type = TREE_VALUE (link);
8030 if (formal_type == void_type_node)
8031 break;
8033 /* Output a (nameless) DIE to represent the formal parameter itself. */
8034 parm_die = gen_formal_parameter_die (formal_type, context_die);
8035 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8036 && link == first_parm_type)
8037 add_AT_flag (parm_die, DW_AT_artificial, 1);
8040 /* If this function type has an ellipsis, add a
8041 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8042 if (formal_type != void_type_node)
8043 gen_unspecified_parameters_die (function_or_method_type, context_die);
8045 /* Make our second (and final) pass over the list of formal parameter types
8046 and output DIEs to represent those types (as necessary). */
8047 for (link = TYPE_ARG_TYPES (function_or_method_type);
8048 link;
8049 link = TREE_CHAIN (link))
8051 formal_type = TREE_VALUE (link);
8052 if (formal_type == void_type_node)
8053 break;
8055 gen_type_die (formal_type, context_die);
8059 /* We want to generate the DIE for TYPE so that we can generate the
8060 die for MEMBER, which has been defined; we will need to refer back
8061 to the member declaration nested within TYPE. If we're trying to
8062 generate minimal debug info for TYPE, processing TYPE won't do the
8063 trick; we need to attach the member declaration by hand. */
8065 static void
8066 gen_type_die_for_member (type, member, context_die)
8067 tree type, member;
8068 dw_die_ref context_die;
8070 gen_type_die (type, context_die);
8072 /* If we're trying to avoid duplicate debug info, we may not have
8073 emitted the member decl for this function. Emit it now. */
8074 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
8075 && ! lookup_decl_die (member))
8077 if (decl_ultimate_origin (member))
8078 abort ();
8080 push_decl_scope (type);
8081 if (TREE_CODE (member) == FUNCTION_DECL)
8082 gen_subprogram_die (member, lookup_type_die (type));
8083 else
8084 gen_variable_die (member, lookup_type_die (type));
8085 pop_decl_scope ();
8089 /* Generate the DWARF2 info for the "abstract" instance
8090 of a function which we may later generate inlined and/or
8091 out-of-line instances of. */
8093 static void
8094 gen_abstract_function (decl)
8095 tree decl;
8097 register dw_die_ref old_die = lookup_decl_die (decl);
8098 tree save_fn;
8100 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
8101 /* We've already generated the abstract instance. */
8102 return;
8104 save_fn = current_function_decl;
8105 current_function_decl = decl;
8107 set_decl_abstract_flags (decl, 1);
8108 dwarf2out_decl (decl);
8109 set_decl_abstract_flags (decl, 0);
8111 current_function_decl = save_fn;
8114 /* Generate a DIE to represent a declared function (either file-scope or
8115 block-local). */
8117 static void
8118 gen_subprogram_die (decl, context_die)
8119 register tree decl;
8120 register dw_die_ref context_die;
8122 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
8123 register tree origin = decl_ultimate_origin (decl);
8124 register dw_die_ref subr_die;
8125 register rtx fp_reg;
8126 register tree fn_arg_types;
8127 register tree outer_scope;
8128 register dw_die_ref old_die = lookup_decl_die (decl);
8129 register int declaration = (current_function_decl != decl
8130 || class_scope_p (context_die));
8132 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
8133 be true, if we started to generate the abstract instance of an inline,
8134 decided to output its containing class, and proceeded to emit the
8135 declaration of the inline from the member list for the class. In that
8136 case, `declaration' takes priority; we'll get back to the abstract
8137 instance when we're done with the class. */
8139 if (origin != NULL)
8141 if (declaration && ! local_scope_p (context_die))
8142 abort ();
8144 subr_die = new_die (DW_TAG_subprogram, context_die);
8145 add_abstract_origin_attribute (subr_die, origin);
8147 else if (old_die && DECL_ABSTRACT (decl)
8148 && get_AT_unsigned (old_die, DW_AT_inline))
8150 /* This must be a redefinition of an extern inline function.
8151 We can just reuse the old die here. */
8152 subr_die = old_die;
8154 /* Clear out the inlined attribute and parm types. */
8155 remove_AT (subr_die, DW_AT_inline);
8156 remove_children (subr_die);
8158 else if (old_die)
8160 register unsigned file_index
8161 = lookup_filename (DECL_SOURCE_FILE (decl));
8163 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
8165 /* ??? This can happen if there is a bug in the program, for
8166 instance, if it has duplicate function definitions. Ideally,
8167 we should detect this case and ignore it. For now, if we have
8168 already reported an error, any error at all, then assume that
8169 we got here because of a input error, not a dwarf2 bug. */
8170 if (errorcount)
8171 return;
8172 abort ();
8175 /* If the definition comes from the same place as the declaration,
8176 maybe use the old DIE. We always want the DIE for this function
8177 that has the *_pc attributes to be under comp_unit_die so the
8178 debugger can find it. For inlines, that is the concrete instance,
8179 so we can use the old DIE here. For non-inline methods, we want a
8180 specification DIE at toplevel, so we need a new DIE. For local
8181 class methods, this doesn't apply; we just use the old DIE. */
8182 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
8183 || context_die == NULL)
8184 && (DECL_ARTIFICIAL (decl)
8185 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
8186 && (get_AT_unsigned (old_die, DW_AT_decl_line)
8187 == (unsigned)DECL_SOURCE_LINE (decl)))))
8189 subr_die = old_die;
8191 /* Clear out the declaration attribute and the parm types. */
8192 remove_AT (subr_die, DW_AT_declaration);
8193 remove_children (subr_die);
8195 else
8197 subr_die = new_die (DW_TAG_subprogram, context_die);
8198 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
8199 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8200 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
8201 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8202 != (unsigned)DECL_SOURCE_LINE (decl))
8203 add_AT_unsigned
8204 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8207 else
8209 subr_die = new_die (DW_TAG_subprogram, context_die);
8211 if (TREE_PUBLIC (decl))
8212 add_AT_flag (subr_die, DW_AT_external, 1);
8214 add_name_and_src_coords_attributes (subr_die, decl);
8215 if (debug_info_level > DINFO_LEVEL_TERSE)
8217 register tree type = TREE_TYPE (decl);
8219 add_prototyped_attribute (subr_die, type);
8220 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
8223 add_pure_or_virtual_attribute (subr_die, decl);
8224 if (DECL_ARTIFICIAL (decl))
8225 add_AT_flag (subr_die, DW_AT_artificial, 1);
8226 if (TREE_PROTECTED (decl))
8227 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
8228 else if (TREE_PRIVATE (decl))
8229 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
8232 if (declaration)
8234 if (! origin)
8235 add_AT_flag (subr_die, DW_AT_declaration, 1);
8237 /* The first time we see a member function, it is in the context of
8238 the class to which it belongs. We make sure of this by emitting
8239 the class first. The next time is the definition, which is
8240 handled above. The two may come from the same source text. */
8241 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
8242 equate_decl_number_to_die (decl, subr_die);
8244 else if (DECL_ABSTRACT (decl))
8246 if (DECL_INLINE (decl) && !flag_no_inline)
8248 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
8249 inline functions, but not for extern inline functions.
8250 We can't get this completely correct because information
8251 about whether the function was declared inline is not
8252 saved anywhere. */
8253 if (DECL_DEFER_OUTPUT (decl))
8254 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8255 else
8256 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8258 else
8259 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
8261 equate_decl_number_to_die (decl, subr_die);
8263 else if (!DECL_EXTERNAL (decl))
8265 if (origin == NULL_TREE)
8266 equate_decl_number_to_die (decl, subr_die);
8268 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8269 current_funcdef_number);
8270 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
8271 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8272 current_funcdef_number);
8273 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8275 add_pubname (decl, subr_die);
8276 add_arange (decl, subr_die);
8278 #ifdef MIPS_DEBUGGING_INFO
8279 /* Add a reference to the FDE for this routine. */
8280 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8281 #endif
8283 /* Define the "frame base" location for this routine. We use the
8284 frame pointer or stack pointer registers, since the RTL for local
8285 variables is relative to one of them. */
8286 fp_reg
8287 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8288 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
8290 #if 0
8291 /* ??? This fails for nested inline functions, because context_display
8292 is not part of the state saved/restored for inline functions. */
8293 if (current_function_needs_context)
8294 add_AT_location_description (subr_die, DW_AT_static_link,
8295 lookup_static_chain (decl));
8296 #endif
8299 /* Now output descriptions of the arguments for this function. This gets
8300 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8301 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8302 `...' at the end of the formal parameter list. In order to find out if
8303 there was a trailing ellipsis or not, we must instead look at the type
8304 associated with the FUNCTION_DECL. This will be a node of type
8305 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8306 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8307 an ellipsis at the end. */
8309 /* In the case where we are describing a mere function declaration, all we
8310 need to do here (and all we *can* do here) is to describe the *types* of
8311 its formal parameters. */
8312 if (debug_info_level <= DINFO_LEVEL_TERSE)
8314 else if (declaration)
8315 gen_formal_types_die (TREE_TYPE (decl), subr_die);
8316 else
8318 /* Generate DIEs to represent all known formal parameters */
8319 register tree arg_decls = DECL_ARGUMENTS (decl);
8320 register tree parm;
8322 /* When generating DIEs, generate the unspecified_parameters DIE
8323 instead if we come across the arg "__builtin_va_alist" */
8324 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
8325 if (TREE_CODE (parm) == PARM_DECL)
8327 if (DECL_NAME (parm)
8328 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8329 "__builtin_va_alist"))
8330 gen_unspecified_parameters_die (parm, subr_die);
8331 else
8332 gen_decl_die (parm, subr_die);
8335 /* Decide whether we need a unspecified_parameters DIE at the end.
8336 There are 2 more cases to do this for: 1) the ansi ... declaration -
8337 this is detectable when the end of the arg list is not a
8338 void_type_node 2) an unprototyped function declaration (not a
8339 definition). This just means that we have no info about the
8340 parameters at all. */
8341 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
8342 if (fn_arg_types != NULL)
8344 /* this is the prototyped case, check for ... */
8345 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
8346 gen_unspecified_parameters_die (decl, subr_die);
8348 else if (DECL_INITIAL (decl) == NULL_TREE)
8349 gen_unspecified_parameters_die (decl, subr_die);
8352 /* Output Dwarf info for all of the stuff within the body of the function
8353 (if it has one - it may be just a declaration). */
8354 outer_scope = DECL_INITIAL (decl);
8356 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8357 node created to represent a function. This outermost BLOCK actually
8358 represents the outermost binding contour for the function, i.e. the
8359 contour in which the function's formal parameters and labels get
8360 declared. Curiously, it appears that the front end doesn't actually
8361 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8362 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8363 list for the function instead.) The BLOCK_VARS list for the
8364 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8365 the function however, and we output DWARF info for those in
8366 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8367 node representing the function's outermost pair of curly braces, and
8368 any blocks used for the base and member initializers of a C++
8369 constructor function. */
8370 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
8372 current_function_has_inlines = 0;
8373 decls_for_scope (outer_scope, subr_die, 0);
8375 #if 0 && defined (MIPS_DEBUGGING_INFO)
8376 if (current_function_has_inlines)
8378 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8379 if (! comp_unit_has_inlines)
8381 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8382 comp_unit_has_inlines = 1;
8385 #endif
8389 /* Generate a DIE to represent a declared data object. */
8391 static void
8392 gen_variable_die (decl, context_die)
8393 register tree decl;
8394 register dw_die_ref context_die;
8396 register tree origin = decl_ultimate_origin (decl);
8397 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
8399 dw_die_ref old_die = lookup_decl_die (decl);
8400 int declaration = (DECL_EXTERNAL (decl)
8401 || class_scope_p (context_die));
8403 if (origin != NULL)
8404 add_abstract_origin_attribute (var_die, origin);
8405 /* Loop unrolling can create multiple blocks that refer to the same
8406 static variable, so we must test for the DW_AT_declaration flag. */
8407 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8408 copy decls and set the DECL_ABSTRACT flag on them instead of
8409 sharing them. */
8410 else if (old_die && TREE_STATIC (decl)
8411 && get_AT_flag (old_die, DW_AT_declaration) == 1)
8413 /* This is a definition of a C++ class level static. */
8414 add_AT_die_ref (var_die, DW_AT_specification, old_die);
8415 if (DECL_NAME (decl))
8417 register unsigned file_index
8418 = lookup_filename (DECL_SOURCE_FILE (decl));
8420 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8421 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
8423 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8424 != (unsigned)DECL_SOURCE_LINE (decl))
8426 add_AT_unsigned (var_die, DW_AT_decl_line,
8427 DECL_SOURCE_LINE (decl));
8430 else
8432 add_name_and_src_coords_attributes (var_die, decl);
8433 add_type_attribute (var_die, TREE_TYPE (decl),
8434 TREE_READONLY (decl),
8435 TREE_THIS_VOLATILE (decl), context_die);
8437 if (TREE_PUBLIC (decl))
8438 add_AT_flag (var_die, DW_AT_external, 1);
8440 if (DECL_ARTIFICIAL (decl))
8441 add_AT_flag (var_die, DW_AT_artificial, 1);
8443 if (TREE_PROTECTED (decl))
8444 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
8446 else if (TREE_PRIVATE (decl))
8447 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
8450 if (declaration)
8451 add_AT_flag (var_die, DW_AT_declaration, 1);
8453 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
8454 equate_decl_number_to_die (decl, var_die);
8456 if (! declaration && ! DECL_ABSTRACT (decl))
8458 add_location_or_const_value_attribute (var_die, decl);
8459 add_pubname (decl, var_die);
8463 /* Generate a DIE to represent a label identifier. */
8465 static void
8466 gen_label_die (decl, context_die)
8467 register tree decl;
8468 register dw_die_ref context_die;
8470 register tree origin = decl_ultimate_origin (decl);
8471 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8472 register rtx insn;
8473 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8474 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
8476 if (origin != NULL)
8477 add_abstract_origin_attribute (lbl_die, origin);
8478 else
8479 add_name_and_src_coords_attributes (lbl_die, decl);
8481 if (DECL_ABSTRACT (decl))
8482 equate_decl_number_to_die (decl, lbl_die);
8483 else
8485 insn = DECL_RTL (decl);
8487 /* Deleted labels are programmer specified labels which have been
8488 eliminated because of various optimisations. We still emit them
8489 here so that it is possible to put breakpoints on them. */
8490 if (GET_CODE (insn) == CODE_LABEL
8491 || ((GET_CODE (insn) == NOTE
8492 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
8494 /* When optimization is enabled (via -O) some parts of the compiler
8495 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8496 represent source-level labels which were explicitly declared by
8497 the user. This really shouldn't be happening though, so catch
8498 it if it ever does happen. */
8499 if (INSN_DELETED_P (insn))
8500 abort ();
8502 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8503 ASM_GENERATE_INTERNAL_LABEL (label, label2,
8504 (unsigned) INSN_UID (insn));
8505 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8510 /* Generate a DIE for a lexical block. */
8512 static void
8513 gen_lexical_block_die (stmt, context_die, depth)
8514 register tree stmt;
8515 register dw_die_ref context_die;
8516 int depth;
8518 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8519 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8521 if (! BLOCK_ABSTRACT (stmt))
8523 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8524 BLOCK_NUMBER (stmt));
8525 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
8526 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
8527 BLOCK_NUMBER (stmt));
8528 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8531 decls_for_scope (stmt, stmt_die, depth);
8534 /* Generate a DIE for an inlined subprogram. */
8536 static void
8537 gen_inlined_subroutine_die (stmt, context_die, depth)
8538 register tree stmt;
8539 register dw_die_ref context_die;
8540 int depth;
8542 if (! BLOCK_ABSTRACT (stmt))
8544 register dw_die_ref subr_die
8545 = new_die (DW_TAG_inlined_subroutine, context_die);
8546 register tree decl = block_ultimate_origin (stmt);
8547 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8549 /* Emit info for the abstract instance first, if we haven't yet. */
8550 gen_abstract_function (decl);
8552 add_abstract_origin_attribute (subr_die, decl);
8553 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8554 BLOCK_NUMBER (stmt));
8555 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
8556 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
8557 BLOCK_NUMBER (stmt));
8558 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
8559 decls_for_scope (stmt, subr_die, depth);
8560 current_function_has_inlines = 1;
8564 /* Generate a DIE for a field in a record, or structure. */
8566 static void
8567 gen_field_die (decl, context_die)
8568 register tree decl;
8569 register dw_die_ref context_die;
8571 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
8573 add_name_and_src_coords_attributes (decl_die, decl);
8574 add_type_attribute (decl_die, member_declared_type (decl),
8575 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8576 context_die);
8578 /* If this is a bit field... */
8579 if (DECL_BIT_FIELD_TYPE (decl))
8581 add_byte_size_attribute (decl_die, decl);
8582 add_bit_size_attribute (decl_die, decl);
8583 add_bit_offset_attribute (decl_die, decl);
8586 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8587 add_data_member_location_attribute (decl_die, decl);
8589 if (DECL_ARTIFICIAL (decl))
8590 add_AT_flag (decl_die, DW_AT_artificial, 1);
8592 if (TREE_PROTECTED (decl))
8593 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
8595 else if (TREE_PRIVATE (decl))
8596 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
8599 #if 0
8600 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8601 Use modified_type_die instead.
8602 We keep this code here just in case these types of DIEs may be needed to
8603 represent certain things in other languages (e.g. Pascal) someday. */
8604 static void
8605 gen_pointer_type_die (type, context_die)
8606 register tree type;
8607 register dw_die_ref context_die;
8609 register dw_die_ref ptr_die
8610 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8612 equate_type_number_to_die (type, ptr_die);
8613 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8614 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8617 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8618 Use modified_type_die instead.
8619 We keep this code here just in case these types of DIEs may be needed to
8620 represent certain things in other languages (e.g. Pascal) someday. */
8621 static void
8622 gen_reference_type_die (type, context_die)
8623 register tree type;
8624 register dw_die_ref context_die;
8626 register dw_die_ref ref_die
8627 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8629 equate_type_number_to_die (type, ref_die);
8630 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
8631 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8633 #endif
8635 /* Generate a DIE for a pointer to a member type. */
8636 static void
8637 gen_ptr_to_mbr_type_die (type, context_die)
8638 register tree type;
8639 register dw_die_ref context_die;
8641 register dw_die_ref ptr_die
8642 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8644 equate_type_number_to_die (type, ptr_die);
8645 add_AT_die_ref (ptr_die, DW_AT_containing_type,
8646 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8647 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8650 /* Generate the DIE for the compilation unit. */
8652 static dw_die_ref
8653 gen_compile_unit_die (filename)
8654 register const char *filename;
8656 register dw_die_ref die;
8657 char producer[250];
8658 char *wd = getpwd ();
8659 int language;
8661 die = new_die (DW_TAG_compile_unit, NULL);
8662 add_name_attribute (die, filename);
8664 if (wd != NULL && filename[0] != DIR_SEPARATOR)
8665 add_AT_string (die, DW_AT_comp_dir, wd);
8667 sprintf (producer, "%s %s", language_string, version_string);
8669 #ifdef MIPS_DEBUGGING_INFO
8670 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8671 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8672 not appear in the producer string, the debugger reaches the conclusion
8673 that the object file is stripped and has no debugging information.
8674 To get the MIPS/SGI debugger to believe that there is debugging
8675 information in the object file, we add a -g to the producer string. */
8676 if (debug_info_level > DINFO_LEVEL_TERSE)
8677 strcat (producer, " -g");
8678 #endif
8680 add_AT_string (die, DW_AT_producer, producer);
8682 if (strcmp (language_string, "GNU C++") == 0)
8683 language = DW_LANG_C_plus_plus;
8684 else if (strcmp (language_string, "GNU Ada") == 0)
8685 language = DW_LANG_Ada83;
8686 else if (strcmp (language_string, "GNU F77") == 0)
8687 language = DW_LANG_Fortran77;
8688 else if (strcmp (language_string, "GNU Pascal") == 0)
8689 language = DW_LANG_Pascal83;
8690 else if (flag_traditional)
8691 language = DW_LANG_C;
8692 else
8693 language = DW_LANG_C89;
8695 add_AT_unsigned (die, DW_AT_language, language);
8697 return die;
8700 /* Generate a DIE for a string type. */
8702 static void
8703 gen_string_type_die (type, context_die)
8704 register tree type;
8705 register dw_die_ref context_die;
8707 register dw_die_ref type_die
8708 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
8710 equate_type_number_to_die (type, type_die);
8712 /* Fudge the string length attribute for now. */
8714 /* TODO: add string length info.
8715 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8716 bound_representation (upper_bound, 0, 'u'); */
8719 /* Generate the DIE for a base class. */
8721 static void
8722 gen_inheritance_die (binfo, context_die)
8723 register tree binfo;
8724 register dw_die_ref context_die;
8726 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
8728 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
8729 add_data_member_location_attribute (die, binfo);
8731 if (TREE_VIA_VIRTUAL (binfo))
8732 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8733 if (TREE_VIA_PUBLIC (binfo))
8734 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
8735 else if (TREE_VIA_PROTECTED (binfo))
8736 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
8739 /* Generate a DIE for a class member. */
8741 static void
8742 gen_member_die (type, context_die)
8743 register tree type;
8744 register dw_die_ref context_die;
8746 register tree member;
8747 dw_die_ref child;
8749 /* If this is not an incomplete type, output descriptions of each of its
8750 members. Note that as we output the DIEs necessary to represent the
8751 members of this record or union type, we will also be trying to output
8752 DIEs to represent the *types* of those members. However the `type'
8753 function (above) will specifically avoid generating type DIEs for member
8754 types *within* the list of member DIEs for this (containing) type execpt
8755 for those types (of members) which are explicitly marked as also being
8756 members of this (containing) type themselves. The g++ front- end can
8757 force any given type to be treated as a member of some other
8758 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8759 to point to the TREE node representing the appropriate (containing)
8760 type. */
8762 /* First output info about the base classes. */
8763 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
8765 register tree bases = TYPE_BINFO_BASETYPES (type);
8766 register int n_bases = TREE_VEC_LENGTH (bases);
8767 register int i;
8769 for (i = 0; i < n_bases; i++)
8770 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
8773 /* Now output info about the data members and type members. */
8774 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
8776 /* If we thought we were generating minimal debug info for TYPE
8777 and then changed our minds, some of the member declarations
8778 may have already been defined. Don't define them again, but
8779 do put them in the right order. */
8781 child = lookup_decl_die (member);
8782 if (child)
8783 splice_child_die (context_die, child);
8784 else
8785 gen_decl_die (member, context_die);
8788 /* Now output info about the function members (if any). */
8789 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
8791 child = lookup_decl_die (member);
8792 if (child)
8793 splice_child_die (context_die, child);
8794 else
8795 gen_decl_die (member, context_die);
8799 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
8800 is set, we pretend that the type was never defined, so we only get the
8801 member DIEs needed by later specification DIEs. */
8803 static void
8804 gen_struct_or_union_type_die (type, context_die)
8805 register tree type;
8806 register dw_die_ref context_die;
8808 register dw_die_ref type_die = lookup_type_die (type);
8809 register dw_die_ref scope_die = 0;
8810 register int nested = 0;
8811 int complete = (TYPE_SIZE (type)
8812 && (! TYPE_STUB_DECL (type)
8813 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
8815 if (type_die && ! complete)
8816 return;
8818 if (TYPE_CONTEXT (type) != NULL_TREE
8819 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
8820 nested = 1;
8822 scope_die = scope_die_for (type, context_die);
8824 if (! type_die || (nested && scope_die == comp_unit_die))
8825 /* First occurrence of type or toplevel definition of nested class. */
8827 register dw_die_ref old_die = type_die;
8829 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8830 ? DW_TAG_structure_type : DW_TAG_union_type,
8831 scope_die);
8832 equate_type_number_to_die (type, type_die);
8833 add_name_attribute (type_die, type_tag (type));
8834 if (old_die)
8835 add_AT_die_ref (type_die, DW_AT_specification, old_die);
8837 else
8838 remove_AT (type_die, DW_AT_declaration);
8840 /* If this type has been completed, then give it a byte_size attribute and
8841 then give a list of members. */
8842 if (complete)
8844 /* Prevent infinite recursion in cases where the type of some member of
8845 this type is expressed in terms of this type itself. */
8846 TREE_ASM_WRITTEN (type) = 1;
8847 add_byte_size_attribute (type_die, type);
8848 if (TYPE_STUB_DECL (type) != NULL_TREE)
8849 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8851 /* If the first reference to this type was as the return type of an
8852 inline function, then it may not have a parent. Fix this now. */
8853 if (type_die->die_parent == NULL)
8854 add_child_die (scope_die, type_die);
8856 push_decl_scope (type);
8857 gen_member_die (type, type_die);
8858 pop_decl_scope ();
8860 /* GNU extension: Record what type our vtable lives in. */
8861 if (TYPE_VFIELD (type))
8863 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
8865 gen_type_die (vtype, context_die);
8866 add_AT_die_ref (type_die, DW_AT_containing_type,
8867 lookup_type_die (vtype));
8870 else
8872 add_AT_flag (type_die, DW_AT_declaration, 1);
8874 /* We don't need to do this for function-local types. */
8875 if (! decl_function_context (TYPE_STUB_DECL (type)))
8876 add_incomplete_type (type);
8880 /* Generate a DIE for a subroutine _type_. */
8882 static void
8883 gen_subroutine_type_die (type, context_die)
8884 register tree type;
8885 register dw_die_ref context_die;
8887 register tree return_type = TREE_TYPE (type);
8888 register dw_die_ref subr_die
8889 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8891 equate_type_number_to_die (type, subr_die);
8892 add_prototyped_attribute (subr_die, type);
8893 add_type_attribute (subr_die, return_type, 0, 0, context_die);
8894 gen_formal_types_die (type, subr_die);
8897 /* Generate a DIE for a type definition */
8899 static void
8900 gen_typedef_die (decl, context_die)
8901 register tree decl;
8902 register dw_die_ref context_die;
8904 register dw_die_ref type_die;
8905 register tree origin;
8907 if (TREE_ASM_WRITTEN (decl))
8908 return;
8909 TREE_ASM_WRITTEN (decl) = 1;
8911 type_die = new_die (DW_TAG_typedef, context_die);
8912 origin = decl_ultimate_origin (decl);
8913 if (origin != NULL)
8914 add_abstract_origin_attribute (type_die, origin);
8915 else
8917 register tree type;
8918 add_name_and_src_coords_attributes (type_die, decl);
8919 if (DECL_ORIGINAL_TYPE (decl))
8921 type = DECL_ORIGINAL_TYPE (decl);
8922 equate_type_number_to_die (TREE_TYPE (decl), type_die);
8924 else
8925 type = TREE_TYPE (decl);
8926 add_type_attribute (type_die, type, TREE_READONLY (decl),
8927 TREE_THIS_VOLATILE (decl), context_die);
8930 if (DECL_ABSTRACT (decl))
8931 equate_decl_number_to_die (decl, type_die);
8934 /* Generate a type description DIE. */
8936 static void
8937 gen_type_die (type, context_die)
8938 register tree type;
8939 register dw_die_ref context_die;
8941 int need_pop;
8943 if (type == NULL_TREE || type == error_mark_node)
8944 return;
8946 /* We are going to output a DIE to represent the unqualified version of
8947 this type (i.e. without any const or volatile qualifiers) so get the
8948 main variant (i.e. the unqualified version) of this type now. */
8949 type = type_main_variant (type);
8951 if (TREE_ASM_WRITTEN (type))
8952 return;
8954 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8955 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8957 TREE_ASM_WRITTEN (type) = 1;
8958 gen_decl_die (TYPE_NAME (type), context_die);
8959 return;
8962 switch (TREE_CODE (type))
8964 case ERROR_MARK:
8965 break;
8967 case POINTER_TYPE:
8968 case REFERENCE_TYPE:
8969 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
8970 ensures that the gen_type_die recursion will terminate even if the
8971 type is recursive. Recursive types are possible in Ada. */
8972 /* ??? We could perhaps do this for all types before the switch
8973 statement. */
8974 TREE_ASM_WRITTEN (type) = 1;
8976 /* For these types, all that is required is that we output a DIE (or a
8977 set of DIEs) to represent the "basis" type. */
8978 gen_type_die (TREE_TYPE (type), context_die);
8979 break;
8981 case OFFSET_TYPE:
8982 /* This code is used for C++ pointer-to-data-member types.
8983 Output a description of the relevant class type. */
8984 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
8986 /* Output a description of the type of the object pointed to. */
8987 gen_type_die (TREE_TYPE (type), context_die);
8989 /* Now output a DIE to represent this pointer-to-data-member type
8990 itself. */
8991 gen_ptr_to_mbr_type_die (type, context_die);
8992 break;
8994 case SET_TYPE:
8995 gen_type_die (TYPE_DOMAIN (type), context_die);
8996 gen_set_type_die (type, context_die);
8997 break;
8999 case FILE_TYPE:
9000 gen_type_die (TREE_TYPE (type), context_die);
9001 abort (); /* No way to represent these in Dwarf yet! */
9002 break;
9004 case FUNCTION_TYPE:
9005 /* Force out return type (in case it wasn't forced out already). */
9006 gen_type_die (TREE_TYPE (type), context_die);
9007 gen_subroutine_type_die (type, context_die);
9008 break;
9010 case METHOD_TYPE:
9011 /* Force out return type (in case it wasn't forced out already). */
9012 gen_type_die (TREE_TYPE (type), context_die);
9013 gen_subroutine_type_die (type, context_die);
9014 break;
9016 case ARRAY_TYPE:
9017 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
9019 gen_type_die (TREE_TYPE (type), context_die);
9020 gen_string_type_die (type, context_die);
9022 else
9023 gen_array_type_die (type, context_die);
9024 break;
9026 case ENUMERAL_TYPE:
9027 case RECORD_TYPE:
9028 case UNION_TYPE:
9029 case QUAL_UNION_TYPE:
9030 /* If this is a nested type whose containing class hasn't been
9031 written out yet, writing it out will cover this one, too.
9032 This does not apply to instantiations of member class templates;
9033 they need to be added to the containing class as they are
9034 generated. FIXME: This hurts the idea of combining type decls
9035 from multiple TUs, since we can't predict what set of template
9036 instantiations we'll get. */
9037 if (TYPE_CONTEXT (type)
9038 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9039 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9041 gen_type_die (TYPE_CONTEXT (type), context_die);
9043 if (TREE_ASM_WRITTEN (type))
9044 return;
9046 /* If that failed, attach ourselves to the stub. */
9047 push_decl_scope (TYPE_CONTEXT (type));
9048 context_die = lookup_type_die (TYPE_CONTEXT (type));
9049 need_pop = 1;
9051 else
9052 need_pop = 0;
9054 if (TREE_CODE (type) == ENUMERAL_TYPE)
9055 gen_enumeration_type_die (type, context_die);
9056 else
9057 gen_struct_or_union_type_die (type, context_die);
9059 if (need_pop)
9060 pop_decl_scope ();
9062 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9063 it up if it is ever completed. gen_*_type_die will set it for us
9064 when appropriate. */
9065 return;
9067 case VOID_TYPE:
9068 case INTEGER_TYPE:
9069 case REAL_TYPE:
9070 case COMPLEX_TYPE:
9071 case BOOLEAN_TYPE:
9072 case CHAR_TYPE:
9073 /* No DIEs needed for fundamental types. */
9074 break;
9076 case LANG_TYPE:
9077 /* No Dwarf representation currently defined. */
9078 break;
9080 default:
9081 abort ();
9084 TREE_ASM_WRITTEN (type) = 1;
9087 /* Generate a DIE for a tagged type instantiation. */
9089 static void
9090 gen_tagged_type_instantiation_die (type, context_die)
9091 register tree type;
9092 register dw_die_ref context_die;
9094 if (type == NULL_TREE || type == error_mark_node)
9095 return;
9097 /* We are going to output a DIE to represent the unqualified version of
9098 this type (i.e. without any const or volatile qualifiers) so make sure
9099 that we have the main variant (i.e. the unqualified version) of this
9100 type now. */
9101 if (type != type_main_variant (type))
9102 abort ();
9104 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
9105 an instance of an unresolved type. */
9107 switch (TREE_CODE (type))
9109 case ERROR_MARK:
9110 break;
9112 case ENUMERAL_TYPE:
9113 gen_inlined_enumeration_type_die (type, context_die);
9114 break;
9116 case RECORD_TYPE:
9117 gen_inlined_structure_type_die (type, context_die);
9118 break;
9120 case UNION_TYPE:
9121 case QUAL_UNION_TYPE:
9122 gen_inlined_union_type_die (type, context_die);
9123 break;
9125 default:
9126 abort ();
9130 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9131 things which are local to the given block. */
9133 static void
9134 gen_block_die (stmt, context_die, depth)
9135 register tree stmt;
9136 register dw_die_ref context_die;
9137 int depth;
9139 register int must_output_die = 0;
9140 register tree origin;
9141 register tree decl;
9142 register enum tree_code origin_code;
9144 /* Ignore blocks never really used to make RTL. */
9146 if (stmt == NULL_TREE || !TREE_USED (stmt)
9147 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
9148 return;
9150 /* Determine the "ultimate origin" of this block. This block may be an
9151 inlined instance of an inlined instance of inline function, so we have
9152 to trace all of the way back through the origin chain to find out what
9153 sort of node actually served as the original seed for the creation of
9154 the current block. */
9155 origin = block_ultimate_origin (stmt);
9156 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
9158 /* Determine if we need to output any Dwarf DIEs at all to represent this
9159 block. */
9160 if (origin_code == FUNCTION_DECL)
9161 /* The outer scopes for inlinings *must* always be represented. We
9162 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9163 must_output_die = 1;
9164 else
9166 /* In the case where the current block represents an inlining of the
9167 "body block" of an inline function, we must *NOT* output any DIE for
9168 this block because we have already output a DIE to represent the
9169 whole inlined function scope and the "body block" of any function
9170 doesn't really represent a different scope according to ANSI C
9171 rules. So we check here to make sure that this block does not
9172 represent a "body block inlining" before trying to set the
9173 `must_output_die' flag. */
9174 if (! is_body_block (origin ? origin : stmt))
9176 /* Determine if this block directly contains any "significant"
9177 local declarations which we will need to output DIEs for. */
9178 if (debug_info_level > DINFO_LEVEL_TERSE)
9179 /* We are not in terse mode so *any* local declaration counts
9180 as being a "significant" one. */
9181 must_output_die = (BLOCK_VARS (stmt) != NULL);
9182 else
9183 /* We are in terse mode, so only local (nested) function
9184 definitions count as "significant" local declarations. */
9185 for (decl = BLOCK_VARS (stmt);
9186 decl != NULL; decl = TREE_CHAIN (decl))
9187 if (TREE_CODE (decl) == FUNCTION_DECL
9188 && DECL_INITIAL (decl))
9190 must_output_die = 1;
9191 break;
9196 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9197 DIE for any block which contains no significant local declarations at
9198 all. Rather, in such cases we just call `decls_for_scope' so that any
9199 needed Dwarf info for any sub-blocks will get properly generated. Note
9200 that in terse mode, our definition of what constitutes a "significant"
9201 local declaration gets restricted to include only inlined function
9202 instances and local (nested) function definitions. */
9203 if (must_output_die)
9205 if (origin_code == FUNCTION_DECL)
9206 gen_inlined_subroutine_die (stmt, context_die, depth);
9207 else
9208 gen_lexical_block_die (stmt, context_die, depth);
9210 else
9211 decls_for_scope (stmt, context_die, depth);
9214 /* Generate all of the decls declared within a given scope and (recursively)
9215 all of its sub-blocks. */
9217 static void
9218 decls_for_scope (stmt, context_die, depth)
9219 register tree stmt;
9220 register dw_die_ref context_die;
9221 int depth;
9223 register tree decl;
9224 register tree subblocks;
9226 /* Ignore blocks never really used to make RTL. */
9227 if (stmt == NULL_TREE || ! TREE_USED (stmt))
9228 return;
9230 /* Output the DIEs to represent all of the data objects and typedefs
9231 declared directly within this block but not within any nested
9232 sub-blocks. Also, nested function and tag DIEs have been
9233 generated with a parent of NULL; fix that up now. */
9234 for (decl = BLOCK_VARS (stmt);
9235 decl != NULL; decl = TREE_CHAIN (decl))
9237 register dw_die_ref die;
9239 if (TREE_CODE (decl) == FUNCTION_DECL)
9240 die = lookup_decl_die (decl);
9241 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9242 die = lookup_type_die (TREE_TYPE (decl));
9243 else
9244 die = NULL;
9246 if (die != NULL && die->die_parent == NULL)
9247 add_child_die (context_die, die);
9248 else
9249 gen_decl_die (decl, context_die);
9252 /* Output the DIEs to represent all sub-blocks (and the items declared
9253 therein) of this block. */
9254 for (subblocks = BLOCK_SUBBLOCKS (stmt);
9255 subblocks != NULL;
9256 subblocks = BLOCK_CHAIN (subblocks))
9257 gen_block_die (subblocks, context_die, depth + 1);
9260 /* Is this a typedef we can avoid emitting? */
9262 static inline int
9263 is_redundant_typedef (decl)
9264 register tree decl;
9266 if (TYPE_DECL_IS_STUB (decl))
9267 return 1;
9269 if (DECL_ARTIFICIAL (decl)
9270 && DECL_CONTEXT (decl)
9271 && is_tagged_type (DECL_CONTEXT (decl))
9272 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9273 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9274 /* Also ignore the artificial member typedef for the class name. */
9275 return 1;
9277 return 0;
9280 /* Generate Dwarf debug information for a decl described by DECL. */
9282 static void
9283 gen_decl_die (decl, context_die)
9284 register tree decl;
9285 register dw_die_ref context_die;
9287 register tree origin;
9289 if (TREE_CODE (decl) == ERROR_MARK)
9290 return;
9292 /* If this ..._DECL node is marked to be ignored, then ignore it. */
9293 if (DECL_IGNORED_P (decl))
9294 return;
9296 switch (TREE_CODE (decl))
9298 case CONST_DECL:
9299 /* The individual enumerators of an enum type get output when we output
9300 the Dwarf representation of the relevant enum type itself. */
9301 break;
9303 case FUNCTION_DECL:
9304 /* Don't output any DIEs to represent mere function declarations,
9305 unless they are class members or explicit block externs. */
9306 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9307 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
9308 break;
9310 /* Emit info for the abstract instance first, if we haven't yet. */
9311 origin = decl_ultimate_origin (decl);
9312 if (origin)
9313 gen_abstract_function (origin);
9315 if (debug_info_level > DINFO_LEVEL_TERSE)
9317 /* Before we describe the FUNCTION_DECL itself, make sure that we
9318 have described its return type. */
9319 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9321 /* And its virtual context. */
9322 if (DECL_VINDEX (decl) != NULL_TREE)
9323 gen_type_die (DECL_CONTEXT (decl), context_die);
9325 /* And its containing type. */
9326 origin = decl_class_context (decl);
9327 if (origin != NULL_TREE)
9328 gen_type_die_for_member (origin, decl, context_die);
9331 /* Now output a DIE to represent the function itself. */
9332 gen_subprogram_die (decl, context_die);
9333 break;
9335 case TYPE_DECL:
9336 /* If we are in terse mode, don't generate any DIEs to represent any
9337 actual typedefs. */
9338 if (debug_info_level <= DINFO_LEVEL_TERSE)
9339 break;
9341 /* In the special case of a TYPE_DECL node representing the
9342 declaration of some type tag, if the given TYPE_DECL is marked as
9343 having been instantiated from some other (original) TYPE_DECL node
9344 (e.g. one which was generated within the original definition of an
9345 inline function) we have to generate a special (abbreviated)
9346 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9347 DIE here. */
9348 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
9350 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9351 break;
9354 if (is_redundant_typedef (decl))
9355 gen_type_die (TREE_TYPE (decl), context_die);
9356 else
9357 /* Output a DIE to represent the typedef itself. */
9358 gen_typedef_die (decl, context_die);
9359 break;
9361 case LABEL_DECL:
9362 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9363 gen_label_die (decl, context_die);
9364 break;
9366 case VAR_DECL:
9367 /* If we are in terse mode, don't generate any DIEs to represent any
9368 variable declarations or definitions. */
9369 if (debug_info_level <= DINFO_LEVEL_TERSE)
9370 break;
9372 /* Output any DIEs that are needed to specify the type of this data
9373 object. */
9374 gen_type_die (TREE_TYPE (decl), context_die);
9376 /* And its containing type. */
9377 origin = decl_class_context (decl);
9378 if (origin != NULL_TREE)
9379 gen_type_die_for_member (origin, decl, context_die);
9381 /* Now output the DIE to represent the data object itself. This gets
9382 complicated because of the possibility that the VAR_DECL really
9383 represents an inlined instance of a formal parameter for an inline
9384 function. */
9385 origin = decl_ultimate_origin (decl);
9386 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9387 gen_formal_parameter_die (decl, context_die);
9388 else
9389 gen_variable_die (decl, context_die);
9390 break;
9392 case FIELD_DECL:
9393 /* Ignore the nameless fields that are used to skip bits, but
9394 handle C++ anonymous unions. */
9395 if (DECL_NAME (decl) != NULL_TREE
9396 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
9398 gen_type_die (member_declared_type (decl), context_die);
9399 gen_field_die (decl, context_die);
9401 break;
9403 case PARM_DECL:
9404 gen_type_die (TREE_TYPE (decl), context_die);
9405 gen_formal_parameter_die (decl, context_die);
9406 break;
9408 case NAMESPACE_DECL:
9409 /* Ignore for now. */
9410 break;
9412 default:
9413 abort ();
9417 /* Add Ada "use" clause information for SGI Workshop debugger. */
9419 void
9420 dwarf2out_add_library_unit_info (filename, context_list)
9421 const char *filename;
9422 const char *context_list;
9424 unsigned int file_index;
9426 if (filename != NULL)
9428 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
9429 tree context_list_decl
9430 = build_decl (LABEL_DECL, get_identifier (context_list),
9431 void_type_node);
9433 TREE_PUBLIC (context_list_decl) = TRUE;
9434 add_name_attribute (unit_die, context_list);
9435 file_index = lookup_filename (filename);
9436 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
9437 add_pubname (context_list_decl, unit_die);
9441 /* Write the debugging output for DECL. */
9443 void
9444 dwarf2out_decl (decl)
9445 register tree decl;
9447 register dw_die_ref context_die = comp_unit_die;
9449 if (TREE_CODE (decl) == ERROR_MARK)
9450 return;
9452 /* If this ..._DECL node is marked to be ignored, then ignore it. */
9453 if (DECL_IGNORED_P (decl))
9454 return;
9456 switch (TREE_CODE (decl))
9458 case FUNCTION_DECL:
9459 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9460 builtin function. Explicit programmer-supplied declarations of
9461 these same functions should NOT be ignored however. */
9462 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
9463 return;
9465 /* What we would really like to do here is to filter out all mere
9466 file-scope declarations of file-scope functions which are never
9467 referenced later within this translation unit (and keep all of ones
9468 that *are* referenced later on) but we aren't clairvoyant, so we have
9469 no idea which functions will be referenced in the future (i.e. later
9470 on within the current translation unit). So here we just ignore all
9471 file-scope function declarations which are not also definitions. If
9472 and when the debugger needs to know something about these functions,
9473 it will have to hunt around and find the DWARF information associated
9474 with the definition of the function. Note that we can't just check
9475 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9476 definitions and which ones represent mere declarations. We have to
9477 check `DECL_INITIAL' instead. That's because the C front-end
9478 supports some weird semantics for "extern inline" function
9479 definitions. These can get inlined within the current translation
9480 unit (an thus, we need to generate DWARF info for their abstract
9481 instances so that the DWARF info for the concrete inlined instances
9482 can have something to refer to) but the compiler never generates any
9483 out-of-lines instances of such things (despite the fact that they
9484 *are* definitions). The important point is that the C front-end
9485 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9486 to generate DWARF for them anyway. Note that the C++ front-end also
9487 plays some similar games for inline function definitions appearing
9488 within include files which also contain
9489 `#pragma interface' pragmas. */
9490 if (DECL_INITIAL (decl) == NULL_TREE)
9491 return;
9493 /* If we're a nested function, initially use a parent of NULL; if we're
9494 a plain function, this will be fixed up in decls_for_scope. If
9495 we're a method, it will be ignored, since we already have a DIE. */
9496 if (decl_function_context (decl))
9497 context_die = NULL;
9499 break;
9501 case VAR_DECL:
9502 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9503 declaration and if the declaration was never even referenced from
9504 within this entire compilation unit. We suppress these DIEs in
9505 order to save space in the .debug section (by eliminating entries
9506 which are probably useless). Note that we must not suppress
9507 block-local extern declarations (whether used or not) because that
9508 would screw-up the debugger's name lookup mechanism and cause it to
9509 miss things which really ought to be in scope at a given point. */
9510 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
9511 return;
9513 /* If we are in terse mode, don't generate any DIEs to represent any
9514 variable declarations or definitions. */
9515 if (debug_info_level <= DINFO_LEVEL_TERSE)
9516 return;
9517 break;
9519 case TYPE_DECL:
9520 /* Don't emit stubs for types unless they are needed by other DIEs. */
9521 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
9522 return;
9524 /* Don't bother trying to generate any DIEs to represent any of the
9525 normal built-in types for the language we are compiling. */
9526 if (DECL_SOURCE_LINE (decl) == 0)
9528 /* OK, we need to generate one for `bool' so GDB knows what type
9529 comparisons have. */
9530 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9531 == DW_LANG_C_plus_plus)
9532 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9533 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
9535 return;
9538 /* If we are in terse mode, don't generate any DIEs for types. */
9539 if (debug_info_level <= DINFO_LEVEL_TERSE)
9540 return;
9542 /* If we're a function-scope tag, initially use a parent of NULL;
9543 this will be fixed up in decls_for_scope. */
9544 if (decl_function_context (decl))
9545 context_die = NULL;
9547 break;
9549 default:
9550 return;
9553 gen_decl_die (decl, context_die);
9556 /* Output a marker (i.e. a label) for the beginning of the generated code for
9557 a lexical block. */
9559 void
9560 dwarf2out_begin_block (blocknum)
9561 register unsigned blocknum;
9563 function_section (current_function_decl);
9564 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
9567 /* Output a marker (i.e. a label) for the end of the generated code for a
9568 lexical block. */
9570 void
9571 dwarf2out_end_block (blocknum)
9572 register unsigned blocknum;
9574 function_section (current_function_decl);
9575 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
9578 /* We've decided not to emit any debugging information for BLOCK; make
9579 sure that we don't end up with orphans as a result. */
9581 void
9582 dwarf2out_ignore_block (block)
9583 tree block;
9585 tree decl;
9586 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
9588 dw_die_ref die;
9590 if (TREE_CODE (decl) == FUNCTION_DECL)
9591 die = lookup_decl_die (decl);
9592 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9593 die = lookup_type_die (TREE_TYPE (decl));
9594 else
9595 die = NULL;
9597 /* Just give them a dummy value for parent so dwarf2out_finish
9598 doesn't blow up; we would use add_child_die if we really
9599 wanted to add them to comp_unit_die's children. */
9600 if (die && die->die_parent == 0)
9601 die->die_parent = comp_unit_die;
9605 /* Output a marker (i.e. a label) at a point in the assembly code which
9606 corresponds to a given source level label. */
9608 void
9609 dwarf2out_label (insn)
9610 register rtx insn;
9612 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9614 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9616 function_section (current_function_decl);
9617 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9618 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9619 (unsigned) INSN_UID (insn));
9623 /* Lookup a filename (in the list of filenames that we know about here in
9624 dwarf2out.c) and return its "index". The index of each (known) filename is
9625 just a unique number which is associated with only that one filename.
9626 We need such numbers for the sake of generating labels
9627 (in the .debug_sfnames section) and references to those
9628 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9629 If the filename given as an argument is not found in our current list,
9630 add it to the list and assign it the next available unique index number.
9631 In order to speed up searches, we remember the index of the filename
9632 was looked up last. This handles the majority of all searches. */
9634 static unsigned
9635 lookup_filename (file_name)
9636 const char *file_name;
9638 static unsigned last_file_lookup_index = 0;
9639 register unsigned i;
9641 /* Check to see if the file name that was searched on the previous call
9642 matches this file name. If so, return the index. */
9643 if (last_file_lookup_index != 0)
9644 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
9645 return last_file_lookup_index;
9647 /* Didn't match the previous lookup, search the table */
9648 for (i = 1; i < file_table_in_use; ++i)
9649 if (strcmp (file_name, file_table[i]) == 0)
9651 last_file_lookup_index = i;
9652 return i;
9655 /* Prepare to add a new table entry by making sure there is enough space in
9656 the table to do so. If not, expand the current table. */
9657 if (file_table_in_use == file_table_allocated)
9659 file_table_allocated += FILE_TABLE_INCREMENT;
9660 file_table
9661 = (char **) xrealloc (file_table,
9662 file_table_allocated * sizeof (char *));
9665 /* Add the new entry to the end of the filename table. */
9666 file_table[file_table_in_use] = xstrdup (file_name);
9667 last_file_lookup_index = file_table_in_use++;
9669 return last_file_lookup_index;
9672 /* Output a label to mark the beginning of a source code line entry
9673 and record information relating to this source line, in
9674 'line_info_table' for later output of the .debug_line section. */
9676 void
9677 dwarf2out_line (filename, line)
9678 register const char *filename;
9679 register unsigned line;
9681 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9683 function_section (current_function_decl);
9685 if (DWARF2_ASM_LINE_DEBUG_INFO)
9687 static const char *lastfile;
9689 /* Emit the .file and .loc directives understood by GNU as. */
9690 if (lastfile == 0 || strcmp (filename, lastfile))
9692 if (lastfile == 0)
9693 ggc_add_string_root ((char **) &lastfile, 1);
9695 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
9696 lastfile = filename;
9699 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
9701 /* Indicate that line number info exists. */
9702 ++line_info_table_in_use;
9704 /* Indicate that multiple line number tables exist. */
9705 if (DECL_SECTION_NAME (current_function_decl))
9706 ++separate_line_info_table_in_use;
9708 else if (DECL_SECTION_NAME (current_function_decl))
9710 register dw_separate_line_info_ref line_info;
9711 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
9712 separate_line_info_table_in_use);
9713 if (flag_debug_asm)
9714 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9715 fputc ('\n', asm_out_file);
9717 /* expand the line info table if necessary */
9718 if (separate_line_info_table_in_use
9719 == separate_line_info_table_allocated)
9721 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9722 separate_line_info_table
9723 = (dw_separate_line_info_ref)
9724 xrealloc (separate_line_info_table,
9725 separate_line_info_table_allocated
9726 * sizeof (dw_separate_line_info_entry));
9729 /* Add the new entry at the end of the line_info_table. */
9730 line_info
9731 = &separate_line_info_table[separate_line_info_table_in_use++];
9732 line_info->dw_file_num = lookup_filename (filename);
9733 line_info->dw_line_num = line;
9734 line_info->function = current_funcdef_number;
9736 else
9738 register dw_line_info_ref line_info;
9740 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
9741 line_info_table_in_use);
9742 if (flag_debug_asm)
9743 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9744 fputc ('\n', asm_out_file);
9746 /* Expand the line info table if necessary. */
9747 if (line_info_table_in_use == line_info_table_allocated)
9749 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9750 line_info_table
9751 = (dw_line_info_ref)
9752 xrealloc (line_info_table,
9753 (line_info_table_allocated
9754 * sizeof (dw_line_info_entry)));
9757 /* Add the new entry at the end of the line_info_table. */
9758 line_info = &line_info_table[line_info_table_in_use++];
9759 line_info->dw_file_num = lookup_filename (filename);
9760 line_info->dw_line_num = line;
9765 /* Record the beginning of a new source file, for later output
9766 of the .debug_macinfo section. At present, unimplemented. */
9768 void
9769 dwarf2out_start_source_file (filename)
9770 register const char *filename ATTRIBUTE_UNUSED;
9774 /* Record the end of a source file, for later output
9775 of the .debug_macinfo section. At present, unimplemented. */
9777 void
9778 dwarf2out_end_source_file ()
9782 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9783 the tail part of the directive line, i.e. the part which is past the
9784 initial whitespace, #, whitespace, directive-name, whitespace part. */
9786 void
9787 dwarf2out_define (lineno, buffer)
9788 register unsigned lineno ATTRIBUTE_UNUSED;
9789 register const char *buffer ATTRIBUTE_UNUSED;
9791 static int initialized = 0;
9792 if (!initialized)
9794 dwarf2out_start_source_file (primary_filename);
9795 initialized = 1;
9799 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9800 the tail part of the directive line, i.e. the part which is past the
9801 initial whitespace, #, whitespace, directive-name, whitespace part. */
9803 void
9804 dwarf2out_undef (lineno, buffer)
9805 register unsigned lineno ATTRIBUTE_UNUSED;
9806 register const char *buffer ATTRIBUTE_UNUSED;
9810 /* Set up for Dwarf output at the start of compilation. */
9812 void
9813 dwarf2out_init (asm_out_file, main_input_filename)
9814 register FILE *asm_out_file;
9815 register char *main_input_filename;
9817 /* Remember the name of the primary input file. */
9818 primary_filename = main_input_filename;
9820 /* Allocate the initial hunk of the file_table. */
9821 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
9822 file_table_allocated = FILE_TABLE_INCREMENT;
9824 /* Skip the first entry - file numbers begin at 1. */
9825 file_table_in_use = 1;
9827 /* Allocate the initial hunk of the decl_die_table. */
9828 decl_die_table
9829 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
9830 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
9831 decl_die_table_in_use = 0;
9833 /* Allocate the initial hunk of the decl_scope_table. */
9834 decl_scope_table
9835 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
9836 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
9837 decl_scope_depth = 0;
9839 /* Allocate the initial hunk of the abbrev_die_table. */
9840 abbrev_die_table
9841 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
9842 sizeof (dw_die_ref));
9843 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
9844 /* Zero-th entry is allocated, but unused */
9845 abbrev_die_table_in_use = 1;
9847 /* Allocate the initial hunk of the line_info_table. */
9848 line_info_table
9849 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
9850 sizeof (dw_line_info_entry));
9851 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
9852 /* Zero-th entry is allocated, but unused */
9853 line_info_table_in_use = 1;
9855 /* Generate the initial DIE for the .debug section. Note that the (string)
9856 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9857 will (typically) be a relative pathname and that this pathname should be
9858 taken as being relative to the directory from which the compiler was
9859 invoked when the given (base) source file was compiled. */
9860 comp_unit_die = gen_compile_unit_die (main_input_filename);
9862 if (ggc_p)
9864 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
9865 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
9868 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
9869 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
9870 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9871 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
9872 else
9873 strcpy (text_section_label, stripattributes (TEXT_SECTION));
9874 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
9875 DEBUG_INFO_SECTION_LABEL, 0);
9876 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
9877 DEBUG_LINE_SECTION_LABEL, 0);
9879 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9880 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
9881 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9883 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9884 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
9886 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9887 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
9888 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9889 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
9892 /* Output stuff that dwarf requires at the end of every file,
9893 and generate the DWARF-2 debugging info. */
9895 void
9896 dwarf2out_finish ()
9898 limbo_die_node *node, *next_node;
9899 dw_die_ref die;
9901 /* Traverse the limbo die list, and add parent/child links. The only
9902 dies without parents that should be here are concrete instances of
9903 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9904 For concrete instances, we can get the parent die from the abstract
9905 instance. */
9906 for (node = limbo_die_list; node; node = next_node)
9908 next_node = node->next;
9909 die = node->die;
9911 if (die->die_parent == NULL)
9913 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
9914 if (origin)
9915 add_child_die (origin->die_parent, die);
9916 else if (die == comp_unit_die)
9918 else
9919 abort ();
9921 free (node);
9923 limbo_die_list = NULL;
9925 /* Walk through the list of incomplete types again, trying once more to
9926 emit full debugging info for them. */
9927 retry_incomplete_types ();
9929 /* Traverse the DIE's, reverse their lists of attributes and children,
9930 and add add sibling attributes to those DIE's that have children. */
9931 add_sibling_attributes (comp_unit_die);
9933 /* Output a terminator label for the .text section. */
9934 fputc ('\n', asm_out_file);
9935 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9936 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
9938 #if 0
9939 /* Output a terminator label for the .data section. */
9940 fputc ('\n', asm_out_file);
9941 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
9942 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
9944 /* Output a terminator label for the .bss section. */
9945 fputc ('\n', asm_out_file);
9946 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
9947 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
9948 #endif
9950 /* Output the source line correspondence table. */
9951 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
9953 if (! DWARF2_ASM_LINE_DEBUG_INFO)
9955 fputc ('\n', asm_out_file);
9956 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9957 output_line_info ();
9960 /* We can only use the low/high_pc attributes if all of the code
9961 was in .text. */
9962 if (separate_line_info_table_in_use == 0)
9964 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
9965 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
9968 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
9969 debug_line_section_label);
9972 #if 0 /* unimplemented */
9973 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
9974 add_AT_unsigned (die, DW_AT_macro_info, 0);
9975 #endif
9977 /* Output the abbreviation table. */
9978 fputc ('\n', asm_out_file);
9979 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9980 build_abbrev_table (comp_unit_die);
9981 output_abbrev_section ();
9983 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9984 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9985 calc_die_sizes (comp_unit_die);
9987 /* Output debugging information. */
9988 fputc ('\n', asm_out_file);
9989 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9990 output_compilation_unit_header ();
9991 output_die (comp_unit_die);
9993 if (pubname_table_in_use)
9995 /* Output public names table. */
9996 fputc ('\n', asm_out_file);
9997 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
9998 output_pubnames ();
10001 /* We only put functions in the arange table, so don't write it out if
10002 we don't have any. */
10003 if (fde_table_in_use)
10005 /* Output the address range information. */
10006 fputc ('\n', asm_out_file);
10007 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
10008 output_aranges ();
10011 #endif /* DWARF2_DEBUGGING_INFO */